Search in sources :

Example 1 with FilterArtifacts

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

the class AbstractRunMojo method addDependencies.

private void addDependencies(List<URL> urls) throws MalformedURLException, MojoExecutionException {
    FilterArtifacts filters = this.useTestClasspath ? getFilters() : getFilters(new TestArtifactFilter());
    Set<Artifact> artifacts = filterDependencies(this.project.getArtifacts(), filters);
    for (Artifact artifact : artifacts) {
        if (artifact.getFile() != null) {
            urls.add(artifact.getFile().toURI().toURL());
        }
    }
}
Also used : FilterArtifacts(org.apache.maven.shared.artifact.filter.collection.FilterArtifacts) Artifact(org.apache.maven.artifact.Artifact)

Example 2 with FilterArtifacts

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

the class AbstractResolveMojo method getPluginArtifactsFilter.

/**
 * @return {@link FilterArtifacts}
 */
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 3 with FilterArtifacts

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

use of org.apache.maven.shared.artifact.filter.collection.FilterArtifacts in project maven-dependency-plugin 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 5 with FilterArtifacts

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

the class ResolvePluginsMojo method resolvePluginArtifacts.

/**
 * This method resolves the plugin artifacts from the project.
 *
 * @return set of resolved plugin artifacts.
 * @throws ArtifactFilterException in case of an error.
 * @throws ArtifactResolverException in case of an error.
 */
protected Set<Artifact> resolvePluginArtifacts() throws ArtifactFilterException, ArtifactResolverException {
    final Set<Artifact> plugins = getProject().getPluginArtifacts();
    final Set<Artifact> reports = getProject().getReportArtifacts();
    Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
    artifacts.addAll(reports);
    artifacts.addAll(plugins);
    final FilterArtifacts filter = getPluginArtifactsFilter();
    artifacts = filter.filter(artifacts);
    Set<Artifact> resolvedArtifacts = new LinkedHashSet<Artifact>(artifacts.size());
    // final ArtifactFilter filter = getPluginFilter();
    for (final Artifact artifact : new LinkedHashSet<Artifact>(artifacts)) {
        // if ( !filter.include( artifact ) )
        // {
        // final String logStr =
        // String.format( " Plugin SKIPPED: %s", DependencyUtil.getFormattedFileName( artifact, false ) );
        // 
        // if ( !silent )
        // {
        // this.getLog().info( logStr );
        // }
        // 
        // artifacts.remove( artifact );
        // continue;
        // }
        ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
        buildingRequest.setRemoteRepositories(this.remotePluginRepositories);
        // resolve the new artifact
        resolvedArtifacts.add(getArtifactResolver().resolveArtifact(buildingRequest, artifact).getArtifact());
    }
    return artifacts;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) FilterArtifacts(org.apache.maven.shared.artifact.filter.collection.FilterArtifacts) Artifact(org.apache.maven.artifact.Artifact) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

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