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);
}
}
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();
}
Aggregations