Search in sources :

Example 1 with DefaultDependableCoordinate

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);
    }
}
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 2 with DefaultDependableCoordinate

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);
        }
    }
}
Also used : DefaultDependableCoordinate(org.apache.maven.shared.dependencies.DefaultDependableCoordinate) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException)

Example 3 with DefaultDependableCoordinate

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);
    }
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) DefaultDependableCoordinate(org.apache.maven.shared.dependencies.DefaultDependableCoordinate) ArrayList(java.util.ArrayList) DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) BootclasspathArtifact(org.apache.maven.plugins.javadoc.options.BootclasspathArtifact) JavadocPathArtifact(org.apache.maven.plugins.javadoc.options.JavadocPathArtifact) ResourcesArtifact(org.apache.maven.plugins.javadoc.options.ResourcesArtifact) Artifact(org.apache.maven.artifact.Artifact) TagletArtifact(org.apache.maven.plugins.javadoc.options.TagletArtifact) DocletArtifact(org.apache.maven.plugins.javadoc.options.DocletArtifact) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 4 with DefaultDependableCoordinate

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);
    }
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) DefaultDependableCoordinate(org.apache.maven.shared.dependencies.DefaultDependableCoordinate) ArrayList(java.util.ArrayList) DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) JavadocPathArtifact(org.apache.maven.plugin.javadoc.options.JavadocPathArtifact) Artifact(org.apache.maven.artifact.Artifact) DocletArtifact(org.apache.maven.plugin.javadoc.options.DocletArtifact) BootclasspathArtifact(org.apache.maven.plugin.javadoc.options.BootclasspathArtifact) ResourcesArtifact(org.apache.maven.plugin.javadoc.options.ResourcesArtifact) TagletArtifact(org.apache.maven.plugin.javadoc.options.TagletArtifact) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 5 with DefaultDependableCoordinate

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

Aggregations

DefaultDependableCoordinate (org.apache.maven.shared.dependencies.DefaultDependableCoordinate)5 DependencyResolverException (org.apache.maven.shared.dependencies.resolve.DependencyResolverException)5 Artifact (org.apache.maven.artifact.Artifact)4 ArtifactResolverException (org.apache.maven.shared.artifact.resolve.ArtifactResolverException)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 MavenReportException (org.apache.maven.reporting.MavenReportException)2 ArtifactFilterException (org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException)2 ArtifactResult (org.apache.maven.shared.artifact.resolve.ArtifactResult)2 BootclasspathArtifact (org.apache.maven.plugin.javadoc.options.BootclasspathArtifact)1 DocletArtifact (org.apache.maven.plugin.javadoc.options.DocletArtifact)1 JavadocPathArtifact (org.apache.maven.plugin.javadoc.options.JavadocPathArtifact)1 ResourcesArtifact (org.apache.maven.plugin.javadoc.options.ResourcesArtifact)1 TagletArtifact (org.apache.maven.plugin.javadoc.options.TagletArtifact)1 BootclasspathArtifact (org.apache.maven.plugins.javadoc.options.BootclasspathArtifact)1 DocletArtifact (org.apache.maven.plugins.javadoc.options.DocletArtifact)1 JavadocPathArtifact (org.apache.maven.plugins.javadoc.options.JavadocPathArtifact)1 ResourcesArtifact (org.apache.maven.plugins.javadoc.options.ResourcesArtifact)1 TagletArtifact (org.apache.maven.plugins.javadoc.options.TagletArtifact)1