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/12/22 15:55:57 UTC
[maven-resolver] branch master updated: [MRESOLVER-303] Make checksum detection reusable (#227)
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 e4d41403 [MRESOLVER-303] Make checksum detection reusable (#227)
e4d41403 is described below
commit e4d4140320a2dfd88aaede4d320457b64c01b528
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Thu Dec 22 16:55:52 2022 +0100
[MRESOLVER-303] Make checksum detection reusable (#227)
Expose it on selector..
---
https://issues.apache.org/jira/browse/MRESOLVER-303
---
.../basic/TestChecksumAlgorithmSelector.java | 6 ++++++
.../internal/impl/Maven2RepositoryLayoutFactory.java | 10 +++++-----
.../DefaultChecksumAlgorithmFactorySelector.java | 20 +++++++++++++++++---
...edChecksumsArtifactResolverPostProcessorTest.java | 6 ++++++
.../connector/checksum/ChecksumAlgorithmFactory.java | 1 +
.../checksum/ChecksumAlgorithmFactorySelector.java | 15 ++++++++++++---
6 files changed, 47 insertions(+), 11 deletions(-)
diff --git a/maven-resolver-connector-basic/src/test/java/org/eclipse/aether/connector/basic/TestChecksumAlgorithmSelector.java b/maven-resolver-connector-basic/src/test/java/org/eclipse/aether/connector/basic/TestChecksumAlgorithmSelector.java
index 574ab5ad..16afbe27 100644
--- a/maven-resolver-connector-basic/src/test/java/org/eclipse/aether/connector/basic/TestChecksumAlgorithmSelector.java
+++ b/maven-resolver-connector-basic/src/test/java/org/eclipse/aether/connector/basic/TestChecksumAlgorithmSelector.java
@@ -98,6 +98,12 @@ public class TestChecksumAlgorithmSelector
.collect( toList() );
}
+ @Override
+ public boolean isChecksumExtension( String extension )
+ {
+ throw new RuntimeException( "not implemented" );
+ }
+
private static class MessageDigestChecksumAlgorithmFactory
extends ChecksumAlgorithmFactorySupport
{
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 6705f767..46d2501f 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
@@ -134,7 +134,7 @@ public final class Maven2RepositoryLayoutFactory
}
return new Maven2RepositoryLayout(
- new ArrayList<>( checksumAlgorithmFactorySelector.getChecksumAlgorithmFactories() ),
+ checksumAlgorithmFactorySelector,
checksumsAlgorithms,
omitChecksumsForExtensions
);
@@ -143,17 +143,17 @@ public final class Maven2RepositoryLayoutFactory
private static class Maven2RepositoryLayout
implements RepositoryLayout
{
- private final List<ChecksumAlgorithmFactory> allChecksumAlgorithms;
+ private final ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector;
private final List<ChecksumAlgorithmFactory> configuredChecksumAlgorithms;
private final Set<String> extensionsWithoutChecksums;
- private Maven2RepositoryLayout( List<ChecksumAlgorithmFactory> allChecksumAlgorithms,
+ private Maven2RepositoryLayout( ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector,
List<ChecksumAlgorithmFactory> configuredChecksumAlgorithms,
Set<String> extensionsWithoutChecksums )
{
- this.allChecksumAlgorithms = Collections.unmodifiableList( allChecksumAlgorithms );
+ this.checksumAlgorithmFactorySelector = requireNonNull( checksumAlgorithmFactorySelector );
this.configuredChecksumAlgorithms = Collections.unmodifiableList( configuredChecksumAlgorithms );
this.extensionsWithoutChecksums = requireNonNull( extensionsWithoutChecksums );
}
@@ -269,7 +269,7 @@ public final class Maven2RepositoryLayoutFactory
private boolean isChecksum( String extension )
{
- return allChecksumAlgorithms.stream().anyMatch( a -> extension.endsWith( "." + a.getFileExtension() ) );
+ return checksumAlgorithmFactorySelector.isChecksumExtension( extension );
}
}
}
diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/checksum/DefaultChecksumAlgorithmFactorySelector.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/checksum/DefaultChecksumAlgorithmFactorySelector.java
index 81d8b64d..da353add 100644
--- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/checksum/DefaultChecksumAlgorithmFactorySelector.java
+++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/checksum/DefaultChecksumAlgorithmFactorySelector.java
@@ -23,8 +23,8 @@ import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
-import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -94,8 +94,22 @@ public class DefaultChecksumAlgorithmFactorySelector
}
@Override
- public List<ChecksumAlgorithmFactory> getChecksumAlgorithmFactories()
+ public Collection<ChecksumAlgorithmFactory> getChecksumAlgorithmFactories()
{
- return new ArrayList<>( factories.values() );
+ return Collections.unmodifiableCollection( factories.values() );
+ }
+
+ @Override
+ public boolean isChecksumExtension( String extension )
+ {
+ requireNonNull( extension );
+ if ( extension.contains( "." ) )
+ {
+ return factories.values().stream().anyMatch( a -> extension.endsWith( "." + a.getFileExtension() ) );
+ }
+ else
+ {
+ return factories.values().stream().anyMatch( a -> extension.equals( a.getFileExtension() ) );
+ }
}
}
diff --git a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/resolution/TrustedChecksumsArtifactResolverPostProcessorTest.java b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/resolution/TrustedChecksumsArtifactResolverPostProcessorTest.java
index 49c3c09e..393cc4bc 100644
--- a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/resolution/TrustedChecksumsArtifactResolverPostProcessorTest.java
+++ b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/resolution/TrustedChecksumsArtifactResolverPostProcessorTest.java
@@ -108,6 +108,12 @@ public class TrustedChecksumsArtifactResolverPostProcessorTest implements Truste
{
return Collections.singletonList( checksumAlgorithmFactory );
}
+
+ @Override
+ public boolean isChecksumExtension( String extension )
+ {
+ throw new RuntimeException( "not implemented" );
+ }
};
subject = new TrustedChecksumsArtifactResolverPostProcessor( selector,
Collections.singletonMap( TRUSTED_SOURCE_NAME, this ) );
diff --git a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ChecksumAlgorithmFactory.java b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ChecksumAlgorithmFactory.java
index f8196d0f..f11f6c6e 100644
--- a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ChecksumAlgorithmFactory.java
+++ b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ChecksumAlgorithmFactory.java
@@ -37,6 +37,7 @@ public interface ChecksumAlgorithmFactory
/**
* Returns the file extension to be used for given checksum file (without leading dot), never {@code null}. The
* extension should be file and URL path friendly, and may differ from value returned by {@link #getName()}.
+ * The checksum extension SHOULD NOT contain dot (".") character.
* Example: "sha1".
*/
String getFileExtension();
diff --git a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ChecksumAlgorithmFactorySelector.java b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ChecksumAlgorithmFactorySelector.java
index 55feea70..6b26ba55 100644
--- a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ChecksumAlgorithmFactorySelector.java
+++ b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ChecksumAlgorithmFactorySelector.java
@@ -41,7 +41,7 @@ public interface ChecksumAlgorithmFactorySelector
ChecksumAlgorithmFactory select( String algorithmName );
/**
- * Returns a list of factories for given algorithm names in order as collection is ordered, or throws if any of the
+ * Returns a list of factories in same order as algorithm names are ordered, or throws if any of the
* algorithm name is not supported. The returned list has equal count of elements as passed in collection of names,
* and if names contains duplicated elements, the returned list of algorithms will have duplicates as well.
*
@@ -52,10 +52,19 @@ public interface ChecksumAlgorithmFactorySelector
List<ChecksumAlgorithmFactory> selectList( Collection<String> algorithmNames );
/**
- * Returns a collection of supported algorithms. This set represents ALL the algorithms supported by Resolver,
- * and is NOT in any relation to given repository layout used checksums, returned by method {@link
+ * Returns immutable collection of all supported algorithms. This set represents ALL the algorithms supported by
+ * Resolver, and is NOT in any relation to given repository layout used checksums, returned by method {@link
* org.eclipse.aether.spi.connector.layout.RepositoryLayout#getChecksumAlgorithmFactories()} (in fact, is super set
* of it).
*/
Collection<ChecksumAlgorithmFactory> getChecksumAlgorithmFactories();
+
+ /**
+ * Returns {@code true} if passed in extension matches any known checksum extension. The extension string may
+ * start or contain dot ("."), but does not have to. In former case "ends with" is checked (i.e. "jar.sha1" -> true;
+ * ".sha1" -> true) while in latter equality (i.e. "sha1" -> true).
+ *
+ * @since 1.9.3
+ */
+ boolean isChecksumExtension( String extension );
}