Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr 3039 #3121

Merged
merged 2 commits into from
Dec 6, 2023
Merged

Pr 3039 #3121

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

Expand Down Expand Up @@ -264,8 +265,10 @@ public P2TargetPlatform createTargetPlatform(TargetPlatformConfigurationStub tpC
return Optional.empty();
}).ifPresent(externalUIs::add);
}
//add p2.inf items...
gatherP2InfUnits(project, externalUIs);
//add p2.inf extra units from all projects...
for (ReactorProject reactorProject : Objects.requireNonNullElse(reactorProjects, List.<ReactorProject> of())) {
gatherP2InfUnits(reactorProject, externalUIs);
}

Map<IInstallableUnit, ReactorProjectIdentities> reactorProjectUIs = getPreliminaryReactorProjectUIs(
reactorProjects);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@
import org.eclipse.equinox.p2.metadata.IVersionedId;
import org.eclipse.tycho.ArtifactType;
import org.eclipse.tycho.DefaultArtifactKey;
import org.eclipse.tycho.IRawArtifactFileProvider;
import org.eclipse.tycho.IDependencyMetadata.DependencyMetadataType;
import org.eclipse.tycho.IRawArtifactFileProvider;
import org.eclipse.tycho.PackagingType;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.ReactorProjectIdentities;
import org.eclipse.tycho.TargetEnvironment;
Expand Down Expand Up @@ -328,12 +329,12 @@ private String[] asArrayUnlessNull(String string) {
private ReactorProject createReactorProject(String artifactId, String[] primaryUnitIds, String[] secondaryUnitIds) {
File basedir = new File("tychotestdummy"); // not dereferenced in the code under test, so the path doesn't need to exist
ReactorProjectStub result = new ReactorProjectStub(basedir, artifactId);
result.setPackagingType(PackagingType.TYPE_ECLIPSE_PLUGIN);

DependencyMetadata dependencyMetadata = new DependencyMetadata();
dependencyMetadata.setDependencyMetadata(DependencyMetadataType.SEED, createUnits(primaryUnitIds));
dependencyMetadata.setDependencyMetadata(DependencyMetadataType.RESOLVE, createUnits(secondaryUnitIds));
result.setDependencyMetadata(dependencyMetadata);

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public String getPackaging() {
return unlessNull(packagingType);
}

public void setPackagingType(String packagingType) {
this.packagingType = packagingType;
}

@Override
public Set<IInstallableUnit> getDependencyMetadata(DependencyMetadataType type) {
return switch (type) {
Expand Down
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
Loading