Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ConfigurationPatternArchetypeMojo |
|
| 0.0;0 |
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.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 | * Creates a new configuration pattern. | |
33 | * | |
34 | * @goal new-pattern | |
35 | * @description The archetype creation goal looks for an archetype with a given newGroupId, newArtifactId, and | |
36 | * newVersion and retrieves it from the remote repository. Once the archetype is retrieve it is process | |
37 | * against a set of user parameters to create a working Maven project. This is a modified newVersion for | |
38 | * bobber to support additional functionality. | |
39 | * @requiresProject false | |
40 | */ | |
41 | 0 | public class ConfigurationPatternArchetypeMojo extends AbstractMojo |
42 | { | |
43 | /** | |
44 | * @parameter expression="${component.org.apache.maven.archetype.Archetype}" | |
45 | * @required | |
46 | */ | |
47 | private Archetype archetype; | |
48 | ||
49 | /** | |
50 | * @parameter expression="${localRepository}" | |
51 | * @required | |
52 | */ | |
53 | private ArtifactRepository localRepository; | |
54 | ||
55 | /** | |
56 | * @parameter expression="${archetypeGroupId}" default-value="org.mule.tools" | |
57 | * @required | |
58 | */ | |
59 | private String archetypeGroupId; | |
60 | ||
61 | /** | |
62 | * @parameter expression="${archetypeArtifactId}" default-value="mule-configuration-pattern-archetype" | |
63 | * @required | |
64 | */ | |
65 | private String archetypeArtifactId; | |
66 | ||
67 | /** | |
68 | * @parameter expression="${archetypeVersion}" default-value="${muleVersion}" | |
69 | * @required | |
70 | */ | |
71 | private String archetypeVersion; | |
72 | ||
73 | /** | |
74 | * @parameter expression="${muleVersion}" | |
75 | * @required | |
76 | */ | |
77 | private String muleVersion; | |
78 | ||
79 | /** | |
80 | * @parameter expression="${groupId}" alias="newGroupId" | |
81 | * @require | |
82 | */ | |
83 | private String groupId; | |
84 | ||
85 | /** | |
86 | * @parameter expression="${artifactId}" alias="newArtifactId" | |
87 | * @require | |
88 | */ | |
89 | private String artifactId; | |
90 | ||
91 | /** | |
92 | * @parameter expression="${version}" alias="newVersion" | |
93 | * @require | |
94 | */ | |
95 | private String version; | |
96 | ||
97 | /** @parameter expression="${packageName}" alias="package" */ | |
98 | private String packageName; | |
99 | ||
100 | /** | |
101 | * @parameter expression="${project.remoteArtifactRepositories}" | |
102 | * @required | |
103 | */ | |
104 | private List<?> remoteRepositories; | |
105 | ||
106 | public void execute() throws MojoExecutionException | |
107 | { | |
108 | // ---------------------------------------------------------------------- | |
109 | // archetypeGroupId | |
110 | // archetypeArtifactId | |
111 | // archetypeVersion | |
112 | // | |
113 | // localRepository | |
114 | // remoteRepository | |
115 | // parameters | |
116 | // ---------------------------------------------------------------------- | |
117 | ||
118 | 0 | final String basedir = System.getProperty("user.dir"); |
119 | ||
120 | 0 | if (packageName == null) |
121 | { | |
122 | 0 | getLog().info("Defaulting package to group ID: " + groupId); |
123 | ||
124 | 0 | packageName = groupId; |
125 | } | |
126 | ||
127 | 0 | final Map<Object, Object> map = new HashMap<Object, Object>(); |
128 | 0 | map.put("basedir", basedir); |
129 | 0 | map.put("package", packageName); |
130 | 0 | map.put("packageName", packageName); |
131 | 0 | map.put("groupId", groupId); |
132 | 0 | map.put("artifactId", artifactId); |
133 | 0 | map.put("version", version); |
134 | 0 | map.put("muleVersion", muleVersion); |
135 | ||
136 | try | |
137 | { | |
138 | 0 | archetype.createArchetype(archetypeGroupId, archetypeArtifactId, archetypeVersion, |
139 | localRepository, remoteRepositories, map); | |
140 | } | |
141 | 0 | catch (final ArchetypeNotFoundException e) |
142 | { | |
143 | 0 | throw new MojoExecutionException("Error creating from archetype", e); |
144 | } | |
145 | 0 | catch (final ArchetypeDescriptorException e) |
146 | { | |
147 | 0 | throw new MojoExecutionException("Error creating from archetype", e); |
148 | } | |
149 | 0 | catch (final ArchetypeTemplateProcessingException e) |
150 | { | |
151 | 0 | throw new MojoExecutionException("Error creating from archetype", e); |
152 | 0 | } |
153 | 0 | } |
154 | ||
155 | } |