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

Merged
merged 13 commits into from
Jun 21, 2024
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,7 +25,9 @@

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
Expand All @@ -35,6 +37,7 @@ public abstract class BaseRepository implements Repository, Tagged {
static IdentityExpression all;
private final PromiseFactory promiseFactory = new PromiseFactory(
PromiseFactory.inlineExecutor());
private Tags tags = RepositoryPlugin.DEFAULT_REPO_TAGS;


static {
Expand Down Expand Up @@ -247,7 +250,11 @@ public RequirementBuilder addAttribute(String name, Object value) {
}

@Override
public Set<String> getTags() {
return Tagged.DEFAULT_REPO_TAGS;
public Tags getTags() {
return this.tags;
}

protected void setTags(Tags tags) {
this.tags = tags;
}
}
2 changes: 1 addition & 1 deletion biz.aQute.bndlib/src/aQute/bnd/service/Registry.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package aQute.bnd.service;

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

import java.util.List;
import java.util.stream.Collectors;
Expand Down
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;
}
}
50 changes: 3 additions & 47 deletions biz.aQute.bndlib/src/aQute/bnd/service/Tagged.java
Original file line number Diff line number Diff line change
@@ -1,60 +1,16 @@
package aQute.bnd.service;

import static aQute.bnd.service.Tagged.RepoTags.resolve;
import static java.util.stream.Collectors.toCollection;

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

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


enum RepoTags {
/**
* 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) Also see {@link Tagged#DEFAULT_REPO_TAGS}
*/
resolve
// add more if neded e.g. relase, baseline
}

/**
* Each repo has by default the tag {@link RepoTags#resolve} if not tags are
* set at the repo definition in build.bnd That means it is consider
*/
Set<String> DEFAULT_REPO_TAGS = Set.of(resolve.name());

/**
* @return a non-null list of tags.
* @return a non-null list of tags. Default is empty (meaning 'no tags').
*/
Set<String> getTags();

static Set<String> toTags(String csvTags, Set<String> defaultTags) {
if (csvTags == null || csvTags.isBlank()) {
return defaultTags; // default
}

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

static <T> boolean matchesTags(T obj, String... tags) {
if (obj instanceof Tagged tagged) {
Set<String> taggedTags = tagged.getTags();
for (String tag : tags) {
if (taggedTags.contains(tag)) {
return true;
}
}
}
return false;
default Tags getTags() {
return Tags.NO_TAGS;
}

}
65 changes: 65 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,65 @@
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)));
}

/**
* @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>
*/
public 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;
}

}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version 1.6
version 1.7.0
12 changes: 7 additions & 5 deletions 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 All @@ -14,7 +16,6 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.jar.Manifest;
Expand All @@ -36,6 +37,7 @@
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 @@ -259,7 +261,7 @@ interface Config {
String name;
boolean inited;
boolean trace;
String tags;
Tags tags = DEFAULT_REPO_TAGS;
PersistentMap<ResourceDescriptor> index;

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

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

/**
Expand Down Expand Up @@ -1059,7 +1061,7 @@ public void setIndex(boolean b) {
}

@Override
public Set<String> getTags() {
return Tagged.toTags(tags, Tagged.DEFAULT_REPO_TAGS);
public Tags getTags() {
return this.tags;
}
}
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 @@ -40,7 +41,6 @@
import aQute.bnd.service.RepositoryListenerPlugin;
import aQute.bnd.service.ResourceHandle;
import aQute.bnd.service.ResourceHandle.Location;
import aQute.bnd.service.Tagged;
import aQute.bnd.version.Version;
import aQute.bnd.version.VersionRange;
import aQute.lib.hex.Hex;
Expand Down Expand Up @@ -83,7 +83,6 @@ interface Config {
private boolean overwrite = true;
private File storageDir;
private String onlydirs = null;
private String tags = null;

// @GuardedBy("newFilesInCoordination")
private final List<URI> newFilesInCoordination = new ArrayList<>();
Expand Down Expand Up @@ -136,7 +135,7 @@ public synchronized void setProperties(Map<String, String> map) {
String.format("Cannot create repository cache: '%s' already exists but is not directory.",
cacheDir.getAbsolutePath()));

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

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

public void close() {}

@Override
public Set<String> getTags() {
return Tagged.toTags(tags, Tagged.DEFAULT_REPO_TAGS);
}

}
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 All @@ -14,7 +15,6 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
Expand Down Expand Up @@ -45,7 +45,6 @@
import aQute.bnd.service.RegistryPlugin;
import aQute.bnd.service.RepositoryListenerPlugin;
import aQute.bnd.service.RepositoryPlugin;
import aQute.bnd.service.Tagged;
import aQute.bnd.service.clipboard.Clipboard;
import aQute.bnd.service.repository.Prepare;
import aQute.bnd.util.repository.DownloadListenerPromise;
Expand Down Expand Up @@ -273,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 @@ -509,8 +509,5 @@ private Archive trySources(String bsn, Version version) throws Exception {
.getOther(Archive.JAR_EXTENSION, Archive.SOURCES_CLASSIFIER);
}

@Override
public Set<String> getTags() {
return Tagged.toTags(configuration.tags(), Tagged.DEFAULT_REPO_TAGS);
}

}