diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index f5196bd072..98368ef572 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -40,9 +40,9 @@ can now be filtered by their location using exclusion and inclusion patterns and
https://foo.bar.org/hidden/**
- https://foo.bar.org/secret/**
+ %regex[http(s)?:\/\/foo\.bar\.org\/secret\/.*]
+ ![https://foo.bar.org/**]
- %regex[http(s)?:\/\/foo\.bar\.org\/.*]
diff --git a/tycho-its/projects/p2Repository.repositoryRef.filter/pom.xml b/tycho-its/projects/p2Repository.repositoryRef.filter/pom.xml
index 33764661d8..09dddecfff 100644
--- a/tycho-its/projects/p2Repository.repositoryRef.filter/pom.xml
+++ b/tycho-its/projects/p2Repository.repositoryRef.filter/pom.xml
@@ -45,8 +45,8 @@
https://download.eclipse.org/lsp4e/**
https://download.eclipse.org/lsp4j/**
+ ![%regex[http(s)?:\/\/download\.eclipse\.org\/.*]]
- %regex[http(s)?:\/\/download\.eclipse\.org\/.*]
diff --git a/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/AssembleRepositoryMojo.java b/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/AssembleRepositoryMojo.java
index 475ee42d9b..6461550af3 100644
--- a/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/AssembleRepositoryMojo.java
+++ b/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/AssembleRepositoryMojo.java
@@ -30,7 +30,7 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.MatchPatterns;
+import org.codehaus.plexus.util.MatchPattern;
import org.eclipse.tycho.PackagingType;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.TychoConstants;
@@ -75,8 +75,8 @@
public class AssembleRepositoryMojo extends AbstractRepositoryMojo {
public static class RepositoryReferenceFilter {
- List exclude;
- List include;
+ /** The list of location patterns that exclude matching repository references. */
+ List exclude = List.of();
}
private static final Object LOCK = new Object();
@@ -224,38 +224,46 @@ public static class RepositoryReferenceFilter {
private boolean addIUTargetRepositoryReferences;
/**
- * A list of patterns to filter the automatically derived repository references by including or
- * excluding their location to control if they are eventually added to the assembled repository.
+ * A list of patterns to exclude automatically derived repository references from being added to
+ * the assembled repository.
*
- * Each pattern is either an inclusion or exclusion and an arbitrary number of
- * each can be specified. The location of a repository reference must match at least one
- * inclusion-pattern (if any is specified) and must not be match by any
- * exclusion-pattern, in order to be eventually added to the assembled repository.
+ * The location of a reference must not be matched by any pattern, in order to be eventually
+ * added to the assembled repository. An arbitrary number of patterns can be specified.
* The specified filters are only applied to those repository references derived from the
* target-definition or pom file, when {@link #addIUTargetRepositoryReferences} respectively
* {@link #addPomRepositoryReferences} is set to {@code true}.
*
*
- * Configuration example
+ * Configuration example 1
+ *
+ *
+ * <repositoryReferenceFilter>
+ * <exclude>https://foo.bar.org/hidden/**</exclude>
+ * </repositoryReferenceFilter>
+ *
+ *
+ * Configuration example 2
*
*
* <repositoryReferenceFilter>
* <exclude>
* <location>https://foo.bar.org/hidden/**</location>
- * <location>https://foo.bar.org/secret/**</location>
+ * <location>%regex[http(s)?:\/\/foo\.bar\.org\/secret\/.*]</location>
+ * <location>![https://foo.bar.org/**]</location>
* </exclude>
- * <include>%regex[http(s)?:\/\/foo\.bar\.org\/.*]</include>
* </repositoryReferenceFilter>
*
*
- * It contains two exclusion patterns using {@code ANT}-style syntax and one
- * inclusion using a {@code Java RegEx} {@link Pattern} (enclosed in
- * {@code %regex[]}). The inclusion pattern uses the shorthand
- * notation for singleton lists.
+ * In the second example the first of the three patterns uses {@code ANT}-style syntax, the
+ * second one uses a {@code Java RegEx} {@link Pattern} (enclosed in
+ * {@code %regex[]}).
+ * The third pattern is a negated (enclosed in {@code ![]}), which
+ * effectively makes it an inclusion pattern that all references must match in order to
+ * be added.
*
*/
@Parameter
- private RepositoryReferenceFilter repositoryReferenceFilter = null;
+ private RepositoryReferenceFilter repositoryReferenceFilter = new RepositoryReferenceFilter();
/**
* If enabled, an
@@ -383,19 +391,17 @@ private List getCategories(final File categoriesDirectory) {
}
private Predicate buildRepositoryReferenceLocationFilter() {
- Predicate filter = l -> true;
- if (repositoryReferenceFilter != null) {
- if (repositoryReferenceFilter.include != null && !repositoryReferenceFilter.include.isEmpty()) {
- MatchPatterns inclusionPattern = MatchPatterns.from(repositoryReferenceFilter.include);
- filter = l -> inclusionPattern.matches(l, true);
- }
- if (repositoryReferenceFilter.exclude != null && !repositoryReferenceFilter.exclude.isEmpty()) {
- MatchPatterns exclusionPattern = MatchPatterns.from(repositoryReferenceFilter.exclude);
- Predicate exclusionFilter = l -> !exclusionPattern.matches(l, true);
- filter = filter.and(exclusionFilter);
- }
- }
- return filter;
+ List> filters = repositoryReferenceFilter.exclude.stream()
+ .> map(exclusionPattern -> {
+ boolean isNegated = false;
+ if (exclusionPattern.startsWith("![") && exclusionPattern.endsWith("]")) {
+ exclusionPattern = exclusionPattern.substring(2, exclusionPattern.length() - 1);
+ isNegated = true;
+ }
+ MatchPattern pattern = MatchPattern.fromString(exclusionPattern);
+ return isNegated ? ref -> !pattern.matchPath(ref, true) : ref -> pattern.matchPath(ref, true);
+ }).toList();
+ return ref -> filters.stream().noneMatch(f -> f.test(ref));
}
}