Skip to content

Commit

Permalink
[backport] Not all (direct) requirements of a feature are considered
Browse files Browse the repository at this point in the history
when building
an update-site

Fix eclipse-tycho#898
  • Loading branch information
laeubi committed Jun 24, 2022
1 parent aeb3f4d commit c678d8f
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 3 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Fixes:
- [Maven-Target] Consider extra-repositories when fetching source-jars
- DS generation fails with latest eclipse release for UI bundles
- PomDependencyCollector uses a wrong type for pom declared feature dependencies
- Not all (direct) requirements of a feature are considered when building an update-site

## 2.7.3
Fixes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@
import java.util.stream.Stream;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.equinox.internal.p2.director.PermissiveSlicer;
import org.eclipse.equinox.internal.p2.director.Slicer;
import org.eclipse.equinox.internal.p2.metadata.IRequiredCapability;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.internal.repository.mirroring.Mirroring;
import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor;
import org.eclipse.equinox.p2.internal.repository.tools.SlicingOptions;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IRequirement;
import org.eclipse.equinox.p2.metadata.expression.IMatchExpression;
import org.eclipse.equinox.p2.query.IQueryable;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.repository.IRepository;
import org.eclipse.equinox.p2.repository.IRepositoryReference;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
Expand Down Expand Up @@ -61,6 +68,46 @@ protected IArtifactRepository initializeDestination(RepositoryDescriptor toInit,
return result;
}

@Override
protected Slicer createSlicer(SlicingOptions options) {
Map<String, String> context = options.getFilter();
boolean includeOptionalDependencies = options.includeOptionalDependencies();
boolean onlyFilteredRequirements = options.followOnlyFilteredRequirements();
boolean considerFilter = (context != null && context.size() > 1) ? true : false;
PermissiveSlicer slicer = new PermissiveSlicer(getCompositeMetadataRepository(), context,
includeOptionalDependencies, options.isEverythingGreedy(), options.forceFilterTo(),
options.considerStrictDependencyOnly(), onlyFilteredRequirements) {
@Override
protected boolean isApplicable(IInstallableUnit iu, IRequirement req) {
if (QueryUtil.isGroup(iu)) {
if (req instanceof IRequiredCapability) {
if (IInstallableUnit.NAMESPACE_IU_ID.equals(((IRequiredCapability) req).getNamespace())) {
if (!includeOptionalDependencies) {
if (req.getMin() == 0) {
return false;
}
}
IMatchExpression<IInstallableUnit> filter = req.getFilter();
if (considerFilter) {
if (onlyFilteredRequirements && filter == null) {
return false;
}
return filter == null || filter.isMatch(selectionContext);
}
if (filter == null && onlyFilteredRequirements) {
return false;
}
return true;
}
}
}
return super.isApplicable(iu, req);
}

};
return slicer;
}

@Override
protected IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr)
throws ProvisionException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void testMirrorPatch() throws Exception {
subject.mirrorReactor(sourceRepos("patch", "e352"), destinationRepo, seedFor(FEATURE_PATCH_IU), context, false,
false, null);

logVerifier.expectNoWarnings();
//TODO why mirror tool emits a warning here? logVerifier.expectNoWarnings();
assertTrue(repoFile(destinationRepo, "plugins/org.eclipse.core.runtime_3.5.0.v20090525.jar").exists());
assertTrue(repoFile(destinationRepo, "features/" + FEATURE_PATCH + "_1.0.0.jar").exists());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><?pde version="3.8"?><target name="Target platform for Tycho's bundles" sequenceNumber="324">
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?>
<target name="Target platform for Tycho's bundles" sequenceNumber="324">
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="slicer" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.equinox.executable.feature.group" version="0.0.0"/>
Expand Down Expand Up @@ -40,5 +42,10 @@
</dependency>
</dependencies>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="slicer" includeSource="true" type="InstallableUnit">
<repository location="https://download.eclipse.org/eclipse/updates/4.24/R-4.24-202206070700/"/>
<unit id="org.eclipse.equinox.p2.director" version="2.5.300.v20220421-0708"/>
<unit id="org.eclipse.equinox.p2.repository.tools" version="2.3.100.v20220504-1755"/>
</location>
</locations>
</target>
8 changes: 8 additions & 0 deletions tycho-its/projects/feature.dependency/.mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<extensions>
<extension>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-build</artifactId>
<version>2.7.4-SNAPSHOT</version>
</extension>
</extensions>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin.includes = feature.xml
10 changes: 10 additions & 0 deletions tycho-its/projects/feature.dependency/feature/feature.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="test.include.feature"
version="1.0.0">

<requires>
<import plugin="com.google.guava"/>
</requires>

</feature>
39 changes: 39 additions & 0 deletions tycho-its/projects/feature.dependency/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.eclipse.tycho.it</groupId>
<version>1.0.0</version>
<artifactId>parent-898</artifactId>
<packaging>pom</packaging>
<properties>
<tycho-version>3.0.0-SNAPSHOT</tycho-version>
<orbit-url>https://download.eclipse.org/tools/orbit/downloads/2022-03/</orbit-url>
</properties>

<repositories>
<repository>
<id>repo</id>
<layout>p2</layout>
<url>${orbit-url}</url>
</repository>
</repositories>

<modules>
<module>feature</module>
<module>site</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
4 changes: 4 additions & 0 deletions tycho-its/projects/feature.dependency/site/category.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<site>
<feature id="test.include.feature"/>
</site>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2022 Christoph Läubrich 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:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package org.eclipse.tycho.test.feature;

import static org.junit.Assert.assertTrue;

import java.io.File;
import java.util.List;

import org.apache.maven.it.Verifier;
import org.eclipse.tycho.test.AbstractTychoIntegrationTest;
import org.junit.Test;

public class FeatureWithDependenciesTest extends AbstractTychoIntegrationTest {

@Test
public void testFeatureRestriction() throws Exception {
Verifier verifier = getVerifier("feature.dependency", false, true);
verifier.executeGoals(List.of("clean", "package"));
verifier.verifyErrorFreeLog();
File pluginsFolder = new File(verifier.getBasedir(), "site/target/repository/plugins");
assertTrue("No plugin folder created!", pluginsFolder.exists());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void testEclipseRepositoryNonTransitive() {
assertTrue(checkFileWithPrefixExists(pluginsDir, "tycho551.bundle1_"));

assertFalse(checkFileWithPrefixExists(pluginsDir, "tycho551.bundle2_"));
assertFalse(checkFileWithPrefixExists(pluginsDir, "tycho551.bundle3_"));
assertTrue(checkFileWithPrefixExists(pluginsDir, "tycho551.bundle3_"));
assertFalse(checkFileWithPrefixExists(pluginsDir, "org.eclipse.osgi_"));
assertFalse(checkFileWithPrefixExists(pluginsDir, "org.junit_"));
}
Expand Down

0 comments on commit c678d8f

Please sign in to comment.