1 package org.codehaus.mojo.gwt.shell;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.artifact.Artifact;
23 import org.apache.maven.plugin.MojoExecutionException;
24 import org.apache.maven.plugin.MojoFailureException;
25 import org.apache.maven.plugins.annotations.Parameter;
26 import org.codehaus.mojo.gwt.AbstractGwtModuleMojo;
27 import org.codehaus.plexus.util.StringUtils;
28 import org.codehaus.plexus.util.cli.CommandLineUtils;
29
30 import java.io.File;
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.Collection;
34 import java.util.List;
35
36
37
38
39
40
41
42
43
44
45 public abstract class AbstractGwtShellMojo
46 extends AbstractGwtModuleMojo
47 {
48
49
50
51
52
53 @Parameter(defaultValue = "${project.build.directory}/.generated", property = "gwt.gen")
54 private File gen;
55
56
57
58
59
60
61
62
63 @Parameter(defaultValue = "true", property = "gwt.genParam")
64 private boolean genParam;
65
66
67
68
69
70
71 @Parameter(defaultValue = "INFO", property = "gwt.logLevel")
72 private String logLevel;
73
74
75
76
77
78
79 @Parameter(property = "gwt.style")
80 protected String style;
81
82
83
84
85
86
87 @Parameter
88 private File deploy;
89
90
91
92
93
94
95
96
97
98 @Parameter(property = "gwt.extraJvmArgs", defaultValue="-Xmx512m")
99 private String extraJvmArgs;
100
101
102
103
104
105
106
107 @Parameter(property = "gwt.jvm")
108 private String jvm;
109
110
111
112
113 @Parameter
114 private int timeOut;
115
116
117
118
119
120
121
122
123
124
125
126
127
128 @Deprecated
129 @Parameter
130 private String[] compileSourcesArtifacts;
131
132
133
134
135
136
137
138
139 @Parameter(property = "gwt.persistentunitcache")
140 private Boolean persistentunitcache;
141
142
143
144
145
146
147
148
149 @Parameter(property = "gwt.persistentunitcachedir")
150 private File persistentunitcachedir;
151
152
153
154
155
156
157
158
159 public final void execute()
160 throws MojoExecutionException, MojoFailureException
161 {
162 doExecute();
163 }
164
165 public abstract void doExecute()
166 throws MojoExecutionException, MojoFailureException;
167
168 protected String getExtraJvmArgs()
169 {
170 return extraJvmArgs;
171 }
172
173 protected String getLogLevel()
174 {
175 return this.logLevel;
176 }
177
178 protected String getStyle()
179 {
180 return this.style;
181 }
182
183
184 protected String getJvm()
185 {
186 return jvm;
187 }
188
189
190
191
192 protected void postProcessClassPath( Collection<File> classpath )
193 {
194
195 }
196
197 private List<String> getJvmArgs()
198 {
199 List<String> extra = new ArrayList<String>();
200 String userExtraJvmArgs = getExtraJvmArgs();
201 if ( userExtraJvmArgs != null )
202 {
203 try
204 {
205
206 userExtraJvmArgs = userExtraJvmArgs.replace('\n', ' ').replace('\r', ' ');
207 return new ArrayList<String>(Arrays.asList( CommandLineUtils.translateCommandline( StringUtils.removeDuplicateWhitespace( userExtraJvmArgs ) ) ) );
208 }
209 catch ( Exception e )
210 {
211 throw new RuntimeException( e );
212 }
213 }
214 return extra;
215 }
216
217
218
219
220 public void setTimeOut( int timeOut )
221 {
222 this.timeOut = timeOut;
223 }
224
225 protected JavaCommand createJavaCommand() {
226 return new JavaCommand()
227 .setLog( getLog() )
228 .setJvm( getJvm() )
229 .setJvmArgs( getJvmArgs() )
230 .setTimeOut( timeOut )
231 .addClassPathProcessors( new ClassPathProcessor()
232 {
233 @Override
234 public void postProcessClassPath( List<File> files )
235 {
236 AbstractGwtShellMojo.this.postProcessClassPath( files );
237 }
238 } );
239 }
240
241
242
243
244
245
246
247
248
249 protected void addCompileSourceArtifacts(JavaCommand cmd)
250 throws MojoExecutionException
251 {
252 if ( compileSourcesArtifacts == null )
253 {
254 return;
255 }
256 for ( String include : compileSourcesArtifacts )
257 {
258 List<String> parts = new ArrayList<String>();
259 parts.addAll( Arrays.asList(include.split(":")) );
260 if ( parts.size() == 2 )
261 {
262
263 parts.add( "jar" );
264 }
265 String dependencyId = StringUtils.join( parts.iterator(), ":" );
266 boolean found = false;
267
268 for ( Artifact artifact : getProjectArtifacts() )
269 {
270 getLog().debug( "compare " + dependencyId + " with " + artifact.getDependencyConflictId() );
271 if ( artifact.getDependencyConflictId().equals( dependencyId ) )
272 {
273 getLog().debug( "Add " + dependencyId + " sources.jar artifact to compile classpath" );
274 Artifact sources =
275 resolve( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
276 "jar", "sources" );
277 cmd.addToClasspath( sources.getFile() );
278 found = true;
279 break;
280 }
281 }
282 if ( !found )
283 getLog().warn(
284 "Declared compileSourcesArtifact was not found in project dependencies " + dependencyId );
285 }
286 }
287
288 protected void addArgumentDeploy(JavaCommand cmd) {
289 if ( deploy != null )
290 {
291 cmd.arg( "-deploy" ).arg( String.valueOf( deploy ) );
292 }
293 }
294
295 protected void addArgumentGen( JavaCommand cmd )
296 {
297 if ( this.genParam )
298 {
299 if ( !this.gen.exists() )
300 {
301 this.gen.mkdirs();
302 }
303 cmd.arg( "-gen", this.gen.getAbsolutePath() );
304 }
305 }
306
307 protected void addPersistentUnitCache(JavaCommand cmd) {
308 if ( persistentunitcache != null )
309 {
310 cmd.systemProperty( "gwt.persistentunitcache", String.valueOf( persistentunitcache.booleanValue() ) );
311 }
312 if ( persistentunitcachedir != null )
313 {
314 cmd.systemProperty( "gwt.persistentunitcachedir", persistentunitcachedir.getAbsolutePath() );
315 }
316 }
317
318 }