Skip to content

Commit

Permalink
Add a reproducer to show that PR #2978 was a partial fix
Browse files Browse the repository at this point in the history
The fix of PR #2978 was a partial fix for issue #2977. It fixed the case
of a single bundled but when the bundle providing/requiring the virtual
IU is required by another bundle it fails with the same error as before
even with Tycho 4.0.4:

```
[ERROR] Cannot resolve project dependencies:
[ERROR]   Software being installed: pvumb.bundle2 1.0.0.qualifier
[ERROR]   Missing requirement: pvumb.bundle1 1.0.0.qualifier requires 'org.eclipse.equinox.p2.iu; configure.pvumb.bundle1 0.0.0' but it could not be found
[ERROR]   Cannot satisfy dependency: pvumb.bundle2 1.0.0.qualifier depends on: osgi.bundle; pvumb.bundle1 0.0.0
```

A workaround is to use:

```
requires.0.optional=true
requires.0.greedy=true
```
  • Loading branch information
mdaloia committed Nov 14, 2023
1 parent 57ba377 commit 2cbbdb7
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: pvumb.bundle1
Bundle-SymbolicName: pvumb.bundle1;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: TEST
Bundle-RequiredExecutionEnvironment: JavaSE-17
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Create the virtual IU
units.0.id=configure.pvumb.bundle1
units.0.version=1.0.0
units.0.provides.1.namespace=org.eclipse.equinox.p2.iu
units.0.provides.1.name=configure.pvumb.bundle1
units.0.provides.1.version=1.0.0

# Require in this bundle the created virtual IU
requires.0.namespace=org.eclipse.equinox.p2.iu
requires.0.name=configure.pvumb.bundle1
requires.0.range=0.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin.includes = META-INF/,\
.
16 changes: 16 additions & 0 deletions tycho-its/projects/p2Inf.virtualUnit.multiBundle/bundle1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>tycho-its-project.p2Inf.virtualUnit.multiBundle</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>pvumb.bundle1</artifactId>
<packaging>eclipse-plugin</packaging>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: pvumb.bundle2
Bundle-SymbolicName: pvumb.bundle2;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: TEST
Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Bundle: pvumb.bundle1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin.includes = META-INF/,\
.
16 changes: 16 additions & 0 deletions tycho-its/projects/p2Inf.virtualUnit.multiBundle/bundle2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>tycho-its-project.p2Inf.virtualUnit.multiBundle</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>pvumb.bundle2</artifactId>
<packaging>eclipse-plugin</packaging>

</project>
40 changes: 40 additions & 0 deletions tycho-its/projects/p2Inf.virtualUnit.multiBundle/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<groupId>tycho-its-project.p2Inf.virtualUnit.multiBundle</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
<tycho-version>4.0.4</tycho-version>
</properties>

<modules>
<module>bundle1</module>
<module>bundle2</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<pomDependencies>consider</pomDependencies>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
Expand Down Expand Up @@ -54,10 +55,29 @@ public void testVirtualUnitRequirementDoesNotFailBuild() throws Exception {
String hostUnitId = "pvu.bundle";
String configureUnitId = "configure.pvu.bundle";

File p2Content = new File(verifier.getBasedir(), "bundle/target/p2content.xml");
Document doc = XMLParser.parse(p2Content);
List<Element> units = getUnits(verifier.getBasedir(), "bundle/target/p2content.xml");
Optional<Element> hostUnit = findUnit(units, hostUnitId);
Optional<Element> configureUnit = findUnit(units, configureUnitId);

Stream<Element> hostUnitRequirements = findRequirements(hostUnit);

assertTrue("Host IU " + hostUnitId + " not found", hostUnit.isPresent());
assertTrue("Configure IU " + configureUnitId + " not found", configureUnit.isPresent());
assertTrue("Requirement of IU " + configureUnitId + " not found in IU " + hostUnitId,
hostUnitRequirements.anyMatch(elem -> configureUnitId.equals(elem.getAttributeValue("name"))));
}

@Test
public void testVirtualUnitMultiBundleWithRequirementDoesNotFailBuild() throws Exception {
Verifier verifier = getVerifier("/p2Inf.virtualUnit.multiBundle", false);
verifier.executeGoals(asList("verify"));
verifier.verifyErrorFreeLog();

List<Element> units = doc.getChild("units").getChildren("unit");
// Host bundle and virtual IU assertions
String hostUnitId = "pvumb.bundle1";
String configureUnitId = "configure.pvumb.bundle1";

List<Element> units = getUnits(verifier.getBasedir(), "bundle1/target/p2content.xml");
Optional<Element> hostUnit = findUnit(units, hostUnitId);
Optional<Element> configureUnit = findUnit(units, configureUnitId);

Expand All @@ -67,6 +87,25 @@ public void testVirtualUnitRequirementDoesNotFailBuild() throws Exception {
assertTrue("Configure IU " + configureUnitId + " not found", configureUnit.isPresent());
assertTrue("Requirement of IU " + configureUnitId + " not found in IU " + hostUnitId,
hostUnitRequirements.anyMatch(elem -> configureUnitId.equals(elem.getAttributeValue("name"))));

// Client bundle assertions
String clientUnitId = "pvumb.bundle2";

units = getUnits(verifier.getBasedir(), "bundle2/target/p2content.xml");
Optional<Element> clientUnit = findUnit(units, clientUnitId);

Stream<Element> clientUnitRequirements = findRequirements(clientUnit);

assertTrue("Client IU " + clientUnitId + " not found", clientUnit.isPresent());
assertTrue("Requirement of IU " + hostUnitId + " not found in IU " + clientUnitId,
clientUnitRequirements.anyMatch(elem -> hostUnitId.equals(elem.getAttributeValue("name"))));
}

private static List<Element> getUnits(String baseDir, String filePath) throws IOException {
File p2Content = new File(baseDir, filePath);
Document doc = XMLParser.parse(p2Content);

return doc.getChild("units").getChildren("unit");
}

private static Optional<Element> findUnit(List<Element> units, String hostUnitId) {
Expand Down

0 comments on commit 2cbbdb7

Please sign in to comment.