Search in sources :

Example 6 with FilterArtifacts

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

the class AbstractDependencyFilterMojo method filterMarkedDependencies.

/**
 * Filter the marked dependencies
 *
 * @param artifacts The artifacts set {@link Artifact}.
 * @return status set {@link DependencyStatusSets}.
 * @throws MojoExecutionException in case of an error.
 */
protected DependencyStatusSets filterMarkedDependencies(Set<Artifact> artifacts) throws MojoExecutionException {
    // remove files that have markers already
    FilterArtifacts filter = new FilterArtifacts();
    filter.clearFilters();
    filter.addFilter(getMarkedArtifactFilter());
    Set<Artifact> unMarkedArtifacts;
    try {
        unMarkedArtifacts = filter.filter(artifacts);
    } catch (ArtifactFilterException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    // calculate the skipped artifacts
    Set<Artifact> skippedArtifacts = new LinkedHashSet<Artifact>();
    skippedArtifacts.addAll(artifacts);
    skippedArtifacts.removeAll(unMarkedArtifacts);
    return new DependencyStatusSets(unMarkedArtifacts, null, skippedArtifacts);
}
Also used : ArtifactFilterException(org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException) LinkedHashSet(java.util.LinkedHashSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FilterArtifacts(org.apache.maven.shared.artifact.filter.collection.FilterArtifacts) DependencyStatusSets(org.apache.maven.plugins.dependency.utils.DependencyStatusSets) Artifact(org.apache.maven.artifact.Artifact)

Example 7 with FilterArtifacts

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

the class AbstractResolveMojo method getPluginArtifactsFilter.

protected FilterArtifacts getPluginArtifactsFilter() {
    if (excludeReactor) {
        final StringBuilder exAids = new StringBuilder();
        if (this.excludeArtifactIds != null) {
            exAids.append(this.excludeArtifactIds);
        }
        for (final MavenProject rp : reactorProjects) {
            if (!"maven-plugin".equals(rp.getPackaging())) {
                continue;
            }
            if (exAids.length() > 0) {
                exAids.append(",");
            }
            exAids.append(rp.getArtifactId());
        }
        this.excludeArtifactIds = exAids.toString();
    }
    final FilterArtifacts filter = new FilterArtifacts();
    // CHECKSTYLE_OFF: LineLength
    filter.addFilter(new org.apache.maven.shared.artifact.filter.collection.ScopeFilter(DependencyUtil.cleanToBeTokenizedString(this.includeScope), DependencyUtil.cleanToBeTokenizedString(this.excludeScope)));
    // CHECKSTYLE_ON: LineLength
    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)));
    return filter;
}
Also used : ArtifactIdFilter(org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter) MavenProject(org.apache.maven.project.MavenProject) ClassifierFilter(org.apache.maven.shared.artifact.filter.collection.ClassifierFilter) FilterArtifacts(org.apache.maven.shared.artifact.filter.collection.FilterArtifacts) TypeFilter(org.apache.maven.shared.artifact.filter.collection.TypeFilter) GroupIdFilter(org.apache.maven.shared.artifact.filter.collection.GroupIdFilter)

Example 8 with FilterArtifacts

use of org.apache.maven.shared.artifact.filter.collection.FilterArtifacts in project spring-boot by spring-projects.

the class AbstractDependencyFilterMojo method getFilters.

/**
	 * Return artifact filters configured for this MOJO.
	 * @param additionalFilters optional additional filters to apply
	 * @return the filters
	 */
protected final FilterArtifacts getFilters(ArtifactsFilter... additionalFilters) {
    FilterArtifacts filters = new FilterArtifacts();
    for (ArtifactsFilter additionalFilter : additionalFilters) {
        filters.addFilter(additionalFilter);
    }
    filters.addFilter(new ArtifactIdFilter("", cleanFilterConfig(this.excludeArtifactIds)));
    filters.addFilter(new MatchingGroupIdFilter(cleanFilterConfig(this.excludeGroupIds)));
    if (this.includes != null && !this.includes.isEmpty()) {
        filters.addFilter(new IncludeFilter(this.includes));
    }
    if (this.excludes != null && !this.excludes.isEmpty()) {
        filters.addFilter(new ExcludeFilter(this.excludes));
    }
    return filters;
}
Also used : ArtifactIdFilter(org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter) FilterArtifacts(org.apache.maven.shared.artifact.filter.collection.FilterArtifacts) ArtifactsFilter(org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter)

Example 9 with FilterArtifacts

use of org.apache.maven.shared.artifact.filter.collection.FilterArtifacts in project m2e-nar by maven-nar.

the class AbstractDependencyMojo method prepareNarArtifacts.

@SuppressWarnings("unchecked")
public void prepareNarArtifacts(final ConfiguratorContext context, IMavenProjectFacade facade, IProgressMonitor monitor) throws MojoExecutionException, CoreException, MojoFailureException {
    narDependencies = new LinkedList<NarArtifact>();
    FilterArtifacts filter = new FilterArtifacts();
    filter.addFilter(new GroupIdFilter(cleanToBeTokenizedString(this.includeGroupIds), cleanToBeTokenizedString(this.excludeGroupIds)));
    filter.addFilter(new ArtifactIdFilter(cleanToBeTokenizedString(this.includeArtifactIds), cleanToBeTokenizedString(this.excludeArtifactIds)));
    filter.addFilter(getArtifactScopeFilter());
    Set<Artifact> artifacts = getMavenProject().getArtifacts();
    // perform filtering
    try {
        artifacts = filter.filter(artifacts);
    } catch (ArtifactFilterException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    for (final Artifact dependency : artifacts) {
        getLog().debug("Examining artifact for NarInfo: " + dependency);
        NarLayout layout;
        EclipseNarLayout eclipseLayout = resolveEclipseProject(dependency, context, facade, monitor);
        NarInfo narInfo;
        if (eclipseLayout != null) {
            layout = eclipseLayout;
            narInfo = getNarInfo(dependency, eclipseLayout);
        } else {
            layout = getLayout();
            narInfo = getNarInfo(dependency);
        }
        if (narInfo != null) {
            getLog().debug("    - added as NarDependency");
            narDependencies.add(new NarArtifact(dependency, narInfo, layout));
        }
    }
    getLog().debug("Dependencies contained " + narDependencies.size() + " NAR artifacts.");
}
Also used : ArtifactFilterException(org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException) ArtifactIdFilter(org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FilterArtifacts(org.apache.maven.shared.artifact.filter.collection.FilterArtifacts) GroupIdFilter(org.apache.maven.shared.artifact.filter.collection.GroupIdFilter) Artifact(org.apache.maven.artifact.Artifact)

Example 10 with FilterArtifacts

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

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