Search in sources :

Example 6 with SpiServiceRegistry

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();
    }
}
Also used : InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) ArtifactPluginDescriptorLoader(org.mule.runtime.module.deployment.impl.internal.plugin.ArtifactPluginDescriptorLoader) ArtifactPluginDescriptorFactory(org.mule.runtime.module.deployment.impl.internal.plugin.ArtifactPluginDescriptorFactory) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) File(java.io.File) ApplicationDescriptor(org.mule.runtime.deployment.model.api.application.ApplicationDescriptor) ServiceRegistryDescriptorLoaderRepository(org.mule.runtime.module.deployment.impl.internal.artifact.ServiceRegistryDescriptorLoaderRepository) Test(org.junit.Test)

Example 7 with SpiServiceRegistry

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 + "}"));
}
Also used : ExtensionModelLoader(org.mule.runtime.extension.api.loader.ExtensionModelLoader) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry)

Example 8 with SpiServiceRegistry

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);
}
Also used : EnvironmentPropertiesConfigurationProvider(org.mule.runtime.config.internal.dsl.model.config.EnvironmentPropertiesConfigurationProvider) XmlApplicationParser(org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationParser) ComponentModelReader(org.mule.runtime.config.internal.dsl.model.ComponentModelReader) ConfigLine(org.mule.runtime.config.api.dsl.processor.ConfigLine) DefaultConfigurationPropertiesResolver(org.mule.runtime.config.internal.dsl.model.config.DefaultConfigurationPropertiesResolver) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry)

Aggregations

SpiServiceRegistry (org.mule.runtime.core.api.registry.SpiServiceRegistry)8 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)3 ExtensionModelLoader (org.mule.runtime.extension.api.loader.ExtensionModelLoader)3 Map (java.util.Map)2 Optional (java.util.Optional)2 Test (org.junit.Test)2 MuleException (org.mule.runtime.api.exception.MuleException)2 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)2 XmlApplicationParser (org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationParser)2 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 String.format (java.lang.String.format)1 System.lineSeparator (java.lang.System.lineSeparator)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Optional.empty (java.util.Optional.empty)1 Optional.of (java.util.Optional.of)1