Skip to content

Commit

Permalink
Merge pull request #19004 from aloubyansky/replace-ext-gav-props
Browse files Browse the repository at this point in the history
Replace ${project.groupId}, ${project.artifactId} and ${project.version} in the quarkus-extension.yaml template
  • Loading branch information
aloubyansky authored Jul 27, 2021
2 parents f77ffd7 + a8fa5e8 commit f4755fc
Showing 1 changed file with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,7 @@ public void execute() throws MojoExecutionException {

transformLegacyToNew(output, extObject, mapper);

JsonNode artifactNode = extObject.get("artifact");
if (artifactNode == null) {
final AppArtifactCoords coords = new AppArtifactCoords(
extObject.has("groupId") ? extObject.get("groupId").asText() : project.getGroupId(),
extObject.has("artifactId") ? extObject.get("artifactId").asText() : project.getArtifactId(),
null,
"jar",
extObject.has("version") ? extObject.get("version").asText() : project.getVersion());
extObject.put("artifact", coords.toString());
}
ensureArtifactCoords(extObject);

if (extObject.get("name") == null) {
if (project.getName() != null) {
Expand Down Expand Up @@ -389,6 +380,45 @@ public void execute() throws MojoExecutionException {
}
}

private void ensureArtifactCoords(ObjectNode extObject) {
String groupId = null;
String artifactId = null;
String version = null;
final JsonNode artifactNode = extObject.get("artifact");
if (artifactNode == null) {
groupId = getRealValueOrNull(extObject.has("groupId") ? extObject.get("groupId").asText() : null,
"${project.groupId");
artifactId = getRealValueOrNull(extObject.has("artifactId") ? extObject.get("artifactId").asText() : null,
"${project.artifactId");
version = getRealValueOrNull(extObject.has("version") ? extObject.get("version").asText() : null,
"${project.version");
} else {
final String[] coordsArr = artifactNode.asText().split(":");
if (coordsArr.length > 0) {
groupId = getRealValueOrNull(coordsArr[0], "${project.groupId}");
if (coordsArr.length > 1) {
artifactId = getRealValueOrNull(coordsArr[1], "${project.artifactId}");
if (coordsArr.length > 2) {
version = getRealValueOrNull(coordsArr[2], "${project.version}");
}
}
}
}
if (artifactNode == null || groupId == null || artifactId == null || version == null) {
final AppArtifactCoords coords = new AppArtifactCoords(
groupId == null ? project.getGroupId() : groupId,
artifactId == null ? project.getArtifactId() : artifactId,
null,
"jar",
version == null ? project.getVersion() : version);
extObject.put("artifact", coords.toString());
}
}

private static String getRealValueOrNull(String s, String propertyExpr) {
return s != null && !s.isBlank() && !s.equals(propertyExpr) ? s : null;
}

private ObjectNode readJsonNode(Path extensionFile, ObjectMapper mapper) throws MojoExecutionException {
try {
return readExtensionYaml(extensionFile, mapper);
Expand Down

0 comments on commit f4755fc

Please sign in to comment.