-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
93 lines (78 loc) · 3.09 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
/*
* Copyright (c) 2012-2014 nadavc <https://twitter.com/nadavc>
* This work is free. You can redistribute it and/or modify it under the
* terms of the WTFPL, Version 2, as published by Sam Hocevar.
* See the COPYING file for more details.
*/
import java.awt.*
import java.util.List
apply plugin: 'groovy'
apply from: 'gradle/idea.gradle'
apply from: 'gradle/eclipse.gradle'
version = '0.5'
repositories {
jcenter()
}
dependencies {
def groovyComponents = ['groovy', 'groovy-ant', 'groovy-sql', 'groovy-test']
testCompile groovyComponents.collect { "org.codehaus.groovy:$it:2.4.3" }
testCompile 'com.h2database:h2:1.3.168'
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
}
task removeSolutions {
description = 'Removes the solutions from all Koans, so you can start fresh!'
doLast {
def solutionsRemoved = 0
def solutionRegex = $/(?sm)(// -{12} START EDITING HERE -{22})(.*?)(\s+// -{12} STOP EDITING HERE -{22})/$
sourceSets.test.allSource.files.each { File sourceFile ->
solutionsRemoved += (sourceFile.text =~ solutionRegex).count
sourceFile.text = sourceFile.text.replaceAll(solutionRegex, '$1\n\n$3')
}
println "Removed $solutionsRemoved solutions from Koans. Good luck!"
}
}
// Adapted from http://www.practicalgradle.org/blog/2011/01/convenient-test-execution-with-camel-case-support/
tasks.addRule('Pattern: koan<Number>: Runs a single Koan') { String taskName ->
if (taskName.startsWith('koan') && taskName.length() > 5) {
// create a dummy task for the task name specified on the command line
def dummyTask = task(taskName)
def koanName = taskName[0].toUpperCase() + taskName[1..-1]
// make all Test tasks a dependency of the dummy task and reset the includes
tasks.withType(Test) { testTask ->
logger.info("Single Koan Execution: apply include pattern to Test task <$testTask.name>")
testTask.includes = WrapUtil.toSet("**/${koanName}.class")
dummyTask.dependsOn testTask
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.8'
}
// show welcome message
task sayHello << {
List<String> lines = file('gradle/one-liners.txt').readLines()
def quote = lines.get(new Random().nextInt(lines.size() - 1))
println "Groovy Koans ${version}:\n${quote}"
println "${'-' * quote.size()}\n"
}
test.dependsOn sayHello
// launch browser if test failed. otherwise show that koan is complete
gradle.taskGraph.afterTask { task, taskState ->
if (task.name != 'test')
return
if (taskState.failure) {
String testRepDir = project.testReportDir
Desktop.desktop.browse(new File(testRepDir, 'index.html').toURI())
} else {
println "Koan is complete. Well done!"
}
}
// since we're running in quiet logging, show the user what tests are running
tasks.withType(Test) { testTask ->
testTask.beforeTest { descriptor ->
print "Running exercises in $descriptor.name()".padRight(60, '.')
}
testTask.afterTest { descriptor, result ->
println result.resultType
}
}