001package org.apache.maven.repository;
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 java.io.File;
023import java.util.List;
024
025import org.apache.maven.artifact.Artifact;
026import org.apache.maven.artifact.InvalidRepositoryException;
027import org.apache.maven.artifact.repository.ArtifactRepository;
028import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
029import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
030import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
031import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
032import org.apache.maven.model.Dependency;
033import org.apache.maven.model.Plugin;
034import org.apache.maven.model.Repository;
035import org.apache.maven.settings.Mirror;
036import org.apache.maven.settings.Server;
037import org.eclipse.aether.RepositorySystemSession;
038
039/**
040 * @author Jason van Zyl
041 * @since 3.0-alpha
042 */
043public interface RepositorySystem
044{
045    String DEFAULT_LOCAL_REPO_ID = "local";
046
047    String userHome = System.getProperty( "user.home" );
048
049    File userMavenConfigurationHome = new File( userHome, ".m2" );
050
051    File defaultUserLocalRepository = new File( userMavenConfigurationHome, "repository" );
052
053    String DEFAULT_REMOTE_REPO_ID = "central";
054
055    String DEFAULT_REMOTE_REPO_URL = "http://repo.maven.apache.org/maven2";
056
057    Artifact createArtifact( String groupId, String artifactId, String version, String packaging );
058
059    Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type );
060
061    Artifact createProjectArtifact( String groupId, String artifactId, String version );
062
063    Artifact createArtifactWithClassifier( String groupId, String artifactId, String version, String type,
064                                           String classifier );
065
066    Artifact createPluginArtifact( Plugin plugin );
067
068    Artifact createDependencyArtifact( Dependency dependency );
069
070    ArtifactRepository buildArtifactRepository( Repository repository )
071        throws InvalidRepositoryException;
072
073    ArtifactRepository createDefaultRemoteRepository()
074        throws InvalidRepositoryException;
075
076    ArtifactRepository createDefaultLocalRepository()
077        throws InvalidRepositoryException;
078
079    ArtifactRepository createLocalRepository( File localRepository )
080        throws InvalidRepositoryException;
081
082    ArtifactRepository createArtifactRepository( String id, String url, ArtifactRepositoryLayout repositoryLayout,
083                                                 ArtifactRepositoryPolicy snapshots, ArtifactRepositoryPolicy releases );
084
085    /**
086     * Calculates the effective repositories for the given input repositories which are assumed to be already mirrored
087     * (if applicable). This process will essentially remove duplicate repositories by merging them into one equivalent
088     * repository. It is worth to point out that merging does not simply choose one of the input repositories and
089     * discards the others but actually combines their possibly different policies.
090     *
091     * @param repositories The original repositories, may be {@code null}.
092     * @return The effective repositories or {@code null} if the input was {@code null}.
093     */
094    List<ArtifactRepository> getEffectiveRepositories( List<ArtifactRepository> repositories );
095
096    /**
097     * Determines the mirror for the specified repository.
098     *
099     * @param repository The repository to determine the mirror for, must not be {@code null}.
100     * @param mirrors The available mirrors, may be {@code null}.
101     * @return The mirror specification for the repository or {@code null} if no mirror matched.
102     */
103    Mirror getMirror( ArtifactRepository repository, List<Mirror> mirrors );
104
105    /**
106     * Injects the mirroring information into the specified repositories. For each repository that is matched by a
107     * mirror, its URL and ID will be updated to match the values from the mirror specification. Repositories without a
108     * matching mirror will pass through unchanged. <em>Note:</em> This method must be called before
109     * {@link #injectAuthentication(List, List)} or the repositories will end up with the wrong credentials.
110     *
111     * @param repositories The repositories into which to inject the mirror information, may be {@code null}.
112     * @param mirrors The available mirrors, may be {@code null}.
113     */
114    void injectMirror( List<ArtifactRepository> repositories, List<Mirror> mirrors );
115
116    /**
117     * Injects the proxy information into the specified repositories. For each repository that is matched by a proxy,
118     * its proxy data will be set accordingly. Repositories without a matching proxy will have their proxy cleared.
119     * <em>Note:</em> This method must be called after {@link #injectMirror(List, List)} or the repositories will end up
120     * with the wrong proxies.
121     *
122     * @param repositories The repositories into which to inject the proxy information, may be {@code null}.
123     * @param proxies The available proxies, may be {@code null}.
124     */
125    void injectProxy( List<ArtifactRepository> repositories, List<org.apache.maven.settings.Proxy> proxies );
126
127    /**
128     * Injects the authentication information into the specified repositories. For each repository that is matched by a
129     * server, its credentials will be updated to match the values from the server specification. Repositories without a
130     * matching server will have their credentials cleared. <em>Note:</em> This method must be called after
131     * {@link #injectMirror(List, List)} or the repositories will end up with the wrong credentials.
132     *
133     * @param repositories The repositories into which to inject the authentication information, may be {@code null}.
134     * @param servers The available servers, may be {@code null}.
135     */
136    void injectAuthentication( List<ArtifactRepository> repositories, List<Server> servers );
137
138    void injectMirror( RepositorySystemSession session, List<ArtifactRepository> repositories );
139
140    void injectProxy( RepositorySystemSession session, List<ArtifactRepository> repositories );
141
142    void injectAuthentication( RepositorySystemSession session, List<ArtifactRepository> repositories );
143    
144    ArtifactResolutionResult resolve( ArtifactResolutionRequest request );
145
146    // Install
147
148    // Deploy
149
150    // Map types of artifacts
151
152    //
153    // Raw file transfers
154    //
155    void publish( ArtifactRepository repository, File source, String remotePath,
156                  ArtifactTransferListener transferListener )
157        throws ArtifactTransferFailedException;
158
159    void retrieve( ArtifactRepository repository, File destination, String remotePath,
160                   ArtifactTransferListener transferListener )
161        throws ArtifactTransferFailedException, ArtifactDoesNotExistException;
162
163}