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 574ab5adc..16afbe279 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 List selectList( Collection algorithmNa .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 6705f767c..46d2501f9 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 RepositoryLayout newInstance( RepositorySystemSession session, RemoteRepo } return new Maven2RepositoryLayout( - new ArrayList<>( checksumAlgorithmFactorySelector.getChecksumAlgorithmFactories() ), + checksumAlgorithmFactorySelector, checksumsAlgorithms, omitChecksumsForExtensions ); @@ -143,17 +143,17 @@ public RepositoryLayout newInstance( RepositorySystemSession session, RemoteRepo private static class Maven2RepositoryLayout implements RepositoryLayout { - private final List allChecksumAlgorithms; + private final ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector; private final List configuredChecksumAlgorithms; private final Set extensionsWithoutChecksums; - private Maven2RepositoryLayout( List allChecksumAlgorithms, + private Maven2RepositoryLayout( ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector, List configuredChecksumAlgorithms, Set extensionsWithoutChecksums ) { - this.allChecksumAlgorithms = Collections.unmodifiableList( allChecksumAlgorithms ); + this.checksumAlgorithmFactorySelector = requireNonNull( checksumAlgorithmFactorySelector ); this.configuredChecksumAlgorithms = Collections.unmodifiableList( configuredChecksumAlgorithms ); this.extensionsWithoutChecksums = requireNonNull( extensionsWithoutChecksums ); } @@ -269,7 +269,7 @@ private List getChecksumLocations( URI location ) 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 81d8b64df..da353add8 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.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 List selectList( Collection algorithmNa } @Override - public List getChecksumAlgorithmFactories() + public Collection 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 49c3c09ee..393cc4bc3 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 Collection getChecksumAlgorithmFactories() { 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 f8196d0fc..f11f6c6e2 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 55feea706..6b26ba55e 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 selectList( Collection 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 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 ); }