Skip to content

Commit

Permalink
Use the updated p2 metadata once the project is packed
Browse files Browse the repository at this point in the history
Currently Tycho always uses the INITIAL dependency metadata to compute
the preliminary target platform. As this metadata can change once the
project is packed (e.g. headers added / removed) this can lead to
problems in plugins that depend on the changed plugin because P2 sees
the updated metadata afterwards and fails.

This now distinguish both cases and used the SEED metadata if the
project was already packed.

Fix eclipse-tycho#3824
  • Loading branch information
laeubi committed Jun 1, 2024
1 parent 1c4a81b commit ec590ad
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ public final int hashCode() {
return Objects.hash(getArtifactId(), getGroupId(), getVersion());
}

@Override
public String toString() {
return "ReactorProjectIdentities [GroupId=" + getGroupId() + ", ArtifactId=" + getArtifactId() + ", Version="
+ getVersion() + ", Basedir=" + getBasedir() + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,7 @@ public Map<String, IP2Artifact> generateMetadata(MavenProject project, boolean g
PublisherOptions options = new PublisherOptions();
options.setGenerateDownloadStats(generateDownloadStatsProperty);
options.setGenerateChecksums(generateChecksums);
Map<String, IP2Artifact> generatedMetadata = generateMetadata(artifacts, options, targetDir);
return generatedMetadata;
return generateMetadata(artifacts, options, targetDir);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,9 @@ private Map<IInstallableUnit, ReactorProjectIdentities> getPreliminaryReactorPro
Map<IInstallableUnit, Set<File>> duplicateReactorUIs = new HashMap<>();

for (ReactorProject project : reactorProjects) {
Set<IInstallableUnit> projectIUs = project.getDependencyMetadata(DependencyMetadataType.INITIAL);

if (projectIUs == null) {
Set<IInstallableUnit> projectIUs = getPreliminaryReactorProjectUIs(project);
if (projectIUs == null || projectIUs.isEmpty()) {
continue;
}
for (IInstallableUnit iu : projectIUs) {
Expand All @@ -589,6 +589,19 @@ private Map<IInstallableUnit, ReactorProjectIdentities> getPreliminaryReactorPro
return reactorUIs;
}

private Set<IInstallableUnit> getPreliminaryReactorProjectUIs(ReactorProject project) {
String packaging = project.getPackaging();
if (PackagingType.TYPE_ECLIPSE_PLUGIN.equals(packaging) || PackagingType.TYPE_ECLIPSE_FEATURE.equals(packaging)
|| PackagingType.TYPE_ECLIPSE_TEST_PLUGIN.equals(packaging)) {
File artifact = project.getArtifact();
if (artifact != null && artifact.isFile()) {
//the project was already build, use the seed units as they include anything maybe updated by p2-metadata mojo
return project.getDependencyMetadata(DependencyMetadataType.SEED);
}
}
return project.getDependencyMetadata(DependencyMetadataType.INITIAL);
}

private void applyFilters(TargetPlatformFilterEvaluator filter, Collection<IInstallableUnit> collectionToModify,
Set<IInstallableUnit> reactorProjectUIs, ExecutionEnvironmentResolutionHints eeResolutionHints,
Set<IInstallableUnit> shadowedIus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,20 @@
<artifactId>org.eclipse.swt.gtk.linux.x86</artifactId>
<version>3.102.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<configuration>
<dependency-resolution>
<optionalDependencies>ignore</optionalDependencies>
<profileProperties>
<org.eclipse.swt.buildtime>true</org.eclipse.swt.buildtime>
</profileProperties>
</dependency-resolution>
</configuration>
</plugin>
</plugins>
</build>
</project>
1 change: 1 addition & 0 deletions tycho-its/projects/tycho-ds-dependency/.mvn/maven.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Dtycho.localArtifacts=ignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import java.io.File;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.List;
import java.util.Optional;

import org.apache.maven.it.Verifier;
import org.cyclonedx.exception.ParseException;
Expand Down Expand Up @@ -242,7 +244,8 @@ private void verifyDependency(Dependency parent, String ref) {
}

private void verifyDependency(List<Dependency> dependencies, String ref) {
if (dependencies.stream().noneMatch(dependency -> match(dependency, ref))) {
if (Optional.ofNullable(dependencies).stream().flatMap(Collection::stream)
.noneMatch(dependency -> match(dependency, ref))) {
fail("No dependency found matching: " + ref);
}
}
Expand Down

0 comments on commit ec590ad

Please sign in to comment.