Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion biz.aQute.bndlib/src/aQute/bnd/maven/support/packageinfo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version 3.1
version 3.2.0
7 changes: 7 additions & 0 deletions biz.aQute.bndlib/src/aQute/bnd/osgi/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ public interface Constants {

String REMOTEWORKSPACE = "-remoteworkspace";

/**
* tag for repos which should be used for Resolving bundles. This is also
* the default tag for all repos which not have specified tags (also for bc
* reasons)
*/
String REPOTAGS_RESOLVE = "resolve";

String RUNBLACKLIST = "-runblacklist";
String RUNREQUIRES = "-runrequires";
String RUNEE = "-runee";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,20 @@

import aQute.bnd.exceptions.Exceptions;
import aQute.bnd.osgi.resource.ResourceUtils;
import aQute.bnd.service.RepositoryPlugin;
import aQute.bnd.service.tags.Tagged;
import aQute.bnd.service.tags.Tags;

/**
* WARNING ! Not tested
*/
public abstract class BaseRepository implements Repository {
public abstract class BaseRepository implements Repository, Tagged {
private static final RequirementExpression[] EMPTY = new RequirementExpression[0];
static IdentityExpression all;
private final PromiseFactory promiseFactory = new PromiseFactory(
PromiseFactory.inlineExecutor());
private Tags tags = RepositoryPlugin.DEFAULT_REPO_TAGS;


static {
Requirement requireAll = ResourceUtils.createWildcardRequirement();
Expand Down Expand Up @@ -244,4 +249,12 @@ public RequirementBuilder addAttribute(String name, Object value) {
};
}

@Override
public Tags getTags() {
return this.tags;
}

protected void setTags(Tags tags) {
this.tags = tags;
}
}
28 changes: 28 additions & 0 deletions biz.aQute.bndlib/src/aQute/bnd/service/Registry.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
package aQute.bnd.service;

import java.util.List;
import java.util.stream.Collectors;

import aQute.bnd.service.tags.Tagged;

/**
* A registry for objects.
*/
public interface Registry {

/**
* @param <T>
* @param c
* @return all plugins matching the given class
*/
<T> List<T> getPlugins(Class<T> c);

/**
* @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.
*/
default <T> List<T> getPlugins(Class<T> c, String... tags) {

if (tags.length == 0) {
return getPlugins(c);
}

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

<T> T getPlugin(Class<T> c);
}
17 changes: 16 additions & 1 deletion biz.aQute.bndlib/src/aQute/bnd/service/RepositoryPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

import org.osgi.util.promise.Promise;

import aQute.bnd.osgi.Constants;
import aQute.bnd.osgi.Processor;
import aQute.bnd.service.tags.Tagged;
import aQute.bnd.service.tags.Tags;
import aQute.bnd.version.Version;

/**
Expand All @@ -18,7 +21,15 @@
* combination. It is also possible to put revisions in a repository if the
* repository is not read only.
*/
public interface RepositoryPlugin {
public interface RepositoryPlugin extends Tagged {

/**
* Each repo has by default the tag {@link Constants#REPOTAGS_RESOLVE} if no
* tags are set at the repo definition in build.bnd That means it is
* consider
*/
Tags DEFAULT_REPO_TAGS = Tags.of(Constants.REPOTAGS_RESOLVE);

/**
* Options used to steer the put operation
*/
Expand Down Expand Up @@ -167,6 +178,8 @@ default void success(File file, Map<String, String> attrs) throws Exception {
boolean progress(File file, int percentage) throws Exception;
}



/**
* Return a URL to a matching version of the given bundle.
* <p/>
Expand Down Expand Up @@ -276,4 +289,6 @@ default Promise<Void> sync() throws Exception {
return null;
});
}


}
2 changes: 1 addition & 1 deletion biz.aQute.bndlib/src/aQute/bnd/service/package-info.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@Version("4.8.0")
@Version("4.9.0")
package aQute.bnd.service;

import org.osgi.annotation.versioning.Version;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version 1.6
version 1.7.0
21 changes: 21 additions & 0 deletions biz.aQute.bndlib/src/aQute/bnd/service/tags/Tagged.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package aQute.bnd.service.tags;

/**
* Allows to add tags to implementing classes. Originally intended for tagging
* repositories.
*/
public interface Tagged {

/**
* Dummy placeholder for "empty tags".
*/
String EMPTY_TAGS = "<<EMPTY>>";

/**
* @return a non-null list of tags. Default is empty (meaning 'no tags').
*/
default Tags getTags() {
return Tags.NO_TAGS;
}

}
163 changes: 163 additions & 0 deletions biz.aQute.bndlib/src/aQute/bnd/service/tags/Tags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package aQute.bnd.service.tags;

import static java.util.Collections.unmodifiableSortedSet;

import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.stream.Collectors;

/**
* 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
* {@link Tagged} interface.
*/
public class Tags implements Set<String> {
private final SortedSet<String> internalSet;

public final static Tags NO_TAGS = of();

private Tags() {
this.internalSet = unmodifiableSortedSet(new TreeSet<>());
}

private Tags(Collection<? extends String> c) {
this.internalSet = unmodifiableSortedSet(new TreeSet<>(c));
}

@Override
public int size() {
return internalSet.size();
}

@Override
public boolean isEmpty() {
return internalSet.isEmpty();
}

@Override
public boolean contains(Object o) {
return internalSet.contains(o);
}

@Override
public Iterator<String> iterator() {
return internalSet.iterator();
}

@Override
public Object[] toArray() {
return internalSet.toArray();
}

@Override
public <T> T[] toArray(T[] a) {
return internalSet.toArray(a);
}

@Override
public boolean add(String s) {
return internalSet.add(s);
}

@Override
public boolean remove(Object o) {
return internalSet.remove(o);
}

@Override
public boolean containsAll(Collection<?> c) {
return internalSet.containsAll(c);
}

@Override
public boolean addAll(Collection<? extends String> c) {
return internalSet.addAll(c);
}

@Override
public boolean retainAll(Collection<?> c) {
return internalSet.retainAll(c);
}

@Override
public boolean removeAll(Collection<?> c) {
return internalSet.removeAll(c);
}

@Override
public void clear() {
internalSet.clear();
}

@Override
public boolean equals(Object o) {
return internalSet.equals(o);
}

@Override
public int hashCode() {
return internalSet.hashCode();
}

@Override
public String toString() {
return internalSet.toString();
}

/**
* @param tags
* @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
* returned.
*/
public boolean includesAny(String... tags) {

if (isEmpty()) {
// this is on purpose to maintain backwards compatibility for
// entities which do not handle tags yet and return an empty set. In
// other words: if the current set is
// empty that means "yes I match any of what you passed".
return true;
}

for (String tag : tags) {
if (contains(tag)) {
return true;
}
}

return false;
}

/**
* @param name
* @return a Tags instance with the given tags.
*/
public static Tags of(String... name) {
return new Tags(Set.of(name));
}

/**
* Parses a comma-separated string of tags into a Tags object.
*
* @param csvTags
* @param defaultTags a default used when csvTags is null or blank
* @return populated Tags or the passed defaultTags.
*/
public static Tags parse(String csvTags, Tags defaultTags) {
if (csvTags == null || csvTags.isBlank()) {
return defaultTags; // default
}

return new Tags(Arrays.stream(csvTags.split(","))
.map(String::trim)
.collect(Collectors.toCollection(LinkedHashSet::new)));
}

}
4 changes: 4 additions & 0 deletions biz.aQute.bndlib/src/aQute/bnd/service/tags/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@Version("1.0.0")
package aQute.bnd.service.tags;

import org.osgi.annotation.versioning.Version;
Loading