dsmiley commented on code in PR #16521:
URL: https://github.com/apache/lucene/pull/16521#discussion_r3816605179
##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/WrapperDownloader.java:
##########
@@ -81,70 +78,19 @@ public static void checkVersion() {
}
public void run(Path destination) throws IOException,
NoSuchAlgorithmException {
- var expectedFileName = destination.getFileName().toString();
- Path checksumPath = destination.resolveSibling(expectedFileName +
".sha256");
- if (!Files.exists(checksumPath)) {
- throw new IOException("Checksum file not found: " + checksumPath);
- }
-
- String expectedChecksum;
- try (var lines = Files.lines(checksumPath, StandardCharsets.UTF_8)) {
- expectedChecksum =
- lines
- .map(
- line -> {
- // "The default mode is to print a line with: checksum, a
space,
- // a character indicating input mode ('*' for binary, ' '
for text
- // or where binary is insignificant), and name for each
FILE."
- var spaceIndex = line.indexOf(" ");
- if (spaceIndex != -1 && spaceIndex + 2 < line.length()) {
- var mode = line.charAt(spaceIndex + 1);
- String fileName = line.substring(spaceIndex + 2);
- if (mode == '*' && fileName.equals(expectedFileName)) {
- return line.substring(0, spaceIndex);
- }
- }
-
- Logger.getLogger(WrapperDownloader.class.getName())
- .warning(
- "Something is wrong with the checksum file.
Regenerate with "
- + "'sha256sum -b gradle-wrapper.jar >
gradle-wrapper.jar.sha256'");
- return null;
- })
- .filter(Objects::nonNull)
- .findFirst()
- .orElse(null);
-
- if (expectedChecksum == null) {
- throw new IOException(
- "The checksum file did not contain the expected checksum for '"
- + expectedFileName
- + "'?");
- }
- }
-
Path wrapperProperties =
destination.resolveSibling(
destination.getFileName().toString().replace(".jar",
".properties"));
if (!Files.exists(wrapperProperties)) {
throw new IOException("Wrapper property file not found: " +
wrapperProperties);
}
- Pattern versionPattern = Pattern.compile("gradle-(?<version>.+?)-bin.zip");
Review Comment:
The regexp is used with matcher.find(), which returns the LEFTMOST match.
The non-greedy
`.+?` doesn't save you here, because `.` also matches `/` -- so the
capture happily runs across path separators.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]