Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
shell - fix MavenSupport.parse() when some current artefact GAV prope…
…rties are inherited from parent artefact.

This case will likely be more often met since we're now able to generate md.restx.json-less (eg pom.xml only) projects
  • Loading branch information
fcamblor committed Aug 27, 2017
1 parent 54198be commit dc2e0f2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions restx-build/src/main/java/restx/build/MavenSupport.java
Expand Up @@ -27,12 +27,12 @@ public ModuleDescriptor parse(InputStream stream) throws IOException {
if (jsonObject.has("parent")) {
JSONObject parentObject = jsonObject.getJSONObject("parent");
// No packaging type is allowed on <parent> tag
parent = getGav(parentObject, null);
parent = getGav(parentObject, null, null);
} else {
parent = null;
}
// Packaging is defined with <packaging> tag on artefact definition
GAV gav = getGav(jsonObject, "packaging");
GAV gav = getGav(jsonObject, "packaging", parent);
String packaging = jsonObject.has("packaging") ? jsonObject.getString("packaging") : "jar";

Map<String, String> properties = new LinkedHashMap<>();
Expand Down Expand Up @@ -64,20 +64,20 @@ public ModuleDescriptor parse(InputStream stream) throws IOException {
}

// Packaging is defined with <type> tag on dependencies
scopeDependencies.add(new ModuleDependency(getGav(dep, "type")));
scopeDependencies.add(new ModuleDependency(getGav(dep, "type", null)));
}
}

return new ModuleDescriptor(parent, gav, packaging,
properties, new HashMap<String,List<ModuleFragment>>(), dependencies);
}

private GAV getGav(JSONObject jsonObject, String typeKey) {
private GAV getGav(JSONObject jsonObject, String typeKey, GAV parentGAV) {
return new GAV(
jsonObject.getString("groupId"),
jsonObject.getString("artifactId"),
String.valueOf(jsonObject.get("version")),
typeKey==null?null:jsonObject.has(typeKey)?jsonObject.getString(typeKey):null,
jsonObject.has("groupId")?jsonObject.getString("groupId"):parentGAV==null?null:parentGAV.getGroupId(),
jsonObject.has("artifactId")?jsonObject.getString("artifactId"):parentGAV==null?null:parentGAV.getArtifactId(),
jsonObject.has("version")?String.valueOf(jsonObject.get("version")):parentGAV==null?null:parentGAV.getVersion(),
typeKey==null?null:jsonObject.has(typeKey)?jsonObject.getString(typeKey):parentGAV==null?null:parentGAV.getType(),
jsonObject.has("classifier")?jsonObject.getString("classifier"):null,
jsonObject.has("optional")?jsonObject.getBoolean("optional"):false);
}
Expand Down

0 comments on commit dc2e0f2

Please sign in to comment.