Skip to content

Instantly share code, notes, and snippets.

@brimworks
Last active April 18, 2020 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brimworks/232b36529c85d3555e0f6c98c6235a60 to your computer and use it in GitHub Desktop.
Save brimworks/232b36529c85d3555e0f6c98c6235a60 to your computer and use it in GitHub Desktop.
Generate java files in a gradle build using ragel.
abstract class Ragel extends DefaultTask {
@InputFile
abstract File inputFile
@OutputFile
abstract File outputFile
@TaskAction
void execute(InputChanges inputChanges) {
project.exec {
commandLine "ragel", "-J", "-o", outputFile, inputFile
}
}
};
def ragels = []
fileTree("src/main/ragel").matching {
include "**/*.java.rl"
}.visit { input ->
if ( input.directory ) return
def ragel = task "${input.relativePath.toString().replaceAll("[/\\\\:<>\"?*|]", " ")}" (type:Ragel) {
inputFile input.file.absoluteFile
outputFile file("${buildDir}/generated-src/java/" + input.relativePath - ".rl")
}
ragels << ragel
}
compileJava {
dependsOn ragels
source = ['src/main/java', 'build/generated-src/java']
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment