From 824e03b2a9ebb6900f33462012c5290898be936a Mon Sep 17 00:00:00 2001 From: Peter Kriens Date: Thu, 29 Jun 2023 10:09:09 +0200 Subject: [PATCH] 5673 Merged properties for standalone. Fixes #5673 --- Signed-off-by: Peter Kriens Signed-off-by: Peter Kriens --- biz.aQute.bndlib/src/aQute/bnd/build/Run.java | 14 +++++++++---- .../src/aQute/bnd/build/Workspace.java | 2 +- .../src/aQute/bnd/help/Syntax.java | 14 ++++++------- .../src/biz/aQute/resolve/Bndrun.java | 3 +-- .../biz/aQute/resolve/StandaloneTest.java | 20 +++++++++++++++++++ .../testdata/standalone/merged.bndrun | 2 ++ docs/_instructions/standalone.md | 2 ++ 7 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 biz.aQute.resolve/testdata/standalone/merged.bndrun diff --git a/biz.aQute.bndlib/src/aQute/bnd/build/Run.java b/biz.aQute.bndlib/src/aQute/bnd/build/Run.java index 5931a9c4e6..1c4f29f5a9 100644 --- a/biz.aQute.bndlib/src/aQute/bnd/build/Run.java +++ b/biz.aQute.bndlib/src/aQute/bnd/build/Run.java @@ -8,8 +8,8 @@ import java.lang.invoke.MethodType; import java.util.Map; -import aQute.bnd.osgi.Processor; import aQute.bnd.exceptions.Exceptions; +import aQute.bnd.osgi.Processor; public class Run extends Project { @@ -57,11 +57,9 @@ private static Run createRun0(Workspace workspace, File file) throws Exception { Processor processor; if (workspace != null) { Run run = new Run(workspace, file); - if (run.getProperties() - .get(STANDALONE) == null) { + if (!run.isStandAlone()) { return run; } - // -standalone specified processor = run; } else { processor = new Processor(); @@ -73,6 +71,14 @@ private static Run createRun0(Workspace workspace, File file) throws Exception { return run; } + /** + * Answer true if this file defines a -standalone. This is only the main + * header, no check for merged properties. + */ + public boolean isStandAlone() { + return getProperty(STANDALONE) != null; + } + public Run(Workspace workspace, File projectDir, File propertiesFile) throws Exception { super(workspace, projectDir, propertiesFile); } diff --git a/biz.aQute.bndlib/src/aQute/bnd/build/Workspace.java b/biz.aQute.bndlib/src/aQute/bnd/build/Workspace.java index 8168a4b5ee..d9b15b15ce 100644 --- a/biz.aQute.bndlib/src/aQute/bnd/build/Workspace.java +++ b/biz.aQute.bndlib/src/aQute/bnd/build/Workspace.java @@ -1337,7 +1337,7 @@ public static Workspace createStandaloneWorkspace(Processor run, URI base) throw AtomicBoolean copyAll = new AtomicBoolean(false); AtomicInteger counter = new AtomicInteger(); - Parameters standalone = new Parameters(run.getProperty(STANDALONE), ws); + Parameters standalone = run.getMergedParameters(STANDALONE); standalone.stream() .filterKey(locationStr -> { if ("true".equalsIgnoreCase(locationStr)) { diff --git a/biz.aQute.bndlib/src/aQute/bnd/help/Syntax.java b/biz.aQute.bndlib/src/aQute/bnd/help/Syntax.java index fbd93db199..8d476bfe98 100644 --- a/biz.aQute.bndlib/src/aQute/bnd/help/Syntax.java +++ b/biz.aQute.bndlib/src/aQute/bnd/help/Syntax.java @@ -269,12 +269,12 @@ null, null, new Syntax("name", "The display name of the developer", "name='Peter ), version, bundle_symbolic_name, bundle_version), - new Syntax(LIBRARY, "The " + LIBRARY - + " instruction includes a library. A library is included in a bundle in a repository. " - + "It is identified by a capability, a bundle can contain multiple libraries. When used in a " - + "workspace, it will include the `workspace.bnd` file from the library by default. For a project, " - + "this is `project.bnd`. The `include` attribute can identify a file in the library. Libraries are " - + "versioned independently from the bundle. The library can contain additional files, also binary.", + new Syntax(LIBRARY, + "The " + LIBRARY + " instruction includes a library. A library is included in a bundle in a repository. " + + "It is identified by a capability, a bundle can contain multiple libraries. When used in a " + + "workspace, it will include the `workspace.bnd` file from the library by default. For a project, " + + "this is `project.bnd`. The `include` attribute can identify a file in the library. Libraries are " + + "versioned independently from the bundle. The library can contain additional files, also binary.", LIBRARY + ": foo;version=1.2.3", null, null), new Syntax(REQUIRE_BUNDLE, "The " + REQUIRE_BUNDLE + " header specifies the required exports from another bundle.", @@ -703,7 +703,7 @@ null, null, new Syntax("name", "The display name of the developer", "name='Peter "When the bundle version’s qualifier equals 'SNAPSHOT' or ends with '-SNAPSHOT', the STRING value of the -snapshot instruction is substituted for 'SNAPSHOT'.", SNAPSHOT + "=${tstamp}", null, null), new Syntax(STANDALONE, - "Used in bndrun files. Disconnects the bndrun file from the workspace and defines its own Capabilities repositories.", + "Used in bndrun files. Disconnects the bndrun file from the workspace and defines its own Capabilities repositories. This is a merged instruction although be careful that the exact header must be set to treat a bndrun file as standalone.", STANDALONE + "=index.html;name=..., ...", null, null), new Syntax(STRICT, "If set to true, then extra verification is done.", STRICT + "=true", "true,false", Verifier.TRUEORFALSEPATTERN), diff --git a/biz.aQute.resolve/src/biz/aQute/resolve/Bndrun.java b/biz.aQute.resolve/src/biz/aQute/resolve/Bndrun.java index 953503d508..2488f05d12 100644 --- a/biz.aQute.resolve/src/biz/aQute/resolve/Bndrun.java +++ b/biz.aQute.resolve/src/biz/aQute/resolve/Bndrun.java @@ -56,8 +56,7 @@ public static Bndrun createBndrun(Workspace workspace, File file) throws Excepti Processor processor; if (workspace != null) { Bndrun run = new Bndrun(workspace, file); - if (run.getProperties() - .get(STANDALONE) == null) { + if (!run.isStandAlone()) { return run; } // -standalone specified diff --git a/biz.aQute.resolve/test/biz/aQute/resolve/StandaloneTest.java b/biz.aQute.resolve/test/biz/aQute/resolve/StandaloneTest.java index 6dd39b656f..1e56ae7a68 100644 --- a/biz.aQute.resolve/test/biz/aQute/resolve/StandaloneTest.java +++ b/biz.aQute.resolve/test/biz/aQute/resolve/StandaloneTest.java @@ -120,6 +120,26 @@ public void testMultipleUrls() throws Exception { assertEquals("https://example.org/index2.xml", f1.getLocation()); } + @Test + public void testMergedUrls() throws Exception { + File f = IO.getFile("testdata/standalone/merged.bndrun"); + Run run = Run.createRun(null, f); + + List repositories = run.getWorkspace() + .getPlugins(Repository.class); + assertEquals(2, repositories.size()); + assertTrue(repositories.get(0) instanceof OSGiRepository); + assertTrue(repositories.get(1) instanceof OSGiRepository); + + OSGiRepository f0 = (OSGiRepository) repositories.get(0); + assertEquals("repo01", f0.getName()); + assertEquals("https://example.org/index1.xml", f0.getLocation()); + + OSGiRepository f1 = (OSGiRepository) repositories.get(1); + assertEquals("second", f1.getName()); + assertEquals("https://example.org/index2.xml", f1.getLocation()); + } + @Test public void testRelativeUrl() throws Exception { File f = IO.getFile("testdata/standalone/relative_url.bndrun"); diff --git a/biz.aQute.resolve/testdata/standalone/merged.bndrun b/biz.aQute.resolve/testdata/standalone/merged.bndrun new file mode 100644 index 0000000000..8e71e46ab5 --- /dev/null +++ b/biz.aQute.resolve/testdata/standalone/merged.bndrun @@ -0,0 +1,2 @@ +-standalone: https://example.org/index1.xml +-standalone.extra: https://example.org/index2.xml; name=second diff --git a/docs/_instructions/standalone.md b/docs/_instructions/standalone.md index 86ba35b344..b3eed7fb3c 100644 --- a/docs/_instructions/standalone.md +++ b/docs/_instructions/standalone.md @@ -6,6 +6,8 @@ summary: Disconnects the bndrun file from the workspace and defines its on repos from: 3.0.1 --- +The `-standalone` instruction in bnd allows you to transform a bndrun file into a standalone file that doesn't require a workspace. It is a merged property, meaning you can specify additional `repo-specs` using `-standalone.extra`. However, the presence of the exact `-standalone` flag is what determines if the bndrun file is standalone. Without the `-standalone` flag, even if `-standalone.extra` is specified, a workspace will still be required. + A `bndrun` file is by default connected to its workspace, where the workspace defines the context and most important: the repositories. The workspace is by default defined in the workspace's `cnf` directory. The `-standalone` instruction tells bnd that this connection should be severed and that all information is contained in the `bndrun` file. The value of the `-standalone` instruction is used to define the repositories. Each `repo-spec` clause defines a repository.