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.api.services;
20  
21  import java.util.concurrent.atomic.AtomicReference;
22  import java.util.function.Consumer;
23  
24  import org.apache.maven.api.Service;
25  import org.apache.maven.api.Session;
26  import org.apache.maven.api.annotations.Nonnull;
27  import org.apache.maven.api.model.Dependency;
28  import org.apache.maven.api.model.Parent;
29  
30  /**
31   * Resolves a POM from its coordinates.
32   */
33  public interface ModelResolver extends Service {
34  
35      /**
36       * Tries to resolve the POM for the specified parent coordinates possibly updating {@code parent}.
37       *
38       * @param session The session to use to resolve the model, must not be {@code null}.
39       * @param parent The parent coordinates to resolve, must not be {@code null}.
40       * @param modified a holder for the updated parent, must not be {@code null}.
41       * @return The source of the requested POM, never {@code null}.
42       * @throws ModelResolverException If the POM could not be resolved from any configured repository.
43       */
44      @Nonnull
45      default ModelSource resolveModel(
46              @Nonnull Session session, @Nonnull Parent parent, @Nonnull AtomicReference<Parent> modified)
47              throws ModelResolverException {
48          return resolveModel(
49                  session,
50                  parent.getGroupId(),
51                  parent.getArtifactId(),
52                  parent.getVersion(),
53                  version -> modified.set(parent.withVersion(version)));
54      }
55  
56      /**
57       * Tries to resolve the POM for the specified dependency coordinates possibly updating {@code dependency}.
58       *
59       * @param session The session to use to resolve the model, must not be {@code null}.
60       * @param dependency The dependency coordinates to resolve, must not be {@code null}.
61       * @param modified a holder for the updated dependency, must not be {@code null}.
62       * @return The source of the requested POM, never {@code null}.
63       * @throws ModelResolverException If the POM could not be resolved from any configured repository.
64       */
65      @Nonnull
66      default ModelSource resolveModel(
67              @Nonnull Session session, @Nonnull Dependency dependency, @Nonnull AtomicReference<Dependency> modified)
68              throws ModelResolverException {
69          return resolveModel(
70                  session,
71                  dependency.getGroupId(),
72                  dependency.getArtifactId(),
73                  dependency.getVersion(),
74                  version -> modified.set(dependency.withVersion(version)));
75      }
76  
77      @Nonnull
78      ModelSource resolveModel(
79              @Nonnull Session session,
80              @Nonnull String groupId,
81              @Nonnull String artifactId,
82              @Nonnull String version,
83              @Nonnull Consumer<String> resolvedVersion)
84              throws ModelResolverException;
85  }