Skip to content

Commit

Permalink
Fix for #6364 to ensure that runbundles decorator is applied to the r…
Browse files Browse the repository at this point in the history
…unbundles resolver output as well.

Signed-off-by: Arnoud Glimmerveen <[email protected]>
  • Loading branch information
glimmerveen committed Dec 14, 2024
1 parent 8e5cfa7 commit 509d0e2
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 1 deletion.
13 changes: 12 additions & 1 deletion 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 @@ -208,7 +210,16 @@ public boolean updateBundles(BndEditModel model) {
newer = older;
}

model.setRunBundles(newer);
// 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<VersionedClause> decorated = bundles.entrySet()
.stream().map(entry -> new VersionedClause(entry.getKey(), entry.getValue()))
.toList();

model.setRunBundles(decorated);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
invoker.goals=--no-transfer-progress package

# Run mvn with --debug for debug logging
#invoker.debug=true

# Run mvn in debugging mode and wait for a debugger to attach
#invoker.environmentVariables.MAVEN_DEBUG_OPTS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>biz.aQute.bnd-test</groupId>
<artifactId>resolver-test</artifactId>
<version>0.0.1</version>
<relativePath>../parent</relativePath>
</parent>

<artifactId>resolve-with-starlevel-and-runbundles-decorator</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.13</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.eventadmin</artifactId>
<version>1.4.8</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>5.4.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-resolver-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import aQute.bnd.build.Workspace
import aQute.bnd.build.model.BndEditModel
import aQute.bnd.osgi.Processor
import aQute.bnd.properties.Document
import aQute.lib.io.IO;

// The resolve-with-starlevel-and-runbundles-decorator case

// Check the bndrun file exist!
File bndrunFile = new File(basedir, 'test.bndrun')
assert bndrunFile.isFile()

// Load the BndEditModel of the bndrun file so we can inspect the result
Processor processor = new Processor()
processor.setProperties(bndrunFile)
BndEditModel bem = new BndEditModel(Workspace.createStandaloneWorkspace(processor, bndrunFile.toURI()))
Document doc = new Document(IO.collect(bndrunFile))
bem.loadFrom(doc)

// Get the -runbundles.
def bemRunBundles = bem.getRunBundles()
assert bemRunBundles
assert bemRunBundles.size() == 4

StringBuilder sb = new StringBuilder()
bemRunBundles.get(0).formatTo(sb)
assert sb.toString() == "org.apache.felix.eventadmin;version='[1.4.8,1.4.9)';startlevel=1000"

sb = new StringBuilder()
bemRunBundles.get(1).formatTo(sb)
assert sb.toString() == "ch.qos.logback.core;version='[1.2.13,1.2.14)';startlevel=1001"

sb = new StringBuilder()
bemRunBundles.get(2).formatTo(sb)
assert sb.toString() == "ch.qos.logback.classic;version='[1.2.13,1.2.14)';startlevel=1002"

sb = new StringBuilder()
bemRunBundles.get(3).formatTo(sb)
assert sb.toString() == "slf4j.api;version='[1.7.36,1.7.37)';startlevel=999"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-runfw: org.apache.felix.framework
-runrequires: \
osgi.identity;filter:='(osgi.identity=org.apache.felix.eventadmin)',\
osgi.identity;filter:='(osgi.identity=slf4j.api)'

-runbundles+: slf4j.api; startlevel=999

-runstartlevel: \
order = leastdependenciesfirst, \
begin = 1000, \
step = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
invoker.goals=--no-transfer-progress package

# Run mvn with --debug for debug logging
#invoker.debug=true

# Run mvn in debugging mode and wait for a debugger to attach
#invoker.environmentVariables.MAVEN_DEBUG_OPTS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>biz.aQute.bnd-test</groupId>
<artifactId>resolver-test</artifactId>
<version>0.0.1</version>
<relativePath>../parent</relativePath>
</parent>

<artifactId>resolve-with-starlevel</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.13</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.eventadmin</artifactId>
<version>1.4.8</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>5.4.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-resolver-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import aQute.bnd.build.Workspace
import aQute.bnd.build.model.BndEditModel
import aQute.bnd.osgi.Processor
import aQute.bnd.properties.Document
import aQute.lib.io.IO;

// The resolve-with-starlevel case

// Check the bndrun file exist!
File bndrunFile = new File(basedir, 'test.bndrun')
assert bndrunFile.isFile()

// Load the BndEditModel of the bndrun file so we can inspect the result
Processor processor = new Processor()
processor.setProperties(bndrunFile)
BndEditModel bem = new BndEditModel(Workspace.createStandaloneWorkspace(processor, bndrunFile.toURI()))
Document doc = new Document(IO.collect(bndrunFile))
bem.loadFrom(doc)

// Get the -runbundles.
def bemRunBundles = bem.getRunBundles()
assert bemRunBundles
assert bemRunBundles.size() == 4

StringBuilder sb = new StringBuilder()
bemRunBundles.get(0).formatTo(sb)
assert sb.toString() == "org.apache.felix.eventadmin;version='[1.4.8,1.4.9)';startlevel=1000"

sb = new StringBuilder()
bemRunBundles.get(1).formatTo(sb)
assert sb.toString() == "ch.qos.logback.core;version='[1.2.13,1.2.14)';startlevel=1001"

sb = new StringBuilder()
bemRunBundles.get(2).formatTo(sb)
assert sb.toString() == "ch.qos.logback.classic;version='[1.2.13,1.2.14)';startlevel=1002"

sb = new StringBuilder()
bemRunBundles.get(3).formatTo(sb)
assert sb.toString() == "slf4j.api;version='[1.7.36,1.7.37)';startlevel=1003"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-runfw: org.apache.felix.framework
-runrequires: \
osgi.identity;filter:='(osgi.identity=org.apache.felix.eventadmin)',\
osgi.identity;filter:='(osgi.identity=slf4j.api)'

-runstartlevel: \
order = leastdependenciesfirst, \
begin = 1000, \
step = 1

0 comments on commit 509d0e2

Please sign in to comment.