gnodet-bot commented on code in PR #13928:
URL: https://github.com/apache/maven/pull/13928#discussion_r4517793785


##########
impl/maven-testing/src/main/java/org/apache/maven/testing/plugin/MojoExtension.java:
##########
@@ -698,17 +690,38 @@ protected String[] mojoCoordinates(String goal) throws 
Exception {
             return goal.split(":");
         } else {
             Path pluginPom = Paths.get(getPluginBasedir(), "pom.xml");
-            Xpp3Dom pluginPomDom;
+            org.apache.maven.api.model.Model pomModel;
             try (Reader reader = Files.newBufferedReader(pluginPom)) {
-                pluginPomDom = Xpp3DomBuilder.build(reader);
+                pomModel = new MavenStaxReader().read(reader);
             }
-            String artifactId = pluginPomDom.getChild("artifactId").getValue();
-            String groupId = interpolate(pluginPom, pluginPomDom, 
resolveFromRootThenParent(pluginPomDom, "groupId"));
-            String version = interpolate(pluginPom, pluginPomDom, 
resolveFromRootThenParent(pluginPomDom, "version"));
+            String artifactId = pomModel.getArtifactId();
+            String groupId = resolveGroupId(pomModel);
+            String rawVersion = resolveVersion(pomModel);
+            String version = interpolateModel(pluginPom, pomModel, rawVersion);
             return new String[] {groupId, artifactId, version, goal};
         }
     }
 
+    private static String resolveGroupId(org.apache.maven.api.model.Model 
model) throws Exception {
+        if (model.getGroupId() != null && !model.getGroupId().isEmpty()) {
+            return model.getGroupId();
+        }
+        if (model.getParent() != null && model.getParent().getGroupId() != 
null) {
+            return model.getParent().getGroupId();
+        }
+        throw new Exception("unable to determine groupId");
+    }
+
+    private static String resolveVersion(org.apache.maven.api.model.Model 
model) throws Exception {

Review Comment:
   Test MojoExtension groupId



##########
impl/maven-testing/src/main/java/org/apache/maven/testing/plugin/MojoExtension.java:
##########
@@ -698,17 +690,38 @@ protected String[] mojoCoordinates(String goal) throws 
Exception {
             return goal.split(":");
         } else {
             Path pluginPom = Paths.get(getPluginBasedir(), "pom.xml");
-            Xpp3Dom pluginPomDom;
+            org.apache.maven.api.model.Model pomModel;
             try (Reader reader = Files.newBufferedReader(pluginPom)) {
-                pluginPomDom = Xpp3DomBuilder.build(reader);
+                pomModel = new MavenStaxReader().read(reader);
             }
-            String artifactId = pluginPomDom.getChild("artifactId").getValue();
-            String groupId = interpolate(pluginPom, pluginPomDom, 
resolveFromRootThenParent(pluginPomDom, "groupId"));
-            String version = interpolate(pluginPom, pluginPomDom, 
resolveFromRootThenParent(pluginPomDom, "version"));
+            String artifactId = pomModel.getArtifactId();
+            String groupId = resolveGroupId(pomModel);
+            String rawVersion = resolveVersion(pomModel);
+            String version = interpolateModel(pluginPom, pomModel, rawVersion);
             return new String[] {groupId, artifactId, version, goal};
         }
     }
 
+    private static String resolveGroupId(org.apache.maven.api.model.Model 
model) throws Exception {
+        if (model.getGroupId() != null && !model.getGroupId().isEmpty()) {
+            return model.getGroupId();
+        }
+        if (model.getParent() != null && model.getParent().getGroupId() != 
null) {
+            return model.getParent().getGroupId();
+        }
+        throw new Exception("unable to determine groupId");
+    }
+
+    private static String resolveVersion(org.apache.maven.api.model.Model 
model) throws Exception {
+        if (model.getVersion() != null && !model.getVersion().isEmpty()) {
+            return model.getVersion();
+        }
+        if (model.getParent() != null && model.getParent().getVersion() != 
null) {
+            return model.getParent().getVersion();
+        }
+        throw new Exception("unable to determine version");
+    }
+
     private XmlNode finalizeConfig(XmlNode config, MojoDescriptor 
mojoDescriptor) {

Review Comment:
   Test MojoExtension version



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to