Search in sources :

Example 6 with MuleModule

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

Example 7 with MuleModule

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

the class DefaultRegionPluginClassLoadersFactoryTestCase method createsPluginWithPrivilegedContainerAccess.

@Test
public void createsPluginWithPrivilegedContainerAccess() throws Exception {
    MuleModule privilegedModule = mock(MuleModule.class);
    when(privilegedModule.getPrivilegedArtifacts()).thenReturn(singleton(PLUGIN_ARTIFACT_ID1));
    when(privilegedModule.getPrivilegedExportedPackages()).thenReturn(singleton(PRIVILEGED_PACKAGE));
    when(moduleRepository.getModules()).thenReturn(singletonList(privilegedModule));
    List<ArtifactPluginDescriptor> artifactPluginDescriptors = singletonList(plugin1Descriptor);
    ArgumentCaptor<Map> mapArgumentCaptor = forClass(Map.class);
    when(regionOwnerLookupPolicy.extend(mapArgumentCaptor.capture())).thenReturn(pluginLookupPolicy);
    List<ArtifactClassLoader> pluginClassLoaders = factory.createPluginClassLoaders(regionClassLoader, artifactPluginDescriptors, regionOwnerLookupPolicy);
    assertThat(pluginClassLoaders, contains(pluginClassLoader1));
    Map<String, LookupStrategy> value = mapArgumentCaptor.getValue();
    assertThat(value, hasEntry(equalTo(PRIVILEGED_PACKAGE), instanceOf(ContainerOnlyLookupStrategy.class)));
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) 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) MuleModule(org.mule.runtime.container.api.MuleModule) Test(org.junit.Test)

Example 8 with MuleModule

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

the class IsolatedClassLoaderFactory method extendLookupPolicyForPrivilegedAccess.

private ClassLoaderLookupPolicy extendLookupPolicyForPrivilegedAccess(ClassLoaderLookupPolicy childClassLoaderLookupPolicy, ModuleRepository moduleRepository, TestContainerClassLoaderFactory testContainerClassLoaderFactory, PluginUrlClassification pluginUrlClassification) {
    ContainerOnlyLookupStrategy containerOnlyLookupStrategy = new ContainerOnlyLookupStrategy(testContainerClassLoaderFactory.getContainerClassLoader().getClassLoader());
    Map<String, LookupStrategy> privilegedLookupStrategies = new HashMap<>();
    for (MuleModule module : moduleRepository.getModules()) {
        if (hasPrivilegedApiAccess(pluginUrlClassification, module)) {
            for (String packageName : module.getPrivilegedExportedPackages()) {
                privilegedLookupStrategies.put(packageName, containerOnlyLookupStrategy);
            }
        }
    }
    if (privilegedLookupStrategies.isEmpty()) {
        return childClassLoaderLookupPolicy;
    } else {
        return childClassLoaderLookupPolicy.extend(privilegedLookupStrategies);
    }
}
Also used : HashMap(java.util.HashMap) ContainerOnlyLookupStrategy(org.mule.runtime.container.internal.ContainerOnlyLookupStrategy) LookupStrategy(org.mule.runtime.module.artifact.api.classloader.LookupStrategy) ChildFirstLookupStrategy(org.mule.runtime.module.artifact.api.classloader.ChildFirstLookupStrategy) ContainerOnlyLookupStrategy(org.mule.runtime.container.internal.ContainerOnlyLookupStrategy) MuleModule(org.mule.runtime.container.api.MuleModule)

Example 9 with MuleModule

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

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

the class TestContainerClassLoaderFactory method createContainerClassLoader.

/**
 * Overrides method due to it has to use the {@link ClassLoader} set to this factory in order to discover modules.
 *
 * @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.
 */
@Override
public ArtifactClassLoader createContainerClassLoader(final ClassLoader parentClassLoader) {
    final List<MuleModule> muleModules = withContextClassLoader(classLoader, () -> testContainerModuleRepository.getModules());
    MuleClassLoaderLookupPolicy lookupPolicy = new MuleClassLoaderLookupPolicy(Collections.emptyMap(), getBootPackages());
    return createArtifactClassLoader(parentClassLoader, muleModules, lookupPolicy, new ArtifactDescriptor("mule"));
}
Also used : MuleClassLoaderLookupPolicy(org.mule.runtime.container.internal.MuleClassLoaderLookupPolicy) ArtifactDescriptor(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor) 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