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