Search in sources :

Example 1 with ConfigResource

use of org.mule.runtime.core.api.config.ConfigResource in project mule by mulesoft.

the class AutoConfigurationBuilder method autoConfigure.

protected void autoConfigure(MuleContext muleContext, ConfigResource[] resources) throws ConfigurationException {
    Map<String, List<ConfigResource>> configsMap = new LinkedHashMap<String, List<ConfigResource>>();
    for (ConfigResource resource : resources) {
        String configExtension = substringAfterLast(resource.getUrl().getPath(), ".");
        List<ConfigResource> configs = configsMap.get(configExtension);
        if (configs == null) {
            configs = new ArrayList<ConfigResource>();
            configsMap.put(configExtension, configs);
        }
        configs.add(resource);
    }
    try {
        Properties props = loadProperties(getResource("configuration-builders.properties", this.getClass()).openStream());
        for (Map.Entry<String, List<ConfigResource>> e : configsMap.entrySet()) {
            String extension = e.getKey();
            List<ConfigResource> configs = e.getValue();
            String className = (String) props.get(extension);
            if (className == null || !ClassUtils.isClassOnPath(className, this.getClass())) {
                throw new ConfigurationException(configurationBuilderNoMatching(createConfigResourcesString()));
            }
            ConfigurationBuilder cb = (ConfigurationBuilder) ClassUtils.instantiateClass(className, new Object[] { configs.stream().map(ConfigResource::getResourceName).toArray(String[]::new), getArtifactProperties(), artifactType });
            if (parentContext != null && cb instanceof ParentMuleContextAwareConfigurationBuilder) {
                ((ParentMuleContextAwareConfigurationBuilder) cb).setParentContext(parentContext);
            } else if (parentContext != null) {
                throw new MuleRuntimeException(createStaticMessage(format("ConfigurationBuilder %s does not support domain context", cb.getClass().getCanonicalName())));
            }
            cb.configure(muleContext);
        }
    } catch (ConfigurationException e) {
        throw e;
    } catch (Exception e) {
        throw new ConfigurationException(e);
    }
}
Also used : ConfigurationBuilder(org.mule.runtime.core.api.config.ConfigurationBuilder) ParentMuleContextAwareConfigurationBuilder(org.mule.runtime.core.internal.config.ParentMuleContextAwareConfigurationBuilder) AbstractResourceConfigurationBuilder(org.mule.runtime.core.api.config.builders.AbstractResourceConfigurationBuilder) Properties(java.util.Properties) PropertiesUtils.loadProperties(org.mule.runtime.core.api.util.PropertiesUtils.loadProperties) ConfigResource(org.mule.runtime.core.api.config.ConfigResource) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) LinkedHashMap(java.util.LinkedHashMap) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ArrayList(java.util.ArrayList) List(java.util.List) ParentMuleContextAwareConfigurationBuilder(org.mule.runtime.core.internal.config.ParentMuleContextAwareConfigurationBuilder) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with ConfigResource

use of org.mule.runtime.core.api.config.ConfigResource in project mule by mulesoft.

the class MuleArtifactContext method resolveArtifactConfig.

private ArtifactConfig resolveArtifactConfig() throws IOException {
    ArtifactConfig.Builder applicationConfigBuilder = new ArtifactConfig.Builder();
    applicationConfigBuilder.setArtifactProperties(this.artifactProperties);
    List<Pair<String, InputStream>> initialConfigFiles = new ArrayList<>();
    for (ConfigResource artifactConfigResource : artifactConfigResources) {
        initialConfigFiles.add(new Pair<>(artifactConfigResource.getResourceName(), artifactConfigResource.getInputStream()));
    }
    List<ConfigFile> configFiles = new ArrayList<>();
    recursivelyResolveConfigFiles(initialConfigFiles, configFiles).forEach(applicationConfigBuilder::addConfigFile);
    applicationConfigBuilder.setApplicationName(muleContext.getConfiguration().getId());
    return applicationConfigBuilder.build();
}
Also used : ConfigFile(org.mule.runtime.config.api.dsl.processor.ConfigFile) ArtifactConfig(org.mule.runtime.config.api.dsl.processor.ArtifactConfig) ArrayList(java.util.ArrayList) ConfigResource(org.mule.runtime.core.api.config.ConfigResource) Pair(org.mule.runtime.api.util.Pair)

Aggregations

ArrayList (java.util.ArrayList)2 ConfigResource (org.mule.runtime.core.api.config.ConfigResource)2 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 Pair (org.mule.runtime.api.util.Pair)1 ArtifactConfig (org.mule.runtime.config.api.dsl.processor.ArtifactConfig)1 ConfigFile (org.mule.runtime.config.api.dsl.processor.ConfigFile)1 ConfigurationBuilder (org.mule.runtime.core.api.config.ConfigurationBuilder)1 ConfigurationException (org.mule.runtime.core.api.config.ConfigurationException)1 AbstractResourceConfigurationBuilder (org.mule.runtime.core.api.config.builders.AbstractResourceConfigurationBuilder)1 PropertiesUtils.loadProperties (org.mule.runtime.core.api.util.PropertiesUtils.loadProperties)1 ParentMuleContextAwareConfigurationBuilder (org.mule.runtime.core.internal.config.ParentMuleContextAwareConfigurationBuilder)1