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 eclipse-tycho#898
  • Loading branch information
laeubi committed Jun 18, 2022
1 parent 4459b21 commit d8fb9fd
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@
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.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 +62,51 @@ protected IArtifactRepository initializeDestination(RepositoryDescriptor toInit,
return result;
}

@Override
protected Slicer createSlicer(SlicingOptions options) {
Map<String, String> context = options.getFilter();
boolean includeOptionalDependencies = options.includeOptionalDependencies();
boolean everythingGreedy = options.isEverythingGreedy();
boolean evalFilterTo = options.forceFilterTo();
boolean considerOnlyStrictDependency = options.considerStrictDependencyOnly();
boolean onlyFilteredRequirements = options.followOnlyFilteredRequirements();
boolean considerFilter = (context != null && context.size() > 1) ? true : false;
PermissiveSlicer slicer = new PermissiveSlicer(getCompositeMetadataRepository(), context,
includeOptionalDependencies, everythingGreedy, evalFilterTo, considerOnlyStrictDependency,
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;
}
}
if (considerFilter) {
if (onlyFilteredRequirements && req.getFilter() == null) {
return false;
}
return super.isApplicable(req);
}
if (req.getFilter() == null) {
if (onlyFilteredRequirements) {
return false;
}
return true;
}
return evalFilterTo;
}
}
}
return super.isApplicable(iu, req);
}

};
return slicer;
}

@Override
protected IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr)
throws ProvisionException {
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());
}
}

0 comments on commit d8fb9fd

Please sign in to comment.