Search in sources :

Example 26 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project launcher by runelite.

the class ArtifactResolverTest method test.

@Test
@Ignore
public void test() throws Exception {
    ArtifactResolver resolver = new ArtifactResolver(folder.newFolder());
    resolver.addRepositories();
    Artifact a = new DefaultArtifact("net.runelite", "client", "", "jar", "1.0.0-SNAPSHOT");
    List<ArtifactResult> artifacts = resolver.resolveArtifacts(a);
    for (ArtifactResult a2 : artifacts) System.out.println(a2.getArtifact().getFile());
}
Also used : DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 27 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project mule by mulesoft.

the class DefaultRepositoryService method lookupBundle.

@Override
public File lookupBundle(BundleDependency bundleDependency) {
    try {
        if (remoteRepositories.isEmpty()) {
            throw new RepositoryServiceDisabledException("Repository service has not been configured so it's disabled. " + "To enable it you must configure the set of repositories to use using the system property: " + MULE_REMOTE_REPOSITORIES_PROPERTY);
        }
        DefaultArtifact artifact = toArtifact(bundleDependency);
        ArtifactRequest getArtifactRequest = new ArtifactRequest();
        getArtifactRequest.setRepositories(remoteRepositories);
        getArtifactRequest.setArtifact(artifact);
        ArtifactResult artifactResult = repositorySystem.resolveArtifact(repositorySystemSession, getArtifactRequest);
        return artifactResult.getArtifact().getFile();
    } catch (ArtifactResolutionException e) {
        if (e.getCause() instanceof ArtifactNotFoundException) {
            throw new BundleNotFoundException(e);
        } else {
            throw new RepositoryConnectionException("There was a problem connecting to one of the repositories", e);
        }
    }
}
Also used : RepositoryConnectionException(org.mule.runtime.module.repository.api.RepositoryConnectionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) RepositoryServiceDisabledException(org.mule.runtime.module.repository.api.RepositoryServiceDisabledException) ArtifactNotFoundException(org.eclipse.aether.transfer.ArtifactNotFoundException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) BundleNotFoundException(org.mule.runtime.module.repository.api.BundleNotFoundException)

Example 28 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project mule by mulesoft.

the class ExtensionModelLoaderFinder method findLoaderByProperty.

/**
 * Searches in the plugin pom.xml for the {@code testExtensionModelLoaderId} property which specifies with which loader the
 * extension must be loaded. The main use of this is for Test Extensions that don't generate a mule-artifact.json.
 */
public Optional<ExtensionModelLoader> findLoaderByProperty(Artifact plugin, DependencyResolver dependencyResolver, List<RemoteRepository> rootArtifactRemoteRepositories) {
    DefaultArtifact artifact = new DefaultArtifact(plugin.getGroupId(), plugin.getArtifactId(), "pom", plugin.getVersion());
    try {
        ArtifactResult artifactResult = dependencyResolver.resolveArtifact(artifact, rootArtifactRemoteRepositories);
        File pomFile = artifactResult.getArtifact().getFile();
        Model mavenProject = MavenModelFactory.createMavenProject(pomFile);
        String id = mavenProject.getProperties().getProperty("testExtensionModelLoaderId");
        return id != null ? Optional.ofNullable(getLoaderById(id)) : Optional.empty();
    } catch (ArtifactResolutionException e) {
        throw new RuntimeException("Cannot load extension, the artifact: [" + plugin.toString() + "] cannot be resolved", e);
    }
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) Model(org.apache.maven.model.Model) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 29 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult 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 30 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult 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)

Aggregations

ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)83 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)53 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)51 Artifact (org.eclipse.aether.artifact.Artifact)41 File (java.io.File)37 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)37 IOException (java.io.IOException)16 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)16 ArrayList (java.util.ArrayList)15 Dependency (org.eclipse.aether.graph.Dependency)15 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)13 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)13 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)12 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)11 CollectRequest (org.eclipse.aether.collection.CollectRequest)11 ArtifactDescriptorResult (org.eclipse.aether.resolution.ArtifactDescriptorResult)10 FileNotFoundException (java.io.FileNotFoundException)9 RepositorySystem (org.eclipse.aether.RepositorySystem)8 Test (org.junit.Test)8 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)7