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


##########
impl/maven-core/src/main/java/org/apache/maven/plugin/internal/MojoExpressionEvaluator.java:
##########
@@ -24,17 +24,17 @@
  * Evaluates mojo parameter expressions and aligns paths to the project base 
directory.
  * Used by {@link V4MojoConfigurator} to resolve plugin parameter values.
  */
-interface MojoExpressionEvaluator {
+public interface MojoExpressionEvaluator {
 
     /**
      * Evaluates the given expression, optionally coercing the result to the 
given type.
      *
      * @param expr the expression to evaluate (e.g. {@code ${project.version}})
      * @param type the desired return type, or {@code null} for no coercion
      * @return the evaluated value, or {@code null}
-     * @throws MojoExpressionEvaluationException if evaluation fails
+     * @throws Exception if evaluation fails
      */
-    Object evaluate(String expr, Class<?> type) throws 
MojoExpressionEvaluationException;
+    Object evaluate(String expr, Class<?> type) throws Exception;
 
     /**
      * Aligns a relative {@link File} to the project base directory.

Review Comment:
   💡 This interface is being promoted to `public` with `@since 4.2.0`, but the 
method now throws bare `Exception` instead of 
`MojoExpressionEvaluationException`. Since `MojoExpressionEvaluationException` 
is also made `public` in this PR, keeping it as the declared throws clause 
would give callers a typed exception to catch rather than forcing them to 
handle `Exception`.



##########
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:
   💡 Same — include the artifact ID for diagnosability:
   ```suggestion
           throw new Exception("unable to determine version for artifact: " + 
model.getArtifactId());
   ```



##########
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:
   💡 The error message doesn't identify *which* POM triggered the failure. 
Including `model.getArtifactId()` would make this much easier to diagnose:
   ```suggestion
           throw new Exception("unable to determine groupId for artifact: " + 
model.getArtifactId());
   ```



-- 
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