Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #462 Delay Pom considered items to the final Target Platform calculation #470

Merged
merged 1 commit into from Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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) 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);

}
@@ -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 @@ -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);
laeubi marked this conversation as resolved.
Show resolved Hide resolved
}

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
@@ -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();
}
}