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..7a0f023090 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,7 @@ protected Slicer createSlicer(SlicingOptions options) throws ProvisionException boolean considerOnlyStrictDependency = options.considerStrictDependencyOnly(); return new PermissiveSlicer(repository, filters.get(0), includeOptionalDependencies, options.isEverythingGreedy(), evalFilterTo, considerOnlyStrictDependency, onlyFilteredRequirements) { + @Override protected boolean isApplicable(IInstallableUnit iu, IRequirement req) { if ((includeRequiredBundles || includeRequiredFeatures) && QueryUtil.isGroup(iu) @@ -147,6 +149,20 @@ protected boolean isApplicable(IRequirement req) { if (considerOnlyStrictDependency && !RequiredCapability.isStrictVersionRequirement(req.getMatches())) { return false; } + + if (!includeAllSource && req.getMin() == 0 && !req.isGreedy() + && req instanceof IRequiredCapability capability + && PublisherHelper.NAMESPACE_ECLIPSE_TYPE.equals(capability.getNamespace()) + && PublisherHelper.TYPE_ECLIPSE_SOURCE.equals(capability.getName())) { + // When dealing with published products, these products always include a dependency to + // 'tooling.source.default', which in turn optionally + non-greedily depends on up all sources. + // Since https://github.com/eclipse-equinox/p2/pull/446 the target platform contains + // all the sources. When 'includeAllDependencies' is true, they would be picked up unless + // we prevent this explicitly by also explicitly looking at 'includeAllSources'. + // See https://github.com/eclipse-tycho/tycho/issues/3522 + return false; + } + //deal with filters IMatchExpression filter = req.getFilter(); if (considerFilter) { 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"); + } +}