use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor 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.deployment.model.api.plugin.ArtifactPluginDescriptor in project mule by mulesoft.
the class DefaultRegionPluginClassLoadersFactoryTestCase method createsDependantPlugins.
@Test
public void createsDependantPlugins() throws Exception {
BundleDependency pluginDependency = new BundleDependency.Builder().setScope(BundleScope.COMPILE).setDescriptor(PLUGIN1_BUNDLE_DESCRIPTOR).setBundleUri(new File("test").toURI()).build();
plugin2Descriptor.setClassLoaderModel(new ClassLoaderModel.ClassLoaderModelBuilder().dependingOn(singleton(pluginDependency)).build());
List<ArtifactPluginDescriptor> artifactPluginDescriptors = new ArrayList<>();
artifactPluginDescriptors.add(plugin1Descriptor);
artifactPluginDescriptors.add(plugin2Descriptor);
when(regionOwnerLookupPolicy.extend(argThat(any(Map.class)))).thenReturn(pluginLookupPolicy);
List<ArtifactClassLoader> pluginClassLoaders = factory.createPluginClassLoaders(regionClassLoader, artifactPluginDescriptors, regionOwnerLookupPolicy);
assertThat(pluginClassLoaders, contains(pluginClassLoader1, pluginClassLoader2));
}
use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor in project mule by mulesoft.
the class DefaultRegionPluginClassLoadersFactoryTestCase method createsPluginWithPrivilegedPluginAccess.
@Test
public void createsPluginWithPrivilegedPluginAccess() throws Exception {
ClassLoaderModel plugin1ClassLoaderModel = new ClassLoaderModel.ClassLoaderModelBuilder().exportingPrivilegedPackages(singleton(PRIVILEGED_PACKAGE), singleton(PLUGIN_ARTIFACT_ID2)).build();
plugin1Descriptor.setClassLoaderModel(plugin1ClassLoaderModel);
BundleDependency pluginDependency = new BundleDependency.Builder().setScope(BundleScope.COMPILE).setDescriptor(PLUGIN1_BUNDLE_DESCRIPTOR).setBundleUri(new File("test").toURI()).build();
plugin2Descriptor.setClassLoaderModel(new ClassLoaderModel.ClassLoaderModelBuilder().dependingOn(singleton(pluginDependency)).build());
List<ArtifactPluginDescriptor> artifactPluginDescriptors = new ArrayList<>();
artifactPluginDescriptors.add(plugin1Descriptor);
artifactPluginDescriptors.add(plugin2Descriptor);
ArgumentCaptor<Map> argumentCaptor = forClass(Map.class);
when(regionOwnerLookupPolicy.extend(argumentCaptor.capture())).thenReturn(pluginLookupPolicy);
List<ArtifactClassLoader> pluginClassLoaders = factory.createPluginClassLoaders(regionClassLoader, artifactPluginDescriptors, regionOwnerLookupPolicy);
assertThat(pluginClassLoaders, contains(pluginClassLoader1, pluginClassLoader2));
assertThat((Map<String, LookupStrategy>) argumentCaptor.getAllValues().get(0), not(hasEntry(equalTo(PRIVILEGED_PACKAGE), instanceOf(DelegateOnlyLookupStrategy.class))));
assertThat((Map<String, LookupStrategy>) argumentCaptor.getAllValues().get(1), hasEntry(equalTo(PRIVILEGED_PACKAGE), instanceOf(DelegateOnlyLookupStrategy.class)));
}
use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor in project mule by mulesoft.
the class BundlePluginDependenciesResolverTestCase method detectsUnresolvablePluginDependency.
@Test
public void detectsUnresolvablePluginDependency() throws Exception {
final List<ArtifactPluginDescriptor> pluginDescriptors = createPluginDescriptors(fooPlugin);
fooPlugin.setClassLoaderModel(new ClassLoaderModelBuilder().dependingOn(singleton(BAR_PLUGIN_DESCRIPTOR)).build());
expectedException.expect(PluginResolutionError.class);
expectedException.expectMessage(format(DEPENDENCY_PROVIDER_ERROR_MESSAGE, BAR_BUNDLE_DESCRIPTOR));
dependenciesResolver.resolve(emptySet(), pluginDescriptors);
}
use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor in project mule by mulesoft.
the class BundlePluginDependenciesResolverTestCase method detectsDuplicateExportedPackagesOnIndependentPlugins.
@Test
public void detectsDuplicateExportedPackagesOnIndependentPlugins() throws Exception {
fooPlugin.setClassLoaderModel(new ClassLoaderModelBuilder().exportingPackages(getFooExportedPackages()).build());
barPlugin.setClassLoaderModel(new ClassLoaderModelBuilder().exportingPackages(getBarExportedPackages()).build());
final List<ArtifactPluginDescriptor> pluginDescriptors = createPluginDescriptors(fooPlugin, barPlugin);
Map<String, List<String>> pluginsPerPackage = new HashMap<>();
pluginsPerPackage.put("org.foo", asList("bar, foo"));
pluginsPerPackage.put("org.foo.mule", asList("bar, foo"));
String expectedErrorMessage = new DuplicateExportedPackageException(pluginsPerPackage).getMessage();
this.expectedException.expect(DuplicateExportedPackageException.class);
this.expectedException.expectMessage(expectedErrorMessage);
dependenciesResolver.resolve(emptySet(), pluginDescriptors);
}
Aggregations