Skip to content

Commit

Permalink
Fixup quarkusio#10279 use AppArtifactKey instead of a string in
Browse files Browse the repository at this point in the history
ExtensionDescriptorMojo
  • Loading branch information
ppalaga committed Jun 26, 2020
1 parent 7a73160 commit d7ce612
Showing 1 changed file with 17 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.quarkus.bootstrap.BootstrapConstants;
import io.quarkus.bootstrap.model.AppArtifactCoords;
import io.quarkus.bootstrap.model.AppArtifactKey;
import io.quarkus.bootstrap.model.AppModel;
import java.io.BufferedReader;
import java.io.BufferedWriter;
Expand Down Expand Up @@ -268,11 +269,13 @@ private void validateExtensionDeps() throws MojoExecutionException {

final AppArtifactCoords deploymentCoords = AppArtifactCoords.fromString(deployment);

final String rootDeploymentGact = gact(deploymentCoords);
final AppArtifactKey rootDeploymentGact = deploymentCoords.getKey();
final Node rootDeployment = new Node(null, rootDeploymentGact, 2);
final Node rootRuntime = rootDeployment.newChild(gact(project.getArtifact()), 1);
final Artifact artifact = project.getArtifact();
final Node rootRuntime = rootDeployment.newChild(new AppArtifactKey(artifact.getGroupId(), artifact.getArtifactId(),
artifact.getClassifier(), artifact.getType()), 1);

final Map<String, Node> expectedExtensionDeps = new HashMap<>();
final Map<AppArtifactKey, Node> expectedExtensionDeps = new HashMap<>();
expectedExtensionDeps.put(rootDeploymentGact, rootDeployment);
expectedExtensionDeps.put(rootRuntime.gact, rootRuntime);
// collect transitive extension deps
Expand Down Expand Up @@ -315,7 +318,7 @@ public boolean visitEnter(DependencyNode node) {
+ BootstrapConstants.PROP_DEPLOYMENT_ARTIFACT + " property in its "
+ BootstrapConstants.DESCRIPTOR_PATH);
}
currentNode = currentNode.newChild(gact(AppArtifactCoords.fromString(deploymentStr)),
currentNode = currentNode.newChild(AppArtifactCoords.fromString(deploymentStr).getKey(),
currentNodeId);
expectedExtensionDeps.put(currentNode.gact, currentNode);
extDepsTotal.incrementAndGet();
Expand Down Expand Up @@ -353,7 +356,8 @@ public boolean visitEnter(DependencyNode dep) {
if (artifact == null) {
return true;
}
final Node node = expectedExtensionDeps.get(gact(artifact));
final Node node = expectedExtensionDeps.get(new AppArtifactKey(artifact.getGroupId(), artifact.getArtifactId(),
artifact.getClassifier(), artifact.getExtension()));
if (node != null && !node.included) {
node.included = true;
extDepsTotal.decrementAndGet();
Expand All @@ -372,12 +376,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<String> missing = rootDeployment.collectMissing(log);
final List<AppArtifactKey> 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<String> i = missing.iterator();
final Iterator<AppArtifactKey> i = missing.iterator();
buf.append(i.next());
while (i.hasNext()) {
buf.append(", ").append(i.next());
Expand Down Expand Up @@ -484,62 +488,32 @@ 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 String gact;
final AppArtifactKey gact;
final int id;
boolean included;
List<Node> children = new ArrayList<>(0);

Node(Node parent, String gact, int id) {
Node(Node parent, AppArtifactKey gact, int id) {
this.parent = parent;
this.gact = gact;
this.id = id;
}

Node newChild(String gact, int id) {
Node newChild(AppArtifactKey gact, int id) {
final Node child = new Node(this, gact, id);
children.add(child);
return child;
}

List<String> collectMissing(Log log) {
final List<String> missing = new ArrayList<>();
List<AppArtifactKey> collectMissing(Log log) {
final List<AppArtifactKey> missing = new ArrayList<>();
collectMissing(log, 0, missing);
return missing;
}

private void collectMissing(Log log, int depth, List<String> missing) {
private void collectMissing(Log log, int depth, List<AppArtifactKey> missing) {
final StringBuilder buf = new StringBuilder();
if (included) {
buf.append('+');
Expand Down

0 comments on commit d7ce612

Please sign in to comment.