use of org.craftercms.commons.config.YamlConfiguration in project studio by craftercms.
the class StudioConfigurationImpl method loadConfig.
@Override
public void loadConfig() {
YamlConfiguration baseConfig = new YamlConfiguration();
YamlConfiguration overrideConfig = new YamlConfiguration();
Resource resource = new ClassPathResource(configLocation);
try (InputStream in = resource.getInputStream()) {
baseConfig.setExpressionEngine(getExpressionEngine());
baseConfig.read(in);
logger.debug("Loaded configuration from location: {0} \n {1}", configLocation, baseConfig);
} catch (IOException | ConfigurationException e) {
logger.error("Failed to load studio configuration from: " + configLocation, e);
}
if (baseConfig.containsKey(STUDIO_CONFIG_OVERRIDE_CONFIG)) {
String overrideConfigLocation = baseConfig.getString(STUDIO_CONFIG_OVERRIDE_CONFIG);
resource = new ClassPathResource(overrideConfigLocation);
try (InputStream in = resource.getInputStream()) {
overrideConfig.setExpressionEngine(getExpressionEngine());
overrideConfig.read(in);
if (!overrideConfig.isEmpty()) {
logger.debug("Loaded additional configuration from location: {0} \n {1}", overrideConfigLocation, overrideConfig);
}
} catch (IOException | ConfigurationException e) {
logger.error("Failed to load studio configuration from: " + overrideConfigLocation, e);
}
}
// Merge the base properties and additional properties
if (!overrideConfig.isEmpty()) {
CombinedConfiguration combinedConfig = new CombinedConfiguration(new OverrideCombiner());
combinedConfig.setExpressionEngine(getExpressionEngine());
combinedConfig.addConfiguration(overrideConfig);
combinedConfig.addConfiguration(baseConfig);
systemConfig = combinedConfig;
} else {
systemConfig = baseConfig;
}
}
use of org.craftercms.commons.config.YamlConfiguration in project deployer by craftercms.
the class ReplaceProcessorUpgradeOperationTest method setUp.
@Before
public void setUp() throws ConfigurationException, IOException, org.apache.commons.configuration2.ex.ConfigurationException {
YamlConfiguration config = new YamlConfiguration();
Resource configFile = new ClassPathResource("upgrade/replaceProcessor/config.yaml");
try (InputStream is = configFile.getInputStream()) {
config.read(is);
}
Yaml yaml = new Yaml();
Resource resource = new ClassPathResource("upgrade/replaceProcessor/target.yaml");
try (InputStream is = resource.getInputStream()) {
targetConfig = yaml.load(is);
}
when(target.getEnv()).thenReturn("preview");
processor.init(null, null, config);
}
use of org.craftercms.commons.config.YamlConfiguration in project deployer by craftercms.
the class DeploymentPipelineFactoryImplTest method createConfiguration.
private HierarchicalConfiguration createConfiguration() throws Exception {
ClassPathResource yamlResource = new ClassPathResource("targets/foobar-test.yaml");
YamlConfiguration yamlConfig = new YamlConfiguration();
yamlConfig.read(new FileReader(yamlResource.getFile()));
yamlConfig.setProperty(TARGET_ID_CONFIG_KEY, "foobar-test");
return yamlConfig;
}
use of org.craftercms.commons.config.YamlConfiguration in project studio by craftercms.
the class StudioConfigurationImpl method loadGlobalRepoConfig.
@SuppressWarnings("unchecked")
private HierarchicalConfiguration<ImmutableNode> loadGlobalRepoConfig() {
String cacheKey = prependIfMissing(systemConfig.getString(STUDIO_CONFIG_GLOBAL_REPO_OVERRIDE_CONFIG), "/");
Path globalRepoOverrideConfigLocation = Paths.get(systemConfig.getString(REPO_BASE_PATH), systemConfig.getString(GLOBAL_REPO_PATH), systemConfig.getString(STUDIO_CONFIG_GLOBAL_REPO_OVERRIDE_CONFIG));
HierarchicalConfiguration<ImmutableNode> config = systemConfig;
Element element = configurationCache.get(cacheKey);
if (element != null && !element.isExpired()) {
config = (HierarchicalConfiguration<ImmutableNode>) element.getObjectValue();
} else {
if (systemConfig.containsKey(STUDIO_CONFIG_GLOBAL_REPO_OVERRIDE_CONFIG)) {
FileSystemResource fsr = new FileSystemResource(globalRepoOverrideConfigLocation.toFile());
if (fsr.exists()) {
try {
YamlConfiguration globalRepoOverrideConfig = new YamlConfiguration();
try (InputStream in = fsr.getInputStream()) {
globalRepoOverrideConfig.setExpressionEngine(getExpressionEngine());
globalRepoOverrideConfig.read(in);
if (!globalRepoOverrideConfig.isEmpty()) {
logger.debug("Loaded additional configuration from location: {0} \n {1}", fsr.getPath(), globalRepoOverrideConfig);
CombinedConfiguration combinedConfig = new CombinedConfiguration(new OverrideCombiner());
combinedConfig.setExpressionEngine(getExpressionEngine());
combinedConfig.addConfiguration(globalRepoOverrideConfig);
combinedConfig.addConfiguration(systemConfig);
config = combinedConfig;
}
}
} catch (IOException | ConfigurationException e) {
logger.error("Failed to load studio configuration from: " + fsr.getPath(), e);
}
}
}
configurationCache.put(new Element(cacheKey, config));
}
return config;
}
Aggregations