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:40 UTC
[maven-resolver] 09/19: Componentize filter factory, expand doco for 1.7.x behaviour
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 5b9a21e4285867e98fc3ee4169f399c73d15b743
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Fri Mar 11 12:33:07 2022 +0100
Componentize filter factory, expand doco for 1.7.x behaviour
---
.../eclipse/aether/impl/guice/AetherModule.java | 5 ++
.../impl/Maven2RepositoryLayoutFactory.java | 34 ++++----
.../checksum/ArtifactExtensionChecksumFilter.java | 62 ---------------
.../DefaultArtifactChecksumFilterFactory.java | 90 ++++++++++++++++++++++
.../impl/Maven2RepositoryLayoutFactoryTest.java | 5 +-
.../checksum/ArtifactChecksumFilterFactory.java | 36 +++++++++
src/site/markdown/configuration.md | 2 +-
7 files changed, 148 insertions(+), 86 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 9629dc9..bf6e5ab 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,6 +43,7 @@ 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;
@@ -84,6 +85,7 @@ 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;
@@ -170,6 +172,9 @@ 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 7e9c4eb..202fe3c 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,8 +26,6 @@ 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;
@@ -35,11 +33,12 @@ import javax.inject.Singleton;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.internal.impl.checksum.ArtifactExtensionChecksumFilter;
+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;
@@ -58,18 +57,16 @@ public final class Maven2RepositoryLayoutFactory
implements RepositoryLayoutFactory
{
- static final String CONFIG_PROP_CHECKSUMS_ALGORITHMS = "aether.checksums.algorithms";
+ public static final String CONFIG_PROP_CHECKSUMS_ALGORITHMS = "aether.checksums.algorithms";
static final String DEFAULT_CHECKSUMS_ALGORITHMS = "SHA-1,MD5";
- static final String CONFIG_PROP_OMIT_CHECKSUMS_FOR_EXTENSIONS = "aether.checksums.omitChecksumsForExtensions";
-
- 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;
@@ -81,13 +78,15 @@ public final class Maven2RepositoryLayoutFactory
@Deprecated
public Maven2RepositoryLayoutFactory()
{
- this( new DefaultChecksumAlgorithmFactorySelector() );
+ this( new DefaultChecksumAlgorithmFactorySelector(), new DefaultArtifactChecksumFilterFactory() );
}
@Inject
- public Maven2RepositoryLayoutFactory( ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector )
+ public Maven2RepositoryLayoutFactory( ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector,
+ ArtifactChecksumFilterFactory artifactChecksumFilterFactory )
{
this.checksumAlgorithmFactorySelector = requireNonNull( checksumAlgorithmFactorySelector );
+ this.artifactChecksumFilterFactory = requireNonNull( artifactChecksumFilterFactory );
}
/**
@@ -124,17 +123,10 @@ 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() );
-
- ArtifactExtensionChecksumFilter artifactChecksumFilter =
- new ArtifactExtensionChecksumFilter( omitChecksumsForExtensions );
-
- return new Maven2RepositoryLayout( checksumsAlgorithms, artifactChecksumFilter );
+ return new Maven2RepositoryLayout(
+ checksumsAlgorithms,
+ artifactChecksumFilterFactory.newInstance( session, repository )
+ );
}
private static class Maven2RepositoryLayout
diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/checksum/ArtifactExtensionChecksumFilter.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/checksum/ArtifactExtensionChecksumFilter.java
deleted file mode 100644
index ee2ae1e..0000000
--- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/checksum/ArtifactExtensionChecksumFilter.java
+++ /dev/null
@@ -1,62 +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.Set;
-
-import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.spi.connector.checksum.ArtifactChecksumFilter;
-
-import static java.util.Objects.requireNonNull;
-
-/**
- * Default implementation.
- *
- * @since 1.8.0
- */
-@Singleton
-@Named
-public class ArtifactExtensionChecksumFilter
- implements ArtifactChecksumFilter
-{
- private final Set<String> extensionsWithoutChecksums;
-
- public ArtifactExtensionChecksumFilter( 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/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
new file mode 100644
index 0000000..a7bea4c
--- /dev/null
+++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/checksum/DefaultArtifactChecksumFilterFactory.java
@@ -0,0 +1,90 @@
+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 c239165..81c5dfb 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,6 +28,7 @@ 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;
@@ -311,7 +312,7 @@ public class Maven2RepositoryLayoutFactoryTest
public void testSignatureChecksums_Force()
throws Exception
{
- session.setConfigProperty( Maven2RepositoryLayoutFactory.CONFIG_PROP_OMIT_CHECKSUMS_FOR_EXTENSIONS, "" );
+ session.setConfigProperty( DefaultArtifactChecksumFilterFactory.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 );
@@ -323,7 +324,7 @@ public class Maven2RepositoryLayoutFactoryTest
public void testCustomChecksumsIgnored()
throws Exception
{
- session.setConfigProperty( Maven2RepositoryLayoutFactory.CONFIG_PROP_OMIT_CHECKSUMS_FOR_EXTENSIONS, ".asc,.foo" );
+ session.setConfigProperty( DefaultArtifactChecksumFilterFactory.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/ArtifactChecksumFilterFactory.java b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ArtifactChecksumFilterFactory.java
new file mode 100644
index 0000000..d1df787
--- /dev/null
+++ b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ArtifactChecksumFilterFactory.java
@@ -0,0 +1,36 @@
+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/src/site/markdown/configuration.md b/src/site/markdown/configuration.md
index 3b19f01..adfa9a8 100644
--- a/src/site/markdown/configuration.md
+++ b/src/site/markdown/configuration.md
@@ -21,7 +21,7 @@ under the License.
Option | Type | Description | Default Value | Supports Repo ID Suffix
--- | --- | --- | --- | ---
`aether.artifactResolver.snapshotNormalization` | boolean | It replaces the timestamped snapshot file name with a filename containing the `SNAPSHOT` qualifier only. This only affects resolving/retrieving artifacts but not uploading those. | `true` | no
-`aether.checksums.omitChecksumsForExtensions` | String | Comma separated list of extensions (`.asc`) that should have checksums omitted. | `.asc` | no
+`aether.checksums.omitChecksumsForExtensions` | String | Comma separated list of extensions (`.asc`) that should have checksums omitted. Note: to achieve 1.7.x `aether.checksums.forSignature=true` behaviour, pass empty string as value for this property. | `.asc` | no
`aether.checksums.algorithms` | String | Comma separated list of checksum algorithms with which checksums are validated (downloaded) and generated (uploaded). Resolver by default supports following algorithms: `MD5`, `SHA-1`, `SHA-256` and `SHA-512`. New algorithms can be added by implementing `ChecksumAlgorithmFactory` component. | `"SHA-1,MD5"` | no
`aether.conflictResolver.verbose` | boolean | Flag controlling the conflict resolver's verbose mode. | `false` | no
`aether.connector.basic.threads` or `maven.artifact.threads` | int | Number of threads to use for uploading/downloading. | `5` | no