use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.
the class ToolingPluginClassLoaderBuilderTestCase method findArtifactClassLoaderByArtifactId.
@Test
public void findArtifactClassLoaderByArtifactId() {
TestToolingPluginClassLoader anotherPluginClassLoader = new TestToolingPluginClassLoader(new ArtifactPluginDescriptor("test-another-plugin-descriptor"));
regionClassLoader.addClassLoader(anotherPluginClassLoader, mock(ArtifactClassLoaderFilter.class));
regionClassLoader.addClassLoader(pluginArtifactClassLoader, mock(ArtifactClassLoaderFilter.class));
ArtifactClassLoader pluginArtifactClassLoader = getPluginArtifactClassLoader(artifactPluginDescriptor, regionClassLoader.getArtifactPluginClassLoaders());
assertThat(pluginArtifactClassLoader, CoreMatchers.sameInstance(pluginArtifactClassLoader));
}
use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.
the class DefaultRegionPluginClassLoadersFactory method createPluginClassLoaders.
@Override
public List<ArtifactClassLoader> createPluginClassLoaders(ArtifactClassLoader regionClassLoader, List<ArtifactPluginDescriptor> artifactPluginDescriptors, ClassLoaderLookupPolicy regionOwnerLookupPolicy) {
List<ArtifactClassLoader> classLoaders = new LinkedList<>();
for (ArtifactPluginDescriptor artifactPluginDescriptor : artifactPluginDescriptors) {
final String pluginArtifactId = getArtifactPluginId(regionClassLoader.getArtifactId(), artifactPluginDescriptor.getName());
ClassLoaderLookupPolicy pluginLookupPolicy = createPluginLookupPolicy(classLoaders, artifactPluginDescriptor, regionOwnerLookupPolicy, artifactPluginDescriptors);
final ArtifactClassLoader artifactClassLoader = artifactPluginClassLoaderFactory.create(pluginArtifactId, artifactPluginDescriptor, regionClassLoader.getClassLoader(), pluginLookupPolicy);
classLoaders.add(artifactClassLoader);
}
return classLoaders;
}
use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.
the class DefaultRegionPluginClassLoadersFactory method createPluginLookupPolicy.
private ClassLoaderLookupPolicy createPluginLookupPolicy(List<ArtifactClassLoader> classLoaders, ArtifactPluginDescriptor descriptor, ClassLoaderLookupPolicy baseLookupPolicy, List<ArtifactPluginDescriptor> artifactPluginDescriptors) {
Map<String, LookupStrategy> pluginsLookupPolicies = new HashMap<>();
List<ArtifactPluginDescriptor> pluginDescriptors = getPluginDescriptors(descriptor, artifactPluginDescriptors);
for (ArtifactPluginDescriptor dependencyPluginDescriptor : pluginDescriptors) {
if (dependencyPluginDescriptor.getName().equals(descriptor.getName())) {
continue;
}
LookupStrategy lookupStrategy = getClassLoaderLookupStrategy(descriptor, dependencyPluginDescriptor);
for (String exportedPackage : dependencyPluginDescriptor.getClassLoaderModel().getExportedPackages()) {
pluginsLookupPolicies.put(exportedPackage, lookupStrategy);
}
if (isPrivilegedPluginDependency(descriptor, dependencyPluginDescriptor)) {
Optional<ArtifactClassLoader> pluginClassLoader = classLoaders.stream().filter(c -> c.getArtifactDescriptor().getBundleDescriptor().getArtifactId().equals(dependencyPluginDescriptor.getBundleDescriptor().getArtifactId())).findFirst();
if (!pluginClassLoader.isPresent()) {
throw new IllegalStateException("Cannot find classloader for plugin: " + dependencyPluginDescriptor.getBundleDescriptor().getArtifactId());
}
lookupStrategy = new DelegateOnlyLookupStrategy(pluginClassLoader.get().getClassLoader());
for (String exportedPackage : dependencyPluginDescriptor.getClassLoaderModel().getPrivilegedExportedPackages()) {
pluginsLookupPolicies.put(exportedPackage, lookupStrategy);
}
}
}
ContainerOnlyLookupStrategy containerOnlyLookupStrategy = new ContainerOnlyLookupStrategy(this.getClass().getClassLoader());
for (MuleModule module : moduleRepository.getModules()) {
if (module.getPrivilegedArtifacts().contains(descriptor.getBundleDescriptor().getGroupId() + ":" + descriptor.getBundleDescriptor().getArtifactId())) {
for (String packageName : module.getPrivilegedExportedPackages()) {
pluginsLookupPolicies.put(packageName, containerOnlyLookupStrategy);
}
}
}
return baseLookupPolicy.extend(pluginsLookupPolicies);
}
use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.
the class DomainClassLoaderFactory method create.
@Override
public ArtifactClassLoader create(String artifactId, ArtifactClassLoader parent, DomainDescriptor descriptor, List<ArtifactClassLoader> artifactClassLoaders) {
String domainId = getDomainId(descriptor.getName());
ArtifactClassLoader domainClassLoader = domainArtifactClassLoaders.get(domainId);
if (domainClassLoader != null) {
return domainClassLoader;
} else {
synchronized (this) {
domainClassLoader = domainArtifactClassLoaders.get(domainId);
if (domainClassLoader == null) {
if (descriptor.getName().equals(DEFAULT_DOMAIN_NAME)) {
domainClassLoader = getDefaultDomainClassLoader(parent.getClassLoaderLookupPolicy());
} else {
domainClassLoader = getCustomDomainClassLoader(parent, descriptor, artifactClassLoaders);
}
domainArtifactClassLoaders.put(domainId, domainClassLoader);
}
}
}
return domainClassLoader;
}
use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.
the class DomainClassLoaderFactory method getCustomDomainClassLoader.
private ArtifactClassLoader getCustomDomainClassLoader(ArtifactClassLoader parent, DomainDescriptor domain, List<ArtifactClassLoader> artifactClassLoaders) {
validateDomain(domain);
final ClassLoaderLookupPolicy classLoaderLookupPolicy = getApplicationClassLoaderLookupPolicy(parent, domain);
ArtifactClassLoader classLoader = new MuleSharedDomainClassLoader(domain, parent.getClassLoader(), classLoaderLookupPolicy, Arrays.asList(domain.getClassLoaderModel().getUrls()), artifactClassLoaders);
return classLoader;
}
Aggregations