Skip to content

Commit

Permalink
fix for APIMAN-956 - customize location of apiman.properties file
Browse files Browse the repository at this point in the history
  • Loading branch information
EricWittmann committed Feb 9, 2016
1 parent 124c395 commit d4e3f7d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
Expand Up @@ -34,7 +34,7 @@ public class ConfigFactory {
public static final CompositeConfiguration createConfig() {
CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
compositeConfiguration.addConfiguration(new SystemPropertiesConfiguration());
compositeConfiguration.addConfiguration(ConfigFileConfiguration.create("apiman.properties")); //$NON-NLS-1$
compositeConfiguration.addConfiguration(ConfigFileConfiguration.create("apiman.properties", "apiman.config.url")); //$NON-NLS-1$ //$NON-NLS-2$
return compositeConfiguration;
}

Expand Down
Expand Up @@ -49,20 +49,49 @@ protected static URL findConfigUrlInDirectory(File directory, String configName)
return null;
}

public static ConfigFileConfiguration create(String configFileName) {
public static ConfigFileConfiguration create(String configFileName, String customConfigPropertyName) {
try {
return new ConfigFileConfiguration(configFileName);
return new ConfigFileConfiguration(configFileName, customConfigPropertyName);
} catch (ConfigurationException e) {
throw new RuntimeException("Failed to find configuration file: " + configFileName, e); //$NON-NLS-1$
}
}

private static URL discoverConfigFileUrl(String configFileName) {
// Wildfly/EAP takes priority
/**
* Discover the location of the apiman.properties (for example) file by checking
* in various likely locations.
*
* @param configFileName
*/
private static URL discoverConfigFileUrl(String configFileName, String customConfigPropertyName) {
URL rval = null;

// User Defined
///////////////////////////////////
String userConfig = System.getProperty(customConfigPropertyName);
if (userConfig != null) {
// Treat it as a URL
try {
rval = new URL(userConfig);
return rval;
} catch (Throwable t) {
}
// Treat it as a file
try {
File f = new File(userConfig);
if (f.isFile()) {
rval = f.toURI().toURL();
return rval;
}
} catch (Throwable t) {
}
throw new RuntimeException("Apiman configuration provided at [" + userConfig + "] but could not be loaded."); //$NON-NLS-1$ //$NON-NLS-2$
}

// Wildfly/EAP
///////////////////////////////////
String jbossConfigDir = System.getProperty("jboss.server.config.dir"); //$NON-NLS-1$
String jbossConfigUrl = System.getProperty("jboss.server.config.url"); //$NON-NLS-1$
URL rval = null;
if (jbossConfigDir != null) {
File dirFile = new File(jbossConfigDir);
rval = findConfigUrlInDirectory(dirFile, configFileName);
Expand All @@ -78,7 +107,7 @@ private static URL discoverConfigFileUrl(String configFileName) {
}
}

// Next try tomcat
// Apache Tomcat
///////////////////////
String tomcatHomeDir = System.getProperty("catalina.home"); //$NON-NLS-1$
if (tomcatHomeDir != null) {
Expand All @@ -97,10 +126,11 @@ private static URL discoverConfigFileUrl(String configFileName) {
/**
* Constructor.
* @param configFileName
* @param customConfigPropertyName
* @throws ConfigurationException
*/
private ConfigFileConfiguration(String configFileName) throws ConfigurationException {
super(discoverConfigFileUrl(configFileName));
private ConfigFileConfiguration(String configFileName, String customConfigPropertyName) throws ConfigurationException {
super(discoverConfigFileUrl(configFileName, customConfigPropertyName));
}

}

0 comments on commit d4e3f7d

Please sign in to comment.