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