1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.internal.impl;
20
21 import javax.inject.Inject;
22 import javax.inject.Named;
23 import javax.inject.Singleton;
24
25 import java.util.Arrays;
26 import java.util.Set;
27 import java.util.stream.Collectors;
28
29 import org.eclipse.aether.ConfigurationProperties;
30 import org.eclipse.aether.RepositorySystemSession;
31 import org.eclipse.aether.spi.artifact.ArtifactPredicate;
32 import org.eclipse.aether.spi.artifact.ArtifactPredicateFactory;
33 import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactorySelector;
34 import org.eclipse.aether.util.ConfigUtils;
35
36 @Singleton
37 @Named
38 public final class DefaultArtifactPredicateFactory implements ArtifactPredicateFactory {
39 private static final String CONFIG_PROPS_PREFIX = ConfigurationProperties.PREFIX_CHECKSUMS;
40
41
42
43
44
45
46
47
48
49
50
51 public static final String CONFIG_PROP_OMIT_CHECKSUMS_FOR_EXTENSIONS =
52 CONFIG_PROPS_PREFIX + "omitChecksumsForExtensions";
53
54 public static final String DEFAULT_OMIT_CHECKSUMS_FOR_EXTENSIONS = ".asc,.sigstore";
55
56 private final ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector;
57
58 @Inject
59 public DefaultArtifactPredicateFactory(ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector) {
60 this.checksumAlgorithmFactorySelector = checksumAlgorithmFactorySelector;
61 }
62
63 @Override
64 public ArtifactPredicate newInstance(RepositorySystemSession session) {
65
66 Set<String> omitChecksumsForExtensions = Arrays.stream(ConfigUtils.getString(
67 session,
68 DEFAULT_OMIT_CHECKSUMS_FOR_EXTENSIONS,
69 CONFIG_PROP_OMIT_CHECKSUMS_FOR_EXTENSIONS)
70 .split(","))
71 .filter(s -> s != null && !s.trim().isEmpty())
72 .collect(Collectors.toSet());
73
74
75 if (omitChecksumsForExtensions.stream().anyMatch(s -> !s.startsWith("."))) {
76 throw new IllegalArgumentException(String.format(
77 "The configuration %s contains illegal values: %s (all entries must start with '.' (dot))",
78 CONFIG_PROP_OMIT_CHECKSUMS_FOR_EXTENSIONS, omitChecksumsForExtensions));
79 }
80 return new DefaultArtifactPredicate(checksumAlgorithmFactorySelector, omitChecksumsForExtensions);
81 }
82 }