Search in sources :

Example 46 with ArtifactClassLoader

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));
}
Also used : ToolingPluginClassLoaderBuilder.getPluginArtifactClassLoader(org.mule.runtime.deployment.model.internal.tooling.ToolingPluginClassLoaderBuilder.getPluginArtifactClassLoader) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) ArtifactClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFilter) Test(org.junit.Test)

Example 47 with ArtifactClassLoader

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;
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) LinkedList(java.util.LinkedList)

Example 48 with ArtifactClassLoader

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);
}
Also used : ModuleRepository(org.mule.runtime.container.api.ModuleRepository) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) DelegateOnlyLookupStrategy(org.mule.runtime.module.artifact.api.classloader.DelegateOnlyLookupStrategy) CHILD_ONLY(org.mule.runtime.module.artifact.api.classloader.ChildOnlyLookupStrategy.CHILD_ONLY) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) Set(java.util.Set) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) 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) MuleModule(org.mule.runtime.container.api.MuleModule) Collectors.toList(java.util.stream.Collectors.toList) MULE_PLUGIN_CLASSIFIER(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor.MULE_PLUGIN_CLASSIFIER) List(java.util.List) ArtifactClassLoaderFactory(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFactory) Map(java.util.Map) Optional(java.util.Optional) ContainerOnlyLookupStrategy(org.mule.runtime.container.internal.ContainerOnlyLookupStrategy) LinkedList(java.util.LinkedList) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) HashMap(java.util.HashMap) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) ContainerOnlyLookupStrategy(org.mule.runtime.container.internal.ContainerOnlyLookupStrategy) MuleModule(org.mule.runtime.container.api.MuleModule) DelegateOnlyLookupStrategy(org.mule.runtime.module.artifact.api.classloader.DelegateOnlyLookupStrategy) DelegateOnlyLookupStrategy(org.mule.runtime.module.artifact.api.classloader.DelegateOnlyLookupStrategy) LookupStrategy(org.mule.runtime.module.artifact.api.classloader.LookupStrategy) ContainerOnlyLookupStrategy(org.mule.runtime.container.internal.ContainerOnlyLookupStrategy)

Example 49 with ArtifactClassLoader

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;
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)

Example 50 with ArtifactClassLoader

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;
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy)

Aggregations

ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)58 Test (org.junit.Test)30 ArrayList (java.util.ArrayList)17 URL (java.net.URL)12 ClassLoaderLookupPolicy (org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy)12 Pair (org.mule.runtime.api.util.Pair)10 ArtifactPluginDescriptor (org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor)10 MuleArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader)10 Service (org.mule.runtime.api.service.Service)8 SmallTest (org.mule.tck.size.SmallTest)8 LookupStrategy (org.mule.runtime.module.artifact.api.classloader.LookupStrategy)7 Map (java.util.Map)6 RegionClassLoader (org.mule.runtime.module.artifact.api.classloader.RegionClassLoader)6 File (java.io.File)5 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)5 List (java.util.List)5 MuleModule (org.mule.runtime.container.api.MuleModule)5 ContainerOnlyLookupStrategy (org.mule.runtime.container.internal.ContainerOnlyLookupStrategy)5 HashSet (java.util.HashSet)4