001package org.apache.maven.model.resolution;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.maven.model.Parent;
023import org.apache.maven.model.Repository;
024import org.apache.maven.model.building.ModelSource;
025
026/**
027 * Resolves a POM from its coordinates. During the build process, the
028 * {@link org.apache.maven.model.building.ModelBuilder} will add any relevant repositories to the model resolver. In
029 * other words, the model resolver is stateful and should not be reused across multiple model building requests.
030 *
031 * @author Benjamin Bentmann
032 */
033public interface ModelResolver
034{
035
036    /**
037     * Tries to resolve the POM for the specified coordinates.
038     *
039     * @param groupId The group identifier of the POM, must not be {@code null}.
040     * @param artifactId The artifact identifier of the POM, must not be {@code null}.
041     * @param version The version of the POM, must not be {@code null}.
042     * @return The source of the requested POM, never {@code null}.
043     * @throws UnresolvableModelException If the POM could not be resolved from any configured repository.
044     */
045    ModelSource resolveModel( String groupId, String artifactId, String version )
046        throws UnresolvableModelException;
047
048    /**
049     * Tries to resolve the POM for the specified parent coordinates possibly updating {@code parent}.
050     *
051     * @param parent The parent coordinates to resolve, must not be {@code null}.
052     * @return The source of the requested POM, never {@code null}.
053     * @throws UnresolvableModelException If the POM could not be resolved from any configured repository.
054     * @since 3.2.2
055     */
056    ModelSource resolveModel( Parent parent )
057        throws UnresolvableModelException;
058
059    /**
060     * Adds a repository to use for subsequent resolution requests. The order in which repositories are added matters,
061     * repositories that were added first should also be searched first. When multiple repositories with the same
062     * identifier are added, only the first repository being added will be used.
063     *
064     * @param repository The repository to add to the internal search chain, must not be {@code null}.
065     * @throws InvalidRepositoryException If the repository could not be added (e.g. due to invalid URL or layout).
066     */
067    void addRepository( Repository repository )
068        throws InvalidRepositoryException;
069
070    /**
071     * Adds a repository to use for subsequent resolution requests. The order in which repositories are added matters,
072     * repositories that were added first should also be searched first. When multiple repositories with the same
073     * identifier are added, then the value of the replace argument is determines the behaviour.
074     *
075     * If replace is false than any existing repository with the same Id will remain in use. If replace
076     * is true the new repository replaces the original.
077     *
078     * @param repository The repository to add to the internal search chain, must not be {@code null}.
079     * @throws InvalidRepositoryException If the repository could not be added (e.g. due to invalid URL or layout).
080     */
081    void addRepository( Repository repository, boolean replace )
082            throws InvalidRepositoryException;
083
084    /**
085     * Clones this resolver for usage in a forked resolution process. In general, implementors need not provide a deep
086     * clone. The only requirement is that invocations of {@link #addRepository(Repository)} on the clone do not affect
087     * the state of the original resolver and vice versa.
088     *
089     * @return The cloned resolver, never {@code null}.
090     */
091    ModelResolver newCopy();
092
093}