From a88ddc4b905584239391d9728c47abd1b2d75f63 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 --- .../tycho/p2tools/TychoMirrorApplication.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 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..724c3947c2 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 @@ -50,6 +50,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 +92,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 +131,21 @@ 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<>(); + Map> sourceIus = new HashMap<>(); targetPlatform.getMetadataRepository().query(QueryUtil.ALL_UNITS, null).forEach(iu -> { if (iu.getId().endsWith(SOURCE_SUFFIX)) { - sourceIus.put(iu.getId(), iu); + sourceIus.computeIfAbsent(iu.getId(), i -> new ArrayList<>()).add(iu); } }); 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);