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.apache.maven.model.resolution;
20
21 import org.apache.maven.model.Dependency;
22 import org.apache.maven.model.Parent;
23 import org.apache.maven.model.Repository;
24 import org.apache.maven.model.building.ModelSource;
25
26 /**
27 * Resolves a POM from its coordinates. During the build process, the
28 * {@link org.apache.maven.model.building.ModelBuilder} will add any relevant repositories to the model resolver. In
29 * other words, the model resolver is stateful and should not be reused across multiple model building requests.
30 *
31 * @author Benjamin Bentmann
32 */
33 public interface ModelResolver {
34
35 /**
36 * Tries to resolve the POM for the specified coordinates.
37 *
38 * @param groupId The group identifier of the POM, must not be {@code null}.
39 * @param artifactId The artifact identifier of the POM, must not be {@code null}.
40 * @param version The version of the POM, must not be {@code null}.
41 * @return The source of the requested POM, never {@code null}.
42 * @throws UnresolvableModelException If the POM could not be resolved from any configured repository.
43 */
44 ModelSource resolveModel(String groupId, String artifactId, String version) throws UnresolvableModelException;
45
46 /**
47 * Tries to resolve the POM for the specified parent coordinates possibly updating {@code parent}.
48 * <p>
49 * Unlike the {@link #resolveModel(java.lang.String, java.lang.String, java.lang.String)} method, this method
50 * supports version ranges and updates the given {@code parent} instance to match the returned {@code ModelSource}.
51 * If {@code parent} declares a version range, the version corresponding to the returned {@code ModelSource} will
52 * be set on the given {@code parent}.
53 * </p>
54 *
55 * @param parent The parent coordinates to resolve, must not be {@code null}.
56 *
57 * @return The source of the requested POM, never {@code null}.
58 *
59 * @throws UnresolvableModelException If the POM could not be resolved from any configured repository.
60 * @since 3.2.2
61 *
62 * @see Parent#clone()
63 */
64 ModelSource resolveModel(Parent parent) throws UnresolvableModelException;
65
66 /**
67 * Tries to resolve the POM for the specified dependency coordinates possibly updating {@code dependency}.
68 * <p>
69 * Unlike the {@link #resolveModel(java.lang.String, java.lang.String, java.lang.String)} method, this method
70 * supports version ranges and updates the given {@code dependency} instance to match the returned
71 * {@code ModelSource}. If {@code dependency} declares a version range, the version corresponding to the returned
72 * {@code ModelSource} will be set on the given {@code dependency}.
73 * </p>
74 *
75 * @param dependency The dependency coordinates to resolve, must not be {@code null}.
76 *
77 * @return The source of the requested POM, never {@code null}.
78 *
79 * @throws UnresolvableModelException If the POM could not be resolved from any configured repository.
80 * @since 3.5.0
81 *
82 * @see Dependency#clone()
83 */
84 ModelSource resolveModel(Dependency dependency) throws UnresolvableModelException;
85
86 /**
87 * Adds a repository to use for subsequent resolution requests. The order in which repositories are added matters,
88 * repositories that were added first should also be searched first. When multiple repositories with the same
89 * identifier are added, only the first repository being added will be used.
90 *
91 * @param repository The repository to add to the internal search chain, must not be {@code null}.
92 * @throws InvalidRepositoryException If the repository could not be added (e.g. due to invalid URL or layout).
93 */
94 void addRepository(Repository repository) throws InvalidRepositoryException;
95
96 /**
97 * Adds a repository to use for subsequent resolution requests. The order in which repositories are added matters,
98 * repositories that were added first should also be searched first. When multiple repositories with the same
99 * identifier are added, then the value of the replace argument is determines the behaviour.
100 *
101 * If replace is false than any existing repository with the same Id will remain in use. If replace
102 * is true the new repository replaces the original.
103 *
104 * @param repository The repository to add to the internal search chain, must not be {@code null}.
105 * @throws InvalidRepositoryException If the repository could not be added (e.g. due to invalid URL or layout).
106 */
107 void addRepository(Repository repository, boolean replace) throws InvalidRepositoryException;
108
109 /**
110 * Clones this resolver for usage in a forked resolution process. In general, implementors need not provide a deep
111 * clone. The only requirement is that invocations of {@link #addRepository(Repository)} on the clone do not affect
112 * the state of the original resolver and vice versa.
113 *
114 * @return The cloned resolver, never {@code null}.
115 */
116 ModelResolver newCopy();
117 }