Skip to content

Commit

Permalink
library: Don't use Workspace repo for Workspace
Browse files Browse the repository at this point in the history
When processing a -library instruction in the Workspace object, we must
not use the Workspace repo to find resources since we are in the middle
of initializing the Workspace upon which all Projects depends and
inherit from. Attempting to locate Workspace library references in
workspace Projects is a form of a cycle.

So when processing -library for the Workspace, we avoid the Workspace
repo.

There are still issues with Projects getting -library info from other
Projects due to ordering issues in initialization of Projects. Some
Projects will necessarily initialize before other Projects and thus may
not locate -library info in yet to be initialized Projects.

Signed-off-by: BJ Hargrave <[email protected]>
  • Loading branch information
bjhargrave committed Feb 22, 2022
1 parent 4391707 commit 6d0034b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
14 changes: 11 additions & 3 deletions biz.aQute.bndlib.tests/test/test/LibraryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public void testLatestVersion() throws Exception {
b1.setBundleVersion("0.0.1");
b1.setProperty("Provide-Capability",
"bnd.library; bnd.library=foo; version= 1.2.3; path = lib/foo");
b1.setIncludeResource("lib/foo/project.bnd;literal='foo=1.2.3\n'");
b1.setIncludeResource(
"lib/foo/project.bnd;literal='foo=1.2.3\n',lib/foo/workspace.bnd;literal='ws=1.2.3\n'");
Jar j1 = b1.build();
repository.put(new JarResource(j1).openInputStream(), null);

Expand All @@ -125,7 +126,8 @@ public void testLatestVersion() throws Exception {
b2.setBundleVersion("0.0.2");
b2.setProperty("Provide-Capability",
"bnd.library; bnd.library=foo; version= 1.2.4; path = lib/foo");
b2.setIncludeResource("lib/foo/project.bnd;literal='foo=1.2.4\n'");
b2.setIncludeResource(
"lib/foo/project.bnd;literal='foo=1.2.4\n',lib/foo/workspace.bnd;literal='ws=1.2.4\n'");
Jar j2 = b2.build();
repository.put(new JarResource(j2).openInputStream(), null);

Expand All @@ -134,7 +136,8 @@ public void testLatestVersion() throws Exception {
b3.setBundleVersion("0.0.3");
b3.setProperty("Provide-Capability",
"bnd.library; bnd.library=foo; version= 1.2.2; path = lib/foo");
b3.setIncludeResource("lib/foo/project.bnd;literal='foo=1.2.2\n'");
b3.setIncludeResource(
"lib/foo/project.bnd;literal='foo=1.2.2\n',lib/foo/workspace.bnd;literal='ws=1.2.2\n'");
Jar j3 = b3.build();
repository.put(new JarResource(j3).openInputStream(), null);
}
Expand All @@ -150,5 +153,10 @@ public void testLatestVersion() throws Exception {

}

IO.store("-library=foo", new File(IO.mkdirs(new File(testDir, "cnf/ext")), "test.bnd"));
try (Workspace ws = new Workspace(testDir)) {
assertThat(ws.getProperty("ws")).isEqualTo("1.2.4");
assertThat(ws.getProperty("foo")).isNull();
}
}
}
12 changes: 9 additions & 3 deletions biz.aQute.bndlib/src/aQute/bnd/build/LibraryHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,12 @@ void update(Processor p, String library, String header) {
error(p, header, name, "Invalid version %s", versionString);
continue;
}
we = getLibrary(name, versionString);
// If the processor is the Workspace, we can't use the
// Workspace Repo since the projects depend upon the
// Workspace which we are augmenting
ResourceRepositoryStrategy strategy = (p == ws) ? ResourceRepositoryStrategy.REPOS
: ResourceRepositoryStrategy.ALL;
we = getLibrary(name, versionString, strategy);
}

if (we == null) {
Expand All @@ -238,9 +243,10 @@ private void error(Processor p, String header, String clause, String format, Obj
}
}

private RepoLibrary getLibrary(String name, String versionRange) throws Exception {
private RepoLibrary getLibrary(String name, String versionRange, ResourceRepositoryStrategy strategy)
throws Exception {
String filter = LibraryNamespace.filter(name, versionRange);
return ws.findProviders(LibraryNamespace.NAMESPACE, filter, ResourceRepositoryStrategy.ALL)
return ws.findProviders(LibraryNamespace.NAMESPACE, filter, strategy)
.map(c -> new RepoLibrary(name, c))
.sorted()
.findFirst()
Expand Down

0 comments on commit 6d0034b

Please sign in to comment.