Search in sources :

Example 6 with ClassLoaderLookupPolicy

use of org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy in project mule by mulesoft.

the class AbstractToolingClassLoaderTestCase method createAppClassLoader.

@Before
public void createAppClassLoader() {
    final ClassLoaderLookupPolicy classLoaderLookupPolicy = mock(ClassLoaderLookupPolicy.class);
    // Mandatory to find a resource releaser instance when doing the dispose of a RegionClassLoader
    when(classLoaderLookupPolicy.getClassLookupStrategy(anyString())).thenReturn(PARENT_FIRST);
    regionClassLoader = new RegionClassLoader(TEST_REGION, new ArtifactDescriptor(REGION_NAME), getClass().getClassLoader(), classLoaderLookupPolicy);
    // Loading the additional classloader as the ToolingPluginClassLoaderBuilder does
    regionClassLoader.addClassLoader(mock(ArtifactClassLoader.class), mock(ArtifactClassLoaderFilter.class));
    artifactPluginDescriptor = new ArtifactPluginDescriptor(PLUGIN_NAME);
    pluginArtifactClassLoader = spy(new TestToolingPluginClassLoader(artifactPluginDescriptor));
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) TestArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.TestArtifactClassLoader) ArtifactDescriptor(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader) ArtifactClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFilter) Before(org.junit.Before)

Example 7 with ClassLoaderLookupPolicy

use of org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy in project mule by mulesoft.

the class DefaultPolicyTemplateFactoryTestCase method createRegionClassLoader.

private RegionClassLoader createRegionClassLoader() {
    ClassLoaderLookupPolicy lookupPolicy = mock(ClassLoaderLookupPolicy.class);
    RegionClassLoader regionClassLoader = new RegionClassLoader(descriptor.getName(), descriptor, this.getClass().getClassLoader(), lookupPolicy);
    // Adds the owner of the region
    ArtifactClassLoader regionOwnerClassLoader = mock(ArtifactClassLoader.class);
    regionClassLoader.addClassLoader(regionOwnerClassLoader, NULL_CLASSLOADER_FILTER);
    return regionClassLoader;
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) MuleDeployableArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader)

Example 8 with ClassLoaderLookupPolicy

use of org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy in project mule by mulesoft.

the class DefaultApplicationFactoryTestCase method createDomain.

private Domain createDomain(String name) {
    final Domain domain = mock(Domain.class);
    final ArtifactClassLoader domainArtifactClassLoader = mock(ArtifactClassLoader.class);
    when(domainArtifactClassLoader.getClassLoader()).thenReturn(mock(ClassLoader.class));
    final ClassLoaderLookupPolicy domainLookupPolicy = mock(ClassLoaderLookupPolicy.class);
    when(domainArtifactClassLoader.getClassLoaderLookupPolicy()).thenReturn(domainLookupPolicy);
    when(domainRepository.getDomain(DOMAIN_ARTIFACT_FILE_NAME)).thenReturn(domain);
    when(domain.getArtifactClassLoader()).thenReturn(domainArtifactClassLoader);
    when(domain.getDescriptor()).thenReturn(new DomainDescriptor(name));
    return domain;
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) MuleApplicationClassLoader(org.mule.runtime.deployment.model.internal.application.MuleApplicationClassLoader) Domain(org.mule.runtime.deployment.model.api.domain.Domain) DomainDescriptor(org.mule.runtime.deployment.model.api.domain.DomainDescriptor)

Example 9 with ClassLoaderLookupPolicy

use of org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy in project mule by mulesoft.

the class AbstractArtifactClassLoaderBuilder method build.

/**
 * Creates a new {@code ArtifactClassLoader} using the provided configuration. It will create the proper class loader hierarchy
 * and filters the artifact resources and plugins classes and resources are resolve correctly.
 *
 * @return a {@code ArtifactClassLoader} created from the provided configuration.
 * @throws IOException exception cause when it was not possible to access the file provided as dependencies
 */
public ArtifactClassLoader build() throws IOException {
    checkState(artifactDescriptor != null, "artifact descriptor cannot be null");
    parentClassLoader = getParentClassLoader();
    checkState(parentClassLoader != null, "parent class loader cannot be null");
    final String artifactId = getArtifactId(artifactDescriptor);
    ClassLoaderLookupPolicy parentLookupPolicy = getParentLookupPolicy(parentClassLoader);
    RegionClassLoader regionClassLoader = new RegionClassLoader(artifactId, artifactDescriptor, parentClassLoader.getClassLoader(), parentLookupPolicy);
    ArtifactClassLoaderFilter artifactClassLoaderFilter = createArtifactClassLoaderFilter(artifactDescriptor.getClassLoaderModel(), parentLookupPolicy);
    Map<String, LookupStrategy> appAdditionalLookupStrategy = new HashMap<>();
    artifactClassLoaderFilter.getExportedClassPackages().stream().forEach(p -> appAdditionalLookupStrategy.put(p, PARENT_FIRST));
    artifactPluginClassLoaders = pluginClassLoadersFactory.createPluginClassLoaders(regionClassLoader, artifactPluginDescriptors, regionClassLoader.getClassLoaderLookupPolicy().extend(appAdditionalLookupStrategy));
    final ArtifactClassLoader artifactClassLoader = createArtifactClassLoader(artifactId, regionClassLoader);
    regionClassLoader.addClassLoader(artifactClassLoader, artifactClassLoaderFilter);
    int artifactPluginIndex = 0;
    for (ArtifactPluginDescriptor artifactPluginDescriptor : artifactPluginDescriptors) {
        final ArtifactClassLoaderFilter classLoaderFilter = createPluginClassLoaderFilter(artifactPluginDescriptor, artifactDescriptor.getClassLoaderModel().getExportedPackages(), parentLookupPolicy);
        regionClassLoader.addClassLoader(artifactPluginClassLoaders.get(artifactPluginIndex), classLoaderFilter);
        artifactPluginIndex++;
    }
    return artifactClassLoader;
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) HashMap(java.util.HashMap) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader) DefaultArtifactClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.DefaultArtifactClassLoaderFilter) ArtifactClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFilter) LookupStrategy(org.mule.runtime.module.artifact.api.classloader.LookupStrategy) ChildFirstLookupStrategy(org.mule.runtime.module.artifact.api.classloader.ChildFirstLookupStrategy)

Example 10 with ClassLoaderLookupPolicy

use of org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy in project mule by mulesoft.

the class IsolatedClassLoaderFactory method createTestRunnerPlugin.

private void createTestRunnerPlugin(ArtifactsUrlClassification artifactsUrlClassification, Map<String, LookupStrategy> appExportedLookupStrategies, ClassLoaderLookupPolicy childClassLoaderLookupPolicy, RegionClassLoader regionClassLoader, List<ArtifactClassLoader> filteredPluginsArtifactClassLoaders, List<ArtifactClassLoader> pluginsArtifactClassLoaders, List<ArtifactClassLoaderFilter> pluginArtifactClassLoaderFilters, DefaultModuleRepository moduleRepository, TestContainerClassLoaderFactory testContainerClassLoaderFactory, Set<String> parentExportedPackages) {
    JarInfo testRunnerJarInfo = getTestRunnerJarInfo(artifactsUrlClassification);
    String testRunnerArtifactId = getArtifactPluginId(regionClassLoader.getArtifactId(), "test-runner");
    List<String> pluginDependencies = artifactsUrlClassification.getPluginUrlClassifications().stream().map(p -> p.getName()).collect(toList());
    PluginUrlClassification testRunnerPluginClassification = new PluginUrlClassification(TEST_RUNNER_ARTIFACT_ID + ":", artifactsUrlClassification.getTestRunnerLibUrls(), emptyList(), pluginDependencies, testRunnerJarInfo.getPackages(), testRunnerJarInfo.getResources(), emptySet(), emptySet());
    ClassLoaderLookupPolicy pluginLookupPolicy = extendLookupPolicyForPrivilegedAccess(childClassLoaderLookupPolicy, moduleRepository, testContainerClassLoaderFactory, testRunnerPluginClassification);
    pluginLookupPolicy = pluginLookupPolicy.extend(appExportedLookupStrategies);
    MuleArtifactClassLoader pluginCL = new MuleArtifactClassLoader(testRunnerArtifactId, new ArtifactDescriptor(testRunnerPluginClassification.getName()), testRunnerPluginClassification.getUrls().toArray(new URL[0]), regionClassLoader, pluginLookupPolicyGenerator.createLookupPolicy(testRunnerPluginClassification, artifactsUrlClassification.getPluginUrlClassifications(), pluginLookupPolicy, pluginsArtifactClassLoaders));
    pluginsArtifactClassLoaders.add(pluginCL);
    ArtifactClassLoaderFilter filter = createArtifactClassLoaderFilter(testRunnerPluginClassification, parentExportedPackages, childClassLoaderLookupPolicy);
    pluginArtifactClassLoaderFilters.add(filter);
    filteredPluginsArtifactClassLoaders.add(new FilteringArtifactClassLoader(pluginCL, filter, emptyList()));
    logClassLoaderUrls("PLUGIN (" + testRunnerPluginClassification.getName() + ")", testRunnerPluginClassification.getUrls());
}
Also used : TEST_RUNNER_ARTIFACT_ID(org.mule.test.runner.RunnerConfiguration.TEST_RUNNER_ARTIFACT_ID) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) PARENT_FIRST(org.mule.runtime.module.artifact.api.classloader.ParentFirstLookupStrategy.PARENT_FIRST) MuleModule(org.mule.runtime.container.api.MuleModule) DefaultArtifactClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.DefaultArtifactClassLoaderFilter) FileUtils.toFile(org.apache.commons.io.FileUtils.toFile) ContainerClassLoaderFilterFactory(org.mule.runtime.container.internal.ContainerClassLoaderFilterFactory) FilteringArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.FilteringArtifactClassLoader) ClassLoaderFilterFactory(org.mule.runtime.module.artifact.api.classloader.ClassLoaderFilterFactory) Map(java.util.Map) System.getProperty(java.lang.System.getProperty) JarExplorer(org.mule.runtime.module.artifact.internal.util.JarExplorer) URI(java.net.URI) MULE_LOG_VERBOSE_CLASSLOADING(org.mule.runtime.core.api.config.MuleProperties.MULE_LOG_VERBOSE_CLASSLOADING) Collectors.toSet(java.util.stream.Collectors.toSet) ArtifactClassLoaderHolder(org.mule.test.runner.api.ArtifactClassLoaderHolder) ClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.ClassLoaderFilter) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) Collections.emptyList(java.util.Collections.emptyList) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader) Collection(java.util.Collection) Set(java.util.Set) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) LookupStrategy(org.mule.runtime.module.artifact.api.classloader.LookupStrategy) DefaultModuleRepository(org.mule.runtime.container.internal.DefaultModuleRepository) Collectors.joining(java.util.stream.Collectors.joining) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) JarInfo(org.mule.runtime.module.artifact.internal.util.JarInfo) ChildFirstLookupStrategy(org.mule.runtime.module.artifact.api.classloader.ChildFirstLookupStrategy) ModuleRepository(org.mule.runtime.container.api.ModuleRepository) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) FileJarExplorer(org.mule.runtime.module.artifact.internal.util.FileJarExplorer) DefaultNativeLibraryFinderFactory(org.mule.runtime.deployment.model.internal.nativelib.DefaultNativeLibraryFinderFactory) ArtifactUrlClassification(org.mule.test.runner.api.ArtifactUrlClassification) ContainerClassLoaderFactory(org.mule.runtime.container.internal.ContainerClassLoaderFactory) HashMap(java.util.HashMap) MuleClassLoaderLookupPolicy(org.mule.runtime.container.internal.MuleClassLoaderLookupPolicy) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PluginUrlClassification(org.mule.test.runner.api.PluginUrlClassification) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) ContainerOnlyLookupStrategy(org.mule.runtime.container.internal.ContainerOnlyLookupStrategy) ArtifactDescriptor(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor) Collections.emptyMap(java.util.Collections.emptyMap) SYSTEM_PACKAGES(org.mule.runtime.container.internal.ContainerClassLoaderFactory.SYSTEM_PACKAGES) ArtifactClassLoaderFilterFactory(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFilterFactory) Logger(org.slf4j.Logger) Collections.emptySet(java.util.Collections.emptySet) MalformedURLException(java.net.MalformedURLException) Boolean.valueOf(java.lang.Boolean.valueOf) File(java.io.File) DefaultRegionPluginClassLoadersFactory.getArtifactPluginId(org.mule.runtime.deployment.model.internal.DefaultRegionPluginClassLoadersFactory.getArtifactPluginId) Collectors.toList(java.util.stream.Collectors.toList) MuleApplicationClassLoader(org.mule.runtime.deployment.model.internal.application.MuleApplicationClassLoader) ArtifactsUrlClassification(org.mule.test.runner.api.ArtifactsUrlClassification) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ArtifactClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFilter) JarInfo(org.mule.runtime.module.artifact.internal.util.JarInfo) ArtifactDescriptor(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) MuleClassLoaderLookupPolicy(org.mule.runtime.container.internal.MuleClassLoaderLookupPolicy) FilteringArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.FilteringArtifactClassLoader) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) DefaultArtifactClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.DefaultArtifactClassLoaderFilter) ArtifactClassLoaderFilter(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFilter) PluginUrlClassification(org.mule.test.runner.api.PluginUrlClassification) URL(java.net.URL)

Aggregations

ClassLoaderLookupPolicy (org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy)32 Test (org.junit.Test)19 SmallTest (org.mule.tck.size.SmallTest)16 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)12 URLClassLoader (java.net.URLClassLoader)8 FineGrainedControlClassLoader (org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader)8 URL (java.net.URL)6 HashMap (java.util.HashMap)5 ArtifactPluginDescriptor (org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor)5 LookupStrategy (org.mule.runtime.module.artifact.api.classloader.LookupStrategy)5 PARENT_FIRST (org.mule.runtime.module.artifact.api.classloader.ParentFirstLookupStrategy.PARENT_FIRST)5 RegionClassLoader (org.mule.runtime.module.artifact.api.classloader.RegionClassLoader)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 MuleModule (org.mule.runtime.container.api.MuleModule)4 ArtifactClassLoaderFilter (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFilter)4 ArtifactDescriptor (org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor)4 TestClassLoader (org.mule.tck.classlaoder.TestClassLoader)4 System.lineSeparator (java.lang.System.lineSeparator)3