Skip to content

Commit

Permalink
Validation of codestart artifacts configured in extension descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
aloubyansky committed Mar 18, 2021
1 parent 7096c33 commit d193de9
Show file tree
Hide file tree
Showing 21 changed files with 69 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ metadata:
name: "amazon-lambda"
kind: "singleton-example"
languages: "java"
artifact: "io.quarkus:quarkus-descriptor-json"
artifact: "io.quarkus:quarkus-platform-descriptor-json"
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ metadata:
name: "azure-functions-http"
kind: "singleton-example"
languages: "java"
artifact: "io.quarkus:quarkus-descriptor-json"
artifact: "io.quarkus:quarkus-platform-descriptor-json"
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ metadata:
languages:
- "java"
- "kotlin"
artifact: "io.quarkus:quarkus-descriptor-json"
artifact: "io.quarkus:quarkus-platform-descriptor-json"
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ metadata:
name: "funqy-amazon-lambda"
kind: "singleton-example"
languages: "java"
artifact: "io.quarkus:quarkus-descriptor-json"
artifact: "io.quarkus:quarkus-platform-descriptor-json"
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ metadata:
name: "funqy-google-cloud-functions-example"
kind: "singleton-example"
languages: "java"
artifact: "io.quarkus:quarkus-descriptor-json"
artifact: "io.quarkus:quarkus-platform-descriptor-json"
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ metadata:
name: "funqy-http"
kind: "example"
languages: "java"
artifact: "io.quarkus:quarkus-descriptor-json"
artifact: "io.quarkus:quarkus-platform-descriptor-json"
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ metadata:
name: "funqy-knative-events"
kind: "singleton-example"
languages: "java"
artifact: "io.quarkus:quarkus-descriptor-json"
artifact: "io.quarkus:quarkus-platform-descriptor-json"
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ metadata:
name: "google-cloud-functions-http"
kind: "singleton-example"
languages: "java"
artifact: "io.quarkus:quarkus-descriptor-json"
artifact: "io.quarkus:quarkus-platform-descriptor-json"
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ metadata:
name: "google-cloud-functions"
kind: "singleton-example"
languages: "java"
artifact: "io.quarkus:quarkus-descriptor-json"
artifact: "io.quarkus:quarkus-platform-descriptor-json"
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ metadata:
codestart:
name: "kotlin"
kind: "core"
artifact: "io.quarkus:quarkus-descriptor-json"
artifact: "io.quarkus:quarkus-platform-descriptor-json"
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ metadata:
languages:
- "java"
- "kotlin"
artifact: "io.quarkus:quarkus-descriptor-json"
artifact: "io.quarkus:quarkus-platform-descriptor-json"
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ metadata:
languages:
- "java"
- "kotlin"
artifact: "io.quarkus:quarkus-descriptor-json"
artifact: "io.quarkus:quarkus-platform-descriptor-json"
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ metadata:
languages:
- "java"
- "kotlin"
artifact: "io.quarkus:quarkus-descriptor-json"
artifact: "io.quarkus:quarkus-platform-descriptor-json"
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ metadata:
languages:
- "java"
- "kotlin"
artifact: "io.quarkus:quarkus-descriptor-json"
artifact: "io.quarkus:quarkus-platform-descriptor-json"
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ metadata:
- "java"
- "kotlin"
- "scala"
artifact: "io.quarkus:quarkus-descriptor-json"
artifact: "io.quarkus:quarkus-platform-descriptor-json"
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ metadata:
- "java"
- "kotlin"
- "scala"
artifact: "io.quarkus:quarkus-descriptor-json"
artifact: "io.quarkus:quarkus-platform-descriptor-json"
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ metadata:
codestart:
name: "scala"
kind: "core"
artifact: "io.quarkus:quarkus-descriptor-json"
artifact: "io.quarkus:quarkus-platform-descriptor-json"
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ metadata:
- "java"
- "kotlin"
- "scala"
artifact: "io.quarkus:quarkus-descriptor-json"
artifact: "io.quarkus:quarkus-platform-descriptor-json"

Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ metadata:
name: "undertow-websockets"
kind: "example"
languages: "java"
artifact: "io.quarkus:quarkus-descriptor-json"
artifact: "io.quarkus:quarkus-platform-descriptor-json"
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ public class ExtensionDescriptorMojo extends AbstractMojo {
@Parameter
private List<String> dependencyCondition = new ArrayList<>(0);

@Parameter(property = "skipCodestartValidation")
boolean skipCodestartValidation;

AppArtifactCoords deploymentCoords;
CollectResult collectedDeploymentDeps;

Expand Down Expand Up @@ -353,6 +356,8 @@ public void execute() throws MojoExecutionException {

setBuiltWithQuarkusCoreVersion(mapper, extObject);

completeCodestartArtifact(mapper, extObject);

final DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter();
prettyPrinter.indentArraysWith(DefaultIndenter.SYSTEM_LINEFEED_INSTANCE);

Expand All @@ -365,6 +370,50 @@ public void execute() throws MojoExecutionException {
}
}

private void completeCodestartArtifact(ObjectMapper mapper, ObjectNode extObject) throws MojoExecutionException {
JsonNode mvalue = getJsonElement(extObject, METADATA, "codestart");
if (mvalue == null || !mvalue.isObject()) {
return;
}
final ObjectNode codestartObject = (ObjectNode) mvalue;
mvalue = mvalue.get("artifact");
if (mvalue == null) {
if (!skipCodestartValidation) {
throw new MojoExecutionException("Codestart artifact is missing from the " + extensionFile);
}
return;
}
org.eclipse.aether.artifact.Artifact codestartArtifact = DependencyNodeUtils.toArtifact(mvalue.asText());
if (codestartArtifact.getVersion() == null || codestartArtifact.getVersion().isEmpty()) {
codestartArtifact = codestartArtifact.setVersion(project.getVersion());
codestartObject.put("artifact",
codestartArtifact.getGroupId() + ":" + codestartArtifact.getArtifactId() + ":"
+ codestartArtifact.getClassifier() + ":" + codestartArtifact.getExtension() + ":"
+ codestartArtifact.getVersion());
}
if (!skipCodestartValidation) {
try {
resolve(codestartArtifact);
} catch (MojoExecutionException e) {
throw new MojoExecutionException("Failed to resolve codestart artifact " + codestartArtifact, e);
}
}
}

private static JsonNode getJsonElement(ObjectNode extObject, String... elements) {
JsonNode mvalue = extObject.get(elements[0]);
int i = 1;
while (i < elements.length) {
if (mvalue == null || !mvalue.isObject()) {
return null;
}
final String element = elements[i++];
extObject = (ObjectNode) mvalue;
mvalue = extObject.get(element);
}
return mvalue;
}

private void setBuiltWithQuarkusCoreVersion(ObjectMapper mapper, ObjectNode extObject) throws MojoExecutionException {
final QuarkusCoreDeploymentVersionLocator coreVersionLocator = new QuarkusCoreDeploymentVersionLocator();
collectDeploymentDeps().getRoot().accept(coreVersionLocator);
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
<invoker.skip>true</invoker.skip> <!-- maven-invoker-plugin -->
<jbang.skip>true</jbang.skip> <!-- jbang-maven-plugin -->
<forbiddenapis.skip>true</forbiddenapis.skip> <!-- forbidden-apis maven plugin -->
<skipCodestartValidation>true</skipCodestartValidation>
</properties>
<build>
<defaultGoal>clean install</defaultGoal>
Expand Down

0 comments on commit d193de9

Please sign in to comment.