-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.gradle
387 lines (328 loc) · 11.9 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
/*
* Copyright 2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.tools.ant.filters.ReplaceTokens
//===========================================
// Basic
//===========================================
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: AnsiColorConsoleLogPlugin
apply plugin: "io.sdkman.vendors"
defaultTasks 'clean', 'check', 'dist' // whole tasks
// keep same as groovy-core
sourceCompatibility = 1.6
targetCompatibility = 1.6
repositories {
mavenLocal()
mavenCentral()
}
configurations {
// dependencies for archives are picked at compile configuration
compile.extendsFrom archives
}
dependencies {
compile "org.codehaus.groovy:groovy-all:${groovyVersion}"
compile 'commons-cli:commons-cli:1.3.1'
archives 'net.java.dev.jna:jna:4.2.2'
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
testRuntime 'cglib:cglib-nodep:3.1' // for spock: enables mocking of classes (in addition to interfaces)
testRuntime 'org.objenesis:objenesis:2.1' // for spock: enables mocking of without default constructor (together with CGLIB)
}
tasks.withType(AbstractCompile)*.options*.encoding = tasks.withType(GroovyCompile)*.groovyOptions*.encoding = 'UTF-8'
//===========================================
// Tasks
//===========================================
//----------------------------------
// copySpec
def localBinSpec = copySpec {
from("$projectDir") {
include "*.txt"
include "*.md"
}
into('lib') {
from configurations.archives
from "$buildDir/libs"
}
into('bin') {
fileMode = 0755
from "$buildDir/platforms/local"
}
}
def binSpec = copySpec {
from("$projectDir") {
include "*.txt"
include "*.md"
}
into('lib') {
from configurations.archives
from "$buildDir/libs"
}
into('platforms') {
fileMode = 0755
from "$buildDir/platforms"
exclude "local"
}
into('bin') {
fileMode = 0755
from "$projectDir/src/main/sh"
from "$projectDir/src/main/bat"
// dummy commands for setup
from "$projectDir/src/main/sh", { rename 'setup.sh', 'groovyclient' }
from "$projectDir/src/main/sh", { rename 'setup.sh', 'groovyserver' }
from "$projectDir/src/main/bat", { rename 'setup.bat', 'groovyserver.bat' }
from "$projectDir/src/main/bat", { rename 'setup.bat', 'groovyclient.bat' }
}
}
def srcSpec = copySpec {
from("$projectDir") {
include "*.txt"
include "*.md"
include "settings.gradle"
include "build.gradle"
include "gradle.properties"
include "Makefile"
}
into("src") {
from "$projectDir/src"
}
into("contrib") {
from "$projectDir/contrib"
}
from("$projectDir") {
fileMode = 0755
include "gradlew*"
}
into("gradle") {
from "$projectDir/gradle"
}
into("buildSrc") {
from "$projectDir/buildSrc"
include "src/**"
include "build.gradle"
}
into("docs") {
from "$projectDir/docs"
}
}
//----------------------------------
// Build
compileGroovy {
// Compiling just for checking at a compile time
source = [file("$projectDir/src/main/java"), file("$projectDir/src/main/groovy")]
destinationDir = file("$buildDir/classes/compile-static")
groovyOptions.configurationScript = file("$projectDir/gradle/configScript.groovy")
doLast {
// Groovy sources shouldn't be compiled in order to avoid a trouble
// of unmatch of Java version between compile-time and runtime.
// Groovy classes compiled from src/main/groovy are used only by unit tests.
// Instead, Groovy sources including JAR file under build/executables directory are used by integration tests.
copy {
into "$buildDir/classes/main"
from "$projectDir/src/main/groovy"
filter(ReplaceTokens, tokens: [GROOVYSERV_VERSION: project.version])
}
}
}
task compileGo {
inputs.dir file("$projectDir/src/main/go")
outputs.dir file("$buildDir/platforms/local")
doLast {
ansi.printlnAsInfo ">> Compiling Go sources..."
fileTree("$projectDir/src/main/go/cmd").include("**/*.go").each { srcFile ->
// for local environment by default for testing
def outputFileName = srcFile.name - '.go'
def env = [:]
if (isWindows()) {
outputFileName += ".exe"
}
compileGoSrc(srcFile, outputFileName, "local", env)
}
}
}
task crossCompileGo {
inputs.dir file("$projectDir/src/main/go")
outputs.dir file("$buildDir/platforms/")
doLast {
ansi.printlnAsInfo ">> Cross compiling Go sources..."
fileTree("$projectDir/src/main/go/cmd").include("**/*.go").each { srcFile ->
[
[GOOS: "darwin", GOARCH: "amd64"],
[GOOS: "linux", GOARCH: "386"],
[GOOS: "linux", GOARCH: "amd64"],
[GOOS: "windows", GOARCH: "386", ext: ".exe"],
].each { platform ->
def outputFileName = srcFile.name - '.go' + (platform.ext ?: '')
compileGoSrc(srcFile, outputFileName, "${platform.GOOS}_${platform.GOARCH}", platform.subMap('GOOS', 'GOARCH'))
}
}
}
}
task executables(type: Copy, dependsOn: ['assemble', 'compileGo']) {
destinationDir = file("$buildDir/executables")
inputs.dir file("$projectDir/src/main")
outputs.dir destinationDir
with localBinSpec
ext.executablesDir = destinationDir
}
task expandDistBin(type: Copy, dependsOn: ['assemble', 'crossCompileGo'], description: "Expand a distBin archive to work directory") {
destinationDir = file("$buildDir/executables-dist")
inputs.dir file("$projectDir/src/main")
outputs.dir destinationDir
with binSpec
}
//----------------------------------
// Distribution
task dist(dependsOn: ['distBin', 'distSrc'], description: "Make all distribution archives.", group: "Distribution")
task distBin(type: Zip, dependsOn: ['assemble', 'crossCompileGo'], description: "Make a distribution archive of binaries.", group: "Distribution") {
inputs.dir file("$projectDir/src/main")
baseName = project.name
classifier = 'bin'
into "$baseName-$version"
with binSpec
}
task distSrc(type: Zip, description: "Make a distribution archive of source code.", group: "Distribution") {
inputs.dir file("$projectDir/src/main")
baseName = project.name
classifier = 'src'
into "$baseName-$version"
with srcSpec
}
task distLocalBin(type: Zip, dependsOn: ['assemble', 'compileGo'], description: "Make a distribution archive of binaries only for a direct use by self-built.", group: "Distribution") {
inputs.dir file("$projectDir/src/main")
baseName = project.name
classifier = 'bin-local'
into "$baseName-$version"
with localBinSpec
}
//----------------------------------
// Test
test {
// This causes running this task even though UP-TO-DATE skipping condition is met.
systemProperty 'spock.configuration', "spock/unit.groovy"
}
task integrationTest(type: Test, dependsOn: 'executables', description: "Run all integration tests.", group: "Verification") {
mustRunAfter "test"
maxParallelForks = 1 // Avoiding run in parallel
reports.html.enabled = false
// This causes running this task even though UP-TO-DATE skipping condition is met.
systemProperty 'spock.configuration', "spock/integration.groovy"
// prop for TestUtils
def binDir = normalizePath(file("${executables.executablesDir}/bin"))
systemProperty 'groovyserv.executable.client', "$binDir/groovyclient"
systemProperty 'groovyserv.executable.server', "$binDir/groovyserver"
doFirst {
restartGroovyServer()
}
doLast {
shutdownGroovyServer()
}
finalizedBy "mergeTestReports"
}
check.dependsOn integrationTest
task mergeTestReports(type: TestReport, group: "Verification") {
destinationDir = file("$buildDir/reports/tests")
// These must point to the binary test results directory generated by a Test task instance.
// If Test task instances are specified directly, this task would depend on them and run them.
reportOn files("$buildDir/test-results/binary/test", "$buildDir/test-results/binary/integrationTest")
}
tasks.withType(Test).each {
it.testLogging {
// show standard out and standard error of the test JVM(s) on the console
showStandardStreams = true
// show the message on failure
exceptionFormat "full"
events "failed"
}
}
//------------------------
// Gradle wrapper
task wrapper(type: Wrapper) {
gradleVersion = '2.14'
}
//------------------------
// Documentation
task docs(description: "Build documentation by Gaiden.", group: "Documentation") {
ext.srcDir = file("$projectDir/docs")
ext.outputDir = file("$buildDir/docs")
ext.env = [
GROOVYSERV_VERSION: project.version,
GROOVY_VERSION: groovyVersion
]
inputs.dir srcDir
inputs.file file("$projectDir/gradle.properties")
outputs.dir outputDir
doLast {
executeCommand(['gaiden', 'build'], env, srcDir)
}
}
task watchDocs(description: "Build documentation continually by Gaiden.", group: "Documentation") << {
executeCommand(['gaiden', 'watch'], docs.env, docs.srcDir)
}
task publishToGhpages(dependsOn: "docs", description: "Copy documentation to gh-pages branch.", group: "Documentation") << {
executeCommand(['git', 'checkout', 'gh-pages'])
delete "*.html", "sources", "static", "css", "extensions", "fonts", "images", "js"
copy {
into "$projectDir"
from docs.outputDir
}
}
//------------------------
// Deployment
sdkman {
api = "https://vendors.sdkman.io/"
// You must set these variables in $HOME/.gradle/gradle.properties
consumerKey = sdkmanConsumerKey
consumerToken = sdkmanConsumerToken
candidate = "groovyserv"
version = project.version
url = "https://bitbucket.org/kobo/groovyserv-mirror/downloads/groovyserv-${project.version}-bin.zip"
hashtag = "#groovyserv"
}
//===========================================
// Helpers
//===========================================
def restartGroovyServer() {
ansi.printlnAsInfo ">> Restarting groovyserver..."
operateServer(["-r", "-v"])
}
def shutdownGroovyServer() {
ansi.printlnAsInfo ">> Shutting down groovyserver..."
operateServer(["-k"])
}
def operateServer(List options) {
def binDir = normalizePath(file("${executables.executablesDir}/bin"))
def groovyserverPath = "$binDir/groovyserver"
executeCommand([groovyserverPath, *options])
}
def executeCommand(List command, Map additionalEnv = [:], File workDir = null) {
ansi.printlnAsInfo ">> Executing command..."
ansi.printlnAsInfo "\$ ${command.join(' ')}"
exec {
commandLine command
environment additionalEnv
if (workDir) workingDir workDir
}
}
def normalizePath(File file) {
file.canonicalPath.replaceAll('\\\\', '/')
}
def isWindows() {
ant.condition(property: "os", value: "windows") { os(family: "windows") }
return ant.properties['os'] == "windows"
}
def compileGoSrc(File srcFile, String outputFileName, String platform, Map<String, String> env = [:]) {
executeCommand(["go", "build", "--ldflags", "-w -s \"-X=main.GroovyServVersion=${project.version}\"", "-o", "$buildDir/platforms/$platform/$outputFileName", srcFile.path], env)
}