Search in sources :

Example 11 with RegionClassLoader

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

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

the class ToolingPluginClassLoaderBuilder method build.

@Override
public ToolingArtifactClassLoader build() throws IOException {
    setArtifactDescriptor(new ArtifactDescriptor(TOOLING_EXTENSION_MODEL));
    List<ArtifactPluginDescriptor> resolvedArtifactPluginDescriptors = pluginDependenciesResolver.resolve(emptySet(), ImmutableList.<ArtifactPluginDescriptor>builder().add(artifactPluginDescriptor).build());
    this.addArtifactPluginDescriptors(resolvedArtifactPluginDescriptors.toArray(new ArtifactPluginDescriptor[resolvedArtifactPluginDescriptors.size()]));
    ArtifactClassLoader ownerArtifactClassLoader = super.build();
    ClassLoader parent = ownerArtifactClassLoader.getClassLoader().getParent();
    if (!(parent instanceof RegionClassLoader)) {
        throw new DeploymentException(createStaticMessage(format("The parent of the current owner must be of type '%s' but found '%s'", RegionClassLoader.class.getName(), parent.getClass().getName())));
    }
    final RegionClassLoader regionClassLoader = (RegionClassLoader) parent;
    return new ToolingArtifactClassLoader(regionClassLoader, getPluginArtifactClassLoader(artifactPluginDescriptor, regionClassLoader.getArtifactPluginClassLoaders()));
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ArtifactDescriptor(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader) DisposableClassLoader(org.mule.runtime.module.artifact.api.classloader.DisposableClassLoader) DeploymentException(org.mule.runtime.deployment.model.api.DeploymentException) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader)

Example 13 with RegionClassLoader

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

the class ArtifactAwareContextSelectorTestCase method returnsParentContextForPolicyClassloader.

@Test
public void returnsParentContextForPolicyClassloader() throws MalformedURLException {
    ClassLoader childClassLoader = new URLClassLoader(new URL[0], regionClassLoader);
    PolicyTemplateDescriptor policyTemplateDescriptor = new PolicyTemplateDescriptor(POLICY_TEMPLATE_NAME, empty());
    RegionClassLoader policyRegionClassLoader = spy(getPolicyRegionClassLoader(policyTemplateDescriptor));
    MuleArtifactClassLoader policyClassLoader = getPolicyArtifactClassLoader(policyTemplateDescriptor, policyRegionClassLoader);
    LoggerContext appCtx = selector.getContext("", childClassLoader, true);
    LoggerContext policyCtx = selector.getContext("", policyClassLoader, true);
    assertThat(policyCtx, sameInstance(appCtx));
}
Also used : URLClassLoader(java.net.URLClassLoader) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) URLClassLoader(java.net.URLClassLoader) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) PolicyTemplateDescriptor(org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor) LoggerContext(org.apache.logging.log4j.core.LoggerContext) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

RegionClassLoader (org.mule.runtime.module.artifact.api.classloader.RegionClassLoader)13 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)10 Test (org.junit.Test)5 ClassLoaderLookupPolicy (org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy)5 SmallTest (org.mule.tck.size.SmallTest)5 ArtifactClassLoaderFilter (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFilter)4 MuleArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader)4 ArtifactDescriptor (org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor)4 HashMap (java.util.HashMap)3 DeploymentException (org.mule.runtime.deployment.model.api.DeploymentException)3 ArtifactPluginDescriptor (org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor)3 ChildFirstLookupStrategy (org.mule.runtime.module.artifact.api.classloader.ChildFirstLookupStrategy)3 DefaultArtifactClassLoaderFilter (org.mule.runtime.module.artifact.api.classloader.DefaultArtifactClassLoaderFilter)3 LookupStrategy (org.mule.runtime.module.artifact.api.classloader.LookupStrategy)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2 ArrayList (java.util.ArrayList)2 ContainerClassLoaderFactory (org.mule.runtime.container.internal.ContainerClassLoaderFactory)2 ContainerOnlyLookupStrategy (org.mule.runtime.container.internal.ContainerOnlyLookupStrategy)2