Skip to content

Commit

Permalink
Removing deprecated API and js task
Browse files Browse the repository at this point in the history
  • Loading branch information
eriwen committed Jun 15, 2012
1 parent 0161eaa commit 9a98ef6
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 242 deletions.
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.eriwen:gradle-js-plugin:0.4'
classpath 'com.eriwen:gradle-js-plugin:1.0'
}
}
// Invoke the plugin
Expand All @@ -38,20 +38,19 @@ task gzipjs(type: com.eriwen.gradle.js.tasks.GzipJsTask, dependsOn: 'minifyjs')
**Need more than 1 set of files generated? We'll have to declare our tasks a bit differently:**

```groovy
task jsDev(type: com.eriwen.gradle.js.tasks.JsTask) {
task jsDev(type: com.eriwen.gradle.js.tasks.CombineJsTask) {
source = ["${projectDir}/js/file1.js", "${projectDir}/js/file2.js"]
dest = file("${buildDir}/all-debug.js")
compilationLevel = 'WHITESPACE_ONLY'
}
task jsProd(type: com.eriwen.gradle.js.tasks.JsTask) {
task jsProd(type: com.eriwen.gradle.js.tasks.CombineJsTask) {
source = ["${projectDir}/js/file1.js", "${projectDir}/js/file2.js"]
dest = file("${buildDir}/all.js")
}
```

**[JSHint](http://jshint.com) support**

```groovy
task jshintjs(type: com.eriwen.gradle.js.tasks.JsHintTask) {
source = ['js/main.js']
Expand Down Expand Up @@ -79,7 +78,7 @@ task props(type: com.eriwen.gradle.js.tasks.Props2JsTask) {

# Available Tasks and Options #
### combineJs ###
- source = [FileCollection](http://gradle.org/current/docs/javadoc/org/gradle/api/file/FileCollection.html) of files to merge
- source = Collection of file paths of files to merge
- dest = File for combined output

### minifyJs (Uses the [Google Closure Compiler](http://code.google.com/closure/compiler/)) ###
Expand All @@ -93,13 +92,6 @@ task props(type: com.eriwen.gradle.js.tasks.Props2JsTask) {
- source = File to compress
- dest = File for compressed output

### js (DEPRECATED, will be removed in v0.5) ###
- inputs.files Files to combine, minify and gzip
- optputs.files File for tiny output :)
- *(Optional)* compilationLevel = 'WHITESPACE_ONLY', 'SIMPLE_OPTIMIZATIONS' (default), or 'ADVANCED_OPTIMIZATIONS' (are you *hardcore*?)
- *(Optional)* warningLevel = 'QUIET', 'DEFAULT' (default), or 'VERBOSE'
- *(Optional)* compilerOptions = [CompilerOptions](http://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/javascript/jscomp/CompilerOptions.java?r=1187) object

### jshint ###
- source = Files to assess with JSHint

Expand Down
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ apply plugin: 'idea'

defaultTasks 'clean', 'build'

version = '0.4.1'
version = '0.4.3'
group = 'com.eriwen'
archivesBaseName = 'gradle-js-plugin'
isSnapshot = version.endsWith("-SNAPSHOT")
ext.archivesBaseName = 'gradle-js-plugin'
ext.isSnapshot = version.endsWith("-SNAPSHOT")

repositories {
mavenCentral()
Expand All @@ -27,9 +27,9 @@ dependencies {
}

idea.module {
gradleCacheVariable = 'GRADLE_CACHE'
ext.gradleCacheVariable = 'GRADLE_CACHE'
downloadJavadoc = true
downloadSource = true
ext.downloadSource = true
outputDir = file("intellij/out")
testOutputDir = file("intellij/testOut")
}
Expand Down Expand Up @@ -58,7 +58,7 @@ task groovydocJar(type: Jar) {
}

task wrapper(type: Wrapper) {
gradleVersion = '1.0-milestone-9'
gradleVersion = '1.0'
}

artifacts {
Expand All @@ -79,7 +79,7 @@ gradle.taskGraph.whenReady { taskGraph ->
install.repositories.mavenInstaller {
pom.project(pomConfiguration)
if (signing.signatory) {
beforeDeployment { signPom(it) }
beforeDeployment { signing.signPom(it) }
}
}

Expand Down
22 changes: 11 additions & 11 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.4.1'
classpath 'com.eriwen:gradle-js-plugin:0.4.3'
}
}

Expand All @@ -13,18 +13,18 @@ repositories {
mavenCentral()
}

//javascript {
// source {
// custom {
// js {
// srcDir "src/test/resources"
// }
// }
// }
//}

apply plugin: 'js'

javascript {
source {
custom {
js {
srcDir "src/test/resources"
}
}
}
}

// Combine JS files
combineJs {
file2 = fileTree(dir: "${projectDir}/src/test/resources", includes: ['file2.js'])
Expand Down
6 changes: 0 additions & 6 deletions src/main/groovy/com/eriwen/gradle/js/JsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ class JsPlugin implements Plugin<Project> {
options = project.convention.plugins.js.options
}

project.task('js', type: JsTask) {
compilerOptions = project.convention.plugins.js.compilerOptions
compilationLevel = project.convention.plugins.js.compilationLevel
warningLevel = project.convention.plugins.js.warningLevel
}

project.task('props2js', type: Props2JsTask) {
type = project.convention.plugins.js.type
functionName = project.convention.plugins.js.functionName
Expand Down
33 changes: 7 additions & 26 deletions src/main/groovy/com/eriwen/gradle/js/tasks/CombineJsTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,20 @@
*/
package com.eriwen.gradle.js.tasks

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

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

@TaskAction
def run() {
if (!getInputs().files.files.empty) {
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 (!getOutputs().files.files.empty) {
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 GradleException('Output must be exactly 1 File object. Example: dest = "myFile"')
}
}

ant.concat(destfile: dest.canonicalPath, fixlastline: 'yes') {
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)
source.files.each {
logger.info("Adding to fileset: ${it}")
fileset(file: it)
}
}
}
Expand Down
30 changes: 10 additions & 20 deletions src/main/groovy/com/eriwen/gradle/js/tasks/GzipJsTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,22 @@
*/
package com.eriwen.gradle.js.tasks

import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
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 DefaultTask {
def source
class GzipJsTask extends SourceTask {
@OutputFile
File dest

@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')
source = getInputs().files.files.toArray()[0] as File
}

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

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)
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
ant.gzip(src: srcPath, destfile: "${srcPath}.gz")
ant.move(file: "${srcPath}.gz", tofile: dest.canonicalPath)
}
}
24 changes: 7 additions & 17 deletions src/main/groovy/com/eriwen/gradle/js/tasks/JsDocTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
package com.eriwen.gradle.js.tasks

import org.gradle.api.tasks.TaskAction
import org.gradle.api.DefaultTask
import com.eriwen.gradle.js.ResourceUtil

import com.eriwen.gradle.js.RhinoExec
import org.gradle.api.tasks.SourceTask
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction

class JsDocTask extends DefaultTask {
class JsDocTask extends SourceTask {
private static final String JSDOC_PATH = 'jsdoc.zip'
private static final String TMP_DIR = "tmp${File.separator}js"
private static final ResourceUtil RESOURCE_UTIL = new ResourceUtil()
Expand All @@ -30,22 +30,12 @@ class JsDocTask extends DefaultTask {
Iterable<String> modulePaths = ['node_modules', 'rhino_modules', '.']
Iterable<String> options = []
Boolean debug = false
def source

@OutputDirectory
File destinationDir

@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'
source = getInputs().files.files.collect { it.canonicalPath }
}

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

final File zipFile = RESOURCE_UTIL.extractFileToDirectory(new File(project.buildDir, TMP_DIR), JSDOC_PATH)
final File jsdocDir = RESOURCE_UTIL.extractZipFile(zipFile)
final String workingDir = "${jsdocDir.absolutePath}${File.separator}jsdoc"
Expand All @@ -58,7 +48,7 @@ class JsDocTask extends DefaultTask {
args.addAll(['-modules', it])
}
args.add("${workingDir}${File.separator}jsdoc.js")
args.addAll(source)
args.addAll(source.files.collect { it.canonicalPath })
args.addAll(['-d', destinationDir.absolutePath])
args.addAll(options.collect { it })

Expand Down
14 changes: 3 additions & 11 deletions src/main/groovy/com/eriwen/gradle/js/tasks/JsHintTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,22 @@
package com.eriwen.gradle.js.tasks

import org.gradle.api.tasks.TaskAction
import org.gradle.api.DefaultTask
import com.eriwen.gradle.js.ResourceUtil
import com.eriwen.gradle.js.RhinoExec
import org.gradle.api.tasks.SourceTask

class JsHintTask extends DefaultTask {
class JsHintTask extends SourceTask {
private static final String JSHINT_PATH = 'jshint-rhino.js'
private static final String TMP_DIR = "tmp${File.separator}js"
private static final ResourceUtil RESOURCE_UTIL = new ResourceUtil()
private final RhinoExec rhino = new RhinoExec(project)

def source

@TaskAction
def run() {
if (!source) {
logger.warn('The syntax "inputs.files ..." is deprecated! Please use `source = "path1"`')
logger.warn('This will be removed in the next version of the JS plugin')
source = getInputs().files.files.collect { it.canonicalPath }
}

final File jshintJsFile = RESOURCE_UTIL.extractFileToDirectory(
new File(project.buildDir, TMP_DIR), JSHINT_PATH)
final List<String> args = [jshintJsFile.canonicalPath]
args.addAll(source)
args.addAll(source.files.collect { it.canonicalPath })
rhino.execute(args)
}
}
Loading

0 comments on commit 9a98ef6

Please sign in to comment.