1 package org.apache.maven.model.resolution; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.util.concurrent.atomic.AtomicReference; 23 24 import org.apache.maven.api.model.Dependency; 25 import org.apache.maven.api.model.Parent; 26 import org.apache.maven.api.model.Repository; 27 import org.apache.maven.model.building.ModelSource; 28 29 /** 30 * Resolves a POM from its coordinates. During the build process, the 31 * {@link org.apache.maven.model.building.ModelBuilder} will add any relevant repositories to the model resolver. In 32 * other words, the model resolver is stateful and should not be reused across multiple model building requests. 33 * 34 * @author Benjamin Bentmann 35 */ 36 public interface ModelResolver 37 { 38 39 /** 40 * Tries to resolve the POM for the specified coordinates. 41 * 42 * @param groupId The group identifier of the POM, must not be {@code null}. 43 * @param artifactId The artifact identifier of the POM, must not be {@code null}. 44 * @param version The version of the POM, must not be {@code null}. 45 * @return The source of the requested POM, never {@code null}. 46 * @throws UnresolvableModelException If the POM could not be resolved from any configured repository. 47 */ 48 ModelSource resolveModel( String groupId, String artifactId, String version ) 49 throws UnresolvableModelException; 50 51 /** 52 * Tries to resolve the POM for the specified parent coordinates possibly updating {@code parent}. 53 * <p> 54 * Unlike the {@link #resolveModel(java.lang.String, java.lang.String, java.lang.String)} method, this method 55 * supports version ranges and updates the given {@code parent} instance to match the returned {@code ModelSource}. 56 * If {@code parent} declares a version range, the version corresponding to the returned {@code ModelSource} will 57 * be set on the given {@code parent}. 58 * </p> 59 * 60 * @param parent The parent coordinates to resolve, must not be {@code null}. 61 * 62 * @return The source of the requested POM, never {@code null}. 63 * 64 * @throws UnresolvableModelException If the POM could not be resolved from any configured repository. 65 * @since 3.2.2 66 * 67 * @see Parent#clone() 68 */ 69 ModelSource resolveModel( org.apache.maven.model.Parent parent ) 70 throws UnresolvableModelException; 71 72 /** 73 * Tries to resolve the POM for the specified dependency coordinates possibly updating {@code dependency}. 74 * <p> 75 * Unlike the {@link #resolveModel(java.lang.String, java.lang.String, java.lang.String)} method, this method 76 * supports version ranges and updates the given {@code dependency} instance to match the returned 77 * {@code ModelSource}. If {@code dependency} declares a version range, the version corresponding to the returned 78 * {@code ModelSource} will be set on the given {@code dependency}. 79 * </p> 80 * 81 * @param dependency The dependency coordinates to resolve, must not be {@code null}. 82 * 83 * @return The source of the requested POM, never {@code null}. 84 * 85 * @throws UnresolvableModelException If the POM could not be resolved from any configured repository. 86 * @since 3.5.0 87 * 88 * @see Dependency#clone() 89 */ 90 ModelSource resolveModel( org.apache.maven.model.Dependency dependency ) 91 throws UnresolvableModelException; 92 93 /** 94 * Adds a repository to use for subsequent resolution requests. The order in which repositories are added matters, 95 * repositories that were added first should also be searched first. When multiple repositories with the same 96 * identifier are added, only the first repository being added will be used. 97 * 98 * @param repository The repository to add to the internal search chain, must not be {@code null}. 99 * @throws InvalidRepositoryException If the repository could not be added (e.g. due to invalid URL or layout). 100 */ 101 void addRepository( org.apache.maven.model.Repository repository ) 102 throws InvalidRepositoryException; 103 104 /** 105 * Adds a repository to use for subsequent resolution requests. The order in which repositories are added matters, 106 * repositories that were added first should also be searched first. When multiple repositories with the same 107 * identifier are added, then the value of the replace argument determines the behaviour. 108 * 109 * If replace is false then any existing repository with the same Id will remain in use. If replace 110 * is true the new repository replaces the original. 111 * 112 * @param repository The repository to add to the internal search chain, must not be {@code null}. 113 * @throws InvalidRepositoryException If the repository could not be added (e.g. due to invalid URL or layout). 114 */ 115 void addRepository( org.apache.maven.model.Repository repository, boolean replace ) 116 throws InvalidRepositoryException; 117 118 /** 119 * Clones this resolver for usage in a forked resolution process. In general, implementors need not provide a deep 120 * clone. The only requirement is that invocations of {@link #addRepository(Repository)} on the clone do not affect 121 * the state of the original resolver and vice versa. 122 * 123 * @return The cloned resolver, never {@code null}. 124 */ 125 ModelResolver newCopy(); 126 127 default ModelSource resolveModel( Parent parent, AtomicReference<Parent> modified ) 128 throws UnresolvableModelException 129 { 130 org.apache.maven.model.Parent p = new org.apache.maven.model.Parent( parent ); 131 ModelSource result = resolveModel( p ); 132 if ( p.getDelegate() != parent ) 133 { 134 modified.set( p.getDelegate() ); 135 } 136 return result; 137 } 138 139 default ModelSource resolveModel( Dependency dependency, AtomicReference<Dependency> modified ) 140 throws UnresolvableModelException 141 { 142 org.apache.maven.model.Dependency d = new org.apache.maven.model.Dependency( dependency ); 143 ModelSource result = resolveModel( d ); 144 if ( d.getDelegate() != dependency ) 145 { 146 modified.set( d.getDelegate() ); 147 } 148 return result; 149 } 150 151 default void addRepository( Repository repository ) 152 throws InvalidRepositoryException 153 { 154 addRepository( new org.apache.maven.model.Repository( repository ) ); 155 } 156 157 default void addRepository( Repository repository, boolean replace ) 158 throws InvalidRepositoryException 159 { 160 addRepository( new org.apache.maven.model.Repository( repository ), replace ); 161 } 162 }