use of org.apache.maven.shared.dependencies.DefaultDependableCoordinate 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.DefaultDependableCoordinate 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.DefaultDependableCoordinate 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);
}
}
use of org.apache.maven.shared.dependencies.DefaultDependableCoordinate 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<String>();
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);
}
}
use of org.apache.maven.shared.dependencies.DefaultDependableCoordinate 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);
}
}
Aggregations