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 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 groupId;
77
78
79
80
81
82 private String artifactId;
83
84
85
86
87
88 private String version;
89
90
91
92
93 private String packageName;
94
95
96
97
98
99 private List remoteRepositories;
100
101 public void execute()
102 throws MojoExecutionException {
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 getLog().info( "Defaulting package to group ID: " + groupId );
120
121 packageName = groupId;
122 }
123
124
125 Map map = new HashMap();
126
127 map.put( "basedir", basedir );
128
129 map.put( "package", packageName );
130
131 map.put( "packageName", packageName );
132
133 map.put( "groupId", groupId );
134
135 map.put( "artifactId", artifactId );
136
137 map.put( "version", version );
138
139
140 try {
141 archetype.createArchetype( archetypeGroupId, archetypeArtifactId, archetypeVersion, localRepository, remoteRepositories, map );
142 } catch ( ArchetypeNotFoundException e ) {
143 throw new MojoExecutionException( "Error creating from archetype", e );
144 } catch ( ArchetypeDescriptorException e ) {
145 throw new MojoExecutionException( "Error creating from archetype", e );
146 } catch ( ArchetypeTemplateProcessingException e ) {
147 throw new MojoExecutionException( "Error creating from archetype", e );
148 }
149 }
150
151
152
153 }