Permalink
Browse files

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 dc2e0f2f05f7f58713fb69f20a0d581410b2d6de
Showing with 8 additions and 8 deletions.
  1. +8 −8 restx-build/src/main/java/restx/build/MavenSupport.java
@@ -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<>();
@@ -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);
}

0 comments on commit dc2e0f2

Please sign in to comment.