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 ModuleArchetypeMojo 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 version;
95
96
97 private String packageName;
98
99
100
101
102
103 private List remoteRepositories;
104
105 public void execute()
106 throws MojoExecutionException
107 {
108
109
110
111
112
113
114
115
116
117
118
119 String basedir = System.getProperty("user.dir");
120
121 if (packageName == null)
122 {
123 getLog().info("Defaulting package to group ID: " + groupId);
124
125 packageName = groupId;
126 }
127
128
129 Map map = new HashMap();
130
131 map.put("basedir", basedir);
132
133 map.put("package", packageName);
134
135 map.put("packageName", packageName);
136
137 map.put("groupId", groupId);
138
139 map.put("artifactId", artifactId);
140
141 map.put("version", version);
142 map.put("muleVersion", muleVersion);
143
144
145 try
146 {
147 archetype.createArchetype(archetypeGroupId, archetypeArtifactId, archetypeVersion, localRepository, remoteRepositories, map);
148 }
149 catch (ArchetypeNotFoundException e)
150 {
151 throw new MojoExecutionException("Error creating from archetype", e);
152 }
153 catch (ArchetypeDescriptorException e)
154 {
155 throw new MojoExecutionException("Error creating from archetype", e);
156 }
157 catch (ArchetypeTemplateProcessingException e)
158 {
159 throw new MojoExecutionException("Error creating from archetype", e);
160 }
161 }
162
163
164 }