Skip to content

Commit 0ff0c62

Browse files
laeubieclipse-tycho-bot
authored andcommitted
Use the updated p2 metadata once the project is packed
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 #3824 (cherry picked from commit fc91332)
1 parent 96b127f commit 0ff0c62

File tree

6 files changed

+88
-30
lines changed

6 files changed

+88
-30
lines changed

p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/InstallableUnitGenerator.java

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public class InstallableUnitGenerator {
8686

8787
private static final String KEY_UNITS = "InstallableUnitGenerator.units";
8888

89+
private static final String KEY_ARTIFACT_FILE = "InstallableUnitGenerator.artifactFile";
90+
8991
@Requirement
9092
private IProvisioningAgent provisioningAgent;
9193

@@ -165,28 +167,37 @@ public Collection<IInstallableUnit> getInstallableUnits(MavenProject project, Ma
165167
Objects.requireNonNull(session);
166168
log.debug("Computing installable units for " + project + ", force update = " + forceUpdate);
167169
synchronized (project) {
168-
if (!forceUpdate) {
169-
Object contextValue = project.getContextValue(KEY_UNITS);
170-
if (contextValue instanceof Collection<?>) {
171-
Collection<IInstallableUnit> collection = (Collection<IInstallableUnit>) contextValue;
172-
if (isCompatible(collection)) {
173-
log.debug("Using cached value for " + project);
174-
return collection;
175-
} else {
176-
log.debug("Cannot use cached value for " + project
177-
+ " because of incompatible classloaders, update is forced");
178-
}
179-
}
180-
}
181170
File basedir = project.getBasedir();
182171
if (basedir == null || !basedir.isDirectory()) {
183172
log.warn("No valid basedir for " + project + " found");
184173
return Collections.emptyList();
185174
}
175+
File projectArtifact = getProjectArtifact(project);
176+
if (!forceUpdate) {
177+
// first check if the packed state might has changed...
178+
if (Objects.equals(project.getContextValue(KEY_ARTIFACT_FILE), projectArtifact)) {
179+
Object contextValue = project.getContextValue(KEY_UNITS);
180+
if (contextValue instanceof Collection<?>) {
181+
// now check if we are classlaoder compatible...
182+
Collection<IInstallableUnit> collection = (Collection<IInstallableUnit>) contextValue;
183+
if (isCompatible(collection)) {
184+
log.debug("Using cached value for " + project);
185+
return collection;
186+
} else {
187+
log.debug("Cannot use cached value for " + project
188+
+ " because of incompatible classloaders, update is forced");
189+
}
190+
}
191+
} else {
192+
log.info("Cannot use cached value for " + project
193+
+ " because project artifact has changed, update is forced");
194+
}
195+
}
186196
String packaging = project.getPackaging();
187197
String version = project.getVersion();
188198
String artifactId = project.getArtifactId();
189-
List<IPublisherAction> actions = getPublisherActions(packaging, basedir, version, artifactId);
199+
List<IPublisherAction> actions = getPublisherActions(packaging, basedir, projectArtifact, version,
200+
artifactId);
190201
Collection<IInstallableUnit> publishedUnits = publisher.publishMetadata(actions);
191202
for (InstallableUnitProvider unitProvider : getProvider(project, session)) {
192203
log.debug("Asking " + unitProvider + " for additional units for " + project);
@@ -207,24 +218,38 @@ public Collection<IInstallableUnit> getInstallableUnits(MavenProject project, Ma
207218
log.debug("Cannot generate any InstallableUnit for packaging type '" + packaging + "' for " + project);
208219
}
209220
project.setContextValue(KEY_UNITS, result);
221+
project.setContextValue(KEY_ARTIFACT_FILE, projectArtifact);
210222
return result;
211223

212224
}
213225
}
214226

215-
private List<IPublisherAction> getPublisherActions(String packaging, File basedir, String version,
216-
String artifactId) throws CoreException {
227+
private static File getProjectArtifact(MavenProject project) {
228+
Artifact artifact = project.getArtifact();
229+
if (artifact != null) {
230+
File file = artifact.getFile();
231+
if (file != null && file.exists()) {
232+
return file;
233+
}
234+
}
235+
return null;
236+
}
237+
238+
private List<IPublisherAction> getPublisherActions(String packaging, File basedir, File projectArtifact,
239+
String version, String artifactId) throws CoreException {
217240
List<IPublisherAction> actions = new ArrayList<>();
218241
switch (packaging) {
219242
case PackagingType.TYPE_ECLIPSE_TEST_PLUGIN:
220243
case PackagingType.TYPE_ECLIPSE_PLUGIN: {
221-
actions.add(new BundlesAction(new File[] { basedir }));
244+
File bundleFile = Objects.requireNonNullElse(projectArtifact, basedir);
245+
actions.add(new BundlesAction(new File[] { bundleFile }));
222246
break;
223247
}
224248
case PackagingType.TYPE_ECLIPSE_FEATURE: {
225249
FeatureParser parser = new FeatureParser();
226-
Feature feature = parser.parse(basedir);
227-
feature.setLocation(basedir.getAbsolutePath());
250+
File featureFile = Objects.requireNonNullElse(projectArtifact, basedir);
251+
Feature feature = parser.parse(featureFile);
252+
feature.setLocation(featureFile.getAbsolutePath());
228253
FeatureDependenciesAction action = new FeatureDependenciesAction(feature);
229254
actions.add(action);
230255
break;
@@ -353,32 +378,31 @@ public synchronized Collection<IInstallableUnit> getUnits(Artifact artifact) {
353378
if (PackagingType.TYPE_ECLIPSE_PLUGIN.equals(type)
354379
|| PackagingType.TYPE_ECLIPSE_TEST_PLUGIN.equals(type) || "bundle".equals(type)) {
355380
List<IPublisherAction> actions = getPublisherActions(PackagingType.TYPE_ECLIPSE_PLUGIN, file,
356-
artifact.getVersion(), artifact.getArtifactId());
381+
file, artifact.getVersion(), artifact.getArtifactId());
357382
return units = publisher.publishMetadata(actions);
358383
} else if (PackagingType.TYPE_ECLIPSE_FEATURE.equals(type)) {
359384
List<IPublisherAction> actions = getPublisherActions(PackagingType.TYPE_ECLIPSE_FEATURE, file,
360-
artifact.getVersion(), artifact.getArtifactId());
385+
file, artifact.getVersion(), artifact.getArtifactId());
361386
return units = publisher.publishMetadata(actions);
362387
} else {
363388
boolean isBundle = false;
364389
boolean isFeature = false;
365390
try (JarFile jarFile = new JarFile(file)) {
366391
Manifest manifest = jarFile.getManifest();
367392
isBundle = manifest != null
368-
&& manifest.getMainAttributes()
369-
.getValue(Constants.BUNDLE_SYMBOLICNAME) != null;
393+
&& manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME) != null;
370394
isFeature = jarFile.getEntry("feature.xml") != null;
371395
} catch (IOException e) {
372396
// can't determine the type then...
373397
}
374398
if (isBundle) {
375399
List<IPublisherAction> actions = getPublisherActions(PackagingType.TYPE_ECLIPSE_PLUGIN,
376-
file, artifact.getVersion(), artifact.getArtifactId());
400+
file, file, artifact.getVersion(), artifact.getArtifactId());
377401
return units = publisher.publishMetadata(actions);
378402
}
379403
if (isFeature) {
380404
List<IPublisherAction> actions = getPublisherActions(PackagingType.TYPE_ECLIPSE_FEATURE,
381-
file, artifact.getVersion(), artifact.getArtifactId());
405+
file, file, artifact.getVersion(), artifact.getArtifactId());
382406
return units = publisher.publishMetadata(actions);
383407
}
384408
}

tycho-api/src/main/java/org/eclipse/tycho/ReactorProjectIdentities.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,10 @@ public final int hashCode() {
4646
return Objects.hash(getArtifactId(), getGroupId(), getVersion());
4747
}
4848

49+
@Override
50+
public String toString() {
51+
return "ReactorProjectIdentities [GroupId=" + getGroupId() + ", ArtifactId=" + getArtifactId() + ", Version="
52+
+ getVersion() + ", Basedir=" + getBasedir() + "]";
53+
}
54+
4955
}

tycho-core/src/main/java/org/eclipse/tycho/p2resolver/P2GeneratorImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,7 @@ public Map<String, IP2Artifact> generateMetadata(MavenProject project, boolean g
451451
PublisherOptions options = new PublisherOptions();
452452
options.setGenerateDownloadStats(generateDownloadStatsProperty);
453453
options.setGenerateChecksums(generateChecksums);
454-
Map<String, IP2Artifact> generatedMetadata = generateMetadata(artifacts, options, targetDir);
455-
return generatedMetadata;
454+
return generateMetadata(artifacts, options, targetDir);
456455
}
457456

458457
@Override

tycho-core/src/main/java/org/eclipse/tycho/p2resolver/TargetPlatformFactoryImpl.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,9 @@ private Map<IInstallableUnit, ReactorProjectIdentities> getPreliminaryReactorPro
561561
Map<IInstallableUnit, Set<File>> duplicateReactorUIs = new HashMap<>();
562562

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

566-
if (projectIUs == null) {
565+
Set<IInstallableUnit> projectIUs = getPreliminaryReactorProjectUIs(project);
566+
if (projectIUs == null || projectIUs.isEmpty()) {
567567
continue;
568568
}
569569
for (IInstallableUnit iu : projectIUs) {
@@ -589,6 +589,19 @@ private Map<IInstallableUnit, ReactorProjectIdentities> getPreliminaryReactorPro
589589
return reactorUIs;
590590
}
591591

592+
private Set<IInstallableUnit> getPreliminaryReactorProjectUIs(ReactorProject project) {
593+
String packaging = project.getPackaging();
594+
if (PackagingType.TYPE_ECLIPSE_PLUGIN.equals(packaging) || PackagingType.TYPE_ECLIPSE_FEATURE.equals(packaging)
595+
|| PackagingType.TYPE_ECLIPSE_TEST_PLUGIN.equals(packaging)) {
596+
File artifact = project.getArtifact();
597+
if (artifact != null && artifact.isFile()) {
598+
//the project was already build, use the seed units as they include anything maybe updated by p2-metadata mojo
599+
return project.getDependencyMetadata(DependencyMetadataType.SEED);
600+
}
601+
}
602+
return project.getDependencyMetadata(DependencyMetadataType.INITIAL);
603+
}
604+
592605
private void applyFilters(TargetPlatformFilterEvaluator filter, Collection<IInstallableUnit> collectionToModify,
593606
Set<IInstallableUnit> reactorProjectUIs, ExecutionEnvironmentResolutionHints eeResolutionHints,
594607
Set<IInstallableUnit> shadowedIus) {

tycho-its/projects/eeProfile.resolution.fragments/org.eclipse.swt.gtk.linux.x86/pom.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,20 @@
1313
<artifactId>org.eclipse.swt.gtk.linux.x86</artifactId>
1414
<version>3.102.0-SNAPSHOT</version>
1515
<packaging>eclipse-plugin</packaging>
16-
16+
<build>
17+
<plugins>
18+
<plugin>
19+
<groupId>org.eclipse.tycho</groupId>
20+
<artifactId>target-platform-configuration</artifactId>
21+
<configuration>
22+
<dependency-resolution>
23+
<optionalDependencies>ignore</optionalDependencies>
24+
<profileProperties>
25+
<org.eclipse.swt.buildtime>true</org.eclipse.swt.buildtime>
26+
</profileProperties>
27+
</dependency-resolution>
28+
</configuration>
29+
</plugin>
30+
</plugins>
31+
</build>
1732
</project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Dtycho.localArtifacts=ignore

0 commit comments

Comments
 (0)