Skip to content

Commit a44c39c

Browse files
pkriensbjhargrave
authored andcommitted
decoration: Backward compatibility
The decoration changes to always include literals was not backward compatible since it added literals for the `-runbundles`. After some discussion we decided to add `++` for decorations that always add literals and a single `+` for the 6.2 behavior of not adding literals. Signed-off-by: Peter Kriens <[email protected]> Signed-off-by: BJ Hargrave <[email protected]>
1 parent 97bfe6d commit a44c39c

File tree

9 files changed

+67
-34
lines changed

9 files changed

+67
-34
lines changed

biz.aQute.bndlib.tests/test/test/InstructionTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void testSelect() {
3131
public void buildpath_decoration() throws Exception {
3232
try (Processor p = new Processor()) {
3333
p.setProperty("maven.target.version", "3.3.9");
34-
p.setProperty("-buildpath+", "\"{aQute.libg}\";version=project;packages=\"!aQute.lib.exceptions.*,*\"");
34+
p.setProperty("-buildpath+", "aQute.libg;version=project;packages=\"!aQute.lib.exceptions.*,*\"");
3535
p.setProperty("-buildpath+.maven",
3636
"org.apache.maven:*;version=${maven.target.version};maven-scope=provided");
3737
p.setProperty("-buildpath",
@@ -50,6 +50,8 @@ public void buildpath_decoration() throws Exception {
5050
assertThat(bundles.get("org.apache.maven:maven-settings")).isEmpty();
5151

5252
Instructions decorator = new Instructions(p.mergeProperties("-buildpath" + "+"));
53+
decorator.decorate(bundles);
54+
decorator = new Instructions(p.mergeProperties("-buildpath" + "++"));
5355
decorator.decorate(bundles, true);
5456
System.out.println(bundles);
5557
assertThat(bundles.keySet()).contains("aQute.libg", "org.apache.maven:maven-artifact",
@@ -75,13 +77,13 @@ public void buildpath_decoration() throws Exception {
7577
@Test
7678
public void conditionalpackage_decoration() throws Exception {
7779
try (Processor p = new Processor()) {
78-
p.setProperty("-conditionalpackage+", "=!aQute.lib.exceptions.*");
80+
p.setProperty("-conditionalpackage++", "=!aQute.lib.exceptions.*");
7981
p.setProperty("-conditionalpackage", "aQute.lib.*,aQute.libg.*");
8082

8183
Parameters parameters = p.getMergedParameters("-conditionalpackage");
8284
assertThat(parameters.keySet()).containsExactly("aQute.lib.*", "aQute.libg.*");
8385

84-
parameters = p.decorated("-conditionalpackage", true);
86+
parameters = p.decorated("-conditionalpackage");
8587
System.out.println(parameters);
8688
assertThat(parameters.keySet()).containsExactly("!aQute.lib.exceptions.*", "aQute.lib.*", "aQute.libg.*");
8789
}

biz.aQute.bndlib.tests/test/test/ProcessorTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,4 +513,20 @@ public void toExternalTest() {
513513
assertThat(ext).hasSize(1);
514514
assertThat(ext.getTyped("foo")).isEqualTo(value);
515515
}
516+
517+
@Test
518+
public void testMergAndSuffixes() throws IOException {
519+
try (Processor p = new Processor()) {
520+
p.setProperty("foo+", "a,b,c");
521+
p.setProperty("foo+.1", "x,y,z");
522+
p.setProperty("foo++", "d,e,f");
523+
524+
String plus = p.mergeProperties("foo+");
525+
assertThat(plus).isEqualTo("a,b,c,x,y,z");
526+
527+
String plusplus = p.mergeProperties("foo++");
528+
assertThat(plusplus).isEqualTo("d,e,f");
529+
}
530+
531+
}
516532
}

biz.aQute.bndlib.tests/test/test/ProjectTest.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -226,26 +226,29 @@ public void testMulti() throws Exception {
226226
public void testDecoration() throws Exception {
227227
Workspace ws = getWorkspace(IO.getFile("testresources/ws"));
228228
Project project = ws.getProject("multipath");
229-
project.setProperty("-runbundles+", "org.apache.*;startlevel=10");
229+
project.setProperty("-runbundles++",
230+
"org.apache.*;startlevel=10, org.apache.felix.org.apache.felix.ipojo.ant;startlevel=1000");
230231
assertNotNull(project);
231232

232233
List<Container> runbundles = new ArrayList<>(project.getRunbundles());
233-
assertEquals(3, runbundles.size());
234-
assertEquals("org.apache.felix.configadmin", runbundles.get(0)
235-
.getBundleSymbolicName());
236-
assertEquals("10", runbundles.get(0)
237-
.getAttributes()
238-
.get("startlevel"));
239-
assertEquals("org.apache.felix.ipojo", runbundles.get(1)
240-
.getBundleSymbolicName());
241-
assertEquals("10", runbundles.get(1)
242-
.getAttributes()
243-
.get("startlevel"));
244-
assertEquals("osgi.core", runbundles.get(2)
245-
.getBundleSymbolicName());
246-
assertThat(runbundles.get(2)
247-
.getAttributes()
248-
.get("startlevel")).isNull();
234+
assertEquals(4, runbundles.size());
235+
236+
Container cm = runbundles.get(0);
237+
Container ipojo = runbundles.get(1);
238+
Container osgi = runbundles.get(2);
239+
Container ant = runbundles.get(3);
240+
241+
assertThat(cm.getBundleSymbolicName()).isEqualTo("org.apache.felix.configadmin");
242+
assertThat(cm.getAttributes()).containsEntry("startlevel", "10");
243+
244+
assertThat(ipojo.getBundleSymbolicName()).isEqualTo("org.apache.felix.ipojo");
245+
assertThat(ipojo.getAttributes()).containsEntry("startlevel", "10");
246+
247+
assertThat(osgi.getBundleSymbolicName()).isEqualTo("osgi.core");
248+
assertThat(osgi.getAttributes()).doesNotContainKey("startlevel");
249+
250+
assertThat(ant.getBundleSymbolicName()).isEqualTo("org.apache.felix.org.apache.felix.ipojo.ant");
251+
assertThat(ant.getAttributes()).containsEntry("startlevel", "1000");
249252

250253
List<Container> runpath = new ArrayList<>(project.getRunpath());
251254
assertEquals(3, runpath.size());

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,8 @@ public List<Container> getBundles(Strategy strategyx, String spec, String source
619619
Parameters bundles = parseHeader(spec);
620620
if (source != null) {
621621
Instructions decorator = new Instructions(mergeProperties(source + "+"));
622+
decorator.decorate(bundles);
623+
decorator = new Instructions(mergeProperties(source + "++"));
622624
decorator.decorate(bundles, true);
623625
}
624626

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ public boolean hasSources() {
402402
@Override
403403
protected Jar getExtra() throws Exception {
404404
Parameters conditionals = getMergedParameters(CONDITIONAL_PACKAGE);
405-
conditionals.putAll(decorated(CONDITIONALPACKAGE, true));
405+
conditionals.putAll(decorated(CONDITIONALPACKAGE));
406406
if (conditionals.isEmpty())
407407
return null;
408408
logger.debug("do Conditional Package {}", conditionals);
@@ -628,9 +628,9 @@ private void doExpand(Jar dot) throws Exception {
628628
}
629629

630630
Parameters private_package = getParameters(PRIVATE_PACKAGE);
631-
Parameters privatepackage = decorated(PRIVATEPACKAGE, true);
631+
Parameters privatepackage = decorated(PRIVATEPACKAGE);
632632
Parameters testpackage = new Parameters();
633-
Parameters includepackage = decorated(INCLUDEPACKAGE, true);
633+
Parameters includepackage = decorated(INCLUDEPACKAGE);
634634

635635
if (buildInstrs.undertest()) {
636636
String h = mergeProperties(Constants.TESTPACKAGES, "test;presence:=optional");
@@ -902,7 +902,7 @@ private Instruction matches(Instructions instructions, String pack, Set<Instruct
902902
private void doIncludeResources(Jar jar) throws Exception {
903903
Parameters includes = parseHeader(getProperty("Bundle-Includes"));
904904
if (includes.isEmpty()) {
905-
includes = decorated(Constants.INCLUDERESOURCE, true);
905+
includes = decorated(Constants.INCLUDERESOURCE);
906906
includes.putAll(getMergedParameters(Constants.INCLUDE_RESOURCE));
907907
} else {
908908
warning("Please use -includeresource instead of Bundle-Includes");

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2532,7 +2532,9 @@ public String getJavaExecutable(String java) {
25322532

25332533
/**
25342534
* Return a parameters that contains the merged properties of the given key
2535-
* and that is decorated by the merged properties of the key + '+'
2535+
* and that is decorated by the merged properties of the key + '+',
2536+
* optionally including literals, and decorated by the merged properties of
2537+
* the key + '++', always including literals.
25362538
*
25372539
* @param key The key of the property
25382540
*/
@@ -2541,6 +2543,8 @@ public Parameters decorated(String key, boolean literalsIncluded) {
25412543
Parameters parameters = getMergedParameters(key);
25422544
Instructions decorator = new Instructions(mergeProperties(key + "+"));
25432545
decorator.decorate(parameters, literalsIncluded);
2546+
decorator = new Instructions(mergeProperties(key + "++"));
2547+
decorator.decorate(parameters, true);
25442548
return parameters;
25452549
}
25462550

bndtools.core/src/bndtools/editor/completion/BndHover.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
6666
sb.append("\nE.g. ");
6767
sb.append(syntax.getExample());
6868
}
69-
Parameters decorated = properties.decorated(key, true);
69+
Parameters decorated = properties.decorated(key);
7070
if (!decorated.isEmpty()) {
7171
sb.append("\n")
7272
.append(key)

docs/_chapters/820-instructions.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,17 @@ This will result in a buildpath of (when debug is not false) of: `com.example.fo
9494

9595
## Decorated Instructions
9696

97-
Instructions can also be _decorated_. A _decorator_ is a header that ends with a `+` sign. A header `-runbundles` is first merged and then decorated by getting all the properties with the keys that match`-runbundles+(.*)`. Notice that for the decorator the root key includes the `+` sign, the suffixes must come after the `+` sign.
97+
Instructions can also be _decorated_. A _decorator_ is a header that ends with `+` or `++`. A header like `-runbundles` is first _merged_ and then _decorated_.
9898

99-
The decorator is a Parameters, it consists of a key and a set of attributes. The decorator key is usually a glob.
99+
In this case, `-runbundles` is the _stem_. First, the total header is assembled by _merging_ the property that has that stem. If there are properties that match stem + `+.*` or `++.*`, then these properties are used to decorate the merged property. Notice that for the decorator the root key includes the `+` sign, the suffixes must come after the `+` sign. For example, for the header `foo`, the decorator would be `foo+` and that would match a key like `foo+.bar`.
100100

101-
After the instruction is merged, the key of each Parameter entry is matched against all globs in the decorator following the order of the decorator. When the first match is found, the attributes of the decorator clause that matches are stored with the attributes of the Parameter entry, overriding any attribute with the same attribute key. A Parameter entry key can only match one decorator glob.
102-
If the name of the decorator clause attribute starts with `!`, then the attribute, using the attribute name after removing the leading `!`, is removed from the Parameter entry.
103-
If the name of the decorator clause attribute starts with `~`, then the decorator clause attribute value will not overwrite an existing value of the Parameter entry attribute, using the attribute name after removing the leading `~`.
101+
The decorator is a Parameters, it consists of a key and a set of attributes. The decorator key is usually a glob expressions.
102+
103+
After the header is merged, the key of each entry is matched against all globs in the decorator following the order of the decorator. When the first match is found, the attributes of the decorator clause that matches are stored with the attributes of the Parameter entry, overriding any attribute with the same attribute key. A Parameter entry key can only match one decorator glob expression.
104+
105+
For example, `-runbundles a` and `-runbundles+ *;startlevel=20` will result in the content `a;startlevel=20`.
106+
107+
If the name of the decorator clause attribute starts with `!`, then the attribute, using the attribute name after removing the leading `!`, is removed from the Parameter entry. If the name of the decorator clause attribute starts with `~`, then the decorator clause attribute value will not overwrite an existing value of the Parameter entry attribute, using the attribute name after removing the leading `~`.
104108

105109
Example:
106110

@@ -109,10 +113,12 @@ Example:
109113
-foo+.d d;skip=true
110114
111115

112-
In this case, the first entry is `b` and it is matched against the second entry in the `-foo` instruction. Since the decorator has the `skip=true` attribute, it is carried over to the instruction. The result is therefore:
116+
In this case, the first entry matched is `b` and it is matched against the second entry in the `-foo` instruction. Since the decorator has the `skip=true` attribute, it is carried over to the instruction. The result is therefore:
113117

114118
a, b;skip=true; c;skip=false, d;skip=true
115119

120+
If the decoration ends with 2 plus signs, for example `-foo++`, then the literals in the decoration headers will be added to the result if they are not matched to any key in the source header. If the decoration ends with a single `+` sign, literals that do not match are ignored.
121+
116122
* Decoration is not used for all instructions. It should be indicated on the instruction page if it is applied.
117123
* There is a macro [`decorated`](/macros/decorated.html) that can be used to apply decoration to any property key
118124

docs/_instructions/runbundles.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ Use the [-runstartlevel][2] instruction to let the resolver calculate the start
3636
resolver will add the `startlevel` attribute.
3737

3838
Use the _decoration_ facility. With the decoration facility you can augment the `-runbundles` instruction by
39-
specifying the `-runbundles+` property. The keys are _glob_ expressions and any attributes or directives
40-
will be set (or overridden) on the merged `-runbundles` instruction.
39+
specifying the `-runbundles+` property (or the `-runbundles++` if you want to add literals). The keys are _glob_ expressions
40+
and any attributes or directives will be set (or overridden) on the merged `-runbundles` instruction.
4141

4242
-runbundles: \
4343
org.apache.felix.configadmin;version='[1.8.8,1.8.9)',\

0 commit comments

Comments
 (0)