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 2978 #2989

Merged
merged 2 commits into from
Nov 3, 2023
Merged

Pr 2978 #2989

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 @@ -41,16 +41,18 @@
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;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
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;
Expand All @@ -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;
Expand Down Expand Up @@ -261,6 +264,8 @@ public P2TargetPlatform createTargetPlatform(TargetPlatformConfigurationStub tpC
return Optional.empty();
}).ifPresent(externalUIs::add);
}
//add p2.inf items...
gatherP2InfUnits(project, externalUIs);

Map<IInstallableUnit, ReactorProjectIdentities> reactorProjectUIs = getPreliminaryReactorProjectUIs(
reactorProjects);
Expand Down Expand Up @@ -291,6 +296,31 @@ public P2TargetPlatform createTargetPlatform(TargetPlatformConfigurationStub tpC
return targetPlatform;
}

private void gatherP2InfUnits(ReactorProject reactorProject, Set<IInstallableUnit> 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"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this hardcoded version 1.0.0 irrelevant? what if the declared unit sets its version to anything else?
(same below on the else branch of the if)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version is only used to check if the advice should be applied to a unit, as we are not interested in the advice itself but only the additional units it defines the version has actually no influence here.

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<MavenArtifactKey> getMissingJunitBundles(ReactorProject project, Set<IInstallableUnit> externalUIs) {
List<MavenArtifactKey> missing = new ArrayList<>();
if (projectManager != null) {
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: pvu.bundle
Bundle-SymbolicName: pvu.bundle;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: TEST
Bundle-RequiredExecutionEnvironment: JavaSE-17
11 changes: 11 additions & 0 deletions tycho-its/projects/p2Inf.virtualUnit/bundle/META-INF/p2.inf
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions tycho-its/projects/p2Inf.virtualUnit/bundle/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin.includes = META-INF/,\
.
29 changes: 29 additions & 0 deletions tycho-its/projects/p2Inf.virtualUnit/bundle/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>pvu.bundle</artifactId>
<packaging>eclipse-plugin</packaging>

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

</project>
31 changes: 31 additions & 0 deletions tycho-its/projects/p2Inf.virtualUnit/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
<tycho-version>4.0.3</tycho-version>
</properties>

<modules>
<module>bundle</module>
</modules>

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

</project>
Original file line number Diff line number Diff line change
@@ -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.
* <p>
* It used to work until 3.0.5 (using <code><pomDependencies>consider</pomDependencies></code>)
* but since 4.0.0 failed with:
* <pre>
* 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
* </pre>
*
* 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<Element> units = doc.getChild("units").getChildren("unit");
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"))));
}

private static Optional<Element> findUnit(List<Element> units, String hostUnitId) {
return units.stream()
.filter(elem -> hostUnitId.equals(elem.getAttributeValue("id")))
.findFirst();
}

private static Stream<Element> findRequirements(Optional<Element> hostUnit) {
return hostUnit.stream().flatMap(elem -> elem.getChild("requires").getChildren("required").stream());
}

}
Loading