Last active
April 18, 2020 21:10
-
-
Save brimworks/232b36529c85d3555e0f6c98c6235a60 to your computer and use it in GitHub Desktop.
Generate java files in a gradle build using ragel.
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
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