Skip to content

Commit

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

Fix #898
  • Loading branch information
laeubi committed Jun 19, 2022
1 parent 1f6f07b commit c09a4b0
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

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.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.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 @@ -55,6 +63,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,
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
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>${tycho-version}</version>
</extension>
</extensions>
1 change: 1 addition & 0 deletions tycho-its/projects/feature.dependency/.mvn/maven.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Dtycho-version=3.0.0-SNAPSHOT
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 c09a4b0

Please sign in to comment.