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);
}
}
}
}
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;
}
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.");
}
}
}
}
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;
}
Aggregations