Skip to content

Commit 63d8377

Browse files
committed
📝 Update Documentation with current version
1 parent 5590613 commit 63d8377

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/checksum/RemoteChecksumCalculator.java

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.net.http.HttpClient;
77
import java.net.http.HttpRequest;
88
import java.net.http.HttpResponse;
9-
import java.nio.file.Files;
109
import java.security.MessageDigest;
1110
import java.util.Locale;
1211
import java.util.Optional;
@@ -27,8 +26,12 @@ public RemoteChecksumCalculator(
2726
ProjectBuildingRequest artifactBuildingRequest,
2827
ProjectBuildingRequest pluginBuildingRequest) {
2928
super(checksumAlgorithm);
30-
if (!(checksumAlgorithm.equals("md5") || checksumAlgorithm.equals("sha1") || checksumAlgorithm.equals("sha256") || checksumAlgorithm.equals("sha512"))) {
31-
throw new IllegalArgumentException("Invalid checksum algorithm maven central only supports md5, sha1, sha256 or sha512.");
29+
if (!(checksumAlgorithm.equals("md5")
30+
|| checksumAlgorithm.equals("sha1")
31+
|| checksumAlgorithm.equals("sha256")
32+
|| checksumAlgorithm.equals("sha512"))) {
33+
throw new IllegalArgumentException(
34+
"Invalid checksum algorithm maven central only supports md5, sha1, sha256 or sha512.");
3235
}
3336

3437
this.artifactBuildingRequest = artifactBuildingRequest;
@@ -52,35 +55,45 @@ private Optional<String> calculateChecksumInternal(Artifact artifact, ProjectBui
5255
.build();
5356

5457
for (ArtifactRepository repository : buildingRequest.getRemoteRepositories()) {
55-
String artifactUrl = repository.getUrl().replaceAll("/$", "") + "/" + groupId + "/" + artifactId + "/" + version
56-
+ "/" + filename;
58+
String artifactUrl = repository.getUrl().replaceAll("/$", "") + "/" + groupId + "/" + artifactId + "/"
59+
+ version + "/" + filename;
5760
String checksumUrl = artifactUrl + "." + checksumAlgorithm;
5861

5962
LOGGER.debug("Checking: " + checksumUrl);
6063

6164
HttpRequest checksumRequest =
6265
HttpRequest.newBuilder().uri(URI.create(checksumUrl)).build();
63-
HttpResponse<String> checksumResponse = client.send(checksumRequest, HttpResponse.BodyHandlers.ofString());
66+
HttpResponse<String> checksumResponse =
67+
client.send(checksumRequest, HttpResponse.BodyHandlers.ofString());
6468

6569
if (checksumResponse.statusCode() >= 200 && checksumResponse.statusCode() < 300) {
6670
return Optional.of(checksumResponse.body().strip());
6771
}
6872

6973
if (checksumResponse.statusCode() == 404) {
70-
HttpRequest artifactRequest = HttpRequest.newBuilder().uri(URI.create(artifactUrl)).build();
71-
HttpResponse<byte[]> artifactResponse = client.send(artifactRequest, HttpResponse.BodyHandlers.ofByteArray());
74+
HttpRequest artifactRequest = HttpRequest.newBuilder()
75+
.uri(URI.create(artifactUrl))
76+
.build();
77+
HttpResponse<byte[]> artifactResponse =
78+
client.send(artifactRequest, HttpResponse.BodyHandlers.ofByteArray());
7279

7380
if (artifactResponse.statusCode() < 200 || artifactResponse.statusCode() >= 300) {
7481
continue;
7582
}
7683

7784
// Fallback to and verify downloaded artifact with sha1
78-
HttpRequest artifactVerificationRequest = HttpRequest.newBuilder().uri(URI.create(artifactUrl + ".sha1")).build();
79-
HttpResponse<String> artifactVerificationResponse = client.send(artifactVerificationRequest, HttpResponse.BodyHandlers.ofString());
80-
81-
if (artifactVerificationResponse.statusCode() >= 200 && artifactVerificationResponse.statusCode() < 300) {
85+
HttpRequest artifactVerificationRequest = HttpRequest.newBuilder()
86+
.uri(URI.create(artifactUrl + ".sha1"))
87+
.build();
88+
HttpResponse<String> artifactVerificationResponse =
89+
client.send(artifactVerificationRequest, HttpResponse.BodyHandlers.ofString());
90+
91+
if (artifactVerificationResponse.statusCode() >= 200
92+
&& artifactVerificationResponse.statusCode() < 300) {
8293
MessageDigest verificationMessageDigest = MessageDigest.getInstance("sha1");
83-
String sha1 = baseEncoding.encode(verificationMessageDigest.digest(artifactResponse.body())).toLowerCase(Locale.ROOT);
94+
String sha1 = baseEncoding
95+
.encode(verificationMessageDigest.digest(artifactResponse.body()))
96+
.toLowerCase(Locale.ROOT);
8497

8598
if (!sha1.equals(artifactVerificationResponse.body().strip())) {
8699
LOGGER.error("Invalid sha1 checksum for download of: " + artifactUrl);
@@ -91,7 +104,9 @@ private Optional<String> calculateChecksumInternal(Artifact artifact, ProjectBui
91104
}
92105

93106
MessageDigest messageDigest = MessageDigest.getInstance(checksumAlgorithm);
94-
String checksum = baseEncoding.encode(messageDigest.digest(artifactResponse.body())).toLowerCase(Locale.ROOT);
107+
String checksum = baseEncoding
108+
.encode(messageDigest.digest(artifactResponse.body()))
109+
.toLowerCase(Locale.ROOT);
95110
return Optional.of(checksum);
96111
}
97112
}

0 commit comments

Comments
 (0)