use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader 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;
}
use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader 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;
}
use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.
the class ArtifactAwareContextSelectorTestCase method returnsMuleLoggerContextForInternalArtifactClassLoader.
@Test
public void returnsMuleLoggerContextForInternalArtifactClassLoader() {
ArtifactClassLoader serviceClassLoader = new MuleArtifactClassLoader("test", new ApplicationDescriptor("test"), new URL[0], this.getClass().getClassLoader(), mock(ClassLoaderLookupPolicy.class));
LoggerContext systemContext = selector.getContext("", this.getClass().getClassLoader(), true);
LoggerContext serviceCtx = selector.getContext("", serviceClassLoader.getClassLoader(), true);
assertThat(serviceCtx, instanceOf(MuleLoggerContext.class));
assertThat(serviceCtx, sameInstance(systemContext));
}
use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.
the class MuleLoggerContextFactory method build.
/**
* Builds a new {@link LoggerContext} for the given {@code classLoader} and {@code selector}
*
* @param classLoader the classloader of the artifact this logger context is for.
* @param selector the selector to bew used when building the loggers for the new context.
* @return
*/
public LoggerContext build(final ClassLoader classLoader, final ArtifactAwareContextSelector selector) {
NewContextParameters parameters = resolveContextParameters(classLoader);
if (parameters == null) {
return getDefaultContext(selector);
}
MuleLoggerContext loggerContext = new MuleLoggerContext(parameters.contextName, parameters.loggerConfigFile, classLoader, selector, isStandalone());
if (classLoader instanceof ArtifactClassLoader) {
final ArtifactClassLoader artifactClassLoader = (ArtifactClassLoader) classLoader;
artifactClassLoader.addShutdownListener(() -> selector.destroyLoggersFor(ArtifactAwareContextSelector.resolveLoggerContextClassLoader(classLoader)));
}
return loggerContext;
}
use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.
the class FileSystemServiceProviderDiscoverer method createServiceProviders.
private List<Pair<ArtifactClassLoader, ServiceProvider>> createServiceProviders(List<ServiceDescriptor> serviceDescriptors, ArtifactClassLoaderFactory<ServiceDescriptor> serviceClassLoaderFactory) throws ServiceResolutionError {
List<Pair<ArtifactClassLoader, ServiceProvider>> serviceProviders = new LinkedList<>();
for (ServiceDescriptor serviceDescriptor : serviceDescriptors) {
final ArtifactClassLoader serviceClassLoader = serviceClassLoaderFactory.create(getServiceArtifactId(serviceDescriptor), serviceDescriptor, apiClassLoader.getClassLoader(), apiClassLoader.getClassLoaderLookupPolicy());
final ServiceProvider serviceProvider = instantiateServiceProvider(serviceClassLoader.getClassLoader(), serviceDescriptor.getServiceProviderClassName());
serviceProviders.add(new Pair<>(serviceClassLoader, serviceProvider));
}
return serviceProviders;
}
Aggregations