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