Skip to content

Commit

Permalink
Merge pull request #6343 from chrisrueger/improve-repo-tags
Browse files Browse the repository at this point in the history
Improve repo tagging
  • Loading branch information
chrisrueger authored Nov 1, 2024
2 parents b4eac9d + 2688cb5 commit ae31d71
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
8 changes: 4 additions & 4 deletions biz.aQute.bndlib/src/aQute/bnd/service/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public interface Registry {
* @param <T>
* @param c
* @param tags
* @return all plugins matching the given class and any of the given tags.
* If no tags are given, all plugins are returned without filtering.
* @return All plugins that have a tag that matches at least one of the
* given tags or have no tags.
*/
default <T> List<T> getPlugins(Class<T> c, String... tags) {

Expand All @@ -31,8 +31,8 @@ default <T> List<T> getPlugins(Class<T> c, String... tags) {
}

return getPlugins(c).stream()
.filter(repo -> repo instanceof Tagged taggedRepo && taggedRepo.getTags()
.includesAny(tags))
.filter(plugin -> (plugin instanceof Tagged taggedPlugin) ? taggedPlugin.getTags()
.includesAny(tags) : true)
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface RepositoryPlugin extends Tagged {
* tags are set at the repo definition in build.bnd That means it is
* consider
*/
Tags DEFAULT_REPO_TAGS = Tags.of(Constants.REPOTAGS_RESOLVE);
Tags DEFAULT_REPO_TAGS = Tags.NO_TAGS;

/**
* Options used to steer the put operation
Expand Down
14 changes: 11 additions & 3 deletions biz.aQute.bndlib/src/aQute/bnd/service/tags/Tags.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.TreeSet;
import java.util.stream.Collectors;

import aQute.libg.glob.Glob;

/**
* A set of tags. A tag is a string-token which can be attached to an entity for
* categorization and filtering. Typically these entities then implement the
Expand Down Expand Up @@ -110,7 +112,7 @@ public String toString() {
}

/**
* @param tags
* @param tags (globs)
* @return <code>true</code> if any of the given tags is included in the
* current set of tags, otherwise returns <code>false</code>. Also
* if the current set of tags is empty, also <code>true</code> is
Expand All @@ -126,13 +128,19 @@ public boolean includesAny(String... tags) {
return true;
}

for (String tag : tags) {
if (contains(tag)) {
for (String tagGlob : tags) {
if (matchesAny(new Glob(tagGlob))) {
return true;
}
}

return false;

}

private boolean matchesAny(Glob glob) {
return internalSet.stream()
.anyMatch(s -> glob.matches(s));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ public void testEnv() throws Exception {

Repository repo = repos.get(0);
assertTrue(repo instanceof Tagged);
assertEquals(1, ((Tagged) repo).getTags()
assertEquals(0, ((Tagged) repo).getTags()
.size());
assertEquals(Constants.REPOTAGS_RESOLVE, new ArrayList<>(((Tagged) repo).getTags()).get(0));
assertTrue(((Tagged) repo).getTags()
.includesAny(Constants.REPOTAGS_RESOLVE));

}

Expand Down

0 comments on commit ae31d71

Please sign in to comment.