From 380bcac46f91c0eb20babed0231439bc60a0163b Mon Sep 17 00:00:00 2001 From: Sebastian Ratz Date: Tue, 12 Mar 2024 18:06:06 +0100 Subject: [PATCH] assemble-repository: Prevent sources from being included inadvertently In the presence of products, P2 adds a virtual 'tooling.source.default' IU which optionally depends on all sources. If these sources are avaialble in the target platform, this would cause them to be picked up even if assemble-repository was configured with false. This scenario has become much more likely with recent changes to P2 [1]. To prevent this, we actively prevent this from happening by ignoring the requirements of the 'tooling.source.default' IU unless includeAllSources is explicitly enabled. These would be picked up even if If however, assemble-repository is Fixes #3522. [1] https://github.com/eclipse-equinox/p2/pull/446 --- .../tycho/p2tools/TychoMirrorApplication.java | 13 +++ .../product.productRepository/pom.xml | 102 ++++++++++++++++++ .../product.productRepository/product.product | 10 ++ .../test/product/ProductRepositoryTest.java | 54 ++++++++++ 4 files changed, 179 insertions(+) create mode 100644 tycho-its/projects/product.productRepository/pom.xml create mode 100644 tycho-its/projects/product.productRepository/product.product create mode 100644 tycho-its/src/test/java/org/eclipse/tycho/test/product/ProductRepositoryTest.java diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java index 9df6fd2983..f273e27326 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java @@ -54,6 +54,7 @@ import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager; +import org.eclipse.equinox.spi.p2.publisher.PublisherHelper; import org.eclipse.tycho.TargetPlatform; import org.eclipse.tycho.p2.tools.DestinationRepositoryDescriptor; import org.eclipse.tycho.p2.tools.RepositoryReference; @@ -118,6 +119,10 @@ protected Slicer createSlicer(SlicingOptions options) throws ProvisionException boolean considerOnlyStrictDependency = options.considerStrictDependencyOnly(); return new PermissiveSlicer(repository, filters.get(0), includeOptionalDependencies, options.isEverythingGreedy(), evalFilterTo, considerOnlyStrictDependency, onlyFilteredRequirements) { + + private static final String TOOLING_SOURCE_IU_ID = PublisherHelper.createDefaultConfigUnitId("source", + "tooling"); + @Override protected boolean isApplicable(IInstallableUnit iu, IRequirement req) { if ((includeRequiredBundles || includeRequiredFeatures) && QueryUtil.isGroup(iu) @@ -160,6 +165,14 @@ protected boolean isApplicable(IRequirement req) { @Override protected boolean isApplicable(IInstallableUnit iu) { + if (!includeAllSource && TOOLING_SOURCE_IU_ID.equals(iu.getId())) { + // When dealing with a repository that contains published products, these products + // always include a dependency to 'tooling.source.default', which picks up all sources. + // And since https://github.com/eclipse-equinox/p2/pull/446 the target platform contains + // all the sources. They would be picked up unless we prevent this here. + // See https://github.com/eclipse-tycho/tycho/issues/3522 + return false; + } if (considerFilter) { IMatchExpression filter = iu.getFilter(); return filter == null || matchesSelectionContext(filter); diff --git a/tycho-its/projects/product.productRepository/pom.xml b/tycho-its/projects/product.productRepository/pom.xml new file mode 100644 index 0000000000..222ce7d15c --- /dev/null +++ b/tycho-its/projects/product.productRepository/pom.xml @@ -0,0 +1,102 @@ + + + 4.0.0 + + tycho-its-project.product.productRepository + product.product + 1.0.0-SNAPSHOT + eclipse-repository + + + + e431 + p2 + + https://download.eclipse.org/eclipse/updates/4.31/R-4.31-202402290520/ + + + + + + + org.eclipse.tycho + tycho-maven-plugin + ${tycho-version} + true + + + + org.eclipse.tycho + target-platform-configuration + ${tycho-version} + + + + linux + gtk + x86_64 + + + + + + + org.eclipse.tycho + tycho-p2-repository-plugin + ${tycho-version} + + true + + + + + org.eclipse.tycho + tycho-p2-director-plugin + ${tycho-version} + + + materialize-products + + materialize-products + + + + + + + product.product + + + + + + + + + + withsources + + + + org.eclipse.tycho + tycho-p2-repository-plugin + ${tycho-version} + + true + + + + org.eclipse.tycho + tycho-p2-director-plugin + ${tycho-version} + + true + + + + + + + + diff --git a/tycho-its/projects/product.productRepository/product.product b/tycho-its/projects/product.productRepository/product.product new file mode 100644 index 0000000000..e7c12a15f3 --- /dev/null +++ b/tycho-its/projects/product.productRepository/product.product @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/product/ProductRepositoryTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/product/ProductRepositoryTest.java new file mode 100644 index 0000000000..0acf776338 --- /dev/null +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/product/ProductRepositoryTest.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2024 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 + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * SAP SE - [Issue #3522] product / repository contains source jars by default + *******************************************************************************/ +package org.eclipse.tycho.test.product; + +import java.io.File; +import java.util.Arrays; + +import org.apache.maven.it.Verifier; +import org.eclipse.tycho.test.AbstractTychoIntegrationTest; +import org.junit.Test; + +public class ProductRepositoryTest extends AbstractTychoIntegrationTest { + + @Test + public void testShouldNotContainSources() throws Exception { + Verifier verifier = getVerifier("product.productRepository", false); + verifier.executeGoals(Arrays.asList("clean", "verify")); + verifier.verifyErrorFreeLog(); + assertFileExists(new File(verifier.getBasedir()), // + "target/repository/plugins/org.eclipse.osgi_*.jar"); + assertFileDoesNotExist(new File(verifier.getBasedir()), // + "target/repository/plugins/org.eclipse.osgi.source_*.jar"); + assertFileExists(new File(verifier.getBasedir()), // + "target/products/product.product/linux/gtk/x86_64/plugins/org.eclipse.osgi_*.jar"); + assertFileDoesNotExist(new File(verifier.getBasedir()), // + "target/products/product.product/linux/gtk/x86_64/plugins/org.eclipse.osgi.source_*.jar"); + } + + @Test + public void testShouldContainSourcesWhenExlicitlyIncluded() throws Exception { + Verifier verifier = getVerifier("product.productRepository", false); + verifier.addCliOption("-Pwithsources"); + verifier.executeGoals(Arrays.asList("clean", "verify")); + verifier.verifyErrorFreeLog(); + assertFileExists(new File(verifier.getBasedir()), // + "target/repository/plugins/org.eclipse.osgi_*.jar"); + assertFileExists(new File(verifier.getBasedir()), // + "target/repository/plugins/org.eclipse.osgi.source_*.jar"); + assertFileExists(new File(verifier.getBasedir()), // + "target/products/product.product/linux/gtk/x86_64/plugins/org.eclipse.osgi_*.jar"); + assertFileExists(new File(verifier.getBasedir()), // + "target/products/product.product/linux/gtk/x86_64/plugins/org.eclipse.osgi.source_*.jar"); + } +}