Skip to content

Commit

Permalink
Using Gradle built-ins to detect single-file inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
eriwen committed Jun 21, 2012
1 parent 80d33df commit aec2464
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ package com.eriwen.gradle.js

import com.google.javascript.jscomp.CompilerOptions
import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.Input

class ClosureCompilerExtension {
public static final NAME = "closure"
CompilerOptions compilerOptions = new CompilerOptions()
String compilationLevel = 'SIMPLE_OPTIMIZATIONS'
String warningLevel = 'DEFAULT'
FileCollection externs = null
@Input CompilerOptions compilerOptions = new CompilerOptions()
@Input String compilationLevel = 'SIMPLE_OPTIMIZATIONS'
@Input String warningLevel = 'DEFAULT'
@Input FileCollection externs = null
}
4 changes: 3 additions & 1 deletion src/main/groovy/com/eriwen/gradle/js/JsDocExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
*/
package com.eriwen.gradle.js

import org.gradle.api.tasks.Input

class JsDocExtension {
public static final String NAME = 'jsdoc'

Iterable<String> options = []
@Input Iterable<String> options = []
}
6 changes: 4 additions & 2 deletions src/main/groovy/com/eriwen/gradle/js/Props2JsExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*/
package com.eriwen.gradle.js

import org.gradle.api.tasks.Input

class Props2JsExtension {
public static final NAME = 'props'

String type = 'json'
String functionName = ''
@Input String type = 'json'
@Input String functionName = ''
}
2 changes: 1 addition & 1 deletion src/main/groovy/com/eriwen/gradle/js/ResourceUtil.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ class ResourceUtil {

return zipTargetDir
}
}
}
10 changes: 7 additions & 3 deletions src/main/groovy/com/eriwen/gradle/js/RhinoExec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ class RhinoExec {
private static final String RHINO_MAIN_CLASS = 'org.mozilla.javascript.tools.shell.Main'
Project project

void execute(final Iterable<String> execargs, final String workingDirIn = '.', final Boolean ignoreExitCode = false) {
def options = {
void execute(final Iterable<String> execargs, final Map<String, Object> options = [:]) {
final String workingDirIn = options.get('workingDir', '.')
final Boolean ignoreExitCode = options.get('ignoreExitCode', false).asBoolean()
final OutputStream out = options.get('out', System.out) as OutputStream
def execOptions = {
main = RHINO_MAIN_CLASS
classpath = project.configurations.rhino
args = execargs
workingDir = workingDirIn
ignoreExitValue = ignoreExitCode
standardOutput = out
}

project.javaexec(options)
project.javaexec(execOptions)
}

public RhinoExec(final Project projectIn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.SourceTask

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

@TaskAction
def run() {
Expand Down
9 changes: 2 additions & 7 deletions src/main/groovy/com/eriwen/gradle/js/tasks/GzipJsTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,16 @@
*/
package com.eriwen.gradle.js.tasks

import org.gradle.api.GradleException
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.SourceTask
import org.gradle.api.tasks.TaskAction

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

@TaskAction
def run() {
if (source.files.size() != 1) {
throw new GradleException("Only 1 file can be minified. Please run MinifyJs for each file.")
}
final String srcPath = (source.files.toArray() as File[])[0].canonicalPath
final String srcPath = source.singleFile.canonicalPath
ant.gzip(src: srcPath, destfile: "${srcPath}.gz")
ant.move(file: "${srcPath}.gz", tofile: dest.canonicalPath)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ class JsDocTask extends SourceTask {
args.addAll(['-d', destinationDir.absolutePath])
args.addAll(project.jsdoc.options.collect { it })

rhino.execute(args, workingDir)
rhino.execute(args, [workingDir: workingDir])
}
}
10 changes: 2 additions & 8 deletions src/main/groovy/com/eriwen/gradle/js/tasks/MinifyJsTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,19 @@ package com.eriwen.gradle.js.tasks


import com.eriwen.gradle.js.JsMinifier
import org.gradle.api.GradleException
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.SourceTask
import org.gradle.api.tasks.TaskAction

class MinifyJsTask extends SourceTask {
private static final JsMinifier MINIFIER = new JsMinifier()

@OutputFile
File dest
@OutputFile File dest

@TaskAction
def run() {
if (source.files.size() != 1) {
throw new GradleException("Only 1 file can be minified. Please run MinifyJs for each file.")
}

Set<File> externsFiles = project.closure.externs ? project.closure.externs.files : [] as Set<File>
MINIFIER.minifyJsFile((source.files.toArray() as File[])[0], externsFiles, dest,
MINIFIER.minifyJsFile(source.singleFile, externsFiles, dest,
project.closure.compilerOptions, project.closure.warningLevel, project.closure.compilationLevel)
}
}

0 comments on commit aec2464

Please sign in to comment.