use of org.eclipse.aether.graph.Dependency in project mule by mulesoft.
the class AetherClassPathClassifierTestCase method before.
@Before
public void before() throws Exception {
String muleVersion = getMuleVersion();
this.rootArtifact = new DefaultArtifact("org.foo:foo-root:1.0-SNAPSHOT");
this.loggingDep = new Dependency(new DefaultArtifact("org.mule.runtime:mule-module-logging:" + muleVersion), COMPILE);
this.fooCoreDep = new Dependency(new DefaultArtifact("org.foo:foo-core:1.0-SNAPSHOT"), PROVIDED);
this.fooToolsArtifactDep = new Dependency(new DefaultArtifact("org.foo.tools:foo-artifact:1.0-SNAPSHOT"), PROVIDED);
this.fooTestsSupportDep = new Dependency(new DefaultArtifact("org.foo.tests:foo-tests-support:1.0-SNAPSHOT"), TEST);
this.derbyDriverDep = new Dependency(new DefaultArtifact("org.apache.derby:derby:10.11.1.1"), TEST);
this.guavaDep = new Dependency(new DefaultArtifact("org.google:guava:18.0"), COMPILE);
serviceArtifact = new DefaultArtifact("org.foo:foo-service:jar:mule-service:1.0-SNAPSHOT");
this.fooServiceDep = new Dependency(serviceArtifact, PROVIDED);
this.dependencyResolver = mock(DependencyResolver.class);
this.context = mock(ClassPathClassifierContext.class);
this.artifactClassificationTypeResolver = mock(ArtifactClassificationTypeResolver.class);
this.classifier = new AetherClassPathClassifier(dependencyResolver, artifactClassificationTypeResolver);
when(context.getRootArtifact()).thenReturn(rootArtifact);
this.directDependencies = newArrayList(fooCoreDep, fooToolsArtifactDep, fooTestsSupportDep, derbyDriverDep, guavaDep);
when(dependencyResolver.getDirectDependencies(rootArtifact)).thenReturn(directDependencies);
}
use of org.eclipse.aether.graph.Dependency in project mule by mulesoft.
the class AetherClassPathClassifierTestCase method onlyProvidedDependenciesNoTransitiveNoManageDependenciesNoFilters.
@Test
public void onlyProvidedDependenciesNoTransitiveNoManageDependenciesNoFilters() throws Exception {
Dependency compileMuleCoreDep = fooCoreDep.setScope(COMPILE);
Dependency compileMuleArtifactDep = fooToolsArtifactDep.setScope(COMPILE);
when(artifactClassificationTypeResolver.resolveArtifactClassificationType(rootArtifact)).thenReturn(MODULE);
ArtifactDescriptorResult artifactDescriptorResult = mock(ArtifactDescriptorResult.class);
List<Dependency> managedDependencies = newArrayList(guavaDep);
when(artifactDescriptorResult.getManagedDependencies()).thenReturn(managedDependencies);
when(dependencyResolver.readArtifactDescriptor(any(Artifact.class))).thenReturn(artifactDescriptorResult);
File rootArtifactFile = temporaryFolder.newFile();
File fooCoreArtifactFile = temporaryFolder.newFile();
File fooToolsArtifactFile = temporaryFolder.newFile();
Artifact jarRootArtifact = rootArtifact.setFile(rootArtifactFile);
ArtifactResult rootArtifactResult = mock(ArtifactResult.class);
when(rootArtifactResult.getArtifact()).thenReturn(jarRootArtifact);
when(dependencyResolver.resolveArtifact(argThat(new ArtifactMatcher(rootArtifact.getGroupId(), rootArtifact.getArtifactId())))).thenReturn(rootArtifactResult);
when(dependencyResolver.resolveDependencies(argThat(nullValue(Dependency.class)), (List<Dependency>) argThat(hasItems(equalTo(compileMuleCoreDep), equalTo(compileMuleArtifactDep), equalTo(loggingDep))), (List<Dependency>) argThat(hasItems(equalTo(guavaDep))), argThat(instanceOf(DependencyFilter.class)), argThat(equalTo(emptyList())))).thenReturn(newArrayList(fooCoreArtifactFile, fooToolsArtifactFile));
ArtifactsUrlClassification classification = classifier.classify(context);
assertThat(classification.getTestRunnerLibUrls(), is(empty()));
assertThat(classification.getPluginUrlClassifications(), is(empty()));
assertThat(classification.getApplicationSharedLibUrls(), is(empty()));
assertThat(classification.getContainerUrls(), hasSize(3));
assertThat(classification.getContainerUrls(), hasItems(fooCoreArtifactFile.toURI().toURL(), fooToolsArtifactFile.toURI().toURL(), rootArtifactFile.toURI().toURL()));
verify(artifactDescriptorResult, atLeastOnce()).getManagedDependencies();
verify(dependencyResolver, atLeastOnce()).readArtifactDescriptor(any(Artifact.class));
verify(dependencyResolver).resolveDependencies(argThat(nullValue(Dependency.class)), (List<Dependency>) argThat(hasItems(equalTo(compileMuleCoreDep), equalTo(compileMuleArtifactDep), equalTo(loggingDep))), (List<Dependency>) argThat(hasItems(equalTo(guavaDep))), argThat(instanceOf(DependencyFilter.class)), argThat(equalTo(emptyList())));
verify(artifactClassificationTypeResolver).resolveArtifactClassificationType(rootArtifact);
verify(rootArtifactResult).getArtifact();
}
use of org.eclipse.aether.graph.Dependency in project mule by mulesoft.
the class AetherClassPathClassifierTestCase method appendApplicationUrls.
@Test
public void appendApplicationUrls() throws Exception {
Dependency compileMuleCoreDep = fooCoreDep.setScope(COMPILE);
Dependency compileMuleArtifactDep = fooToolsArtifactDep.setScope(COMPILE);
when(artifactClassificationTypeResolver.resolveArtifactClassificationType(rootArtifact)).thenReturn(APPLICATION);
ArtifactDescriptorResult artifactDescriptorResult = mock(ArtifactDescriptorResult.class);
List<Dependency> managedDependencies = newArrayList(guavaDep);
when(artifactDescriptorResult.getManagedDependencies()).thenReturn(managedDependencies);
when(dependencyResolver.readArtifactDescriptor(any(Artifact.class), any(List.class))).thenReturn(artifactDescriptorResult);
artifactDescriptorResult = mock(ArtifactDescriptorResult.class);
when(artifactDescriptorResult.getRepositories()).thenReturn(emptyList());
when(dependencyResolver.readArtifactDescriptor(argThat(new ArtifactMatcher(rootArtifact.getGroupId(), rootArtifact.getArtifactId())))).thenReturn(artifactDescriptorResult);
File rootArtifactFile = temporaryFolder.newFile();
File fooCoreArtifactFile = temporaryFolder.newFile();
File fooToolsArtifactFile = temporaryFolder.newFile();
Artifact jarRootArtifact = rootArtifact.setFile(rootArtifactFile);
ArtifactResult rootArtifactResult = mock(ArtifactResult.class);
when(rootArtifactResult.getArtifact()).thenReturn(jarRootArtifact);
when(dependencyResolver.resolveArtifact(argThat(new ArtifactMatcher(rootArtifact.getGroupId(), rootArtifact.getArtifactId())))).thenReturn(rootArtifactResult);
when(dependencyResolver.resolveDependencies(argThat(nullValue(Dependency.class)), (List<Dependency>) argThat(hasItems(equalTo(compileMuleCoreDep), equalTo(compileMuleArtifactDep))), (List<Dependency>) argThat(hasItems(equalTo(guavaDep))), argThat(instanceOf(DependencyFilter.class)), argThat(equalTo(emptyList())))).thenReturn(newArrayList(fooCoreArtifactFile, fooToolsArtifactFile));
URL url = temporaryFolder.newFile().toURI().toURL();
List<URL> testRunnerUrls = newArrayList(url);
when(context.getTestRunnerPluginUrls()).thenReturn(testRunnerUrls);
ArtifactsUrlClassification classification = classifier.classify(context);
assertThat(classification.getTestRunnerLibUrls(), hasSize(2));
assertThat(classification.getTestRunnerLibUrls(), contains(rootArtifactFile.toURI().toURL(), url));
assertThat(classification.getPluginUrlClassifications(), is(empty()));
assertThat(classification.getApplicationSharedLibUrls(), is(empty()));
assertThat(classification.getContainerUrls(), hasSize(2));
assertThat(classification.getContainerUrls(), hasItems(fooCoreArtifactFile.toURI().toURL(), fooToolsArtifactFile.toURI().toURL()));
verify(artifactDescriptorResult, atLeastOnce()).getManagedDependencies();
verify(dependencyResolver, atLeastOnce()).readArtifactDescriptor(any(Artifact.class), any(List.class));
verify(dependencyResolver).resolveDependencies(argThat(nullValue(Dependency.class)), (List<Dependency>) argThat(hasItems(equalTo(compileMuleCoreDep), equalTo(compileMuleArtifactDep))), (List<Dependency>) argThat(hasItems(equalTo(guavaDep))), argThat(instanceOf(DependencyFilter.class)), argThat(equalTo(emptyList())));
verify(artifactClassificationTypeResolver).resolveArtifactClassificationType(rootArtifact);
verify(context, atLeastOnce()).getTestRunnerPluginUrls();
verify(rootArtifactResult).getArtifact();
}
use of org.eclipse.aether.graph.Dependency in project mule by mulesoft.
the class AetherClassPathClassifier method buildPluginUrlClassifications.
/**
* Plugin classifications are being done by resolving the dependencies for each plugin coordinates defined by the rootArtifact
* direct dependencies as {@value #MULE_SERVICE_CLASSIFIER}.
* <p/>
* While resolving the dependencies for the plugin artifact, only {@value org.eclipse.aether.util.artifact.JavaScopes#COMPILE}
* dependencies will be selected. {@link ClassPathClassifierContext#getExcludedArtifacts()} will be exluded too.
* <p/>
* The resulting {@link PluginUrlClassification} for each plugin will have as name the Maven artifact id coordinates:
* {@code <groupId>:<artifactId>:<extension>[:<classifier>]:<version>}.
*
* @param context {@link ClassPathClassifierContext} with settings for the classification process
* @param directDependencies {@link List} of {@link Dependency} with direct dependencies for the rootArtifact
* @param rootArtifactType {@link ArtifactClassificationType} for rootArtifact
* @param rootArtifactRemoteRepositories remote repositories defined at the rootArtifact
* @return {@link List} of {@link PluginUrlClassification}s for plugins class loaders
*/
private List<PluginUrlClassification> buildPluginUrlClassifications(ClassPathClassifierContext context, List<Dependency> directDependencies, ArtifactClassificationType rootArtifactType, List<RemoteRepository> rootArtifactRemoteRepositories) {
Set<ArtifactClassificationNode> pluginsClassified = newLinkedHashSet();
Artifact rootArtifact = context.getRootArtifact();
List<Artifact> pluginsArtifacts = directDependencies.stream().filter(dependency -> dependency.getArtifact().getClassifier().equals(MULE_PLUGIN_CLASSIFIER)).map(dependency -> dependency.getArtifact()).collect(toList());
logger.debug("{} plugins defined to be classified", pluginsArtifacts.size());
Predicate<Dependency> mulePluginDependencyFilter = dependency -> dependency.getArtifact().getClassifier().equals(MULE_PLUGIN_CLASSIFIER) && dependency.getScope().equals(COMPILE);
if (PLUGIN.equals(rootArtifactType)) {
logger.debug("rootArtifact '{}' identified as Mule plugin", rootArtifact);
buildPluginUrlClassification(rootArtifact, context, mulePluginDependencyFilter, pluginsClassified, rootArtifactRemoteRepositories);
pluginsArtifacts = pluginsArtifacts.stream().filter(pluginArtifact -> !(rootArtifact.getGroupId().equals(pluginArtifact.getGroupId()) && rootArtifact.getArtifactId().equals(pluginArtifact.getArtifactId()))).collect(toList());
}
pluginsArtifacts.stream().forEach(pluginArtifact -> buildPluginUrlClassification(pluginArtifact, context, mulePluginDependencyFilter, pluginsClassified, rootArtifactRemoteRepositories));
if (context.isExtensionMetadataGenerationEnabled()) {
ExtensionPluginMetadataGenerator extensionPluginMetadataGenerator = new ExtensionPluginMetadataGenerator(context.getPluginResourcesFolder());
for (ArtifactClassificationNode pluginClassifiedNode : pluginsClassified) {
List<URL> urls = generateExtensionMetadata(pluginClassifiedNode.getArtifact(), context, extensionPluginMetadataGenerator, pluginClassifiedNode.getUrls(), rootArtifactRemoteRepositories);
pluginClassifiedNode.setUrls(urls);
}
}
return toPluginUrlClassification(pluginsClassified);
}
use of org.eclipse.aether.graph.Dependency in project wildfly-swarm by wildfly-swarm.
the class ExtraArtifactsHandler method createNode.
private DependencyNode createNode(DependencyNode n, Optional<String> extension, Optional<String> classifier) {
Artifact original = n.getArtifact();
Artifact withExtension = new DefaultArtifact(original.getGroupId(), original.getArtifactId(), classifier.orElse(original.getClassifier()), extension.orElse(original.getExtension()), original.getVersion(), original.getProperties(), (File) null);
DefaultDependencyNode nodeWithClassifier = new DefaultDependencyNode(new Dependency(withExtension, "system"));
return nodeWithClassifier;
}
Aggregations