Skip to content

Commit

Permalink
Changed GroocssTask to extend AbstractCopyTask
Browse files Browse the repository at this point in the history
  • Loading branch information
adamldavis committed Oct 12, 2017
1 parent c6f1512 commit 90ed128
Showing 1 changed file with 44 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,54 @@
package org.groocss

import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import org.gradle.api.internal.file.CopyActionProcessingStreamAction
import org.gradle.api.internal.file.FileResolver
import org.gradle.api.internal.file.copy.CopyAction
import org.gradle.api.internal.file.copy.CopyActionProcessingStream
import org.gradle.api.internal.file.copy.FileCopyDetailsInternal
import org.gradle.api.internal.tasks.SimpleWorkResult
import org.gradle.api.tasks.AbstractCopyTask
import org.gradle.api.tasks.WorkResult

class GroocssTask extends DefaultTask {
/** Converts GrooCSS files using the same features as the Copy task. */
class GroocssTask extends AbstractCopyTask {

Config conf
File inFile
File outFile

/** Converts the given GrooCSS file with current config, and outputs to given file. */
@TaskAction
def convert() {
if (!conf) {
conf = new Config()
@Override
protected CopyAction createCopyAction() {
return new CopyAction() {
@Override
WorkResult execute(CopyActionProcessingStream stream) {
if (!conf) {
conf = new Config()
}
def action = new GroocssFileAction(fileResolver, conf)
stream.process(action)
return new SimpleWorkResult(action.didWork)
}
}
GrooCSS.convert(conf, inFile, outFile)
}

/** Converts the given GrooCSS file with current config, and outputs to given file. */
static class GroocssFileAction implements CopyActionProcessingStreamAction {
FileResolver fileResolver
Config config
boolean didWork

GroocssFileAction(FileResolver fileResolver, Config config) {
this.fileResolver = fileResolver
this.config = config
}

@Override
void processFile(FileCopyDetailsInternal details) {
File source = fileResolver.resolve(details.relativeSourcePath.pathString)
File target = fileResolver.resolve(details.relativePath.pathString)

if (source.isFile() || source.isDirectory()) {
GrooCSS.convert(config, source, target)
didWork = true
}
}
}
}

0 comments on commit 90ed128

Please sign in to comment.