Search in sources :

Example 1 with YamlConfiguration

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;
    }
}
Also used : ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) InputStream(java.io.InputStream) ClassPathResource(org.springframework.core.io.ClassPathResource) FileSystemResource(org.springframework.core.io.FileSystemResource) Resource(org.springframework.core.io.Resource) CombinedConfiguration(org.apache.commons.configuration2.CombinedConfiguration) IOException(java.io.IOException) YamlConfiguration(org.craftercms.commons.config.YamlConfiguration) ClassPathResource(org.springframework.core.io.ClassPathResource) OverrideCombiner(org.apache.commons.configuration2.tree.OverrideCombiner)

Example 2 with YamlConfiguration

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);
}
Also used : InputStream(java.io.InputStream) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) YamlConfiguration(org.craftercms.commons.config.YamlConfiguration) ClassPathResource(org.springframework.core.io.ClassPathResource) Yaml(org.yaml.snakeyaml.Yaml) Before(org.junit.Before)

Example 3 with YamlConfiguration

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;
}
Also used : FileReader(java.io.FileReader) YamlConfiguration(org.craftercms.commons.config.YamlConfiguration) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 4 with YamlConfiguration

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;
}
Also used : Path(java.nio.file.Path) ImmutableNode(org.apache.commons.configuration2.tree.ImmutableNode) InputStream(java.io.InputStream) Element(net.sf.ehcache.Element) CombinedConfiguration(org.apache.commons.configuration2.CombinedConfiguration) FileSystemResource(org.springframework.core.io.FileSystemResource) IOException(java.io.IOException) YamlConfiguration(org.craftercms.commons.config.YamlConfiguration) OverrideCombiner(org.apache.commons.configuration2.tree.OverrideCombiner) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException)

Aggregations

YamlConfiguration (org.craftercms.commons.config.YamlConfiguration)4 InputStream (java.io.InputStream)3 ClassPathResource (org.springframework.core.io.ClassPathResource)3 IOException (java.io.IOException)2 CombinedConfiguration (org.apache.commons.configuration2.CombinedConfiguration)2 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)2 OverrideCombiner (org.apache.commons.configuration2.tree.OverrideCombiner)2 FileSystemResource (org.springframework.core.io.FileSystemResource)2 Resource (org.springframework.core.io.Resource)2 FileReader (java.io.FileReader)1 Path (java.nio.file.Path)1 Element (net.sf.ehcache.Element)1 ImmutableNode (org.apache.commons.configuration2.tree.ImmutableNode)1 Before (org.junit.Before)1 Yaml (org.yaml.snakeyaml.Yaml)1