From 504840d2a8a47c79c8148d7c96ace8f3b635db04 Mon Sep 17 00:00:00 2001 From: Peter Kriens Date: Tue, 24 May 2022 19:08:52 +0200 Subject: [PATCH] [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. Since we use decorations requiring adding literals in our own build, this changes adds support for `++` decoration while `+` decoration still adds literals. After this build is complete, we will following with changing our build to use `++` where necessary and also change the `+` behavior back to not adding literals. Signed-off-by: Peter Kriens Signed-off-by: BJ Hargrave --- .../test/test/InstructionTest.java | 8 ++-- .../test/test/ProcessorTest.java | 16 ++++++++ .../test/test/ProjectTest.java | 37 ++++++++++--------- .../src/aQute/bnd/build/Project.java | 3 ++ .../src/aQute/bnd/osgi/Builder.java | 4 ++ .../src/aQute/bnd/osgi/Processor.java | 6 ++- .../bndtools/editor/completion/BndHover.java | 2 +- docs/_chapters/820-instructions.md | 18 ++++++--- docs/_instructions/runbundles.md | 4 +- 9 files changed, 68 insertions(+), 30 deletions(-) diff --git a/biz.aQute.bndlib.tests/test/test/InstructionTest.java b/biz.aQute.bndlib.tests/test/test/InstructionTest.java index 524317f3ef..3022e7b1a3 100644 --- a/biz.aQute.bndlib.tests/test/test/InstructionTest.java +++ b/biz.aQute.bndlib.tests/test/test/InstructionTest.java @@ -31,7 +31,7 @@ public void testSelect() { public void buildpath_decoration() throws Exception { try (Processor p = new Processor()) { p.setProperty("maven.target.version", "3.3.9"); - p.setProperty("-buildpath+", "\"{aQute.libg}\";version=project;packages=\"!aQute.lib.exceptions.*,*\""); + p.setProperty("-buildpath+", "aQute.libg;version=project;packages=\"!aQute.lib.exceptions.*,*\""); p.setProperty("-buildpath+.maven", "org.apache.maven:*;version=${maven.target.version};maven-scope=provided"); p.setProperty("-buildpath", @@ -50,6 +50,8 @@ public void buildpath_decoration() throws Exception { assertThat(bundles.get("org.apache.maven:maven-settings")).isEmpty(); Instructions decorator = new Instructions(p.mergeProperties("-buildpath" + "+")); + decorator.decorate(bundles); + decorator = new Instructions(p.mergeProperties("-buildpath" + "++")); decorator.decorate(bundles, true); System.out.println(bundles); assertThat(bundles.keySet()).contains("aQute.libg", "org.apache.maven:maven-artifact", @@ -75,13 +77,13 @@ public void buildpath_decoration() throws Exception { @Test public void conditionalpackage_decoration() throws Exception { try (Processor p = new Processor()) { - p.setProperty("-conditionalpackage+", "=!aQute.lib.exceptions.*"); + p.setProperty("-conditionalpackage++", "=!aQute.lib.exceptions.*"); p.setProperty("-conditionalpackage", "aQute.lib.*,aQute.libg.*"); Parameters parameters = p.getMergedParameters("-conditionalpackage"); assertThat(parameters.keySet()).containsExactly("aQute.lib.*", "aQute.libg.*"); - parameters = p.decorated("-conditionalpackage", true); + parameters = p.decorated("-conditionalpackage"); System.out.println(parameters); assertThat(parameters.keySet()).containsExactly("!aQute.lib.exceptions.*", "aQute.lib.*", "aQute.libg.*"); } diff --git a/biz.aQute.bndlib.tests/test/test/ProcessorTest.java b/biz.aQute.bndlib.tests/test/test/ProcessorTest.java index f2d91533e4..0095b91ccc 100644 --- a/biz.aQute.bndlib.tests/test/test/ProcessorTest.java +++ b/biz.aQute.bndlib.tests/test/test/ProcessorTest.java @@ -513,4 +513,20 @@ public void toExternalTest() { assertThat(ext).hasSize(1); assertThat(ext.getTyped("foo")).isEqualTo(value); } + + @Test + public void testMergAndSuffixes() throws IOException { + try (Processor p = new Processor()) { + p.setProperty("foo+", "a,b,c"); + p.setProperty("foo+.1", "x,y,z"); + p.setProperty("foo++", "d,e,f"); + + String plus = p.mergeProperties("foo+"); + assertThat(plus).isEqualTo("a,b,c,x,y,z"); + + String plusplus = p.mergeProperties("foo++"); + assertThat(plusplus).isEqualTo("d,e,f"); + } + + } } diff --git a/biz.aQute.bndlib.tests/test/test/ProjectTest.java b/biz.aQute.bndlib.tests/test/test/ProjectTest.java index 4c14e02413..b1185be55c 100644 --- a/biz.aQute.bndlib.tests/test/test/ProjectTest.java +++ b/biz.aQute.bndlib.tests/test/test/ProjectTest.java @@ -226,26 +226,29 @@ public void testMulti() throws Exception { public void testDecoration() throws Exception { Workspace ws = getWorkspace(IO.getFile("testresources/ws")); Project project = ws.getProject("multipath"); - project.setProperty("-runbundles+", "org.apache.*;startlevel=10"); + project.setProperty("-runbundles++", + "org.apache.*;startlevel=10, org.apache.felix.org.apache.felix.ipojo.ant;startlevel=1000"); assertNotNull(project); List runbundles = new ArrayList<>(project.getRunbundles()); - assertEquals(3, runbundles.size()); - assertEquals("org.apache.felix.configadmin", runbundles.get(0) - .getBundleSymbolicName()); - assertEquals("10", runbundles.get(0) - .getAttributes() - .get("startlevel")); - assertEquals("org.apache.felix.ipojo", runbundles.get(1) - .getBundleSymbolicName()); - assertEquals("10", runbundles.get(1) - .getAttributes() - .get("startlevel")); - assertEquals("osgi.core", runbundles.get(2) - .getBundleSymbolicName()); - assertThat(runbundles.get(2) - .getAttributes() - .get("startlevel")).isNull(); + assertEquals(4, runbundles.size()); + + Container cm = runbundles.get(0); + Container ipojo = runbundles.get(1); + Container osgi = runbundles.get(2); + Container ant = runbundles.get(3); + + assertThat(cm.getBundleSymbolicName()).isEqualTo("org.apache.felix.configadmin"); + assertThat(cm.getAttributes()).containsEntry("startlevel", "10"); + + assertThat(ipojo.getBundleSymbolicName()).isEqualTo("org.apache.felix.ipojo"); + assertThat(ipojo.getAttributes()).containsEntry("startlevel", "10"); + + assertThat(osgi.getBundleSymbolicName()).isEqualTo("osgi.core"); + assertThat(osgi.getAttributes()).doesNotContainKey("startlevel"); + + assertThat(ant.getBundleSymbolicName()).isEqualTo("org.apache.felix.org.apache.felix.ipojo.ant"); + assertThat(ant.getAttributes()).containsEntry("startlevel", "1000"); List runpath = new ArrayList<>(project.getRunpath()); assertEquals(3, runpath.size()); diff --git a/biz.aQute.bndlib/src/aQute/bnd/build/Project.java b/biz.aQute.bndlib/src/aQute/bnd/build/Project.java index 911867ac1b..d4115a1c6b 100644 --- a/biz.aQute.bndlib/src/aQute/bnd/build/Project.java +++ b/biz.aQute.bndlib/src/aQute/bnd/build/Project.java @@ -619,6 +619,9 @@ public List getBundles(Strategy strategyx, String spec, String source Parameters bundles = parseHeader(spec); if (source != null) { Instructions decorator = new Instructions(mergeProperties(source + "+")); + // TODO change the decorated call to remove the second arg. + decorator.decorate(bundles, true); + decorator = new Instructions(mergeProperties(source + "++")); decorator.decorate(bundles, true); } diff --git a/biz.aQute.bndlib/src/aQute/bnd/osgi/Builder.java b/biz.aQute.bndlib/src/aQute/bnd/osgi/Builder.java index 0fa88e5ae9..a33b797568 100644 --- a/biz.aQute.bndlib/src/aQute/bnd/osgi/Builder.java +++ b/biz.aQute.bndlib/src/aQute/bnd/osgi/Builder.java @@ -402,6 +402,7 @@ public boolean hasSources() { @Override protected Jar getExtra() throws Exception { Parameters conditionals = getMergedParameters(CONDITIONAL_PACKAGE); + // TODO change the decorated call to remove the second arg. conditionals.putAll(decorated(CONDITIONALPACKAGE, true)); if (conditionals.isEmpty()) return null; @@ -628,8 +629,10 @@ private void doExpand(Jar dot) throws Exception { } Parameters private_package = getParameters(PRIVATE_PACKAGE); + // TODO change the decorated call to remove the second arg. Parameters privatepackage = decorated(PRIVATEPACKAGE, true); Parameters testpackage = new Parameters(); + // TODO change the decorated call to remove the second arg. Parameters includepackage = decorated(INCLUDEPACKAGE, true); if (buildInstrs.undertest()) { @@ -902,6 +905,7 @@ private Instruction matches(Instructions instructions, String pack, Set