Search in sources :

Example 16 with Dependency

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);
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Dependency(org.eclipse.aether.graph.Dependency) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Before(org.junit.Before)

Example 17 with Dependency

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();
}
Also used : Dependency(org.eclipse.aether.graph.Dependency) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) File(java.io.File) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) SmallTest(org.mule.tck.size.SmallTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 18 with Dependency

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();
}
Also used : Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) Dependency(org.eclipse.aether.graph.Dependency) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) File(java.io.File) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) URL(java.net.URL) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) SmallTest(org.mule.tck.size.SmallTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 19 with Dependency

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);
}
Also used : PLUGIN(org.mule.test.runner.api.ArtifactClassificationType.PLUGIN) ListIterator(java.util.ListIterator) URL(java.net.URL) Optional.of(java.util.Optional.of) TEST(org.eclipse.aether.util.artifact.JavaScopes.TEST) LoggerFactory(org.slf4j.LoggerFactory) DependencyFilterUtils.orFilter(org.eclipse.aether.util.filter.DependencyFilterUtils.orFilter) FileUtils.toFile(org.apache.commons.io.FileUtils.toFile) APPLICATION(org.mule.test.runner.api.ArtifactClassificationType.APPLICATION) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) Collections.singleton(java.util.Collections.singleton) DependencyFilterUtils.andFilter(org.eclipse.aether.util.filter.DependencyFilterUtils.andFilter) Map(java.util.Map) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Collectors.toSet(java.util.stream.Collectors.toSet) ArtifactIdUtils.toId(org.eclipse.aether.util.artifact.ArtifactIdUtils.toId) PROVIDED(org.eclipse.aether.util.artifact.JavaScopes.PROVIDED) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) Artifact(org.eclipse.aether.artifact.Artifact) Preconditions.checkNotNull(org.mule.runtime.api.util.Preconditions.checkNotNull) PatternInclusionsDependencyFilter(org.mule.test.runner.classification.PatternInclusionsDependencyFilter) String.format(java.lang.String.format) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Optional(java.util.Optional) Maps.newLinkedHashMap(com.google.common.collect.Maps.newLinkedHashMap) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) PatternExclusionsDependencyFilter(org.mule.test.runner.classification.PatternExclusionsDependencyFilter) Optional.empty(java.util.Optional.empty) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) Extension(org.mule.runtime.extension.api.annotation.Extension) Dependency(org.eclipse.aether.graph.Dependency) AtomicReference(java.util.concurrent.atomic.AtomicReference) COMPILE(org.eclipse.aether.util.artifact.JavaScopes.COMPILE) MODULE(org.mule.test.runner.api.ArtifactClassificationType.MODULE) VersionChecker.areCompatibleVersions(org.mule.maven.client.internal.util.VersionChecker.areCompatibleVersions) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) Properties(java.util.Properties) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Sets.newLinkedHashSet(com.google.common.collect.Sets.newLinkedHashSet) IOException(java.io.IOException) File(java.io.File) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Collectors.toList(java.util.stream.Collectors.toList) FileFilter(java.io.FileFilter) StringUtils.endsWithIgnoreCase(org.apache.commons.lang3.StringUtils.endsWithIgnoreCase) VersionChecker.isHighestVersion(org.mule.maven.client.internal.util.VersionChecker.isHighestVersion) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) Exclusion(org.eclipse.aether.graph.Exclusion) DependencyFilterUtils.classpathFilter(org.eclipse.aether.util.filter.DependencyFilterUtils.classpathFilter) Collections(java.util.Collections) Dependency(org.eclipse.aether.graph.Dependency) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) URL(java.net.URL)

Example 20 with Dependency

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;
}
Also used : DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) Dependency(org.eclipse.aether.graph.Dependency) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Aggregations

Dependency (org.eclipse.aether.graph.Dependency)57 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)39 Artifact (org.eclipse.aether.artifact.Artifact)36 File (java.io.File)25 CollectRequest (org.eclipse.aether.collection.CollectRequest)22 ArrayList (java.util.ArrayList)19 DependencyNode (org.eclipse.aether.graph.DependencyNode)17 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)17 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)17 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)15 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)15 ArtifactDescriptorResult (org.eclipse.aether.resolution.ArtifactDescriptorResult)14 IOException (java.io.IOException)13 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)13 Exclusion (org.eclipse.aether.graph.Exclusion)13 MalformedURLException (java.net.MalformedURLException)12 DependencyResolutionException (org.eclipse.aether.resolution.DependencyResolutionException)11 List (java.util.List)10 URL (java.net.URL)9 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)9