slawekjaranowski commented on PR #422:
URL:
https://github.com/apache/maven-help-plugin/pull/422#issuecomment-6753408074
I merged `master` into this branch to resolve the conflict in
`EffectivePomMojoTest` (#414 added the same file). The `encodingOrDefault`
tests now live next to the mojo test. I also moved the `project.getModel()`
stub from `@BeforeEach` into the mojo test, otherwise Mockito strict stubs fail
the two static tests with `UnnecessaryStubbingException`.
I also looked at the implementation itself:
1. **The null case is very unlikely.** `Model.modelEncoding` defaults to
`"UTF-8"` in maven-model 3.x, and the JVM always sets `file.encoding`. Even
with null, `prettyFormat` already skips `format.setEncoding(...)`. So the
fallback is fine as a safety net, but it doesn't change behavior in any real
scenario.
2. **Change when `output` is not set.** Before, the XML declaration printed
to the console used `file.encoding`. MPH-87 (80b2ae2) chose that on purpose, to
"provide the encoding of the output stream written to". Now it always uses the
model encoding. This affects only the console text, so it is OK for me, but it
is more than #394 asks for.
3. **Existing issue, not introduced here:** `writeXmlFile` always writes
UTF-8 (`Files.newBufferedWriter`), while the XML declaration uses the model
encoding. For a POM with `encoding="ISO-8859-1"` and `-Doutput=...`, the file
declares ISO-8859-1 but contains UTF-8 bytes. Non-ASCII characters then make it
invalid XML.
4. `EffectiveSettingsMojo` (lines 93-95) still has the same `output != null
? ... : System.getProperty("file.encoding")` pattern.
5. The PR description mentions `Charset.defaultCharset()`, but the code now
falls back to UTF-8. Please update the description.
I suggest keeping this PR as it is (after fixing the description) and
handling 3 and 4 in a separate issue. A consistent fix there could always use
UTF-8, for both the declaration and the file writer, in both mojos.
--
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]