Search in sources :

Example 1 with ClassLoaderFilter

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

the class ContainerClassLoaderFilterFactoryTestCase method acceptsExportedSystemPackages.

@Test
public void acceptsExportedSystemPackages() throws Exception {
    final List<MuleModule> muleModules = new ArrayList<>();
    final Set<String> bootPackages = singleton("org.foo1");
    final ClassLoaderFilter classLoaderFilter = factory.create(bootPackages, muleModules);
    assertThat(classLoaderFilter.exportsClass("org.foo1.Foo"), is(true));
    assertThat(classLoaderFilter.exportsClass("org.foo1.bar.Bar"), is(true));
    assertThat(classLoaderFilter.exportsClass("org.bar.Bar"), is(false));
}
Also used : ClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.ClassLoaderFilter) ArrayList(java.util.ArrayList) MuleModule(org.mule.runtime.container.api.MuleModule) Test(org.junit.Test)

Example 2 with ClassLoaderFilter

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

the class IsolatedClassLoaderFactory method createContainerArtifactClassLoader.

/**
 * Creates an {@link ArtifactClassLoader} for the container. The difference between a mule container {@link ArtifactClassLoader}
 * in standalone mode and this one is that it has to be aware that the parent class loader has all the URLs loaded in launcher
 * app class loader so it has to create a particular look policy to resolve classes as CHILD_FIRST.
 * <p/>
 * In order to do that a {@link FilteringArtifactClassLoader} resolve is created with and empty look policy (meaning that
 * CHILD_FIRST strategy will be used) for the {@link URL}s that are going to be exposed from the container class loader. This
 * would be the parent class loader for the container so instead of going directly the launcher application class loader that
 * has access to the whole classpath this filtering class loader will resolve only the classes for the {@link URL}s defined to
 * be in the container.
 *
 * @param testContainerClassLoaderFactory {@link TestContainerClassLoaderFactory} that has the logic to create a container class
 *        loader
 * @param artifactsUrlClassification the classifications to get plugins {@link URL}s
 * @return an {@link ArtifactClassLoader} for the container
 */
protected ArtifactClassLoader createContainerArtifactClassLoader(TestContainerClassLoaderFactory testContainerClassLoaderFactory, ArtifactsUrlClassification artifactsUrlClassification) {
    MuleArtifactClassLoader launcherArtifact = createLauncherArtifactClassLoader();
    final List<MuleModule> muleModules = emptyList();
    ClassLoaderFilter filteredClassLoaderLauncher = new ContainerClassLoaderFilterFactory().create(testContainerClassLoaderFactory.getBootPackages(), muleModules);
    logClassLoaderUrls("CONTAINER", artifactsUrlClassification.getContainerUrls());
    ArtifactClassLoader containerClassLoader = testContainerClassLoaderFactory.createContainerClassLoader(new FilteringArtifactClassLoader(launcherArtifact, filteredClassLoaderLauncher, emptyList()));
    return containerClassLoader;
}
Also used : FilteringArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.FilteringArtifactClassLoader) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) DefaultArtifactClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.DefaultArtifactClassLoaderFilter) ClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.ClassLoaderFilter) ArtifactClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFilter) FilteringArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.FilteringArtifactClassLoader) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) ContainerClassLoaderFilterFactory(org.mule.runtime.container.internal.ContainerClassLoaderFilterFactory) MuleModule(org.mule.runtime.container.api.MuleModule)

Example 3 with ClassLoaderFilter

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

the class DefaultArtifactClassLoaderFilterFactoryTestCase method createsFilter.

@Test
public void createsFilter() throws Exception {
    final ClassLoaderFilter filter = factory.create("java.lang, java.lang.annotation", "META-INF/MANIFEST.MF, META-INF/xml/schema.xsd");
    assertThat(filter.exportsClass(Object.class.getName()), is(true));
    assertThat(filter.exportsClass(Annotation.class.getName()), is(true));
    assertThat(filter.exportsClass(AnnotatedElement.class.getName()), is(false));
    assertThat(filter.exportsResource("META-INF/MANIFEST.MF"), is(true));
    assertThat(filter.exportsResource("META-INF/readme.txt"), is(false));
    assertThat(filter.exportsResource("META-INF/xml/schema.xsd"), is(true));
    assertThat(filter.exportsResource("META-INF/xml/readme.txt"), is(false));
}
Also used : ClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.ClassLoaderFilter) Test(org.junit.Test)

Example 4 with ClassLoaderFilter

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

the class ContainerClassLoaderFilterFactoryTestCase method acceptsExportedModulePackages.

@Test
public void acceptsExportedModulePackages() throws Exception {
    final List<MuleModule> muleModules = new ArrayList<>();
    muleModules.add(new TestModuleBuilder("module1").exportingPackages("org.foo1", "org.foo1.bar.").exportingResources("META-INF/foo.txt", "META-INF/docs1/foo.txt").build());
    muleModules.add(new TestModuleBuilder("module2").exportingPackages("org.foo2").exportingResources("META-INF/", "/META-INF/docs2").build());
    final ClassLoaderFilter classLoaderFilter = factory.create(Collections.emptySet(), muleModules);
    assertThat(classLoaderFilter.exportsClass("org.foo1.Foo"), is(true));
    assertThat(classLoaderFilter.exportsClass("org.foo1.bar.Bar"), is(true));
    assertThat(classLoaderFilter.exportsClass("org.foo2.Foo"), is(true));
    assertThat(classLoaderFilter.exportsClass("org.bar.Bar"), is(false));
    assertThat(classLoaderFilter.exportsClass("org.foo2.bar.Bar"), is(false));
    assertThat(classLoaderFilter.exportsResource("META-INF/foo.txt"), is(true));
    assertThat(classLoaderFilter.exportsResource("META-INF/docs1/foo.txt"), is(true));
    assertThat(classLoaderFilter.exportsResource("META-INF/docs2/foo.txt"), is(true));
    assertThat(classLoaderFilter.exportsResource("/META-INF/docs2/foo.txt"), is(true));
    assertThat(classLoaderFilter.exportsResource("/foo.txt"), is(false));
}
Also used : ClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.ClassLoaderFilter) ArrayList(java.util.ArrayList) MuleModule(org.mule.runtime.container.api.MuleModule) Test(org.junit.Test)

Example 5 with ClassLoaderFilter

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

the class TestBootstrapRegistryConfigurationBuilderTestCase method createBootstrapServiceDiscovererContextBuilder.

private TestBootstrapServiceDiscovererConfigurationBuilder createBootstrapServiceDiscovererContextBuilder() {
    try {
        final ClassLoaderFilter filter = mock(ClassLoaderFilter.class);
        when(filter.exportsClass(anyString())).thenReturn(true);
        final ArtifactClassLoader pluginClassLoader1 = mock(ArtifactClassLoader.class);
        when(pluginClassLoader1.getClassLoader()).thenReturn(this.getClass().getClassLoader());
        final List<ArtifactClassLoader> artifactClassLoaders = new ArrayList<>();
        artifactClassLoaders.add(new FilteringArtifactClassLoader(pluginClassLoader1, filter, Collections.emptyList()));
        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));
        final ArtifactClassLoader appClassLoader = mock(ArtifactClassLoader.class);
        when(appClassLoader.getClassLoader()).thenReturn(this.getClass().getClassLoader());
        when(appClassLoader.findResources(BOOTSTRAP_PROPERTIES)).thenReturn(new EnumerationAdapter<>(emptyList()));
        final ClassLoader executionClassLoader = new FilteringArtifactClassLoader(appClassLoader, filter, Collections.emptyList());
        return new TestBootstrapServiceDiscovererConfigurationBuilder(getClass().getClassLoader(), executionClassLoader, artifactClassLoaders);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) FilteringArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.FilteringArtifactClassLoader) ClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.ClassLoaderFilter) ArrayList(java.util.ArrayList) FilteringArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.FilteringArtifactClassLoader) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) FilteringArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.FilteringArtifactClassLoader) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

ClassLoaderFilter (org.mule.runtime.module.artifact.api.classloader.ClassLoaderFilter)5 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 MuleModule (org.mule.runtime.container.api.MuleModule)3 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)2 FilteringArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.FilteringArtifactClassLoader)2 IOException (java.io.IOException)1 URL (java.net.URL)1 ContainerClassLoaderFilterFactory (org.mule.runtime.container.internal.ContainerClassLoaderFilterFactory)1 ArtifactClassLoaderFilter (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFilter)1 DefaultArtifactClassLoaderFilter (org.mule.runtime.module.artifact.api.classloader.DefaultArtifactClassLoaderFilter)1 MuleArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader)1