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"));
}
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)));
}
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);
}
}
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;
}
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"));
}
Aggregations