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.checksum;
20
21 import javax.inject.Inject;
22 import javax.inject.Named;
23 import javax.inject.Singleton;
24
25 import java.util.List;
26 import java.util.Map;
27
28 import org.eclipse.aether.RepositorySystemSession;
29 import org.eclipse.aether.artifact.Artifact;
30 import org.eclipse.aether.repository.RemoteRepository;
31 import org.eclipse.aether.spi.checksums.ProvidedChecksumsSource;
32 import org.eclipse.aether.spi.checksums.TrustedChecksumsSource;
33 import org.eclipse.aether.spi.connector.ArtifactDownload;
34 import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactory;
35
36 import static java.util.Objects.requireNonNull;
37
38
39
40
41
42
43
44 @Singleton
45 @Named(TrustedToProvidedChecksumsSourceAdapter.NAME)
46 public final class TrustedToProvidedChecksumsSourceAdapter implements ProvidedChecksumsSource {
47 public static final String NAME = "trusted2provided";
48
49 private final Map<String, TrustedChecksumsSource> trustedChecksumsSources;
50
51 @Inject
52 public TrustedToProvidedChecksumsSourceAdapter(Map<String, TrustedChecksumsSource> trustedChecksumsSources) {
53 this.trustedChecksumsSources = requireNonNull(trustedChecksumsSources);
54 }
55
56 @Override
57 public Map<String, String> getProvidedArtifactChecksums(
58 RepositorySystemSession session,
59 ArtifactDownload transfer,
60 RemoteRepository repository,
61 List<ChecksumAlgorithmFactory> checksumAlgorithmFactories) {
62 Artifact artifact = transfer.getArtifact();
63 Map<String, String> trustedChecksums;
64
65 for (TrustedChecksumsSource trustedChecksumsSource : trustedChecksumsSources.values()) {
66 trustedChecksums = trustedChecksumsSource.getTrustedArtifactChecksums(
67 session, artifact, repository, checksumAlgorithmFactories);
68 if (trustedChecksums != null && !trustedChecksums.isEmpty()) {
69 return trustedChecksums;
70 }
71 }
72
73 if (!transfer.getRepositories().isEmpty()) {
74 for (RemoteRepository remoteRepository : transfer.getRepositories()) {
75 for (TrustedChecksumsSource trustedChecksumsSource : trustedChecksumsSources.values()) {
76 trustedChecksums = trustedChecksumsSource.getTrustedArtifactChecksums(
77 session, artifact, remoteRepository, checksumAlgorithmFactories);
78 if (trustedChecksums != null && !trustedChecksums.isEmpty()) {
79 return trustedChecksums;
80 }
81 }
82 }
83 }
84 return null;
85 }
86 }