|
52 | 52 | import groovy.json.JsonOutput
|
53 | 53 |
|
54 | 54 | import java.net.http.HttpClient
|
| 55 | + import java.net.http.HttpClient.Redirect |
55 | 56 | import java.net.http.HttpRequest
|
56 | 57 | import java.net.http.HttpResponse.BodyHandlers
|
57 | 58 | import java.util.concurrent.CompletableFuture
|
58 | 59 | import java.util.stream.Collectors;
|
59 | 60 |
|
60 |
| -
|
61 | 61 | def checksumsFile = new File(project.basedir.absolutePath, "gradle/checksums/checksums.json")
|
62 | 62 | if (System.getProperty("eclipse.jdt.ls.skipGradleChecksums") != null && checksumsFile.exists()) {
|
63 | 63 | println "Skipping gradle wrapper validation checksums ..."
|
|
77 | 77 | String wrapperChecksumUrl;
|
78 | 78 | String sha256
|
79 | 79 | }
|
80 |
| - HttpClient client = HttpClient.newHttpClient() |
| 80 | +
|
| 81 | + HttpClient client = HttpClient.newBuilder() |
| 82 | + .followRedirects(Redirect.NORMAL) |
| 83 | + .build(); |
81 | 84 | def futures = []
|
82 | 85 | versions.each {
|
83 |
| - if (it.wrapperChecksumUrl == null) { |
| 86 | + if (it.wrapperChecksumUrl == null || it.nightly || it.snapshot || it.rcFor != "" || it.broken) { |
84 | 87 | return
|
85 | 88 | }
|
86 | 89 | HttpRequest request = HttpRequest.newBuilder().uri(URI.create(it.wrapperChecksumUrl)).build()
|
87 |
| - futures.add(client.sendAsync(request, BodyHandlers.ofString()).thenApply { response -> |
88 |
| - if (response.statusCode() == 301) { |
89 |
| - String newUrl = response.headers().firstValue("location").orElse(null) |
90 |
| - if (newUrl != null) { |
91 |
| - HttpRequest newRequest = HttpRequest.newBuilder() |
92 |
| - .uri(URI.create(newUrl)) |
93 |
| - .build() |
94 |
| - try { |
95 |
| - String sha256 = client.send(newRequest, BodyHandlers.ofString()).body() |
96 |
| - return new Checksum(wrapperChecksumUrl: it.wrapperChecksumUrl, sha256: sha256) |
97 |
| - } catch (IOException | InterruptedException e) { |
98 |
| - return null |
99 |
| - } |
100 |
| - } else { |
101 |
| - return null |
102 |
| - } |
103 |
| - } else { |
104 |
| - // Return the body of the original response |
105 |
| - return new Checksum(wrapperChecksumUrl: it.wrapperChecksumUrl, sha256: response.body()) |
106 |
| - } |
107 |
| - }) |
| 90 | + future = client.sendAsync(request, BodyHandlers.ofString()).thenApply { response -> |
| 91 | + return new Checksum(wrapperChecksumUrl: it.wrapperChecksumUrl, sha256: response.body()) |
| 92 | + } |
| 93 | + futures.add(future) |
108 | 94 | }
|
109 | 95 |
|
110 |
| - def checksums = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])) |
111 |
| - .thenApply { v -> |
112 |
| - futures.stream().map({ f -> |
113 |
| - f.join() |
114 |
| - }).collect(Collectors.toList()) |
115 |
| - }.get() |
| 96 | + CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get() |
| 97 | + def checksums = futures.stream().map({ f -> f.join() }).collect(Collectors.toList()) |
116 | 98 |
|
117 | 99 | def json = JsonOutput.toJson(checksums)
|
118 | 100 | checksumsFile.write(JsonOutput.prettyPrint(json))
|
|
0 commit comments