arturobernalg opened a new pull request, #463:
URL: https://github.com/apache/maven-wrapper/pull/463

   WrapperMojo#replaceProperties always rewrote maven-wrapper.properties from 
scratch based only on this execution's parameters, so distributionSha256Sum was 
silently dropped whenever the wrapper was upgraded or reinstalled without 
passing -DdistributionSha256Sum again, leaving the distribution integrity check 
disabled without the user noticing.
   
   Load the existing properties file before rewriting it, and carry over its 
distributionSha256Sum when the execution did not set one explicitly and the 
distributionUrl being configured is unchanged. If the distribution did change, 
the old checksum no longer applies to it, so it is still dropped, but now with 
a warning telling the user to set it again.
   
   Fixes #367
   
   ### What
   Fixes #367: `distributionSha256Sum` in 
`.mvn/wrapper/maven-wrapper.properties` gets silently removed whenever the 
Maven Wrapper is reinstalled/upgraded without passing `-DdistributionSha256Sum` 
again, since `WrapperMojo` always rewrites the properties file from scratch 
based only on the current execution's parameters.
   
   ### How
   - `WrapperMojo#replaceProperties` now loads the existing 
`maven-wrapper.properties` (if any) before rewriting it.
   - New `determineDistributionSha256Sum` method: if `distributionSha256Sum` 
wasn't explicitly set for this execution, it carries over the existing file's 
value, but only when the `distributionUrl` being configured is unchanged from 
the existing file.
   - If the distribution did change (e.g. `-Dmaven=<other-version>`), the stale 
checksum would no longer be valid for it, so it's still dropped as before, but 
now with a `[WARNING]` telling the user to set it again — answering the "open 
question" raised in the issue.
   - `distributionTypeFromExistingMavenWrapperProperties` refactored to share 
the new `loadExistingProperties` helper instead of duplicating the file-read 
logic.
   
   ### Tests
   - 4 new unit tests on `determineDistributionSha256Sum` covering: explicit 
value wins, no existing file, existing sum retained when distribution 
unchanged, existing sum dropped (with warning) when distribution changed.
   - Reproduced the bug first against the exact repro from the issue (`mvn 
wrapper:wrapper -Dmaven=3.9.11`, set `distributionSha256Sum`, `./mvnw 
wrapper:wrapper` again): before the fix the property was missing after 
reinstall; after the fix it's retained.
   - Also verified: reinstalling with a different `-Dmaven=<version>` drops the 
stale checksum and prints the warning, instead of silently carrying forward a 
checksum for the wrong distribution.
   - `mvn -pl maven-wrapper-plugin test`: 8 tests, 0 failures. 
`checkstyle:check`: 0 violations.
   
   ---
   
   To make clear that you license your contribution under
   the [Apache License Version 2.0, January 
2004](https://www.apache.org/licenses/LICENSE-2.0)
   check one of the following:
   
   - [x] I hereby declare this contribution to be licensed under the [Apache 
License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
   - [x] I hereby declare that I have filed an [Apache Individual Contributor 
License Agreement](https://www.apache.org/licenses/icla.pdf).
   


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