Last active
May 5, 2016 16:02
-
-
Save martinda/cbc6ff033e9e5f0410fb15d6ded3da5d to your computer and use it in GitHub Desktop.
Workaround for List<String> args not serializable
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
// To reproduce the bug: | |
// mkdir -p src/main/apple | |
// echo "red" >src/main/apple/pomme.txt | |
// gradle juicerJuicer | |
@Managed interface JuiceComponent extends GeneralComponentSpec { } | |
@Managed interface FruitLanguage extends LanguageSourceSet {} | |
@Managed | |
interface JuiceBinarySpec extends BinarySpec { | |
File getOutputDir() | |
void setOutputDir(File outputDir) | |
List<String> getArgs() | |
void setArgs(List<String> args) | |
} | |
class JuicerTask extends SourceTask { | |
@Input | |
List<String> args | |
// For a workaround: | |
// - remove @Input from args above | |
// - uncomment out the next 4 lines | |
//@Input | |
//List<String> getArgsWorkaround() { | |
// args.collect { it.toString() } | |
//} | |
@OutputDirectory | |
File outputDir | |
@TaskAction | |
void makeJuice() { | |
println('Juicy args: '+args) | |
} | |
} | |
class JuicerRules extends RuleSource { | |
@ComponentType void registerComponent(TypeBuilder<JuiceComponent> builder) { } | |
@ComponentType void registerFruitLanguage(TypeBuilder<FruitLanguage> builder) { } | |
@ComponentType void registerJuiceBinarySpec(TypeBuilder<JuiceBinarySpec> builder) { } | |
@ComponentBinaries | |
void generateJuiceBinaries(ModelMap<JuiceBinarySpec> binaries, GeneralComponentSpec component, @Path("buildDir") File buildDir) { | |
binaries.create("juicer") { binary -> | |
outputDir = new File(buildDir, "${component.name}/${binary.name}") | |
} | |
} | |
@BinaryTasks | |
void generateTasks(ModelMap<Task> tasks, final JuiceBinarySpec binary) { | |
binary.inputs.withType(FruitLanguage) { fruitLanguage -> | |
def outputDir = new File(binary.outputDir, fruitLanguage.name) | |
tasks.create("${binary.name}Juicer", JuicerTask) { task -> | |
task.args = binary.getArgs() | |
task.outputDir = outputDir | |
task.source = fruitLanguage.source.srcDirs | |
} | |
} | |
} | |
} | |
apply plugin: JuicerRules | |
model { | |
components { | |
juiceComponent(JuiceComponent) { | |
binaries { | |
// Describe the distributions | |
juicer { | |
args = ['a', 'b'] | |
} | |
} | |
sources { | |
// Describe the sources | |
apple(FruitLanguage) { | |
source { | |
srcDirs 'src/main/apple' | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment