use of org.apache.maven.shared.dependencies.resolve.DependencyResolverException in project maven-dependency-plugin by apache.
the class PurgeLocalRepositoryMojo method getFilteredResolvedArtifacts.
private Set<Artifact> getFilteredResolvedArtifacts(MavenProject theProject, List<Dependency> dependencies, TransformableFilter filter) {
try {
Iterable<ArtifactResult> results = dependencyResolver.resolveDependencies(session.getProjectBuildingRequest(), theProject.getModel(), filter);
Set<Artifact> resolvedArtifacts = new LinkedHashSet<Artifact>();
for (ArtifactResult artResult : results) {
resolvedArtifacts.add(artResult.getArtifact());
}
return resolvedArtifacts;
} catch (DependencyResolverException e) {
getLog().info("Unable to resolve all dependencies for: " + theProject.getGroupId() + ":" + theProject.getArtifactId() + ":" + theProject.getVersion() + ". Falling back to non-transitive mode for initial artifact resolution.");
}
Set<Artifact> resolvedArtifacts = new LinkedHashSet<Artifact>();
ArtifactFilter artifactFilter = filter.transform(new ArtifactIncludeFilterTransformer());
for (Dependency dependency : dependencies) {
DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
coordinate.setGroupId(dependency.getGroupId());
coordinate.setArtifactId(dependency.getArtifactId());
coordinate.setVersion(dependency.getVersion());
coordinate.setExtension(artifactHandlerManager.getArtifactHandler(dependency.getType()).getExtension());
try {
Artifact artifact = artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), coordinate).getArtifact();
if (artifactFilter.include(artifact)) {
resolvedArtifacts.add(artifact);
}
} catch (ArtifactResolverException e) {
getLog().debug("Unable to resolve artifact: " + coordinate);
}
}
return resolvedArtifacts;
}
use of org.apache.maven.shared.dependencies.resolve.DependencyResolverException in project maven-dependency-plugin 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.dependencies.resolve.DependencyResolverException in project maven-plugins by apache.
the class InstallMojo method installExtraArtifacts.
private void installExtraArtifacts(String[] extraArtifacts) throws MojoExecutionException {
if (extraArtifacts == null) {
return;
}
for (String extraArtifact : extraArtifacts) {
String[] gav = extraArtifact.split(":");
if (gav.length < 3 || gav.length > 5) {
throw new MojoExecutionException("Invalid artifact " + extraArtifact);
}
String groupId = gav[0];
String artifactId = gav[1];
String version = gav[2];
String type = "jar";
if (gav.length > 3) {
type = gav[3];
}
String classifier = null;
if (gav.length == 5) {
classifier = gav[4];
}
DefaultDependableCoordinate coordinate = new DefaultDependableCoordinate();
try {
coordinate.setGroupId(groupId);
coordinate.setArtifactId(artifactId);
coordinate.setVersion(version);
coordinate.setType(type);
coordinate.setClassifier(classifier);
resolver.resolveDependencies(projectBuildingRequest, coordinate, null);
} catch (DependencyResolverException e) {
throw new MojoExecutionException("Unable to resolve dependencies for: " + coordinate, e);
}
}
}
use of org.apache.maven.shared.dependencies.resolve.DependencyResolverException in project maven-plugins by apache.
the class PurgeLocalRepositoryMojo method getFilteredResolvedArtifacts.
private Set<Artifact> getFilteredResolvedArtifacts(MavenProject project, List<Dependency> dependencies, TransformableFilter filter) {
try {
Iterable<ArtifactResult> results = dependencyResolver.resolveDependencies(session.getProjectBuildingRequest(), project.getModel(), filter);
Set<Artifact> resolvedArtifacts = new LinkedHashSet<Artifact>();
for (ArtifactResult artResult : results) {
resolvedArtifacts.add(artResult.getArtifact());
}
return resolvedArtifacts;
} catch (DependencyResolverException e) {
getLog().info("Unable to resolve all dependencies for: " + project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion() + ". Falling back to non-transitive mode for initial artifact resolution.");
}
Set<Artifact> resolvedArtifacts = new LinkedHashSet<Artifact>();
ArtifactFilter artifactFilter = filter.transform(new ArtifactIncludeFilterTransformer());
for (Dependency dependency : dependencies) {
DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
coordinate.setGroupId(dependency.getGroupId());
coordinate.setArtifactId(dependency.getArtifactId());
coordinate.setVersion(dependency.getVersion());
coordinate.setExtension(artifactHandlerManager.getArtifactHandler(dependency.getType()).getExtension());
try {
Artifact artifact = artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), coordinate).getArtifact();
if (artifactFilter.include(artifact)) {
resolvedArtifacts.add(artifact);
}
} catch (ArtifactResolverException e) {
getLog().debug("Unable to resolve artifact: " + coordinate);
}
}
return resolvedArtifacts;
}
use of org.apache.maven.shared.dependencies.resolve.DependencyResolverException in project maven-plugins by apache.
the class AbstractJavadocMojo method getArtifactsAbsolutePath.
/**
* Return the Javadoc artifact path and its transitive dependencies path from the local repository
*
* @param javadocArtifact not null
* @return a list of locale artifacts absolute path
* @throws MavenReportException if any
*/
private List<String> getArtifactsAbsolutePath(JavadocPathArtifact javadocArtifact) throws MavenReportException {
if ((StringUtils.isEmpty(javadocArtifact.getGroupId())) && (StringUtils.isEmpty(javadocArtifact.getArtifactId())) && (StringUtils.isEmpty(javadocArtifact.getVersion()))) {
return Collections.emptyList();
}
List<String> path = new ArrayList<>();
try {
Artifact artifact = createAndResolveArtifact(javadocArtifact);
path.add(artifact.getFile().getAbsolutePath());
DefaultDependableCoordinate coordinate = new DefaultDependableCoordinate();
coordinate.setGroupId(javadocArtifact.getGroupId());
coordinate.setArtifactId(javadocArtifact.getArtifactId());
coordinate.setVersion(javadocArtifact.getVersion());
Iterable<ArtifactResult> deps = dependencyResolver.resolveDependencies(session.getProjectBuildingRequest(), coordinate, ScopeFilter.including("compile", "provided"));
for (ArtifactResult a : deps) {
path.add(a.getArtifact().getFile().getAbsolutePath());
}
return path;
} catch (ArtifactResolverException e) {
throw new MavenReportException("Unable to resolve artifact:" + javadocArtifact, e);
} catch (DependencyResolverException e) {
throw new MavenReportException("Unable to resolve dependencies for:" + javadocArtifact, e);
}
}
Aggregations