Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
BobberArchetypeMojo |
|
| 8.0;8 |
1 | /* | |
2 | * Copyright 2001-2005 The Apache Software Foundation. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | ||
17 | package org.apache.maven.plugin.archetype; | |
18 | ||
19 | import java.util.HashMap; | |
20 | import java.util.List; | |
21 | import java.util.Map; | |
22 | ||
23 | import org.apache.maven.archetype.Archetype; | |
24 | import org.apache.maven.archetype.ArchetypeDescriptorException; | |
25 | import org.apache.maven.archetype.ArchetypeNotFoundException; | |
26 | import org.apache.maven.archetype.ArchetypeTemplateProcessingException; | |
27 | import org.apache.maven.artifact.repository.ArtifactRepository; | |
28 | import org.apache.maven.plugin.AbstractMojo; | |
29 | import org.apache.maven.plugin.MojoExecutionException; | |
30 | ||
31 | /** | |
32 | * Builds archetype containers. | |
33 | * | |
34 | * @goal create | |
35 | * @description The archetype creation goal looks for an archetype with a given groupId, artifactId, and | |
36 | * version and retrieves it from the remote repository. Once the archetype is retrieve it is process against | |
37 | * a set of user parameters to create a working Maven project. This is a modified version for bobber to support additional functionality. | |
38 | * @requiresProject false | |
39 | */ | |
40 | 0 | public class BobberArchetypeMojo |
41 | extends AbstractMojo | |
42 | { | |
43 | /** | |
44 | * @parameter expression="${component.org.apache.maven.archetype.Archetype}" | |
45 | * @required | |
46 | */ | |
47 | private Archetype archetype; | |
48 | ||
49 | /** | |
50 | * @parameter expression="${localRepository}" | |
51 | * @required | |
52 | */ | |
53 | private ArtifactRepository localRepository; | |
54 | ||
55 | /** | |
56 | * @parameter expression="${archetypeGroupId}" default-value="org.apache.maven.archetypes" | |
57 | * @required | |
58 | */ | |
59 | private String archetypeGroupId; | |
60 | ||
61 | /** | |
62 | * @parameter expression="${archetypeArtifactId}" default-value="maven-archetype-quickstart" | |
63 | * @required | |
64 | */ | |
65 | private String archetypeArtifactId; | |
66 | ||
67 | /** | |
68 | * @parameter expression="${archetypeVersion}" default-value="RELEASE" | |
69 | * @required | |
70 | */ | |
71 | private String archetypeVersion; | |
72 | ||
73 | /** | |
74 | * @parameter expression="${groupId}" | |
75 | * @required | |
76 | */ | |
77 | private String groupId; | |
78 | ||
79 | /** | |
80 | * @parameter expression="${artifactId}" | |
81 | * @required | |
82 | */ | |
83 | private String artifactId; | |
84 | ||
85 | /** | |
86 | * @parameter expression="${version}" default-value="1.0-SNAPSHOT" | |
87 | * @required | |
88 | */ | |
89 | private String version; | |
90 | ||
91 | /** @parameter expression="${packageName}" alias="package" */ | |
92 | private String packageName; | |
93 | ||
94 | /** | |
95 | * @parameter expression="${project.remoteArtifactRepositories}" | |
96 | * @required | |
97 | */ | |
98 | private List remoteRepositories; | |
99 | ||
100 | public void execute() | |
101 | throws MojoExecutionException | |
102 | { | |
103 | // TODO: prompt for missing values | |
104 | // TODO: configurable license | |
105 | ||
106 | // ---------------------------------------------------------------------- | |
107 | // archetypeGroupId | |
108 | // archetypeArtifactId | |
109 | // archetypeVersion | |
110 | // | |
111 | // localRepository | |
112 | // remoteRepository | |
113 | // parameters | |
114 | // ---------------------------------------------------------------------- | |
115 | ||
116 | 0 | String basedir = System.getProperty("user.dir"); |
117 | ||
118 | 0 | if (packageName == null) |
119 | { | |
120 | 0 | getLog().info("Defaulting package to group ID: " + groupId); |
121 | ||
122 | 0 | packageName = groupId; |
123 | } | |
124 | ||
125 | // TODO: context mojo more appropriate? | |
126 | 0 | Map map = new HashMap(); |
127 | ||
128 | 0 | map.put("basedir", basedir); |
129 | ||
130 | 0 | map.put("package", packageName); |
131 | ||
132 | 0 | map.put("packageName", packageName); |
133 | ||
134 | 0 | map.put("groupId", groupId); |
135 | ||
136 | 0 | map.put("artifactId", artifactId); |
137 | ||
138 | 0 | map.put("version", version); |
139 | ||
140 | ||
141 | try | |
142 | { | |
143 | 0 | archetype.createArchetype(archetypeGroupId, archetypeArtifactId, archetypeVersion, localRepository, remoteRepositories, map); |
144 | } | |
145 | 0 | catch (ArchetypeNotFoundException e) |
146 | { | |
147 | 0 | throw new MojoExecutionException("Error creating from archetype", e); |
148 | } | |
149 | 0 | catch (ArchetypeDescriptorException e) |
150 | { | |
151 | 0 | throw new MojoExecutionException("Error creating from archetype", e); |
152 | } | |
153 | 0 | catch (ArchetypeTemplateProcessingException e) |
154 | { | |
155 | 0 | throw new MojoExecutionException("Error creating from archetype", e); |
156 | 0 | } |
157 | 0 | } |
158 | ||
159 | ||
160 | } |