Skip to content

Commit 736ab82

Browse files
committed
WIP filter repos for buildpath,testpath
Signed-off-by: Christoph Rueger <[email protected]>
1 parent fa8b282 commit 736ab82

File tree

4 files changed

+76
-31
lines changed

4 files changed

+76
-31
lines changed

biz.aQute.bndlib/src/aQute/bnd/build/Project.java

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@
105105
import aQute.bnd.service.export.Exporter;
106106
import aQute.bnd.service.release.ReleaseBracketingPlugin;
107107
import aQute.bnd.service.specifications.RunSpecification;
108-
import aQute.bnd.service.tags.Tags;
109108
import aQute.bnd.stream.MapStream;
110109
import aQute.bnd.version.Version;
111110
import aQute.bnd.version.VersionRange;
@@ -638,6 +637,8 @@ public List<Container> getBundles(Strategy strategyx, String spec, String source
638637
decorator.decorate(bundles, true);
639638
}
640639

640+
List<RepositoryPlugin> repos = getRepositories(repoTagsBySource(source));
641+
641642
List<Container> result = new ArrayList<>();
642643
try {
643644
for (Entry<String, Attrs> entry : bundles.entrySet()) {
@@ -650,12 +651,12 @@ public List<Container> getBundles(Strategy strategyx, String spec, String source
650651
boolean triedGetBundle = false;
651652

652653
if (bsn.indexOf('*') >= 0) {
653-
return getBundlesWildcard(bsn, versionRange, strategyx, attrs);
654+
return getBundlesWildcard(bsn, versionRange, strategyx, attrs, repos);
654655
}
655656

656657
if (versionRange != null) {
657658
if (versionRange.equals(VERSION_ATTR_LATEST) || versionRange.equals(VERSION_ATTR_SNAPSHOT)) {
658-
found = getBundle(bsn, versionRange, strategyx, attrs);
659+
found = getBundle(bsn, versionRange, strategyx, attrs, repos);
659660
triedGetBundle = true;
660661
}
661662
}
@@ -694,7 +695,7 @@ public List<Container> getBundles(Strategy strategyx, String spec, String source
694695
found = new Container(this, bsn, "file", Container.TYPE.EXTERNAL, f, error, attrs, null);
695696
}
696697
} else if (!triedGetBundle) {
697-
found = getBundle(bsn, versionRange, strategyx, attrs);
698+
found = getBundle(bsn, versionRange, strategyx, attrs, repos);
698699
}
699700
}
700701

@@ -728,6 +729,25 @@ public List<Container> getBundles(Strategy strategyx, String spec, String source
728729
return result;
729730
}
730731

732+
private String[] repoTagsBySource(String source) {
733+
734+
if (source == null) {
735+
return null;
736+
}
737+
738+
if (Constants.BUILDPATH.equals(source)) {
739+
return new String[] {
740+
Constants.REPOTAGS_COMPILE
741+
};
742+
} else if (Constants.TESTPATH.equals(source)) {
743+
return new String[] {
744+
Constants.REPOTAGS_COMPILE, Constants.REPOTAGS_TEST
745+
};
746+
}
747+
// TODO how to determine tag "debug"
748+
return null;
749+
}
750+
731751
/**
732752
* Just calls a new method with a default parm.
733753
*
@@ -751,6 +771,13 @@ Collection<Container> getBundles(Strategy strategy, String spec) throws Exceptio
751771
public List<Container> getBundlesWildcard(String bsnPattern, String range, Strategy strategyx,
752772
Map<String, String> attrs) throws Exception {
753773

774+
List<RepositoryPlugin> plugins = getRepositories();
775+
return getBundlesWildcard(bsnPattern, range, strategyx, attrs, plugins);
776+
}
777+
778+
private List<Container> getBundlesWildcard(String bsnPattern, String range, Strategy strategyx,
779+
Map<String, String> attrs, List<RepositoryPlugin> repos) throws Exception {
780+
754781
if (VERSION_ATTR_SNAPSHOT.equals(range) || VERSION_ATTR_PROJECT.equals(range))
755782
return Collections.singletonList(new Container(this, bsnPattern, range, TYPE.ERROR, null,
756783
"Cannot use snapshot or project version with wildcard matches", null, null));
@@ -774,8 +801,7 @@ public List<Container> getBundlesWildcard(String bsnPattern, String range, Strat
774801

775802
SortedMap<String, Pair<Version, RepositoryPlugin>> providerMap = new TreeMap<>();
776803

777-
List<RepositoryPlugin> plugins = getRepositories();
778-
for (RepositoryPlugin plugin : plugins) {
804+
for (RepositoryPlugin plugin : repos) {
779805

780806
if (repoFilter != null && !repoFilter.match(plugin))
781807
continue;
@@ -1256,6 +1282,14 @@ public void release(String name, boolean test) throws Exception {
12561282
public Container getBundle(String bsn, String range, Strategy strategy, Map<String, String> attrs)
12571283
throws Exception {
12581284

1285+
List<RepositoryPlugin> plugins = getRepositories();
1286+
return getBundle(bsn, range, strategy, attrs, plugins);
1287+
1288+
}
1289+
1290+
private Container getBundle(String bsn, String range, Strategy strategy, Map<String, String> attrs,
1291+
List<RepositoryPlugin> repos) throws Exception {
1292+
12591293
if (range == null)
12601294
range = "0";
12611295
if (attrs == null) {
@@ -1281,7 +1315,7 @@ public Container getBundle(String bsn, String range, Strategy strategy, Map<Stri
12811315
useStrategy = overrideStrategy(attrs, useStrategy);
12821316
RepoFilter repoFilter = parseRepoFilter(attrs);
12831317

1284-
List<RepositoryPlugin> plugins = getRepositories();
1318+
12851319

12861320
if (useStrategy == Strategy.EXACT) {
12871321
if (!Verifier.isVersion(range))
@@ -1291,7 +1325,8 @@ public Container getBundle(String bsn, String range, Strategy strategy, Map<Stri
12911325
// For an exact range we just iterate over the repos
12921326
// and return the first we find.
12931327
Version version = new Version(range);
1294-
for (RepositoryPlugin plugin : plugins) {
1328+
1329+
for (RepositoryPlugin plugin : repos) {
12951330
DownloadBlocker blocker = new DownloadBlocker(this);
12961331
File result = plugin.get(bsn, version, attrs, blocker);
12971332
if (result != null)
@@ -1307,7 +1342,8 @@ public Container getBundle(String bsn, String range, Strategy strategy, Map<Stri
13071342
// multiple repos we take the first
13081343

13091344
SortedMap<Version, RepositoryPlugin> versions = new TreeMap<>();
1310-
for (RepositoryPlugin plugin : plugins) {
1345+
1346+
for (RepositoryPlugin plugin : repos) {
13111347

13121348
if (repoFilter != null && !repoFilter.match(plugin))
13131349
continue;
@@ -1385,8 +1421,7 @@ public Container getBundle(String bsn, String range, Strategy strategy, Map<Stri
13851421
//
13861422

13871423
return new Container(this, bsn, range, Container.TYPE.ERROR, null,
1388-
bsn + ";version=" + range + " Not found in " + plugins, attrs, null);
1389-
1424+
bsn + ";version=" + range + " Not found in " + repos, attrs, null);
13901425
}
13911426

13921427
/**
@@ -1397,19 +1432,8 @@ public Container getBundle(String bsn, String range, Strategy strategy, Map<Stri
13971432
*
13981433
* @return a list of relevant repositories used by various methods.
13991434
*/
1400-
public List<RepositoryPlugin> getRepositories() {
1401-
1402-
return workspace.getRepositories()
1403-
.stream()
1404-
.filter(repo -> {
1405-
Tags tags = repo.getTags();
1406-
1407-
if (tags == null || tags.includesAny(Constants.REPOTAGS_COMPILE)) {
1408-
return true;
1409-
}
1410-
return false;
1411-
})
1412-
.toList();
1435+
public List<RepositoryPlugin> getRepositories(String... tags) {
1436+
return workspace.getRepositories(tags);
14131437
}
14141438

14151439
/**

biz.aQute.bndlib/src/aQute/bnd/build/Workspace.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
import aQute.bnd.service.repository.Prepare;
9999
import aQute.bnd.service.repository.RepositoryDigest;
100100
import aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor;
101+
import aQute.bnd.service.tags.Tags;
101102
import aQute.bnd.stream.MapStream;
102103
import aQute.bnd.url.MultiURLConnectionHandler;
103104
import aQute.bnd.util.home.Home;
@@ -720,6 +721,29 @@ public List<RepositoryPlugin> getRepositories() {
720721
return data.repositories.get();
721722
}
722723

724+
/**
725+
* @param tags list tags to filter. <code>null</code> means all.
726+
* @return matching repositories.
727+
*/
728+
public List<RepositoryPlugin> getRepositories(String... tags) {
729+
730+
if (tags == null) {
731+
return data.repositories.get();
732+
}
733+
734+
return data.repositories.get()
735+
.stream()
736+
.filter(repo -> {
737+
Tags repotags = repo.getTags();
738+
739+
if (repotags == null || repotags.includesAny(tags)) {
740+
return true;
741+
}
742+
return false;
743+
})
744+
.toList();
745+
}
746+
723747
private List<RepositoryPlugin> initRepositories() {
724748
List<RepositoryPlugin> plugins = getPlugins(RepositoryPlugin.class);
725749
for (RepositoryPlugin repo : plugins) {

biz.aQute.bndlib/src/aQute/bnd/osgi/Constants.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,14 @@ public interface Constants {
259259
String REMOTEWORKSPACE = "-remoteworkspace";
260260

261261
/**
262-
* tag for repos which should be used for Resolving bundles. This is also
262+
* tags for repos which should be used for Resolving bundles. This is also
263263
* the default tag for all repos which not have specified tags (also for bc
264264
* reasons)
265265
*/
266266
String REPOTAGS_RESOLVE = "resolve";
267-
268-
/**
269-
* tag for repos which should be included in project compilation
270-
* (-buildpath, -testpath).
271-
*/
272267
String REPOTAGS_COMPILE = "compile";
268+
String REPOTAGS_TEST = "test";
269+
String REPOTAGS_DEBUG = "debug";
273270

274271
String RUNBLACKLIST = "-runblacklist";
275272
String RUNREQUIRES = "-runrequires";

biz.aQute.resolve/test/biz/aQute/resolve/RunResolutionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ public MyBndrun(Workspace workspace, File propertiesFile) throws Exception {
591591
}
592592

593593
@Override
594-
public List<RepositoryPlugin> getRepositories() {
594+
public List<RepositoryPlugin> getRepositories(String... tags) {
595595
return getPlugins(RepositoryPlugin.class);
596596
}
597597

0 commit comments

Comments
 (0)