Skip to content

Commit

Permalink
Merge pull request #5709 from pkriens/issue/5673-standalone-merged-pr…
Browse files Browse the repository at this point in the history
…operties

5673 Merged properties for standalone.
  • Loading branch information
pkriens committed Jun 29, 2023
2 parents 5aa8865 + 824e03b commit 6313c4e
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 14 deletions.
14 changes: 10 additions & 4 deletions biz.aQute.bndlib/src/aQute/bnd/build/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion biz.aQute.bndlib/src/aQute/bnd/build/Workspace.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
14 changes: 7 additions & 7 deletions biz.aQute.bndlib/src/aQute/bnd/help/Syntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions biz.aQute.resolve/src/biz/aQute/resolve/Bndrun.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions biz.aQute.resolve/test/biz/aQute/resolve/StandaloneTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Repository> 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");
Expand Down
2 changes: 2 additions & 0 deletions biz.aQute.resolve/testdata/standalone/merged.bndrun
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-standalone: https://example.org/index1.xml
-standalone.extra: https://example.org/index2.xml; name=second
2 changes: 2 additions & 0 deletions docs/_instructions/standalone.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6313c4e

Please sign in to comment.