View Javadoc
1   package org.apache.maven.repository;
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.io.File;
23  import java.util.List;
24  
25  import org.apache.maven.artifact.Artifact;
26  import org.apache.maven.artifact.InvalidRepositoryException;
27  import org.apache.maven.artifact.repository.ArtifactRepository;
28  import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
29  import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
30  import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
31  import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
32  import org.apache.maven.model.Dependency;
33  import org.apache.maven.model.Plugin;
34  import org.apache.maven.model.Repository;
35  import org.apache.maven.settings.Mirror;
36  import org.apache.maven.settings.Server;
37  import org.eclipse.aether.RepositorySystemSession;
38  
39  /**
40   * @author Jason van Zyl
41   * @since 3.0-alpha
42   */
43  public interface RepositorySystem
44  {
45      String DEFAULT_LOCAL_REPO_ID = "local";
46  
47      @SuppressWarnings( "checkstyle:constantname" )
48      String userHome = System.getProperty( "user.home" );
49  
50      @SuppressWarnings( "checkstyle:constantname" )
51      File userMavenConfigurationHome = new File( userHome, ".m2" );
52  
53      @SuppressWarnings( "checkstyle:constantname" )
54      File defaultUserLocalRepository = new File( userMavenConfigurationHome, "repository" );
55  
56      String DEFAULT_REMOTE_REPO_ID = "central";
57  
58      String DEFAULT_REMOTE_REPO_URL = "https://repo.maven.apache.org/maven2";
59  
60      Artifact createArtifact( String groupId, String artifactId, String version, String packaging );
61  
62      Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type );
63  
64      Artifact createProjectArtifact( String groupId, String artifactId, String version );
65  
66      Artifact createArtifactWithClassifier( String groupId, String artifactId, String version, String type,
67                                             String classifier );
68  
69      Artifact createPluginArtifact( Plugin plugin );
70  
71      Artifact createDependencyArtifact( Dependency dependency );
72  
73      ArtifactRepository buildArtifactRepository( Repository repository )
74          throws InvalidRepositoryException;
75  
76      ArtifactRepository createDefaultRemoteRepository()
77          throws InvalidRepositoryException;
78  
79      ArtifactRepository createDefaultLocalRepository()
80          throws InvalidRepositoryException;
81  
82      ArtifactRepository createLocalRepository( File localRepository )
83          throws InvalidRepositoryException;
84  
85      ArtifactRepository createArtifactRepository( String id, String url, ArtifactRepositoryLayout repositoryLayout,
86                                                   ArtifactRepositoryPolicy snapshots,
87                                                   ArtifactRepositoryPolicy releases );
88  
89      /**
90       * Calculates the effective repositories for the given input repositories which are assumed to be already mirrored
91       * (if applicable). This process will essentially remove duplicate repositories by merging them into one equivalent
92       * repository. It is worth to point out that merging does not simply choose one of the input repositories and
93       * discards the others but actually combines their possibly different policies.
94       *
95       * @param repositories The original repositories, may be {@code null}.
96       * @return The effective repositories or {@code null} if the input was {@code null}.
97       */
98      List<ArtifactRepository> getEffectiveRepositories( List<ArtifactRepository> repositories );
99  
100     /**
101      * Determines the mirror for the specified repository.
102      *
103      * @param repository The repository to determine the mirror for, must not be {@code null}.
104      * @param mirrors The available mirrors, may be {@code null}.
105      * @return The mirror specification for the repository or {@code null} if no mirror matched.
106      */
107     Mirror getMirror( ArtifactRepository repository, List<Mirror> mirrors );
108 
109     /**
110      * Injects the mirroring information into the specified repositories. For each repository that is matched by a
111      * mirror, its URL and ID will be updated to match the values from the mirror specification. Repositories without a
112      * matching mirror will pass through unchanged. <em>Note:</em> This method must be called before
113      * {@link #injectAuthentication(List, List)} or the repositories will end up with the wrong credentials.
114      *
115      * @param repositories The repositories into which to inject the mirror information, may be {@code null}.
116      * @param mirrors The available mirrors, may be {@code null}.
117      */
118     void injectMirror( List<ArtifactRepository> repositories, List<Mirror> mirrors );
119 
120     /**
121      * Injects the proxy information into the specified repositories. For each repository that is matched by a proxy,
122      * its proxy data will be set accordingly. Repositories without a matching proxy will have their proxy cleared.
123      * <em>Note:</em> This method must be called after {@link #injectMirror(List, List)} or the repositories will end up
124      * with the wrong proxies.
125      *
126      * @param repositories The repositories into which to inject the proxy information, may be {@code null}.
127      * @param proxies The available proxies, may be {@code null}.
128      */
129     void injectProxy( List<ArtifactRepository> repositories, List<org.apache.maven.settings.Proxy> proxies );
130 
131     /**
132      * Injects the authentication information into the specified repositories. For each repository that is matched by a
133      * server, its credentials will be updated to match the values from the server specification. Repositories without a
134      * matching server will have their credentials cleared. <em>Note:</em> This method must be called after
135      * {@link #injectMirror(List, List)} or the repositories will end up with the wrong credentials.
136      *
137      * @param repositories The repositories into which to inject the authentication information, may be {@code null}.
138      * @param servers The available servers, may be {@code null}.
139      */
140     void injectAuthentication( List<ArtifactRepository> repositories, List<Server> servers );
141 
142     void injectMirror( RepositorySystemSession session, List<ArtifactRepository> repositories );
143 
144     void injectProxy( RepositorySystemSession session, List<ArtifactRepository> repositories );
145 
146     void injectAuthentication( RepositorySystemSession session, List<ArtifactRepository> repositories );
147 
148     ArtifactResolutionResult resolve( ArtifactResolutionRequest request );
149 
150     // Install
151 
152     // Deploy
153 
154     // Map types of artifacts
155 
156     //
157     // Raw file transfers
158     //
159     void publish( ArtifactRepository repository, File source, String remotePath,
160                   ArtifactTransferListener transferListener )
161         throws ArtifactTransferFailedException;
162 
163     void retrieve( ArtifactRepository repository, File destination, String remotePath,
164                    ArtifactTransferListener transferListener )
165         throws ArtifactTransferFailedException, ArtifactDoesNotExistException;
166 
167 }