Skip to content

Commit

Permalink
Failing fast when we detect a file that doesn't exist, fixes eriwen#5
Browse files Browse the repository at this point in the history
  • Loading branch information
eriwen committed Mar 10, 2012
1 parent 3c8abf4 commit 9277179
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 23 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 = '0.3.42-SNAPSHOT'
version = '0.3.44-SNAPSHOT'
group = 'com.eriwen'
archivesBaseName = 'gradle-js-plugin'
isSnapshot = version.endsWith("-SNAPSHOT")
Expand Down
6 changes: 3 additions & 3 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:0.3.42-SNAPSHOT'
classpath 'com.eriwen:gradle-js-plugin:0.3.44-SNAPSHOT'
}
}

Expand Down Expand Up @@ -43,13 +43,13 @@ combineJs {

task combine(type: com.eriwen.gradle.js.tasks.CombineJsTask) {
//javascript.source.custom.js.files.toList()
source = ["${projectDir}/src/test/resources/file1.js", "${projectDir}/src/test/resources/file2.js"]
source = ["${projectDir}/src/test/resources/file1.js", "${projectDir}/src/test/resources/file3.js"]
dest = file("${buildDir}/all.js")
}

// Minify with Google Closure Compiler
minifyJs {
inputs.file file("${buildDir}/all.js")
inputs.file file("${buildDir}/all2.js")
outputs.file file("${buildDir}/all-min.js")
warningLevel = 'QUIET'
}
Expand Down
14 changes: 9 additions & 5 deletions src/main/groovy/com/eriwen/gradle/js/tasks/CombineJsTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.eriwen.gradle.js.tasks

import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import org.gradle.api.GradleException

class CombineJsTask extends DefaultTask {
def source
Expand All @@ -31,19 +32,22 @@ class CombineJsTask extends DefaultTask {
}

if (!getOutputs().files.files.empty) {
logger.warn('The syntax "outputs.files ..." is deprecated! Please use `dest = "dest/filename.js"`')
logger.warn 'The syntax "outputs.files ..." is deprecated! Please use `dest = "dest/filename.js"`'
def outputFiles = getOutputs().files.files
if (outputFiles.size() == 1) {
dest = (outputFiles.toArray()[0] as File)
} else if (!dest) {
throw new IllegalArgumentException('Output must be exactly 1 File object. Example: dest = "myFile"')
throw new GradleException('Output must be exactly 1 File object. Example: dest = "myFile"')
}
}

ant.concat(destfile: dest.canonicalPath, fixlastline: 'yes') {
source.each {
logger.info("Adding to fileset: ${it}")
fileset(file: it)
source.each { String path ->
if (!(new File(path).exists())) {
throw new GradleException("Source JS file ${path} does not exist!")
}
logger.info("Adding to fileset: ${path}")
fileset(file: path)
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/main/groovy/com/eriwen/gradle/js/tasks/GzipJsTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ package com.eriwen.gradle.js.tasks

import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import org.gradle.api.GradleException

class GzipJsTask extends DefaultTask {
File source
def source
File dest

@TaskAction
Expand All @@ -35,7 +36,11 @@ class GzipJsTask extends DefaultTask {
dest = getOutputs().files.files.toArray()[0] as File
}

ant.gzip(src: source.canonicalPath, destfile: "${source.canonicalPath}.gz")
ant.move(file: "${source.canonicalPath}.gz", tofile: dest.canonicalPath)
if (!source.exists()) {
throw new GradleException("JS file ${source.canonicalPath} doesn't exist!")
} else {
ant.gzip(src: source.canonicalPath, destfile: "${source.canonicalPath}.gz")
ant.move(file: "${source.canonicalPath}.gz", tofile: dest.canonicalPath)
}
}
}
6 changes: 3 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 @@ -36,13 +36,13 @@ class JsDocTask extends DefaultTask {
@TaskAction
def run() {
if (!source) {
logger.warn('The syntax "inputs.files ..." is deprecated! Please use `source = ["path1", "path2"]`')
logger.warn('This will be removed in the next version of the JS plugin')
logger.warn 'The syntax "inputs.files ..." is deprecated! Please use `source = ["path1", "path2"]`'
logger.warn 'This will be removed in the next version of the JS plugin'
source = getInputs().files.files.collect { it.canonicalPath }
}

if (!destinationDir) {
logger.warn('The syntax "outputs.file file(..)" is deprecated! Please use `destinationDir = file(buildDir)`')
logger.warn 'The syntax "outputs.file file(..)" is deprecated! Please use `destinationDir = file(buildDir)`'
destinationDir = getOutputs().files.files.toArray()[0] as File
}

Expand Down
15 changes: 10 additions & 5 deletions src/main/groovy/com/eriwen/gradle/js/tasks/MinifyJsTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import org.gradle.api.tasks.TaskAction

import com.google.javascript.jscomp.CompilerOptions
import com.eriwen.gradle.js.JsMinifier
import org.gradle.api.GradleException

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

// FIXME: Wire defaults in properly through convention (#14)
// FIXME: Wire defaults in properly through convention (issue #14)
CompilerOptions compilerOptions = new CompilerOptions()
String compilationLevel = 'SIMPLE_OPTIMIZATIONS'
String warningLevel = 'DEFAULT'
Expand All @@ -34,16 +35,20 @@ class MinifyJsTask extends DefaultTask {
@TaskAction
def run() {
if (!source) {
logger.warn('The syntax "inputs.files ..." is deprecated! Please use `source = file("path1")`')
logger.warn('This will be removed in the next version of the JS plugin')
logger.warn 'The syntax "inputs.files ..." is deprecated! Please use `source = file("path1")`'
logger.warn 'This will be removed in the next version of the JS plugin'
source = getInputs().files.files.toArray()[0] as File
}

if (!source.exists()) {
throw new GradleException("JS file ${source.canonicalPath} doesn't exist!")
}

if (!dest) {
logger.warn('The syntax "outputs.files ..." is deprecated! Please use `dest = file("dest/file.js")`')
logger.warn 'The syntax "outputs.files ..." is deprecated! Please use `dest = file("dest/file.js")`'
dest = getOutputs().files.files.toArray()[0] as File
}

MINIFIER.minifyJsFile(source, dest, compilerOptions, warningLevel, compilationLevel)
}
}
}
11 changes: 8 additions & 3 deletions src/main/groovy/com/eriwen/gradle/js/tasks/Props2JsTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.eriwen.gradle.js.tasks
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import com.eriwen.gradle.js.ResourceUtil
import org.gradle.api.GradleException

class Props2JsTask extends DefaultTask {
private static final String PROPS2JS_JAR = 'props2js-0.1.0.jar'
Expand All @@ -34,16 +35,20 @@ class Props2JsTask extends DefaultTask {
@TaskAction
def run() {
if (!propertiesFile) {
logger.warn('The syntax "inputs.file file(..)" is deprecated! Please use `propertiesFile = file("path/file.props")`')
logger.warn('This will be removed in the next version of the JS plugin')
logger.warn 'The syntax "inputs.file file(..)" is deprecated! Please use `propertiesFile = file("path/file.props")`'
logger.warn 'This will be removed in the next version of the JS plugin'
propertiesFile = getInputs().files.files.toArray()[0] as File
}

if (!dest) {
logger.warn('The syntax "outputs.file file(..)" is deprecated! Please use `dest = file("dest/file.js")`')
logger.warn 'The syntax "outputs.file file(..)" is deprecated! Please use `dest = file("dest/file.js")`'
dest = getOutputs().files.files.toArray()[0] as File
}

if (!propertiesFile.exists()) {
throw new GradleException("${propertiesFile} does not exist!")
}

// Prevent arguments that don't make sense
if (!AVAILABLE_TYPES.contains(type)) {
throw new IllegalArgumentException("Invalid type specified. Must be one of: ${AVAILABLE_TYPES.join(',')}")
Expand Down

0 comments on commit 9277179

Please sign in to comment.