use of org.commonjava.indy.conf.IndyConfigInfo in project indy by Commonjava.
the class DefaultIndyConfigFactory method writeDefaultConfigs.
@Override
public void writeDefaultConfigs(final File dir) throws ConfigurationException {
Properties props = getBaseSystemProperties();
for (final IndyConfigInfo section : configSections) {
String sectionName = ConfigUtils.getSectionName(section.getClass());
logger.info("Config section: {} with name: {}", section, sectionName);
writeDefaultsFor(section, dir);
}
}
use of org.commonjava.indy.conf.IndyConfigInfo in project indy by Commonjava.
the class DefaultIndyConfigFactory method load.
// private static String configPath = System.getProperty( CONFIG_PATH_PROP, DEFAULT_CONFIG_PATH );
//
// public static void setConfigPath( final String path )
// {
// configPath = path;
// }
//
// @PostConstruct
@Override
public synchronized void load(final String configPath) throws ConfigurationException {
Properties props = getBaseSystemProperties();
logger.info("\n\n\n\n[CONFIG] Reading Indy configuration in: '{}'\n\nAdding configuration section listeners:", Thread.currentThread().getName());
logger.info("Adding configuration sections...");
if (configSections != null) {
for (final IndyConfigInfo section : configSections) {
String sectionName = ConfigUtils.getSectionName(section.getClass());
logger.info("Adding configuration section: {}", sectionName);
with(sectionName, section);
}
}
final String config = configPath(configPath);
logger.info("\n\n[CONFIG] Reading configuration in: '{}'\n\nfrom {}", Thread.currentThread().getName(), config);
File configFile = new File(config);
if (configFile.isDirectory()) {
configFile = new File(configFile, "main.conf");
}
if (!configFile.exists()) {
File dir = configFile;
if (dir.getName().equals("main.conf")) {
dir = dir.getParentFile();
}
logger.warn("Cannot find configuration in: {}. Writing default configurations there for future modification.", dir);
if (!dir.exists() && !dir.mkdirs()) {
throw new ConfigurationException("Failed to create configuration directory: %s, in order to write defaults.", dir);
}
writeDefaultConfigs(dir);
}
List<ConfigurationListener> listeners = new ArrayList<>();
listeners.add(this);
if (configListeners != null) {
configListeners.forEach((listener) -> listeners.add(listener));
}
InputStream stream = null;
try {
stream = ConfigFileUtils.readFileWithIncludes(config, props);
new DotConfConfigurationReader(listeners).loadConfiguration(stream);
Properties sysprops = System.getProperties();
props.stringPropertyNames().forEach((name) -> sysprops.setProperty(name, props.getProperty(name)));
configSections.forEach((section) -> {
if (section instanceof SystemPropertyProvider) {
Properties p = ((SystemPropertyProvider) section).getSystemProperties();
p.stringPropertyNames().forEach((name) -> sysprops.setProperty(name, p.getProperty(name)));
}
});
System.setProperties(sysprops);
} catch (final IOException e) {
throw new ConfigurationException("Cannot open configuration file: {}. Reason: {}", e, configPath, e.getMessage());
} finally {
closeQuietly(stream);
}
logger.info("[CONFIG] Indy configuration complete for: '{}'.\n\n\n\n", Thread.currentThread().getName());
}
Aggregations