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 2022/03/15 08:04:42 UTC

[maven-resolver] 11/19: Refactor: it is layout matter, does an artifact has checksums or not.

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

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

commit b6b613a004c67f5a6c76282c7d4690923d94804b
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Sun Mar 13 00:39:44 2022 +0100

    Refactor: it is layout matter, does an artifact has checksums or not.
    
    This is about REMOTE_EXTERNAL checksums, that ARE part of layout.
---
 .../eclipse/aether/impl/guice/AetherModule.java    |  5 --
 .../impl/Maven2RepositoryLayoutFactory.java        | 50 ++++++++----
 .../DefaultArtifactChecksumFilterFactory.java      | 90 ----------------------
 .../impl/Maven2RepositoryLayoutFactoryTest.java    |  5 +-
 .../connector/checksum/ArtifactChecksumFilter.java | 44 -----------
 .../checksum/ArtifactChecksumFilterFactory.java    | 36 ---------
 .../spi/connector/layout/RepositoryLayout.java     | 18 +++++
 7 files changed, 55 insertions(+), 193 deletions(-)

diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/guice/AetherModule.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/guice/AetherModule.java
index bf6e5ab..9629dc9 100644
--- a/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/guice/AetherModule.java
+++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/guice/AetherModule.java
@@ -43,7 +43,6 @@ import org.eclipse.aether.impl.RepositoryEventDispatcher;
 import org.eclipse.aether.internal.impl.DefaultTrackingFileManager;
 import org.eclipse.aether.internal.impl.FileProvidedChecksumsSource;
 import org.eclipse.aether.internal.impl.TrackingFileManager;
-import org.eclipse.aether.internal.impl.checksum.DefaultArtifactChecksumFilterFactory;
 import org.eclipse.aether.internal.impl.checksum.Md5ChecksumAlgorithmFactory;
 import org.eclipse.aether.internal.impl.checksum.Sha1ChecksumAlgorithmFactory;
 import org.eclipse.aether.internal.impl.checksum.Sha256ChecksumAlgorithmFactory;
@@ -85,7 +84,6 @@ import org.eclipse.aether.internal.impl.Maven2RepositoryLayoutFactory;
 import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
 import org.eclipse.aether.internal.impl.slf4j.Slf4jLoggerFactory;
 import org.eclipse.aether.named.providers.NoopNamedLockFactory;
-import org.eclipse.aether.spi.connector.checksum.ArtifactChecksumFilterFactory;
 import org.eclipse.aether.spi.connector.checksum.ProvidedChecksumsSource;
 import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactorySelector;
 import org.eclipse.aether.spi.connector.checksum.ChecksumPolicyProvider;
@@ -172,9 +170,6 @@ public class AetherModule
                 .to( EnhancedLocalRepositoryManagerFactory.class ).in( Singleton.class );
         bind( TrackingFileManager.class ).to( DefaultTrackingFileManager.class ).in( Singleton.class );
 
-        bind( ArtifactChecksumFilterFactory.class )
-                .to( DefaultArtifactChecksumFilterFactory.class ).in( Singleton.class );
-
         bind( ProvidedChecksumsSource.class ).annotatedWith( Names.named( FileProvidedChecksumsSource.NAME ) ) //
             .to( FileProvidedChecksumsSource.class ).in( Singleton.class );
 
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 202fe3c..f2433cc 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
@@ -26,6 +26,8 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 import javax.inject.Inject;
 import javax.inject.Named;
@@ -33,12 +35,9 @@ import javax.inject.Singleton;
 
 import org.eclipse.aether.RepositorySystemSession;
 import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.internal.impl.checksum.DefaultArtifactChecksumFilterFactory;
 import org.eclipse.aether.internal.impl.checksum.DefaultChecksumAlgorithmFactorySelector;
 import org.eclipse.aether.metadata.Metadata;
 import org.eclipse.aether.repository.RemoteRepository;
-import org.eclipse.aether.spi.connector.checksum.ArtifactChecksumFilter;
-import org.eclipse.aether.spi.connector.checksum.ArtifactChecksumFilterFactory;
 import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactory;
 import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactorySelector;
 import org.eclipse.aether.spi.connector.layout.RepositoryLayout;
@@ -59,14 +58,17 @@ public final class Maven2RepositoryLayoutFactory
 
     public static final String CONFIG_PROP_CHECKSUMS_ALGORITHMS = "aether.checksums.algorithms";
 
-    static final String DEFAULT_CHECKSUMS_ALGORITHMS = "SHA-1,MD5";
+    private static final String DEFAULT_CHECKSUMS_ALGORITHMS = "SHA-1,MD5";
+
+    public static final String CONFIG_PROP_OMIT_CHECKSUMS_FOR_EXTENSIONS =
+            "aether.checksums.omitChecksumsForExtensions";
+
+    private static final String DEFAULT_OMIT_CHECKSUMS_FOR_EXTENSIONS = ".asc";
 
     private float priority;
 
     private final ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector;
 
-    private final ArtifactChecksumFilterFactory artifactChecksumFilterFactory;
-
     public float getPriority()
     {
         return priority;
@@ -78,15 +80,13 @@ public final class Maven2RepositoryLayoutFactory
     @Deprecated
     public Maven2RepositoryLayoutFactory()
     {
-        this( new DefaultChecksumAlgorithmFactorySelector(), new DefaultArtifactChecksumFilterFactory() );
+        this( new DefaultChecksumAlgorithmFactorySelector() );
     }
 
     @Inject
-    public Maven2RepositoryLayoutFactory( ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector,
-                                          ArtifactChecksumFilterFactory artifactChecksumFilterFactory )
+    public Maven2RepositoryLayoutFactory( ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector )
     {
         this.checksumAlgorithmFactorySelector = requireNonNull( checksumAlgorithmFactorySelector );
-        this.artifactChecksumFilterFactory = requireNonNull( artifactChecksumFilterFactory );
     }
 
     /**
@@ -123,9 +123,15 @@ public final class Maven2RepositoryLayoutFactory
             checksumsAlgorithms.add( checksumAlgorithmFactorySelector.select( checksumsAlgorithmName ) );
         }
 
+        // ensure uniqueness of (potentially user set) extension list
+        Set<String> omitChecksumsForExtensions = Arrays.stream( ConfigUtils.getString(
+                        session, DEFAULT_OMIT_CHECKSUMS_FOR_EXTENSIONS, CONFIG_PROP_OMIT_CHECKSUMS_FOR_EXTENSIONS )
+                .split( "," )
+        ).filter( s -> s != null && !s.trim().isEmpty() ).collect( Collectors.toSet() );
+
         return new Maven2RepositoryLayout(
                 checksumsAlgorithms,
-                artifactChecksumFilterFactory.newInstance( session, repository )
+                omitChecksumsForExtensions
         );
     }
 
@@ -135,13 +141,13 @@ public final class Maven2RepositoryLayoutFactory
 
         private final List<ChecksumAlgorithmFactory> checksumAlgorithms;
 
-        private final ArtifactChecksumFilter artifactChecksumFilter;
+        private final Set<String> extensionsWithoutChecksums;
 
         private Maven2RepositoryLayout( List<ChecksumAlgorithmFactory> checksumAlgorithms,
-                                          ArtifactChecksumFilter artifactChecksumFilter )
+                                        Set<String> extensionsWithoutChecksums )
         {
             this.checksumAlgorithms = Collections.unmodifiableList( checksumAlgorithms );
-            this.artifactChecksumFilter = artifactChecksumFilter;
+            this.extensionsWithoutChecksums = requireNonNull( extensionsWithoutChecksums );
         }
 
         private URI toUri( String path )
@@ -163,6 +169,20 @@ public final class Maven2RepositoryLayoutFactory
         }
 
         @Override
+        public boolean hasChecksums( Artifact artifact )
+        {
+            String artifactExtension = artifact.getExtension(); // ie. pom.asc
+            for ( String extensionWithoutChecksums : extensionsWithoutChecksums )
+            {
+                if ( artifactExtension.endsWith( extensionWithoutChecksums ) )
+                {
+                    return false;
+                }
+            }
+            return true;
+        }
+
+        @Override
         public URI getLocation( Artifact artifact, boolean upload )
         {
             StringBuilder path = new StringBuilder( 128 );
@@ -216,7 +236,7 @@ public final class Maven2RepositoryLayoutFactory
         @Override
         public List<ChecksumLocation> getChecksumLocations( Artifact artifact, boolean upload, URI location )
         {
-            if ( artifactChecksumFilter.omitChecksumsFor( artifact ) || isChecksum( artifact.getExtension() ) )
+            if ( !hasChecksums( artifact ) || isChecksum( artifact.getExtension() ) )
             {
                 return Collections.emptyList();
             }
diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/checksum/DefaultArtifactChecksumFilterFactory.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/checksum/DefaultArtifactChecksumFilterFactory.java
deleted file mode 100644
index a7bea4c..0000000
--- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/checksum/DefaultArtifactChecksumFilterFactory.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package org.eclipse.aether.internal.impl.checksum;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import javax.inject.Named;
-import javax.inject.Singleton;
-
-import java.util.Arrays;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import org.eclipse.aether.RepositorySystemSession;
-import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.repository.RemoteRepository;
-import org.eclipse.aether.spi.connector.checksum.ArtifactChecksumFilter;
-import org.eclipse.aether.spi.connector.checksum.ArtifactChecksumFilterFactory;
-import org.eclipse.aether.util.ConfigUtils;
-
-import static java.util.Objects.requireNonNull;
-
-/**
- * Default implementation that implements default resolver strategy: filters by known (user configured) extensions,
- * or by default only for GPG signature.
- *
- * @since 1.8.0
- */
-@Singleton
-@Named
-public class DefaultArtifactChecksumFilterFactory
-        implements ArtifactChecksumFilterFactory
-{
-    public static final String CONFIG_PROP_OMIT_CHECKSUMS_FOR_EXTENSIONS =
-            "aether.checksums.omitChecksumsForExtensions";
-
-    private static final String DEFAULT_OMIT_CHECKSUMS_FOR_EXTENSIONS = ".asc";
-
-    @Override
-    public ArtifactChecksumFilter newInstance( RepositorySystemSession session, RemoteRepository repository )
-    {
-        // ensure uniqueness of (potentially user set) extension list
-        Set<String> omitChecksumsForExtensions = Arrays.stream( ConfigUtils.getString(
-                session, DEFAULT_OMIT_CHECKSUMS_FOR_EXTENSIONS, CONFIG_PROP_OMIT_CHECKSUMS_FOR_EXTENSIONS )
-                .split( "," )
-        ).filter( s -> s != null && !s.trim().isEmpty() ).collect( Collectors.toSet() );
-
-        return new ExtensionArtifactChecksumFilter( omitChecksumsForExtensions );
-    }
-
-    private static class ExtensionArtifactChecksumFilter
-            implements ArtifactChecksumFilter
-    {
-        private final Set<String> extensionsWithoutChecksums;
-
-        private ExtensionArtifactChecksumFilter( Set<String> extensionsWithoutChecksums )
-        {
-            this.extensionsWithoutChecksums = requireNonNull( extensionsWithoutChecksums );
-        }
-
-        @Override
-        public boolean omitChecksumsFor( Artifact artifact )
-        {
-            String artifactExtension = artifact.getExtension(); // ie. pom.asc
-            for ( String extensionWithoutChecksums : extensionsWithoutChecksums )
-            {
-                if ( artifactExtension.endsWith( extensionWithoutChecksums ) )
-                {
-                    return true;
-                }
-            }
-            return false;
-        }
-    }
-}
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 81c5dfb..c239165 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
@@ -28,7 +28,6 @@ import java.util.stream.Collectors;
 
 import org.eclipse.aether.DefaultRepositorySystemSession;
 import org.eclipse.aether.artifact.DefaultArtifact;
-import org.eclipse.aether.internal.impl.checksum.DefaultArtifactChecksumFilterFactory;
 import org.eclipse.aether.internal.test.util.TestUtils;
 import org.eclipse.aether.metadata.DefaultMetadata;
 import org.eclipse.aether.metadata.Metadata;
@@ -312,7 +311,7 @@ public class Maven2RepositoryLayoutFactoryTest
     public void testSignatureChecksums_Force()
         throws Exception
     {
-        session.setConfigProperty( DefaultArtifactChecksumFilterFactory.CONFIG_PROP_OMIT_CHECKSUMS_FOR_EXTENSIONS, "" );
+        session.setConfigProperty( Maven2RepositoryLayoutFactory.CONFIG_PROP_OMIT_CHECKSUMS_FOR_EXTENSIONS, "" );
         layout = factory.newInstance( session, newRepo( "default" ) );
         DefaultArtifact artifact = new DefaultArtifact( "g.i.d", "a-i.d", "cls", "jar.asc", "1.0" );
         URI uri = layout.getLocation( artifact, true );
@@ -324,7 +323,7 @@ public class Maven2RepositoryLayoutFactoryTest
     public void testCustomChecksumsIgnored()
             throws Exception
     {
-        session.setConfigProperty( DefaultArtifactChecksumFilterFactory.CONFIG_PROP_OMIT_CHECKSUMS_FOR_EXTENSIONS, ".asc,.foo" );
+        session.setConfigProperty( Maven2RepositoryLayoutFactory.CONFIG_PROP_OMIT_CHECKSUMS_FOR_EXTENSIONS, ".asc,.foo" );
         layout = factory.newInstance( session, newRepo( "default" ) );
         DefaultArtifact artifact = new DefaultArtifact( "g.i.d", "a-i.d", "cls", "jar.foo", "1.0" );
         URI uri = layout.getLocation( artifact, true );
diff --git a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ArtifactChecksumFilter.java b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ArtifactChecksumFilter.java
deleted file mode 100644
index bf19190..0000000
--- a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ArtifactChecksumFilter.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package org.eclipse.aether.spi.connector.checksum;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.eclipse.aether.artifact.Artifact;
-
-/**
- * Filter that is able to tell does artifact have expected checksums or not. Most notably, artifacts like
- * different kind of signatures will not have checksums.
- *
- * @since 1.8.0
- */
-public interface ArtifactChecksumFilter
-{
-    /**
-     * Tells whether given artifact have checksums according to current layout or not. If it returns {@code false},
-     * then layout configured checksums will be expected: on upload they will be calculated and deployed along
-     * artifact, on download they will be retrieved and validated.
-     *
-     * If it returns {@code true} the given artifacts will have checksums omitted: on upload they will not be
-     * calculated and deployed, and on download they will be not retrieved nor validated.
-     *
-     * Typical case to return {@code true} (to omit checksums) is for GPG signatures, that are already a "sub-artifact"
-     * of some main artifact (ie. a JAR), and they can be validated by some other means.
-     */
-    boolean omitChecksumsFor( Artifact artifact );
-}
diff --git a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ArtifactChecksumFilterFactory.java b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ArtifactChecksumFilterFactory.java
deleted file mode 100644
index d1df787..0000000
--- a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ArtifactChecksumFilterFactory.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package org.eclipse.aether.spi.connector.checksum;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.eclipse.aether.RepositorySystemSession;
-import org.eclipse.aether.repository.RemoteRepository;
-
-/**
- * Factory component for {@link ArtifactChecksumFilter} instances.
- *
- * @since 1.8.0
- */
-public interface ArtifactChecksumFilterFactory
-{
-    /**
-     * Returns {@link ArtifactChecksumFilter} for given session and repository, never {@code null}.
-     */
-    ArtifactChecksumFilter newInstance( RepositorySystemSession session, RemoteRepository repository );
-}
diff --git a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/layout/RepositoryLayout.java b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/layout/RepositoryLayout.java
index 5db7deb..8e4bef0 100644
--- a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/layout/RepositoryLayout.java
+++ b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/layout/RepositoryLayout.java
@@ -134,6 +134,24 @@ public interface RepositoryLayout
     List<ChecksumAlgorithmFactory> getChecksumAlgorithmFactories();
 
     /**
+     * Tells whether given artifact have remote external checksums according to current layout or not. If it returns
+     * {@code true}, then layout configured checksums will be expected: on upload they will be calculated and deployed
+     * along artifact, on download they will be retrieved and validated.
+     *
+     * If it returns {@code false} the given artifacts will have checksums omitted: on upload they will not be
+     * calculated and deployed, and on download they will be not retrieved nor validated.
+     *
+     * The result affects only layout provided checksums. See
+     * {@link org.eclipse.aether.spi.connector.checksum.ChecksumPolicy.ChecksumKind#REMOTE_EXTERNAL}.
+     * On download, the {@link org.eclipse.aether.spi.connector.layout.RepositoryLayout#getChecksumAlgorithmFactories()}
+     * layout required checksums are calculated, and non layout-provided checksums are still utilized.
+     *
+     * Typical case to return {@code true} (to omit checksums) is for artifact signatures, that are already a
+     * "sub-artifact" of some main artifact (for example a JAR), and they can be validated by some other means.
+     */
+    boolean hasChecksums( Artifact artifact );
+
+    /**
      * Gets the location within a remote repository where the specified artifact resides. The URI is relative to the
      * root directory of the repository.
      *