-
Notifications
You must be signed in to change notification settings - Fork 2
/
gwtBuild.gradle
470 lines (354 loc) · 15.5 KB
/
gwtBuild.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
import java.io.File
import java.util.Collection
import groovy.lang.Closure;
import org.gradle.api.Action;
import org.gradle.api.artifacts.ConfigurationContainer
import org.gradle.api.artifacts.ExternalModuleDependency
import org.gradle.api.file.FileCollection
import org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency
import org.gradle.api.internal.artifacts.dsl.dependencies.ModuleFactoryHelper
import org.gradle.api.logging.LogLevel
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.WarPlugin
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.StopActionException
import org.gradle.api.tasks.compile.Compile
apply plugin: 'war'
apply plugin: 'jettyEclipse'
project.ext { gwtVersion = '2.6.0' }
final File gwtExtraDir = project.file(project.getBuildDir().name + File.separator + "gwt" + File.separator + "extras")
final File gwtWarDir = project.file(project.getBuildDir().name + File.separator + "gwt" + File.separator + "war")
final String PROJECT_DIR_NAME_LC = project.name.toLowerCase();
public interface GWTConstants {
public final static String LIB_NAME = "lib"
public final static String WAR_DIR_NAME = "war"
public final static String WEB_INF_NAME = "WEB-INF"
public final static String CLASSES_NAME = "classes"
public final static String DEPLOY_NAME = "deploy"
public final static String GWT_CONFIGURATION_NAME = "gwt"
public final static String SUPER_GWT_CONFIGURATION_NAME = "superGwt"
public final static String ECLIPSE_EXCLUDE_CONFIGURATION_NAME = "eclipseExclude"
public final static String WEB_INF_CLASSES_DIR_NAME = WEB_INF_NAME + File.separator + CLASSES_NAME
public final static String WEB_INF_DEPLOY_DIR_NAME = WEB_INF_NAME + File.separator + DEPLOY_NAME
public final static String WEB_INF_LIB_DIR_NAME = WEB_INF_NAME + File.separator + LIB_NAME
public final static String WAR_WEB_INF_DIR_NAME = WAR_DIR_NAME + File.separator + WEB_INF_NAME
public final static String WAR_WEB_INF_CLASSES_DIR_NAME = WAR_WEB_INF_DIR_NAME + File.separator + CLASSES_NAME
public final static String WAR_WEB_INF_LIB_DIR_NAME = WAR_WEB_INF_DIR_NAME + File.separator + LIB_NAME
}
ConfigurationContainer configurations = project.configurations
configurations.create(GWTConstants.GWT_CONFIGURATION_NAME).
setVisible(false).
extendsFrom(configurations.getByName(JavaPlugin.COMPILE_CONFIGURATION_NAME)).
setDescription("GWT libraries to be used to compile this GWT project.")
configurations.create(GWTConstants.SUPER_GWT_CONFIGURATION_NAME).
setVisible(false).
extendsFrom(configurations.getByName(JavaPlugin.COMPILE_CONFIGURATION_NAME)).
setDescription("GWT libraries to be used for super dev mode")
configurations.create(GWTConstants.ECLIPSE_EXCLUDE_CONFIGURATION_NAME).
setVisible(false).
setDescription("GWT jars to exclude from eclipse project because they are part of the GWT container already")
project.extensions.eclipse.classpath.containers 'com.google.gwt.eclipse.core.GWT_CONTAINER'
project.extensions.eclipse.classpath.minusConfigurations += project.configurations.getByName(GWTConstants.ECLIPSE_EXCLUDE_CONFIGURATION_NAME)
project.extensions.eclipse.project.natures 'com.google.gwt.eclipse.core.gwtNature'
project.extensions.eclipse.project.buildCommand 'com.google.gwt.eclipse.core.gwtProjectValidator'
ExternalModuleDependency dependency
dependency = new DefaultExternalModuleDependency("com.google.gwt", "gwt-dev", gwtVersion)
dependency.setTransitive(false)
project.configurations.getByName(GWTConstants.GWT_CONFIGURATION_NAME).dependencies.add(dependency)
project.configurations.getByName(GWTConstants.SUPER_GWT_CONFIGURATION_NAME).dependencies.add(dependency)
project.configurations.getByName(GWTConstants.ECLIPSE_EXCLUDE_CONFIGURATION_NAME).dependencies.add(dependency)
dependency = new DefaultExternalModuleDependency("com.google.gwt", "gwt-codeserver", gwtVersion)
dependency.setTransitive(false)
project.configurations.getByName(GWTConstants.SUPER_GWT_CONFIGURATION_NAME).dependencies.add(dependency)
project.configurations.getByName(GWTConstants.ECLIPSE_EXCLUDE_CONFIGURATION_NAME).dependencies.add(dependency)
dependency = new DefaultExternalModuleDependency("javax.validation", "validation-api", "1.0.0.GA")
project.configurations.getByName(GWTConstants.GWT_CONFIGURATION_NAME).dependencies.add(dependency)
project.configurations.getByName(GWTConstants.ECLIPSE_EXCLUDE_CONFIGURATION_NAME).dependencies.add(dependency)
dependency = new DefaultExternalModuleDependency("javax.validation", "validation-api", "1.0.0.GA")
ModuleFactoryHelper.addExplicitArtifactsIfDefined(dependency, null, "sources")
project.configurations.getByName(GWTConstants.GWT_CONFIGURATION_NAME).dependencies.add(dependency)
project.configurations.getByName(GWTConstants.ECLIPSE_EXCLUDE_CONFIGURATION_NAME).dependencies.add(dependency)
dependency = new DefaultExternalModuleDependency("com.google.gwt", "gwt-user", gwtVersion )
project.configurations.getByName(WarPlugin.PROVIDED_COMPILE_CONFIGURATION_NAME).dependencies.add(dependency)
project.configurations.getByName(GWTConstants.SUPER_GWT_CONFIGURATION_NAME).dependencies.add(dependency)
project.configurations.getByName(GWTConstants.ECLIPSE_EXCLUDE_CONFIGURATION_NAME).dependencies.add(dependency)
dependency = new DefaultExternalModuleDependency("com.google.gwt", "gwt-servlet", gwtVersion)
project.configurations.getByName(JavaPlugin.RUNTIME_CONFIGURATION_NAME).dependencies.add(dependency)
project.configurations.getByName(GWTConstants.ECLIPSE_EXCLUDE_CONFIGURATION_NAME).dependencies.add(dependency)
project.tasks.withType(Compile.class).all { Compile task ->
if (task.getClasspath()) {
task.setClasspath(task.getClasspath() + project.configurations.getByName(GWTConstants.GWT_CONFIGURATION_NAME))
}
else {
task.setClasspath(project.configurations.getByName(GWTConstants.GWT_CONFIGURATION_NAME))
}
}
class ActionClosure<T> extends Closure<T> {
private static final long serialVersionUID = 1L;
private Action<T> action;
public ActionClosure(Object owner, Action<T> action) {
super(owner);
this.action = action;
}
public void doCall(T object) {
action.execute(object);
}
}
class GwtBase extends org.gradle.api.internal.ConventionTask implements GWTConstants {
@Input
Collection<String> modules
static collectDependedUponProjects(org.gradle.api.Project project, LinkedHashSet result, String type) {
def config = project.configurations.findByName(type)
if (config) {
def projectDeps = config.allDependencies.withType(org.gradle.api.artifacts.ProjectDependency)
def dependedUponProjects = projectDeps*.dependencyProject
result.addAll(dependedUponProjects)
for (dependedUponProject in dependedUponProjects) {
collectDependedUponProjects(dependedUponProject, result, type)
}
}
}
}
class CompileGwt extends GwtBase {
static final String COMPILER_CLASSNAME = 'com.google.gwt.dev.Compiler'
static final String GWT_CLASSPATH_ID = 'gwt.classpath'
String style = 'OBF'
String logLevel = 'INFO'
boolean debug = false
boolean disableClassMetadata = false
boolean disableCastChecking = false
boolean validateOnly = false
boolean draftCompile = false
boolean compileReport = false
int localWorkers = Runtime.getRuntime().availableProcessors()
java.util.List customJvmArgs = []
Map customEnvironment = [:]
Map customSystemProperties = [:]
Map options = [
fork: true,
failonerror : true,
maxmemory: "512m",
newEnvironment: false,
cloneVm: false
]
Map otherArgs = [
classpathref: GWT_CLASSPATH_ID,
classname: COMPILER_CLASSNAME
]
@InputFiles
FileCollection classpath
@OutputDirectory
File warOutputDir
@OutputDirectory
File extraOutputDir
@org.gradle.api.tasks.TaskAction
def compileGwt() {
if( modules == null || modules.size == 0 ) {
logger.warn("No GWT Modules defined for project " + project.name)
throw new StopActionException("No gwt modules specified")
}
def allProjects = [] as LinkedHashSet
collectDependedUponProjects(project, allProjects, "compile")
project.getAnt().path(id: GWT_CLASSPATH_ID) {
classpath.each {
logger.info("Add {} to GWT classpath!", it)
pathelement(location: it)
}
allProjects.each { p ->
p.configurations['source'].allArtifacts.getFiles().each {
logger.info("Add {} to GWT classpath!", it)
pathelement(location: it)
}
}
}
ant.java(otherArgs + options) {
customJvmArgs.each { jvmarg(value: it) }
customEnvironment.each {String key, value -> env(key: key, value: value) }
customSystemProperties.each {String key, value -> sysproperty(key: key, value: value) }
if (debug) {
arg(line: '-ea')
}
if (validateOnly) arg(line: '-validateOnly')
if (draftCompile) arg(line: '-draftCompile')
if (compileReport) arg(line: '-compileReport')
if (localWorkers > 1) arg(line: "-localWorkers ${localWorkers}")
if (disableClassMetadata) arg(line: "-disableClassMetadata")
if (disableCastChecking) arg(line: "-XdisableCastChecking")
arg(line: "-logLevel ${logLevel}")
arg(line: "-style ${style}")
extraOutputDir.mkdirs()
arg(line: "-extra \"${extraOutputDir}\"")
warOutputDir.mkdirs()
arg(line: "-war \"${warOutputDir}\"")
modules.each {
logger.info("Compiling GWT Module {}", it)
arg(value: it)
}
}
}
}
class DevMode extends GwtBase {
@Input
String startupUrl
@Input
String maxHeap = '1024m'
@Input
String port = '8888'
@Input
String codePort = '9997'
@Input
Collection<String> jvmArgs = ['-XX:MaxPermSize=512m']
@org.gradle.api.tasks.TaskAction
public void exec() {
final ExecResult execResult = getProject().javaexec(new ActionClosure<JavaExecSpec>(this, new Action<JavaExecSpec>() {
@Override
public void execute(JavaExecSpec javaExecSpec) {
if (getModules() == null || getModules().isEmpty()) {
throw new InvalidUserDataException("No module[s] given");
}
javaExecSpec.setMain('com.google.gwt.dev.DevMode');
javaExecSpec.setDebug(false);
javaExecSpec.setMaxHeapSize(DevMode.this.maxHeap);
javaExecSpec.setJvmArgs(DevMode.this.jvmArgs);
FileCollection classpath = getProject().files(getProject().sourceSets.main.resources.srcDirs,
getProject().sourceSets.main.java.srcDirs,
getProject().sourceSets.main.output.classesDir,
getProject().configurations.getByName(GWTConstants.GWT_CONFIGURATION_NAME),
getProject().configurations.getByName(JavaPlugin.RUNTIME_CONFIGURATION_NAME))
def allProjects = [] as LinkedHashSet
collectDependedUponProjects(getProject(), allProjects, "compile")
allProjects.each { p ->
classpath = classpath.plus(getProject().files(p.sourceSets.main.allJava.srcDirs))
classpath = classpath.plus(getProject().files(p.sourceSets.main.resources.srcDirs))
}
javaExecSpec.setClasspath(classpath);
javaExecSpec.jvmArgs DevMode.this.jvmArgs;
javaExecSpec.args '-war'
javaExecSpec.args getProject().file(GWTConstants.WAR_DIR_NAME)
javaExecSpec.args '-codeServerPort'
javaExecSpec.args DevMode.this.codePort
javaExecSpec.args '-port'
javaExecSpec.args DevMode.this.port
javaExecSpec.args '-startupUrl'
javaExecSpec.args DevMode.this.startupUrl
javaExecSpec.args DevMode.this.modules
}
}));
execResult.assertNormalExitValue().rethrowFailure();
}
}
class SuperDevMode extends GwtBase {
@Input
String maxHeap = '1024m'
@Input
String port = '9876'
@Input
Collection<String> jvmArgs = ['-XX:MaxPermSize=512m']
@org.gradle.api.tasks.TaskAction
public void exec() {
final ExecResult execResult = getProject().javaexec(new ActionClosure<JavaExecSpec>(this, new Action<JavaExecSpec>() {
@Override
public void execute(JavaExecSpec javaExecSpec) {
if (getModules() == null || getModules().isEmpty()) {
throw new InvalidUserDataException("No module[s] given");
}
javaExecSpec.setMain('com.google.gwt.dev.codeserver.CodeServer');
javaExecSpec.setDebug(false);
javaExecSpec.setMaxHeapSize(SuperDevMode.this.maxHeap);
javaExecSpec.setJvmArgs(SuperDevMode.this.jvmArgs);
FileCollection classpath = getProject().files(getProject().sourceSets.main.output.classesDir,
getProject().configurations.getByName(GWTConstants.SUPER_GWT_CONFIGURATION_NAME))
javaExecSpec.setClasspath(classpath);
javaExecSpec.jvmArgs SuperDevMode.this.jvmArgs;
def allProjects = [] as LinkedHashSet
collectDependedUponProjects(getProject(), allProjects, "compile")
getProject().sourceSets.main.allJava.srcDirs.each {
if(it.exists() && it.isDirectory()) {
javaExecSpec.args '-src'
javaExecSpec.args it
}
}
getProject().sourceSets.main.resources.srcDirs.each {
if(it.exists() && it.isDirectory()) {
javaExecSpec.args '-src'
javaExecSpec.args it
}
}
def theSrcs = [] as LinkedHashSet
allProjects.each { p ->
p.sourceSets.main.allJava.srcDirs.each {
if(it.exists() && it.isDirectory()) {
javaExecSpec.args '-src'
javaExecSpec.args it
}
}
p.sourceSets.main.resources.srcDirs.each {
if(it.exists() && it.isDirectory()) {
javaExecSpec.args '-src'
javaExecSpec.args it
}
}
}
javaExecSpec.args '-noprecompile'
javaExecSpec.args '-port'
javaExecSpec.args SuperDevMode.this.port
javaExecSpec.args SuperDevMode.this.modules
println(javaExecSpec.args)
}
}));
execResult.assertNormalExitValue().rethrowFailure();
}
}
task devMode(type: DevMode, dependsOn: 'classes') {
}
task superDevMode(type: SuperDevMode, dependsOn: 'classes') {
}
task compileGwt(type: CompileGwt, dependsOn: org.gradle.api.plugins.JavaPlugin.COMPILE_JAVA_TASK_NAME) {
classpath = project.files(sourceSets.main.resources.srcDirs,
sourceSets.main.java.srcDirs,
sourceSets.main.output.classesDir,
project.configurations.getByName(GWTConstants.GWT_CONFIGURATION_NAME),
project.configurations.getByName(JavaPlugin.RUNTIME_CONFIGURATION_NAME))
warOutputDir = gwtWarDir
extraOutputDir = gwtExtraDir
}
war {
dependsOn 'compileGwt'
duplicatesStrategy = 'exclude'
from project.fileTree(gwtWarDir)
//don't pull in eclipse compile of gwt
//don't pull in jars from war/WEB-INF/lib dir (lib/gwt-servlet.jar for example)
from(GWTConstants.WAR_DIR_NAME) {
exclude PROJECT_DIR_NAME_LC
exclude GWTConstants.WEB_INF_DEPLOY_DIR_NAME
exclude GWTConstants.WEB_INF_CLASSES_DIR_NAME
exclude GWTConstants.WEB_INF_LIB_DIR_NAME
}
}
task setProjectArtifacts << {
def allProjects = [] as LinkedHashSet
GwtBase.collectDependedUponProjects(project, allProjects, "runtime")
def art = files {};
def allProjectArtifacts = [] as LinkedHashSet
allProjects.each { project ->
project.configurations.findAll().each {
allProjectArtifacts.addAll(it.allArtifacts.getFiles().getFiles())
}
};
project.ext.projectArtifacts = allProjectArtifacts
}
task copyLibs(type: Sync) {
from configurations.runtime
exclude ('**/gwt-user*')
exclude { detail ->
project.ext.projectArtifacts.contains(detail.file)
}
into GWTConstants.WAR_WEB_INF_LIB_DIR_NAME
rename 'gwt-servlet-(.+).jar', 'gwt-servlet.jar'
}
project.tasks.copyLibs.dependsOn 'setProjectArtifacts'
project.tasks.eclipse.dependsOn 'copyLibs'
eclipse.classpath.defaultOutputDir = file(GWTConstants.WAR_WEB_INF_CLASSES_DIR_NAME)