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

- if pom dependencies are considered allow for a partial resolution of
the preliminary target platform
- don't use pom considered dependencies in computation of build-order
anymore
- pom considered dependencies are now part of the final target platform
calculation

These changes allow for other reactor projects to contribute to the OSGi
classpath results including for example bnd/felix bundle plugin.


Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
  • Loading branch information
laeubi committed Jan 7, 2022
1 parent 26c90cb commit 65328b3
Show file tree
Hide file tree
Showing 30 changed files with 552 additions and 157 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2014 Sonatype Inc. and others.
* Copyright (c) 2008, 2022 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 All @@ -12,6 +12,8 @@
*******************************************************************************/
package org.eclipse.tycho;

import java.util.Set;

/**
* Tycho's packaging types.
*/
Expand All @@ -28,4 +30,8 @@ public final class PackagingType {
public static final String TYPE_ECLIPSE_TARGET_DEFINITION = "eclipse-target-definition";
public static final String TYPE_P2_IU = ArtifactType.TYPE_INSTALLABLE_UNIT;

public static final Set<String> TYCHO_PACKAGING_TYPES = Set.of(PackagingType.TYPE_ECLIPSE_PLUGIN,
TYPE_ECLIPSE_TEST_PLUGIN, TYPE_ECLIPSE_FEATURE, TYPE_ECLIPSE_REPOSITORY, TYPE_ECLIPSE_TARGET_DEFINITION,
TYPE_ECLIPSE_UPDATE_SITE, TYPE_ECLIPSE_APPLICATION);

}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 @@ -190,7 +190,7 @@ public void testSourceBundle() throws Exception {
sb.setDependencyMetadata(metadata);
reactorProjects.add(sb);

result = singleEnv(impl.resolveTargetDependencies(getTargetPlatform(), projectToResolve));
result = singleEnv(impl.resolveTargetDependencies(getTargetPlatform(false), projectToResolve));

assertEquals(3, result.getArtifacts().size());
List<P2ResolutionResult.Entry> entries = new ArrayList<>(result.getArtifacts());
Expand All @@ -214,7 +214,10 @@ public void testEclipseRepository() throws Exception {

addContextProject(resourceFile("resolver/bundle01"), TYPE_ECLIPSE_PLUGIN);

result = singleEnv(impl.resolveTargetDependencies(getTargetPlatform(), projectToResolve));
P2TargetPlatform targetPlatform = getTargetPlatform();
Map<TargetEnvironment, P2ResolutionResult> map = impl.resolveTargetDependencies(targetPlatform,
projectToResolve);
result = singleEnv(map);

assertEquals(3, result.getArtifacts().size()); // the product, bundle01, and the one dependency of bundle01
assertEquals(4, result.getNonReactorUnits().size()); // + a.jre
Expand Down Expand Up @@ -277,7 +280,7 @@ public void testSwtFragment() throws Exception {
projectToResolve = createReactorProject(swtFragment, TYPE_ECLIPSE_PLUGIN,
"org.eclipse.tycho.p2.impl.resolver.test.swtFragment");

result = singleEnv(impl.resolveTargetDependencies(getTargetPlatform(), projectToResolve));
result = singleEnv(impl.resolveTargetDependencies(getTargetPlatform(false), projectToResolve));

assertEquals(2, result.getArtifacts().size());
assertEquals(0, result.getNonReactorUnits().size());
Expand Down Expand Up @@ -313,7 +316,7 @@ public void testReactorVsExternal() throws Exception {
projectToResolve = createReactorProject(resourceFile("reactor-vs-external/feature01"), TYPE_ECLIPSE_FEATURE,
"org.sonatype.tycho.p2.impl.resolver.test.feature01");

result = singleEnv(impl.resolveTargetDependencies(getTargetPlatform(), projectToResolve));
result = singleEnv(impl.resolveTargetDependencies(getTargetPlatform(false), projectToResolve));

assertEquals(2, result.getArtifacts().size());
assertEquals(1, result.getNonReactorUnits().size()); // a.jre
Expand Down Expand Up @@ -506,11 +509,26 @@ public void testResolveWithoutProject() throws Exception {
}

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

private P2TargetPlatform getTargetPlatform(boolean finalTarget) {
return getTargetPlatform(NOOP_EE_RESOLUTION_HANDLER, finalTarget);
}

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

private P2TargetPlatform getTargetPlatform(ExecutionEnvironmentResolutionHandler eeResolutionHandler,
boolean finalTarget) {
P2TargetPlatform preliminaryTP = tpFactory.createTargetPlatform(tpConfig, eeResolutionHandler, reactorProjects);
if (finalTarget) {
return tpFactory.createTargetPlatformWithUpdatedReactorContent(preliminaryTP, Collections.emptyList(),
pomDependencies);
} else {
return preliminaryTP;
}
}

private static P2ResolutionResult singleEnv(Map<TargetEnvironment, P2ResolutionResult> map) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 All @@ -14,7 +14,6 @@
*******************************************************************************/
package org.eclipse.tycho.p2.target;

import static org.eclipse.tycho.p2.target.ExecutionEnvironmentTestUtils.NOOP_EE_RESOLUTION_HANDLER;
import static org.eclipse.tycho.p2.testutil.InstallableUnitMatchers.unitWithId;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
Expand All @@ -29,7 +28,6 @@
import org.eclipse.tycho.p2.impl.test.ArtifactMock;
import org.eclipse.tycho.p2.impl.test.ReactorProjectStub;
import org.eclipse.tycho.p2.target.facade.PomDependencyCollector;
import org.eclipse.tycho.p2.target.facade.TargetPlatformConfigurationStub;
import org.eclipse.tycho.test.util.LogVerifier;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -61,7 +59,7 @@ public void testAddArtifactWithExistingMetadataRespectsClassifier() throws Excep

subject.addArtifactWithExistingMetadata(artifact, existingMetadata());

Collection<IInstallableUnit> units = getTargetPlatformUnits();
Collection<IInstallableUnit> units = (Collection<IInstallableUnit>) subject.getMavenInstallableUnits().keySet();
assertThat(units, hasItem(unitWithId("test.unit.source")));
assertThat(units.size(), is(1));
}
Expand All @@ -73,7 +71,7 @@ public void testAddArtifactWithExistingMetadataOfMainArtifact() throws Exception

subject.addArtifactWithExistingMetadata(artifact, existingMetadata());

Collection<IInstallableUnit> units = getTargetPlatformUnits();
Collection<IInstallableUnit> units = (Collection<IInstallableUnit>) subject.getMavenInstallableUnits().keySet();
assertThat(units, hasItem(unitWithId("test.unit")));
assertThat(units.size(), is(1));
}
Expand All @@ -85,7 +83,7 @@ public void testAddArtifactWithExistingMetadataButNonMatchingClassifier() throws

subject.addArtifactWithExistingMetadata(artifact, existingMetadata());

Collection<IInstallableUnit> units = getTargetPlatformUnits();
Collection<IInstallableUnit> units = (Collection<IInstallableUnit>) subject.getMavenInstallableUnits().keySet();
assertThat(units.size(), is(0));
}

Expand All @@ -100,10 +98,4 @@ static ArtifactMock existingMetadata() {
"groupId", "artifactId", "1", PackagingType.TYPE_ECLIPSE_PLUGIN, "p2metadata");
}

private Collection<IInstallableUnit> getTargetPlatformUnits() {
TestResolverFactory resolverFactory = new TestResolverFactory(logVerifier.getLogger());
P2TargetPlatform platform = resolverFactory.getTargetPlatformFactoryImpl()
.createTargetPlatform(new TargetPlatformConfigurationStub(), NOOP_EE_RESOLUTION_HANDLER, null, subject);
return platform.getInstallableUnits();
}
}
Loading

0 comments on commit 65328b3

Please sign in to comment.