From 5f42c87339a28bd244bf11795e7eb5800fdd07d3 Mon Sep 17 00:00:00 2001 From: Arnoud Glimmerveen Date: Thu, 19 Dec 2024 06:15:01 +0100 Subject: [PATCH] Rework on fix for #6364 based on PR feedback. * Moved decoration between older/newer check to ensure that check also incorporates the decoration. * Added JUnit test. Signed-off-by: Arnoud Glimmerveen --- .../src/biz/aQute/resolve/RunResolution.java | 20 ++++++++-------- .../biz/aQute/resolve/RunResolutionTest.java | 23 +++++++++++++++++++ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/biz.aQute.resolve/src/biz/aQute/resolve/RunResolution.java b/biz.aQute.resolve/src/biz/aQute/resolve/RunResolution.java index 2a762a9e74..99c93bc85a 100644 --- a/biz.aQute.resolve/src/biz/aQute/resolve/RunResolution.java +++ b/biz.aQute.resolve/src/biz/aQute/resolve/RunResolution.java @@ -196,6 +196,15 @@ public boolean updateBundles(BndEditModel model) { List newer = new ArrayList<>(nonNull(getRunBundles())); List older = new ArrayList<>(nonNull(model.getRunBundles())); + // Apply the -runbundles decorator on the computed RunBundles + Parameters bundles = HeaderClause.toParameters(newer); + Instructions decorator = new Instructions(project.mergeProperties(Constants.RUNBUNDLES_DECORATOR)); + decorator.decorate(bundles); + + newer = bundles.entrySet() + .stream().map(entry -> new VersionedClause(entry.getKey(), entry.getValue())) + .collect(Collectors.toList()); + if (newer.equals(older)) return false; @@ -210,16 +219,7 @@ public boolean updateBundles(BndEditModel model) { newer = older; } - // Apply the -runbundles decorator on the computed RunBundles - Parameters bundles = HeaderClause.toParameters(newer); - Instructions decorator = new Instructions(project.mergeProperties(Constants.RUNBUNDLES_DECORATOR)); - decorator.decorate(bundles); - - List decorated = bundles.entrySet() - .stream().map(entry -> new VersionedClause(entry.getKey(), entry.getValue())) - .toList(); - - model.setRunBundles(decorated); + model.setRunBundles(newer); return true; } diff --git a/biz.aQute.resolve/test/biz/aQute/resolve/RunResolutionTest.java b/biz.aQute.resolve/test/biz/aQute/resolve/RunResolutionTest.java index 47896c1b24..c091efd18d 100644 --- a/biz.aQute.resolve/test/biz/aQute/resolve/RunResolutionTest.java +++ b/biz.aQute.resolve/test/biz/aQute/resolve/RunResolutionTest.java @@ -14,6 +14,8 @@ import java.util.Set; import java.util.TreeMap; +import aQute.bnd.build.model.clauses.HeaderClause; +import aQute.bnd.build.model.conversions.NoopConverter; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -502,4 +504,25 @@ public void testPrintHumanReadableDifference() throws Exception { } + @Test + public void testStartLevelDecoration() throws Exception { + Bndrun bndrun = Bndrun.createBndrun(workspace, IO.getFile(ws.toFile(), "test.simple/resolve.bndrun")); + bndrun.setProperty("-runstartlevel", "order=leastdependenciesfirst,begin=100,step=10"); + + // Decorate test.simple to get startlevel 90 (which would otherwise be 110 within the assigned runstartlevel). + bndrun.setProperty("-runbundles+", "test.simple;startlevel=90"); + + List runBundles = List.copyOf(bndrun.resolve(false, false, new NoopConverter<>())); + + assertThat(runBundles).hasSize(2); + assertThat(runBundles.get(0) + .getName()).isEqualTo("osgi.enroute.junit.wrapper"); + assertThat(runBundles.get(0) + .getAttribs()).containsEntry(Constants.RUNBUNDLES_STARTLEVEL_ATTRIBUTE, "100"); + assertThat(runBundles.get(1) + .getName()).isEqualTo("test.simple"); + assertThat(runBundles.get(1) + .getAttribs()).containsEntry(Constants.RUNBUNDLES_STARTLEVEL_ATTRIBUTE, "90"); + } + }