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