Search in sources :

Example 1 with ClassLoaderLookupPolicy

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

the class FineGrainedControlClassLoaderTestCase method usesChildFirstLookup.

@Test
public void usesChildFirstLookup() throws Exception {
    URLClassLoader parent = new URLClassLoader(new URL[] { getParentResource() }, Thread.currentThread().getContextClassLoader());
    final ClassLoaderLookupPolicy lookupPolicy = mock(ClassLoaderLookupPolicy.class);
    when(lookupPolicy.getClassLookupStrategy(TEST_CLASS_NAME)).thenReturn(CHILD_FIRST);
    when(lookupPolicy.getClassLookupStrategy(Object.class.getName())).thenReturn(PARENT_ONLY);
    when(lookupPolicy.getClassLookupStrategy(String.class.getName())).thenReturn(PARENT_ONLY);
    FineGrainedControlClassLoader ext = new FineGrainedControlClassLoader(new URL[] { getChildFileResource() }, parent, lookupPolicy);
    assertEquals(EXPECTED_CHILD_MESSAGE, invokeTestClassMethod(ext));
}
Also used : FineGrainedControlClassLoader(org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) URLClassLoader(java.net.URLClassLoader) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with ClassLoaderLookupPolicy

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

the class FineGrainedControlClassLoaderTestCase method usesChildFirstThenParentLookup.

@Test
public void usesChildFirstThenParentLookup() throws Exception {
    URLClassLoader parent = new URLClassLoader(new URL[] { getParentResource() }, Thread.currentThread().getContextClassLoader());
    final ClassLoaderLookupPolicy lookupPolicy = mock(ClassLoaderLookupPolicy.class);
    when(lookupPolicy.getClassLookupStrategy(TEST_CLASS_NAME)).thenReturn(PARENT_FIRST);
    FineGrainedControlClassLoader ext = new FineGrainedControlClassLoader(new URL[0], parent, lookupPolicy);
    assertEquals(EXPECTED_PARENT_MESSAGE, invokeTestClassMethod(ext));
}
Also used : FineGrainedControlClassLoader(org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) URLClassLoader(java.net.URLClassLoader) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with ClassLoaderLookupPolicy

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

the class FineGrainedControlClassLoaderTestCase method usesParentOnlyLookup.

@Test
public void usesParentOnlyLookup() throws Exception {
    URLClassLoader parent = new URLClassLoader(new URL[] { getParentResource() }, Thread.currentThread().getContextClassLoader());
    final ClassLoaderLookupPolicy lookupPolicy = mock(ClassLoaderLookupPolicy.class);
    when(lookupPolicy.getClassLookupStrategy(TEST_CLASS_NAME)).thenReturn(PARENT_ONLY);
    FineGrainedControlClassLoader ext = new FineGrainedControlClassLoader(new URL[] { getChildFileResource() }, parent, lookupPolicy);
    assertEquals(EXPECTED_PARENT_MESSAGE, invokeTestClassMethod(ext));
}
Also used : FineGrainedControlClassLoader(org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) URLClassLoader(java.net.URLClassLoader) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 4 with ClassLoaderLookupPolicy

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

the class MuleClassLoaderLookupPolicyProviderTestCase method usesChildFirstForNoConfiguredPackage.

@Test
public void usesChildFirstForNoConfiguredPackage() throws Exception {
    ClassLoaderLookupPolicy lookupPolicy = new MuleClassLoaderLookupPolicy(emptyMap(), emptySet());
    assertThat(lookupPolicy.getClassLookupStrategy(FOO_CLASS), sameInstance(CHILD_FIRST));
}
Also used : ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 5 with ClassLoaderLookupPolicy

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

the class ContainerClassLoaderFactory method createContainerClassLoader.

/**
 * Creates the classLoader to represent the Mule container.
 *
 * @param parentClassLoader parent classLoader. Can be null.
 * @return a non null {@link ArtifactClassLoader} containing container code that can be used as parent classloader for other
 *         mule artifacts.
 */
public ArtifactClassLoader createContainerClassLoader(final ClassLoader parentClassLoader) {
    final List<MuleModule> muleModules = moduleRepository.getModules();
    final ClassLoaderLookupPolicy containerLookupPolicy = getContainerClassLoaderLookupPolicy(parentClassLoader, muleModules);
    return createArtifactClassLoader(parentClassLoader, muleModules, containerLookupPolicy, new ArtifactDescriptor("mule"));
}
Also used : ArtifactDescriptor(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) MuleModule(org.mule.runtime.container.api.MuleModule)

Aggregations

ClassLoaderLookupPolicy (org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy)32 Test (org.junit.Test)19 SmallTest (org.mule.tck.size.SmallTest)16 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)12 URLClassLoader (java.net.URLClassLoader)8 FineGrainedControlClassLoader (org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader)8 URL (java.net.URL)6 HashMap (java.util.HashMap)5 ArtifactPluginDescriptor (org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor)5 LookupStrategy (org.mule.runtime.module.artifact.api.classloader.LookupStrategy)5 PARENT_FIRST (org.mule.runtime.module.artifact.api.classloader.ParentFirstLookupStrategy.PARENT_FIRST)5 RegionClassLoader (org.mule.runtime.module.artifact.api.classloader.RegionClassLoader)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 MuleModule (org.mule.runtime.container.api.MuleModule)4 ArtifactClassLoaderFilter (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFilter)4 ArtifactDescriptor (org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor)4 TestClassLoader (org.mule.tck.classlaoder.TestClassLoader)4 System.lineSeparator (java.lang.System.lineSeparator)3