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));
}
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()));
}
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);
}
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);
}
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));
}
Aggregations