Search in sources :

Example 1 with ArtifactPlugin

use of org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin in project mule by mulesoft.

the class DefaultDomainFactory method doCreateArtifact.

@Override
protected Domain doCreateArtifact(File domainLocation, Optional<Properties> deploymentProperties) throws IOException {
    String domainName = domainLocation.getName();
    Domain domain = domainManager.getDomain(domainName);
    if (domain != null) {
        throw new IllegalArgumentException(format("Domain '%s'  already exists", domainName));
    }
    if (domainName.contains(" ")) {
        throw new IllegalArgumentException("Mule domain name may not contain spaces: " + domainName);
    }
    DomainDescriptor domainDescriptor = findDomain(domainName, domainLocation, deploymentProperties);
    List<ArtifactPluginDescriptor> resolvedArtifactPluginDescriptors = pluginDependenciesResolver.resolve(emptySet(), domainDescriptor.getPlugins().stream().collect(toList()));
    DomainClassLoaderBuilder artifactClassLoaderBuilder = domainClassLoaderBuilderFactory.createArtifactClassLoaderBuilder();
    MuleDeployableArtifactClassLoader domainClassLoader = artifactClassLoaderBuilder.addArtifactPluginDescriptors(resolvedArtifactPluginDescriptors.toArray(new ArtifactPluginDescriptor[resolvedArtifactPluginDescriptors.size()])).setArtifactId(domainDescriptor.getName()).setArtifactDescriptor(domainDescriptor).build();
    List<ArtifactPlugin> artifactPlugins = createArtifactPluginList(domainClassLoader, resolvedArtifactPluginDescriptors);
    DefaultMuleDomain defaultMuleDomain = new DefaultMuleDomain(domainDescriptor, domainClassLoader, classLoaderRepository, serviceRepository, artifactPlugins, extensionModelLoaderManager);
    DomainWrapper domainWrapper = new DomainWrapper(defaultMuleDomain, this);
    domainManager.addDomain(domainWrapper);
    return domainWrapper;
}
Also used : ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) MuleDeployableArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader) DomainClassLoaderBuilder(org.mule.runtime.deployment.model.internal.domain.DomainClassLoaderBuilder) Domain(org.mule.runtime.deployment.model.api.domain.Domain) DomainDescriptor(org.mule.runtime.deployment.model.api.domain.DomainDescriptor) DefaultArtifactPlugin(org.mule.runtime.module.deployment.impl.internal.plugin.DefaultArtifactPlugin) ArtifactPlugin(org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin)

Example 2 with ArtifactPlugin

use of org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin in project mule by mulesoft.

the class ArtifactBootstrapRegistryConfigurationBuilderTestCase method createBootstrapServiceDiscovererContextBuilder.

private ArtifactBootstrapServiceDiscovererConfigurationBuilder createBootstrapServiceDiscovererContextBuilder() {
    try {
        ArtifactPlugin plugin1 = mock(ArtifactPlugin.class);
        final ArtifactClassLoader pluginClassLoader1 = mock(ArtifactClassLoader.class);
        when(plugin1.getArtifactClassLoader()).thenReturn(pluginClassLoader1);
        final List<ArtifactPlugin> artifactPlugins = new ArrayList<>();
        artifactPlugins.add(plugin1);
        final List<URL> urls = new ArrayList<>();
        urls.add(this.getClass().getResource("/plugin1-bootstrap.properties"));
        urls.add(this.getClass().getResource("/plugin2-bootstrap.properties"));
        when(pluginClassLoader1.findResources(BOOTSTRAP_PROPERTIES)).thenReturn(new EnumerationAdapter<>(urls));
        return new ArtifactBootstrapServiceDiscovererConfigurationBuilder(artifactPlugins);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URL(java.net.URL) ArtifactPlugin(org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin)

Example 3 with ArtifactPlugin

use of org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin in project mule by mulesoft.

the class DefaultApplicationFactory method createArtifact.

public Application createArtifact(ApplicationDescriptor descriptor) throws IOException {
    Domain domain = getApplicationDomain(descriptor);
    List<ArtifactPluginDescriptor> resolvedArtifactPluginDescriptors = pluginDependenciesResolver.resolve(domain.getDescriptor().getPlugins(), new ArrayList<>(getArtifactPluginDescriptors(descriptor)));
    // Refreshes the list of plugins on the descriptor with the resolved from domain and transitive plugin dependencies
    Set resolvedArtifactPlugins = new LinkedHashSet<>();
    resolvedArtifactPlugins.addAll(resolvedArtifactPluginDescriptors);
    descriptor.setPlugins(resolvedArtifactPlugins);
    ApplicationClassLoaderBuilder artifactClassLoaderBuilder = applicationClassLoaderBuilderFactory.createArtifactClassLoaderBuilder();
    MuleDeployableArtifactClassLoader applicationClassLoader = artifactClassLoaderBuilder.setDomain(domain).addArtifactPluginDescriptors(resolvedArtifactPluginDescriptors.toArray(new ArtifactPluginDescriptor[0])).setArtifactId(descriptor.getName()).setArtifactDescriptor(descriptor).build();
    List<ArtifactPlugin> artifactPlugins = createArtifactPluginList(applicationClassLoader, resolvedArtifactPluginDescriptors);
    MuleApplicationPolicyProvider applicationPolicyProvider = new MuleApplicationPolicyProvider(new DefaultPolicyTemplateFactory(policyTemplateClassLoaderBuilderFactory, pluginDependenciesResolver, licenseValidator), new DefaultPolicyInstanceProviderFactory(serviceRepository, classLoaderRepository, extensionModelLoaderRepository));
    DefaultMuleApplication delegate = new DefaultMuleApplication(descriptor, applicationClassLoader, artifactPlugins, domainRepository, serviceRepository, extensionModelLoaderRepository, descriptor.getArtifactLocation(), classLoaderRepository, applicationPolicyProvider);
    applicationPolicyProvider.setApplication(delegate);
    return new ApplicationWrapper(delegate);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) ApplicationClassLoaderBuilder(org.mule.runtime.deployment.model.internal.application.ApplicationClassLoaderBuilder) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) DefaultPolicyInstanceProviderFactory(org.mule.runtime.module.deployment.impl.internal.policy.DefaultPolicyInstanceProviderFactory) MuleDeployableArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader) Domain(org.mule.runtime.deployment.model.api.domain.Domain) DefaultPolicyTemplateFactory(org.mule.runtime.module.deployment.impl.internal.policy.DefaultPolicyTemplateFactory) DefaultArtifactPlugin(org.mule.runtime.module.deployment.impl.internal.plugin.DefaultArtifactPlugin) ArtifactPlugin(org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin)

Example 4 with ArtifactPlugin

use of org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin in project mule by mulesoft.

the class ArtifactBootstrapServiceDiscovererConfigurationBuilder method doConfigure.

@Override
protected void doConfigure(MuleContext muleContext) throws Exception {
    final PropertiesBootstrapServiceDiscoverer propertiesBootstrapServiceDiscoverer = new PropertiesBootstrapServiceDiscoverer(this.getClass().getClassLoader());
    List<BootstrapService> bootstrapServices = new LinkedList<>();
    bootstrapServices.addAll(propertiesBootstrapServiceDiscoverer.discover());
    for (ArtifactPlugin artifactPlugin : artifactPlugins) {
        final Enumeration<URL> resources = artifactPlugin.getArtifactClassLoader().findResources(BOOTSTRAP_PROPERTIES);
        while (resources.hasMoreElements()) {
            final URL localResource = resources.nextElement();
            final Properties properties = PropertiesUtils.loadProperties(localResource);
            final BootstrapService pluginBootstrapService = new PropertiesBootstrapService(artifactPlugin.getArtifactClassLoader().getClassLoader(), properties);
            bootstrapServices.add(pluginBootstrapService);
        }
    }
    muleContext.setBootstrapServiceDiscoverer(() -> bootstrapServices);
}
Also used : PropertiesBootstrapServiceDiscoverer(org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapServiceDiscoverer) PropertiesBootstrapService(org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapService) Properties(java.util.Properties) LinkedList(java.util.LinkedList) URL(java.net.URL) BootstrapService(org.mule.runtime.core.api.config.bootstrap.BootstrapService) PropertiesBootstrapService(org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapService) ArtifactPlugin(org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin)

Example 5 with ArtifactPlugin

use of org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin in project mule by mulesoft.

the class DefaultApplicationFactoryTestCase method createsApplication.

@Test
public void createsApplication() throws Exception {
    final ApplicationDescriptor descriptor = new ApplicationDescriptor(APP_NAME);
    descriptor.setClassLoaderModel(createClassLoaderModelWithDomain());
    final File[] resourceFiles = new File[] { new File("mule-config.xml") };
    when(applicationDescriptorFactory.create(any(), any())).thenReturn(descriptor);
    final ArtifactPluginDescriptor coreArtifactPluginDescriptor = new ArtifactPluginDescriptor(FAKE_ARTIFACT_PLUGIN);
    coreArtifactPluginDescriptor.setClassLoaderModel(new ClassLoaderModel.ClassLoaderModelBuilder().build());
    final ArtifactPlugin appPlugin = mock(ArtifactPlugin.class);
    final ArtifactClassLoader artifactClassLoader = mock(ArtifactClassLoader.class);
    when(appPlugin.getArtifactClassLoader()).thenReturn(artifactClassLoader);
    when(artifactClassLoader.getArtifactId()).thenReturn(FAKE_ARTIFACT_PLUGIN);
    when(appPlugin.getDescriptor()).thenReturn(coreArtifactPluginDescriptor);
    final Domain domain = createDomain(DOMAIN_NAME);
    final ClassLoaderLookupPolicy sharedLibLookupPolicy = mock(ClassLoaderLookupPolicy.class);
    when(domain.getArtifactClassLoader().getClassLoaderLookupPolicy().extend(anyMap())).thenReturn(sharedLibLookupPolicy);
    final MuleApplicationClassLoader applicationArtifactClassLoader = mock(MuleApplicationClassLoader.class);
    when(applicationArtifactClassLoader.getArtifactId()).thenReturn(APP_ID);
    ApplicationClassLoaderBuilder applicationClassLoaderBuilderMock = mock(ApplicationClassLoaderBuilder.class);
    when(applicationClassLoaderBuilderMock.setDomain(any())).thenReturn(applicationClassLoaderBuilderMock);
    when(applicationClassLoaderBuilderMock.setArtifactDescriptor(any())).thenReturn(applicationClassLoaderBuilderMock);
    when(applicationClassLoaderBuilderMock.setArtifactId(any())).thenReturn(applicationClassLoaderBuilderMock);
    when(applicationClassLoaderBuilderMock.addArtifactPluginDescriptors(descriptor.getPlugins().toArray(new ArtifactPluginDescriptor[0]))).thenReturn(applicationClassLoaderBuilderMock);
    when(applicationClassLoaderBuilderMock.build()).thenReturn(applicationArtifactClassLoader);
    when(applicationClassLoaderBuilderFactory.createArtifactClassLoaderBuilder()).thenReturn(applicationClassLoaderBuilderMock);
    List<ArtifactClassLoader> pluginClassLoaders = new ArrayList<>();
    pluginClassLoaders.add(artifactClassLoader);
    when(applicationArtifactClassLoader.getArtifactPluginClassLoaders()).thenReturn(pluginClassLoaders);
    final Application application = applicationFactory.createArtifact(new File(APP_NAME), empty());
    assertThat(application.getDomain(), is(domain));
    assertThat(application.getArtifactClassLoader(), is(applicationArtifactClassLoader));
    assertThat(application.getDescriptor(), is(descriptor));
    assertThat(application.getArtifactName(), is(APP_NAME));
    assertThat(application.getResourceFiles(), is(resourceFiles));
    verify(domainRepository, times(2)).getDomain(DOMAIN_ARTIFACT_FILE_NAME);
    verify(applicationClassLoaderBuilderMock).setDomain(domain);
    verify(applicationClassLoaderBuilderMock).addArtifactPluginDescriptors(descriptor.getPlugins().toArray(new ArtifactPluginDescriptor[0]));
    verify(applicationClassLoaderBuilderMock).setArtifactDescriptor(descriptor);
    verify(applicationClassLoaderBuilderMock).setArtifactId(APP_NAME);
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ApplicationClassLoaderBuilder(org.mule.runtime.deployment.model.internal.application.ApplicationClassLoaderBuilder) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) ArrayList(java.util.ArrayList) ApplicationDescriptor(org.mule.runtime.deployment.model.api.application.ApplicationDescriptor) Domain(org.mule.runtime.deployment.model.api.domain.Domain) MuleApplicationClassLoader(org.mule.runtime.deployment.model.internal.application.MuleApplicationClassLoader) File(java.io.File) Application(org.mule.runtime.deployment.model.api.application.Application) ArtifactPlugin(org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin) Test(org.junit.Test)

Aggregations

ArtifactPlugin (org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin)6 ArtifactPluginDescriptor (org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor)4 Domain (org.mule.runtime.deployment.model.api.domain.Domain)3 MuleDeployableArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader)3 DefaultArtifactPlugin (org.mule.runtime.module.deployment.impl.internal.plugin.DefaultArtifactPlugin)3 IOException (java.io.IOException)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 ApplicationClassLoaderBuilder (org.mule.runtime.deployment.model.internal.application.ApplicationClassLoaderBuilder)2 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)2 File (java.io.File)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 Set (java.util.Set)1 Test (org.junit.Test)1 BootstrapService (org.mule.runtime.core.api.config.bootstrap.BootstrapService)1 PropertiesBootstrapService (org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapService)1 PropertiesBootstrapServiceDiscoverer (org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapServiceDiscoverer)1