forked from nadavc/groovykoans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
95 lines (81 loc) · 3.21 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
/**
* Copyright 2012 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 java.awt.Desktop
apply plugin: 'groovy'
apply from: 'gradle/idea.gradle'
version = '0.3.1'
repositories {
mavenCentral()
}
dependencies {
def groovyComponents = ['groovy', 'groovy-ant', 'groovy-sql', 'groovy-test']
groovy groovyComponents.collect { "org.codehaus.groovy:$it:2.0.5" }
groovy 'com.h2database:h2:1.3.168'
}
task removeSolutions << {
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 = '1.1'
}
// 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 = task.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
}
}