Skip to content

Commit

Permalink
Merge pull request #6407 from Thales-Netherlands/6364-startlevel-runb…
Browse files Browse the repository at this point in the history
…undles-decorator

Apply the -runbundles+ decorator on the computed RunBundles when resolving
  • Loading branch information
pkriens authored Dec 23, 2024
2 parents 2734eca + efd0bae commit 4024ba2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions biz.aQute.resolve/src/biz/aQute/resolve/RunResolution.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import aQute.bnd.header.Parameters;
import aQute.bnd.osgi.Instructions;
import org.osgi.resource.Resource;
import org.osgi.resource.Wire;
import org.osgi.service.resolver.ResolutionException;
Expand Down Expand Up @@ -194,6 +196,15 @@ public boolean updateBundles(BndEditModel model) {
List<VersionedClause> newer = new ArrayList<>(nonNull(getRunBundles()));
List<VersionedClause> 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;

Expand Down
23 changes: 23 additions & 0 deletions biz.aQute.resolve/test/biz/aQute/resolve/RunResolutionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<? extends HeaderClause> 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");
}

}

0 comments on commit 4024ba2

Please sign in to comment.