1+ buildscript {
2+ repositories {
3+ mavenLocal()
4+ mavenCentral()
5+ }
6+ dependencies {
7+ classpath ' com.eriwen:gradle-js-plugin:0.2'
8+ }
9+ }
10+
11+ apply plugin : ' js'
12+
113defaultTasks ' all'
14+ buildDir = " ../target"
215
3- def srcDir = ' ..'
4- def outputDir = ' target'
5- def jshintConfig = ' jshint.json'
6- def jshintOutput = outputDir + ' /jshint.xml'
16+ def srcFile = " ../stacktrace.js"
17+ def destFile = " ${ buildDir} /stacktrace-min.js"
718def testDir = ' test'
8- def minifiedFilePath = " ../${ outputDir} /stacktrace-min.js"
919
1020repositories {
1121 mavenRepo urls : ' http://repository.springsource.com/maven/bundles/release'
1222 mavenCentral()
1323}
1424
15- configurations {
16- js
25+ task clean ( description : ' Cleans old artifacts ' ) << {
26+ ant . delete( dir : buildDir)
1727}
1828
19- dependencies {
20- js ' com.google.javascript:closure-compiler:r+'
29+ task init (type : Directory , dependsOn : ' clean' , description : ' Creates artifact output directories' ) {
30+ outputs. dir(buildDir)
31+ file(buildDir). mkdirs()
32+ doLast {
33+ file(buildDir). mkdirs()
34+ }
2135}
2236
23- task clean << {
24- description = ' Cleans old artifacts'
25- ant. delete(dir : outputDir)
26- ant. delete(file : jshintOutput)
37+ task wrapper (type : Wrapper ) {
38+ gradleVersion = ' 1.0-milestone-5'
2739}
2840
29- task init (dependsOn : ' clean' ) << {
30- description = ' Creates artifact output directories'
31- (new File (outputDir)). mkdirs()
41+ task jshintz (type : Exec , dependsOn : ' init' , description : ' runs jshint on all non-test and lib JS files' ) {
42+ inputs. file file(srcFile)
43+ outputs. file file(" ${ buildDir} /jshint.xml" )
44+
45+ commandLine = [" jshint" , srcFile, " --config" , ' jshint.json' , " --jslint-reporter" ]
46+ standardOutput = new BufferedOutputStream (new FileOutputStream (" ${ buildDir} /jshint.xml" ))
3247}
3348
34- task minify << {
35- description = ' minify JS file'
36- project. ant {
37- ant. taskdef(name : ' jscomp' ,
38- classname : ' com.google.javascript.jscomp.ant.CompileTask' ,
39- classpath : configurations. js. asPath)
40-
41- jscomp(compilationLevel : ' simple' , warning : ' quiet' , debug : ' false' , output : minifiedFilePath) {
42- sources(dir : srcDir) {
43- file(name : ' stacktrace.js' ){}
44- }
45- }
46- }
49+ task jsduck (type : Exec , dependsOn : ' init' , description : ' Generates jsduck documentation' ) {
50+ inputs. file file(srcFile)
51+ outputs. file file(" ${ buildDir} /docs" )
52+
53+ commandLine = [' jsduck' , srcFile, ' --output' , " ${ buildDir} /docs" ]
54+ ignoreExitValue = true
4755}
4856
49- task zip << {
50- description = ' GZip file for distribution'
51- ant. gzip(src : minifiedFilePath, destfile : " ${ minifiedFilePath} .gz" )
52- ant. move(file : " ${ minifiedFilePath} .gz" , tofile : minifiedFilePath)
57+ minifyJs {
58+ dependsOn << ' init'
59+ input = file(srcFile)
60+ output = file(destFile)
61+ warningLevel = ' QUIET'
5362}
5463
55- task jshint (dependsOn : ' init' ) << {
56- description = ' runs jshint on stacktrace JS file'
57- def command = " jshint ${ new File('stacktrace.js').canonicalPath} --config ${ jshintConfig} --jslint-reporter"
58- println command
59- new File (jshintOutput). write(command. execute(). text)
64+ gzipJs {
65+ dependsOn << ' minifyJs'
66+ input = file(destFile)
67+ output = input
6068}
6169
6270task test (dependsOn : ' init' ) << {
@@ -73,31 +81,45 @@ task test(dependsOn: 'init') << {
7381 def numFailures = 0
7482 def testsFailed = false
7583 specs. each { File spec ->
76- println " Running ${ spec.name} ..."
84+ print " Running ${ spec.name} ..."
7785
78- def outputFile = " ${ outputDir } /TEST-${ spec.name.replace('-', '').replace('.html', '.xml')} "
86+ def outputFile = " ${ buildDir } /TEST-${ spec.name.replace('-', '').replace('.html', '.xml')} "
7987 ant. exec(outputproperty : ' cmdOut' , errorproperty : ' cmdErr' ,
8088 resultproperty : ' exitCode' , failonerror : ' false' , executable : ' /usr/bin/env' ) {
8189 arg(value : ' DISPLAY=:1' )
8290 arg(value : ' /usr/local/bin/phantomjs' )
83- arg(value : ' ../test/lib/phantomjs-qunit-runner.js' )
91+ arg(value : " ../test/lib/phantomjs-qunit-runner.js" )
8492 arg(value : " ${ spec.canonicalPath} " )
8593 }
8694 // Check exit code
8795 if (ant. project. properties. exitCode != ' 0' ) {
8896 testsFailed = true
8997 numFailures++
90- println ' \t FAILED '
98+ println ' FAILED '
9199 } else {
92- println ' \t PASSED '
100+ println ' PASSED '
93101 }
94102
95103 new File (outputFile). write(ant. project. properties. cmdOut)
96104 }
97105
98106 println " QUnit tests completed in ${ new Date().time - startTime} ms"
99- println " QUnit Tests ${ testsFailed ? 'FAILED' : 'PASSED'} - view reports in ${ outputDir } "
107+ println " QUnit Tests ${ testsFailed ? 'FAILED' : 'PASSED'} - view reports in ${ buildDir } "
100108 ant. fail (if : testsFailed, message : ' JS Tests Failed' )
101109}
102110
103- task all (dependsOn : [' clean' , ' minify' , ' zip' , ' jshint' , ' test' ]) << {}
111+ task jstd (type : Exec , dependsOn : ' init' , description : ' runs JS tests through JsTestDriver' ) {
112+ // Default to MacOS and check for other environments
113+ def firefoxPath = ' /Applications/Firefox.app/Contents/MacOS/firefox'
114+ if (" uname" . execute(). text. trim() != ' Darwin' ) {
115+ firefoxPath = " which firefox" . execute(). text
116+ }
117+
118+ 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]
119+ }
120+
121+ task jsCoverage (type : Exec , dependsOn : ' jstd' , description : ' JS code coverage with cobertura' ) {
122+ commandLine = [' python' , " ${ projectDir} /test/lib/lcov-to-cobertura-xml.py" , ' -b' , " ../" , ' -e' , ' test.lib' , ' -o' , " ${ buildDir} /coverage.xml" , " ${ buildDir} /jsTestDriver.conf-coverage.dat" ]
123+ }
124+
125+ task all (dependsOn : [' clean' , ' jshintz' , ' test' , ' jsduck' , ' minifyJs' , ' gzipJs' ]) << {}
0 commit comments