Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ProjectArchetypeMojo |
|
| 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.mule.tools.maven.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 newGroupId, newArtifactId, and | |
36 | * newVersion 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 newVersion for bobber to support additional functionality. | |
38 | * @requiresProject false | |
39 | */ | |
40 | 0 | public class ProjectArchetypeMojo extends AbstractMojo |
41 | { | |
42 | /** | |
43 | * @parameter expression="${component.org.apache.maven.archetype.Archetype}" | |
44 | * @required | |
45 | */ | |
46 | private Archetype archetype; | |
47 | ||
48 | /** | |
49 | * @parameter expression="${localRepository}" | |
50 | * @required | |
51 | */ | |
52 | private ArtifactRepository localRepository; | |
53 | ||
54 | /** | |
55 | * @parameter expression="${archetypeGroupId}" default-value="org.mule.tools" | |
56 | * @required | |
57 | */ | |
58 | private String archetypeGroupId; | |
59 | ||
60 | /** | |
61 | * @parameter expression="${archetypeArtifactId}" default-value="mule-project-archetype" | |
62 | * @required | |
63 | */ | |
64 | private String archetypeArtifactId; | |
65 | ||
66 | /** | |
67 | * @parameter expression="${archetypeVersion}" default-value="${muleVersion}" | |
68 | * @required | |
69 | */ | |
70 | private String archetypeVersion; | |
71 | ||
72 | /** | |
73 | * @parameter expression="${muleVersion}" | |
74 | * @required | |
75 | */ | |
76 | private String muleVersion; | |
77 | ||
78 | /** | |
79 | * @parameter expression="${groupId}" alias="newGroupId" default-value="com.mycompany.mule" | |
80 | * @require | |
81 | */ | |
82 | private String groupId; | |
83 | ||
84 | /** | |
85 | * @parameter expression="${artifactId}" alias="newArtifactId" default-value="my-mule-project" | |
86 | * @require | |
87 | */ | |
88 | private String artifactId; | |
89 | ||
90 | /** | |
91 | * @parameter expression="${version}" alias="newVersion" default-value="1.0-SNAPSHOT" | |
92 | * @require | |
93 | */ | |
94 | private String version; | |
95 | ||
96 | /** @parameter expression="${packageName}" alias="package" */ | |
97 | private String packageName; | |
98 | ||
99 | /** | |
100 | * @parameter expression="${project.remoteArtifactRepositories}" | |
101 | * @required | |
102 | */ | |
103 | private List remoteRepositories; | |
104 | ||
105 | public void execute() | |
106 | throws MojoExecutionException | |
107 | { | |
108 | ||
109 | // ---------------------------------------------------------------------- | |
110 | // archetypeGroupId | |
111 | // archetypeArtifactId | |
112 | // archetypeVersion | |
113 | // | |
114 | // localRepository | |
115 | // remoteRepository | |
116 | // parameters | |
117 | // ---------------------------------------------------------------------- | |
118 | ||
119 | 0 | String basedir = System.getProperty("user.dir"); |
120 | ||
121 | 0 | if (packageName == null) |
122 | { | |
123 | 0 | getLog().info("Defaulting package to group ID: " + groupId); |
124 | ||
125 | 0 | packageName = groupId; |
126 | } | |
127 | ||
128 | // TODO: context mojo more appropriate? | |
129 | 0 | Map map = new HashMap(); |
130 | ||
131 | 0 | map.put("basedir", basedir); |
132 | ||
133 | 0 | map.put("package", packageName); |
134 | ||
135 | 0 | map.put("packageName", packageName); |
136 | ||
137 | 0 | map.put("groupId", groupId); |
138 | ||
139 | 0 | map.put("artifactId", artifactId); |
140 | ||
141 | 0 | map.put("version", version); |
142 | 0 | map.put("muleVersion", muleVersion); |
143 | ||
144 | try | |
145 | { | |
146 | 0 | archetype.createArchetype(archetypeGroupId, archetypeArtifactId, archetypeVersion, localRepository, remoteRepositories, map); |
147 | } | |
148 | 0 | catch (ArchetypeNotFoundException e) |
149 | { | |
150 | 0 | throw new MojoExecutionException("Error creating from archetype", e); |
151 | } | |
152 | 0 | catch (ArchetypeDescriptorException e) |
153 | { | |
154 | 0 | throw new MojoExecutionException("Error creating from archetype", e); |
155 | } | |
156 | 0 | catch (ArchetypeTemplateProcessingException e) |
157 | { | |
158 | 0 | throw new MojoExecutionException("Error creating from archetype", e); |
159 | 0 | } |
160 | 0 | } |
161 | ||
162 | ||
163 | } |