View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.archetype;
20  
21  import java.util.Collections;
22  import java.util.List;
23  import java.util.Properties;
24  
25  import org.apache.maven.archetype.catalog.Archetype;
26  import org.apache.maven.artifact.repository.ArtifactRepository;
27  import org.apache.maven.execution.MavenSession;
28  import org.apache.maven.project.ProjectBuildingRequest;
29  import org.eclipse.aether.RepositorySystem;
30  import org.eclipse.aether.RepositorySystemSession;
31  import org.eclipse.aether.repository.RemoteRepository;
32  
33  /**
34   * <b>NOTICE</b> all setters method are public for technical reasons, should be recognised as internals,
35   * so should not be used directly.
36   *
37   * @author Jason van Zyl
38   */
39  public class ArchetypeGenerationRequest {
40      private ProjectBuildingRequest projectBuildingRequest;
41  
42      private boolean offline;
43  
44      private MavenSession mavenSession;
45  
46      private RepositorySystemSession repositorySession;
47  
48      private RepositorySystem repositorySystem;
49  
50      private boolean interactiveMode;
51  
52      private boolean askForDefaultPropertyValues;
53  
54      private String outputDirectory;
55  
56      private ArtifactRepository localRepository;
57  
58      private List<ArtifactRepository> remoteArtifactRepositories;
59  
60      private List<RemoteRepository> remoteRepositories = Collections.emptyList();
61  
62      // Archetype definition
63      private String archetypeName;
64  
65      private String archetypeGroupId;
66  
67      private String archetypeArtifactId;
68  
69      private String archetypeVersion;
70  
71      private String archetypeGoals = "";
72  
73      /**
74       * The URL to the archetype repository
75       *
76       * @deprecated see ARCHETYPE-439
77       */
78      @Deprecated
79      private String archetypeRepository;
80  
81      // Archetype configuration
82      private String groupId;
83  
84      private String artifactId;
85  
86      private String version;
87  
88      private String packageName;
89  
90      private Properties properties = new Properties();
91  
92      /**
93       * @since 2.1
94       */
95      private String filter;
96  
97      public ArchetypeGenerationRequest() {
98          // no op
99      }
100 
101     public ArchetypeGenerationRequest(Archetype archetype) {
102         this.archetypeGroupId = archetype.getGroupId();
103         this.archetypeArtifactId = archetype.getArtifactId();
104         this.archetypeVersion = archetype.getVersion();
105         this.archetypeRepository = archetype.getRepository();
106     }
107 
108     public MavenSession getMavenSession() {
109         return mavenSession;
110     }
111 
112     public ArchetypeGenerationRequest setMavenSession(MavenSession mavenSession) {
113         this.mavenSession = mavenSession;
114         return this;
115     }
116 
117     public RepositorySystemSession getRepositorySession() {
118         return repositorySession;
119     }
120 
121     public ArchetypeGenerationRequest setRepositorySession(RepositorySystemSession repoSession) {
122         this.repositorySession = repoSession;
123         return this;
124     }
125 
126     public RepositorySystem getRepositorySystem() {
127         return repositorySystem;
128     }
129 
130     public ArchetypeGenerationRequest setRepositorySystem(RepositorySystem repositorySystem) {
131         this.repositorySystem = repositorySystem;
132         return this;
133     }
134 
135     /**
136      * @deprecated please use {@link #getMavenSession()} and {@link MavenSession#getProjectBuildingRequest()}
137      */
138     @Deprecated
139     public ProjectBuildingRequest getProjectBuildingRequest() {
140         return projectBuildingRequest;
141     }
142 
143     public ArchetypeGenerationRequest setProjectBuildingRequest(ProjectBuildingRequest projectBuildingRequest) {
144         this.projectBuildingRequest = projectBuildingRequest;
145         return this;
146     }
147 
148     public String getArchetypeGroupId() {
149         return archetypeGroupId;
150     }
151 
152     public ArchetypeGenerationRequest setArchetypeGroupId(String archetypeGroupId) {
153         this.archetypeGroupId = archetypeGroupId;
154         return this;
155     }
156 
157     public String getArchetypeArtifactId() {
158         return archetypeArtifactId;
159     }
160 
161     public ArchetypeGenerationRequest setArchetypeArtifactId(String archetypeArtifactId) {
162         this.archetypeArtifactId = archetypeArtifactId;
163         return this;
164     }
165 
166     public String getArchetypeVersion() {
167         return archetypeVersion;
168     }
169 
170     public ArchetypeGenerationRequest setArchetypeVersion(String archetypeVersion) {
171         this.archetypeVersion = archetypeVersion;
172         return this;
173     }
174 
175     public String getArchetypeGoals() {
176         return archetypeGoals;
177     }
178 
179     public ArchetypeGenerationRequest setArchetypeGoals(String archetypeGoals) {
180         this.archetypeGoals = archetypeGoals;
181         return this;
182     }
183 
184     public String getArchetypeName() {
185         return archetypeName;
186     }
187 
188     public ArchetypeGenerationRequest setArchetypeName(String archetypeName) {
189         this.archetypeName = archetypeName;
190         return this;
191     }
192 
193     /**
194      * @return the URL of the archetype repository
195      * @deprecated see ARCHETYPE-439
196      */
197     @Deprecated
198     public String getArchetypeRepository() {
199         return archetypeRepository;
200     }
201 
202     /**
203      * @param archetypeRepository the URL of the archetype repository
204      * @return this request
205      * @deprecated see ARCHETYPE-439
206      */
207     @Deprecated
208     public ArchetypeGenerationRequest setArchetypeRepository(String archetypeRepository) {
209         this.archetypeRepository = archetypeRepository;
210 
211         return this;
212     }
213 
214     public String getArtifactId() {
215         return artifactId;
216     }
217 
218     public ArchetypeGenerationRequest setArtifactId(String artifactId) {
219         this.artifactId = artifactId;
220         return this;
221     }
222 
223     public String getGroupId() {
224         return groupId;
225     }
226 
227     public ArchetypeGenerationRequest setGroupId(String groupId) {
228         this.groupId = groupId;
229         return this;
230     }
231 
232     public String getVersion() {
233         return version;
234     }
235 
236     public ArchetypeGenerationRequest setVersion(String version) {
237         this.version = version;
238         return this;
239     }
240 
241     public String getPackage() {
242         return packageName;
243     }
244 
245     public ArchetypeGenerationRequest setPackage(String packageName) {
246         this.packageName = packageName;
247         return this;
248     }
249 
250     public Properties getProperties() {
251         return properties;
252     }
253 
254     public ArchetypeGenerationRequest setProperties(Properties additionalProperties) {
255         this.properties = additionalProperties;
256 
257         return this;
258     }
259 
260     /**
261      * @deprecated please use {@link #getRepositorySession()} and {@link RepositorySystemSession#getLocalRepository()}
262      */
263     @Deprecated
264     public ArtifactRepository getLocalRepository() {
265         return localRepository;
266     }
267 
268     public ArchetypeGenerationRequest setLocalRepository(ArtifactRepository localRepository) {
269         this.localRepository = localRepository;
270 
271         return this;
272     }
273 
274     public String getOutputDirectory() {
275         return outputDirectory;
276     }
277 
278     public ArchetypeGenerationRequest setOutputDirectory(String outputDirectory) {
279         this.outputDirectory = outputDirectory;
280         return this;
281     }
282 
283     public boolean isInteractiveMode() {
284         return interactiveMode;
285     }
286 
287     public ArchetypeGenerationRequest setInteractiveMode(boolean interactiveMode) {
288         this.interactiveMode = interactiveMode;
289         return this;
290     }
291 
292     public boolean isAskForDefaultPropertyValues() {
293         return askForDefaultPropertyValues;
294     }
295 
296     public ArchetypeGenerationRequest setAskForDefaultPropertyValues(boolean askForDefaultPropertyValues) {
297         this.askForDefaultPropertyValues = askForDefaultPropertyValues;
298         return this;
299     }
300 
301     /**
302      * @deprecated please use {@link #getRepositorySession()} and {@link RepositorySystemSession#isOffline()}
303      *         or {@link #getMavenSession()} and {@link MavenSession#isOffline()}
304      */
305     @Deprecated
306     public boolean isOffline() {
307         return offline;
308     }
309 
310     public ArchetypeGenerationRequest setOffline(boolean offline) {
311         this.offline = offline;
312         return this;
313     }
314 
315     /**
316      * @deprecated please use {@link #getRemoteRepositories()}
317      */
318     @Deprecated
319     public List<ArtifactRepository> getRemoteArtifactRepositories() {
320         return remoteArtifactRepositories;
321     }
322 
323     public ArchetypeGenerationRequest setRemoteArtifactRepositories(
324             List<ArtifactRepository> remoteArtifactRepositories) {
325         this.remoteArtifactRepositories = remoteArtifactRepositories;
326 
327         return this;
328     }
329 
330     public List<RemoteRepository> getRemoteRepositories() {
331         return remoteRepositories;
332     }
333 
334     public ArchetypeGenerationRequest setRemoteRepositories(List<RemoteRepository> remoteRepositories) {
335         this.remoteRepositories = remoteRepositories;
336         return this;
337     }
338 
339     public String getFilter() {
340         return filter;
341     }
342 
343     public ArchetypeGenerationRequest setFilter(String filter) {
344         this.filter = filter;
345         return this;
346     }
347 }