1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.eclipse.aether.spi.checksums;
20
21 import java.util.List;
22 import java.util.Map;
23
24 import org.eclipse.aether.RepositorySystemSession;
25 import org.eclipse.aether.repository.RemoteRepository;
26 import org.eclipse.aether.spi.connector.ArtifactDownload;
27 import org.eclipse.aether.spi.connector.MetadataDownload;
28 import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactory;
29 import org.eclipse.aether.spi.connector.checksum.ChecksumPolicy;
30
31 /**
32 * Component able to provide (expected) checksums to connector beforehand the download happens. Checksum provided by
33 * this component are of kind {@link ChecksumPolicy.ChecksumKind#PROVIDED}. Resolver by default provides one
34 * implementation: an adapter, that makes {@link TrustedChecksumsSource} into {@link ProvidedChecksumsSource}. Users
35 * are encouraged to rely on this adapter, and do not create their own implementations.
36 *
37 * @since 1.9.14
38 */
39 public interface ProvidedChecksumsSource {
40 /**
41 * May return the provided checksums (for given artifact transfer) from source other than remote repository, or
42 * {@code null} if it have no checksums available for given transfer. Provided checksums are "opt-in" for
43 * transfer, in a way IF they are available upfront, they will be enforced according to checksum policy
44 * in effect. Otherwise, provided checksum verification is completely left out.
45 * <p>
46 * For enabled provided checksum source is completely acceptable to return {@code null} values, as that carries
47 * the meaning "nothing to add here", as there are no checksums to be provided upfront transfer. Semantically, this
48 * is equivalent to returning empty map, but signals the intent better.
49 *
50 * @param session The current session.
51 * @param transfer The transfer that is about to be executed.
52 * @param remoteRepository The remote repository connector is about to contact.
53 * @param checksumAlgorithmFactories The checksum algorithms that are expected.
54 * @return Map of expected checksums, or {@code null}.
55 */
56 Map<String, String> getProvidedArtifactChecksums(
57 RepositorySystemSession session,
58 ArtifactDownload transfer,
59 RemoteRepository remoteRepository,
60 List<ChecksumAlgorithmFactory> checksumAlgorithmFactories);
61
62 /**
63 * May return the provided checksums (for given metadata transfer) from source other than remote repository,
64 * or {@code null} if it has no checksums available for given transfer. Semantics are the same as for
65 * {@link #getProvidedArtifactChecksums(RepositorySystemSession, ArtifactDownload, RemoteRepository, List)},
66 * but covering metadata downloads: metadata like {@code maven-metadata.xml} influences resolution decisions
67 * (for example version range selection), so it should be coverable by the strongest configured integrity
68 * source just like artifacts are.
69 * <p>
70 * The default implementation returns {@code null} ("nothing to add here"), preserving the behavior of
71 * implementations written before this method existed.
72 *
73 * @param session The current session.
74 * @param transfer The metadata transfer that is about to be executed.
75 * @param remoteRepository The remote repository connector is about to contact.
76 * @param checksumAlgorithmFactories The checksum algorithms that are expected.
77 * @return Map of expected checksums, or {@code null}.
78 * @since 2.0.23
79 */
80 default Map<String, String> getProvidedMetadataChecksums(
81 RepositorySystemSession session,
82 MetadataDownload transfer,
83 RemoteRepository remoteRepository,
84 List<ChecksumAlgorithmFactory> checksumAlgorithmFactories) {
85 return null;
86 }
87 }