use of org.mule.runtime.module.artifact.api.classloader.RegionClassLoader in project mule by mulesoft.
the class DefaultPolicyTemplateFactoryTestCase method createsPolicyTemplate.
@Test
public void createsPolicyTemplate() throws Exception {
RegionClassLoader regionClassLoader = createRegionClassLoader();
PolicyTemplateClassLoaderBuilder policyTemplateClassLoaderBuilder = createPolicyTemplateClassLoaderBuilder(regionClassLoader);
MuleDeployableArtifactClassLoader policyClassLoader = mock(MuleDeployableArtifactClassLoader.class);
when(policyClassLoader.getArtifactId()).thenReturn(POLICY_ID);
when(policyTemplateClassLoaderBuilder.build()).thenReturn(policyClassLoader);
when(classLoaderBuilderFactory.createArtifactClassLoaderBuilder()).thenReturn(policyTemplateClassLoaderBuilder);
PolicyTemplate policyTemplate = policyTemplateFactory.createArtifact(createApplication(regionClassLoader), descriptor);
assertThat(policyTemplate.getArtifactClassLoader(), is(policyClassLoader));
assertThat(policyTemplate.getDescriptor(), is(descriptor));
assertThat(policyTemplate.getArtifactId(), is(POLICY_ID));
assertThat(regionClassLoader.getArtifactPluginClassLoaders().size(), equalTo(1));
}
use of org.mule.runtime.module.artifact.api.classloader.RegionClassLoader 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.classloader.RegionClassLoader in project mule by mulesoft.
the class ArtifactAwareContextSelectorTestCase method returnsParentContextForPolicyClassloader.
@Test
public void returnsParentContextForPolicyClassloader() throws MalformedURLException {
ClassLoader childClassLoader = new URLClassLoader(new URL[0], regionClassLoader);
PolicyTemplateDescriptor policyTemplateDescriptor = new PolicyTemplateDescriptor(POLICY_TEMPLATE_NAME, empty());
RegionClassLoader policyRegionClassLoader = spy(getPolicyRegionClassLoader(policyTemplateDescriptor));
MuleArtifactClassLoader policyClassLoader = getPolicyArtifactClassLoader(policyTemplateDescriptor, policyRegionClassLoader);
LoggerContext appCtx = selector.getContext("", childClassLoader, true);
LoggerContext policyCtx = selector.getContext("", policyClassLoader, true);
assertThat(policyCtx, sameInstance(appCtx));
}
Aggregations