Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for repository tags #6116

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
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.Tagged;
import aQute.bnd.service.Tags;

/**
* WARNING ! Not tested
*/
public abstract class BaseRepository implements Repository {
public abstract class BaseRepository implements Repository, Tagged {
chrisrueger marked this conversation as resolved.
Show resolved Hide resolved
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;
}
}
14 changes: 14 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,26 @@
package aQute.bnd.service;

import static aQute.bnd.service.Tagged.matchesTags;

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

/**
* A registry for objects.
*/
public interface Registry {
<T> List<T> getPlugins(Class<T> c);

default <T> List<T> getPlugins(Class<T> c, String... tags) {

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

return getPlugins(c).stream()
.filter(repo -> matchesTags(repo, tags))
.collect(Collectors.toList());
}

<T> T getPlugin(Class<T> c);
}
18 changes: 17 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,6 +9,7 @@

import org.osgi.util.promise.Promise;

import aQute.bnd.osgi.Constants;
import aQute.bnd.osgi.Processor;
import aQute.bnd.version.Version;

Expand All @@ -18,7 +19,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);
chrisrueger marked this conversation as resolved.
Show resolved Hide resolved

/**
* Options used to steer the put operation
*/
Expand Down Expand Up @@ -167,6 +176,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 +287,9 @@ default Promise<Void> sync() throws Exception {
return null;
});
}

@Override
default Tags getTags() {
return DEFAULT_REPO_TAGS;
}
}
35 changes: 35 additions & 0 deletions biz.aQute.bndlib/src/aQute/bnd/service/Tagged.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package aQute.bnd.service;

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

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

/**
* @param <T>
* @param obj
* @param tags
* @return <code>true</code> if the passed object matches any of the given
* tags, otherwise returns <code>false</code>
*/
static <T> boolean matchesTags(T obj, String... tags) {
if (obj instanceof Tagged tagged) {
Tags taggedTags = tagged.getTags();
for (String tag : tags) {
if (taggedTags.contains(tag)) {
return true;
}
}
}
return false;
}

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

import static java.util.stream.Collectors.toCollection;

import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;

/**
* 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 final class Tags extends LinkedHashSet<String> {
chrisrueger marked this conversation as resolved.
Show resolved Hide resolved

private static final long serialVersionUID = 1L;

public final static Tags NO_TAGS = of();

private Tags(Collection<String> c) {
super(c);
}

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(toCollection(LinkedHashSet::new)));
}



}
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
18 changes: 17 additions & 1 deletion biz.aQute.bndlib/src/aQute/lib/deployer/FileRepo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package aQute.lib.deployer;

import static aQute.bnd.service.Tags.parse;

import java.io.Closeable;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -34,6 +36,8 @@
import aQute.bnd.service.RegistryPlugin;
import aQute.bnd.service.RepositoryListenerPlugin;
import aQute.bnd.service.RepositoryPlugin;
import aQute.bnd.service.Tagged;
import aQute.bnd.service.Tags;
import aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor;
import aQute.bnd.version.Version;
import aQute.lib.collections.SortedList;
Expand Down Expand Up @@ -75,7 +79,7 @@
*/

@aQute.bnd.annotation.plugin.BndPlugin(name = "Filerepo", parameters = FileRepo.Config.class)
public class FileRepo implements Plugin, RepositoryPlugin, Refreshable, RegistryPlugin, Actionable, Closeable {
public class FileRepo implements Plugin, RepositoryPlugin, Refreshable, RegistryPlugin, Actionable, Closeable, Tagged {
private final static Logger logger = LoggerFactory.getLogger(FileRepo.class);

interface Config {
Expand Down Expand Up @@ -143,6 +147,11 @@ interface Config {
*/
public final static String NAME = "name";

/**
* A comma-separated list of tags.
*/
public final static String TAGS = "tags";

/**
* Should this file repo have an index? Either true or false (absent)
*/
Expand Down Expand Up @@ -252,6 +261,7 @@ interface Config {
String name;
boolean inited;
boolean trace;
Tags tags = DEFAULT_REPO_TAGS;
PersistentMap<ResourceDescriptor> index;

private boolean hasIndex;
Expand Down Expand Up @@ -336,6 +346,7 @@ public void setProperties(Map<String, String> map) {
action = map.get(CMD_AFTER_ACTION);

trace = Boolean.parseBoolean(map.get(TRACE));
tags = parse(map.get(TAGS), DEFAULT_REPO_TAGS);
}

/**
Expand Down Expand Up @@ -1048,4 +1059,9 @@ private ResourceDescriptor buildDescriptor(File f, Jar jar, byte[] digest, Strin
public void setIndex(boolean b) {
hasIndex = b;
}

@Override
public Tags getTags() {
return this.tags;
}
}
2 changes: 1 addition & 1 deletion biz.aQute.bndlib/src/aQute/lib/deployer/packageinfo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version 1.0.1
version 1.1.0
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package aQute.bnd.deployer.repository;

import static aQute.bnd.deployer.repository.RepoConstants.DEFAULT_CACHE_DIR;
import static aQute.bnd.service.Tags.parse;

import java.io.ByteArrayOutputStream;
import java.io.File;
Expand Down Expand Up @@ -61,6 +62,7 @@ public class LocalIndexedRepo extends AbstractIndexedRepo implements Refreshable
public static final String PROP_PRETTY = "pretty";
public static final String PROP_OVERWRITE = "overwrite";
public static final String PROP_ONLYDIRS = "onlydirs";
public static final String PROP_TAGS = "tags";

// not actually used (yet). Just to get some parameters
interface Config {
Expand Down Expand Up @@ -132,6 +134,8 @@ public synchronized void setProperties(Map<String, String> map) {
throw new IllegalArgumentException(
String.format("Cannot create repository cache: '%s' already exists but is not directory.",
cacheDir.getAbsolutePath()));

super.setTags(parse(map.get(PROP_TAGS), DEFAULT_REPO_TAGS));
}

@Override
Expand Down Expand Up @@ -614,4 +618,5 @@ public String title(Object... target) throws Exception {

public void close() {}


}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@Version("5.0.0")
@Version("5.1.0")
package aQute.bnd.deployer.repository;

import org.osgi.annotation.versioning.Version;
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package aQute.bnd.repository.maven.pom.provider;

import static aQute.bnd.osgi.Constants.BSN_SOURCE_SUFFIX;
import static aQute.bnd.service.Tags.parse;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

Expand Down Expand Up @@ -271,6 +272,7 @@ public boolean refresh() throws Exception {
@Override
public void setProperties(Map<String, String> map) throws Exception {
configuration = Converter.cnv(PomConfiguration.class, map);
super.setTags(parse(configuration.tags(), DEFAULT_REPO_TAGS));
}

@Override
Expand Down Expand Up @@ -507,4 +509,5 @@ private Archive trySources(String bsn, Version version) throws Exception {
.getOther(Archive.JAR_EXTENSION, Archive.SOURCES_CLASSIFIER);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,9 @@ public interface PomConfiguration {
*/
boolean dependencyManagement(boolean deflt);

/**
* @return a comma separated list of tags.
*/
String tags();

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@Version("2.1.0")
@Version("2.2.0")
package aQute.bnd.repository.maven.pom.provider;

import org.osgi.annotation.versioning.Version;
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ public interface Configuration {
* Extensions for files that contain multiple JARs
*/
String multi();

/**
* @return a comma separated list of tags.
*/
String tags();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package aQute.bnd.repository.maven.provider;

import static aQute.bnd.osgi.Constants.BSN_SOURCE_SUFFIX;
import static aQute.bnd.service.Tags.parse;

import java.io.Closeable;
import java.io.File;
Expand Down Expand Up @@ -773,6 +774,7 @@ public void setProperties(Map<String, String> map) throws Exception {
configuration = Converter.cnv(Configuration.class, map);
name = configuration.name("Maven");
localRepo = IO.getFile(configuration.local(MAVEN_REPO_LOCAL));
super.setTags(parse(configuration.tags(), DEFAULT_REPO_TAGS));
}

@Override
Expand Down Expand Up @@ -1074,4 +1076,5 @@ public String getStatus() {
public boolean isRemote() {
return remote;
}

}