Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only fetch checksums for final gradle releases during build #2917

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 12 additions & 30 deletions org.eclipse.jdt.ls.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
import groovy.json.JsonOutput

import java.net.http.HttpClient
import java.net.http.HttpClient.Redirect
import java.net.http.HttpRequest
import java.net.http.HttpResponse.BodyHandlers
import java.util.concurrent.CompletableFuture
import java.util.stream.Collectors;


def checksumsFile = new File(project.basedir.absolutePath, "gradle/checksums/checksums.json")
if (System.getProperty("eclipse.jdt.ls.skipGradleChecksums") != null && checksumsFile.exists()) {
println "Skipping gradle wrapper validation checksums ..."
Expand All @@ -77,42 +77,24 @@
String wrapperChecksumUrl;
String sha256
}
HttpClient client = HttpClient.newHttpClient()

HttpClient client = HttpClient.newBuilder()
.followRedirects(Redirect.NORMAL)
.build();
def futures = []
versions.each {
if (it.wrapperChecksumUrl == null) {
if (it.wrapperChecksumUrl == null || it.nightly || it.snapshot || it.rcFor != "" || it.broken) {
return
}
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(it.wrapperChecksumUrl)).build()
futures.add(client.sendAsync(request, BodyHandlers.ofString()).thenApply { response ->
if (response.statusCode() == 301) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you eliminating redirection support because none of the links currently require it ? Wouldn't it be good to have this just in case ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The client does that implicitly if configured to:

HttpClient client = HttpClient.newBuilder()
	.followRedirects(Redirect.NORMAL)
	.build();

String newUrl = response.headers().firstValue("location").orElse(null)
if (newUrl != null) {
HttpRequest newRequest = HttpRequest.newBuilder()
.uri(URI.create(newUrl))
.build()
try {
String sha256 = client.send(newRequest, BodyHandlers.ofString()).body()
return new Checksum(wrapperChecksumUrl: it.wrapperChecksumUrl, sha256: sha256)
} catch (IOException | InterruptedException e) {
return null
}
} else {
return null
}
} else {
// Return the body of the original response
return new Checksum(wrapperChecksumUrl: it.wrapperChecksumUrl, sha256: response.body())
}
})
future = client.sendAsync(request, BodyHandlers.ofString()).thenApply { response ->
return new Checksum(wrapperChecksumUrl: it.wrapperChecksumUrl, sha256: response.body())
}
futures.add(future)
}

def checksums = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]))
.thenApply { v ->
futures.stream().map({ f ->
f.join()
}).collect(Collectors.toList())
}.get()
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get()
def checksums = futures.stream().map({ f -> f.join() }).collect(Collectors.toList())

def json = JsonOutput.toJson(checksums)
checksumsFile.write(JsonOutput.prettyPrint(json))
Expand Down