-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
478 lines (438 loc) · 15.4 KB
/
build.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
469
470
471
472
473
474
475
476
477
478
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
classpath 'io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.5.3'
}
}
plugins {
id 'checkstyle'
id 'eclipse'
id 'java'
id 'com.bmuschko.nexus' version '2.3.1'
id 'com.palantir.git-version' version '0.2.0'
}
apply plugin: 'io.codearte.nexus-staging'
repositories {
mavenCentral()
}
sourceSets {
main // Code generation utilities (org.inferred.internal.source)
testing // Testing utilities (org.inferred.internal.source-testing)
test // Unit and integration tests for both main and testing
}
sourceCompatibility = 1.6
targetCompatibility = 1.6
compileTestJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
compileTestingJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
dependencies {
compile commonsLang3
compile(googleJavaFormat) {
// Exclude transitive dependencies that don't affect the formatter
exclude module: 'jcommander'
exclude module: 'org.eclipse.equinox.app'
exclude module: 'org.eclipse.core.filesystem'
exclude module: 'org.eclipse.text'
exclude module: 'org.eclipse.equinox.registry'
}
compile guava
testingCompile javassist
testingCompile junit
testingCompile truth
testCompile guavaTestlib
testCompile hamcrest
testCompile mockito
}
tasks.withType(Test) {
testLogging {
events "passed", "skipped", "failed"
}
}
//// Testing JAR /////////////////////////////////////////////////
configurations {
testingCompile.extendsFrom compile
testingCompileOnly.extendsFrom compileOnly
testCompile.extendsFrom testingCompile
testCompileOnly.extendsFrom testingCompileOnly
}
sourceSets {
testing {
java {
compileClasspath += main.output
runtimeClasspath += main.output
}
}
test {
java {
compileClasspath += testing.output
runtimeClasspath += testing.output
}
}
}
task testingJar(type: Jar) {
group = BasePlugin.BUILD_GROUP
description = 'Assembles a jar archive containing the testing classes.'
dependsOn tasks.testingClasses
baseName = 'source-testing'
from tasks.compileTestingJava.outputs, tasks.processTestingResources.outputs
assemble.dependsOn it
}
artifacts {
archives testingJar
}
afterEvaluate {
if (extraArchive.javadoc) {
task testingJavadoc(type: Javadoc) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = 'Generates Javadoc API documentation for the testing source code.'
classpath = sourceSets.testing.output + sourceSets.testing.compileClasspath
source = sourceSets.testing.allJava
destinationDir = file("$docsDir/testing-javadoc")
title = "source-testing $version"
}
task testingJavadocJar(type: Jar) {
group = BasePlugin.BUILD_GROUP
description = 'Assembles a jar archive containing the generated Javadoc ' +
'API documentation of the testing source code.'
baseName = 'source-testing'
classifier = 'javadoc'
from tasks.testingJavadoc
}
artifacts {
archives testingJavadocJar
}
}
if (extraArchive.sources) {
task testingSourcesJar(type: Jar) {
group = BasePlugin.BUILD_GROUP
description = 'Assembles a jar archive containing the testing sources of ' +
'this project.'
baseName = 'source-testing'
classifier = 'sources'
from project.sourceSets.testing.allSource
}
artifacts {
archives testingSourcesJar
}
}
}
//// Checkstyle //////////////////////////////////////////////////
checkstyle {
toolVersion = "6.19"
configProperties['config_loc'] = "$rootDir/config/checkstyle"
}
tasks.withType(Checkstyle).each { checkstyleTask ->
checkstyleTask.doLast {
reports.all { report ->
def outputFile = report.destination
if (outputFile.exists() && outputFile.text.contains("<error ")) {
throw new GradleException("There were checkstyle warnings! See $outputFile")
}
}
}
}
eclipse.project {
natures 'net.sf.eclipsecs.core.CheckstyleNature'
buildCommand 'net.sf.eclipsecs.core.CheckstyleBuilder'
}
import org.gradle.plugins.ide.eclipse.GenerateEclipseProject
tasks.withType(GenerateEclipseProject, { generateTask ->
afterEvaluate {
generateTask.projectModel.natures 'net.sf.eclipsecs.core.CheckstyleNature'
generateTask.projectModel.buildCommand 'net.sf.eclipsecs.core.CheckstyleBuilder'
}
def taskName = generateTask.name.replaceAll('Project$','') + 'Checkstyle'
def createTask = task(taskName) {
ext.enabled = true
ext.outputFile = { new File(generateTask.outputFile.parentFile, '.checkstyle') }
outputs.file outputFile
doLast {
def output = file(outputFile)
output.parentFile.mkdirs()
output.delete()
if (enabled) {
output << """
<?xml version="1.0" encoding="UTF-8"?>
<fileset-config file-format-version="1.2.0" simple-config="false" sync-formatter="false">
<local-check-config name="Gradle configuration file" location="${checkstyle.configFile}" type="external" description="">
<additional-data name="protect-config-file" value="true"/>
</local-check-config>
<fileset name="all" enabled="true" check-config-name="Gradle configuration file" local="true">
<file-match-pattern match-pattern=".java\$" include-pattern="true"/>
</fileset>
<filter name="DerivedFiles" enabled="true"/>
</fileset-config>
""".replaceFirst('\n', '').stripIndent()
}
}
tasks.eclipse.dependsOn it
}
def cleanTaskName = 'clean' + taskName.substring(0, 1).toUpperCase() + taskName.substring(1, taskName.length())
task(cleanTaskName, type: Delete) {
delete createTask.outputFile
tasks.cleanEclipse.dependsOn it
}
})
//// Publication /////////////////////////////////////////////////
project.ext.testingPoms = []
afterEvaluate {
project.ext.poms += project.ext.testingPoms
}
group = 'org.inferred.internal'
version = (System.env.TRAVIS_TAG ?: gitVersion()).replaceAll('^v','')
modifyPom {
project {
switch (artifactId) {
case 'source':
name 'Source'
description 'A Java library for code generation'
break
case 'source-testing':
name 'Source Testing'
description 'A Java library for testing code generators'
break
default:
throw new RuntimeException("Unexpected artifact ID $artifactId")
}
url 'https://github.com/inferred/source'
scm {
url 'https://github.com/inferred/source'
connection 'scm:git:git://github.com/inferred/source.git'
developerConnection 'scm:git:[email protected]:inferred/source.git'
}
licenses {
license {
name 'Apache 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id 'chrisalice'
name 'Chris Purcell'
email '[email protected]'
timezone 'Europe/London'
}
}
}
}
tasks.withType(Upload) {
repositories.withType(MavenResolver) {
pom = addFilter('source') { artifact, file ->
artifact.name == 'source'
}
MavenPom testingPom = addFilter('source-testing') { artifact, file ->
artifact.name == 'source-testing'
}
testingPoms += [ testingPom ]
testingPom.scopeMappings.addMapping(
MavenPlugin.COMPILE_PRIORITY,
configurations.testingCompile,
Conf2ScopeMappingContainer.COMPILE)
testingPom.scopeMappings.addMapping(
MavenPlugin.RUNTIME_PRIORITY,
configurations.testingRuntime,
Conf2ScopeMappingContainer.RUNTIME)
}
}
if (System.env.PGP_KEY_ID) {
ext['signing.keyId'] = System.env.PGP_KEY_ID
ext['signing.password'] = System.env.PGP_PASSWORD
ext['signing.secretKeyRingFile'] = System.env.PGP_SECRET_KEY_RING_FILE
}
ext['nexusUsername'] = System.env.NEXUS_USERNAME
ext['nexusPassword'] = System.env.NEXUS_PASSWORD
nexusStaging {
packageGroup = 'org.inferred'
}
//// Eclipse /////////////////////////////////////////////////////
eclipse.classpath {
// Only src/main/java is compiled with JDK 6
file.withXml { xml ->
node = xml.asNode()
node.findAll { it.@kind == 'src' && it.@path != 'src/main/java' }.each { src ->
node.remove(src)
}
}
// Don't include test dependencies in the classpath
plusConfigurations.clear()
plusConfigurations += [ configurations.compileClasspath ]
}
void setFilter(project, path, filter) {
project.file.withXml {
if (asNode().find { it.name() == 'filteredResources' } == null) {
asNode().append(new XmlParser().parseText("""
<filteredResources>
<filter>
<id>""" + System.currentTimeMillis() + """</id>
<name>${path}</name>
<type>9</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-true-false-${filter}</arguments>
</matcher>
</filter>
</filteredResources>
"""))
}
}
}
// Exclude everything in src except src/main
setFilter(eclipse.project, 'src', 'main')
import org.gradle.plugins.ide.eclipse.model.EclipseModel
extensions.create("eclipseTesting", EclipseModel)
extensions.create("eclipseTest", EclipseModel)
import org.gradle.plugins.ide.eclipse.GenerateEclipseProject
import org.gradle.plugins.ide.eclipse.internal.LinkedResourcesCreator
task eclipseTestingProject(type: GenerateEclipseProject) {
description = 'Generates the Eclipse testing project file.'
inputFile = project.file('.testing/.project')
outputFile = inputFile
projectModel.name = project.name + '-testing'
projectModel.buildCommand 'org.eclipse.jdt.core.javabuilder'
projectModel.natures "org.eclipse.jdt.core.javanature"
projectModel.natures 'net.sf.eclipsecs.core.CheckstyleNature'
projectModel.buildCommand 'net.sf.eclipsecs.core.CheckstyleBuilder'
projectModel.linkedResource name: 'src', type:'2', location: 'PARENT-1-PROJECT_LOC/src'
setFilter(projectModel, 'src', 'testing')
eclipseTesting.project = projectModel
tasks.eclipse.dependsOn it
}
task cleanEclipseTestingProject(type: Delete) {
delete file('.testing/.project')
tasks.cleanEclipse.dependsOn it
}
task eclipseTestProject(type: GenerateEclipseProject) {
description = 'Generates the Eclipse test project file.'
inputFile = project.file('.test/.project')
outputFile = inputFile
projectModel.name = project.name + '-test'
projectModel.buildCommand 'org.eclipse.jdt.core.javabuilder'
projectModel.natures "org.eclipse.jdt.core.javanature"
projectModel.natures 'net.sf.eclipsecs.core.CheckstyleNature'
projectModel.buildCommand 'net.sf.eclipsecs.core.CheckstyleBuilder'
projectModel.linkedResource name: 'src', type:'2', location: 'PARENT-1-PROJECT_LOC/src'
setFilter(projectModel, 'src', 'test')
eclipseTest.project = projectModel
tasks.eclipse.dependsOn it
}
task cleanEclipseTestProject(type: Delete) {
delete file('.test/.project')
tasks.cleanEclipse.dependsOn it
}
import org.gradle.plugins.ide.eclipse.GenerateEclipseJdt
task eclipseTestingJdt(type: GenerateEclipseJdt) {
description = 'Generates the Eclipse testing JDT settings file.'
inputFile = project.file('.testing/.settings/org.eclipse.jdt.core.prefs')
outputFile = inputFile
eclipseTesting.jdt = jdt
jdt.conventionMapping.map('sourceCompatibility') { JavaVersion.toVersion(compileTestingJava.sourceCompatibility) }
jdt.conventionMapping.map('targetCompatibility') { JavaVersion.toVersion(compileTestingJava.targetCompatibility) }
jdt.conventionMapping.map('javaRuntimeName') { 'JavaSE-' + jdt.targetCompatibility }
tasks.eclipse.dependsOn it
}
task cleanEclipseTestingJdt(type: Delete) {
delete file('.testing/.settings/org.eclipse.jdt.core.prefs')
tasks.cleanEclipse.dependsOn it
}
task eclipseTestJdt(type: GenerateEclipseJdt) {
description = 'Generates the Eclipse test JDT settings file.'
inputFile = project.file('.test/.settings/org.eclipse.jdt.core.prefs')
outputFile = inputFile
eclipseTest.jdt = jdt
jdt.conventionMapping.map('sourceCompatibility') { JavaVersion.toVersion(compileTestJava.sourceCompatibility) }
jdt.conventionMapping.map('targetCompatibility') { JavaVersion.toVersion(compileTestJava.targetCompatibility) }
jdt.conventionMapping.map('javaRuntimeName') { 'JavaSE-' + jdt.targetCompatibility }
tasks.eclipse.dependsOn it
}
task cleanEclipseTestJdt(type: Delete) {
delete file('.test/.settings/org.eclipse.jdt.core.prefs')
tasks.cleanEclipse.dependsOn it
}
import org.gradle.api.internal.plugins.DslObject
import org.gradle.internal.xml.XmlTransformer
import org.gradle.plugins.ide.api.XmlFileContentMerger
import org.gradle.plugins.ide.eclipse.GenerateEclipseClasspath
import org.gradle.plugins.ide.eclipse.model.EclipseClasspath
task eclipseTestingClasspath(type: GenerateEclipseClasspath) {
description = 'Generates the Eclipse testing classpath file.'
inputFile = project.file('.testing/.classpath')
outputFile = inputFile
classpath = new EclipseClasspath(project)
classpath.file = new XmlFileContentMerger((XmlTransformer) getProperty('xmlTransformer'))
classpath.sourceSets = []
project.afterEvaluate {
Set<String> containers = new LinkedHashSet<>()
containers.add(
'org.eclipse.jdt.launching.JRE_CONTAINER/'
+ 'org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/'
+ eclipseTesting.jdt.javaRuntimeName + '/')
containers.addAll(classpath.containers)
classpath.containers = containers
}
classpath.plusConfigurations += [
configurations.testingCompileClasspath
]
classpath.defaultOutputDir = project.file('.testing/bin')
dependsOn sourceSets.main.output.dirs
dependsOn sourceSets.testing.output.dirs
eclipseTesting.classpath = classpath
tasks.eclipse.dependsOn it
}
task cleanEclipseTestingClasspath(type: Delete) {
delete file('.testing/.classpath')
tasks.cleanEclipse.dependsOn it
}
task eclipseTestClasspath(type: GenerateEclipseClasspath) {
description = 'Generates the Eclipse test classpath file.'
inputFile = project.file('.test/.classpath')
outputFile = inputFile
classpath = new EclipseClasspath(project)
classpath.file = new XmlFileContentMerger((XmlTransformer) getProperty('xmlTransformer'))
classpath.sourceSets = []
project.afterEvaluate {
Set<String> containers = new LinkedHashSet<>()
containers.add(
'org.eclipse.jdt.launching.JRE_CONTAINER/'
+ 'org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/'
+ eclipseTest.jdt.javaRuntimeName + '/')
containers.addAll(classpath.containers)
classpath.containers = containers
}
classpath.plusConfigurations += [
configurations.testCompileClasspath
]
classpath.defaultOutputDir = project.file('.test/bin')
dependsOn sourceSets.main.output.dirs
dependsOn sourceSets.testing.output.dirs
dependsOn sourceSets.test.output.dirs
eclipseTest.classpath = classpath
tasks.eclipse.dependsOn it
}
task cleanEclipseTestClasspath(type: Delete) {
delete file('.test/.classpath')
tasks.cleanEclipse.dependsOn it
}
import org.gradle.plugins.ide.eclipse.model.ProjectDependency
import org.gradle.plugins.ide.eclipse.model.SourceFolder
eclipseTesting.classpath.file.beforeMerged {
entries += [
new SourceFolder('/' + project.name, null),
new SourceFolder('src/testing/java', null)
]
}
eclipseTest.classpath.file.beforeMerged {
entries += [
new SourceFolder('/' + project.name, null),
new SourceFolder('/' + project.name + '-testing', null),
new SourceFolder('src/test/java', null)
]
}