use of org.mule.runtime.config.internal.dsl.model.config.EnvironmentPropertiesConfigurationProvider in project mule by mulesoft.
the class ApplicationModel method createConfigurationAttributeResolver.
private void createConfigurationAttributeResolver(ArtifactConfig artifactConfig, Optional<ConfigurationProperties> parentConfigurationProperties, Map<String, String> deploymentProperties) {
EnvironmentPropertiesConfigurationProvider environmentPropertiesConfigurationProvider = new EnvironmentPropertiesConfigurationProvider();
ConfigurationPropertiesProvider globalPropertiesConfigurationAttributeProvider = createProviderFromGlobalProperties(artifactConfig);
DefaultConfigurationPropertiesResolver localResolver = new DefaultConfigurationPropertiesResolver(of(new DefaultConfigurationPropertiesResolver(of(new DefaultConfigurationPropertiesResolver(empty(), environmentPropertiesConfigurationProvider)), globalPropertiesConfigurationAttributeProvider)), environmentPropertiesConfigurationProvider);
List<ConfigurationPropertiesProvider> configConfigurationPropertiesProviders = getConfigurationPropertiesProvidersFromComponents(artifactConfig, localResolver);
FileConfigurationPropertiesProvider externalPropertiesConfigurationProvider = new FileConfigurationPropertiesProvider(externalResourceProvider, "External files");
Optional<ConfigurationPropertiesResolver> parentConfigurationPropertiesResolver = of(localResolver);
if (parentConfigurationProperties.isPresent()) {
parentConfigurationPropertiesResolver = of(new DefaultConfigurationPropertiesResolver(empty(), new ConfigurationPropertiesProvider() {
@Override
public Optional<ConfigurationProperty> getConfigurationProperty(String configurationAttributeKey) {
return parentConfigurationProperties.get().resolveProperty(configurationAttributeKey).map(value -> new DefaultConfigurationProperty(parentConfigurationProperties, configurationAttributeKey, value));
}
@Override
public String getDescription() {
return "Domain properties";
}
}));
}
if (!configConfigurationPropertiesProviders.isEmpty()) {
CompositeConfigurationPropertiesProvider configurationAttributesProvider = new CompositeConfigurationPropertiesProvider(configConfigurationPropertiesProviders);
parentConfigurationPropertiesResolver = of(new DefaultConfigurationPropertiesResolver(parentConfigurationPropertiesResolver, configurationAttributesProvider));
}
DefaultConfigurationPropertiesResolver globalPropertiesConfigurationPropertiesResolver = new DefaultConfigurationPropertiesResolver(parentConfigurationPropertiesResolver, globalPropertiesConfigurationAttributeProvider);
DefaultConfigurationPropertiesResolver systemPropertiesResolver = new DefaultConfigurationPropertiesResolver(of(globalPropertiesConfigurationPropertiesResolver), environmentPropertiesConfigurationProvider);
DefaultConfigurationPropertiesResolver externalPropertiesResolver = new DefaultConfigurationPropertiesResolver(of(systemPropertiesResolver), externalPropertiesConfigurationProvider);
if (deploymentProperties.isEmpty()) {
this.configurationProperties = new PropertiesResolverConfigurationProperties(externalPropertiesResolver);
} else {
this.configurationProperties = new PropertiesResolverConfigurationProperties(new DefaultConfigurationPropertiesResolver(of(externalPropertiesResolver), new MapConfigurationPropertiesProvider(deploymentProperties, "Deployment properties")));
}
}
use of org.mule.runtime.config.internal.dsl.model.config.EnvironmentPropertiesConfigurationProvider in project mule by mulesoft.
the class XmlExtensionLoaderDelegate method getModuleComponentModel.
private ComponentModel getModuleComponentModel(URL resource, Document moduleDocument) {
XmlApplicationParser xmlApplicationParser = new XmlApplicationParser(new SpiServiceRegistry(), singletonList(currentThread().getContextClassLoader()));
Optional<ConfigLine> parseModule = xmlApplicationParser.parse(moduleDocument.getDocumentElement());
if (!parseModule.isPresent()) {
// This happens in org.mule.runtime.config.dsl.processor.xml.XmlApplicationParser.configLineFromElement()
throw new IllegalArgumentException(format("There was an issue trying to read the stream of '%s'", resource.getFile()));
}
ComponentModelReader componentModelReader = new ComponentModelReader(new DefaultConfigurationPropertiesResolver(empty(), new EnvironmentPropertiesConfigurationProvider()));
return componentModelReader.extractComponentDefinitionModel(parseModule.get(), modulePath);
}
use of org.mule.runtime.config.internal.dsl.model.config.EnvironmentPropertiesConfigurationProvider in project mule by mulesoft.
the class MuleArtifactContext method recursivelyResolveConfigFiles.
private List<ConfigFile> recursivelyResolveConfigFiles(List<Pair<String, InputStream>> configFilesToResolve, List<ConfigFile> alreadyResolvedConfigFiles) {
DefaultConfigurationPropertiesResolver propertyResolver = new DefaultConfigurationPropertiesResolver(empty(), new EnvironmentPropertiesConfigurationProvider());
ImmutableList.Builder<ConfigFile> resolvedConfigFilesBuilder = ImmutableList.<ConfigFile>builder().addAll(alreadyResolvedConfigFiles);
configFilesToResolve.stream().filter(fileNameInputStreamPair -> !alreadyResolvedConfigFiles.stream().anyMatch(configFile -> configFile.getFilename().equals(fileNameInputStreamPair.getFirst()))).forEach(fileNameInputStreamPair -> {
Document document = xmlConfigurationDocumentLoader.loadDocument(muleContext.getExtensionManager() == null ? emptySet() : muleContext.getExtensionManager().getExtensions(), fileNameInputStreamPair.getFirst(), fileNameInputStreamPair.getSecond());
ConfigLine mainConfigLine = xmlApplicationParser.parse(document.getDocumentElement()).get();
ConfigFile configFile = new ConfigFile(fileNameInputStreamPair.getFirst(), asList(mainConfigLine));
resolvedConfigFilesBuilder.add(configFile);
try {
fileNameInputStreamPair.getSecond().close();
} catch (IOException e) {
throw new MuleRuntimeException(e);
}
});
ImmutableSet.Builder<String> importedFiles = ImmutableSet.builder();
for (ConfigFile configFile : resolvedConfigFilesBuilder.build()) {
List<ConfigLine> rootConfigLines = configFile.getConfigLines();
ConfigLine muleRootElementConfigLine = rootConfigLines.get(0);
importedFiles.addAll(muleRootElementConfigLine.getChildren().stream().filter(configLine -> configLine.getNamespace().equals(CORE_PREFIX) && configLine.getIdentifier().equals(IMPORT_ELEMENT)).map(configLine -> {
SimpleConfigAttribute fileConfigAttribute = configLine.getConfigAttributes().get("file");
if (fileConfigAttribute == null) {
throw new RuntimeConfigurationException(createStaticMessage(format("<import> does not have a file attribute defined. At file '%s', at line %s", configFile.getFilename(), configLine.getLineNumber())));
}
return fileConfigAttribute.getValue();
}).map(value -> (String) propertyResolver.resolveValue(value)).filter(fileName -> !alreadyResolvedConfigFiles.stream().anyMatch(solvedConfigFile -> solvedConfigFile.getFilename().equals(fileName))).collect(toList()));
}
Set<String> importedConfigurationFiles = importedFiles.build();
if (importedConfigurationFiles.isEmpty()) {
return resolvedConfigFilesBuilder.build();
}
List<Pair<String, InputStream>> newConfigFilesToResolved = importedConfigurationFiles.stream().map(importedFileName -> {
InputStream resourceAsStream = muleContext.getExecutionClassLoader().getResourceAsStream(importedFileName);
if (resourceAsStream == null) {
throw new RuntimeConfigurationException(createStaticMessage(format("Could not find imported resource '%s'", importedFileName)));
}
return (Pair<String, InputStream>) new Pair(importedFileName, resourceAsStream);
}).collect(toList());
return recursivelyResolveConfigFiles(newConfigFilesToResolved, resolvedConfigFilesBuilder.build());
}
Aggregations