new BundleDependency.Builder() .setDescriptor(artifactPluginDescriptorResolved.getBundleDescriptor()) .setScope(dependency.getScope()) .build())) .build());
public BundleDependency convert(org.mule.maven.client.api.model.BundleDependency mavenBundleDependency) { BundleDependency bundleDependency = cache.get(mavenBundleDependency.getDescriptor()); if ((bundleDependency != null && bundleDependency.getBundleUri() != null) || (bundleDependency != null && mavenBundleDependency.getBundleUri() == null)) { return bundleDependency; } BundleDependency.Builder builder = new BundleDependency.Builder() .setScope(BundleScope.valueOf(mavenBundleDependency.getScope().name())) .setBundleUri(mavenBundleDependency.getBundleUri()) .setTransitiveDependencies(mavenBundleDependency.getTransitiveDependencies().stream() .filter(transitiveDependency -> !org.mule.maven.client.api.model.BundleScope.PROVIDED .equals(transitiveDependency.getScope())) .map(this::convert) .collect(toSet())) .setDescriptor(convertBundleDescriptor(mavenBundleDependency.getDescriptor())); bundleDependency = builder.build(); cache.put(mavenBundleDependency.getDescriptor(), bundleDependency); return bundleDependency; }
@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))); } }
@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))); } }
@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)); }
protected BundleDependency convertBundleDependency(org.mule.maven.client.api.model.BundleDependency mavenClientDependency) { BundleDependency.Builder builder = new BundleDependency.Builder() .setScope(BundleScope.valueOf(mavenClientDependency.getScope().name())) .setBundleUri(mavenClientDependency.getBundleUri()) .setDescriptor(convertBundleDescriptor(mavenClientDependency.getDescriptor())); return builder.build(); }
private BundleDependency toBundleDependency(Artifact artifact) { BundleDependency.Builder builder = new BundleDependency.Builder(); if (artifact.getArtifactCoordinates().getScope() != null) { builder.setScope(BundleScope.valueOf(artifact.getArtifactCoordinates().getScope().toUpperCase())); } return builder .setBundleUri(new File(artifactFolder, artifact.getUri().toString()).toURI()) .setDescriptor(new BundleDescriptor.Builder() .setArtifactId(artifact.getArtifactCoordinates().getArtifactId()) .setGroupId(artifact.getArtifactCoordinates().getGroupId()) .setVersion(artifact.getArtifactCoordinates().getVersion()) .setClassifier(artifact.getArtifactCoordinates().getClassifier()) .setType(artifact.getArtifactCoordinates().getType()) .build()) .build(); }
@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)); }
private static BundleDependency createBundleDependency(BundleDescriptor bundleDescriptor, boolean createBundleUri) { try { final BundleDependency.Builder builder = new BundleDependency.Builder(); builder.setDescriptor(bundleDescriptor); builder.setScope(BundleScope.COMPILE); if (createBundleUri) { builder.setBundleUri(temporaryFolder.newFile(bundleDescriptor.getArtifactFileName()).toURI()); } return builder.build(); } catch (IOException e) { throw new UncheckedIOException(e); } }