diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/publisher/ExpandedProduct.java b/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/publisher/ExpandedProduct.java index 78d9526369..734d5b4dc3 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/publisher/ExpandedProduct.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/publisher/ExpandedProduct.java @@ -46,7 +46,8 @@ class ExpandedProduct implements IProductDescriptor { private final String expandedVersion; private List expandedBundles = null; private List expandedFeatures = null; - private List expandedRootFeatures = Collections.emptyList(); + private List expandedRootFeatures = Collections.emptyList(); + private List expandedRootFeatureIUs = Collections.emptyList(); private final MultiLineLogger logger; @@ -93,7 +94,7 @@ public List getFeatures(int options) { } public List getRootFeatures() { - return expandedRootFeatures; + return expandedRootFeatureIUs; } private void expandVersions() { @@ -106,7 +107,9 @@ private void expandVersions() { if (contentType != ProductContentType.BUNDLES) { expandedFeatures = resolver.resolveReferences("feature", ArtifactType.TYPE_ECLIPSE_FEATURE, defaults.getFeatures(INCLUDED_FEATURES)); - expandedRootFeatures = resolver.resolveReferencesToIUs("feature", ArtifactType.TYPE_ECLIPSE_FEATURE, + expandedRootFeatures = resolver.resolveReferences("feature", ArtifactType.TYPE_ECLIPSE_FEATURE, + defaults.getFeatures(ROOT_FEATURES)); + expandedRootFeatureIUs = resolver.resolveReferencesToIUs("feature", ArtifactType.TYPE_ECLIPSE_FEATURE, defaults.getFeatures(ROOT_FEATURES)); } resolver.reportErrors(logger); diff --git a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/PublishProductToolTest.java b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/PublishProductToolTest.java index c7eae473de..69be8274fd 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/PublishProductToolTest.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/PublishProductToolTest.java @@ -26,7 +26,6 @@ import static org.hamcrest.CoreMatchers.endsWith; import static org.hamcrest.CoreMatchers.hasItem; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; @@ -272,9 +271,11 @@ public void testPublishingWithRootFeatures() { assertThat(productUnit.getRequirements(), hasItem(requirement("org.eclipse.rcp.feature.group", "4.4.0.v20140128"))); assertThat(productUnit.getRequirements(), hasItem(requirement("org.eclipse.e4.rcp.feature.group", "1.0"))); - assertThat(productUnit.getRequirements(), - not(hasItem(requirement("org.eclipse.help.feature.group", "2.0.102.v20140128")))); - assertThat(productUnit.getRequirements(), not(hasItem(requirement("org.eclipse.egit.feature.group", "2.0")))); + assertThat(productUnit.getRequirements(), hasItem(requirement("org.eclipse.help.feature.group", + "2.0.102.v20140128", + "(|(org.eclipse.equinox.p2.install.mode.root=true)(product.with.root.features.install.mode.root=true))"))); + assertThat(productUnit.getRequirements(), hasItem(requirement("org.eclipse.egit.feature.group", "2.0", + "(|(org.eclipse.equinox.p2.install.mode.root=true)(product.with.root.features.install.mode.root=true))"))); assertEquals("org.eclipse.help", seeds.get(1).getId()); assertThat(seeds.get(1).getInstallableUnit(), is(unitWithId("org.eclipse.help.feature.group"))); diff --git a/tycho-core/src/test/java/org/eclipse/tycho/test/util/InstallableUnitMatchers.java b/tycho-core/src/test/java/org/eclipse/tycho/test/util/InstallableUnitMatchers.java index 9309ec53df..03652ef623 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/test/util/InstallableUnitMatchers.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/test/util/InstallableUnitMatchers.java @@ -16,13 +16,16 @@ import static org.eclipse.tycho.test.util.InstallableUnitUtil.PRODUCT_TYPE_PROPERTY; import java.util.Map; +import java.util.Objects; +import org.eclipse.equinox.internal.p2.metadata.InstallableUnit; import org.eclipse.equinox.p2.metadata.IInstallableUnit; import org.eclipse.equinox.p2.metadata.IProvidedCapability; import org.eclipse.equinox.p2.metadata.IRequirement; import org.eclipse.equinox.p2.metadata.ITouchpointData; import org.eclipse.equinox.p2.metadata.IVersionedId; import org.eclipse.equinox.p2.metadata.Version; +import org.eclipse.equinox.p2.metadata.expression.IMatchExpression; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; @@ -167,6 +170,26 @@ public void describeTo(Description description) { }; } + public static Matcher requirement(final String id, final String version, + final String filter) { + IMatchExpression filterEpxression = InstallableUnit.parseFilter(filter); + final IInstallableUnit unit = InstallableUnitUtil.createIU(id, version); + return new TypeSafeMatcher<>() { + + @Override + public void describeTo(Description description) { + description.appendText("a require of unit ").appendText(id).appendText(":").appendText(version) + .appendText(";filter=").appendText(filter); + } + + @Override + protected boolean matchesSafely(IRequirement item) { + IMatchExpression requirementFilter = item.getFilter(); + return item.isMatch(unit) && Objects.equals(filterEpxression, requirementFilter); + } + }; + } + public static Matcher requirement(final String id, final String version) { final IInstallableUnit unit = InstallableUnitUtil.createIU(id, version); return new TypeSafeMatcher<>() { diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/product/Tycho188P2EnabledRcpTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/product/Tycho188P2EnabledRcpTest.java index f2baf53e7b..c46831a450 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/product/Tycho188P2EnabledRcpTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/product/Tycho188P2EnabledRcpTest.java @@ -127,9 +127,12 @@ public void testRootLevelFeaturesAreIncludedInP2Repository() throws Exception { Optional rootFeatureInRepo = p2Repository.findFeatureArtifact("pi.root-level-installed-feature"); assertTrue(rootFeatureInRepo.isPresent()); - // ... although there is no dependency from the product IU. - assertThat(p2Repository.getUniqueIU("main.product.id").getRequiredIds(), - not(hasItem("pi.root-level-installed-feature.feature.group"))); + // ... although there is no unfiltered dependency from the product IU. + var unfilteredRequiredIds = p2Repository.getUniqueIU("main.product.id").getUnfilteredRequiredIds(); + assertThat(unfilteredRequiredIds, not(hasItem("pi.root-level-installed-feature.feature.group"))); + + // There are the expected unfiltered requirement such as this one. + assertThat(unfilteredRequiredIds, hasItem("pi.example.feature.feature.group")); } @Test diff --git a/tycho-testing-harness/src/main/java/org/eclipse/tycho/test/util/P2RepositoryTool.java b/tycho-testing-harness/src/main/java/org/eclipse/tycho/test/util/P2RepositoryTool.java index 5369ac8697..5a53911e27 100644 --- a/tycho-testing-harness/src/main/java/org/eclipse/tycho/test/util/P2RepositoryTool.java +++ b/tycho-testing-harness/src/main/java/org/eclipse/tycho/test/util/P2RepositoryTool.java @@ -283,6 +283,17 @@ public List getRequiredIds() throws Exception { return getValues(unitElement, "requires/required/@name"); } + public List getUnfilteredRequiredIds() throws Exception { + return XMLTool.getMatchingNodes(unitElement, "requires/required").stream().filter(node -> { + try { + var nodes = getNodes(node, "filter"); + return nodes.isEmpty(); + } catch (XPathExpressionException e) { + throw new RuntimeException(e); + } + }).map(node -> node.getAttributes().getNamedItem("name")).map(Node::getNodeValue).toList(); + } + /** * Returns the IDs of IUs required with strict version range. */