Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
BobberArchetypeMojo |
|
| 8.0;8 |
1 | /* | |
2 | * Copyright 2001-2005 The Apache Software Foundation. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
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 | * Builds archetype containers. | |
33 | * | |
34 | * @goal create | |
35 | * @description The archetype creation goal looks for an archetype with a given groupId, artifactId, and | |
36 | * version and retrieves it from the remote repository. Once the archetype is retrieve it is process against | |
37 | * a set of user parameters to create a working Maven project. This is a modified version for bobber to support additional functionality. | |
38 | * @requiresProject false | |
39 | */ | |
40 | 0 | public class BobberArchetypeMojo |
41 | extends AbstractMojo { | |
42 | /** | |
43 | * @parameter expression="${component.org.apache.maven.archetype.Archetype}" | |
44 | * @required | |
45 | */ | |
46 | private Archetype archetype; | |
47 | ||
48 | /** | |
49 | * @parameter expression="${localRepository}" | |
50 | * @required | |
51 | */ | |
52 | private ArtifactRepository localRepository; | |
53 | ||
54 | /** | |
55 | * @parameter expression="${archetypeGroupId}" default-value="org.apache.maven.archetypes" | |
56 | * @required | |
57 | */ | |
58 | private String archetypeGroupId; | |
59 | ||
60 | /** | |
61 | * @parameter expression="${archetypeArtifactId}" default-value="maven-archetype-quickstart" | |
62 | * @required | |
63 | */ | |
64 | private String archetypeArtifactId; | |
65 | ||
66 | /** | |
67 | * @parameter expression="${archetypeVersion}" default-value="RELEASE" | |
68 | * @required | |
69 | */ | |
70 | private String archetypeVersion; | |
71 | ||
72 | /** | |
73 | * @parameter expression="${groupId}" | |
74 | * @required | |
75 | */ | |
76 | private String groupId; | |
77 | ||
78 | /** | |
79 | * @parameter expression="${artifactId}" | |
80 | * @required | |
81 | */ | |
82 | private String artifactId; | |
83 | ||
84 | /** | |
85 | * @parameter expression="${version}" default-value="1.0-SNAPSHOT" | |
86 | * @required | |
87 | */ | |
88 | private String version; | |
89 | ||
90 | /** | |
91 | * @parameter expression="${packageName}" alias="package" | |
92 | */ | |
93 | private String packageName; | |
94 | ||
95 | /** | |
96 | * @parameter expression="${project.remoteArtifactRepositories}" | |
97 | * @required | |
98 | */ | |
99 | private List remoteRepositories; | |
100 | ||
101 | public void execute() | |
102 | throws MojoExecutionException { | |
103 | // TODO: prompt for missing values | |
104 | // TODO: configurable license | |
105 | ||
106 | // ---------------------------------------------------------------------- | |
107 | // archetypeGroupId | |
108 | // archetypeArtifactId | |
109 | // archetypeVersion | |
110 | // | |
111 | // localRepository | |
112 | // remoteRepository | |
113 | // parameters | |
114 | // ---------------------------------------------------------------------- | |
115 | ||
116 | 0 | String basedir = System.getProperty( "user.dir" ); |
117 | ||
118 | 0 | if ( packageName == null ) { |
119 | 0 | getLog().info( "Defaulting package to group ID: " + groupId ); |
120 | ||
121 | 0 | packageName = groupId; |
122 | } | |
123 | ||
124 | // TODO: context mojo more appropriate? | |
125 | 0 | Map map = new HashMap(); |
126 | ||
127 | 0 | map.put( "basedir", basedir ); |
128 | ||
129 | 0 | map.put( "package", packageName ); |
130 | ||
131 | 0 | map.put( "packageName", packageName ); |
132 | ||
133 | 0 | map.put( "groupId", groupId ); |
134 | ||
135 | 0 | map.put( "artifactId", artifactId ); |
136 | ||
137 | 0 | map.put( "version", version ); |
138 | ||
139 | ||
140 | try { | |
141 | 0 | archetype.createArchetype( archetypeGroupId, archetypeArtifactId, archetypeVersion, localRepository, remoteRepositories, map ); |
142 | 0 | } catch ( ArchetypeNotFoundException e ) { |
143 | 0 | throw new MojoExecutionException( "Error creating from archetype", e ); |
144 | 0 | } catch ( ArchetypeDescriptorException e ) { |
145 | 0 | throw new MojoExecutionException( "Error creating from archetype", e ); |
146 | 0 | } catch ( ArchetypeTemplateProcessingException e ) { |
147 | 0 | throw new MojoExecutionException( "Error creating from archetype", e ); |
148 | 0 | } |
149 | 0 | } |
150 | ||
151 | ||
152 | ||
153 | } |