diff --git a/java/maven/src/org/netbeans/modules/maven/NbArtifactFixer.java b/java/maven/src/org/netbeans/modules/maven/NbArtifactFixer.java index 0d8e7ae2cff7..50d0626b63ec 100644 --- a/java/maven/src/org/netbeans/modules/maven/NbArtifactFixer.java +++ b/java/maven/src/org/netbeans/modules/maven/NbArtifactFixer.java @@ -26,6 +26,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.function.Consumer; import java.util.logging.Level; @@ -100,7 +101,7 @@ public class NbArtifactFixer implements ArtifactFixer { } else { LOG.log(Level.INFO, "Cycle in NbArtifactFixer resolution (issue #234586): {0}", Arrays.toString(gavSet.toArray())); } - + // NOTE: this catches metadata request for all artifacts not locally cached, but all will be repored as POMs. try { File f = createFallbackPOM(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); //instead of workarounds down the road, we set the artifact's file here. @@ -108,7 +109,35 @@ public class NbArtifactFixer implements ArtifactFixer { artifact.setFile(f); Set s = CAPTURE_FAKE_ARTIFACTS.get(); if (s != null) { - s.add(artifact); + String c = artifact.getProperty("nbResolvingArtifact.classifier", null); + String e = artifact.getProperty("nbResolvingArtifact.extension", null); + + if ("".equals(c)) { + c = null; + } + // If it really resolves a POM dependency, add to missing artifacts. + if ((c == null && e == null) || + (Objects.equals(c, artifact.getClassifier()) && Objects.equals(e, artifact.getExtension()))) { + s.add(artifact); + } else { + if (local.getLayout() != null) { // #189807: for unknown reasons, there is no layout when running inside MavenCommandLineExecutor.run + + //the special snapshot handling is important in case of SNAPSHOT or x-SNAPSHOT versions, for some reason aether has slightly different + //handling of baseversion compared to maven artifact. we need to manually set the baseversion here.. + boolean isSnapshot = artifact.isSnapshot(); + DefaultArtifact art = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), null, e, c, new DefaultArtifactHandler(e)); + if (isSnapshot) { + art.setBaseVersion(artifact.getBaseVersion()); + } + String path = local.pathOf(art); + File af = new File(local.getBasedir(), path); + art.setFile(af); + org.eclipse.aether.artifact.DefaultArtifact da = new org.eclipse.aether.artifact.DefaultArtifact( + art.getGroupId(), art.getArtifactId(), art.getClassifier(), art.getType(), + art.getVersion(), artifact.getProperties(), af); + s.add(da); + } + } } return f; } catch (IOException x) { diff --git a/java/maven/src/org/netbeans/modules/maven/problems/MavenModelProblemsProvider.java b/java/maven/src/org/netbeans/modules/maven/problems/MavenModelProblemsProvider.java index 100411840877..333d7a9cdf15 100644 --- a/java/maven/src/org/netbeans/modules/maven/problems/MavenModelProblemsProvider.java +++ b/java/maven/src/org/netbeans/modules/maven/problems/MavenModelProblemsProvider.java @@ -31,12 +31,15 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.stream.Collectors; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; @@ -321,6 +324,11 @@ private void addMissingArtifact(Artifact a) { problemReporter.addMissingArtifact(a, checkMissing); } + private static String artifactId(Artifact a) { + return a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion() + ":" + + (a.getClassifier() == null ? "" : a.getClassifier()) + "/" + a.getType(); + } + @NbBundle.Messages({ "ERR_SystemScope=A 'system' scope dependency was not found. Code completion is affected.", "MSG_SystemScope=There is a 'system' scoped dependency in the project but the path to the binary is not valid.\n" @@ -368,7 +376,9 @@ public Collection doArtifactChecks(@NonNull MavenProject project Collection toCheck = new HashSet<>(project.getArtifacts()); if (fakes != null) { - toCheck.addAll(fakes); + // the fake artifacts are typically without a scope, so ignore scope when merging with other reported pieces. + Set ids = toCheck.stream().map(MavenModelProblemsProvider::artifactId).collect(Collectors.toSet()); + fakes.stream().filter(a -> !ids.contains(artifactId(a))).forEach(toCheck::add); } for (Artifact art : toCheck) {