1
2
3
4
5
6
7 package org.mule.tools.maven.archetype;
8
9 import java.util.HashMap;
10 import java.util.List;
11 import java.util.Map;
12
13 import org.apache.maven.archetype.Archetype;
14 import org.apache.maven.archetype.ArchetypeDescriptorException;
15 import org.apache.maven.archetype.ArchetypeNotFoundException;
16 import org.apache.maven.archetype.ArchetypeTemplateProcessingException;
17 import org.apache.maven.artifact.repository.ArtifactRepository;
18 import org.apache.maven.plugin.AbstractMojo;
19 import org.apache.maven.plugin.MojoExecutionException;
20
21
22
23
24
25
26
27
28
29
30 public class ExampleArchetypeMojo extends AbstractMojo
31 {
32
33
34
35
36 private Archetype archetype;
37
38
39
40
41
42 private ArtifactRepository localRepository;
43
44
45
46
47
48 private String archetypeGroupId;
49
50
51
52
53
54 private String archetypeArtifactId;
55
56
57
58
59
60 private String archetypeVersion;
61
62
63
64
65
66 private String muleVersion;
67
68
69
70
71
72 private String groupId;
73
74
75
76
77
78 private String artifactId;
79
80
81
82
83
84 private String version;
85
86
87 private String packageName;
88
89
90
91
92
93 private List remoteRepositories;
94
95 public void execute()
96 throws MojoExecutionException
97 {
98
99
100
101
102
103
104
105
106
107
108
109 String basedir = System.getProperty("user.dir");
110
111 if (packageName == null)
112 {
113 getLog().info("Defaulting package to group ID: " + groupId);
114
115 packageName = groupId;
116 }
117
118
119 Map map = new HashMap();
120
121 map.put("basedir", basedir);
122
123 map.put("package", packageName);
124
125 map.put("packageName", packageName);
126
127 map.put("groupId", groupId);
128
129 map.put("artifactId", artifactId);
130
131 map.put("version", version);
132 map.put("muleVersion", muleVersion);
133
134
135 try
136 {
137 archetype.createArchetype(archetypeGroupId, archetypeArtifactId, archetypeVersion, localRepository, remoteRepositories, map);
138 }
139 catch (ArchetypeNotFoundException e)
140 {
141 throw new MojoExecutionException("Error creating from archetype", e);
142 }
143 catch (ArchetypeDescriptorException e)
144 {
145 throw new MojoExecutionException("Error creating from archetype", e);
146 }
147 catch (ArchetypeTemplateProcessingException e)
148 {
149 throw new MojoExecutionException("Error creating from archetype", e);
150 }
151 }
152
153
154 }