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
41 public class ConfigurationPatternArchetypeMojo extends AbstractMojo
42 {
43
44
45
46
47 private Archetype archetype;
48
49
50
51
52
53 private ArtifactRepository localRepository;
54
55
56
57
58
59 private String archetypeGroupId;
60
61
62
63
64
65 private String archetypeArtifactId;
66
67
68
69
70
71 private String archetypeVersion;
72
73
74
75
76
77 private String muleVersion;
78
79
80
81
82
83 private String groupId;
84
85
86
87
88
89 private String artifactId;
90
91
92
93
94
95 private String version;
96
97
98 private String packageName;
99
100
101
102
103
104 private List<?> remoteRepositories;
105
106 public void execute() throws MojoExecutionException
107 {
108
109
110
111
112
113
114
115
116
117
118 final String basedir = System.getProperty("user.dir");
119
120 if (packageName == null)
121 {
122 getLog().info("Defaulting package to group ID: " + groupId);
123
124 packageName = groupId;
125 }
126
127 final Map<Object, Object> map = new HashMap<Object, Object>();
128 map.put("basedir", basedir);
129 map.put("package", packageName);
130 map.put("packageName", packageName);
131 map.put("groupId", groupId);
132 map.put("artifactId", artifactId);
133 map.put("version", version);
134 map.put("muleVersion", muleVersion);
135
136 try
137 {
138 archetype.createArchetype(archetypeGroupId, archetypeArtifactId, archetypeVersion,
139 localRepository, remoteRepositories, map);
140 }
141 catch (final ArchetypeNotFoundException e)
142 {
143 throw new MojoExecutionException("Error creating from archetype", e);
144 }
145 catch (final ArchetypeDescriptorException e)
146 {
147 throw new MojoExecutionException("Error creating from archetype", e);
148 }
149 catch (final ArchetypeTemplateProcessingException e)
150 {
151 throw new MojoExecutionException("Error creating from archetype", e);
152 }
153 }
154
155 }