You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2020/06/13 16:07:39 UTC

[maven-resolver] branch MRESOLVER-115 updated (5a31cf5 -> d68c614)

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

michaelo pushed a change to branch MRESOLVER-115
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git.


 discard 5a31cf5  [MRESOLVER-115] Make checksum algorithms configurable
     new d68c614  [MRESOLVER-115] Make checksum algorithms configurable

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (5a31cf5)
            \
             N -- N -- N   refs/heads/MRESOLVER-115 (d68c614)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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.


Summary of changes:
 .../aether/internal/impl/Maven2RepositoryLayoutFactory.java        | 7 +++----
 .../aether/internal/impl/Maven2RepositoryLayoutFactoryTest.java    | 4 ++--
 2 files changed, 5 insertions(+), 6 deletions(-)


[maven-resolver] 01/01: [MRESOLVER-115] Make checksum algorithms configurable

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

michaelo pushed a commit to branch MRESOLVER-115
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git

commit d68c614bea0fe97dd36a77c10f7d3fcf7dfaef30
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Wed Jun 10 16:24:50 2020 +0200

    [MRESOLVER-115] Make checksum algorithms configurable
    
    This closes #53
---
 .../impl/Maven2RepositoryLayoutFactory.java        | 33 +++++++++++++++++-----
 .../impl/Maven2RepositoryLayoutFactoryTest.java    | 27 ++++++++++++++++++
 2 files changed, 53 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 d8dff28..7dd4e0b 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
@@ -23,6 +23,7 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.LinkedList;
 import java.util.List;
 
 import javax.inject.Named;
@@ -45,6 +46,9 @@ public final class Maven2RepositoryLayoutFactory
 {
 
     static final String CONFIG_PROP_SIGNATURE_CHECKSUMS = "aether.checksums.forSignature";
+    static final String CONFIG_PROP_CHECKSUMS_ALGORITHMS = "aether.checksums.algorithms";
+
+    static final String DEFAULT_CHECKSUMS_ALGORITHMS = "SHA-512,SHA-256,SHA-1,MD5";
 
     private float priority;
 
@@ -73,14 +77,24 @@ public final class Maven2RepositoryLayoutFactory
             throw new NoRepositoryLayoutException( repository );
         }
         boolean forSignature = ConfigUtils.getBoolean( session, false, CONFIG_PROP_SIGNATURE_CHECKSUMS );
-        return forSignature ? Maven2RepositoryLayout.INSTANCE : Maven2RepositoryLayoutEx.INSTANCE;
+        List<String> checksumsAlgorithms = Arrays.asList( ConfigUtils.getString( session,
+                DEFAULT_CHECKSUMS_ALGORITHMS, CONFIG_PROP_CHECKSUMS_ALGORITHMS ).split( "," ) );
+
+        return forSignature
+                ? new Maven2RepositoryLayout( checksumsAlgorithms )
+                : new Maven2RepositoryLayoutEx( checksumsAlgorithms );
     }
 
     private static class Maven2RepositoryLayout
         implements RepositoryLayout
     {
 
-        public static final RepositoryLayout INSTANCE = new Maven2RepositoryLayout();
+        private final List<String> checksumsAlgorithms;
+
+        protected Maven2RepositoryLayout( List<String> checksumsAlgorithms )
+        {
+            this.checksumsAlgorithms = checksumsAlgorithms;
+        }
 
         private URI toUri( String path )
         {
@@ -155,10 +169,12 @@ public final class Maven2RepositoryLayoutFactory
 
         private List<Checksum> getChecksums( URI location )
         {
-            return Arrays.asList( Checksum.forLocation( location, "SHA-512" ),
-                                  Checksum.forLocation( location, "SHA-256" ),
-                                  Checksum.forLocation( location, "SHA-1" ),
-                                  Checksum.forLocation( location, "MD5" ) );
+            List<Checksum> checksums = new LinkedList<>();
+            for ( String algorithm : checksumsAlgorithms )
+            {
+                checksums.add( Checksum.forLocation( location, algorithm ) );
+            }
+            return checksums;
         }
 
     }
@@ -167,7 +183,10 @@ public final class Maven2RepositoryLayoutFactory
         extends Maven2RepositoryLayout
     {
 
-        public static final RepositoryLayout INSTANCE = new Maven2RepositoryLayoutEx();
+        protected Maven2RepositoryLayoutEx( List<String> checksumsAlgorithms )
+        {
+            super( checksumsAlgorithms );
+        }
 
         @Override
         public List<Checksum> getChecksums( Artifact artifact, boolean upload, URI location )
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 4d14cb0..bbf67cd 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
@@ -22,6 +22,7 @@ package org.eclipse.aether.internal.impl;
 import static org.junit.Assert.*;
 
 import java.net.URI;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Locale;
 
@@ -162,6 +163,19 @@ public class Maven2RepositoryLayoutFactoryTest
     }
 
     @Test
+    public void testArtifactChecksums_DownloadWithCustomAlgorithms() throws NoRepositoryLayoutException
+    {
+        session.setConfigProperty( Maven2RepositoryLayoutFactory.CONFIG_PROP_CHECKSUMS_ALGORITHMS, "SHA-256,SHA-1");
+        layout = factory.newInstance( session, newRepo( "default" ) );
+        DefaultArtifact artifact = new DefaultArtifact( "g.i.d", "a-i.d", "cls", "ext", "1.0" );
+        URI uri = layout.getLocation( artifact, false );
+        List<Checksum> checksums = layout.getChecksums( artifact, false, uri );
+        assertEquals( 2, checksums.size() );
+        assertChecksum( checksums.get( 0 ), "g/i/d/a-i.d/1.0/a-i.d-1.0-cls.ext.sha256", "SHA-256" );
+        assertChecksum( checksums.get( 1 ), "g/i/d/a-i.d/1.0/a-i.d-1.0-cls.ext.sha1", "SHA-1" );
+    }
+
+    @Test
     public void testArtifactChecksums_Upload()
     {
         DefaultArtifact artifact = new DefaultArtifact( "g.i.d", "a-i.d", "cls", "ext", "1.0" );
@@ -175,6 +189,19 @@ public class Maven2RepositoryLayoutFactoryTest
     }
 
     @Test
+    public void testArtifactChecksums_UploadWithCustomAlgorithms() throws NoRepositoryLayoutException
+    {
+        session.setConfigProperty( Maven2RepositoryLayoutFactory.CONFIG_PROP_CHECKSUMS_ALGORITHMS, "SHA-512,MD5" );
+        layout = factory.newInstance( session, newRepo( "default" ) );
+        DefaultArtifact artifact = new DefaultArtifact( "g.i.d", "a-i.d", "cls", "ext", "1.0" );
+        URI uri = layout.getLocation( artifact, true );
+        List<Checksum> checksums = layout.getChecksums( artifact, true, uri );
+        assertEquals( 2, checksums.size() );
+        assertChecksum( checksums.get( 0 ), "g/i/d/a-i.d/1.0/a-i.d-1.0-cls.ext.sha512", "SHA-512" );
+        assertChecksum( checksums.get( 1 ), "g/i/d/a-i.d/1.0/a-i.d-1.0-cls.ext.md5", "MD5" );
+    }
+
+    @Test
     public void testMetadataChecksums_Download()
     {
         DefaultMetadata metadata =