Skip to content

Commit 7fa6c2b

Browse files
committed
P2ResolverImpl: Don't add implicit test deps to eclipse-test-plugin
In c6edec4 / https://bugs.eclipse.org/bugs/show_bug.cgi?id=443396 implicit dependencies were added to every 'eclipse-test-plugin' project to work around a very special situation: When building the eclipse.platform.ui repository the test harness is part of the same reactor build as well and the tests do not explicitly depend on it. The dependency resolution was then failing because, quote [1], - Tycho sees that org.eclipse.ui.ide.application is part of the reactor, and hence filters all other versions of this bundle from the external target platform content. - The afterProjectsRead dependency resolution doesn't find a dependency between the eclipse-test-plugin module and the org.eclipse.ui.ide.application module, so it doesn't add it to the target platform for the eclipse-test-plugin module. (Adding only the "needed" reactor modules instead of all previously built modules is something which doesn't give us any benefits today, but it is a prerequisite for allowing parallel builds in the future.) - The resolution of the test runtime fails. However, this had the undesired side-effect that these artificial dependencies were added to every other 'eclipse-test-plugin' project as well, which does not need it. This caused every 'eclipse-test-plugin' to list all the UI hardness dependencies in their dependencies tree, even ending up in things like generated SBOMs, which is incorrect. With recent improvements to Tycho, especially with #2092, the quoted issue above is not an issue anymore: Instead of filtering out shadowed units from the external target platform completely, it can now still access them if needed. Therefore, this change reverts implicit adding of UI harness dependencies. This results in a slight change of behavior when running tests in 'eclipse.platform.ui': - Before this change, the *project / reactor' version of the test harness was used when executing tests that did not themselves depend on the workbench. - After this change, the *external target* version of the test harness is used + some warnings are logged. - If this turns out to be a problem, Eclipse side has to adapt, e.g. by adding <extraRequirements> to target-platform-configuration in eclipse.platform.releng.aggregator/eclipse-platform-parent/pom.xml, restoring the previous Tycho behavior - but only at the place where it is actually needed. [1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=443396#c8 Fixes #5349.
1 parent 0bb68c0 commit 7fa6c2b

15 files changed

Lines changed: 131 additions & 108 deletions

File tree

tycho-core/src/main/java/org/eclipse/tycho/core/resolver/TestPluginPackagingInstallableUnitProvider.java

Lines changed: 0 additions & 73 deletions
This file was deleted.

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.Objects;
3131
import java.util.Optional;
3232
import java.util.Set;
33-
import java.util.function.Consumer;
3433

3534
import org.apache.felix.resolver.util.CopyOnWriteSet;
3635
import org.eclipse.core.runtime.IProgressMonitor;
@@ -53,7 +52,6 @@
5352
import org.eclipse.tycho.IArtifactFacade;
5453
import org.eclipse.tycho.IDependencyMetadata.DependencyMetadataType;
5554
import org.eclipse.tycho.IllegalArtifactReferenceException;
56-
import org.eclipse.tycho.PackagingType;
5755
import org.eclipse.tycho.ReactorProject;
5856
import org.eclipse.tycho.ReactorProjectIdentities;
5957
import org.eclipse.tycho.TargetEnvironment;
@@ -109,12 +107,6 @@ public Map<TargetEnvironment, P2ResolutionResult> resolveTargetDependencies(Targ
109107
ReactorProject project) {
110108
P2TargetPlatform targetPlatform = getTargetFromContext(context);
111109

112-
// Adding extra deps for testswould better be performed as part of tycho-core resolver rather
113-
// than in this P2ResolverImpl
114-
if (project != null && PackagingType.TYPE_ECLIPSE_TEST_PLUGIN.equals(project.getPackaging())) {
115-
addDependenciesForTests(additionalRequirements::add);
116-
}
117-
118110
// we need a linked hashmap to maintain iteration-order, some of the code relies on it!
119111
Map<TargetEnvironment, P2ResolutionResult> results = new LinkedHashMap<>();
120112
Set<IInstallableUnit> usedTargetPlatformUnits = new LinkedHashSet<>();
@@ -466,19 +458,6 @@ private static void addArtifactFile(DefaultP2ResolutionResult result, IInstallab
466458
// throw new IllegalArgumentException();
467459
}
468460

469-
public static void addDependenciesForTests(Consumer<IRequirement> requirementsConsumer) {
470-
/*
471-
* In case the test harness bundles (cf. TestMojo.getTestDependencies()) are part of the
472-
* reactor, the dependency resolution needs to identify them as a dependency of
473-
* eclipse-test-plugin modules. Otherwise they will be missing in the final target platform
474-
* of the module - they would be filtered from the external target platform, and not added
475-
* from the reactor - and hence the test runtime resolution would fail (see bug 443396).
476-
*/
477-
requirementsConsumer.accept(optionalGreedyRequirementTo("org.eclipse.equinox.launcher"));
478-
requirementsConsumer.accept(optionalGreedyRequirementTo("org.eclipse.core.runtime"));
479-
requirementsConsumer.accept(optionalGreedyRequirementTo("org.eclipse.ui.ide.application"));
480-
}
481-
482461
@Override
483462
public void setPomDependencies(PomDependencies pomDependencies) {
484463
this.pomDependencies = pomDependencies;

tycho-core/src/test/java/org/eclipse/tycho/p2resolver/P2ResolverTest.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static org.eclipse.tycho.test.util.InstallableUnitMatchers.unitWithId;
2525
import static org.hamcrest.CoreMatchers.hasItem;
2626
import static org.hamcrest.MatcherAssert.assertThat;
27+
import static org.hamcrest.Matchers.matchesRegex;
2728
import static org.junit.Assert.assertEquals;
2829
import static org.junit.Assert.assertFalse;
2930
import static org.junit.Assert.assertThrows;
@@ -198,18 +199,33 @@ public void testEclipseRepository() throws Exception {
198199
}
199200

200201
@Test
201-
public void testEclipseTestPluginAutomaticallyDependsOnTestHarnesses() throws Exception {
202-
tpConfig.addP2Repository(resourceFile("repositories/e342").toURI());
203-
addContextProject(resourceFile("resolver/bundle.uitestharness"), TYPE_ECLIPSE_PLUGIN);
202+
public void testEclipseTestPluginTestHarnessesCanBeResolvedEvenIfHarnessIsPartOfReactorItself() throws Exception {
203+
// https://github.com/eclipse-tycho/tycho/issues/5349
204+
205+
// Add a an external target platform that contains the test harness bundle 'org.eclipse.ui.ide.application' (stub)
206+
tpConfig.addP2Repository(resourceFile("repositories/testHarnessExternalStub").toURI());
207+
208+
// Make the test harness itself part of the reactor as well by adding a project stub for 'org.eclipse.ui.ide.application'
209+
this.reactorProjects.add(createReactorProject(resourceFile("resolver/bundle.uitestharness"),
210+
TYPE_ECLIPSE_PLUGIN, "org.eclipse.ui.ide.application"));
204211

205212
projectToResolve = createReactorProject(resourceFile("resolver/bundle.nodeps"), TYPE_ECLIPSE_TEST_PLUGIN,
206213
"bundle.nodeps");
207214

215+
// Simulate surefire's adding of the additional test harness 'org.eclipse.ui.ide.application' dependency
216+
impl.addAdditionalBundleDependency("org.eclipse.ui.ide.application");
217+
208218
result = singleEnv(impl.resolveTargetDependencies(getTargetPlatform(), projectToResolve));
209219

210220
assertEquals(2, result.getArtifacts().size());
211-
assertThat(result.getArtifacts(), hasItem(withId("bundle.nodeps")));
212-
assertThat(result.getArtifacts(), hasItem(withId("org.eclipse.ui.ide.application")));
221+
assertThat(result.getArtifacts(), hasItem(withIdAndVersion("bundle.nodeps", "1.0.0.qualifier")));
222+
223+
// The test harness is satisfied from the shadowed bundle of the external target platform
224+
assertThat(result.getArtifacts(), hasItem(
225+
withIdAndVersion("org.eclipse.ui.ide.application", "1.0.0.bundleStubFromExternalTargetPlatform")));
226+
// Since the bundle is also part of the reactor, we expect a warning message
227+
logVerifier.expectWarning(matchesRegex(
228+
"(?s).*org\\.eclipse\\.ui\\.ide\\.application 1\\.0\\.0\\.bundleStubFromExternalTargetPlatform.*shadowed.*"));
213229
}
214230

215231
@Test
@@ -516,17 +532,17 @@ private static P2ResolutionResult.Entry getClassifiedArtifact(P2ResolutionResult
516532
return selectedEntry;
517533
}
518534

519-
static Matcher<Entry> withId(final String id) {
535+
static Matcher<Entry> withIdAndVersion(final String id, final String version) {
520536
return new TypeSafeMatcher<>() {
521537

522538
@Override
523539
protected boolean matchesSafely(Entry entry) {
524-
return id.equals(entry.getId());
540+
return id.equals(entry.getId()) && version.equals(entry.getVersion());
525541
}
526542

527543
@Override
528544
public void describeTo(Description description) {
529-
description.appendText("an artifact with ID " + id);
545+
description.appendText("an artifact with ID " + id + " and version " + version);
530546
}
531547
};
532548
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<?artifactRepository version='1.1.0'?>
3+
<repository name='e342' type='org.eclipse.equinox.p2.artifact.repository.simpleRepository' version='1'>
4+
<properties size='2'>
5+
<property name='p2.timestamp' value='1308584189023'/>
6+
<property name='p2.compressed' value='false'/>
7+
</properties>
8+
<mappings size='3'>
9+
<rule filter='(&amp; (classifier=osgi.bundle))' output='${repoUrl}/plugins/${id}_${version}.jar'/>
10+
<rule filter='(&amp; (classifier=binary))' output='${repoUrl}/binary/${id}_${version}'/>
11+
<rule filter='(&amp; (classifier=org.eclipse.update.feature))' output='${repoUrl}/features/${id}_${version}.jar'/>
12+
</mappings>
13+
<artifacts size='1'>
14+
<artifact classifier='osgi.bundle' id='org.eclipse.ui.ide.application' version='1.0.0.bundleStubFromExternalTargetPlatform'>
15+
<properties size='3'>
16+
<property name='artifact.size' value='394'/>
17+
<property name='download.size' value='394'/>
18+
</properties>
19+
</artifact>
20+
</artifacts>
21+
</repository>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<?metadataRepository version='1.1.0'?>
3+
<repository name='e342' type='org.eclipse.equinox.internal.p2.metadata.repository.LocalMetadataRepository' version='1'>
4+
<properties size='2'>
5+
<property name='p2.timestamp' value='1308584189029'/>
6+
<property name='p2.compressed' value='false'/>
7+
</properties>
8+
<units size='1'>
9+
<unit id='org.eclipse.ui.ide.application' version='1.0.0.bundleStubFromExternalTargetPlatform'>
10+
<update id='org.eclipse.core.runtime' range='[0.0.0,1.0.0.bundleStubFromExternalTargetPlatform)' severity='0'/>
11+
<properties size='5'>
12+
<property name='df_LT.providerName' value='Eclipse.org'/>
13+
<property name='df_LT.pluginName' value='UI Test Harness Stub'/>
14+
<property name='org.eclipse.equinox.p2.name' value='%pluginName'/>
15+
<property name='org.eclipse.equinox.p2.provider' value='%providerName'/>
16+
<property name='org.eclipse.equinox.p2.bundle.localization' value='plugin'/>
17+
</properties>
18+
<provides size='4'>
19+
<provided namespace='org.eclipse.equinox.p2.iu' name='org.eclipse.ui.ide.application' version='1.0.0.bundleStubFromExternalTargetPlatform'/>
20+
<provided namespace='osgi.bundle' name='org.eclipse.ui.ide.application' version='1.0.0.bundleStubFromExternalTargetPlatform'/>
21+
<provided namespace='org.eclipse.equinox.p2.eclipse.type' name='bundle' version='1.0.0'/>
22+
<provided namespace='org.eclipse.equinox.p2.localization' name='df_LT' version='1.0.0'/>
23+
</provides>
24+
<artifacts size='1'>
25+
<artifact classifier='osgi.bundle' id='org.eclipse.ui.ide.application' version='1.0.0.bundleStubFromExternalTargetPlatform'/>
26+
</artifacts>
27+
<touchpoint id='org.eclipse.equinox.p2.osgi' version='1.0.0'/>
28+
<touchpointData size='1'>
29+
<instructions size='1'>
30+
<instruction key='manifest'>
31+
Manifest-Version: 1.0&#xA;Bundle-ManifestVersion: 2&#xA;Bundle-Name: Stub for the bundle containing the non-UI test harness&#xA;Bundle-SymbolicName: org.eclipse.osgi&#xA;Bundle-Version: 1.0.0.bundleStubFromExternalTargetPlatform&#xA;
32+
</instruction>
33+
</instructions>
34+
</touchpointData>
35+
</unit>
36+
</units>
37+
</repository>

tycho-core/src/test/resources/resolver/bundle.uitestharness/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: Stub for the bundle containing the UI test harness
44
Bundle-SymbolicName: org.eclipse.ui.ide.application
5-
Bundle-Version: 1.0.0.qualifier
5+
Bundle-Version: 9999.0.0.qualifier

tycho-its/projects/sbom/example.test1/META-INF/MANIFEST.MF renamed to tycho-its/projects/sbom/example.testFragment/META-INF/MANIFEST.MF

File renamed without changes.

tycho-its/projects/sbom/example.test1/build.properties renamed to tycho-its/projects/sbom/example.testFragment/build.properties

File renamed without changes.

tycho-its/projects/sbom/example.test2/META-INF/MANIFEST.MF renamed to tycho-its/projects/sbom/example.testStandAlone/META-INF/MANIFEST.MF

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
3-
Bundle-Name: Test-Fragment with SBOM
3+
Bundle-Name: Test-Bundle with SBOM
44
Bundle-SymbolicName: example.test2
55
Bundle-Version: 1.0.0.qualifier
6-
Fragment-Host: example.plugin
6+
Require-Bundle: example.plugin
77
Automatic-Module-Name: example.test2
88
Bundle-RequiredExecutionEnvironment: JavaSE-17

0 commit comments

Comments
 (0)