Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TransportArchetypeMojo |
|
| 8.0;8 |
1 | package org.mule.tools.maven.archetype; | |
2 | ||
3 | /* | |
4 | * Copyright 2001-2005 The Apache Software Foundation. | |
5 | * | |
6 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
7 | * you may not use this file except in compliance with the License. | |
8 | * 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, software | |
13 | * distributed under the License is distributed on an "AS IS" BASIS, | |
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
15 | * See the License for the specific language governing permissions and | |
16 | * limitations under the License. | |
17 | */ | |
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 TransportArchetypeMojo 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-transport-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="${transportId}" | |
80 | * @required | |
81 | */ | |
82 | private String transportId; | |
83 | ||
84 | /** | |
85 | * @parameter expression="${groupId}" alias="newGroupId" default-value="org.mule.transport.${transportId} | |
86 | * @require | |
87 | */ | |
88 | private String groupId; | |
89 | ||
90 | /** | |
91 | * @parameter expression="${artifactId}" alias="newArtifactId" default-value="mule-transport-${transportId}" | |
92 | * @require | |
93 | */ | |
94 | private String artifactId; | |
95 | ||
96 | /** | |
97 | * @parameter expression="${version}" alias="newVersion" default-value="1.0-SNAPSHOT" | |
98 | * @require | |
99 | */ | |
100 | private String version; | |
101 | ||
102 | /** @parameter expression="${packageName}" alias="package" */ | |
103 | private String packageName; | |
104 | ||
105 | /** | |
106 | * @parameter expression="${project.remoteArtifactRepositories}" | |
107 | * @required | |
108 | */ | |
109 | private List remoteRepositories; | |
110 | ||
111 | public void execute() | |
112 | throws MojoExecutionException | |
113 | { | |
114 | ||
115 | // ---------------------------------------------------------------------- | |
116 | // archetypeGroupId | |
117 | // archetypeArtifactId | |
118 | // archetypeVersion | |
119 | // | |
120 | // localRepository | |
121 | // remoteRepository | |
122 | // parameters | |
123 | // ---------------------------------------------------------------------- | |
124 | ||
125 | 0 | String basedir = System.getProperty("user.dir"); |
126 | ||
127 | 0 | if (packageName == null) |
128 | { | |
129 | 0 | getLog().info("Defaulting package to group ID: " + groupId); |
130 | ||
131 | 0 | packageName = groupId; |
132 | } | |
133 | ||
134 | // TODO: context mojo more appropriate? | |
135 | 0 | Map map = new HashMap(); |
136 | ||
137 | 0 | map.put("basedir", basedir); |
138 | ||
139 | 0 | map.put("package", packageName); |
140 | ||
141 | 0 | map.put("packageName", packageName); |
142 | ||
143 | 0 | map.put("groupId", groupId); |
144 | ||
145 | 0 | map.put("artifactId", artifactId); |
146 | ||
147 | 0 | map.put("version", version); |
148 | 0 | map.put("muleVersion", muleVersion); |
149 | 0 | map.put("transportId", transportId); |
150 | ||
151 | ||
152 | try | |
153 | { | |
154 | 0 | archetype.createArchetype(archetypeGroupId, archetypeArtifactId, archetypeVersion, localRepository, remoteRepositories, map); |
155 | } | |
156 | 0 | catch (ArchetypeNotFoundException e) |
157 | { | |
158 | 0 | throw new MojoExecutionException("Error creating from archetype", e); |
159 | } | |
160 | 0 | catch (ArchetypeDescriptorException e) |
161 | { | |
162 | 0 | throw new MojoExecutionException("Error creating from archetype", e); |
163 | } | |
164 | 0 | catch (ArchetypeTemplateProcessingException e) |
165 | { | |
166 | 0 | throw new MojoExecutionException("Error creating from archetype", e); |
167 | 0 | } |
168 | 0 | } |
169 | ||
170 | ||
171 | } |