Search in sources :

Example 1 with MuleModule

use of org.mule.runtime.container.api.MuleModule in project mule by mulesoft.

the class ClasspathModuleDiscovererTestCase method discoversModuleWithExportedJavaPackages.

@Test
public void discoversModuleWithExportedJavaPackages() throws Exception {
    List<URL> moduleProperties = new ArrayList();
    moduleProperties.add(getClass().getClassLoader().getResource("moduleJavaPackages.properties"));
    when(classLoader.getResources(ClasspathModuleDiscoverer.MODULE_PROPERTIES)).thenReturn(new EnumerationAdapter(moduleProperties));
    List<MuleModule> muleModules = moduleDiscoverer.discover();
    assertThat(muleModules, hasSize(1));
    MuleModule muleModule = muleModules.get(0);
    assertThat(muleModule.getName(), is("moduleJavaPackages"));
    assertThat(muleModule.getExportedPackages(), contains("org.foo", "org.bar"));
    assertThat(muleModule.getExportedPaths(), is(empty()));
    assertThat(muleModule.getPrivilegedExportedPackages(), is(empty()));
    assertThat(muleModule.getPrivilegedArtifacts(), is(empty()));
    assertThat(muleModule.getExportedServices(), is(empty()));
}
Also used : ArrayList(java.util.ArrayList) EnumerationAdapter(org.mule.runtime.core.internal.util.EnumerationAdapter) URL(java.net.URL) MuleModule(org.mule.runtime.container.api.MuleModule) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 2 with MuleModule

use of org.mule.runtime.container.api.MuleModule in project mule by mulesoft.

the class CompositeModuleDiscovererTestCase method delegatesToComposedDiscovers.

@Test
public void delegatesToComposedDiscovers() throws Exception {
    final ModuleDiscoverer discoverer1 = mock(ModuleDiscoverer.class);
    MuleModule module1 = new MuleModule("module1", emptySet(), emptySet(), emptySet(), emptySet(), emptyList());
    final List<MuleModule> modules1 = new ArrayList<>();
    modules1.add(module1);
    when(discoverer1.discover()).thenReturn(modules1);
    MuleModule module2 = new MuleModule("module1", emptySet(), emptySet(), emptySet(), emptySet(), emptyList());
    final List<MuleModule> modules2 = new ArrayList<>();
    modules2.add(module2);
    final ModuleDiscoverer discoverer2 = mock(ModuleDiscoverer.class);
    when(discoverer2.discover()).thenReturn(modules2);
    final CompositeModuleDiscoverer composite = new CompositeModuleDiscoverer(discoverer1, discoverer2);
    final List<MuleModule> discovered = composite.discover();
    assertThat(discovered.size(), equalTo(2));
    assertThat(discovered, contains(module1, module2));
}
Also used : ArrayList(java.util.ArrayList) MuleModule(org.mule.runtime.container.api.MuleModule) Test(org.junit.Test)

Example 3 with MuleModule

use of org.mule.runtime.container.api.MuleModule 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 4 with MuleModule

use of org.mule.runtime.container.api.MuleModule in project mule by mulesoft.

the class JreModuleDiscovererTestCase method discoversJreModule.

@Test
public void discoversJreModule() throws Exception {
    final List<MuleModule> muleModules = moduleDiscoverer.discover();
    assertThat(muleModules.size(), equalTo(1));
    final MuleModule muleModule = muleModules.get(0);
    assertThat(muleModule.getName(), equalTo(JRE_MODULE_NAME));
    assertThat(muleModule.getExportedPaths(), is(not(empty())));
    assertThat(muleModule.getExportedPackages(), is(not(empty())));
    assertThat(muleModule.getExportedServices(), is(not(empty())));
}
Also used : MuleModule(org.mule.runtime.container.api.MuleModule) Test(org.junit.Test)

Example 5 with MuleModule

use of org.mule.runtime.container.api.MuleModule in project mule by mulesoft.

the class ContainerClassLoaderFactory method buildClassLoaderLookupStrategy.

/**
 * Creates a {@link Map<String, LookupStrategy>} for the packages exported on the container.
 *
 * @param containerClassLoader class loader containing container's classes. Non null.
 * @param modules to be used for collecting the exported packages. Non null
 * @return a {@link Map<String, LookupStrategy>} for the packages exported on the container
 */
private Map<String, LookupStrategy> buildClassLoaderLookupStrategy(ClassLoader containerClassLoader, List<MuleModule> modules) {
    checkArgument(containerClassLoader != null, "containerClassLoader cannot be null");
    checkArgument(modules != null, "modules cannot be null");
    ContainerOnlyLookupStrategy containerOnlyLookupStrategy = new ContainerOnlyLookupStrategy(containerClassLoader);
    final Map<String, LookupStrategy> result = new HashMap<>();
    for (MuleModule muleModule : modules) {
        for (String exportedPackage : muleModule.getExportedPackages()) {
            // Lets artifacts to extend javax packages
            result.put(exportedPackage, exportedPackage.startsWith("javax.") ? PARENT_FIRST : containerOnlyLookupStrategy);
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) LookupStrategy(org.mule.runtime.module.artifact.api.classloader.LookupStrategy) MuleModule(org.mule.runtime.container.api.MuleModule)

Aggregations

MuleModule (org.mule.runtime.container.api.MuleModule)21 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)11 URL (java.net.URL)5 EnumerationAdapter (org.mule.runtime.core.internal.util.EnumerationAdapter)5 SmallTest (org.mule.tck.size.SmallTest)5 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)4 LookupStrategy (org.mule.runtime.module.artifact.api.classloader.LookupStrategy)4 HashMap (java.util.HashMap)3 ModuleRepository (org.mule.runtime.container.api.ModuleRepository)3 ContainerOnlyLookupStrategy (org.mule.runtime.container.internal.ContainerOnlyLookupStrategy)3 ClassLoaderFilter (org.mule.runtime.module.artifact.api.classloader.ClassLoaderFilter)3 ClassLoaderLookupPolicy (org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy)3 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 ArtifactPluginDescriptor (org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor)2 DelegateOnlyLookupStrategy (org.mule.runtime.module.artifact.api.classloader.DelegateOnlyLookupStrategy)2 ArtifactDescriptor (org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor)2 IOException (java.io.IOException)1