use of org.apache.maven.artifact.resolver.filter.AndArtifactFilter in project felix by apache.
the class AbstractDependencyFilter method processInstructions.
protected final void processInstructions(String header) throws MojoExecutionException {
Map<String, Attrs> instructions = OSGiHeader.parseHeader(MISSING_KEY_PATTERN.matcher(header).replaceAll("$1$2*;$3"));
Collection<Artifact> availableDependencies = new LinkedHashSet<Artifact>(m_dependencyArtifacts);
for (Iterator<Map.Entry<String, Attrs>> clauseIterator = instructions.entrySet().iterator(); clauseIterator.hasNext(); ) {
String inline = "false";
// always start with a fresh *modifiable* collection for each unique clause
Collection<Artifact> filteredDependencies = new LinkedHashSet<Artifact>(availableDependencies);
// CLAUSE: REGEXP --> { ATTRIBUTE MAP }
Map.Entry<String, Attrs> clause = clauseIterator.next();
String primaryKey = clause.getKey().replaceFirst("~+$", "");
boolean isNegative = primaryKey.startsWith("!");
if (isNegative) {
primaryKey = primaryKey.substring(1);
}
final AndArtifactFilter andArtifactFilter = new AndArtifactFilter();
if (!"*".equals(primaryKey)) {
ArtifactFilter filter = new DependencyFilter(primaryKey) {
@Override
public boolean include(Artifact dependency) {
return super.matches(dependency.getArtifactId());
}
};
// FILTER ON MAIN CLAUSE
andArtifactFilter.add(filter);
}
for (Iterator<Map.Entry<String, String>> attrIterator = clause.getValue().entrySet().iterator(); attrIterator.hasNext(); ) {
final ArtifactFilter filter;
// ATTRIBUTE: KEY --> REGEXP
Map.Entry<String, String> attr = attrIterator.next();
if ("groupId".equals(attr.getKey())) {
filter = new DependencyFilter(attr.getValue()) {
@Override
public boolean include(Artifact dependency) {
return super.matches(dependency.getGroupId());
}
};
} else if ("artifactId".equals(attr.getKey())) {
filter = new DependencyFilter(attr.getValue()) {
@Override
public boolean include(Artifact dependency) {
return super.matches(dependency.getArtifactId());
}
};
} else if ("version".equals(attr.getKey())) {
filter = new DependencyFilter(attr.getValue()) {
@Override
public boolean include(Artifact dependency) {
try {
// use the symbolic version if available (ie. 1.0.0-SNAPSHOT)
return super.matches(dependency.getSelectedVersion().toString());
} catch (Exception e) {
return super.matches(dependency.getVersion());
}
}
};
} else if ("scope".equals(attr.getKey())) {
filter = new DependencyFilter(attr.getValue(), "compile") {
@Override
public boolean include(Artifact dependency) {
return super.matches(dependency.getScope());
}
};
} else if ("type".equals(attr.getKey())) {
filter = new DependencyFilter(attr.getValue(), "jar") {
@Override
public boolean include(Artifact dependency) {
return super.matches(dependency.getType());
}
};
} else if ("classifier".equals(attr.getKey())) {
filter = new DependencyFilter(attr.getValue()) {
@Override
public boolean include(Artifact dependency) {
return super.matches(dependency.getClassifier());
}
};
} else if ("optional".equals(attr.getKey())) {
filter = new DependencyFilter(attr.getValue(), "false") {
@Override
public boolean include(Artifact dependency) {
return super.matches("" + dependency.isOptional());
}
};
} else if ("inline".equals(attr.getKey())) {
inline = attr.getValue();
continue;
} else {
throw new MojoExecutionException("Unexpected attribute " + attr.getKey());
}
// FILTER ON EACH ATTRIBUTE
andArtifactFilter.add(filter);
}
filteredDependencies(andArtifactFilter, filteredDependencies);
if (isNegative) {
// negative clauses reduce the set of available artifacts
availableDependencies.removeAll(filteredDependencies);
if (!clauseIterator.hasNext()) {
// assume there's an implicit * missing at the end
processDependencies(availableDependencies, inline);
}
} else {
// positive clause; doesn't alter the available artifacts
processDependencies(filteredDependencies, inline);
}
}
}
use of org.apache.maven.artifact.resolver.filter.AndArtifactFilter 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.artifact.resolver.filter.AndArtifactFilter 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.artifact.resolver.filter.AndArtifactFilter 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