Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand Down Expand Up @@ -49,8 +50,14 @@ public void prewarmArtifactCache(Collection<Artifact> 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) {
Expand Down
Loading