use of org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy in project mule by mulesoft.
the class AbstractToolingClassLoaderTestCase method createAppClassLoader.
@Before
public void createAppClassLoader() {
final ClassLoaderLookupPolicy classLoaderLookupPolicy = mock(ClassLoaderLookupPolicy.class);
// Mandatory to find a resource releaser instance when doing the dispose of a RegionClassLoader
when(classLoaderLookupPolicy.getClassLookupStrategy(anyString())).thenReturn(PARENT_FIRST);
regionClassLoader = new RegionClassLoader(TEST_REGION, new ArtifactDescriptor(REGION_NAME), getClass().getClassLoader(), classLoaderLookupPolicy);
// Loading the additional classloader as the ToolingPluginClassLoaderBuilder does
regionClassLoader.addClassLoader(mock(ArtifactClassLoader.class), mock(ArtifactClassLoaderFilter.class));
artifactPluginDescriptor = new ArtifactPluginDescriptor(PLUGIN_NAME);
pluginArtifactClassLoader = spy(new TestToolingPluginClassLoader(artifactPluginDescriptor));
}
use of org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy in project mule by mulesoft.
the class DefaultPolicyTemplateFactoryTestCase method createRegionClassLoader.
private RegionClassLoader createRegionClassLoader() {
ClassLoaderLookupPolicy lookupPolicy = mock(ClassLoaderLookupPolicy.class);
RegionClassLoader regionClassLoader = new RegionClassLoader(descriptor.getName(), descriptor, this.getClass().getClassLoader(), lookupPolicy);
// Adds the owner of the region
ArtifactClassLoader regionOwnerClassLoader = mock(ArtifactClassLoader.class);
regionClassLoader.addClassLoader(regionOwnerClassLoader, NULL_CLASSLOADER_FILTER);
return regionClassLoader;
}
use of org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy in project mule by mulesoft.
the class DefaultApplicationFactoryTestCase method createDomain.
private Domain createDomain(String name) {
final Domain domain = mock(Domain.class);
final ArtifactClassLoader domainArtifactClassLoader = mock(ArtifactClassLoader.class);
when(domainArtifactClassLoader.getClassLoader()).thenReturn(mock(ClassLoader.class));
final ClassLoaderLookupPolicy domainLookupPolicy = mock(ClassLoaderLookupPolicy.class);
when(domainArtifactClassLoader.getClassLoaderLookupPolicy()).thenReturn(domainLookupPolicy);
when(domainRepository.getDomain(DOMAIN_ARTIFACT_FILE_NAME)).thenReturn(domain);
when(domain.getArtifactClassLoader()).thenReturn(domainArtifactClassLoader);
when(domain.getDescriptor()).thenReturn(new DomainDescriptor(name));
return domain;
}
use of org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy in project mule by mulesoft.
the class AbstractArtifactClassLoaderBuilder method build.
/**
* Creates a new {@code ArtifactClassLoader} using the provided configuration. It will create the proper class loader hierarchy
* and filters the artifact resources and plugins classes and resources are resolve correctly.
*
* @return a {@code ArtifactClassLoader} created from the provided configuration.
* @throws IOException exception cause when it was not possible to access the file provided as dependencies
*/
public ArtifactClassLoader build() throws IOException {
checkState(artifactDescriptor != null, "artifact descriptor cannot be null");
parentClassLoader = getParentClassLoader();
checkState(parentClassLoader != null, "parent class loader cannot be null");
final String artifactId = getArtifactId(artifactDescriptor);
ClassLoaderLookupPolicy parentLookupPolicy = getParentLookupPolicy(parentClassLoader);
RegionClassLoader regionClassLoader = new RegionClassLoader(artifactId, artifactDescriptor, parentClassLoader.getClassLoader(), parentLookupPolicy);
ArtifactClassLoaderFilter artifactClassLoaderFilter = createArtifactClassLoaderFilter(artifactDescriptor.getClassLoaderModel(), parentLookupPolicy);
Map<String, LookupStrategy> appAdditionalLookupStrategy = new HashMap<>();
artifactClassLoaderFilter.getExportedClassPackages().stream().forEach(p -> appAdditionalLookupStrategy.put(p, PARENT_FIRST));
artifactPluginClassLoaders = pluginClassLoadersFactory.createPluginClassLoaders(regionClassLoader, artifactPluginDescriptors, regionClassLoader.getClassLoaderLookupPolicy().extend(appAdditionalLookupStrategy));
final ArtifactClassLoader artifactClassLoader = createArtifactClassLoader(artifactId, regionClassLoader);
regionClassLoader.addClassLoader(artifactClassLoader, artifactClassLoaderFilter);
int artifactPluginIndex = 0;
for (ArtifactPluginDescriptor artifactPluginDescriptor : artifactPluginDescriptors) {
final ArtifactClassLoaderFilter classLoaderFilter = createPluginClassLoaderFilter(artifactPluginDescriptor, artifactDescriptor.getClassLoaderModel().getExportedPackages(), parentLookupPolicy);
regionClassLoader.addClassLoader(artifactPluginClassLoaders.get(artifactPluginIndex), classLoaderFilter);
artifactPluginIndex++;
}
return artifactClassLoader;
}
use of org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy in project mule by mulesoft.
the class IsolatedClassLoaderFactory method createTestRunnerPlugin.
private void createTestRunnerPlugin(ArtifactsUrlClassification artifactsUrlClassification, Map<String, LookupStrategy> appExportedLookupStrategies, ClassLoaderLookupPolicy childClassLoaderLookupPolicy, RegionClassLoader regionClassLoader, List<ArtifactClassLoader> filteredPluginsArtifactClassLoaders, List<ArtifactClassLoader> pluginsArtifactClassLoaders, List<ArtifactClassLoaderFilter> pluginArtifactClassLoaderFilters, DefaultModuleRepository moduleRepository, TestContainerClassLoaderFactory testContainerClassLoaderFactory, Set<String> parentExportedPackages) {
JarInfo testRunnerJarInfo = getTestRunnerJarInfo(artifactsUrlClassification);
String testRunnerArtifactId = getArtifactPluginId(regionClassLoader.getArtifactId(), "test-runner");
List<String> pluginDependencies = artifactsUrlClassification.getPluginUrlClassifications().stream().map(p -> p.getName()).collect(toList());
PluginUrlClassification testRunnerPluginClassification = new PluginUrlClassification(TEST_RUNNER_ARTIFACT_ID + ":", artifactsUrlClassification.getTestRunnerLibUrls(), emptyList(), pluginDependencies, testRunnerJarInfo.getPackages(), testRunnerJarInfo.getResources(), emptySet(), emptySet());
ClassLoaderLookupPolicy pluginLookupPolicy = extendLookupPolicyForPrivilegedAccess(childClassLoaderLookupPolicy, moduleRepository, testContainerClassLoaderFactory, testRunnerPluginClassification);
pluginLookupPolicy = pluginLookupPolicy.extend(appExportedLookupStrategies);
MuleArtifactClassLoader pluginCL = new MuleArtifactClassLoader(testRunnerArtifactId, new ArtifactDescriptor(testRunnerPluginClassification.getName()), testRunnerPluginClassification.getUrls().toArray(new URL[0]), regionClassLoader, pluginLookupPolicyGenerator.createLookupPolicy(testRunnerPluginClassification, artifactsUrlClassification.getPluginUrlClassifications(), pluginLookupPolicy, pluginsArtifactClassLoaders));
pluginsArtifactClassLoaders.add(pluginCL);
ArtifactClassLoaderFilter filter = createArtifactClassLoaderFilter(testRunnerPluginClassification, parentExportedPackages, childClassLoaderLookupPolicy);
pluginArtifactClassLoaderFilters.add(filter);
filteredPluginsArtifactClassLoaders.add(new FilteringArtifactClassLoader(pluginCL, filter, emptyList()));
logClassLoaderUrls("PLUGIN (" + testRunnerPluginClassification.getName() + ")", testRunnerPluginClassification.getUrls());
}
Aggregations