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 2022/06/24 08:45:56 UTC

[maven-resolver] branch MRESOLVER-265-checksum-of-checksum created (now a9e87f7d)

This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a change to branch MRESOLVER-265-checksum-of-checksum
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git


      at a9e87f7d [MRESOLVER-265] Checksum of checksum

This branch includes the following new commits:

     new a9e87f7d [MRESOLVER-265] Checksum of checksum

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-resolver] 01/01: [MRESOLVER-265] Checksum of checksum

Posted by cs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a commit to branch MRESOLVER-265-checksum-of-checksum
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git

commit a9e87f7d630f6b1dfec324c202fa7e5eff276c42
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Fri Jun 24 10:44:31 2022 +0200

    [MRESOLVER-265] Checksum of checksum
    
    There is a discrepancy when a checksum is attached (so not added
    by resolver itself), and resolver will checksum it if the algorithm
    is not configured (ie. default config used but SHA512 added).
    
    This makes it work as expected, as checksum recognition works
    now against ALL SUPPORTED and not configured ONLY checksums).
---
 .../internal/impl/Maven2RepositoryLayoutFactory.java   | 18 +++++++++++-------
 .../impl/Maven2RepositoryLayoutFactoryTest.java        | 11 +++++++++++
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/Maven2RepositoryLayoutFactory.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/Maven2RepositoryLayoutFactory.java
index 30c3e8ad..1b76940e 100644
--- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/Maven2RepositoryLayoutFactory.java
+++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/Maven2RepositoryLayoutFactory.java
@@ -142,6 +142,7 @@ public final class Maven2RepositoryLayoutFactory
         }
 
         return new Maven2RepositoryLayout(
+                new ArrayList<>( checksumAlgorithmFactorySelector.getChecksumAlgorithmFactories() ),
                 checksumsAlgorithms,
                 omitChecksumsForExtensions
         );
@@ -150,15 +151,18 @@ public final class Maven2RepositoryLayoutFactory
     private static class Maven2RepositoryLayout
             implements RepositoryLayout
     {
+        private final List<ChecksumAlgorithmFactory> allChecksumAlgorithms;
 
-        private final List<ChecksumAlgorithmFactory> checksumAlgorithms;
+        private final List<ChecksumAlgorithmFactory> configuredChecksumAlgorithms;
 
         private final Set<String> extensionsWithoutChecksums;
 
-        private Maven2RepositoryLayout( List<ChecksumAlgorithmFactory> checksumAlgorithms,
+        private Maven2RepositoryLayout( List<ChecksumAlgorithmFactory> allChecksumAlgorithms,
+                                        List<ChecksumAlgorithmFactory> configuredChecksumAlgorithms,
                                         Set<String> extensionsWithoutChecksums )
         {
-            this.checksumAlgorithms = Collections.unmodifiableList( checksumAlgorithms );
+            this.allChecksumAlgorithms = Collections.unmodifiableList( allChecksumAlgorithms );
+            this.configuredChecksumAlgorithms = Collections.unmodifiableList( configuredChecksumAlgorithms );
             this.extensionsWithoutChecksums = requireNonNull( extensionsWithoutChecksums );
         }
 
@@ -177,7 +181,7 @@ public final class Maven2RepositoryLayoutFactory
         @Override
         public List<ChecksumAlgorithmFactory> getChecksumAlgorithmFactories()
         {
-            return checksumAlgorithms;
+            return configuredChecksumAlgorithms;
         }
 
         @Override
@@ -263,8 +267,8 @@ public final class Maven2RepositoryLayoutFactory
 
         private List<ChecksumLocation> getChecksumLocations( URI location )
         {
-            List<ChecksumLocation> checksumLocations = new ArrayList<>( checksumAlgorithms.size() );
-            for ( ChecksumAlgorithmFactory checksumAlgorithmFactory : checksumAlgorithms )
+            List<ChecksumLocation> checksumLocations = new ArrayList<>( configuredChecksumAlgorithms.size() );
+            for ( ChecksumAlgorithmFactory checksumAlgorithmFactory : configuredChecksumAlgorithms )
             {
                 checksumLocations.add( ChecksumLocation.forLocation( location, checksumAlgorithmFactory ) );
             }
@@ -273,7 +277,7 @@ public final class Maven2RepositoryLayoutFactory
 
         private boolean isChecksum( String extension )
         {
-            return checksumAlgorithms.stream().anyMatch( a -> extension.endsWith( "." + a.getFileExtension() ) );
+            return allChecksumAlgorithms.stream().anyMatch( a -> extension.endsWith( "." + a.getFileExtension() ) );
         }
     }
 }
diff --git a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/Maven2RepositoryLayoutFactoryTest.java b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/Maven2RepositoryLayoutFactoryTest.java
index 0fc7a293..7b7fecf0 100644
--- a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/Maven2RepositoryLayoutFactoryTest.java
+++ b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/Maven2RepositoryLayoutFactoryTest.java
@@ -331,6 +331,17 @@ public class Maven2RepositoryLayoutFactoryTest
         assertEquals( 0, checksums.size() );
     }
 
+    @Test
+    public void testNotConfiguredButSupportedChecksumsHandledAsChecksums()
+            throws Exception
+    {
+        layout = factory.newInstance( session, newRepo( "default" ) );
+        DefaultArtifact artifact = new DefaultArtifact( "g.i.d", "a-i.d", "cls", "jar.sha512", "1.0" );
+        URI uri = layout.getLocation( artifact, true );
+        List<ChecksumLocation> checksums = layout.getChecksumLocations( artifact, true, uri );
+        assertEquals( 0, checksums.size() );
+    }
+
     @Test
     public void testCustomChecksumsIgnored_IllegalInout()
             throws Exception