gnodet commented on PR #13816:
URL: https://github.com/apache/maven/pull/13816#issuecomment-6632788742

   In 4.2.x (master), we now have `maven-utils` (added in #13554) which already 
provides a `StringInterpolator` class designed exactly for this use case. The 
hand-rolled `interpolate()` method added here could be replaced by it.
   
   The equivalent with `StringInterpolator` would be:
   
   ```java
   private static final StringInterpolator INTERPOLATOR = new 
StringInterpolator();
   
   // in mojoCoordinates():
   String groupId = INTERPOLATOR.interpolate(
       resolveFromRootThenParent(pluginPomDom, "groupId"),
       key -> child(pluginPomDom, "properties")
                .flatMap(p -> child(p, key))
                .map(Xpp3Dom::getValue)
                .orElseGet(() -> System.getProperty(key)));
   ```
   
   The only difference is that `StringInterpolator` by default preserves 
unresolved `${...}` placeholders (doesn't throw), so you'd need to check 
whether the result still contains `${}` and throw if so. That said, 
`StringInterpolator` also supports cycle detection and nested expressions — 
it's a more complete implementation.
   
   This would require adding `maven-utils` as a dependency in 
`impl/maven-testing/pom.xml` (and a `requires org.apache.maven.utils;` in 
`module-info.java` if one exists). Fine to keep the current approach if you'd 
rather avoid the dependency, but since the whole point of `maven-utils` is 
zero-dependency shared utilities, it feels like the right fit.


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