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