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