From 90ed128c09928a68e7cacb9c5b511e9d420ef048 Mon Sep 17 00:00:00 2001 From: Adam Davis Date: Thu, 12 Oct 2017 09:04:46 -0400 Subject: [PATCH] Changed GroocssTask to extend AbstractCopyTask --- .../groovy/org/groocss/GroocssTask.groovy | 55 +++++++++++++++---- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/groocss-gradle-plugin/src/main/groovy/org/groocss/GroocssTask.groovy b/groocss-gradle-plugin/src/main/groovy/org/groocss/GroocssTask.groovy index d8156dc..2dd487a 100644 --- a/groocss-gradle-plugin/src/main/groovy/org/groocss/GroocssTask.groovy +++ b/groocss-gradle-plugin/src/main/groovy/org/groocss/GroocssTask.groovy @@ -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 + } + } + } }