Search in sources :

Example 46 with Dependency

use of org.eclipse.aether.graph.Dependency in project mule by mulesoft.

the class AetherClassPathClassifierTestCase method serviceClassification.

@Test
public void serviceClassification() throws Exception {
    this.directDependencies = newArrayList(fooCoreDep, fooToolsArtifactDep, fooTestsSupportDep, derbyDriverDep, guavaDep, fooServiceDep);
    when(dependencyResolver.getDirectDependencies(rootArtifact)).thenReturn(directDependencies);
    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);
    when(dependencyResolver.resolveArtifact(any(Artifact.class), any(List.class))).thenAnswer(invocation -> {
        Artifact artifact = (Artifact) invocation.getArguments()[0];
        artifact = artifact.setFile(temporaryFolder.newFile());
        return new ArtifactResult(new ArtifactRequest(artifact, null, null)).setArtifact(artifact);
    });
    when(artifactClassificationTypeResolver.resolveArtifactClassificationType(rootArtifact)).thenReturn(APPLICATION);
    File fooServiceArtifactFile = temporaryFolder.newFolder();
    File metaInfFolder = new File(fooServiceArtifactFile, META_INF);
    metaInfFolder.delete();
    metaInfFolder.mkdir();
    File descriptor = new File(metaInfFolder, MULE_ARTIFACT_JSON_DESCRIPTOR);
    MuleServiceModel muleServiceModel = new MuleServiceModelBuilder().setName("Foo").setMinMuleVersion("4.0.0").withServiceProviderClassName("org.foo.ServiceProvider").withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap())).withBundleDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap())).build();
    String model = new MuleServiceModelJsonSerializer().serialize(muleServiceModel);
    FileUtils.write(descriptor, model);
    List<File> fooServiceUrls = newArrayList(fooServiceArtifactFile);
    when(dependencyResolver.resolveDependencies(argThat(equalTo(new Dependency(fooServiceDep.getArtifact(), COMPILE))), argThat(equalTo(emptyList())), argThat(equalTo(emptyList())), argThat(instanceOf(DependencyFilter.class)), argThat(equalTo(emptyList())))).thenReturn(fooServiceUrls);
    File rootArtifactFile = 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);
    File serviceArtifactFile = temporaryFolder.newFile();
    ArtifactResult serviceArtifactResult = mock(ArtifactResult.class);
    Artifact jarServiceArtifact = serviceArtifact.setFile(serviceArtifactFile);
    when(serviceArtifactResult.getArtifact()).thenReturn(jarServiceArtifact);
    when(dependencyResolver.resolveArtifact(argThat(new ArtifactMatcher(serviceArtifact.getGroupId(), serviceArtifact.getArtifactId())))).thenReturn(serviceArtifactResult);
    ArtifactDescriptorResult defaultArtifactDescriptorResult = noManagedDependencies();
    Dependency compileMuleCoreDep = fooCoreDep.setScope(COMPILE);
    Dependency compileMuleArtifactDep = fooToolsArtifactDep.setScope(COMPILE);
    File fooCoreArtifactFile = temporaryFolder.newFile();
    File fooToolsArtifactFile = temporaryFolder.newFile();
    when(dependencyResolver.resolveDependencies(argThat(nullValue(Dependency.class)), (List<Dependency>) and((argThat(hasItems(equalTo(compileMuleCoreDep), equalTo(compileMuleArtifactDep)))), argThat(hasSize(3))), (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(), hasSize(1));
    assertThat(classification.getTestRunnerLibUrls(), hasItem(rootArtifactFile.toURI().toURL()));
    assertThat(classification.getPluginUrlClassifications(), is(empty()));
    assertThat(classification.getApplicationSharedLibUrls(), is(empty()));
    assertThat(classification.getContainerUrls(), hasSize(2));
    assertThat(classification.getServiceUrlClassifications(), hasSize(1));
    assertThat(classification.getServiceUrlClassifications().get(0).getUrls(), hasItem(fooServiceArtifactFile.toURI().toURL()));
    verify(defaultArtifactDescriptorResult, atLeastOnce()).getManagedDependencies();
    verify(dependencyResolver, atLeastOnce()).readArtifactDescriptor(any(Artifact.class), anyObject());
    verify(dependencyResolver, atLeastOnce()).resolveDependencies(argThat(equalTo(new Dependency(fooServiceDep.getArtifact(), COMPILE))), argThat(equalTo(emptyList())), argThat(equalTo(emptyList())), argThat(instanceOf(DependencyFilter.class)), argThat(equalTo(emptyList())));
    verify(artifactClassificationTypeResolver).resolveArtifactClassificationType(rootArtifact);
    verify(dependencyResolver, atLeastOnce()).resolveDependencies(argThat(nullValue(Dependency.class)), (List<Dependency>) and((argThat(hasItems(equalTo(compileMuleCoreDep), equalTo(compileMuleArtifactDep)))), argThat(hasSize(3))), (List<Dependency>) argThat(hasItems(equalTo(guavaDep))), argThat(instanceOf(DependencyFilter.class)), argThat(equalTo(emptyList())));
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) Dependency(org.eclipse.aether.graph.Dependency) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MuleServiceModelBuilder(org.mule.runtime.api.deployment.meta.MuleServiceModel.MuleServiceModelBuilder) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) MuleServiceModelJsonSerializer(org.mule.runtime.api.deployment.persistence.MuleServiceModelJsonSerializer) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) File(java.io.File) MuleServiceModel(org.mule.runtime.api.deployment.meta.MuleServiceModel) SmallTest(org.mule.tck.size.SmallTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 47 with Dependency

use of org.eclipse.aether.graph.Dependency in project mule by mulesoft.

the class AetherClassPathClassifierTestCase method noManagedDependencies.

private ArtifactDescriptorResult noManagedDependencies() throws ArtifactDescriptorException {
    ArtifactDescriptorResult artifactDescriptorResult = mock(ArtifactDescriptorResult.class);
    List<Dependency> managedDependencies = emptyList();
    when(artifactDescriptorResult.getManagedDependencies()).thenReturn(managedDependencies);
    when(dependencyResolver.readArtifactDescriptor(any(Artifact.class))).thenReturn(artifactDescriptorResult);
    return artifactDescriptorResult;
}
Also used : Dependency(org.eclipse.aether.graph.Dependency) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 48 with Dependency

use of org.eclipse.aether.graph.Dependency in project spring-cloud-function by spring-cloud.

the class DependencyResolutionModule method getArtifactRequests.

private List<ArtifactRequest> getArtifactRequests(List<Dependency> dependencies) {
    List<ArtifactRequest> list = new ArrayList<>();
    for (Dependency dependency : dependencies) {
        ArtifactRequest request = new ArtifactRequest(dependency.getArtifact(), null, null);
        request.setRepositories(aetherRepositories(new Properties()));
        list.add(request);
    }
    return list;
}
Also used : ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) ArrayList(java.util.ArrayList) Dependency(org.eclipse.aether.graph.Dependency) Properties(java.util.Properties)

Example 49 with Dependency

use of org.eclipse.aether.graph.Dependency in project spring-cloud-function by spring-cloud.

the class MemoryBasedJavaFileManager method addAndResolveDependencies.

public List<CompilationMessage> addAndResolveDependencies(String[] dependencies) {
    List<CompilationMessage> resolutionMessages = new ArrayList<>();
    for (String dependency : dependencies) {
        if (dependency.startsWith("maven:")) {
            // Resolving an explicit external archive
            String coordinates = dependency.replaceFirst("maven:\\/*", "");
            DependencyResolver engine = DependencyResolver.instance();
            try {
                File resolved = engine.resolve(new Dependency(new DefaultArtifact(coordinates), "runtime"));
                // Example:
                // dependency =
                // maven://org.springframework:spring-expression:4.3.9.RELEASE
                // resolved.toURI() =
                // file:/Users/aclement/.m2/repository/org/springframework/spring-expression/4.3.9.RELEASE/spring-expression-4.3.9.RELEASE.jar
                resolvedAdditionalDependencies.put(dependency, resolved);
            } catch (RuntimeException re) {
                CompilationMessage compilationMessage = new CompilationMessage(CompilationMessage.Kind.ERROR, re.getMessage(), null, 0, 0);
                resolutionMessages.add(compilationMessage);
            }
        } else if (dependency.startsWith("file:")) {
            resolvedAdditionalDependencies.put(dependency, new File(URI.create(dependency)));
        } else {
            resolutionMessages.add(new CompilationMessage(CompilationMessage.Kind.ERROR, "Unrecognized dependency: " + dependency + " (expected something of the form: maven://groupId:artifactId:version)", null, 0, 0));
        }
    }
    return resolutionMessages;
}
Also used : ArrayList(java.util.ArrayList) Dependency(org.eclipse.aether.graph.Dependency) ZipFile(java.util.zip.ZipFile) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 50 with Dependency

use of org.eclipse.aether.graph.Dependency in project pinpoint by naver.

the class DependencyResolver method resolveArtifactsAndDependencies.

public List<File> resolveArtifactsAndDependencies(List<Artifact> artifacts) throws DependencyResolutionException {
    List<Dependency> dependencies = new ArrayList<>();
    for (Artifact artifact : artifacts) {
        dependencies.add(new Dependency(artifact, JavaScopes.RUNTIME));
    }
    CollectRequest collectRequest = new CollectRequest((Dependency) null, dependencies, repositories);
    DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME);
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFilter);
    DependencyResult result = system.resolveDependencies(session, dependencyRequest);
    List<File> files = new ArrayList<>();
    for (ArtifactResult artifactResult : result.getArtifactResults()) {
        files.add(artifactResult.getArtifact().getFile());
    }
    return files;
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyResult(org.eclipse.aether.resolution.DependencyResult) ArrayList(java.util.ArrayList) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Aggregations

Dependency (org.eclipse.aether.graph.Dependency)55 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)37 Artifact (org.eclipse.aether.artifact.Artifact)34 File (java.io.File)25 CollectRequest (org.eclipse.aether.collection.CollectRequest)20 ArrayList (java.util.ArrayList)19 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)16 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)16 DependencyNode (org.eclipse.aether.graph.DependencyNode)15 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)15 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)13 ArtifactDescriptorResult (org.eclipse.aether.resolution.ArtifactDescriptorResult)13 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)13 MalformedURLException (java.net.MalformedURLException)12 Exclusion (org.eclipse.aether.graph.Exclusion)12 IOException (java.io.IOException)11 List (java.util.List)10 URL (java.net.URL)9 DependencyResolutionException (org.eclipse.aether.resolution.DependencyResolutionException)9 DependencyResult (org.eclipse.aether.resolution.DependencyResult)9