Search in sources :

Example 31 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project wildfly-swarm by wildfly-swarm.

the class MavenArtifactResolvingHelper method resolve.

@Override
public ArtifactSpec resolve(ArtifactSpec spec) {
    if (spec.file == null) {
        final DefaultArtifact artifact = new DefaultArtifact(spec.groupId(), spec.artifactId(), spec.classifier(), spec.type(), spec.version());
        final LocalArtifactResult localResult = this.session.getLocalRepositoryManager().find(this.session, new LocalArtifactRequest(artifact, this.remoteRepositories, null));
        if (localResult.isAvailable()) {
            spec.file = localResult.getFile();
        } else {
            try {
                final ArtifactResult result = resolver.resolveArtifact(this.session, new ArtifactRequest(artifact, this.remoteRepositories, null));
                if (result.isResolved()) {
                    spec.file = result.getArtifact().getFile();
                }
            } catch (ArtifactResolutionException e) {
                e.printStackTrace();
            }
        }
    }
    return spec.file != null ? spec : null;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) LocalArtifactRequest(org.eclipse.aether.repository.LocalArtifactRequest) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) LocalArtifactResult(org.eclipse.aether.repository.LocalArtifactResult) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) LocalArtifactRequest(org.eclipse.aether.repository.LocalArtifactRequest) LocalArtifactResult(org.eclipse.aether.repository.LocalArtifactResult) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 32 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project activemq-artemis by apache.

the class ArtemisAbstractPlugin method resolveArtifact.

protected File resolveArtifact(Artifact artifact) throws MojoExecutionException, DependencyCollectionException {
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(artifact);
    request.setRepositories(remoteRepos);
    ArtifactResult result;
    try {
        result = repositorySystem.resolveArtifact(repoSession, request);
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    return result.getArtifact().getFile();
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 33 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project storm by apache.

the class DependencyResolverTest method resolveValid.

@Test
public void resolveValid() throws Exception {
    // please pick small artifact which has small transitive dependency
    // and let's mark as Ignore if we want to run test even without internet or maven central is often not stable
    Dependency dependency = new Dependency(new DefaultArtifact("org.apache.storm:flux-core:1.0.0"), JavaScopes.COMPILE);
    List<ArtifactResult> results = sut.resolve(Lists.newArrayList(dependency));
    assertTrue(results.size() > 0);
    // it should be org.apache.storm:flux-core:jar:1.0.0 and commons-cli:commons-cli:jar:1.2
    assertContains(results, "org.apache.storm", "flux-core", "1.0.0");
    assertContains(results, "commons-cli", "commons-cli", "1.2");
}
Also used : Dependency(org.eclipse.aether.graph.Dependency) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Test(org.junit.Test)

Example 34 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project storm by apache.

the class DependencyResolverMain method transformArtifactResultToArtifactToPaths.

private static Map<String, String> transformArtifactResultToArtifactToPaths(List<ArtifactResult> artifactResults) {
    Map<String, String> artifactToPath = new LinkedHashMap<>();
    for (ArtifactResult artifactResult : artifactResults) {
        Artifact artifact = artifactResult.getArtifact();
        artifactToPath.put(AetherUtils.artifactToString(artifact), artifact.getFile().getAbsolutePath());
    }
    return artifactToPath;
}
Also used : Artifact(org.eclipse.aether.artifact.Artifact) LinkedHashMap(java.util.LinkedHashMap) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 35 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project storm by apache.

the class DependencyResolverMain method main.

/**
 * Main entry of dependency resolver.
 *
 * @param args console arguments
 * @throws ParseException If there's parsing error on option parse.
 * @throws MalformedURLException If proxy URL is malformed.
 */
public static void main(String[] args) throws ParseException, MalformedURLException {
    Options options = buildOptions();
    CommandLineParser parser = new DefaultParser();
    CommandLine commandLine = parser.parse(options, args);
    if (!commandLine.hasOption(OPTION_ARTIFACTS_LONG)) {
        throw new IllegalArgumentException("artifacts must be presented.");
    }
    String artifactsArg = commandLine.getOptionValue(OPTION_ARTIFACTS_LONG);
    // DO NOT CHANGE THIS TO SYSOUT
    System.err.println("DependencyResolver input - artifacts: " + artifactsArg);
    List<Dependency> dependencies = parseArtifactArgs(artifactsArg);
    List<RemoteRepository> repositories;
    if (commandLine.hasOption(OPTION_ARTIFACT_REPOSITORIES_LONG)) {
        String remoteRepositoryArg = commandLine.getOptionValue(OPTION_ARTIFACT_REPOSITORIES_LONG);
        // DO NOT CHANGE THIS TO SYSOUT
        System.err.println("DependencyResolver input - repositories: " + remoteRepositoryArg);
        repositories = parseRemoteRepositoryArgs(remoteRepositoryArg);
    } else {
        repositories = Collections.emptyList();
    }
    try {
        String localMavenRepoPath = getOrDefaultLocalMavenRepositoryPath(commandLine.getOptionValue(OPTION_MAVEN_LOCAL_REPOSITORY_DIRECTORY_LONG), DEFAULT_FAILBACK_MAVEN_LOCAL_REPOSITORY_DIRECTORY);
        // create root directory if not exist
        Files.createDirectories(new File(localMavenRepoPath).toPath());
        DependencyResolver resolver = new DependencyResolver(localMavenRepoPath, repositories);
        if (commandLine.hasOption(OPTION_PROXY_URL_LONG)) {
            String proxyUrl = commandLine.getOptionValue(OPTION_PROXY_URL_LONG);
            String proxyUsername = commandLine.getOptionValue(OPTION_PROXY_USERNAME_LONG);
            String proxyPassword = commandLine.getOptionValue(OPTION_PROXY_PASSWORD_LONG);
            resolver.setProxy(parseProxyArg(proxyUrl, proxyUsername, proxyPassword));
        }
        List<ArtifactResult> artifactResults = resolver.resolve(dependencies);
        Iterable<ArtifactResult> missingArtifacts = filterMissingArtifacts(artifactResults);
        if (missingArtifacts.iterator().hasNext()) {
            printMissingArtifactsToSysErr(missingArtifacts);
            throw new RuntimeException("Some artifacts are not resolved");
        }
        System.out.println(JSONValue.toJSONString(transformArtifactResultToArtifactToPaths(artifactResults)));
        System.out.flush();
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}
Also used : Options(org.apache.commons.cli.Options) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Dependency(org.eclipse.aether.graph.Dependency) DependencyResolver(org.apache.storm.submit.dependency.DependencyResolver) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) CommandLine(org.apache.commons.cli.CommandLine) CommandLineParser(org.apache.commons.cli.CommandLineParser) File(java.io.File) DefaultParser(org.apache.commons.cli.DefaultParser)

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