View Javadoc
1   package org.apache.maven.artifact.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.util.ArrayList;
23  import java.util.List;
24  
25  import org.apache.maven.execution.MavenSession;
26  import org.apache.maven.project.MavenProject;
27  
28  /**
29   * Collects basic settings to access the repository system.
30   *
31   * @author Benjamin Bentmann
32   */
33  public class DefaultRepositoryRequest
34      implements RepositoryRequest
35  {
36  
37      private boolean offline;
38  
39      private boolean forceUpdate;
40  
41      private ArtifactRepository localRepository;
42  
43      private List<ArtifactRepository> remoteRepositories;
44  
45      /**
46       * Creates an empty repository request.
47       */
48      public DefaultRepositoryRequest()
49      {
50          // enables no-arg constructor
51      }
52  
53      /**
54       * Creates a shallow copy of the specified repository request.
55       *
56       * @param repositoryRequest The repository request to copy from, must not be {@code null}.
57       */
58      public DefaultRepositoryRequest( RepositoryRequest repositoryRequest )
59      {
60          setLocalRepository( repositoryRequest.getLocalRepository() );
61          setRemoteRepositories( repositoryRequest.getRemoteRepositories() );
62          setOffline( repositoryRequest.isOffline() );
63          setForceUpdate( repositoryRequest.isForceUpdate() );
64      }
65  
66      public static RepositoryRequest getRepositoryRequest( MavenSession session, MavenProject project )
67      {
68          RepositoryRequest request = new DefaultRepositoryRequest();
69  
70          request.setLocalRepository( session.getLocalRepository() );
71          if ( project != null )
72          {
73              request.setRemoteRepositories( project.getPluginArtifactRepositories() );
74          }
75          request.setOffline( session.isOffline() );
76          request.setForceUpdate( session.getRequest().isUpdateSnapshots() );
77  
78          return request;
79      }
80  
81      public boolean isOffline()
82      {
83          return offline;
84      }
85  
86      public DefaultRepositoryRequest setOffline( boolean offline )
87      {
88          this.offline = offline;
89  
90          return this;
91      }
92  
93      public boolean isForceUpdate()
94      {
95          return forceUpdate;
96      }
97  
98      public DefaultRepositoryRequest setForceUpdate( boolean forceUpdate )
99      {
100         this.forceUpdate = forceUpdate;
101 
102         return this;
103     }
104 
105     public ArtifactRepository getLocalRepository()
106     {
107         return localRepository;
108     }
109 
110     public DefaultRepositoryRequest setLocalRepository( ArtifactRepository localRepository )
111     {
112         this.localRepository = localRepository;
113 
114         return this;
115     }
116 
117     public List<ArtifactRepository> getRemoteRepositories()
118     {
119         if ( remoteRepositories == null )
120         {
121             remoteRepositories = new ArrayList<>();
122         }
123 
124         return remoteRepositories;
125     }
126 
127     public DefaultRepositoryRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories )
128     {
129         this.remoteRepositories = remoteRepositories;
130 
131         return this;
132     }
133 
134 }