Search in sources :

Example 11 with LookupStrategy

use of org.mule.runtime.module.artifact.api.classloader.LookupStrategy 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);
}
Also used : HashMap(java.util.HashMap) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) LookupStrategy(org.mule.runtime.module.artifact.api.classloader.LookupStrategy) DomainDescriptor(org.mule.runtime.deployment.model.api.domain.DomainDescriptor)

Example 12 with LookupStrategy

use of org.mule.runtime.module.artifact.api.classloader.LookupStrategy 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);
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) PluginUrlClassification(org.mule.test.runner.api.PluginUrlClassification) List(java.util.List) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) DelegateOnlyLookupStrategy(org.mule.runtime.module.artifact.api.classloader.DelegateOnlyLookupStrategy) Map(java.util.Map) Optional(java.util.Optional) LookupStrategy(org.mule.runtime.module.artifact.api.classloader.LookupStrategy) HashMap(java.util.HashMap) PARENT_FIRST(org.mule.runtime.module.artifact.api.classloader.ParentFirstLookupStrategy.PARENT_FIRST) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) HashMap(java.util.HashMap) DelegateOnlyLookupStrategy(org.mule.runtime.module.artifact.api.classloader.DelegateOnlyLookupStrategy) PluginUrlClassification(org.mule.test.runner.api.PluginUrlClassification) DelegateOnlyLookupStrategy(org.mule.runtime.module.artifact.api.classloader.DelegateOnlyLookupStrategy) LookupStrategy(org.mule.runtime.module.artifact.api.classloader.LookupStrategy)

Aggregations

LookupStrategy (org.mule.runtime.module.artifact.api.classloader.LookupStrategy)12 HashMap (java.util.HashMap)9 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)7 ContainerOnlyLookupStrategy (org.mule.runtime.container.internal.ContainerOnlyLookupStrategy)6 ArtifactPluginDescriptor (org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor)6 Map (java.util.Map)5 MuleModule (org.mule.runtime.container.api.MuleModule)5 ClassLoaderLookupPolicy (org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy)5 ChildFirstLookupStrategy (org.mule.runtime.module.artifact.api.classloader.ChildFirstLookupStrategy)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ArtifactClassLoaderFilter (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFilter)3 DefaultArtifactClassLoaderFilter (org.mule.runtime.module.artifact.api.classloader.DefaultArtifactClassLoaderFilter)3 DelegateOnlyLookupStrategy (org.mule.runtime.module.artifact.api.classloader.DelegateOnlyLookupStrategy)3 RegionClassLoader (org.mule.runtime.module.artifact.api.classloader.RegionClassLoader)3 PluginUrlClassification (org.mule.test.runner.api.PluginUrlClassification)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 File (java.io.File)2 URL (java.net.URL)2 Optional (java.util.Optional)2