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) {