Search in sources :

Example 1 with PatternIncludesArtifactFilter

use of org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter in project randomizedtesting by randomizedtesting.

the class JUnit4Mojo method setupTestClasspath.

/**
 * Setup the classpath used for tests.
 */
private void setupTestClasspath(Element junit4) {
    junit4.addComment("Runtime classpath.");
    Element cp = junit4.addElement("classpath");
    // Test classes.
    cp.addComment("Test classes directory.");
    cp.addElement("pathelement").addAttribute("location", testClassesDirectory.getAbsolutePath());
    // Classes directory.
    cp.addComment("Test classes directory.");
    cp.addElement("pathelement").addAttribute("location", classesDirectory.getAbsolutePath());
    // Project dependencies.
    cp.addComment("Project dependencies.");
    Set<Artifact> classpathArtifacts = (Set<Artifact>) project.getArtifacts();
    if (!Strings.isNullOrEmpty(classpathDependencyScopeExclude)) {
        classpathArtifacts = filterArtifacts(cp, classpathArtifacts, new ScopeArtifactFilter(classpathDependencyScopeExclude));
    }
    if (classpathDependencyExcludes != null && !classpathDependencyExcludes.isEmpty()) {
        classpathArtifacts = filterArtifacts(cp, classpathArtifacts, new PatternIncludesArtifactFilter(classpathDependencyExcludes));
    }
    for (Artifact artifact : classpathArtifacts) {
        if (artifact.getArtifactHandler().isAddedToClasspath()) {
            File file = artifact.getFile();
            if (file != null) {
                cp.addComment("Dependency artifact: " + artifact.getId());
                cp.addElement("pathelement").addAttribute("location", file.getAbsolutePath());
            }
        }
    }
    // Additional dependencies.
    cp.addComment("Additional classpath elements.");
    if (additionalClasspathElements != null && !additionalClasspathElements.isEmpty()) {
        for (String classpathElement : additionalClasspathElements) {
            if (!Strings.isNullOrEmpty(classpathElement)) {
                cp.addElement("pathelement").addAttribute("location", classpathElement);
            }
        }
    }
}
Also used : ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Element(org.dom4j.Element) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 2 with PatternIncludesArtifactFilter

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

the class DefaultRepositoryAssembler method buildRepositoryFilter.

private ArtifactFilter buildRepositoryFilter(RepositoryInfo repository, MavenProject project) {
    AndArtifactFilter filter = new AndArtifactFilter();
    ArtifactFilter scopeFilter = new ScopeArtifactFilter(repository.getScope());
    filter.add(scopeFilter);
    // ----------------------------------------------------------------------------
    // Includes
    // 
    // We'll take everything if no includes are specified to try and make
    // this
    // process more maintainable. Don't want to have to update the assembly
    // descriptor everytime the POM is updated.
    // ----------------------------------------------------------------------------
    List<String> includes = repository.getIncludes();
    if ((includes == null) || includes.isEmpty()) {
        List<String> patterns = new ArrayList<String>();
        Set<Artifact> projectArtifacts = project.getDependencyArtifacts();
        if (projectArtifacts != null) {
            for (Artifact artifact : projectArtifacts) {
                patterns.add(artifact.getDependencyConflictId());
            }
        }
        PatternIncludesArtifactFilter includeFilter = new PatternIncludesArtifactFilter(patterns, true);
        filter.add(includeFilter);
    } else {
        filter.add(new PatternIncludesArtifactFilter(repository.getIncludes(), true));
    }
    // ----------------------------------------------------------------------------
    // Excludes
    // 
    // We still want to make it easy to exclude a few things even if we
    // slurp
    // up everything.
    // ----------------------------------------------------------------------------
    List<String> excludes = repository.getExcludes();
    if ((excludes != null) && !excludes.isEmpty()) {
        filter.add(new PatternExcludesArtifactFilter(repository.getExcludes(), true));
    }
    return filter;
}
Also used : ScopeArtifactFilter(org.apache.maven.shared.artifact.filter.ScopeArtifactFilter) PatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) ScopeArtifactFilter(org.apache.maven.shared.artifact.filter.ScopeArtifactFilter) PatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) ArrayList(java.util.ArrayList) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) Artifact(org.apache.maven.artifact.Artifact)

Example 3 with PatternIncludesArtifactFilter

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

the class FilterUtils method filterArtifacts.

public static void filterArtifacts(final Set<Artifact> artifacts, final List<String> includes, final List<String> excludes, final boolean strictFiltering, final boolean actTransitively, final Logger logger, final ArtifactFilter... additionalFilters) throws InvalidAssemblerConfigurationException {
    final List<ArtifactFilter> allFilters = new ArrayList<ArtifactFilter>();
    final AndArtifactFilter filter = new AndArtifactFilter();
    if (additionalFilters != null && additionalFilters.length > 0) {
        for (final ArtifactFilter additionalFilter : additionalFilters) {
            if (additionalFilter != null) {
                filter.add(additionalFilter);
            }
        }
    }
    if (!includes.isEmpty()) {
        final ArtifactFilter includeFilter = new PatternIncludesArtifactFilter(includes, actTransitively);
        filter.add(includeFilter);
        allFilters.add(includeFilter);
    }
    if (!excludes.isEmpty()) {
        final ArtifactFilter excludeFilter = new PatternExcludesArtifactFilter(excludes, actTransitively);
        filter.add(excludeFilter);
        allFilters.add(excludeFilter);
    }
    for (final Iterator<Artifact> it = artifacts.iterator(); it.hasNext(); ) {
        final Artifact artifact = it.next();
        if (!filter.include(artifact)) {
            it.remove();
            if (logger.isDebugEnabled()) {
                logger.debug(artifact.getId() + " was removed by one or more filters.");
            }
        }
    }
    reportFilteringStatistics(allFilters, logger);
    for (final ArtifactFilter f : allFilters) {
        if (f instanceof StatisticsReportingArtifactFilter) {
            final StatisticsReportingArtifactFilter sFilter = (StatisticsReportingArtifactFilter) f;
            if (strictFiltering && sFilter.hasMissedCriteria()) {
                throw new InvalidAssemblerConfigurationException("One or more filters had unmatched criteria. Check debug log for more information.");
            }
        }
    }
}
Also used : PatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) StatisticsReportingArtifactFilter(org.apache.maven.shared.artifact.filter.StatisticsReportingArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) PatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) ArrayList(java.util.ArrayList) StatisticsReportingArtifactFilter(org.apache.maven.shared.artifact.filter.StatisticsReportingArtifactFilter) InvalidAssemblerConfigurationException(org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) Artifact(org.apache.maven.artifact.Artifact)

Example 4 with PatternIncludesArtifactFilter

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

the class FilterUtils method filterProjects.

public static Set<MavenProject> filterProjects(final Set<MavenProject> projects, final List<String> includes, final List<String> excludes, final boolean actTransitively, final Logger logger) {
    final List<PatternIncludesArtifactFilter> allFilters = new ArrayList<PatternIncludesArtifactFilter>();
    final AndArtifactFilter filter = new AndArtifactFilter();
    if (!includes.isEmpty()) {
        final PatternIncludesArtifactFilter includeFilter = new PatternIncludesArtifactFilter(includes, actTransitively);
        filter.add(includeFilter);
        allFilters.add(includeFilter);
    }
    if (!excludes.isEmpty()) {
        final PatternExcludesArtifactFilter excludeFilter = new PatternExcludesArtifactFilter(excludes, actTransitively);
        filter.add(excludeFilter);
        allFilters.add(excludeFilter);
    }
    Set<MavenProject> result = new LinkedHashSet<MavenProject>(projects.size());
    for (MavenProject project : projects) {
        final Artifact artifact = project.getArtifact();
        if (filter.include(artifact)) {
            result.add(project);
        }
    }
    for (final PatternIncludesArtifactFilter f : allFilters) {
        if (f != null) {
            f.reportMissedCriteria(logger);
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MavenProject(org.apache.maven.project.MavenProject) PatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) ArrayList(java.util.ArrayList) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

Artifact (org.apache.maven.artifact.Artifact)4 PatternIncludesArtifactFilter (org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter)4 ArrayList (java.util.ArrayList)3 AndArtifactFilter (org.apache.maven.artifact.resolver.filter.AndArtifactFilter)3 PatternExcludesArtifactFilter (org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter)3 LinkedHashSet (java.util.LinkedHashSet)2 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)2 File (java.io.File)1 Set (java.util.Set)1 ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)1 InvalidAssemblerConfigurationException (org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException)1 MavenProject (org.apache.maven.project.MavenProject)1 ScopeArtifactFilter (org.apache.maven.shared.artifact.filter.ScopeArtifactFilter)1 StatisticsReportingArtifactFilter (org.apache.maven.shared.artifact.filter.StatisticsReportingArtifactFilter)1 Element (org.dom4j.Element)1