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/11 20:11:02 UTC
[maven-resolver] 01/01: [MRESOLVER-115] Make checksum algorithms
configurable
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 5a31cf5bf55390f3cd3a6d9e62ee87fd1794e776
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 | 34 +++++++++++++++++-----
.../impl/Maven2RepositoryLayoutFactoryTest.java | 27 +++++++++++++++++
2 files changed, 54 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..f1dce10 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,10 @@ 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 List<String> DEFAULT_CHECKSUMS_ALGORITHMS =
+ Arrays.asList( "SHA-512", "SHA-256", "SHA-1", "MD5" );
private float priority;
@@ -73,14 +78,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 = ( List<String> ) ConfigUtils.getList( session,
+ DEFAULT_CHECKSUMS_ALGORITHMS, CONFIG_PROP_CHECKSUMS_ALGORITHMS );
+
+ 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 +170,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 +184,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..0dac7ee 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, Arrays.asList( "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, Arrays.asList( "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 =