From 2f9593ec1029fc7ea17a590c129ce1faa9a8b9c5 Mon Sep 17 00:00:00 2001 From: Martin D'Aloia Date: Tue, 31 Oct 2023 13:21:59 -0300 Subject: [PATCH 1/2] Add a reproducer IT for issue #2977 Virtual configuration IU in p2.inf does not work in 4.0.3 (works in 3.0.5) --- .../bundle/META-INF/MANIFEST.MF | 7 ++ .../p2Inf.virtualUnit/bundle/META-INF/p2.inf | 11 +++ .../p2Inf.virtualUnit/bundle/build.properties | 2 + .../projects/p2Inf.virtualUnit/bundle/pom.xml | 29 +++++++ tycho-its/projects/p2Inf.virtualUnit/pom.xml | 31 +++++++ .../tycho/test/p2Inf/VirtualUnitTest.java | 80 +++++++++++++++++++ 6 files changed, 160 insertions(+) create mode 100644 tycho-its/projects/p2Inf.virtualUnit/bundle/META-INF/MANIFEST.MF create mode 100644 tycho-its/projects/p2Inf.virtualUnit/bundle/META-INF/p2.inf create mode 100644 tycho-its/projects/p2Inf.virtualUnit/bundle/build.properties create mode 100644 tycho-its/projects/p2Inf.virtualUnit/bundle/pom.xml create mode 100644 tycho-its/projects/p2Inf.virtualUnit/pom.xml create mode 100644 tycho-its/src/test/java/org/eclipse/tycho/test/p2Inf/VirtualUnitTest.java diff --git a/tycho-its/projects/p2Inf.virtualUnit/bundle/META-INF/MANIFEST.MF b/tycho-its/projects/p2Inf.virtualUnit/bundle/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..e84277d955 --- /dev/null +++ b/tycho-its/projects/p2Inf.virtualUnit/bundle/META-INF/MANIFEST.MF @@ -0,0 +1,7 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: pvu.bundle +Bundle-SymbolicName: pvu.bundle;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: TEST +Bundle-RequiredExecutionEnvironment: JavaSE-17 diff --git a/tycho-its/projects/p2Inf.virtualUnit/bundle/META-INF/p2.inf b/tycho-its/projects/p2Inf.virtualUnit/bundle/META-INF/p2.inf new file mode 100644 index 0000000000..36434565aa --- /dev/null +++ b/tycho-its/projects/p2Inf.virtualUnit/bundle/META-INF/p2.inf @@ -0,0 +1,11 @@ +# Create the virtual IU +units.0.id=configure.pvu.bundle +units.0.version=1.0.0 +units.0.provides.1.namespace=org.eclipse.equinox.p2.iu +units.0.provides.1.name=configure.pvu.bundle +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.pvu.bundle +requires.0.range=0.0.0 diff --git a/tycho-its/projects/p2Inf.virtualUnit/bundle/build.properties b/tycho-its/projects/p2Inf.virtualUnit/bundle/build.properties new file mode 100644 index 0000000000..7594fab8d5 --- /dev/null +++ b/tycho-its/projects/p2Inf.virtualUnit/bundle/build.properties @@ -0,0 +1,2 @@ +bin.includes = META-INF/,\ + . diff --git a/tycho-its/projects/p2Inf.virtualUnit/bundle/pom.xml b/tycho-its/projects/p2Inf.virtualUnit/bundle/pom.xml new file mode 100644 index 0000000000..2a785844bf --- /dev/null +++ b/tycho-its/projects/p2Inf.virtualUnit/bundle/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + + + tycho-its-project.p2Inf.virtualUnit + parent + 1.0.0-SNAPSHOT + + + pvu.bundle + eclipse-plugin + + + + + org.eclipse.tycho + target-platform-configuration + ${tycho-version} + + consider + + + + + + diff --git a/tycho-its/projects/p2Inf.virtualUnit/pom.xml b/tycho-its/projects/p2Inf.virtualUnit/pom.xml new file mode 100644 index 0000000000..a8ceaabba6 --- /dev/null +++ b/tycho-its/projects/p2Inf.virtualUnit/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + + tycho-its-project.p2Inf.virtualUnit + parent + 1.0.0-SNAPSHOT + pom + + + 4.0.3 + + + + bundle + + + + + + org.eclipse.tycho + tycho-maven-plugin + ${tycho-version} + true + + + + + diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/p2Inf/VirtualUnitTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/p2Inf/VirtualUnitTest.java new file mode 100644 index 0000000000..9bb5c1078b --- /dev/null +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/p2Inf/VirtualUnitTest.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2023 Martin D'Aloia and others. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.tycho.test.p2Inf; + +import static java.util.Arrays.asList; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.apache.maven.it.Verifier; +import org.eclipse.tycho.test.AbstractTychoIntegrationTest; +import org.junit.Test; + +import de.pdark.decentxml.Document; +import de.pdark.decentxml.Element; +import de.pdark.decentxml.XMLParser; + +import java.io.File; +import java.util.List; +import java.util.Optional; +import java.util.stream.Stream; + +/** + * Test that a virtual IU created just with metadata in a p2.inf file can be required + * in the same p2.inf file. + *

+ * It used to work until 3.0.5 (using consider) + * but since 4.0.0 failed with: + *

+ * Cannot resolve project dependencies:
+ *   Software being installed: pvu.bundle 1.0.0.qualifier
+ *   Missing requirement: pvu.bundle 1.0.0.qualifier requires 'org.eclipse.equinox.p2.iu; configure.pvu.bundle 0.0.0' but it could not be found
+ * 
+ * + * See https://github.com/eclipse-tycho/tycho/blob/master/RELEASE_NOTES.md#mixed-reactor-setups-require-the-new-resolver-now + * and https://github.com/eclipse-tycho/tycho/issues/2977 + */ +public class VirtualUnitTest extends AbstractTychoIntegrationTest { + + @Test + public void testVirtualUnitRequirementDoesNotFailBuild() throws Exception { + Verifier verifier = getVerifier("/p2Inf.virtualUnit", false); + verifier.executeGoals(asList("verify")); + verifier.verifyErrorFreeLog(); + + 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 units = doc.getChild("units").getChildren("unit"); + Optional hostUnit = findUnit(units, hostUnitId); + Optional configureUnit = findUnit(units, configureUnitId); + + Stream 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")))); + } + + private static Optional findUnit(List units, String hostUnitId) { + return units.stream() + .filter(elem -> hostUnitId.equals(elem.getAttributeValue("id"))) + .findFirst(); + } + + private static Stream findRequirements(Optional hostUnit) { + return hostUnit.stream().flatMap(elem -> elem.getChild("requires").getChildren("required").stream()); + } + +} From 670d17fd40ddef9bb11e7f8571604640a054bd2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Fri, 3 Nov 2023 13:19:34 +0100 Subject: [PATCH 2/2] Make additional P2 units from p2.inf available to the target-platform Currently units from p2.inf are not published to the target-platform what can fail resolving when these are referenced in the project. This publishes these units into the target-platform state of the project. Fix https://github.com/eclipse-tycho/tycho/issues/2977 --- .../p2resolver/TargetPlatformFactoryImpl.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/TargetPlatformFactoryImpl.java b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/TargetPlatformFactoryImpl.java index e1c02fe946..82c410df41 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/TargetPlatformFactoryImpl.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/TargetPlatformFactoryImpl.java @@ -41,8 +41,8 @@ import org.codehaus.plexus.logging.Logger; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.URIUtil; -import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactDescriptor; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.metadata.IArtifactKey; @@ -50,7 +50,9 @@ import org.eclipse.equinox.p2.metadata.IProvidedCapability; import org.eclipse.equinox.p2.metadata.MetadataFactory; import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription; +import org.eclipse.equinox.p2.metadata.Version; import org.eclipse.equinox.p2.metadata.VersionRange; +import org.eclipse.equinox.p2.publisher.AdviceFileAdvice; import org.eclipse.equinox.p2.query.IQuery; import org.eclipse.equinox.p2.query.IQueryResult; import org.eclipse.equinox.p2.query.QueryUtil; @@ -68,6 +70,7 @@ import org.eclipse.tycho.IRepositoryIdManager; import org.eclipse.tycho.MavenArtifactKey; import org.eclipse.tycho.MavenRepositoryLocation; +import org.eclipse.tycho.PackagingType; import org.eclipse.tycho.ReactorProject; import org.eclipse.tycho.ReactorProjectIdentities; import org.eclipse.tycho.ResolvedArtifactKey; @@ -261,6 +264,8 @@ public P2TargetPlatform createTargetPlatform(TargetPlatformConfigurationStub tpC return Optional.empty(); }).ifPresent(externalUIs::add); } + //add p2.inf items... + gatherP2InfUnits(project, externalUIs); Map reactorProjectUIs = getPreliminaryReactorProjectUIs( reactorProjects); @@ -291,6 +296,31 @@ public P2TargetPlatform createTargetPlatform(TargetPlatformConfigurationStub tpC return targetPlatform; } + private void gatherP2InfUnits(ReactorProject reactorProject, Set externalUIs) { + if (reactorProject == null) { + return; + } + AdviceFileAdvice advice; + if (PackagingType.TYPE_ECLIPSE_PLUGIN.equals(reactorProject.getPackaging())) { + advice = new AdviceFileAdvice(reactorProject.getArtifactId(), Version.parseVersion("1.0.0"), + new Path(reactorProject.getBasedir().getAbsolutePath()), AdviceFileAdvice.BUNDLE_ADVICE_FILE); + } else if (PackagingType.TYPE_ECLIPSE_FEATURE.equals(reactorProject.getPackaging())) { + advice = new AdviceFileAdvice(reactorProject.getArtifactId(), Version.parseVersion("1.0.0"), + new Path(reactorProject.getBasedir().getAbsolutePath()), new Path("p2.inf")); + } else { + //not a project with advice... + return; + } + if (advice.containsAdvice()) { + InstallableUnitDescription[] descriptions = advice.getAdditionalInstallableUnitDescriptions(null); + if (descriptions != null && descriptions.length > 0) { + for (InstallableUnitDescription desc : descriptions) { + externalUIs.add(MetadataFactory.createInstallableUnit(desc)); + } + } + } + } + private List getMissingJunitBundles(ReactorProject project, Set externalUIs) { List missing = new ArrayList<>(); if (projectManager != null) {