1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.maven.plugin.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 BobberArchetypeMojo
41 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 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()
101 throws MojoExecutionException
102 {
103
104
105
106
107
108
109
110
111
112
113
114
115
116 String basedir = System.getProperty("user.dir");
117
118 if (packageName == null)
119 {
120 getLog().info("Defaulting package to group ID: " + groupId);
121
122 packageName = groupId;
123 }
124
125
126 Map map = new HashMap();
127
128 map.put("basedir", basedir);
129
130 map.put("package", packageName);
131
132 map.put("packageName", packageName);
133
134 map.put("groupId", groupId);
135
136 map.put("artifactId", artifactId);
137
138 map.put("version", version);
139
140
141 try
142 {
143 archetype.createArchetype(archetypeGroupId, archetypeArtifactId, archetypeVersion, localRepository, remoteRepositories, map);
144 }
145 catch (ArchetypeNotFoundException e)
146 {
147 throw new MojoExecutionException("Error creating from archetype", e);
148 }
149 catch (ArchetypeDescriptorException e)
150 {
151 throw new MojoExecutionException("Error creating from archetype", e);
152 }
153 catch (ArchetypeTemplateProcessingException e)
154 {
155 throw new MojoExecutionException("Error creating from archetype", e);
156 }
157 }
158
159
160 }