Search in sources :

Example 41 with ArtifactClassLoader

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

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

the class DefaultRegionPluginClassLoadersFactoryTestCase method createsDependantPlugins.

@Test
public void createsDependantPlugins() throws Exception {
    BundleDependency pluginDependency = new BundleDependency.Builder().setScope(BundleScope.COMPILE).setDescriptor(PLUGIN1_BUNDLE_DESCRIPTOR).setBundleUri(new File("test").toURI()).build();
    plugin2Descriptor.setClassLoaderModel(new ClassLoaderModel.ClassLoaderModelBuilder().dependingOn(singleton(pluginDependency)).build());
    List<ArtifactPluginDescriptor> artifactPluginDescriptors = new ArrayList<>();
    artifactPluginDescriptors.add(plugin1Descriptor);
    artifactPluginDescriptors.add(plugin2Descriptor);
    when(regionOwnerLookupPolicy.extend(argThat(any(Map.class)))).thenReturn(pluginLookupPolicy);
    List<ArtifactClassLoader> pluginClassLoaders = factory.createPluginClassLoaders(regionClassLoader, artifactPluginDescriptors, regionOwnerLookupPolicy);
    assertThat(pluginClassLoaders, contains(pluginClassLoader1, pluginClassLoader2));
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) ArrayList(java.util.ArrayList) File(java.io.File) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) Test(org.junit.Test)

Example 43 with ArtifactClassLoader

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

the class DefaultRegionPluginClassLoadersFactoryTestCase method createsPluginWithPrivilegedPluginAccess.

@Test
public void createsPluginWithPrivilegedPluginAccess() throws Exception {
    ClassLoaderModel plugin1ClassLoaderModel = new ClassLoaderModel.ClassLoaderModelBuilder().exportingPrivilegedPackages(singleton(PRIVILEGED_PACKAGE), singleton(PLUGIN_ARTIFACT_ID2)).build();
    plugin1Descriptor.setClassLoaderModel(plugin1ClassLoaderModel);
    BundleDependency pluginDependency = new BundleDependency.Builder().setScope(BundleScope.COMPILE).setDescriptor(PLUGIN1_BUNDLE_DESCRIPTOR).setBundleUri(new File("test").toURI()).build();
    plugin2Descriptor.setClassLoaderModel(new ClassLoaderModel.ClassLoaderModelBuilder().dependingOn(singleton(pluginDependency)).build());
    List<ArtifactPluginDescriptor> artifactPluginDescriptors = new ArrayList<>();
    artifactPluginDescriptors.add(plugin1Descriptor);
    artifactPluginDescriptors.add(plugin2Descriptor);
    ArgumentCaptor<Map> argumentCaptor = forClass(Map.class);
    when(regionOwnerLookupPolicy.extend(argumentCaptor.capture())).thenReturn(pluginLookupPolicy);
    List<ArtifactClassLoader> pluginClassLoaders = factory.createPluginClassLoaders(regionClassLoader, artifactPluginDescriptors, regionOwnerLookupPolicy);
    assertThat(pluginClassLoaders, contains(pluginClassLoader1, pluginClassLoader2));
    assertThat((Map<String, LookupStrategy>) argumentCaptor.getAllValues().get(0), not(hasEntry(equalTo(PRIVILEGED_PACKAGE), instanceOf(DelegateOnlyLookupStrategy.class))));
    assertThat((Map<String, LookupStrategy>) argumentCaptor.getAllValues().get(1), hasEntry(equalTo(PRIVILEGED_PACKAGE), instanceOf(DelegateOnlyLookupStrategy.class)));
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) ArrayList(java.util.ArrayList) DelegateOnlyLookupStrategy(org.mule.runtime.module.artifact.api.classloader.DelegateOnlyLookupStrategy) File(java.io.File) Map(java.util.Map) DelegateOnlyLookupStrategy(org.mule.runtime.module.artifact.api.classloader.DelegateOnlyLookupStrategy) ContainerOnlyLookupStrategy(org.mule.runtime.container.internal.ContainerOnlyLookupStrategy) LookupStrategy(org.mule.runtime.module.artifact.api.classloader.LookupStrategy) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) Test(org.junit.Test)

Example 44 with ArtifactClassLoader

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

the class PolicyTemplateClassLoaderFactoryTestCase method createsEmptyClassLoader.

@Test
public void createsEmptyClassLoader() throws Exception {
    final ArtifactClassLoader artifactClassLoader = factory.create(POLICY_ID, parentClassLoader, descriptor, emptyList());
    final MuleArtifactClassLoader classLoader = (MuleArtifactClassLoader) artifactClassLoader.getClassLoader();
    assertThat(classLoader.getURLs(), equalTo(new URL[0]));
}
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) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) URL(java.net.URL) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 45 with ArtifactClassLoader

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

the class PolicyTemplateClassLoaderFactoryTestCase method usesClassLoaderLookupPolicy.

@Test
public void usesClassLoaderLookupPolicy() throws Exception {
    final ArtifactClassLoader artifactClassLoader = factory.create(POLICY_ID, parentClassLoader, descriptor, emptyList());
    final MuleArtifactClassLoader classLoader = (MuleArtifactClassLoader) artifactClassLoader.getClassLoader();
    final String className = "com.dummy.Foo";
    try {
        classLoader.loadClass(className);
        fail("Able to load an un-existent class");
    } catch (ClassNotFoundException e) {
    // Expected
    }
    verify(lookupPolicy).getClassLookupStrategy(className);
}
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) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) Matchers.anyString(org.mockito.Matchers.anyString) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)58 Test (org.junit.Test)30 ArrayList (java.util.ArrayList)17 URL (java.net.URL)12 ClassLoaderLookupPolicy (org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy)12 Pair (org.mule.runtime.api.util.Pair)10 ArtifactPluginDescriptor (org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor)10 MuleArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader)10 Service (org.mule.runtime.api.service.Service)8 SmallTest (org.mule.tck.size.SmallTest)8 LookupStrategy (org.mule.runtime.module.artifact.api.classloader.LookupStrategy)7 Map (java.util.Map)6 RegionClassLoader (org.mule.runtime.module.artifact.api.classloader.RegionClassLoader)6 File (java.io.File)5 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)5 List (java.util.List)5 MuleModule (org.mule.runtime.container.api.MuleModule)5 ContainerOnlyLookupStrategy (org.mule.runtime.container.internal.ContainerOnlyLookupStrategy)5 HashSet (java.util.HashSet)4