Skip to content

Commit b9a574f

Browse files
committed
rework - repos now have 'resolve' tag by default
- this commit partly reverts previous commit - repos now get the 'resolve' tag by default if not specified - .bndrun: empty -runrepos will be populated with all repos having the 'resolve' tag - .bndrun: resolution consider all repos having the 'resolve' tag. that means you can exclude a repo from resolution by manually assigning it a different tag (e.g. to exclude the baseline repo from resolution, you should give the baseline-repo e.g. the tag 'baseline' and make sure it does NOT have the 'resolve' tag Signed-off-by: Christoph Rueger <[email protected]>
1 parent dd36fe1 commit b9a574f

File tree

13 files changed

+118
-43
lines changed

13 files changed

+118
-43
lines changed

biz.aQute.bndlib/src/aQute/bnd/osgi/repository/BaseRepository.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ public abstract class BaseRepository implements Repository, Tagged {
3636
private final PromiseFactory promiseFactory = new PromiseFactory(
3737
PromiseFactory.inlineExecutor());
3838

39-
private static final String DEFAULT_TAG = "all";
40-
private static final Set<String> DEFAULT_TAGS = Set.of(DEFAULT_TAG);
4139

4240
static {
4341
Requirement requireAll = ResourceUtils.createWildcardRequirement();
@@ -250,6 +248,6 @@ public RequirementBuilder addAttribute(String name, Object value) {
250248

251249
@Override
252250
public Set<String> getTags() {
253-
return DEFAULT_TAGS;
251+
return Tagged.DEFAULT_REPO_TAGS;
254252
}
255253
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
package aQute.bnd.service;
22

3+
import static aQute.bnd.service.Tagged.matchesTags;
4+
35
import java.util.List;
6+
import java.util.stream.Collectors;
47

58
/**
69
* A registry for objects.
710
*/
811
public interface Registry {
912
<T> List<T> getPlugins(Class<T> c);
1013

14+
default <T> List<T> getPlugins(Class<T> c, String... tags) {
15+
16+
if (tags == null || tags.length == 0) {
17+
return getPlugins(c);
18+
}
19+
20+
return getPlugins(c).stream()
21+
.filter(repo -> matchesTags(repo, tags))
22+
.collect(Collectors.toList());
23+
}
24+
1125
<T> T getPlugin(Class<T> c);
1226
}
Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,60 @@
11
package aQute.bnd.service;
22

3+
import static aQute.bnd.service.Tagged.RepoTags.resolve;
4+
import static java.util.stream.Collectors.toCollection;
5+
36
import java.util.Arrays;
47
import java.util.LinkedHashSet;
58
import java.util.Set;
6-
import java.util.stream.Collectors;
79

810
/**
911
* Allows to add tags to implementing classes. Originally intended for tagging
1012
* repositories.
1113
*/
1214
public interface Tagged {
1315

16+
17+
enum RepoTags {
18+
/**
19+
* tag for repos which should be used for Resolving bundles. This is
20+
* also the default tag for all repos which not have specified tags
21+
* (also for bc reasons) Also see {@link Tagged#DEFAULT_REPO_TAGS}
22+
*/
23+
resolve
24+
// add more if neded e.g. relase, baseline
25+
}
26+
27+
/**
28+
* Each repo has by default the tag {@link RepoTags#resolve} if not tags are
29+
* set at the repo definition in build.bnd That means it is consider
30+
*/
31+
Set<String> DEFAULT_REPO_TAGS = Set.of(resolve.name());
32+
1433
/**
1534
* @return a non-null list of tags.
1635
*/
1736
Set<String> getTags();
1837

19-
static Set<String> toTags(String csvTags) {
38+
static Set<String> toTags(String csvTags, Set<String> defaultTags) {
2039
if (csvTags == null || csvTags.isBlank()) {
21-
return Set.of("all"); // default
40+
return defaultTags; // default
2241
}
2342

2443
return Arrays.stream(csvTags.split(","))
2544
.map(String::trim)
26-
.collect(Collectors.toCollection(LinkedHashSet::new));
45+
.collect(toCollection(LinkedHashSet::new));
46+
}
47+
48+
static <T> boolean matchesTags(T obj, String... tags) {
49+
if (obj instanceof Tagged tagged) {
50+
Set<String> taggedTags = tagged.getTags();
51+
for (String tag : tags) {
52+
if (taggedTags.contains(tag)) {
53+
return true;
54+
}
55+
}
56+
}
57+
return false;
2758
}
2859

2960
}

biz.aQute.bndlib/src/aQute/lib/deployer/FileRepo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,6 @@ public void setIndex(boolean b) {
10601060

10611061
@Override
10621062
public Set<String> getTags() {
1063-
return Tagged.toTags(tags);
1063+
return Tagged.toTags(tags, Tagged.DEFAULT_REPO_TAGS);
10641064
}
10651065
}

biz.aQute.repository/src/aQute/bnd/deployer/repository/LocalIndexedRepo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ public void close() {}
621621

622622
@Override
623623
public Set<String> getTags() {
624-
return Tagged.toTags(tags);
624+
return Tagged.toTags(tags, Tagged.DEFAULT_REPO_TAGS);
625625
}
626626

627627
}

biz.aQute.repository/src/aQute/bnd/repository/maven/pom/provider/BndPomRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,6 @@ private Archive trySources(String bsn, Version version) throws Exception {
511511

512512
@Override
513513
public Set<String> getTags() {
514-
return Tagged.toTags(configuration.tags());
514+
return Tagged.toTags(configuration.tags(), Tagged.DEFAULT_REPO_TAGS);
515515
}
516516
}

biz.aQute.repository/src/aQute/bnd/repository/maven/provider/MavenBndRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,6 @@ public boolean isRemote() {
10781078

10791079
@Override
10801080
public Set<String> getTags() {
1081-
return Tagged.toTags(configuration.tags());
1081+
return Tagged.toTags(configuration.tags(), Tagged.DEFAULT_REPO_TAGS);
10821082
}
10831083
}

biz.aQute.repository/src/aQute/bnd/repository/osgi/OSGiRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,6 @@ private void status(String s) {
417417

418418
@Override
419419
public Set<String> getTags() {
420-
return Tagged.toTags(config.tags());
420+
return Tagged.toTags(config.tags(), Tagged.DEFAULT_REPO_TAGS);
421421
}
422422
}

biz.aQute.repository/src/aQute/bnd/repository/p2/provider/P2Repository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public String title(Object... target) throws Exception {
197197

198198
@Override
199199
public Set<String> getTags() {
200-
return Tagged.toTags(config.tags());
200+
return Tagged.toTags(config.tags(), Tagged.DEFAULT_REPO_TAGS);
201201
}
202202

203203
}

biz.aQute.repository/test/aQute/bnd/repository/maven/provider/WorkspaceTest.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
package aQute.bnd.repository.maven.provider;
22

3+
import static org.junit.jupiter.api.Assertions.assertEquals;
34
import static org.junit.jupiter.api.Assertions.assertNotNull;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
46

57
import java.io.File;
8+
import java.util.ArrayList;
69
import java.util.Formatter;
710
import java.util.HashMap;
11+
import java.util.List;
812
import java.util.Map;
913

1014
import org.junit.jupiter.api.AfterEach;
1115
import org.junit.jupiter.api.BeforeEach;
1216
import org.junit.jupiter.api.Test;
17+
import org.osgi.service.repository.Repository;
1318

1419
import aQute.bnd.build.Workspace;
20+
import aQute.bnd.service.Tagged;
21+
import aQute.bnd.service.Tagged.RepoTags;
1522
import aQute.bnd.test.jupiter.InjectTemporaryDirectory;
1623
import aQute.http.testservers.HttpTestServer.Config;
1724
import aQute.lib.io.IO;
@@ -57,6 +64,37 @@ public void testEnv() throws Exception {
5764
assertNotNull(workspace);
5865
assertNotNull(repo);
5966
System.out.println(workspace.getBase());
67+
68+
// check repo tags
69+
// repos should have the 'resolve' tag by default if no tag is specified
70+
List<Repository> repos = workspace.getPlugins(Repository.class);
71+
List<Repository> resolveRepos = workspace.getPlugins(Repository.class, RepoTags.resolve.name());
72+
assertEquals(repos, resolveRepos);
73+
74+
Repository repo = repos.get(0);
75+
assertTrue(repo instanceof Tagged);
76+
assertEquals(1, ((Tagged) repo).getTags()
77+
.size());
78+
assertEquals(RepoTags.resolve.name(), new ArrayList<>(((Tagged) repo).getTags()).get(0));
79+
80+
}
81+
82+
@Test
83+
public void testRepoWithDifferentTag() throws Exception {
84+
// similar as testEnv()
85+
// but override the tag with a different one and repeat the tests
86+
config(Map.of("tags", "foo"));
87+
88+
List<Repository> resolveRepos = workspace.getPlugins(Repository.class, RepoTags.resolve.name());
89+
assertTrue(resolveRepos.isEmpty());
90+
91+
List<Repository> repos = workspace.getPlugins(Repository.class);
92+
Repository repo = repos.get(0);
93+
assertTrue(repo instanceof Tagged);
94+
assertEquals(1, ((Tagged) repo).getTags()
95+
.size());
96+
assertEquals("foo", new ArrayList<>(((Tagged) repo).getTags()).get(0));
97+
6098
}
6199

62100
void config(Map<String, String> override) throws Exception {
@@ -74,7 +112,12 @@ void config(Map<String, String> override) throws Exception {
74112
sb.format(" name=test; \\\n", MavenBndRepository.class.getName());
75113
sb.format(" local=%s; \\\n", config.get("local"));
76114
sb.format(" releaseUrl=%s; \\\n", config.get("releaseUrl"));
77-
sb.format(" index=%s\n", config.get("index"));
115+
sb.format(" index=%s; \\\n", config.get("index"));
116+
117+
String tags = config.get("tags");
118+
if (tags != null && !tags.isBlank()) {
119+
sb.format(" tags=%s\n", tags);
120+
}
78121

79122
build.getParentFile()
80123
.mkdirs();

0 commit comments

Comments
 (0)