michael-o commented on a change in pull request #141:
URL: https://github.com/apache/maven-resolver/pull/141#discussion_r795037478



##########
File path: 
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/FileProvidedChecksumSource.java
##########
@@ -0,0 +1,188 @@
+package org.eclipse.aether.internal.impl;
+
+/*
+ * 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 java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.spi.connector.ArtifactDownload;
+import org.eclipse.aether.spi.connector.MetadataDownload;
+import org.eclipse.aether.spi.connector.checksum.ProvidedChecksumsSource;
+import org.eclipse.aether.spi.connector.layout.RepositoryLayout;
+import 
org.eclipse.aether.spi.connector.layout.RepositoryLayout.ChecksumLocation;
+import org.eclipse.aether.spi.io.FileProcessor;
+import org.eclipse.aether.util.ConfigUtils;
+import org.eclipse.aether.util.artifact.ArtifactIdUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * {@link ProvidedChecksumsSource} that does use specified directory structure 
to look up checksums.
+ *
+ * @since TBD
+ */
+@Singleton
+@Named( FileProvidedChecksumSource.NAME )
+public final class FileProvidedChecksumSource
+    implements ProvidedChecksumsSource
+{
+    public static final String NAME = "file";
+
+    static final String CONFIG_PROP_BASE_DIR = 
"aether.artifactResolver.providedChecksumSource.file.baseDir";
+
+    static final String LOCAL_REPO_PREFIX = ".checksums";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( 
FileProvidedChecksumSource.class );
+
+    private final FileProcessor fileProcessor;
+
+    @Inject
+    public FileProvidedChecksumSource( FileProcessor fileProcessor )
+    {
+        this.fileProcessor = requireNonNull( fileProcessor );
+    }
+
+    @Override
+    public Map<String, String> getProvidedMetadataChecksums( 
RepositorySystemSession session,

Review comment:
       Both methods look almost identical, would it make sense to refactor the 
common code to a private method?

##########
File path: 
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/FileProvidedChecksumSource.java
##########
@@ -0,0 +1,188 @@
+package org.eclipse.aether.internal.impl;
+
+/*
+ * 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 java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.spi.connector.ArtifactDownload;
+import org.eclipse.aether.spi.connector.MetadataDownload;
+import org.eclipse.aether.spi.connector.checksum.ProvidedChecksumsSource;
+import org.eclipse.aether.spi.connector.layout.RepositoryLayout;
+import 
org.eclipse.aether.spi.connector.layout.RepositoryLayout.ChecksumLocation;
+import org.eclipse.aether.spi.io.FileProcessor;
+import org.eclipse.aether.util.ConfigUtils;
+import org.eclipse.aether.util.artifact.ArtifactIdUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * {@link ProvidedChecksumsSource} that does use specified directory structure 
to look up checksums.
+ *
+ * @since TBD
+ */
+@Singleton
+@Named( FileProvidedChecksumSource.NAME )
+public final class FileProvidedChecksumSource
+    implements ProvidedChecksumsSource
+{
+    public static final String NAME = "file";
+
+    static final String CONFIG_PROP_BASE_DIR = 
"aether.artifactResolver.providedChecksumSource.file.baseDir";
+
+    static final String LOCAL_REPO_PREFIX = ".checksums";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( 
FileProvidedChecksumSource.class );
+
+    private final FileProcessor fileProcessor;
+
+    @Inject
+    public FileProvidedChecksumSource( FileProcessor fileProcessor )
+    {
+        this.fileProcessor = requireNonNull( fileProcessor );
+    }
+
+    @Override
+    public Map<String, String> getProvidedMetadataChecksums( 
RepositorySystemSession session,
+                                                             MetadataDownload 
transfer,
+                                                             RepositoryLayout 
repositoryLayout )
+    {
+        URI baseURI = getBaseURI( session );
+        if ( baseURI == null )
+        {
+            return null;
+        }
+
+        HashMap<String, String> checksums = new HashMap<>();
+        Metadata metadata = transfer.getMetadata();
+        List<ChecksumLocation> checksumLocations = 
repositoryLayout.getChecksumLocations(
+            metadata, false, repositoryLayout.getLocation( metadata, false )
+        );
+        for ( ChecksumLocation checksumLocation : checksumLocations )
+        {
+            Path checksumPath = new File( baseURI.resolve( 
checksumLocation.getLocation() ) ).toPath();
+            if ( Files.isReadable( checksumPath ) )
+            {
+                try
+                {
+                    String checksum = fileProcessor.readChecksum( 
checksumPath.toFile() );
+                    if ( checksum != null )
+                    {
+                        if ( LOGGER.isDebugEnabled() )
+                        {
+                            LOGGER.debug( "{} -> {}:{}", metadata,
+                                
checksumLocation.getChecksumAlgorithmFactory().getName(), checksum );
+                        }
+
+                        checksums.put( 
checksumLocation.getChecksumAlgorithmFactory().getName(), checksum );
+                    }
+                }
+                catch ( IOException e )
+                {
+                    LOGGER.warn( "Could not read provided checksum for {} at 
path {}", metadata, checksumPath, e );
+                }
+            }
+        }
+        return checksums.isEmpty() ? null : checksums;
+    }
+
+    @Override
+    public Map<String, String> getProvidedArtifactChecksums( 
RepositorySystemSession session,
+                                                             ArtifactDownload 
transfer,
+                                                             RepositoryLayout 
repositoryLayout )
+    {
+        URI baseURI = getBaseURI( session );
+        if ( baseURI == null )
+        {
+            return null;
+        }
+
+        HashMap<String, String> checksums = new HashMap<>();
+        Artifact artifact = transfer.getArtifact();
+        List<ChecksumLocation> checksumLocations = 
repositoryLayout.getChecksumLocations(
+            artifact, false, repositoryLayout.getLocation( artifact, false )
+        );
+        for ( ChecksumLocation checksumLocation : checksumLocations )
+        {
+            Path checksumPath = new File( baseURI.resolve( 
checksumLocation.getLocation() ) ).toPath();
+            if ( Files.isReadable( checksumPath ) )
+            {
+                try
+                {
+                    String checksum = fileProcessor.readChecksum( 
checksumPath.toFile() );
+                    if ( checksum != null )
+                    {
+                        if ( LOGGER.isDebugEnabled() )
+                        {
+                            LOGGER.debug( "{} -> {}:{}", ArtifactIdUtils.toId( 
artifact ),
+                                
checksumLocation.getChecksumAlgorithmFactory().getName(), checksum );
+                        }
+
+                        checksums.put( 
checksumLocation.getChecksumAlgorithmFactory().getName(), checksum );
+                    }
+                }
+                catch ( IOException e )
+                {
+                    LOGGER.warn( "Could not read provided checksum for {} at 
path {}",

Review comment:
       Same here

##########
File path: 
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/FileProvidedChecksumSource.java
##########
@@ -0,0 +1,188 @@
+package org.eclipse.aether.internal.impl;
+
+/*
+ * 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 java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.spi.connector.ArtifactDownload;
+import org.eclipse.aether.spi.connector.MetadataDownload;
+import org.eclipse.aether.spi.connector.checksum.ProvidedChecksumsSource;
+import org.eclipse.aether.spi.connector.layout.RepositoryLayout;
+import 
org.eclipse.aether.spi.connector.layout.RepositoryLayout.ChecksumLocation;
+import org.eclipse.aether.spi.io.FileProcessor;
+import org.eclipse.aether.util.ConfigUtils;
+import org.eclipse.aether.util.artifact.ArtifactIdUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * {@link ProvidedChecksumsSource} that does use specified directory structure 
to look up checksums.
+ *
+ * @since TBD
+ */
+@Singleton
+@Named( FileProvidedChecksumSource.NAME )
+public final class FileProvidedChecksumSource
+    implements ProvidedChecksumsSource
+{
+    public static final String NAME = "file";
+
+    static final String CONFIG_PROP_BASE_DIR = 
"aether.artifactResolver.providedChecksumSource.file.baseDir";
+
+    static final String LOCAL_REPO_PREFIX = ".checksums";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( 
FileProvidedChecksumSource.class );
+
+    private final FileProcessor fileProcessor;
+
+    @Inject
+    public FileProvidedChecksumSource( FileProcessor fileProcessor )
+    {
+        this.fileProcessor = requireNonNull( fileProcessor );
+    }
+
+    @Override
+    public Map<String, String> getProvidedMetadataChecksums( 
RepositorySystemSession session,
+                                                             MetadataDownload 
transfer,
+                                                             RepositoryLayout 
repositoryLayout )
+    {
+        URI baseURI = getBaseURI( session );
+        if ( baseURI == null )
+        {
+            return null;
+        }
+
+        HashMap<String, String> checksums = new HashMap<>();
+        Metadata metadata = transfer.getMetadata();
+        List<ChecksumLocation> checksumLocations = 
repositoryLayout.getChecksumLocations(
+            metadata, false, repositoryLayout.getLocation( metadata, false )
+        );
+        for ( ChecksumLocation checksumLocation : checksumLocations )
+        {
+            Path checksumPath = new File( baseURI.resolve( 
checksumLocation.getLocation() ) ).toPath();
+            if ( Files.isReadable( checksumPath ) )
+            {
+                try
+                {
+                    String checksum = fileProcessor.readChecksum( 
checksumPath.toFile() );
+                    if ( checksum != null )
+                    {
+                        if ( LOGGER.isDebugEnabled() )
+                        {
+                            LOGGER.debug( "{} -> {}:{}", metadata,
+                                
checksumLocation.getChecksumAlgorithmFactory().getName(), checksum );
+                        }
+
+                        checksums.put( 
checksumLocation.getChecksumAlgorithmFactory().getName(), checksum );
+                    }
+                }
+                catch ( IOException e )
+                {
+                    LOGGER.warn( "Could not read provided checksum for {} at 
path {}", metadata, checksumPath, e );

Review comment:
       Add single quotes to args.

##########
File path: 
maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ChecksumPolicy.java
##########
@@ -64,53 +64,52 @@
  */
 public interface ChecksumPolicy
 {
-
     /**
-     * Bit flag indicating a checksum which is not part of the official 
repository layout/structure.
+     * Enum denoting origin of checksum: remotely fetched (was before the 
"official"), smart or provided.
+     *
+     * @since TBD
      */
-    int KIND_UNOFFICIAL = 0x01;
+    enum ChecksumKind
+    {
+        REMOTE, SMART, PROVIDED

Review comment:
       I absolutely dislike the term "smart" because computers aren't smart. 
They are stupid. The inline checksums are also remote. I would prefer some 
other term for it.

##########
File path: 
maven-resolver-connector-basic/src/main/java/org/eclipse/aether/connector/basic/ChecksumValidator.java
##########
@@ -97,7 +102,13 @@ public void validate( Map<String, ?> actualChecksums, 
Map<String, ?> inlinedChec
         {
             return;
         }
-        if ( inlinedChecksums != null && validateInlinedChecksums( 
actualChecksums, inlinedChecksums ) )
+        if ( providedChecksums != null
+               && validateChecksums( actualChecksums, ChecksumKind.PROVIDED, 
providedChecksums ) )
+        {
+            return;
+        }
+        if ( inlinedChecksums != null
+               && validateChecksums( actualChecksums, ChecksumKind.SMART, 
inlinedChecksums ) )

Review comment:
       `SMART` => `REMOTE_INLINE`?

##########
File path: 
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/FileProvidedChecksumSource.java
##########
@@ -0,0 +1,188 @@
+package org.eclipse.aether.internal.impl;
+
+/*
+ * 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 java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.spi.connector.ArtifactDownload;
+import org.eclipse.aether.spi.connector.MetadataDownload;
+import org.eclipse.aether.spi.connector.checksum.ProvidedChecksumsSource;
+import org.eclipse.aether.spi.connector.layout.RepositoryLayout;
+import 
org.eclipse.aether.spi.connector.layout.RepositoryLayout.ChecksumLocation;
+import org.eclipse.aether.spi.io.FileProcessor;
+import org.eclipse.aether.util.ConfigUtils;
+import org.eclipse.aether.util.artifact.ArtifactIdUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * {@link ProvidedChecksumsSource} that does use specified directory structure 
to look up checksums.
+ *
+ * @since TBD
+ */
+@Singleton
+@Named( FileProvidedChecksumSource.NAME )
+public final class FileProvidedChecksumSource
+    implements ProvidedChecksumsSource
+{
+    public static final String NAME = "file";
+
+    static final String CONFIG_PROP_BASE_DIR = 
"aether.artifactResolver.providedChecksumSource.file.baseDir";
+
+    static final String LOCAL_REPO_PREFIX = ".checksums";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( 
FileProvidedChecksumSource.class );
+
+    private final FileProcessor fileProcessor;
+
+    @Inject
+    public FileProvidedChecksumSource( FileProcessor fileProcessor )
+    {
+        this.fileProcessor = requireNonNull( fileProcessor );
+    }
+
+    @Override
+    public Map<String, String> getProvidedMetadataChecksums( 
RepositorySystemSession session,
+                                                             MetadataDownload 
transfer,
+                                                             RepositoryLayout 
repositoryLayout )
+    {
+        URI baseURI = getBaseURI( session );
+        if ( baseURI == null )
+        {
+            return null;
+        }
+
+        HashMap<String, String> checksums = new HashMap<>();
+        Metadata metadata = transfer.getMetadata();
+        List<ChecksumLocation> checksumLocations = 
repositoryLayout.getChecksumLocations(
+            metadata, false, repositoryLayout.getLocation( metadata, false )
+        );
+        for ( ChecksumLocation checksumLocation : checksumLocations )
+        {
+            Path checksumPath = new File( baseURI.resolve( 
checksumLocation.getLocation() ) ).toPath();
+            if ( Files.isReadable( checksumPath ) )
+            {
+                try
+                {
+                    String checksum = fileProcessor.readChecksum( 
checksumPath.toFile() );
+                    if ( checksum != null )
+                    {
+                        if ( LOGGER.isDebugEnabled() )
+                        {
+                            LOGGER.debug( "{} -> {}:{}", metadata,
+                                
checksumLocation.getChecksumAlgorithmFactory().getName(), checksum );
+                        }
+
+                        checksums.put( 
checksumLocation.getChecksumAlgorithmFactory().getName(), checksum );
+                    }
+                }
+                catch ( IOException e )
+                {
+                    LOGGER.warn( "Could not read provided checksum for {} at 
path {}", metadata, checksumPath, e );
+                }
+            }
+        }
+        return checksums.isEmpty() ? null : checksums;
+    }
+
+    @Override
+    public Map<String, String> getProvidedArtifactChecksums( 
RepositorySystemSession session,
+                                                             ArtifactDownload 
transfer,
+                                                             RepositoryLayout 
repositoryLayout )
+    {
+        URI baseURI = getBaseURI( session );
+        if ( baseURI == null )
+        {
+            return null;
+        }
+
+        HashMap<String, String> checksums = new HashMap<>();
+        Artifact artifact = transfer.getArtifact();
+        List<ChecksumLocation> checksumLocations = 
repositoryLayout.getChecksumLocations(
+            artifact, false, repositoryLayout.getLocation( artifact, false )
+        );
+        for ( ChecksumLocation checksumLocation : checksumLocations )
+        {
+            Path checksumPath = new File( baseURI.resolve( 
checksumLocation.getLocation() ) ).toPath();
+            if ( Files.isReadable( checksumPath ) )
+            {
+                try
+                {
+                    String checksum = fileProcessor.readChecksum( 
checksumPath.toFile() );
+                    if ( checksum != null )
+                    {
+                        if ( LOGGER.isDebugEnabled() )
+                        {
+                            LOGGER.debug( "{} -> {}:{}", ArtifactIdUtils.toId( 
artifact ),

Review comment:
       Why does this one use `toId()` and the other one not?

##########
File path: 
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/AbstractChecksumPolicy.java
##########
@@ -41,26 +41,26 @@ protected AbstractChecksumPolicy( TransferResource resource 
)
     }
 
     @Override
-    public boolean onChecksumMatch( String algorithm, int kind )
+    public boolean onChecksumMatch( String algorithm, ChecksumKind kind )
     {
         requireNonNull( algorithm, "algorithm cannot be null" );
         return true;
     }
 
     @Override
-    public void onChecksumMismatch( String algorithm, int kind, 
ChecksumFailureException exception )
+    public void onChecksumMismatch( String algorithm, ChecksumKind kind, 
ChecksumFailureException exception )
             throws ChecksumFailureException
     {
         requireNonNull( algorithm, "algorithm cannot be null" );
         requireNonNull( exception, "exception cannot be null" );
-        if ( ( kind & KIND_UNOFFICIAL ) == 0 )
+        if ( ChecksumKind.REMOTE == kind )

Review comment:
       Why is `UNOFFICIAL` now remote?

##########
File path: 
maven-resolver-impl/src/main/java/org/eclipse/aether/impl/guice/AetherModule.java
##########
@@ -207,6 +212,17 @@ protected void configure()
 
     }
 
+    @Provides
+    @Singleton
+    Map<String, ProvidedChecksumsSource> provideDownloadChecksumSources(

Review comment:
       Stupid question: What is the purpose of `Download`? Is there going to be 
`Upload` as well?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to