1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
33
34
35
36
37
38
39
40 public class TransportArchetypeMojo extends AbstractMojo
41 {
42
43
44
45
46 private Archetype archetype;
47
48
49
50
51
52 private ArtifactRepository localRepository;
53
54
55
56
57
58 private String archetypeGroupId;
59
60
61
62
63
64 private String archetypeArtifactId;
65
66
67
68
69
70 private String archetypeVersion;
71
72
73
74
75
76 private String muleVersion;
77
78
79
80
81
82 private String groupId;
83
84
85
86
87
88 private String artifactId;
89
90
91
92
93
94 private String transportId;
95
96
97
98
99
100 private String version;
101
102
103 private String packageName;
104
105
106
107
108
109 private List<?> remoteRepositories;
110
111 public void execute()
112 throws MojoExecutionException
113 {
114
115
116
117
118
119
120
121
122
123
124
125 String basedir = System.getProperty("user.dir");
126
127 if (packageName == null)
128 {
129 getLog().info("Defaulting package to group ID: " + groupId);
130
131 packageName = groupId;
132 }
133
134
135 Map<String, String> map = new HashMap<String, String>();
136
137 if (artifactId == null)
138 {
139 artifactId = transportId;
140 }
141
142 map.put("basedir", basedir);
143
144 map.put("package", packageName);
145
146 map.put("packageName", packageName);
147
148 map.put("groupId", groupId);
149
150 map.put("version", version);
151 map.put("muleVersion", muleVersion);
152 map.put("transportId", artifactId);
153
154 artifactId = "mule-transport-" + artifactId;
155
156 map.put("artifactId", artifactId);
157
158 try
159 {
160 archetype.createArchetype(archetypeGroupId, archetypeArtifactId, archetypeVersion, localRepository, remoteRepositories, map);
161 }
162 catch (ArchetypeNotFoundException e)
163 {
164 throw new MojoExecutionException("Error creating from archetype", e);
165 }
166 catch (ArchetypeDescriptorException e)
167 {
168 throw new MojoExecutionException("Error creating from archetype", e);
169 }
170 catch (ArchetypeTemplateProcessingException e)
171 {
172 throw new MojoExecutionException("Error creating from archetype", e);
173 }
174 }
175 }