Author: echatellier Date: 2012-01-12 12:19:12 +0100 (Thu, 12 Jan 2012) New Revision: 3315 Url: http://chorem.org/repositories/revision/lima/3315 Log: Fix appconfig Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java trunk/lima-business/src/test/java/org/chorem/lima/business/LimaTestConfig.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java 2012-01-10 14:01:43 UTC (rev 3314) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java 2012-01-12 11:19:12 UTC (rev 3315) @@ -48,9 +48,9 @@ * * @author chatellier * @version $Revision$ - * <p/> - * Last update : $Date$ - * By : $Author$ + * <p/> + * Last update : $Date$ + * By : $Author$ */ public class LimaConfig extends ApplicationConfig { @@ -58,14 +58,14 @@ protected static LimaConfig instance; - protected static final String CONFIGFILE = "lima.properties"; - protected AccountingRules accountingRules; public LimaConfig() { // set defaut option (included configuration file name : important) for (Option o : Option.values()) { - setDefaultOption(o.key, o.defaultValue); + if (o.getDefaultValue() != null) { + setDefaultOption(o.key, o.defaultValue); + } } setOption(TopiaMigrationService.TOPIA_SERVICE_NAME, TopiaMigrationEngine.class.getName()); @@ -77,7 +77,7 @@ public static LimaConfig getInstance() { if (instance == null) { instance = new LimaConfig(); - instance.loadConfiguration(CONFIGFILE); + instance.loadConfiguration(); } return instance; } @@ -96,8 +96,10 @@ } else { try { accountingRules = (AccountingRules) accountingRulesClass.newInstance(); - } catch (Exception e) { - log.error("Can't instantiate accounting rules", e); + } catch (Exception ex) { + if (log.isErrorEnabled()) { + log.error("Can't instantiate accounting rules", ex); + } } } } @@ -151,8 +153,7 @@ * * @param configFileName file name to read */ - protected void loadConfiguration(String configFileName) { - instance.setConfigFileName(configFileName); + protected void loadConfiguration() { try { instance.parse(); } catch (ArgumentsParserException ex) { @@ -173,7 +174,7 @@ */ public enum Option implements OptionDef { - CONFIG_FILE(CONFIG_FILE_NAME, _("lima.config.configFileName.description"), "lima-config.properties", String.class, true, true), + CONFIG_FILE(CONFIG_FILE_NAME, _("lima.config.configFileName.description"), "lima.properties", String.class, true, true), DATA_DIR("lima.data.dir", _("lima.config.data.dir.description"), "${user.home}/.lima", File.class, false, false), REPORTS_DIR("lima.reports.dir", _("lima.config.reports.dir.description"), "${lima.data.dir}/reports", File.class, false, false), RULES_NATIONALTY("lima.rules", _("lima.config.rulesnationality.description"), FranceAccountingRules.class.getName(), String.class, false, false), Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/LimaTestConfig.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/LimaTestConfig.java 2012-01-10 14:01:43 UTC (rev 3314) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/LimaTestConfig.java 2012-01-12 11:19:12 UTC (rev 3315) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2008 - 2010 CodeLutin + * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -50,10 +50,11 @@ public static LimaConfig getInstance() { if (instance == null) { instance = new LimaTestConfig(); - // do not call parse() method (don't read /etc... - + + // do not call parse() method (don't read /etc...) + // load file manually (lima.properties) Properties testProperties = new Properties(); - InputStream stream = LimaTestConfig.class.getResourceAsStream("/" + CONFIGFILE); + InputStream stream = LimaTestConfig.class.getResourceAsStream("/" + Option.CONFIG_FILE.getDefaultValue()); try { testProperties.load(stream);