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());
}
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations