From f9a6b301f44b21cbf988302067fad6f2d9d5f66b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Wed, 29 Jan 2025 18:40:13 +0100 Subject: [PATCH] Find reactor projects by location even if their file location changed Currently we cache the "known location" for an artifact, but for a reactor project this location can change (e.g. when it is finally packed to a jar). This leads to the unfortunate situation that we probably no longer find it in the map. This now first lookup the project with the map key, but if it is not found performs a deeper analysis of the artifacts and check if the location actually maps to the artifact location of the reactor project. If that is the case we use that instead of return nothing. Fix https://github.com/eclipse-tycho/tycho/issues/4653 (cherry picked from commit 4d75930fc44d744352d9265ef08fb76c5f7f8ce8) --- .../targetplatform/ArtifactCollection.java | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/targetplatform/ArtifactCollection.java b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/targetplatform/ArtifactCollection.java index 7e2ef1df5a..6b0a003cf7 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/targetplatform/ArtifactCollection.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/targetplatform/ArtifactCollection.java @@ -47,7 +47,7 @@ public class ArtifactCollection { protected final Map artifacts = new LinkedHashMap<>(); - protected final Map> artifactsWithKnownLocation = new LinkedHashMap<>(); + private final Map> artifactsWithKnownLocation = new LinkedHashMap<>(); public List getArtifacts(String type) { return getArtifacts(key -> key.getType().equals(type)); @@ -296,6 +296,15 @@ public ReactorProject getMavenProject(File location) { // #addArtifact enforces all artifacts at the same location have the same reactor project return classified.values().iterator().next().getMavenProject(); } + for (Entry entry : artifacts.entrySet()) { + ArtifactDescriptor value = entry.getValue(); + ReactorProject mavenProject = value.getMavenProject(); + if (mavenProject != null) { + if (Objects.equals(location, mavenProject.getArtifact())) { + return mavenProject; + } + } + } return null; } @@ -303,11 +312,30 @@ public ReactorProject getMavenProject(File location) { * This triggers fetch of all dependencies. * * @param location - * @return + * @return a map of classifier to ArtifactDescriptor (while null represents the + * default artifact) */ public Map getArtifact(File location) { artifacts.values().forEach(artifact -> artifact.getLocation(true)); - return artifactsWithKnownLocation.get(normalizeLocation(location)); + File normalized = normalizeLocation(location); + Map map = artifactsWithKnownLocation.get(normalized); + if (map == null) { + LinkedHashMap hashMap = new LinkedHashMap<>(); + for (ArtifactDescriptor descriptor : artifacts.values()) { + ReactorProject mavenProject = descriptor.getMavenProject(); + if (mavenProject != null) { + if (Objects.equals(location, mavenProject.getArtifact())) { + hashMap.put(descriptor.getClassifier(), descriptor); + } + } + } + if (hashMap.isEmpty()) { + return null; + } + artifactsWithKnownLocation.put(normalizeLocation(location), hashMap); + return hashMap; + } + return map; } public ArtifactDescriptor getArtifact(ArtifactKey key) {