Search in sources :

Example 26 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-dependency-plugin by apache.

the class PurgeLocalRepositoryMojo method reResolveArtifacts.

private void reResolveArtifacts(MavenProject theProject, Set<Artifact> artifacts, ArtifactFilter filter) throws ArtifactResolutionException, ArtifactNotFoundException {
    // because Maven 2 will not automatically re-resolve them when resolving the artifact
    for (Artifact artifact : artifacts) {
        try {
            // CHECKSTYLE_OFF: LineLength
            artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), org.apache.maven.shared.artifact.TransferUtils.toArtifactCoordinate(artifact));
        // CHECKSTYLE_ON: LineLength
        } catch (ArtifactResolverException e) {
            verbose(e.getMessage());
        }
    }
    List<Artifact> missingArtifacts = new ArrayList<Artifact>();
    for (Artifact artifact : artifacts) {
        verbose("Resolving artifact: " + artifact.getId());
        try {
            artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), artifact);
        } catch (ArtifactResolverException e) {
            verbose(e.getMessage());
            missingArtifacts.add(artifact);
        }
    }
    if (missingArtifacts.size() > 0) {
        StringBuffer message = new StringBuffer("required artifacts missing:\n");
        for (Artifact missingArtifact : missingArtifacts) {
            message.append("  ").append(missingArtifact.getId()).append('\n');
        }
        message.append("\nfor the artifact:");
        throw new ArtifactResolutionException(message.toString(), theProject.getArtifact(), theProject.getRemoteArtifactRepositories());
    }
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact)

Example 27 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-dependency-plugin by apache.

the class GetMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (isSkip()) {
        getLog().info("Skipping plugin execution");
        return;
    }
    if (coordinate.getArtifactId() == null && artifact == null) {
        throw new MojoFailureException("You must specify an artifact, " + "e.g. -Dartifact=org.apache.maven.plugins:maven-downloader-plugin:1.0");
    }
    if (artifact != null) {
        String[] tokens = StringUtils.split(artifact, ":");
        if (tokens.length < 3 || tokens.length > 5) {
            throw new MojoFailureException("Invalid artifact, you must specify " + "groupId:artifactId:version[:packaging[:classifier]] " + artifact);
        }
        coordinate.setGroupId(tokens[0]);
        coordinate.setArtifactId(tokens[1]);
        coordinate.setVersion(tokens[2]);
        if (tokens.length >= 4) {
            coordinate.setType(tokens[3]);
        }
        if (tokens.length == 5) {
            coordinate.setClassifier(tokens[4]);
        }
    }
    ArtifactRepositoryPolicy always = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
    List<ArtifactRepository> repoList = new ArrayList<ArtifactRepository>();
    if (pomRemoteRepositories != null) {
        repoList.addAll(pomRemoteRepositories);
    }
    if (remoteRepositories != null) {
        // Use the same format as in the deploy plugin id::layout::url
        List<String> repos = Arrays.asList(StringUtils.split(remoteRepositories, ","));
        for (String repo : repos) {
            repoList.add(parseRepository(repo, always));
        }
    }
    try {
        ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
        buildingRequest.setRemoteRepositories(repoList);
        if (transitive) {
            getLog().info("Resolving " + coordinate + " with transitive dependencies");
            dependencyResolver.resolveDependencies(buildingRequest, coordinate, null);
        } else {
            getLog().info("Resolving " + coordinate);
            artifactResolver.resolveArtifact(buildingRequest, toArtifactCoordinate(coordinate));
        }
    } catch (ArtifactResolverException e) {
        throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
    } catch (DependencyResolverException e) {
        throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
    }
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArrayList(java.util.ArrayList) DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

Example 28 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins by apache.

the class ResolvePluginsMojo method doExecute.

/**
 * Main entry into mojo. Gets the list of dependencies and iterates through displaying the resolved version.
 *
 * @throws MojoExecutionException with a message if an error occurs.
 */
@Override
protected void doExecute() throws MojoExecutionException {
    try {
        // ideally this should either be DependencyCoordinates or DependencyNode
        final Set<Artifact> plugins = resolvePluginArtifacts();
        StringBuilder sb = new StringBuilder();
        sb.append("\n");
        sb.append("The following plugins have been resolved:\n");
        if (plugins == null || plugins.isEmpty()) {
            sb.append("   none\n");
        } else {
            for (Artifact plugin : plugins) {
                String artifactFilename = null;
                if (outputAbsoluteArtifactFilename) {
                    try {
                        // we want to print the absolute file name here
                        artifactFilename = plugin.getFile().getAbsoluteFile().getPath();
                    } catch (NullPointerException e) {
                        // ignore the null pointer, we'll output a null string
                        artifactFilename = null;
                    }
                }
                String id = plugin.toString();
                sb.append("   " + id + (outputAbsoluteArtifactFilename ? ":" + artifactFilename : "") + "\n");
                if (!excludeTransitive) {
                    DefaultDependableCoordinate pluginCoordinate = new DefaultDependableCoordinate();
                    pluginCoordinate.setGroupId(plugin.getGroupId());
                    pluginCoordinate.setArtifactId(plugin.getArtifactId());
                    pluginCoordinate.setVersion(plugin.getVersion());
                    for (final Artifact artifact : resolveArtifactDependencies(pluginCoordinate)) {
                        artifactFilename = null;
                        if (outputAbsoluteArtifactFilename) {
                            try {
                                // we want to print the absolute file name here
                                artifactFilename = artifact.getFile().getAbsoluteFile().getPath();
                            } catch (NullPointerException e) {
                                // ignore the null pointer, we'll output a null string
                                artifactFilename = null;
                            }
                        }
                        id = artifact.toString();
                        sb.append("      " + id + (outputAbsoluteArtifactFilename ? ":" + artifactFilename : "") + "\n");
                    }
                }
            }
            sb.append("\n");
            String output = sb.toString();
            if (outputFile == null) {
                DependencyUtil.log(output, getLog());
            } else {
                DependencyUtil.write(output, outputFile, appendOutput, getLog());
            }
        }
    } catch (final IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (final ArtifactFilterException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (ArtifactResolverException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (DependencyResolverException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
Also used : ArtifactFilterException(org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) DefaultDependableCoordinate(org.apache.maven.shared.dependencies.DefaultDependableCoordinate) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) IOException(java.io.IOException) Artifact(org.apache.maven.artifact.Artifact)

Example 29 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins by apache.

the class CopyDependenciesMojo method getResolvedPomArtifact.

protected Artifact getResolvedPomArtifact(Artifact artifact) {
    DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
    coordinate.setGroupId(artifact.getGroupId());
    coordinate.setArtifactId(artifact.getArtifactId());
    coordinate.setVersion(artifact.getVersion());
    coordinate.setExtension("pom");
    Artifact pomArtifact = null;
    // Resolve the pom artifact using repos
    try {
        ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
        pomArtifact = getArtifactResolver().resolveArtifact(buildingRequest, coordinate).getArtifact();
    } catch (ArtifactResolverException e) {
        getLog().info(e.getMessage());
    }
    return pomArtifact;
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate) Artifact(org.apache.maven.artifact.Artifact)

Example 30 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins by apache.

the class ShadeMojo method resolveArtifactSources.

private File resolveArtifactSources(Artifact artifact) {
    DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
    coordinate.setGroupId(artifact.getGroupId());
    coordinate.setArtifactId(artifact.getArtifactId());
    coordinate.setVersion(artifact.getVersion());
    coordinate.setExtension("jar");
    coordinate.setClassifier("sources");
    Artifact resolvedArtifact;
    try {
        resolvedArtifact = artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), coordinate).getArtifact();
    } catch (ArtifactResolverException e) {
        getLog().warn("Could not get sources for " + artifact);
        return null;
    }
    if (resolvedArtifact.isResolved()) {
        return resolvedArtifact.getFile();
    }
    return null;
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

ArtifactResolverException (org.apache.maven.shared.artifact.resolve.ArtifactResolverException)35 Artifact (org.apache.maven.artifact.Artifact)28 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)14 DefaultArtifactCoordinate (org.apache.maven.shared.artifact.DefaultArtifactCoordinate)13 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)12 ArrayList (java.util.ArrayList)11 DependencyResolverException (org.apache.maven.shared.dependencies.resolve.DependencyResolverException)9 IOException (java.io.IOException)8 LinkedHashSet (java.util.LinkedHashSet)8 MavenReportException (org.apache.maven.reporting.MavenReportException)8 File (java.io.File)7 ArtifactResult (org.apache.maven.shared.artifact.resolve.ArtifactResult)7 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)6 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)5 ArtifactIncludeFilterTransformer (org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer)4 DefaultDependableCoordinate (org.apache.maven.shared.dependencies.DefaultDependableCoordinate)4 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)3 BootclasspathArtifact (org.apache.maven.plugin.javadoc.options.BootclasspathArtifact)3 DocletArtifact (org.apache.maven.plugin.javadoc.options.DocletArtifact)3 JavadocPathArtifact (org.apache.maven.plugin.javadoc.options.JavadocPathArtifact)3