use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor 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.deployment.model.api.plugin.ArtifactPluginDescriptor 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.deployment.model.api.plugin.ArtifactPluginDescriptor 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.deployment.model.api.plugin.ArtifactPluginDescriptor in project mule by mulesoft.
the class ApplicationClassLoaderBuilder method getParentLookupPolicy.
@Override
protected ClassLoaderLookupPolicy getParentLookupPolicy(ArtifactClassLoader parentClassLoader) {
Map<String, LookupStrategy> lookupStrategies = new HashMap<>();
DomainDescriptor descriptor = parentClassLoader.getArtifactDescriptor();
descriptor.getClassLoaderModel().getExportedPackages().forEach(p -> lookupStrategies.put(p, PARENT_FIRST));
for (ArtifactPluginDescriptor artifactPluginDescriptor : descriptor.getPlugins()) {
artifactPluginDescriptor.getClassLoaderModel().getExportedPackages().forEach(p -> lookupStrategies.put(p, PARENT_FIRST));
}
return parentClassLoader.getClassLoaderLookupPolicy().extend(lookupStrategies);
}
use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor in project mule by mulesoft.
the class BundlePluginDependenciesResolver method resolvePluginsDependencies.
private List<ArtifactPluginDescriptor> resolvePluginsDependencies(List<ArtifactPluginDescriptor> descriptors) {
Set<BundleDescriptor> knownPlugins = descriptors.stream().map(ArtifactPluginDescriptor::getBundleDescriptor).collect(toSet());
descriptors = getArtifactsWithDependencies(descriptors, knownPlugins);
List<ArtifactPluginDescriptor> sortedDescriptors = new ArrayList<>(descriptors);
sortedDescriptors.sort((d1, d2) -> (d1.getName().compareTo(d2.getName())));
List<ArtifactPluginDescriptor> resolvedPlugins = new LinkedList<>();
List<ArtifactPluginDescriptor> unresolvedPlugins = new LinkedList<>(sortedDescriptors);
boolean continueResolution = true;
while (continueResolution) {
int initialResolvedCount = resolvedPlugins.size();
List<ArtifactPluginDescriptor> pendingUnresolvedPlugins = new LinkedList<>();
for (ArtifactPluginDescriptor unresolvedPlugin : unresolvedPlugins) {
if (isResolvedPlugin(unresolvedPlugin, resolvedPlugins)) {
sanitizeExportedPackages(unresolvedPlugin, resolvedPlugins);
resolvedPlugins.add(unresolvedPlugin);
} else {
pendingUnresolvedPlugins.add(unresolvedPlugin);
}
}
// Will try to resolve the plugins that are still unresolved
unresolvedPlugins = pendingUnresolvedPlugins;
continueResolution = resolvedPlugins.size() > initialResolvedCount;
}
if (unresolvedPlugins.size() != 0) {
throw new PluginResolutionError(createResolutionErrorMessage(unresolvedPlugins, resolvedPlugins));
}
return resolvedPlugins;
}
Aggregations