You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2024/01/15 11:13:03 UTC
(maven-resolver) branch master updated: [MRESOLVER-463] sort checksum summary file per path and not checksum to be human friendly (#404)
This is an automated email from the ASF dual-hosted git repository.
cstamas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git
The following commit(s) were added to refs/heads/master by this push:
new 821c512c [MRESOLVER-463] sort checksum summary file per path and not checksum to be human friendly (#404)
821c512c is described below
commit 821c512c2a3f401907996a6acbedc2b91522c7b2
Author: Romain Manni-Bucau <rm...@gmail.com>
AuthorDate: Mon Jan 15 12:12:57 2024 +0100
[MRESOLVER-463] sort checksum summary file per path and not checksum to be human friendly (#404)
---
.../SummaryFileTrustedChecksumsSource.java | 2 +-
.../SummaryFileTrustedChecksumsSourceTest.java | 58 ++++++++++++++++++++++
2 files changed, 59 insertions(+), 1 deletion(-)
diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/checksum/SummaryFileTrustedChecksumsSource.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/checksum/SummaryFileTrustedChecksumsSource.java
index a31c0894..35000710 100644
--- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/checksum/SummaryFileTrustedChecksumsSource.java
+++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/checksum/SummaryFileTrustedChecksumsSource.java
@@ -315,7 +315,7 @@ public final class SummaryFileTrustedChecksumsSource extends FileTrustedChecksum
p -> Files.write(
p,
result.entrySet().stream()
- .sorted(Map.Entry.comparingByValue())
+ .sorted(Map.Entry.comparingByKey())
.map(e -> e.getValue() + " " + e.getKey())
.collect(toList())));
} catch (IOException e) {
diff --git a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/checksum/SummaryFileTrustedChecksumsSourceTest.java b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/checksum/SummaryFileTrustedChecksumsSourceTest.java
index 403f1cb9..ecc09c82 100644
--- a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/checksum/SummaryFileTrustedChecksumsSourceTest.java
+++ b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/checksum/SummaryFileTrustedChecksumsSourceTest.java
@@ -18,9 +18,26 @@
*/
package org.eclipse.aether.internal.impl.checksum;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.impl.RepositorySystemLifecycle;
import org.eclipse.aether.internal.impl.DefaultLocalPathComposer;
+import org.eclipse.aether.internal.impl.DefaultRepositorySystemLifecycle;
+import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
+import org.eclipse.aether.repository.LocalRepository;
+import org.eclipse.aether.repository.NoLocalRepositoryManagerException;
+import org.eclipse.aether.spi.checksums.TrustedChecksumsSource;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static java.util.Arrays.asList;
+import static java.util.Collections.singletonList;
+import static java.util.Collections.singletonMap;
+import static org.junit.jupiter.api.Assertions.assertLinesMatch;
public class SummaryFileTrustedChecksumsSourceTest extends FileTrustedChecksumsSourceTestSupport {
@Override
@@ -32,4 +49,45 @@ public class SummaryFileTrustedChecksumsSourceTest extends FileTrustedChecksumsS
protected void enableSource(DefaultRepositorySystemSession session) {
session.setConfigProperty("aether.trustedChecksumsSource.summaryFile", Boolean.TRUE.toString());
}
+
+ @Test
+ void ensureOrderIsHumanFriendly(@TempDir final Path work) throws NoLocalRepositoryManagerException, IOException {
+ final RepositorySystemLifecycle lifecycle = new DefaultRepositorySystemLifecycle();
+ final FileTrustedChecksumsSourceSupport src = prepareSubject(lifecycle);
+ final DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(h -> false);
+ final LocalRepository repository = new LocalRepository(work.toFile(), "simple");
+ session.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(session, repository));
+
+ final Sha1ChecksumAlgorithmFactory algorithmFactory = new Sha1ChecksumAlgorithmFactory();
+ final TrustedChecksumsSource.Writer appender = src.doGetTrustedArtifactChecksumsWriter(session);
+
+ // we ensure if we sort by checksum we keep the "add" order
+ // to avoid false positives but we'll sort by paths so not keep it
+ appender.addTrustedArtifactChecksums(
+ new DefaultArtifact("org.foo", "bar", "jar", "1.2.3"),
+ repository,
+ singletonList(algorithmFactory),
+ singletonMap("SHA-1", "000"));
+ appender.addTrustedArtifactChecksums(
+ new DefaultArtifact("com.dummy", "something", "jar", "0.0.1"),
+ repository,
+ singletonList(algorithmFactory),
+ singletonMap("SHA-1", "111"));
+ appender.addTrustedArtifactChecksums(
+ new DefaultArtifact("org.zzzz", "art", "jar", "5.6.7"),
+ repository,
+ singletonList(algorithmFactory),
+ singletonMap("SHA-1", "222"));
+
+ // generate the dump
+ lifecycle.systemEnded();
+
+ // ensure it is sorted by artifact "path"
+ assertLinesMatch(
+ asList(
+ "111 com/dummy/something/0.0.1/something-0.0.1.jar",
+ "000 org/foo/bar/1.2.3/bar-1.2.3.jar",
+ "222 org/zzzz/art/5.6.7/art-5.6.7.jar"),
+ Files.readAllLines(work.resolve(".checksums/checksums-local.sha1")));
+ }
}