Search in sources :

Example 11 with ArtifactDescriptor

use of org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor in project mule by mulesoft.

the class CustomJavaSerializationProtocolTestCase method serializeWithoutDefaultConstructorFromArtifactClassLoader.

@Test
public final void serializeWithoutDefaultConstructorFromArtifactClassLoader() throws Exception {
    final File compiledClasses = new File(temporaryFolder.getRoot(), "compiledClasses");
    compiledClasses.mkdirs();
    final File sourceFile = new File(getClass().getResource("/org/foo/SerializableClass.java").toURI());
    CompilerUtils.SingleClassCompiler compiler = new CompilerUtils.SingleClassCompiler();
    compiler.compile(sourceFile);
    final URL[] urls = new URL[] { compiler.getTargetFolder().toURL() };
    final ClassLoaderLookupPolicy lookupPolicy = mock(ClassLoaderLookupPolicy.class);
    when(lookupPolicy.getClassLookupStrategy(any())).thenReturn(PARENT_FIRST);
    final MuleArtifactClassLoader artifactClassLoader = new MuleArtifactClassLoader(ARTIFACT_ID, new ArtifactDescriptor(ARTIFACT_NAME), urls, getClass().getClassLoader(), lookupPolicy);
    when(classLoaderRepository.getId(artifactClassLoader)).thenReturn(Optional.of(ARTIFACT_ID));
    when(classLoaderRepository.find(ARTIFACT_ID)).thenReturn(Optional.of(artifactClassLoader));
    final Class<?> echoTestClass = artifactClassLoader.loadClass(SERIALIZABLE_CLASS);
    final Object payload = echoTestClass.newInstance();
    setObjectName(payload);
    CoreEvent event = eventBuilder(muleContext).message(of(payload)).build();
    byte[] bytes = serializationProtocol.serialize(event.getMessage());
    InternalMessage message = serializationProtocol.deserialize(bytes);
    Object deserialized = message.getPayload().getValue();
    assertThat(deserialized.getClass().getName(), equalTo(SERIALIZABLE_CLASS));
    assertThat(deserialized.getClass().getClassLoader(), equalTo(artifactClassLoader));
    assertThat(deserialized, equalTo(payload));
    assertThat(getObjectName(deserialized), equalTo(INSTANCE_NAME));
}
Also used : InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) URL(java.net.URL) ArtifactDescriptor(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) CompilerUtils(org.mule.tck.util.CompilerUtils) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader) File(java.io.File) Test(org.junit.Test)

Example 12 with ArtifactDescriptor

use of org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor in project mule by mulesoft.

the class ToolingPluginClassLoaderBuilder method build.

@Override
public ToolingArtifactClassLoader build() throws IOException {
    setArtifactDescriptor(new ArtifactDescriptor(TOOLING_EXTENSION_MODEL));
    List<ArtifactPluginDescriptor> resolvedArtifactPluginDescriptors = pluginDependenciesResolver.resolve(emptySet(), ImmutableList.<ArtifactPluginDescriptor>builder().add(artifactPluginDescriptor).build());
    this.addArtifactPluginDescriptors(resolvedArtifactPluginDescriptors.toArray(new ArtifactPluginDescriptor[resolvedArtifactPluginDescriptors.size()]));
    ArtifactClassLoader ownerArtifactClassLoader = super.build();
    ClassLoader parent = ownerArtifactClassLoader.getClassLoader().getParent();
    if (!(parent instanceof RegionClassLoader)) {
        throw new DeploymentException(createStaticMessage(format("The parent of the current owner must be of type '%s' but found '%s'", RegionClassLoader.class.getName(), parent.getClass().getName())));
    }
    final RegionClassLoader regionClassLoader = (RegionClassLoader) parent;
    return new ToolingArtifactClassLoader(regionClassLoader, getPluginArtifactClassLoader(artifactPluginDescriptor, regionClassLoader.getArtifactPluginClassLoaders()));
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ArtifactDescriptor(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader) DisposableClassLoader(org.mule.runtime.module.artifact.api.classloader.DisposableClassLoader) DeploymentException(org.mule.runtime.deployment.model.api.DeploymentException) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader)

Example 13 with ArtifactDescriptor

use of org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor in project mule by mulesoft.

the class IsolatedClassLoaderFactory method createApplicationArtifactClassLoader.

/**
 * Creates an {@link ArtifactClassLoader} for the application.
 *
 * @param parent the parent class loader to be assigned to the new one created here
 * @param childClassLoaderLookupPolicy look policy to be used
 * @param artifactsUrlClassification the url classifications to get plugins urls
 * @param pluginsArtifactClassLoaders the classloaders of the plugins used by the application
 * @return the {@link ArtifactClassLoader} to be used for running the test
 */
protected ArtifactClassLoader createApplicationArtifactClassLoader(ClassLoader parent, ClassLoaderLookupPolicy childClassLoaderLookupPolicy, ArtifactsUrlClassification artifactsUrlClassification, List<ArtifactClassLoader> pluginsArtifactClassLoaders) {
    List<URL> applicationUrls = new ArrayList<>();
    applicationUrls.addAll(artifactsUrlClassification.getApplicationLibUrls());
    applicationUrls.addAll(artifactsUrlClassification.getApplicationSharedLibUrls());
    logClassLoaderUrls("APP", applicationUrls);
    return new MuleApplicationClassLoader(APP_NAME, new ArtifactDescriptor(APP_NAME), parent, new DefaultNativeLibraryFinderFactory().create(APP_NAME, applicationUrls.toArray(new URL[applicationUrls.size()])), applicationUrls, childClassLoaderLookupPolicy, pluginsArtifactClassLoaders);
}
Also used : ArtifactDescriptor(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) DefaultNativeLibraryFinderFactory(org.mule.runtime.deployment.model.internal.nativelib.DefaultNativeLibraryFinderFactory) MuleApplicationClassLoader(org.mule.runtime.deployment.model.internal.application.MuleApplicationClassLoader) URL(java.net.URL)

Example 14 with ArtifactDescriptor

use of org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor in project mule by mulesoft.

the class TestContainerClassLoaderFactory method createArtifactClassLoader.

/**
 * Overrides the method in order to create a {@link ArtifactClassLoader} that will have a CHILD_FIRST
 * {@link ClassLoaderLookupPolicy}, it is needed due to as difference from a mule standalone container where the parent
 * {@link ClassLoader} for the container only has bootstrap jars plugins mule modules and third-party libraries when the runner
 * runs this tests using has a full class path with all the artifacts declared as dependencies for the artifact so we have to
 * change that and change the look strategy to be CHILD_FIRST for the container.
 * <p/>
 * The {@code muleModules} parameter will be ignored due to it has all the modules in classpath, instead they are discovered
 * once again but using a {@link URLClassLoader} that has the {@link URL}'s classified for the container {@link ClassLoader}.
 *
 * @param parentClassLoader the parent {@link ClassLoader} to delegate PARENT look ups
 * @param muleModules {@link MuleModule} discovered from the launcher {@link ClassLoader} but will be not considered here due to
 *        it has all the class path
 * @param containerLookupPolicy the default {@link ClassLoaderLookupPolicy} defined for a container but will be ignored due to
 *        it has to be different when running with a full class path as parent {@link ClassLoader}
 * @param artifactDescriptor
 * @return the {@link ArtifactClassLoader} to be used for the container
 */
@Override
protected ArtifactClassLoader createArtifactClassLoader(final ClassLoader parentClassLoader, final List<MuleModule> muleModules, final ClassLoaderLookupPolicy containerLookupPolicy, ArtifactDescriptor artifactDescriptor) {
    final ArtifactDescriptor containerDescriptor = new ArtifactDescriptor("mule");
    containerClassLoader = new MuleArtifactClassLoader(containerDescriptor.getName(), containerDescriptor, urls, parentClassLoader, containerLookupPolicy);
    return createContainerFilteringClassLoader(withContextClassLoader(classLoader, () -> testContainerModuleRepository.getModules()), containerClassLoader);
}
Also used : ArtifactDescriptor(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor) MuleArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader)

Example 15 with ArtifactDescriptor

use of org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor in project mule by mulesoft.

the class LoggerContextConfigurerTestCase method noAppendersForMutedApplication.

@Test
public void noAppendersForMutedApplication() throws Exception {
    when(context.isArtifactClassloader()).thenReturn(true);
    when(context.isApplicationClassloader()).thenReturn(true);
    ArtifactDescriptor descriptor = mock(ArtifactDescriptor.class);
    Properties properties = new Properties();
    properties.setProperty(MULE_MUTE_APP_LOGS_DEPLOYMENT_PROPERTY, "true");
    when(descriptor.getDeploymentProperties()).thenReturn(Optional.of(properties));
    when(context.getArtifactDescriptor()).thenReturn(descriptor);
    contextConfigurer.update(context);
    verify(context.getConfiguration(), never()).addAppender(any(Appender.class));
}
Also used : RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) Appender(org.apache.logging.log4j.core.Appender) ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) ArtifactDescriptor(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor) MuleProperties(org.mule.runtime.core.api.config.MuleProperties) Properties(java.util.Properties) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

ArtifactDescriptor (org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor)15 URL (java.net.URL)8 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)5 ClassLoaderLookupPolicy (org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy)5 MuleArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader)5 RegionClassLoader (org.mule.runtime.module.artifact.api.classloader.RegionClassLoader)4 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Before (org.junit.Before)3 MuleModule (org.mule.runtime.container.api.MuleModule)3 MuleClassLoaderLookupPolicy (org.mule.runtime.container.internal.MuleClassLoaderLookupPolicy)3 ArtifactClassLoaderFilter (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFilter)3 FilteringArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.FilteringArtifactClassLoader)3 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 ContainerClassLoaderFactory (org.mule.runtime.container.internal.ContainerClassLoaderFactory)2 ContainerOnlyLookupStrategy (org.mule.runtime.container.internal.ContainerOnlyLookupStrategy)2 DefaultModuleRepository (org.mule.runtime.container.internal.DefaultModuleRepository)2