Skip to content

Commit

Permalink
Flexible outputs for eriwen#23
Browse files Browse the repository at this point in the history
  • Loading branch information
eriwen committed Jul 1, 2012
1 parent 0645bde commit ca95f3e
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'idea'

defaultTasks 'clean', 'build'

version = '1.0.3'
version = '1.0.4'
group = 'com.eriwen'
ext.archivesBaseName = 'gradle-js-plugin'
ext.isSnapshot = version.endsWith("-SNAPSHOT")
Expand Down
10 changes: 5 additions & 5 deletions plugin.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.eriwen:gradle-js-plugin:1.0.3'
classpath 'com.eriwen:gradle-js-plugin:1.0.4'
}
}

Expand All @@ -31,7 +31,7 @@ task clean(type: Delete) {
// Combine JS files
task combine(type: com.eriwen.gradle.js.tasks.CombineJsTask) {
source = javascript.source.custom.js.files
dest = file("${buildDir}/all.js")
dest = "${buildDir}/all.js"
}

// Minify with Google Closure Compiler
Expand All @@ -52,17 +52,17 @@ def version = "1.7.2"
// GZip it!
task gzip(type: com.eriwen.gradle.js.tasks.GzipJsTask) {
source = minify
dest = file("${buildDir}/all-${version}.min.js")
dest = "${buildDir}/all-${version}.min.js"
}

task jshintz(type: com.eriwen.gradle.js.tasks.JsHintTask) {
source = javascript.source.custom.js.files
dest = file("${buildDir}/jshint.out")
dest = "${buildDir}/jshint.out"
}

task jsdocz(type: com.eriwen.gradle.js.tasks.JsDocTask) {
source = javascript.source.custom.js.files
destinationDir = file("${buildDir}/jsdoc")
destinationDir = "${buildDir}/jsdoc"
}

task props(type: com.eriwen.gradle.js.tasks.Props2JsTask) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.SourceTask

class CombineJsTask extends SourceTask {
@OutputFile File dest
@OutputFile def dest

File getDest() {
project.file(dest)
}

@TaskAction
def run() {
ant.concat(destfile: dest.canonicalPath, fixlastline: 'yes') {
ant.concat(destfile: (dest as File).canonicalPath, fixlastline: 'yes') {
source.files.each {
logger.info("Adding to fileset: ${it}")
fileset(file: it)
Expand Down
8 changes: 6 additions & 2 deletions src/main/groovy/com/eriwen/gradle/js/tasks/GzipJsTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ import org.gradle.api.tasks.SourceTask
import org.gradle.api.tasks.TaskAction

class GzipJsTask extends SourceTask {
@OutputFile File dest
@OutputFile def dest

File getDest() {
project.file(dest)
}

@TaskAction
def run() {
final String srcPath = source.singleFile.canonicalPath
ant.gzip(src: srcPath, destfile: "${srcPath}.gz")
ant.move(file: "${srcPath}.gz", tofile: dest.canonicalPath)
ant.move(file: "${srcPath}.gz", tofile: (dest as File).canonicalPath)
}
}
9 changes: 6 additions & 3 deletions src/main/groovy/com/eriwen/gradle/js/tasks/JsDocTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ class JsDocTask extends SourceTask {
Iterable<String> modulePaths = ['node_modules', 'rhino_modules', '.']
Boolean debug = false

@OutputDirectory
File destinationDir
@OutputDirectory def destinationDir

File getDestinationDir() {
project.file(destinationDir)
}

@TaskAction
def run() {
Expand All @@ -48,7 +51,7 @@ class JsDocTask extends SourceTask {
}
args.add("${workingDir}${File.separator}jsdoc.js")
args.addAll(source.files.collect { it.canonicalPath })
args.addAll(['-d', destinationDir.absolutePath])
args.addAll(['-d', (destinationDir as File).absolutePath])
args.addAll(project.jsdoc.options.collect { it })

rhino.execute(args, [workingDir: workingDir])
Expand Down
8 changes: 6 additions & 2 deletions src/main/groovy/com/eriwen/gradle/js/tasks/JsHintTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ class JsHintTask extends SourceTask {
private static final ResourceUtil RESOURCE_UTIL = new ResourceUtil()
private final RhinoExec rhino = new RhinoExec(project)

@OutputFile File dest;
@OutputFile def dest

File getDest() {
project.file(dest)
}

@TaskAction
def run() {
final File jshintJsFile = RESOURCE_UTIL.extractFileToDirectory(
new File(project.buildDir, TMP_DIR), JSHINT_PATH)
final List<String> args = [jshintJsFile.canonicalPath]
args.addAll(source.files.collect { it.canonicalPath })
rhino.execute(args, [ignoreExitCode: true, out: new FileOutputStream(dest)])
rhino.execute(args, [ignoreExitCode: true, out: new FileOutputStream(dest as File)])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ import org.gradle.api.tasks.TaskAction
class MinifyJsTask extends SourceTask {
private static final JsMinifier MINIFIER = new JsMinifier()

@OutputFile File dest
@OutputFile def dest

File getDest() {
project.file(dest)
}

@TaskAction
def run() {
Set<File> externsFiles = project.closure.externs ? project.closure.externs.files : [] as Set<File>
MINIFIER.minifyJsFile(source.singleFile, externsFiles, dest,
MINIFIER.minifyJsFile(source.singleFile, externsFiles, dest as File,
project.closure.compilerOptions, project.closure.warningLevel, project.closure.compilationLevel)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ class Props2JsTask extends SourceTask {
private static final ResourceUtil RESOURCE_UTIL = new ResourceUtil()
private static final Set<String> AVAILABLE_TYPES = ['js', 'json', 'jsonp']

@OutputFile
File dest
@OutputFile def dest

File getDest() {
project.file(dest)
}

@TaskAction
def run() {
Expand All @@ -53,7 +56,7 @@ class Props2JsTask extends SourceTask {
if (functionName) {
props2JsArgs.addAll(['--name', functionName])
}
props2JsArgs.addAll(['-o', dest.canonicalPath])
props2JsArgs.addAll(['-o', (dest as File).canonicalPath])
project.javaexec {
main = '-jar'
args = props2JsArgs
Expand Down

0 comments on commit ca95f3e

Please sign in to comment.