From d2e3e29e8e2358df7c97ca56399aa2545474f262 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Thu, 31 Aug 2023 00:14:45 +0200 Subject: [PATCH] Consider Source-Unit version when adding sources to a P2-repo And add a test case to verify the behavior is correct. (cherry picked from commit 5e26e1654c7cc404b174b791b6db0a475478d4df) --- .../tycho/p2tools/TychoMirrorApplication.java | 32 +++++++++++-------- .../Maven.target | 16 ++++++++++ .../category.xml | 2 ++ .../p2Repository/IncludeAllSourcesTest.java | 8 +++-- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java index 072b38a4f3..becbe1c044 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java @@ -16,12 +16,13 @@ import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import java.util.stream.Stream; +import java.util.stream.StreamSupport; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.equinox.internal.p2.director.PermissiveSlicer; @@ -36,6 +37,7 @@ import org.eclipse.equinox.p2.metadata.IRequirement; import org.eclipse.equinox.p2.metadata.expression.IMatchExpression; import org.eclipse.equinox.p2.query.CollectionResult; +import org.eclipse.equinox.p2.query.IQueryResult; import org.eclipse.equinox.p2.query.IQueryable; import org.eclipse.equinox.p2.query.QueryUtil; import org.eclipse.equinox.p2.repository.IRepository; @@ -50,6 +52,7 @@ public class TychoMirrorApplication extends org.eclipse.tycho.p2tools.copiedfromp2.MirrorApplication { private static final String SOURCE_SUFFIX = ".source"; + private static final String FEATURE_GROUP = ".feature.group"; private final Map extraArtifactRepositoryProperties; private final List repositoryReferences; private boolean includeAllSource; @@ -91,7 +94,7 @@ protected boolean isApplicable(IInstallableUnit iu, IRequirement req) { if ((includeRequiredBundles || includeRequiredFeatures) && QueryUtil.isGroup(iu)) { if (req instanceof IRequiredCapability capability) { if (IInstallableUnit.NAMESPACE_IU_ID.equals(capability.getNamespace())) { - boolean isFeature = capability.getName().endsWith(".feature.group"); + boolean isFeature = capability.getName().endsWith(FEATURE_GROUP); if ((isFeature && includeRequiredFeatures) || (!isFeature && includeRequiredBundles)) { if (!includeOptionalDependencies) { if (req.getMin() == 0) { @@ -130,19 +133,20 @@ public IQueryable slice(IInstallableUnit[] ius, IProgressMonit if (includeAllSource && targetPlatform != null) { Set collected = slice.query(QueryUtil.ALL_UNITS, null).toSet(); Set result = new HashSet<>(collected); - Map sourceIus = new HashMap<>(); - targetPlatform.getMetadataRepository().query(QueryUtil.ALL_UNITS, null).forEach(iu -> { - if (iu.getId().endsWith(SOURCE_SUFFIX)) { - sourceIus.put(iu.getId(), iu); - } - }); + IQueryResult query = targetPlatform.getMetadataRepository() + .query(QueryUtil.ALL_UNITS, null); + Map> sourceIus = StreamSupport.stream(query.spliterator(), false) + .filter(iu -> iu.getId().endsWith(SOURCE_SUFFIX)) + .collect(Collectors.groupingBy(IInstallableUnit::getId)); for (IInstallableUnit iu : collected) { - String sourceId = iu.getId().endsWith(".feature.group") - ? iu.getId().replaceAll(".feature.group", SOURCE_SUFFIX) - : iu.getId() + SOURCE_SUFFIX; - IInstallableUnit sourceUnit = sourceIus.get(sourceId); - if (sourceUnit != null) { - result.add(sourceUnit); + String id = iu.getId(); + String sourceId = id.endsWith(FEATURE_GROUP) + ? id.substring(id.length() - FEATURE_GROUP.length()) + SOURCE_SUFFIX + : id + SOURCE_SUFFIX; + List sourceUnits = sourceIus.get(sourceId); + if (sourceUnits != null) { + sourceUnits.stream().filter(su -> su.getVersion().equals(iu.getVersion())) // + .findFirst().ifPresent(result::add); } } return new CollectionResult<>(result); diff --git a/tycho-its/projects/p2Repository.includeAllSources/Maven.target b/tycho-its/projects/p2Repository.includeAllSources/Maven.target index ee7f7e3235..ddc2c3a295 100644 --- a/tycho-its/projects/p2Repository.includeAllSources/Maven.target +++ b/tycho-its/projects/p2Repository.includeAllSources/Maven.target @@ -6,5 +6,21 @@ + + + + org.opentest4j + opentest4j + 1.3.0 + jar + + + org.opentest4j + opentest4j + 1.2.0 + jar + + + \ No newline at end of file diff --git a/tycho-its/projects/p2Repository.includeAllSources/category.xml b/tycho-its/projects/p2Repository.includeAllSources/category.xml index 77c459e674..33b1b4ff9d 100644 --- a/tycho-its/projects/p2Repository.includeAllSources/category.xml +++ b/tycho-its/projects/p2Repository.includeAllSources/category.xml @@ -1,4 +1,6 @@ + + diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/p2Repository/IncludeAllSourcesTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/p2Repository/IncludeAllSourcesTest.java index 294909af11..e968944096 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/p2Repository/IncludeAllSourcesTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/p2Repository/IncludeAllSourcesTest.java @@ -9,6 +9,8 @@ *******************************************************************************/ package org.eclipse.tycho.test.p2Repository; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -29,7 +31,7 @@ public class IncludeAllSourcesTest extends AbstractTychoIntegrationTest { @Test public void testSourceInclusion() throws Exception { - Verifier verifier = new IncludeAllSourcesTest().getVerifier("p2Repository.includeAllSources", false); + Verifier verifier = getVerifier("p2Repository.includeAllSources", false); verifier.executeGoal("verify"); // Missing source should never trigger an error verifier.verifyErrorFreeLog(); @@ -42,11 +44,13 @@ public void testSourceInclusion() throws Exception { assertThrows(AssertionError.class, () -> { p2Repo.getUniqueIU("org.apache.commons.commons-io.source"); }); + // test inclusion of sources for multiple version of the main/source artifact + assertThat(p2Repo.getUnitVersions("org.opentest4j.source"), containsInAnyOrder("1.2.0", "1.3.0")); } @Test public void testIncludeAllSourcesFromOldOrbit() throws Exception { - Verifier verifier = new IncludeAllSourcesTest().getVerifier("p2Repository.includeAllSources.oldOrbit", false); + Verifier verifier = getVerifier("p2Repository.includeAllSources.oldOrbit", false); File localRepository = new File(verifier.getLocalRepository()); File indexFile = new File(localRepository, FileBasedTychoRepositoryIndex.ARTIFACTS_INDEX_RELPATH); if (indexFile.exists()) {