forked from stacktracejs/stacktrace.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
123 lines (101 loc) · 3.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
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.eriwen:gradle-js-plugin:1.1'
}
}
apply plugin: 'js'
defaultTasks 'all'
buildDir = 'target'
def srcFile = 'stacktrace.js'
def destFile = "${buildDir}/stacktrace-min.js"
def testDir = 'test'
repositories {
mavenRepo url: 'http://repository.springsource.com/maven/bundles/release'
mavenCentral()
}
task clean(type: Delete) {
delete buildDir
}
task init(type: Directory, dependsOn: 'clean', description: 'Creates artifact output directories') {
outputs.dir(buildDir)
doLast {
file(buildDir).mkdirs()
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.1'
}
task jshintz(dependsOn: 'init', description: 'runs jshint on all non-test and lib JS files') {
doLast {
def command = "jshint ${new File('stacktrace.js').canonicalPath} --config jshint.json --jslint-reporter"
new File("${buildDir}/jshint.xml").write(command.execute().text)
}
}
task jsduck(type: Exec, dependsOn: 'init', description: 'Generates jsduck documentation') {
inputs.file file(srcFile)
outputs.file file("${buildDir}/docs")
commandLine = ['jsduck', srcFile, '--output', "${buildDir}/docs"]
ignoreExitValue = true
}
minifyJs {
dependsOn << 'init'
source = file(srcFile)
dest = file(destFile)
closure {
warningLevel = 'QUIET'
}
}
gzipJs {
source = minifyJs
dest = file(destFile)
}
task test(dependsOn: 'init') << {
description = 'run QUnit tests and create JUnit test reports'
def specs = []
new File(testDir).eachFile {
if (it.name.endsWith('.html')) {
specs << it
}
}
def phantomJsPath = "which phantomjs".execute().text.trim()
def startTime = new Date().time
def numFailures = 0
def testsFailed = false
specs.each { File spec ->
print "Running ${spec.name}..."
def outputFile = "${buildDir}/TEST-${spec.name.replace('-', '').replace('.html', '.xml')}"
ant.exec(outputproperty: 'cmdOut', errorproperty: 'cmdErr',
resultproperty: 'exitCode', failonerror: 'false', executable: phantomJsPath) {
arg(value: 'test/lib/phantomjs-qunit-runner.js')
arg(value: spec.canonicalPath)
}
// Check exit code
if (ant.project.properties.exitCode != '0') {
testsFailed = true
numFailures++
println 'FAILED'
} else {
println 'PASSED'
}
new File(outputFile).write(ant.project.properties.cmdOut)
}
println "QUnit tests completed in ${new Date().time - startTime}ms"
println "QUnit Tests ${testsFailed ? 'FAILED' : 'PASSED'} - view reports in ${buildDir}"
ant.fail(if: testsFailed, message: 'JS Tests Failed')
}
task jstd(type: Exec, dependsOn: 'init', description: 'runs JS tests through JsTestDriver') {
// Default to MacOS and check for other environments
def firefoxPath = '/Applications/Firefox.app/Contents/MacOS/firefox'
if ("uname".execute().text.trim() != 'Darwin') {
firefoxPath = "which firefox".execute().text.trim()
}
commandLine = ['/usr/bin/env', 'DISPLAY=:1', 'java', '-jar', "test/lib/JsTestDriver-1.3.3d.jar", '--config', "test/jsTestDriver.conf", '--port', '4224', '--browser', firefoxPath, '--tests', 'all', '--testOutput', buildDir]
}
task jsCoverage(type: Exec, dependsOn: 'jstd', description: 'JS code coverage with cobertura') {
commandLine = ['python', "${projectDir}/test/lib/lcov-to-cobertura-xml.py", '-e', 'test.lib', '-o', "${buildDir}/coverage.xml", "${buildDir}/jsTestDriver.conf-coverage.dat"]
}
task all(dependsOn: ['clean', 'jshintz', 'test', 'jsduck', 'minifyJs', 'gzipJs']) << {}