Skip to content

Commit 61d275e

Browse files
authored
Merge pull request #42 from frengor/gradle-checksum
Improve `checksum` methods
2 parents 0e1df99 + 4b73444 commit 61d275e

File tree

8 files changed

+25
-19
lines changed

8 files changed

+25
-19
lines changed

core/src/main/java/com/alessiodp/libby/Library.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -528,25 +528,25 @@ public Builder checksum(byte @Nullable [] checksum) {
528528
}
529529

530530
/**
531-
* Sets the Base64 hexadecimal bytes encoded SHA-256 checksum for this library.
531+
* Sets the SHA-256 checksum for this library.
532532
*
533-
* @param checksum Base64 binary encoded SHA-256 checksum
533+
* @param checksum SHA-256 checksum
534534
* @return this builder
535535
*/
536536
@NotNull
537537
public Builder checksum(@Nullable String checksum) {
538-
return checksum != null ? checksum(Base64.getDecoder().decode(checksum)) : this;
538+
return checksum != null ? checksum(hexStringToByteArray(checksum)) : this;
539539
}
540540

541541
/**
542-
* Sets the SHA-256 checksum for this library.
542+
* Sets the Base64 hexadecimal bytes encoded SHA-256 checksum for this library.
543543
*
544-
* @param checksum SHA-256 checksum
544+
* @param checksum Base64 binary encoded SHA-256 checksum
545545
* @return this builder
546546
*/
547547
@NotNull
548-
public Builder checksumFromSha256(@Nullable String checksum) {
549-
return checksum != null ? checksum(hexStringToByteArray(checksum)) : this;
548+
public Builder checksumFromBase64(@Nullable String checksum) {
549+
return checksum != null ? checksum(Base64.getDecoder().decode(checksum)) : this;
550550
}
551551

552552
/**

core/src/main/java/com/alessiodp/libby/classloader/ClassLoaderHelper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ protected Instrumentation initInstrumentation(LibraryManager libraryManager) thr
303303
.groupId("net{}bytebuddy")
304304
.artifactId("byte-buddy-agent")
305305
.version("1.12.1")
306-
.checksum("mcCtBT9cljUEniB5ESpPDYZMfVxEs1JRPllOiWTP+bM=")
306+
.checksumFromBase64("mcCtBT9cljUEniB5ESpPDYZMfVxEs1JRPllOiWTP+bM=")
307307
.repository(Repositories.MAVEN_CENTRAL)
308308
.build()
309309
));

core/src/main/java/com/alessiodp/libby/configuration/ConfigurationFetcher.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public ConfigurationFetcher(@NotNull LibraryManager libraryManager) {
104104
.groupId("com{}grack")
105105
.artifactId("nanojson")
106106
.version("1.8")
107-
.checksum("qyhAVZM8LYvqhGQrbmW2aHV4hRzn+2flPCV98wAimJo=")
107+
.checksumFromBase64("qyhAVZM8LYvqhGQrbmW2aHV4hRzn+2flPCV98wAimJo=")
108108
.repository(Repositories.MAVEN_CENTRAL)
109109
.build()
110110
));
@@ -343,7 +343,8 @@ private Set<ExcludedDependency> fetchExcludedTransitiveDependencies(@NotNull Map
343343
* </ul>
344344
* Optional properties:
345345
* <ul>
346-
* <li>checksum: The SHA-256 checksum of the library, must be a base64 encoded string and may only be included if the library is a JAR</li>
346+
* <li>checksum: The SHA-256 checksum of the library, may only be included if the library is a JAR</li>
347+
* <li>checksumFromBase64: The SHA-256 checksum of the library, must be a base64 encoded string and may only be included if the library is a JAR</li>
347348
* <li>classifier: The artifact classifier of the library</li>
348349
* <li>isolatedLoad: Whether to load this library in an IsolatedClassLoader</li>
349350
* <li>loaderId: The loader ID of this library</li>
@@ -399,8 +400,14 @@ private List<Library> fetchLibraries(@NotNull Map<String, Object> configuration,
399400
String checksum = getString(library, "checksum");
400401

401402
if (checksum != null) {
403+
libraryBuilder.checksum(checksum);
404+
}
405+
406+
String checksumFromBase64 = getString(library, "checksumFromBase64");
407+
408+
if (checksumFromBase64 != null) {
402409
try {
403-
libraryBuilder.checksum(checksum);
410+
libraryBuilder.checksumFromBase64(checksumFromBase64);
404411
} catch (IllegalArgumentException ignored) {
405412
throw new ConfigurationException("The checksum property must be a valid base64 encoded SHA-256 checksum");
406413
}

core/src/main/java/com/alessiodp/libby/relocation/RelocationHelper.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public RelocationHelper(@NotNull LibraryManager libraryManager) {
6666
.groupId("org{}ow2{}asm")
6767
.artifactId("asm-commons")
6868
.version("9.2")
69-
.checksum("vkzlMTiiOLtSLNeBz5Hzulzi9sqT7GLUahYqEnIl4KY=")
69+
.checksumFromBase64("vkzlMTiiOLtSLNeBz5Hzulzi9sqT7GLUahYqEnIl4KY=")
7070
.repository(Repositories.MAVEN_CENTRAL)
7171
.build()
7272
));
@@ -77,7 +77,7 @@ public RelocationHelper(@NotNull LibraryManager libraryManager) {
7777
.groupId("org{}ow2{}asm")
7878
.artifactId("asm")
7979
.version("9.2")
80-
.checksum("udT+TXGTjfOIOfDspCqqpkz4sxPWeNoDbwyzyhmbR/U=")
80+
.checksumFromBase64("udT+TXGTjfOIOfDspCqqpkz4sxPWeNoDbwyzyhmbR/U=")
8181
.repository(Repositories.MAVEN_CENTRAL)
8282
.build()
8383
));
@@ -88,7 +88,7 @@ public RelocationHelper(@NotNull LibraryManager libraryManager) {
8888
.groupId("me{}lucko")
8989
.artifactId("jar-relocator")
9090
.version("1.7")
91-
.checksum("b30RhOF6kHiHl+O5suNLh/+eAr1iOFEFLXhwkHHDu4I=")
91+
.checksumFromBase64("b30RhOF6kHiHl+O5suNLh/+eAr1iOFEFLXhwkHHDu4I=")
9292
.repository(Repositories.MAVEN_CENTRAL)
9393
.build()
9494
));

core/src/main/java/com/alessiodp/libby/transitive/TransitiveLibraryResolutionDependency.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public Library toLibrary() {
5151
.groupId(groupId)
5252
.artifactId(artifactId)
5353
.version(version)
54-
.checksum(checksum)
54+
.checksumFromBase64(checksum)
5555
.repository(Repositories.MAVEN_CENTRAL)
5656
// Relocate all packages used in Libby to avoid conflicts
5757
.relocate("org{}eclipse{}aether{}util", "org.eclipse.aether.util") // maven-resolver-util

core/src/test/java/com/alessiodp/libby/ConfigurationFetcherTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public class ConfigurationFetcherTest {
2626
private LibraryManagerMock libraryManager;
2727
private ConfigurationFetcher configurationFetcher;
2828

29-
3029
@BeforeEach
3130
public void setUp() throws Exception {
3231
libraryManager = new LibraryManagerMock();
@@ -123,7 +122,7 @@ public void testFails() {
123122
assertTrue(ex.getMessage().contains("version property"));
124123

125124
// Invalid checksum
126-
ex = assertThrows(ConfigurationException.class, () -> parseAndRead("{\"libraries\":[{\"groupId\":\"\",\"artifactId\":\"\",\"version\":\"\",\"checksum\":\"invalid-checksum\"}]}"));
125+
ex = assertThrows(ConfigurationException.class, () -> parseAndRead("{\"libraries\":[{\"groupId\":\"\",\"artifactId\":\"\",\"version\":\"\",\"checksumFromBase64\":\"invalid-checksum\"}]}"));
127126
assertTrue(ex.getMessage().contains("valid base64"));
128127
}
129128

core/src/test/java/com/alessiodp/libby/TestUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class TestUtils {
2222
.groupId("org{}apache{}commons")
2323
.artifactId("commons-lang3")
2424
.version("3.13.0")
25-
.checksum("gvUoz3GMejwvMPxbx4TjxqChCxdgXa254WyC7eEeYGQ=")
25+
.checksumFromBase64("gvUoz3GMejwvMPxbx4TjxqChCxdgXa254WyC7eEeYGQ=")
2626
.build();
2727
public static final Library APACHE_COMMONS_LANG3_ISOLATED = Library.builder()
2828
.groupId(APACHE_COMMONS_LANG3.getGroupId())

standalone/src/test/java/com/alessiodp/libby/TestUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ public class TestUtils {
88
.groupId("org{}apache{}commons")
99
.artifactId("commons-lang3")
1010
.version("3.13.0")
11-
.checksum("gvUoz3GMejwvMPxbx4TjxqChCxdgXa254WyC7eEeYGQ=")
11+
.checksumFromBase64("gvUoz3GMejwvMPxbx4TjxqChCxdgXa254WyC7eEeYGQ=")
1212
.build();
1313
}

0 commit comments

Comments
 (0)