Skip to content

Commit

Permalink
Fix eclipse-tycho#462 Delay Pom considered items to the final Target …
Browse files Browse the repository at this point in the history
…Platform

calculation

Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
  • Loading branch information
laeubi committed Jan 2, 2022
1 parent 2edd657 commit 6eec46c
Show file tree
Hide file tree
Showing 18 changed files with 210 additions and 134 deletions.
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2013 SAP AG and others.
* Copyright (c) 2013, 2021 SAP AG 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
Expand All @@ -9,6 +9,7 @@
*
* Contributors:
* SAP AG - initial API and implementation
* Christoph Läubrich - Issue #462 - Delay Pom considered items to the final Target Platform calculation
*******************************************************************************/
package org.eclipse.tycho.target;

Expand All @@ -19,7 +20,9 @@
import java.util.List;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
Expand All @@ -30,9 +33,12 @@
import org.eclipse.sisu.equinox.EquinoxServiceFactory;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.ReactorProjectIdentities;
import org.eclipse.tycho.core.DependencyResolver;
import org.eclipse.tycho.core.osgitools.DefaultReactorProject;
import org.eclipse.tycho.core.resolver.DefaultDependencyResolverFactory;
import org.eclipse.tycho.p2.repository.GAV;
import org.eclipse.tycho.p2.repository.RepositoryLayoutHelper;
import org.eclipse.tycho.p2.target.facade.PomDependencyCollector;
import org.eclipse.tycho.repository.registry.facade.ReactorRepositoryManagerFacade;

@Mojo(name = "target-platform", threadSafe = true)
Expand All @@ -49,13 +55,24 @@ public class TargetPlatformMojo extends AbstractMojo {
@Component
private Logger logger;

@Component
private LegacySupport legacySupport;

@Component
private DefaultDependencyResolverFactory dependencyResolverLocator;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
synchronized (LOCK) {
ReactorRepositoryManagerFacade repositoryManager = osgiServices
.getService(ReactorRepositoryManagerFacade.class);
List<ReactorProjectIdentities> upstreamProjects = getReferencedTychoProjects();
repositoryManager.computeFinalTargetPlatform(DefaultReactorProject.adapt(project), upstreamProjects);
ReactorProject reactorProject = DefaultReactorProject.adapt(project);
MavenSession session = legacySupport.getSession();
DependencyResolver dependencyResolver = dependencyResolverLocator.lookupDependencyResolver(project);
PomDependencyCollector pomDependenciesCollector = dependencyResolver.resolvePomDependencies(session,
project);
repositoryManager.computeFinalTargetPlatform(reactorProject, upstreamProjects, pomDependenciesCollector);
}
}

Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2013, 2020 SAP SE and others.
* Copyright (c) 2013, 2021 SAP SE 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
Expand Down Expand Up @@ -84,12 +84,12 @@ public void testTargetPlatformComputationInIntegration() throws Exception {
tpConfig.addP2Repository(
new MavenRepositoryLocation(null, ResourceUtil.resourceFile("repositories/launchers").toURI()));
subject.computePreliminaryTargetPlatform(currentProject, tpConfig,
new ExecutionEnvironmentConfigurationStub("JavaSE-1.7"), null, pomDependencyCollector);
new ExecutionEnvironmentConfigurationStub("JavaSE-1.7"), null);

ReactorProjectIdentities upstreamProject = new ReactorProjectIdentitiesStub(
ResourceUtil.resourceFile("projectresult"));

subject.computeFinalTargetPlatform(currentProject, Arrays.asList(upstreamProject));
subject.computeFinalTargetPlatform(currentProject, Arrays.asList(upstreamProject), pomDependencyCollector);

P2TargetPlatform finalTP = (P2TargetPlatform) currentProject
.getContextValue("org.eclipse.tycho.core.TychoConstants/targetPlatform");
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2020 Sonatype Inc. and others.
* Copyright (c) 2008, 2021 Sonatype Inc. 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
Expand Down Expand Up @@ -506,11 +506,11 @@ public void testResolveWithoutProject() throws Exception {
}

private P2TargetPlatform getTargetPlatform() {
return tpFactory.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, reactorProjects, pomDependencies);
return tpFactory.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, reactorProjects);
}

private P2TargetPlatform getTargetPlatform(ExecutionEnvironmentResolutionHandler eeResolutionHandler) {
return tpFactory.createTargetPlatform(tpConfig, eeResolutionHandler, reactorProjects, pomDependencies);
return tpFactory.createTargetPlatform(tpConfig, eeResolutionHandler, reactorProjects);
}

private static P2ResolutionResult singleEnv(Map<TargetEnvironment, P2ResolutionResult> map) {
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2020 Sonatype Inc. and others.
* Copyright (c) 2011, 2021 Sonatype Inc. 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
Expand Down Expand Up @@ -103,7 +103,7 @@ static ArtifactMock existingMetadata() {
private Collection<IInstallableUnit> getTargetPlatformUnits() {
TestResolverFactory resolverFactory = new TestResolverFactory(logVerifier.getLogger());
P2TargetPlatform platform = resolverFactory.getTargetPlatformFactoryImpl()
.createTargetPlatform(new TargetPlatformConfigurationStub(), NOOP_EE_RESOLUTION_HANDLER, null, subject);
.createTargetPlatform(new TargetPlatformConfigurationStub(), NOOP_EE_RESOLUTION_HANDLER, null);
return platform.getInstallableUnits();
}
}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2020 SAP SE and others.
* Copyright (c) 2008, 2021 SAP SE 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
Expand Down Expand Up @@ -98,35 +98,33 @@ public void setUpSubjectAndContext() throws Exception {
public void testFinalTargetPlatformNotContainsPreliminaryReactorIU() throws Exception {
List<ReactorProject> preliminaryReactor = Arrays.asList(createReactorProject("artifactId", "reactor.id", null));
P2TargetPlatform preliminaryTP = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER,
preliminaryReactor, pomDependencyCollector);
preliminaryReactor);

// final TP without any reactor content
P2TargetPlatform finalTP = subject.createTargetPlatformWithUpdatedReactorUnits(preliminaryTP, null,
REACTOR_ARTIFACTS);
REACTOR_ARTIFACTS, pomDependencyCollector);

assertThat(finalTP.getInstallableUnits(), not(hasItem(unitWithId("reactor.id"))));
}

@Test
public void testFinalTargetPlatformContainsExternalRepoIU() throws Exception {
tpConfig.addP2Repository(ResourceUtil.resourceFile("repositories/launchers").toURI());
P2TargetPlatform preliminaryTP = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, null,
pomDependencyCollector);
P2TargetPlatform preliminaryTP = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, null);

P2TargetPlatform finalTP = subject.createTargetPlatformWithUpdatedReactorUnits(preliminaryTP, null,
REACTOR_ARTIFACTS);
REACTOR_ARTIFACTS, pomDependencyCollector);

assertThat(finalTP.getInstallableUnits(), hasItem(unitWithId("org.eclipse.equinox.launcher")));
}

@Test
public void testFinalTargetPlatformContainsTargetFileIU() {
tpConfig.addTargetDefinition(targetDefinition(TestRepositories.V1_AND_V2, MAIN_BUNDLE));
P2TargetPlatform preliminaryTP = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, null,
pomDependencyCollector);
P2TargetPlatform preliminaryTP = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, null);

P2TargetPlatform finalTP = subject.createTargetPlatformWithUpdatedReactorUnits(preliminaryTP, null,
REACTOR_ARTIFACTS);
REACTOR_ARTIFACTS, pomDependencyCollector);

assertThat(finalTP.getInstallableUnits(),
hasItem(unit(MAIN_BUNDLE.getId(), MAIN_BUNDLE.getVersion().toString())));
Expand All @@ -136,36 +134,33 @@ public void testFinalTargetPlatformContainsTargetFileIU() {
public void testFinalTargetPlatformContainsPomDependencyIU() throws Exception {
pomDependencyCollector.addArtifactWithExistingMetadata(PomDependencyCollectorTest.artifactWithClassifier(null),
PomDependencyCollectorTest.existingMetadata());
P2TargetPlatform preliminaryTP = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, null,
pomDependencyCollector);
P2TargetPlatform preliminaryTP = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, null);

P2TargetPlatform finalTP = subject.createTargetPlatformWithUpdatedReactorUnits(preliminaryTP, null,
REACTOR_ARTIFACTS);
REACTOR_ARTIFACTS, pomDependencyCollector);

assertThat(finalTP.getInstallableUnits(), hasItem(unitWithId("test.unit")));
}

@Test
public void testFinalTargetPlatformContainsExecutionEnvironmentIU() throws Exception {
P2TargetPlatform preliminaryTP = subject.createTargetPlatform(tpConfig, ExecutionEnvironmentTestUtils
.standardEEResolutionHintProvider(new ExecutionEnvironmentStub("J2SE-1.4")), null,
pomDependencyCollector);
.standardEEResolutionHintProvider(new ExecutionEnvironmentStub("J2SE-1.4")), null);

P2TargetPlatform finalTP = subject.createTargetPlatformWithUpdatedReactorUnits(preliminaryTP, null,
REACTOR_ARTIFACTS);
REACTOR_ARTIFACTS, pomDependencyCollector);

assertThat(finalTP.getInstallableUnits(), hasItem(unit("a.jre.j2se", "1.4.0")));
}

@Test
public void testFinalTargetPlatformContainsFinalReactorIU() throws Exception {
P2TargetPlatform preliminaryTP = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, null,
pomDependencyCollector);
P2TargetPlatform preliminaryTP = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, null);

Map<IInstallableUnit, ReactorProjectIdentities> finalUnits = Collections
.singletonMap(InstallableUnitUtil.createIU("bundle", "1.2.0"), DUMMY_PROJECT);
P2TargetPlatform finalTP = subject.createTargetPlatformWithUpdatedReactorUnits(preliminaryTP, finalUnits,
REACTOR_ARTIFACTS);
REACTOR_ARTIFACTS, pomDependencyCollector);

assertThat(finalTP.getInstallableUnits(), hasItem(unit("bundle", "1.2.0")));
}
Expand All @@ -180,7 +175,7 @@ public void testConfiguredFiltersOnReactorIUsInPreliminaryTP() throws Exception

ReactorProject reactorProject = createReactorProject("artifactId", "test.feature.feature.group", "iu.p2.inf");
P2TargetPlatform preliminaryTP = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER,
Collections.singletonList(reactorProject), pomDependencyCollector);
Collections.singletonList(reactorProject));

assertThat(preliminaryTP.getInstallableUnits(), hasItem(unitWithId("test.feature.feature.group")));
assertThat(preliminaryTP.getInstallableUnits(), not(hasItem(unitWithId("iu.p2.inf"))));
Expand All @@ -191,14 +186,13 @@ public void testConfiguredFiltersOnReactorIUsInFinalTP() throws Exception {
TargetPlatformFilter filter = TargetPlatformFilter.removeAllFilter(
CapabilityPattern.patternWithoutVersion(CapabilityType.P2_INSTALLABLE_UNIT, "iu.p2.inf"));
tpConfig.addFilters(Arrays.asList(filter));
P2TargetPlatform preliminaryTP = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, null,
pomDependencyCollector);
P2TargetPlatform preliminaryTP = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, null);

Map<IInstallableUnit, ReactorProjectIdentities> finalUnits = new HashMap<>();
finalUnits.put(InstallableUnitUtil.createIU("test.feature.feature.group"), DUMMY_PROJECT);
finalUnits.put(InstallableUnitUtil.createIU("iu.p2.inf"), DUMMY_PROJECT);
P2TargetPlatform finalTP = subject.createTargetPlatformWithUpdatedReactorUnits(preliminaryTP, finalUnits,
REACTOR_ARTIFACTS);
REACTOR_ARTIFACTS, pomDependencyCollector);

assertThat(finalTP.getInstallableUnits(), hasItem(unitWithId("test.feature.feature.group")));
assertThat(finalTP.getInstallableUnits(), not(hasItem(unitWithId("iu.p2.inf"))));
Expand All @@ -213,12 +207,11 @@ public void testConfiguredFiltersOnPomDependencies() throws Exception {
CapabilityPattern.patternWithoutVersion(CapabilityType.P2_INSTALLABLE_UNIT, "test.unit"));
tpConfig.addFilters(Arrays.asList(filter));

P2TargetPlatform preliminaryTP = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, null,
pomDependencyCollector);
P2TargetPlatform preliminaryTP = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, null);
assertThat(preliminaryTP.getInstallableUnits(), not(hasItem(unitWithId("test.unit"))));

P2TargetPlatform finalTP = subject.createTargetPlatformWithUpdatedReactorUnits(preliminaryTP, null,
REACTOR_ARTIFACTS);
REACTOR_ARTIFACTS, pomDependencyCollector);
assertThat(finalTP.getInstallableUnits(), not(hasItem(unitWithId("test.unit"))));
}

Expand All @@ -230,15 +223,15 @@ public void testOtherVersionsOfReactorIUsAreFilteredFromExternalContent() throws
// reactor artifact produces a unit with same ID
ReactorProject reactorProject = createReactorProject("artifactId", "trt.bundle/1.5.5.qualifier", null);
P2TargetPlatform preliminaryTP = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER,
Collections.singletonList(reactorProject), pomDependencyCollector);
Collections.singletonList(reactorProject));

assertThat(preliminaryTP.getInstallableUnits(), hasItem(unit("trt.bundle", "1.5.5.qualifier")));
assertThat(preliminaryTP.getInstallableUnits(), not(hasItem(unit("trt.bundle", "1.0.0.201108051343"))));

Map<IInstallableUnit, ReactorProjectIdentities> finalUnits = Collections.singletonMap(
InstallableUnitUtil.createIU("trt.bundle", "1.5.5.20140216"), reactorProject.getIdentities());
P2TargetPlatform finalTP = subject.createTargetPlatformWithUpdatedReactorUnits(preliminaryTP, finalUnits,
REACTOR_ARTIFACTS);
REACTOR_ARTIFACTS, pomDependencyCollector);

assertThat(finalTP.getInstallableUnits(), hasItem(unit("trt.bundle", "1.5.5.20140216")));
assertThat(finalTP.getInstallableUnits(), not(hasItem(unit("trt.bundle", "1.0.0.201108051343"))));
Expand All @@ -253,12 +246,10 @@ public void testIncludeLocalMavenRepo() throws Exception {
new GAV("test", "foo", "1.0.0"));
subject = factory.getTargetPlatformFactoryImpl();
Collection<IInstallableUnit> iusIncludingLocalRepo = subject
.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, null, pomDependencyCollector)
.getInstallableUnits();
.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, null).getInstallableUnits();
tpConfig.setForceIgnoreLocalArtifacts(true);
Collection<IInstallableUnit> iusWithoutLocalRepo = subject
.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, null, pomDependencyCollector)
.getInstallableUnits();
.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, null).getInstallableUnits();
Set<IInstallableUnit> retainedIUs = new HashSet<>(iusIncludingLocalRepo);
retainedIUs.removeAll(iusWithoutLocalRepo);
assertEquals(1, retainedIUs.size());
Expand All @@ -269,8 +260,7 @@ public void testIncludeLocalMavenRepo() throws Exception {
public void testMultipleIndependentlyResolvedTargetFiles() throws Exception {
tpConfig.addTargetDefinition(plannerTargetDefinition(TestRepositories.V1, REFERENCED_BUNDLE_V1));
tpConfig.addTargetDefinition(plannerTargetDefinition(TestRepositories.V2, REFERENCED_BUNDLE_V2));
P2TargetPlatform tp = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, null,
pomDependencyCollector);
P2TargetPlatform tp = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, null);
// platforms must have been resolved in two planner calls because otherwise the singleton bundles would have collided

assertThat(tp.getInstallableUnits(), hasItem(unitWithIdAndVersion(REFERENCED_BUNDLE_V1)));
Expand All @@ -282,7 +272,7 @@ public void testDuplicateReactorUnits() throws Exception {
List<ReactorProject> reactorProjects = new ArrayList<>();
reactorProjects.add(createReactorProject("project1", "unit.a", "unit.b"));
reactorProjects.add(createReactorProject("project2", "unit.b", null));
subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, reactorProjects, pomDependencyCollector);
subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, reactorProjects);
}

private static TargetDefinition plannerTargetDefinition(TestRepositories repository, IVersionedId unit) {
Expand Down
Expand Up @@ -76,7 +76,7 @@ public void testReadFullSpecificationFromTargetPlatform() throws Exception {
* (which is wrapped around the eeConfigurationCapture argument by the called method)
* correctly reads the custom profile specification from the target platform.
*/
tpFactory.createTargetPlatform(tpConfig, eeConfigurationCapture, null, pomDependencyCollector);
tpFactory.createTargetPlatform(tpConfig, eeConfigurationCapture, null);

List<SystemCapability> result = eeConfigurationCapture.capturedSystemCapabilities;

Expand All @@ -95,7 +95,7 @@ public void testMissingSpecificationInTargetPlatform() throws Exception {
"MissingProfile-1.2.3");

Exception e = assertThrows(Exception.class,
() -> tpFactory.createTargetPlatform(tpConfig, eeConfigurationCapture, null, pomDependencyCollector));
() -> tpFactory.createTargetPlatform(tpConfig, eeConfigurationCapture, null));
assertTrue(e.getMessage().contains(
"Could not find specification for custom execution environment profile 'MissingProfile-1.2.3'"));
}
Expand Down

0 comments on commit 6eec46c

Please sign in to comment.