Skip to content

Commit

Permalink
fix: 🐛 Include leading zeros in checksums (#399)
Browse files Browse the repository at this point in the history
Co-authored-by: i-al-istannen <i-al-istannen@users.noreply.github.com>
Co-authored-by: SirYwell <hannesgreule@outlook.de>
  • Loading branch information
3 people authored Aug 31, 2023
1 parent 8b8d20d commit 5964e7a
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion github_action/lockfile.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"artifactID": "maven-lockfile-github-action",
"groupID": "io.github.chains-project",
"version": "4.1.1-SNAPSHOT",
"version": "4.2.1-SNAPSHOT",
"lockFileVersion": 1,
"dependencies": [
{
Expand Down
2 changes: 1 addition & 1 deletion lockfile.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"artifactID": "maven-lockfile-parent",
"groupID": "io.github.chains-project",
"version": "4.1.1-SNAPSHOT",
"version": "4.2.1-SNAPSHOT",
"lockFileVersion": 1,
"dependencies": [],
"mavenPlugins": [
Expand Down
2 changes: 1 addition & 1 deletion maven_plugin/lockfile.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"artifactID": "maven-lockfile",
"groupID": "io.github.chains-project",
"version": "4.1.1-SNAPSHOT",
"version": "4.2.1-SNAPSHOT",
"lockFileVersion": 1,
"dependencies": [
{
Expand Down
1 change: 0 additions & 1 deletion maven_plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,4 @@
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public void execute() throws MojoExecutionException {
sb.append("Lock file validation failed. Differences:");
sb.append("\n");
sb.append("Your lockfile from file is for:"

Check warning on line 57 in maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/ValidateChecksumMojo.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

String concatenation as argument to 'StringBuilder.append()' call

String concatenation as argument to `StringBuilder.append()` call
+ lockFileFromFile.getGroupId().getValue() + ":"
+ lockFileFromFile.getName().getValue() + ":"
+ lockFileFromFile.getGroupId().getValue()
+ ":" + lockFileFromFile.getName().getValue() + ":"
+ lockFileFromFile.getVersion().getValue() + "\n");
sb.append("Your generated lockfile is for:"

Check warning on line 61 in maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/ValidateChecksumMojo.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

String concatenation as argument to 'StringBuilder.append()' call

String concatenation as argument to `StringBuilder.append()` call
+ lockFileFromProject.getGroupId().getValue() + ":"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package io.github.chains_project.maven_lockfile.checksum;

import java.math.BigInteger;
import com.google.common.io.BaseEncoding;
import java.nio.file.Files;
import java.security.MessageDigest;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import org.apache.log4j.Logger;
import org.apache.maven.artifact.Artifact;
Expand Down Expand Up @@ -63,7 +64,8 @@ private Optional<String> calculateChecksumInternal(Artifact artifact) {
MessageDigest messageDigest = MessageDigest.getInstance(checksumAlgorithm);
byte[] fileBuffer = Files.readAllBytes(artifact.getFile().toPath());
byte[] artifactHash = messageDigest.digest(fileBuffer);
return Optional.of(new BigInteger(1, artifactHash).toString(16));
BaseEncoding baseEncoding = BaseEncoding.base16();
return Optional.of(baseEncoding.encode(artifactHash).toLowerCase(Locale.ROOT));
} catch (Exception e) {
LOGGER.warn("Could not calculate checksum for artifact " + artifact, e);
return Optional.empty();
Expand Down

0 comments on commit 5964e7a

Please sign in to comment.