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.remoterepo;
20
21 import org.eclipse.aether.ConfigurationProperties;
22 import org.eclipse.aether.RepositorySystemSession;
23 import org.eclipse.aether.repository.RepositoryKeyFunction;
24
25 /**
26 * A factory to create {@link RepositoryKeyFunction} instances.
27 *
28 * @since 2.0.14
29 */
30 public interface RepositoryKeyFunctionFactory {
31 /**
32 * Returns system-wide repository key function.
33 *
34 * @param session The repository session, must not be {@code null}.
35 * @return The repository key function.
36 * @see #repositoryKeyFunction(Class, RepositorySystemSession, String, String)
37 * @see org.eclipse.aether.ConfigurationProperties#REPOSITORY_SYSTEM_REPOSITORY_KEY_FUNCTION
38 */
39 default RepositoryKeyFunction systemRepositoryKeyFunction(RepositorySystemSession session) {
40 return repositoryKeyFunction(
41 RepositoryKeyFunctionFactory.class,
42 session,
43 ConfigurationProperties.DEFAULT_REPOSITORY_SYSTEM_REPOSITORY_KEY_FUNCTION,
44 ConfigurationProperties.REPOSITORY_SYSTEM_REPOSITORY_KEY_FUNCTION);
45 }
46
47 /**
48 * Returns system-wide tracking repository key function.
49 *
50 * @param session The repository session, must not be {@code null}.
51 * @return The repository key function.
52 * @see #repositoryKeyFunction(Class, RepositorySystemSession, String, String)
53 * @see org.eclipse.aether.ConfigurationProperties#REPOSITORY_TRACKING_REPOSITORY_KEY_FUNCTION
54 * @since 2.0.23
55 */
56 default RepositoryKeyFunction trackingRepositoryKeyFunction(RepositorySystemSession session) {
57 return repositoryKeyFunction(
58 RepositoryKeyFunctionFactory.class,
59 session,
60 ConfigurationProperties.DEFAULT_REPOSITORY_TRACKING_REPOSITORY_KEY_FUNCTION,
61 ConfigurationProperties.REPOSITORY_TRACKING_REPOSITORY_KEY_FUNCTION);
62 }
63
64 /**
65 * Method that based on configuration returns the "repository key function". The returned function will be session
66 * cached if session is equipped with cache, otherwise it will be non cached. Method never returns {@code null}.
67 * Only the {@code configurationKey} parameter may be {@code null} in which case no configuration lookup happens
68 * but the {@code defaultValue} is directly used instead.
69 *
70 * @param owner The "owner" of key function (used to create cache-key), must not be {@code null}.
71 * @param session The repository session, must not be {@code null}.
72 * @param defaultValue The default value of repository key configuration, must not be {@code null}.
73 * @param configurationKey The configuration key to lookup configuration from, may be {@code null}, in which case
74 * no configuration lookup happens but the {@code defaultValue} is used to create the
75 * repository key function.
76 * @return The repository key function.
77 */
78 RepositoryKeyFunction repositoryKeyFunction(
79 Class<?> owner, RepositorySystemSession session, String defaultValue, String configurationKey);
80 }