Search in sources :

Example 1 with ProjectTransitivityFilter

use of org.apache.maven.shared.artifact.filter.collection.ProjectTransitivityFilter in project maven-dependency-plugin 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 true to fail if artifacts can't be resolved false otherwise.
 * @param includeParents <code>true</code> if parents should be included or not <code>false</code>.
 * @return DependencyStatusSets - Bean of TreeSets that contains information on the projects dependencies
 * @throws MojoExecutionException in case of errors.
 */
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)

Example 2 with ProjectTransitivityFilter

use of org.apache.maven.shared.artifact.filter.collection.ProjectTransitivityFilter 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 true to fail if artifacts can't be resolved false otherwise.
 * @param includeParents <code>true</code> if parents should be included or not <code>false</code>.
 * @return DependencyStatusSets - Bean of TreeSets that contains information on the projects dependencies
 * @throws MojoExecutionException in case of errors.
 */
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)

Example 3 with ProjectTransitivityFilter

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

the class ProcessRemoteResourcesMojo method getProjects.

@SuppressWarnings("unchecked")
protected List<MavenProject> getProjects() throws MojoExecutionException {
    List<MavenProject> projects = new ArrayList<MavenProject>();
    // add filters in well known order, least specific to most specific
    FilterArtifacts filter = new FilterArtifacts();
    Set<Artifact> artifacts = resolveProjectArtifacts();
    if (this.excludeTransitive) {
        Set<Artifact> depArtifacts;
        if (runOnlyAtExecutionRoot) {
            depArtifacts = aggregateProjectDependencyArtifacts();
        } else {
            depArtifacts = project.getDependencyArtifacts();
        }
        filter.addFilter(new ProjectTransitivityFilter(depArtifacts, true));
    }
    filter.addFilter(new ScopeFilter(this.includeScope, this.excludeScope));
    filter.addFilter(new GroupIdFilter(this.includeGroupIds, this.excludeGroupIds));
    filter.addFilter(new ArtifactIdFilter(this.includeArtifactIds, this.excludeArtifactIds));
    // perform filtering
    try {
        artifacts = filter.filter(artifacts);
    } catch (ArtifactFilterException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    for (Artifact artifact : artifacts) {
        try {
            List<ArtifactRepository> remoteRepo = remoteArtifactRepositories;
            if (artifact.isSnapshot()) {
                VersionRange rng = VersionRange.createFromVersion(artifact.getBaseVersion());
                artifact = artifactFactory.createDependencyArtifact(artifact.getGroupId(), artifact.getArtifactId(), rng, artifact.getType(), artifact.getClassifier(), artifact.getScope(), null, artifact.isOptional());
            }
            getLog().debug("Building project for " + artifact);
            MavenProject p;
            try {
                p = mavenProjectBuilder.buildFromRepository(artifact, remoteRepo, localRepository);
            } catch (InvalidProjectModelException e) {
                getLog().warn("Invalid project model for artifact [" + artifact.getArtifactId() + ":" + artifact.getGroupId() + ":" + artifact.getVersion() + "]. " + "It will be ignored by the remote resources Mojo.");
                continue;
            }
            String supplementKey = generateSupplementMapKey(p.getModel().getGroupId(), p.getModel().getArtifactId());
            if (supplementModels.containsKey(supplementKey)) {
                Model mergedModel = mergeModels(p.getModel(), supplementModels.get(supplementKey));
                MavenProject mergedProject = new MavenProject(mergedModel);
                projects.add(mergedProject);
                mergedProject.setArtifact(artifact);
                mergedProject.setVersion(artifact.getVersion());
                getLog().debug("Adding project with groupId [" + mergedProject.getGroupId() + "] (supplemented)");
            } else {
                projects.add(p);
                getLog().debug("Adding project with groupId [" + p.getGroupId() + "]");
            }
        } catch (ProjectBuildingException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
    Collections.sort(projects, new ProjectComparator());
    return projects;
}
Also used : InvalidProjectModelException(org.apache.maven.project.InvalidProjectModelException) ArtifactIdFilter(org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) ProjectTransitivityFilter(org.apache.maven.shared.artifact.filter.collection.ProjectTransitivityFilter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) VersionRange(org.apache.maven.artifact.versioning.VersionRange) Artifact(org.apache.maven.artifact.Artifact) ArtifactFilterException(org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException) ScopeFilter(org.apache.maven.shared.artifact.filter.collection.ScopeFilter) MavenProject(org.apache.maven.project.MavenProject) FilterArtifacts(org.apache.maven.shared.artifact.filter.collection.FilterArtifacts) Model(org.apache.maven.model.Model) GroupIdFilter(org.apache.maven.shared.artifact.filter.collection.GroupIdFilter)

Aggregations

ArrayList (java.util.ArrayList)3 Artifact (org.apache.maven.artifact.Artifact)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 ArtifactFilterException (org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException)3 ArtifactIdFilter (org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter)3 FilterArtifacts (org.apache.maven.shared.artifact.filter.collection.FilterArtifacts)3 GroupIdFilter (org.apache.maven.shared.artifact.filter.collection.GroupIdFilter)3 ProjectTransitivityFilter (org.apache.maven.shared.artifact.filter.collection.ProjectTransitivityFilter)3 ScopeFilter (org.apache.maven.shared.artifact.filter.collection.ScopeFilter)3 DependencyStatusSets (org.apache.maven.plugins.dependency.utils.DependencyStatusSets)2 ClassifierFilter (org.apache.maven.shared.artifact.filter.collection.ClassifierFilter)2 TypeFilter (org.apache.maven.shared.artifact.filter.collection.TypeFilter)2 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