use of org.mule.runtime.module.artifact.api.classloader.RegionClassLoader 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));
}
use of org.mule.runtime.module.artifact.api.classloader.RegionClassLoader in project mule by mulesoft.
the class ToolingApplicationClassLoaderBuilder method build.
/**
* Creates a new {@code ArtifactClassLoader} using the provided configuration. It will create the proper class loader hierarchy
* and filters so application classes, resources, plugins and it's domain resources are resolve correctly.
*
* @return a {@code MuleDeployableArtifactClassLoader} created from the provided configuration.
* @throws IOException exception cause when it was not possible to access the file provided as dependencies
*/
public ToolingArtifactClassLoader build() throws IOException {
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, ownerArtifactClassLoader);
}
use of org.mule.runtime.module.artifact.api.classloader.RegionClassLoader in project mule by mulesoft.
the class ToolingDomainClassLoaderBuilder method build.
/**
* Creates a new {@code ArtifactClassLoader} using the provided configuration. It will create the proper class loader hierarchy
* and filters so domain classes, resources and plugins are resolve correctly.
*
* @return a {@code MuleDeployableArtifactClassLoader} created from the provided configuration.
* @throws IOException exception cause when it was not possible to access the file provided as dependencies
*/
public ToolingArtifactClassLoader build() throws IOException {
ArtifactClassLoader domainClassLoader = super.build();
ClassLoader parent = domainClassLoader.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, domainClassLoader);
}
use of org.mule.runtime.module.artifact.api.classloader.RegionClassLoader 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;
}
use of org.mule.runtime.module.artifact.api.classloader.RegionClassLoader in project mule by mulesoft.
the class DefaultPolicyTemplateFactoryTestCase method managesArtifactContextCreationFailure.
@Test
public void managesArtifactContextCreationFailure() throws Exception {
RegionClassLoader regionClassLoader = createRegionClassLoader();
PolicyTemplateClassLoaderBuilder policyTemplateClassLoaderBuilder = createPolicyTemplateClassLoaderBuilder(regionClassLoader);
final String errorMessage = "Error";
final IOException exceptionCause = new IOException(errorMessage);
when(policyTemplateClassLoaderBuilder.build()).thenThrow(exceptionCause);
when(classLoaderBuilderFactory.createArtifactClassLoaderBuilder()).thenReturn(policyTemplateClassLoaderBuilder);
this.expectedException.expect(PolicyTemplateCreationException.class);
this.expectedException.expectMessage(createPolicyTemplateCreationErrorMessage(POLICY_NAME));
this.expectedException.expectCause(equalTo(exceptionCause));
policyTemplateFactory.createArtifact(createApplication(regionClassLoader), descriptor);
// Checks that the region was not updated
assertThat(regionClassLoader.getArtifactPluginClassLoaders().size(), equalTo(0));
}
Aggregations