-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed GroocssTask to extend AbstractCopyTask
- Loading branch information
1 parent
c6f1512
commit 90ed128
Showing
1 changed file
with
44 additions
and
11 deletions.
There are no files selected for viewing
55 changes: 44 additions & 11 deletions
55
groocss-gradle-plugin/src/main/groovy/org/groocss/GroocssTask.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} |