From cead3969a8ec44a2cc81d488be1960aa35b659cc Mon Sep 17 00:00:00 2001 From: Peter Palaga Date: Thu, 25 Jun 2020 22:04:30 +0200 Subject: [PATCH] Fix #10279 Dependency parity validator is missing dependencies with different versions --- .../maven/ExtensionDescriptorMojo.java | 81 ++++++++++++------- 1 file changed, 52 insertions(+), 29 deletions(-) diff --git a/independent-projects/bootstrap/maven-plugin/src/main/java/io/quarkus/maven/ExtensionDescriptorMojo.java b/independent-projects/bootstrap/maven-plugin/src/main/java/io/quarkus/maven/ExtensionDescriptorMojo.java index 67d933981fdef..75d0de4c0ea9b 100644 --- a/independent-projects/bootstrap/maven-plugin/src/main/java/io/quarkus/maven/ExtensionDescriptorMojo.java +++ b/independent-projects/bootstrap/maven-plugin/src/main/java/io/quarkus/maven/ExtensionDescriptorMojo.java @@ -268,12 +268,13 @@ private void validateExtensionDeps() throws MojoExecutionException { final AppArtifactCoords deploymentCoords = AppArtifactCoords.fromString(deployment); - final Node rootDeployment = new Node(null, deploymentCoords, 2); - final Node rootRuntime = rootDeployment.newChild(toCoords(project.getArtifact()), 1); + final String rootDeploymentGact = gact(deploymentCoords); + final Node rootDeployment = new Node(null, rootDeploymentGact, 2); + final Node rootRuntime = rootDeployment.newChild(gact(project.getArtifact()), 1); - final Map expectedExtensionDeps = new HashMap<>(); - expectedExtensionDeps.put(deploymentCoords, rootDeployment); - expectedExtensionDeps.put(rootRuntime.coords, rootRuntime); + final Map expectedExtensionDeps = new HashMap<>(); + expectedExtensionDeps.put(rootDeploymentGact, rootDeployment); + expectedExtensionDeps.put(rootRuntime.gact, rootRuntime); // collect transitive extension deps final DependencyResult resolvedDeps; @@ -314,8 +315,9 @@ public boolean visitEnter(DependencyNode node) { + BootstrapConstants.PROP_DEPLOYMENT_ARTIFACT + " property in its " + BootstrapConstants.DESCRIPTOR_PATH); } - currentNode = currentNode.newChild(AppArtifactCoords.fromString(deploymentStr), currentNodeId); - expectedExtensionDeps.put(currentNode.coords, currentNode); + currentNode = currentNode.newChild(gact(AppArtifactCoords.fromString(deploymentStr)), + currentNodeId); + expectedExtensionDeps.put(currentNode.gact, currentNode); extDepsTotal.incrementAndGet(); } } catch (IOException e) { @@ -351,9 +353,7 @@ public boolean visitEnter(DependencyNode dep) { if (artifact == null) { return true; } - final AppArtifactCoords coords = new AppArtifactCoords(artifact.getGroupId(), artifact.getArtifactId(), - artifact.getClassifier(), artifact.getExtension(), artifact.getVersion()); - final Node node = expectedExtensionDeps.get(coords); + final Node node = expectedExtensionDeps.get(gact(artifact)); if (node != null && !node.included) { node.included = true; extDepsTotal.decrementAndGet(); @@ -372,12 +372,12 @@ public boolean visitLeave(DependencyNode node) { log.error("Quarkus Extension Dependency Verification Error"); log.error("Deployment artifact " + deploymentCoords + " was found to be missing dependencies on Quarkus extension artifacts marked with '-' below:"); - final List missing = rootDeployment.collectMissing(log); + final List missing = rootDeployment.collectMissing(log); final StringBuilder buf = new StringBuilder(); buf.append("Deployment artifact "); buf.append(deploymentCoords); buf.append(" is missing the following dependencies from its configuration: "); - final Iterator i = missing.iterator(); + final Iterator i = missing.iterator(); buf.append(i.next()); while (i.hasNext()) { buf.append(", ").append(i.next()); @@ -415,11 +415,6 @@ private boolean isAnalyzable(final File f) { return f != null && f.getName().endsWith(".jar") && f.exists() && !f.isDirectory(); } - private AppArtifactCoords toCoords(Artifact a) { - return new AppArtifactCoords(a.getGroupId(), a.getArtifactId(), a.getClassifier(), - a.getArtifactHandler().getExtension(), a.getVersion()); - } - private void transformLegacyToNew(final Path output, ObjectNode extObject, ObjectMapper mapper) throws MojoExecutionException { ObjectNode metadata = null; @@ -461,8 +456,6 @@ private void transformLegacyToNew(final Path output, ObjectNode extObject, Objec extObject.set("metadata", metadata); - // updateSourceFiles(output, extObject, mapper); - } /** @@ -491,44 +484,74 @@ private ObjectMapper getMapper(boolean yaml) { } } + static String gact(AppArtifactCoords artifact) { + StringBuilder buf = new StringBuilder(); + buf.append(artifact.getGroupId()).append(':').append(artifact.getArtifactId()).append(':'); + final String classifier = artifact.getClassifier(); + if (classifier != null && !classifier.isEmpty()) { + buf.append(classifier); + } + return buf.append(':').append(artifact.getType()).append(':').toString(); + } + + static String gact(Artifact artifact) { + StringBuilder buf = new StringBuilder(); + buf.append(artifact.getGroupId()).append(':').append(artifact.getArtifactId()).append(':'); + final String classifier = artifact.getClassifier(); + if (classifier != null && !classifier.isEmpty()) { + buf.append(classifier); + } + return buf.append(':').append(artifact.getType()).append(':').toString(); + } + + static String gact(org.eclipse.aether.artifact.Artifact artifact) { + StringBuilder buf = new StringBuilder(); + buf.append(artifact.getGroupId()).append(':').append(artifact.getArtifactId()).append(':'); + final String classifier = artifact.getClassifier(); + if (classifier != null && !classifier.isEmpty()) { + buf.append(classifier); + } + return buf.append(':').append(artifact.getExtension()).append(':').toString(); + } + private static class Node { final Node parent; - final AppArtifactCoords coords; + final String gact; final int id; boolean included; List children = new ArrayList<>(0); - Node(Node parent, AppArtifactCoords artifact, int id) { + Node(Node parent, String gact, int id) { this.parent = parent; - this.coords = artifact; + this.gact = gact; this.id = id; } - Node newChild(AppArtifactCoords artifact, int id) { - final Node child = new Node(this, artifact, id); + Node newChild(String gact, int id) { + final Node child = new Node(this, gact, id); children.add(child); return child; } - List collectMissing(Log log) { - final List missing = new ArrayList<>(); + List collectMissing(Log log) { + final List missing = new ArrayList<>(); collectMissing(log, 0, missing); return missing; } - private void collectMissing(Log log, int depth, List missing) { + private void collectMissing(Log log, int depth, List missing) { final StringBuilder buf = new StringBuilder(); if (included) { buf.append('+'); } else { buf.append('-'); - missing.add(coords); + missing.add(gact); } buf.append(' '); for (int i = 0; i < depth; ++i) { buf.append(" "); } - buf.append(coords); + buf.append(gact); log.error(buf.toString()); for (Node child : children) { child.collectMissing(log, depth + 1, missing);