From b7b825009abdee9696e893353bd1f907ea101c88 Mon Sep 17 00:00:00 2001 From: Joe Morris Date: Wed, 29 Apr 2026 15:47:05 -0400 Subject: [PATCH 1/2] fix: normalize lockfiles for Windows Normalize line endings before calculating checksum. test code-quality on windows runner --- .github/workflows/code-qualitiy.yml | 2 +- .../checksum/AbstractChecksumCalculator.java | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/code-qualitiy.yml b/.github/workflows/code-qualitiy.yml index 30d9a32fb..48790af72 100644 --- a/.github/workflows/code-qualitiy.yml +++ b/.github/workflows/code-qualitiy.yml @@ -8,7 +8,7 @@ permissions: contents: read jobs: maven-quality: - runs-on: ubuntu-latest + runs-on: windows-latest steps: - name: Harden Runner diff --git a/maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/checksum/AbstractChecksumCalculator.java b/maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/checksum/AbstractChecksumCalculator.java index bc4d87ddb..db1be3bf6 100644 --- a/maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/checksum/AbstractChecksumCalculator.java +++ b/maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/checksum/AbstractChecksumCalculator.java @@ -8,6 +8,7 @@ import java.util.Collection; import java.util.Locale; import org.apache.maven.artifact.Artifact; +import java.nio.charset.StandardCharsets; public abstract class AbstractChecksumCalculator { @@ -49,8 +50,14 @@ public void prewarmArtifactCache(Collection artifacts) { public String calculatePomChecksum(Path path) { try { MessageDigest messageDigest = MessageDigest.getInstance(checksumAlgorithm); - byte[] fileBuffer = Files.readAllBytes(path); - byte[] artifactHash = messageDigest.digest(fileBuffer); + + //normalize line endings to prevent false-positives on checksum mismatch + byte[] normalizedBytes = Files.readString(path) + .replace("\r\n", "\n") + .replace("\r", "\n") + .getBytes(StandardCharsets.UTF_8); + + byte[] artifactHash = messageDigest.digest(normalizedBytes); BaseEncoding baseEncoding = BaseEncoding.base16(); return baseEncoding.encode(artifactHash).toLowerCase(Locale.ROOT); } catch (Exception e) { From ce494e38726762e77dd2f6b1be6bd35347ef9645 Mon Sep 17 00:00:00 2001 From: Joe Morris Date: Mon, 11 May 2026 12:28:50 -0400 Subject: [PATCH 2/2] fix: relative dir generation revert yml changes --- .github/workflows/code-qualitiy.yml | 2 +- .../maven_lockfile/LockFileFacade.java | 16 +++++++++++----- .../checksum/AbstractChecksumCalculator.java | 12 ++++++------ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.github/workflows/code-qualitiy.yml b/.github/workflows/code-qualitiy.yml index 48790af72..30d9a32fb 100644 --- a/.github/workflows/code-qualitiy.yml +++ b/.github/workflows/code-qualitiy.yml @@ -8,7 +8,7 @@ permissions: contents: read jobs: maven-quality: - runs-on: windows-latest + runs-on: ubuntu-latest steps: - name: Harden Runner diff --git a/maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/LockFileFacade.java b/maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/LockFileFacade.java index 689fa202e..0f592807b 100644 --- a/maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/LockFileFacade.java +++ b/maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/LockFileFacade.java @@ -12,6 +12,7 @@ import java.nio.file.Path; import java.util.*; import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.DefaultArtifactHandler; @@ -517,11 +518,16 @@ private static Pom constructRecursivePom( String relativePath = isExternalPom ? null - : initialProject - .getBasedir() - .toPath() - .relativize(project.getFile().toPath()) - .toString(); + : StreamSupport.stream( + initialProject + .getBasedir() + .toPath() + .relativize(project.getFile().toPath()) + .spliterator(), + false) + .map(Path::toString) + .collect(Collectors.joining("/")); + String checksum; ResolvedUrl resolved = null; RepositoryId repoId = null; diff --git a/maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/checksum/AbstractChecksumCalculator.java b/maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/checksum/AbstractChecksumCalculator.java index db1be3bf6..8f5a0720f 100644 --- a/maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/checksum/AbstractChecksumCalculator.java +++ b/maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/checksum/AbstractChecksumCalculator.java @@ -2,13 +2,13 @@ import com.google.common.io.BaseEncoding; import io.github.chains_project.maven_lockfile.reporting.PluginLogManager; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.security.MessageDigest; import java.util.Collection; import java.util.Locale; import org.apache.maven.artifact.Artifact; -import java.nio.charset.StandardCharsets; public abstract class AbstractChecksumCalculator { @@ -51,12 +51,12 @@ public String calculatePomChecksum(Path path) { try { MessageDigest messageDigest = MessageDigest.getInstance(checksumAlgorithm); - //normalize line endings to prevent false-positives on checksum mismatch + // normalize line endings to prevent false-positives on checksum mismatch byte[] normalizedBytes = Files.readString(path) - .replace("\r\n", "\n") - .replace("\r", "\n") - .getBytes(StandardCharsets.UTF_8); - + .replace("\r\n", "\n") + .replace("\r", "\n") + .getBytes(StandardCharsets.UTF_8); + byte[] artifactHash = messageDigest.digest(normalizedBytes); BaseEncoding baseEncoding = BaseEncoding.base16(); return baseEncoding.encode(artifactHash).toLowerCase(Locale.ROOT);