use of org.mule.runtime.module.artifact.api.classloader.ParentFirstLookupStrategy.PARENT_FIRST in project mule by mulesoft.
the class FineGrainedControlClassLoaderTestCase method usesParentFirstAndChildLookupAndFails.
@Test
public void usesParentFirstAndChildLookupAndFails() throws Exception {
ClassLoader parent = Thread.currentThread().getContextClassLoader();
final ClassLoaderLookupPolicy lookupPolicy = mock(ClassLoaderLookupPolicy.class);
when(lookupPolicy.getClassLookupStrategy(TEST_CLASS_NAME)).thenReturn(PARENT_FIRST);
expected.expect(CompositeClassNotFoundException.class);
expected.expectMessage(startsWith("Cannot load class '" + TEST_CLASS_NAME + "': ["));
FineGrainedControlClassLoader ext = buildFineGrainedControlClassLoader(parent, lookupPolicy);
expected.expect(expressionMatches((e) -> ((CompositeClassNotFoundException) e).getExceptions(), contains(hasMessage(is(TEST_CLASS_NAME)), expressionMatches((e) -> ((TestClassNotFoundException) e).getClassLoader(), is((ClassLoader) ext)))));
invokeTestClassMethod(ext);
}
use of org.mule.runtime.module.artifact.api.classloader.ParentFirstLookupStrategy.PARENT_FIRST in project mule by mulesoft.
the class PluginLookPolicyFactory method createLookupPolicy.
/**
* Creates a {@link ClassLoaderLookupPolicy} for plugins considering their dependencies.
*
* @param pluginClassification the {@link PluginUrlClassification} to creates its {@link ClassLoaderLookupPolicy}
* @param pluginClassifications whole list of {@link PluginUrlClassification} for the current context
* @param parentLookupPolicies the {@link ClassLoaderLookupPolicy} for the parent {@link ClassLoader}
* @param classLoaders
* @return {@link ClassLoaderLookupPolicy} for the plugin
*/
public ClassLoaderLookupPolicy createLookupPolicy(PluginUrlClassification pluginClassification, List<PluginUrlClassification> pluginClassifications, ClassLoaderLookupPolicy parentLookupPolicies, List<ArtifactClassLoader> classLoaders) {
Map<String, LookupStrategy> pluginsLookupPolicies = new HashMap<>();
for (PluginUrlClassification dependencyPluginClassification : pluginClassifications) {
if (dependencyPluginClassification.getArtifactId().equals(pluginClassification.getArtifactId())) {
continue;
}
if (pluginClassification.getPluginDependencies().contains(dependencyPluginClassification.getName())) {
LookupStrategy lookUpPolicyStrategy = PARENT_FIRST;
for (String exportedPackage : dependencyPluginClassification.getExportedPackages()) {
pluginsLookupPolicies.put(exportedPackage, lookUpPolicyStrategy);
}
if (isPrivilegedPluginDependency(pluginClassification, dependencyPluginClassification)) {
Optional<ArtifactClassLoader> pluginClassLoader = classLoaders.stream().filter(c -> c.getArtifactId().contains(dependencyPluginClassification.getName())).findFirst();
if (!pluginClassLoader.isPresent()) {
throw new IllegalStateException("Cannot find classloader for plugin: " + dependencyPluginClassification.getArtifactId());
}
lookUpPolicyStrategy = new DelegateOnlyLookupStrategy(pluginClassLoader.get().getClassLoader());
for (String exportedPackage : dependencyPluginClassification.getPrivilegedExportedPackages()) {
pluginsLookupPolicies.put(exportedPackage, lookUpPolicyStrategy);
}
}
}
}
return parentLookupPolicies.extend(pluginsLookupPolicies);
}
Aggregations