Skip to content

Commit

Permalink
Merge pull request #6002 from timothyjward/resolver-verify
Browse files Browse the repository at this point in the history
Ensure bnd-resolver-maven-plugin verify handles multi-release jars
  • Loading branch information
timothyjward committed Jan 30, 2024
2 parents 193dfc8 + 09237ba commit 43a572e
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ public List<Resource> getResources() {
return new ArrayList<>(resources);
}

/**
* Tests whether the supplied resources is contained in this repository
*
* @param resource the resource to test
* @return true if this resource is already part of this ResourcesRepository
*/
public boolean contains(Resource resource) {
return resources.contains(resource);
}

/**
* Returns a collector that accumulates capabilities into a list.
*
Expand Down
16 changes: 16 additions & 0 deletions biz.aQute.resolve/src/biz/aQute/resolve/RunResolution.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package biz.aQute.resolve;

import static java.util.stream.Collectors.toList;

import java.io.File;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
Expand Down Expand Up @@ -30,6 +32,7 @@
import aQute.bnd.help.instructions.ResolutionInstructions;
import aQute.bnd.help.instructions.ResolutionInstructions.RunStartLevel;
import aQute.bnd.help.instructions.ResolutionInstructions.Runorder;
import aQute.bnd.osgi.BundleId;
import aQute.bnd.osgi.Constants;
import aQute.bnd.osgi.Processor;
import aQute.bnd.osgi.resource.ResourceUtils;
Expand Down Expand Up @@ -280,6 +283,19 @@ public List<VersionedClause> getRunBundles() {
return versionedClauses;
}

/**
* Gets the resolution result as a list of bundle ids that represent the new
* -runbundles
*
* @return the BundleIds of the bundles in the resolution
*/
public List<BundleId> getResolvedRunBundles() {
return getOrderedResources().stream()
.filter(this::isBundle)
.map(ResourceUtils::getBundleId)
.collect(toList());
}

/**
* Return the current -runbundles.
*
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,48 @@
<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>verify-multirelease</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>

<properties>
<it.resolve.skip>true</it.resolve.skip>
</properties>

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.16.1</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-resolver-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>verify</goal>
</goals>
<configuration>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-runfw: org.apache.felix.framework
-runrequires: osgi.identity;filter:='(osgi.identity=com.fasterxml.jackson.core.jackson-databind)'

-runbundles: com.fasterxml.jackson.core.jackson-databind;version='[2.16.1,2.16.2)',\
com.fasterxml.jackson.core.jackson-core;version='[2.16.1,2.16.2)',\
com.fasterxml.jackson.core.jackson-annotations;version='[2.16.1,2.16.2)'

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import aQute.bnd.maven.lib.resolve.Scope;
import aQute.bnd.osgi.BundleId;
import aQute.bnd.osgi.Constants;
import aQute.bnd.osgi.repository.ResourcesRepository;
import aQute.bnd.osgi.resource.CapReqBuilder;
import aQute.bnd.osgi.resource.ResourceUtils;
import aQute.bnd.unmodifiable.Sets;
Expand Down Expand Up @@ -168,10 +169,7 @@ private Operation getOperation() {
RunResolution result = run.resolve(new BundleFilter(runBundleReqs));

if (result.isOK()) {
List<BundleId> resolved = result.getContainers()
.stream()
.map(Container::getBundleId)
.collect(toList());
List<BundleId> resolved = result.getResolvedRunBundles();

List<BundleId> missing = expectedRunbundles.stream()
.filter(c -> !resolved.contains(c))
Expand Down Expand Up @@ -231,6 +229,12 @@ private Operation getOperation() {

private static class BundleFilter implements ResolutionCallback {
private final List<Requirement> bundleRequirements;
/**
* We slowly build up a repository of resources which we allow. This
* includes any SupportingResources without us having to introspect
* them.
*/
private final ResourcesRepository repo = new ResourcesRepository();

public BundleFilter(List<Requirement> bundleRequirements) {
this.bundleRequirements = bundleRequirements;
Expand All @@ -240,11 +244,17 @@ public BundleFilter(List<Requirement> bundleRequirements) {
public void processCandidates(Requirement requirement, Set<Capability> wired, List<Capability> candidates) {
Iterator<Capability> it = candidates.iterator();
while (it.hasNext()) {
Capability id = ResourceUtils.getIdentityCapability(it.next()
.getResource());
if (bundleRequirements.stream()
.noneMatch(r -> ResourceUtils.matches(r, id))) {
it.remove();
Resource resource = it.next()
.getResource();
if (!repo.contains(resource)) {
Capability id = ResourceUtils.getIdentityCapability(resource);
if (bundleRequirements.stream()
.noneMatch(r -> ResourceUtils.matches(r, id))) {
// Not part of the repository and not in -runbundles
it.remove();
} else {
repo.add(resource);
}
}
}
}
Expand Down

0 comments on commit 43a572e

Please sign in to comment.