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

assemble-repository: Prevent sources from being included inadvertently #3635

Merged
merged 1 commit into from
Mar 18, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is actually the place where you want to filter things, this test if a requirement for a IU is applicable and you don't want the new requirement to be considered.

Expand Down Expand Up @@ -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<IInstallableUnit> filter = req.getFilter();
if (considerFilter) {
Expand Down
102 changes: 102 additions & 0 deletions tycho-its/projects/product.productRepository/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<groupId>tycho-its-project.product.productRepository</groupId>
<artifactId>product.product</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-repository</packaging>

<repositories>
<repository>
<id>e431</id>
<layout>p2</layout>
<!-- Important: This update site must have already been generated with the new P2 that adds the source as optional dependencyies with <filter>(org.eclipse.update.install.sources=true)</filter> metadata for the problem to show -->
<url>https://download.eclipse.org/eclipse/updates/4.31/R-4.31-202402290520/</url>
</repository>
</repositories>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>

<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<environments>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
</environments>
</configuration>
</plugin>

<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<includeAllDependencies>true</includeAllDependencies>
</configuration>
</plugin>

<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-director-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<id>materialize-products</id>
<goals>
<goal>materialize-products</goal>
</goals>
</execution>
</executions>
<configuration>
<products>
<product>
<id>product.product</id>
</product>
</products>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>withsources</id>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<includeAllSources>true</includeAllSources>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-director-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<installSources>true</installSources>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
10 changes: 10 additions & 0 deletions tycho-its/projects/product.productRepository/product.product
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<?pde version="3.5"?>

<product uid="product.product" id="product" application="application" version="1.0.0.qualifier" useFeatures="false" includeLaunchers="false">

<plugins>
<plugin id="org.eclipse.osgi"/>
</plugins>

</product>
Original file line number Diff line number Diff line change
@@ -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");
}
}
Loading