use of org.mule.runtime.core.api.registry.SpiServiceRegistry in project mule by mulesoft.
the class PropertyOverridesTestCase method testOverrides.
@Test
public void testOverrides() throws Exception {
File tempProps = File.createTempFile("property", "overrides");
InputStream input = getClass().getClassLoader().getResourceAsStream("overridden.properties");
FileOutputStream output = new FileOutputStream(tempProps);
copy(input, output);
input.close();
output.close();
ApplicationDescriptor descriptor = new ApplicationDescriptor("app");
ApplicationDescriptorFactory applicationDescriptorFactory = new ApplicationDescriptorFactory(new ArtifactPluginDescriptorLoader(new ArtifactPluginDescriptorFactory()), new ServiceRegistryDescriptorLoaderRepository(new SpiServiceRegistry()), ArtifactDescriptorValidatorBuilder.builder());
applicationDescriptorFactory.setApplicationProperties(descriptor, tempProps);
Map<String, String> appProps = descriptor.getAppProperties();
assertEquals("state", appProps.get("texas"));
assertEquals("country", appProps.get("peru"));
assertEquals("austin", appProps.get("texas.capital"));
assertEquals("4", appProps.get("peru.capital.numberOfletters"));
assertEquals("runtime", appProps.get("mule"));
assertEquals("ipaas", appProps.get("mule.ion"));
try {
setSystemProperties();
descriptor = new ApplicationDescriptor("app");
applicationDescriptorFactory.setApplicationProperties(descriptor, tempProps);
appProps = descriptor.getAppProperties();
assertEquals("state", appProps.get("texas"));
assertEquals("nation", appProps.get("peru"));
assertEquals("austin", appProps.get("texas.capital"));
assertEquals("4", appProps.get("peru.capital.numberOfletters"));
assertEquals("wayCool", appProps.get("mule"));
assertEquals("ipaas", appProps.get("mule.ion"));
assertEquals("evenCooler", appProps.get("mule.mmc"));
descriptor = new ApplicationDescriptor("app");
applicationDescriptorFactory.setApplicationProperties(descriptor, new File("nonexistent.nonexistent"));
appProps = descriptor.getAppProperties();
assertNull(appProps.get("texas"));
assertEquals("nation", appProps.get("peru"));
assertNull(appProps.get("texas.capital"));
assertNull(appProps.get("peru.capital.numberOfletters"));
assertEquals("wayCool", appProps.get("mule"));
assertNull(appProps.get("mule.ion"));
assertEquals("evenCooler", appProps.get("mule.mmc"));
} finally {
resetSystemProperties();
}
}
use of org.mule.runtime.core.api.registry.SpiServiceRegistry in project mule by mulesoft.
the class ExtensionLoaderUtils method getLoaderById.
public static ExtensionModelLoader getLoaderById(String id) {
final SpiServiceRegistry spiServiceRegistry = new SpiServiceRegistry();
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final Collection<ExtensionModelLoader> extensionModelLoaders = spiServiceRegistry.lookupProviders(ExtensionModelLoader.class, classLoader);
return extensionModelLoaders.stream().filter(extensionModelLoader -> extensionModelLoader.getId().equals(id)).findAny().orElseThrow(() -> new RuntimeException("No loader found for id:{" + id + "}"));
}
use of org.mule.runtime.core.api.registry.SpiServiceRegistry 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);
}
Aggregations