Use the antlr plugin for gradle

This commit is contained in:
Ben Gruver 2015-03-01 20:31:10 -08:00
parent 0f6f00a325
commit 57bd527d43
4 changed files with 14 additions and 57 deletions

View File

@ -29,12 +29,9 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
apply plugin: 'antlr'
apply plugin: 'jflex' apply plugin: 'jflex'
configurations {
antlr3
}
buildscript { buildscript {
repositories { repositories {
mavenCentral() mavenCentral()
@ -46,21 +43,15 @@ buildscript {
} }
configurations { configurations {
// Remove the full antlr library that's added by the antlr plugin. We manually
// add the smaller antlr_runtime library instead
compile.exclude group: 'org.antlr', module: 'antlr'
// The jflex lexer doesn't have any runtime dependencies, so remove the dependency // The jflex lexer doesn't have any runtime dependencies, so remove the dependency
// that gets added by the jflex plugin // that gets added by the jflex plugin
compile.exclude group: 'de.jflex', module: 'jflex' compile.exclude group: 'de.jflex', module: 'jflex'
} }
ext.antlrSource = 'src/main/antlr3'
ext.antlrOutput = file("${buildDir}/generated-sources/antlr3")
ext.testAntlrSource = 'src/test/antlr3'
ext.testAntlrOutput = file("${buildDir}/generated-test-sources/antlr3")
sourceSets.main.java.srcDir antlrOutput
sourceSets.test.java.srcDir testAntlrOutput
idea { idea {
module { module {
excludeDirs -= buildDir excludeDirs -= buildDir
@ -85,52 +76,10 @@ dependencies {
testCompile depends.junit testCompile depends.junit
antlr3 depends.antlr antlr depends.antlr
jflex depends.jflex jflex depends.jflex
} }
task generateParserAntlrSource(type: JavaExec) {
inputs.dir file(antlrSource)
outputs.dir file(antlrOutput)
mkdir(antlrOutput)
def grammars = fileTree(antlrSource).include('**/smaliParser.g')
classpath = configurations.antlr3
main = 'org.antlr.Tool'
args '-fo', relativePath("${antlrOutput}/org/jf/smali")
args grammars.files
}
task generateTreeWalkerAntlrSource(type: JavaExec) {
inputs.dir file(antlrSource)
outputs.dir file(antlrOutput)
mkdir(antlrOutput)
def grammars = fileTree(antlrSource).include('**/smaliTreeWalker.g')
classpath = configurations.antlr3
main = 'org.antlr.Tool'
args '-fo', relativePath("${antlrOutput}/org/jf/smali")
args grammars.files
}
task generateTestAntlrSource(type: JavaExec) {
inputs.dir file(testAntlrSource)
outputs.dir file(testAntlrOutput)
mkdir(testAntlrOutput)
def grammars = fileTree(testAntlrSource).include('**/*.g')
classpath = configurations.antlr3
main = 'org.antlr.Tool'
args '-fo', relativePath("${testAntlrOutput}/org/jf/smali")
args grammars.files.join(' ')
}
compileJava.dependsOn generateParserAntlrSource, generateTreeWalkerAntlrSource
compileTestJava.dependsOn generateTestAntlrSource
processResources.inputs.property('version', version) processResources.inputs.property('version', version)
processResources.expand('version': version) processResources.expand('version': version)
@ -156,6 +105,14 @@ task fatJar(type: Jar, dependsOn: jar) {
} }
tasks.getByPath('build').dependsOn(fatJar) tasks.getByPath('build').dependsOn(fatJar)
generateTestGrammarSource {
outputDirectory = new File(outputDirectory, "org/jf/smali")
}
generateGrammarSource {
outputDirectory = new File(outputDirectory, "org/jf/smali")
}
generateJFlexSource { generateJFlexSource {
outputDirectory = new File(outputDirectory, "org/jf/smali") outputDirectory = new File(outputDirectory, "org/jf/smali")
} }