Search in sources :

Example 6 with ArtifactFilterException

use of org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException 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 7 with ArtifactFilterException

use of org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException in project maven-plugins by apache.

the class AbstractDependencyFilterMojo method getDependencySets.

/**
     * Method creates filters and filters the projects dependencies. This method
     * also transforms the dependencies if classifier is set. The dependencies
     * are filtered in least specific to most specific order
     *
     * @param stopOnFailure
     * @return DependencyStatusSets - Bean of TreeSets that contains information
     *         on the projects dependencies
     * @throws MojoExecutionException
     */
protected DependencyStatusSets getDependencySets(boolean stopOnFailure, boolean includeParents) throws MojoExecutionException {
    // add filters in well known order, least specific to most specific
    FilterArtifacts filter = new FilterArtifacts();
    filter.addFilter(new ProjectTransitivityFilter(getProject().getDependencyArtifacts(), this.excludeTransitive));
    filter.addFilter(new ScopeFilter(DependencyUtil.cleanToBeTokenizedString(this.includeScope), DependencyUtil.cleanToBeTokenizedString(this.excludeScope)));
    filter.addFilter(new TypeFilter(DependencyUtil.cleanToBeTokenizedString(this.includeTypes), DependencyUtil.cleanToBeTokenizedString(this.excludeTypes)));
    filter.addFilter(new ClassifierFilter(DependencyUtil.cleanToBeTokenizedString(this.includeClassifiers), DependencyUtil.cleanToBeTokenizedString(this.excludeClassifiers)));
    filter.addFilter(new GroupIdFilter(DependencyUtil.cleanToBeTokenizedString(this.includeGroupIds), DependencyUtil.cleanToBeTokenizedString(this.excludeGroupIds)));
    filter.addFilter(new ArtifactIdFilter(DependencyUtil.cleanToBeTokenizedString(this.includeArtifactIds), DependencyUtil.cleanToBeTokenizedString(this.excludeArtifactIds)));
    // start with all artifacts.
    Set<Artifact> artifacts = getProject().getArtifacts();
    if (includeParents) {
        // add dependencies parents
        for (Artifact dep : new ArrayList<Artifact>(artifacts)) {
            addParentArtifacts(buildProjectFromArtifact(dep), artifacts);
        }
        // add current project parent
        addParentArtifacts(getProject(), artifacts);
    }
    // perform filtering
    try {
        artifacts = filter.filter(artifacts);
    } catch (ArtifactFilterException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    // transform artifacts if classifier is set
    DependencyStatusSets status;
    if (StringUtils.isNotEmpty(classifier)) {
        status = getClassifierTranslatedDependencies(artifacts, stopOnFailure);
    } else {
        status = filterMarkedDependencies(artifacts);
    }
    return status;
}
Also used : ArtifactIdFilter(org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter) ProjectTransitivityFilter(org.apache.maven.shared.artifact.filter.collection.ProjectTransitivityFilter) ClassifierFilter(org.apache.maven.shared.artifact.filter.collection.ClassifierFilter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) TypeFilter(org.apache.maven.shared.artifact.filter.collection.TypeFilter) DependencyStatusSets(org.apache.maven.plugins.dependency.utils.DependencyStatusSets) Artifact(org.apache.maven.artifact.Artifact) ArtifactFilterException(org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException) ScopeFilter(org.apache.maven.shared.artifact.filter.collection.ScopeFilter) FilterArtifacts(org.apache.maven.shared.artifact.filter.collection.FilterArtifacts) GroupIdFilter(org.apache.maven.shared.artifact.filter.collection.GroupIdFilter)

Aggregations

MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 ArtifactFilterException (org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException)7 Artifact (org.apache.maven.artifact.Artifact)6 FilterArtifacts (org.apache.maven.shared.artifact.filter.collection.FilterArtifacts)3 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 DependencyStatusSets (org.apache.maven.plugins.dependency.utils.DependencyStatusSets)2 ArtifactIdFilter (org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter)2 GroupIdFilter (org.apache.maven.shared.artifact.filter.collection.GroupIdFilter)2 ProjectTransitivityFilter (org.apache.maven.shared.artifact.filter.collection.ProjectTransitivityFilter)2 ScopeFilter (org.apache.maven.shared.artifact.filter.collection.ScopeFilter)2 IOException (java.io.IOException)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 VersionRange (org.apache.maven.artifact.versioning.VersionRange)1 Model (org.apache.maven.model.Model)1 InvalidProjectModelException (org.apache.maven.project.InvalidProjectModelException)1 MavenProject (org.apache.maven.project.MavenProject)1 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)1 ClassifierFilter (org.apache.maven.shared.artifact.filter.collection.ClassifierFilter)1 TypeFilter (org.apache.maven.shared.artifact.filter.collection.TypeFilter)1