Skip to content

Commit dc2e0f2

Browse files
committed
shell - fix MavenSupport.parse() when some current artefact GAV properties 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
1 parent 54198be commit dc2e0f2

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

restx-build/src/main/java/restx/build/MavenSupport.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public ModuleDescriptor parse(InputStream stream) throws IOException {
2727
if (jsonObject.has("parent")) {
2828
JSONObject parentObject = jsonObject.getJSONObject("parent");
2929
// No packaging type is allowed on <parent> tag
30-
parent = getGav(parentObject, null);
30+
parent = getGav(parentObject, null, null);
3131
} else {
3232
parent = null;
3333
}
3434
// Packaging is defined with <packaging> tag on artefact definition
35-
GAV gav = getGav(jsonObject, "packaging");
35+
GAV gav = getGav(jsonObject, "packaging", parent);
3636
String packaging = jsonObject.has("packaging") ? jsonObject.getString("packaging") : "jar";
3737

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

6666
// Packaging is defined with <type> tag on dependencies
67-
scopeDependencies.add(new ModuleDependency(getGav(dep, "type")));
67+
scopeDependencies.add(new ModuleDependency(getGav(dep, "type", null)));
6868
}
6969
}
7070

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

75-
private GAV getGav(JSONObject jsonObject, String typeKey) {
75+
private GAV getGav(JSONObject jsonObject, String typeKey, GAV parentGAV) {
7676
return new GAV(
77-
jsonObject.getString("groupId"),
78-
jsonObject.getString("artifactId"),
79-
String.valueOf(jsonObject.get("version")),
80-
typeKey==null?null:jsonObject.has(typeKey)?jsonObject.getString(typeKey):null,
77+
jsonObject.has("groupId")?jsonObject.getString("groupId"):parentGAV==null?null:parentGAV.getGroupId(),
78+
jsonObject.has("artifactId")?jsonObject.getString("artifactId"):parentGAV==null?null:parentGAV.getArtifactId(),
79+
jsonObject.has("version")?String.valueOf(jsonObject.get("version")):parentGAV==null?null:parentGAV.getVersion(),
80+
typeKey==null?null:jsonObject.has(typeKey)?jsonObject.getString(typeKey):parentGAV==null?null:parentGAV.getType(),
8181
jsonObject.has("classifier")?jsonObject.getString("classifier"):null,
8282
jsonObject.has("optional")?jsonObject.getBoolean("optional"):false);
8383
}

0 commit comments

Comments
 (0)