Skip to content

Commit

Permalink
New task API for props2js fixing issue eriwen#13
Browse files Browse the repository at this point in the history
  • Loading branch information
eriwen committed Mar 10, 2012
1 parent 4020934 commit 3c8abf4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 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.41-SNAPSHOT'
version = '0.3.42-SNAPSHOT'
group = 'com.eriwen'
archivesBaseName = 'gradle-js-plugin'
isSnapshot = version.endsWith("-SNAPSHOT")
Expand Down
4 changes: 2 additions & 2 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.41-SNAPSHOT'
classpath 'com.eriwen:gradle-js-plugin:0.3.42-SNAPSHOT'
}
}

Expand Down Expand Up @@ -97,7 +97,7 @@ props2js {
}

task props(type: com.eriwen.gradle.js.tasks.Props2JsTask) {
source = file("${projectDir}/src/test/resources/test.properties")
propertiesFile = file("${projectDir}/src/test/resources/test.properties")
dest = file("${buildDir}/props.jsonp")
type = 'jsonp'
functionName = 'fn'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class JsDocTask extends DefaultTask {
}

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

Expand Down
37 changes: 22 additions & 15 deletions src/main/groovy/com/eriwen/gradle/js/tasks/Props2JsTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,24 @@ class Props2JsTask extends DefaultTask {
private static final ResourceUtil RESOURCE_UTIL = new ResourceUtil()
private static final Set<String> AVAILABLE_TYPES = ['js', 'json', 'jsonp']

File propertiesFile
File dest
// FIXME: populate defaults using plugin convention (issue #14)
String functionName = ''
String type = 'json'

@TaskAction
def run() {
def inputFiles = getInputs().files.files.toArray()
def outputFiles = getOutputs().files.files.toArray()
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')
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")`')
dest = getOutputs().files.files.toArray()[0] as File
}

// Prevent arguments that don't make sense
if (!AVAILABLE_TYPES.contains(type)) {
Expand All @@ -42,19 +53,15 @@ class Props2JsTask extends DefaultTask {
throw new IllegalArgumentException("Must specify a 'functionName' when type is 'jsonp' or 'js'")
}

if (outputFiles.size() == 1 && inputFiles.size() == 1) {
final File props2JsJar = RESOURCE_UTIL.extractFileToDirectory(new File(project.buildDir, TMP_DIR), PROPS2JS_JAR)
final List<String> props2JsArgs = [props2JsJar.canonicalPath, (inputFiles[0] as File).canonicalPath, '-t', type]
if (functionName) {
props2JsArgs.addAll(['--name', functionName])
}
props2JsArgs.addAll(['-o', (outputFiles[0] as File).canonicalPath])
project.javaexec {
main = '-jar'
args = props2JsArgs
}
} else {
throw new IllegalArgumentException("Could not map input files to output files. Found ${inputFiles.size()} inputs and ${outputFiles.size()} outputs")
final File props2JsJar = RESOURCE_UTIL.extractFileToDirectory(new File(project.buildDir, TMP_DIR), PROPS2JS_JAR)
final List<String> props2JsArgs = [props2JsJar.canonicalPath, propertiesFile.canonicalPath, '-t', type]
if (functionName) {
props2JsArgs.addAll(['--name', functionName])
}
props2JsArgs.addAll(['-o', dest.canonicalPath])
project.javaexec {
main = '-jar'
args = props2JsArgs
}
}
}

0 comments on commit 3c8abf4

Please sign in to comment.