garretwilson commented on code in PR #76:
URL: https://github.com/apache/maven-help-plugin/pull/76#discussion_r1014281946
##########
src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java:
##########
@@ -140,24 +161,85 @@ public void execute()
}
String effectivePom = prettyFormat( w.toString(), encoding, false );
+ effectivePom = prettyFormatVerbose( effectivePom );
+ reportEffectivePom( effectivePom, output );
+ }
+
+ private void generateIndividualEffectivePom() throws MojoExecutionException
+ {
+ String encoding = project.getModel().getModelEncoding();
+ if ( shouldWriteAllEffectivePOMsInReactor() )
+ {
+ // outer root element
+ for ( MavenProject subProject : projects )
+ {
+ StringWriter w = new StringWriter();
+ XMLWriter writer =
+ getPrettyPrintXMLWriterForEffectivePom( w, encoding );
+ writeHeader( writer );
+ writeEffectivePom( subProject, writer );
+ String effectivePom = prettyFormat( w.toString(), encoding,
false );
+ effectivePom = prettyFormatVerbose( effectivePom );
+ File effectiveOutput = output == null ? null
+ : getRelativeOutput( subProject );
+ reportEffectivePom( effectivePom, effectiveOutput );
+ }
+ }
+ else
+ {
+ StringWriter w = new StringWriter();
+ XMLWriter writer =
+ getPrettyPrintXMLWriterForEffectivePom( w, encoding );
+ writeHeader( writer );
+ writeEffectivePom( project, writer );
+ String effectivePom = prettyFormat( w.toString(), encoding, false
);
+ effectivePom = prettyFormatVerbose( effectivePom );
+ File effectiveOutput = output == null ? null
+ : getRelativeOutput( project );
+ reportEffectivePom( effectivePom, effectiveOutput );
+ }
+ }
+
+ private File getRelativeOutput( MavenProject relativeProject )
+ {
+ String rawOutputPath = output.getPath();
+ String rawBasedirPath = project.getBasedir().getPath();
+ String result = rawOutputPath.contains( rawBasedirPath )
Review Comment:
This brute-force searching of strings is not the correct way to process
paths. Even in the best of worlds, there are all sorts of cases this won't work
with (e.g. if the paths are not normalized, and contains `../, etc. In addition
you're using `contains()`, which even with this approach isn't correct (it
looks even in the _middle_ of the string).
Instead of searching raw strings, you should be using path manipulation
methods for semantic `Path` objects. For example, there's a method made to do
exactly what you want:
[`Path.relativize()`](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/Path.html#relativize(java.nio.file.Path)).
And if you don't have a `Path`, you can convert from the old `File` model to
the new Java NIO `Path` model and back.
If you're not used to working with semantic path objects, you might start at
Oracle's [The Path
Class](https://docs.oracle.com/javase/tutorial/essential/io/pathClass.html)
tutorial, which includes [Path
Operations](https://docs.oracle.com/javase/tutorial/essential/io/pathOps.html)
explanations..
--
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]