Revision 4b393363
Added by Andreas Kohlbecker over 6 years ago
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/ConfigFileUtil.java | ||
---|---|---|
24 | 24 |
*/ |
25 | 25 |
public class ConfigFileUtil { |
26 | 26 |
|
27 |
/** |
|
28 |
* |
|
29 |
*/ |
|
30 |
public static final String CDM_CONFIGFILE_OVERRIDE = "cdm.configfile.override."; |
|
31 |
|
|
27 | 32 |
private Properties props = null; |
28 | 33 |
|
29 | 34 |
private String defaultContent = ""; |
... | ... | |
39 | 44 |
return this; |
40 | 45 |
} |
41 | 46 |
|
47 |
/** |
|
48 |
* Per default the <code>propertiesSet</code> is loaded from a file located in |
|
49 |
* <code>~/.cdmLibrary/remote-webapp/{instanceName}/{propertiesSet}.properties</code>. |
|
50 |
* <p> |
|
51 |
* This behavior can be overwritten by setting the java System property |
|
52 |
* <code>cdm.configfile.override.{propertiesSet}</code> to an alternative file location. |
|
53 |
* This mechanism should only be used for unit and integration tests. |
|
54 |
* |
|
55 |
* @param instanceName the name of the cdm instance. This value can be retrieved from the |
|
56 |
* Spring environment with the key DataSourceConfigurer.CDM_DATA_SOURCE_ID ("") |
|
57 |
* @param propertiesSet |
|
58 |
* The base name of the properties file to be loaded. This name is extended with |
|
59 |
* ".properties" to form the actual filename |
|
60 |
* |
|
61 |
* @return |
|
62 |
* The file containing the properties |
|
63 |
*/ |
|
42 | 64 |
public File getPropertiesFile(String instanceName, String propertiesSet) { |
43 | 65 |
|
44 | 66 |
if(propertiesSet == null){ |
45 | 67 |
throw new NullPointerException(); |
46 | 68 |
} |
47 |
File configFolder = CdmUtils.getCdmInstanceSubDir(CdmUtils.SUBFOLDER_WEBAPP, instanceName); |
|
48 |
return new File(configFolder, propertiesSet + ".properties"); |
|
69 |
String override = System.getProperty(CDM_CONFIGFILE_OVERRIDE + propertiesSet); |
|
70 |
if(override != null){ |
|
71 |
return new File(override); |
|
72 |
} else { |
|
73 |
File configFolder = CdmUtils.getCdmInstanceSubDir(CdmUtils.SUBFOLDER_WEBAPP, instanceName); |
|
74 |
return new File(configFolder, propertiesSet + ".properties"); |
|
75 |
} |
|
49 | 76 |
} |
50 | 77 |
|
51 | 78 |
/** |
79 |
* Per default the <code>propertiesSet</code> is loaded from a file located in |
|
80 |
* <code>~/.cdmLibrary/remote-webapp/{instanceName}/{propertiesSet}.properties</code>. |
|
81 |
* <p> |
|
82 |
* This behavior can be overwritten by setting the java System property |
|
83 |
* <code>cdm.configfile.override.{propertiesSet}</code> to an alternative file location. |
|
84 |
* This mechanism should only be used for unit and integration tests. |
|
52 | 85 |
* |
53 |
* @param instanceName |
|
54 |
* @param propertiesName |
|
55 |
* Is used to compose the properties filename by adding the file extension <code>.properties</code> |
|
86 |
* @param instanceName the name of the cdm instance. This value can be retrieved from the |
|
87 |
* Spring environment with the key DataSourceConfigurer.CDM_DATA_SOURCE_ID ("") |
|
88 |
* @param propertiesSet |
|
89 |
* The base name of the properties file to be loaded. This name is extended with |
|
90 |
* ".properties" to form the actual filename |
|
56 | 91 |
* |
57 | 92 |
* @return |
58 |
* @throws IOException
|
|
93 |
* The properties loaded from the file
|
|
59 | 94 |
*/ |
60 | 95 |
public Properties getProperties(String instanceName, String propertiesName) throws IOException { |
61 | 96 |
|
Also available in: Unified diff
allowing to override property files for test environments