Search in sources :

Example 1 with MuleDeployableArtifactClassLoader

use of org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader 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 MuleDeployableArtifactClassLoader

use of org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader in project mule by mulesoft.

the class PolicyTemplateClassLoaderFactoryTestCase method createsClassLoaderWithPlugins.

@Test
public void createsClassLoaderWithPlugins() throws Exception {
    ArtifactClassLoader pluginClassLoader1 = mock(ArtifactClassLoader.class);
    ArtifactClassLoader pluginClassLoader2 = mock(ArtifactClassLoader.class);
    List<ArtifactClassLoader> artifactPluginClassLoaders = new ArrayList<>();
    artifactPluginClassLoaders.add(pluginClassLoader1);
    artifactPluginClassLoaders.add(pluginClassLoader2);
    final ArtifactClassLoader artifactClassLoader = factory.create(POLICY_ID, parentClassLoader, descriptor, artifactPluginClassLoaders);
    final MuleDeployableArtifactClassLoader classLoader = (MuleDeployableArtifactClassLoader) artifactClassLoader.getClassLoader();
    assertThat(classLoader.getArtifactPluginClassLoaders(), contains(pluginClassLoader1, pluginClassLoader2));
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) MuleDeployableArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) MuleDeployableArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader) ArrayList(java.util.ArrayList) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with MuleDeployableArtifactClassLoader

use of org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader 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 MuleDeployableArtifactClassLoader

use of org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader in project mule by mulesoft.

the class DefaultPolicyTemplateFactoryTestCase method createsPolicyTemplate.

@Test
public void createsPolicyTemplate() throws Exception {
    RegionClassLoader regionClassLoader = createRegionClassLoader();
    PolicyTemplateClassLoaderBuilder policyTemplateClassLoaderBuilder = createPolicyTemplateClassLoaderBuilder(regionClassLoader);
    MuleDeployableArtifactClassLoader policyClassLoader = mock(MuleDeployableArtifactClassLoader.class);
    when(policyClassLoader.getArtifactId()).thenReturn(POLICY_ID);
    when(policyTemplateClassLoaderBuilder.build()).thenReturn(policyClassLoader);
    when(classLoaderBuilderFactory.createArtifactClassLoaderBuilder()).thenReturn(policyTemplateClassLoaderBuilder);
    PolicyTemplate policyTemplate = policyTemplateFactory.createArtifact(createApplication(regionClassLoader), descriptor);
    assertThat(policyTemplate.getArtifactClassLoader(), is(policyClassLoader));
    assertThat(policyTemplate.getDescriptor(), is(descriptor));
    assertThat(policyTemplate.getArtifactId(), is(POLICY_ID));
    assertThat(regionClassLoader.getArtifactPluginClassLoaders().size(), equalTo(1));
}
Also used : MuleDeployableArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader) PolicyTemplateClassLoaderBuilder(org.mule.runtime.deployment.model.internal.policy.PolicyTemplateClassLoaderBuilder) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader) PolicyTemplate(org.mule.runtime.deployment.model.api.policy.PolicyTemplate) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 5 with MuleDeployableArtifactClassLoader

use of org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader in project mule by mulesoft.

the class DefaultPolicyTemplateFactory method createArtifact.

@Override
public PolicyTemplate createArtifact(Application application, PolicyTemplateDescriptor descriptor) {
    MuleDeployableArtifactClassLoader policyClassLoader;
    List<ArtifactPluginDescriptor> resolvedPolicyPluginsDescriptors = resolvePolicyPluginDescriptors(application, descriptor);
    try {
        policyClassLoader = policyTemplateClassLoaderBuilderFactory.createArtifactClassLoaderBuilder().addArtifactPluginDescriptors(resolvedPolicyPluginsDescriptors.toArray(new ArtifactPluginDescriptor[resolvedPolicyPluginsDescriptors.size()])).setParentClassLoader(application.getRegionClassLoader()).setArtifactDescriptor(descriptor).build();
    } catch (IOException e) {
        throw new PolicyTemplateCreationException(createPolicyTemplateCreationErrorMessage(descriptor.getName()), e);
    }
    application.getRegionClassLoader().addClassLoader(policyClassLoader, NULL_CLASSLOADER_FILTER);
    List<ArtifactPlugin> artifactPlugins = createArtifactPluginList(policyClassLoader, resolvedPolicyPluginsDescriptors);
    validateArtifactLicense(policyClassLoader.getClassLoader(), artifactPlugins, licenseValidator);
    DefaultPolicyTemplate policy = new DefaultPolicyTemplate(policyClassLoader.getArtifactId(), descriptor, policyClassLoader, artifactPlugins);
    return policy;
}
Also used : ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) MuleDeployableArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader) IOException(java.io.IOException) ArtifactPlugin(org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin) DefaultArtifactPlugin(org.mule.runtime.module.deployment.impl.internal.plugin.DefaultArtifactPlugin)

Aggregations

MuleDeployableArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader)6 ArtifactPlugin (org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin)3 ArtifactPluginDescriptor (org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor)3 DefaultArtifactPlugin (org.mule.runtime.module.deployment.impl.internal.plugin.DefaultArtifactPlugin)3 Test (org.junit.Test)2 Domain (org.mule.runtime.deployment.model.api.domain.Domain)2 SmallTest (org.mule.tck.size.SmallTest)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 DomainDescriptor (org.mule.runtime.deployment.model.api.domain.DomainDescriptor)1 PolicyTemplate (org.mule.runtime.deployment.model.api.policy.PolicyTemplate)1 ApplicationClassLoaderBuilder (org.mule.runtime.deployment.model.internal.application.ApplicationClassLoaderBuilder)1 DomainClassLoaderBuilder (org.mule.runtime.deployment.model.internal.domain.DomainClassLoaderBuilder)1 PolicyTemplateClassLoaderBuilder (org.mule.runtime.deployment.model.internal.policy.PolicyTemplateClassLoaderBuilder)1 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)1 ClassLoaderLookupPolicy (org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy)1