Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ExampleArchetypeMojo |
|
| 8.0;8 |
1 | /* | |
2 | * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com | |
3 | * The software in this package is published under the terms of the CPAL v1.0 | |
4 | * license, a copy of which has been included with this distribution in the | |
5 | * LICENSE.txt file. | |
6 | */ | |
7 | package org.mule.tools.maven.archetype; | |
8 | ||
9 | import java.util.HashMap; | |
10 | import java.util.List; | |
11 | import java.util.Map; | |
12 | ||
13 | import org.apache.maven.archetype.Archetype; | |
14 | import org.apache.maven.archetype.ArchetypeDescriptorException; | |
15 | import org.apache.maven.archetype.ArchetypeNotFoundException; | |
16 | import org.apache.maven.archetype.ArchetypeTemplateProcessingException; | |
17 | import org.apache.maven.artifact.repository.ArtifactRepository; | |
18 | import org.apache.maven.plugin.AbstractMojo; | |
19 | import org.apache.maven.plugin.MojoExecutionException; | |
20 | ||
21 | /** | |
22 | * Builds archetype containers. | |
23 | * | |
24 | * @goal create | |
25 | * @description The archetype creation goal looks for an archetype with a given newGroupId, newArtifactId, and | |
26 | * newVersion and retrieves it from the remote repository. Once the archetype is retrieve it is process against | |
27 | * a set of user parameters to create a working Maven project. This is a modified newVersion for bobber to support additional functionality. | |
28 | * @requiresProject false | |
29 | */ | |
30 | 0 | public class ExampleArchetypeMojo extends AbstractMojo |
31 | { | |
32 | /** | |
33 | * @parameter expression="${component.org.apache.maven.archetype.Archetype}" | |
34 | * @required | |
35 | */ | |
36 | private Archetype archetype; | |
37 | ||
38 | /** | |
39 | * @parameter expression="${localRepository}" | |
40 | * @required | |
41 | */ | |
42 | private ArtifactRepository localRepository; | |
43 | ||
44 | /** | |
45 | * @parameter expression="${archetypeGroupId}" default-value="org.mule.tools" | |
46 | * @required | |
47 | */ | |
48 | private String archetypeGroupId; | |
49 | ||
50 | /** | |
51 | * @parameter expression="${archetypeArtifactId}" default-value="mule-example-archetype" | |
52 | * @required | |
53 | */ | |
54 | private String archetypeArtifactId; | |
55 | ||
56 | /** | |
57 | * @parameter expression="${archetypeVersion}" default-value="${muleVersion}" | |
58 | * @required | |
59 | */ | |
60 | private String archetypeVersion; | |
61 | ||
62 | /** | |
63 | * @parameter expression="${muleVersion}" | |
64 | * @required | |
65 | */ | |
66 | private String muleVersion; | |
67 | ||
68 | /** | |
69 | * @parameter expression="${groupId}" alias="newGroupId" default-value="com.mycompany.mule" | |
70 | * @require | |
71 | */ | |
72 | private String groupId; | |
73 | ||
74 | /** | |
75 | * @parameter expression="${artifactId}" alias="newArtifactId" default-value="my-mule-example" | |
76 | * @require | |
77 | */ | |
78 | private String artifactId; | |
79 | ||
80 | /** | |
81 | * @parameter expression="${version}" alias="newVersion" default-value="1.0-SNAPSHOT" | |
82 | * @require | |
83 | */ | |
84 | private String version; | |
85 | ||
86 | /** @parameter expression="${packageName}" alias="package" */ | |
87 | private String packageName; | |
88 | ||
89 | /** | |
90 | * @parameter expression="${project.remoteArtifactRepositories}" | |
91 | * @required | |
92 | */ | |
93 | private List remoteRepositories; | |
94 | ||
95 | public void execute() | |
96 | throws MojoExecutionException | |
97 | { | |
98 | ||
99 | // ---------------------------------------------------------------------- | |
100 | // archetypeGroupId | |
101 | // archetypeArtifactId | |
102 | // archetypeVersion | |
103 | // | |
104 | // localRepository | |
105 | // remoteRepository | |
106 | // parameters | |
107 | // ---------------------------------------------------------------------- | |
108 | ||
109 | 0 | String basedir = System.getProperty("user.dir"); |
110 | ||
111 | 0 | if (packageName == null) |
112 | { | |
113 | 0 | getLog().info("Defaulting package to group ID: " + groupId); |
114 | ||
115 | 0 | packageName = groupId; |
116 | } | |
117 | ||
118 | // TODO: context mojo more appropriate? | |
119 | 0 | Map map = new HashMap(); |
120 | ||
121 | 0 | map.put("basedir", basedir); |
122 | ||
123 | 0 | map.put("package", packageName); |
124 | ||
125 | 0 | map.put("packageName", packageName); |
126 | ||
127 | 0 | map.put("groupId", groupId); |
128 | ||
129 | 0 | map.put("artifactId", artifactId); |
130 | ||
131 | 0 | map.put("version", version); |
132 | 0 | map.put("muleVersion", muleVersion); |
133 | ||
134 | ||
135 | try | |
136 | { | |
137 | 0 | archetype.createArchetype(archetypeGroupId, archetypeArtifactId, archetypeVersion, localRepository, remoteRepositories, map); |
138 | } | |
139 | 0 | catch (ArchetypeNotFoundException e) |
140 | { | |
141 | 0 | throw new MojoExecutionException("Error creating from archetype", e); |
142 | } | |
143 | 0 | catch (ArchetypeDescriptorException e) |
144 | { | |
145 | 0 | throw new MojoExecutionException("Error creating from archetype", e); |
146 | } | |
147 | 0 | catch (ArchetypeTemplateProcessingException e) |
148 | { | |
149 | 0 | throw new MojoExecutionException("Error creating from archetype", e); |
150 | 0 | } |
151 | 0 | } |
152 | ||
153 | ||
154 | } |