From 57bd527d431e71ecf507e18d268d04e3f68c8085 Mon Sep 17 00:00:00 2001 From: Ben Gruver Date: Sun, 1 Mar 2015 20:31:10 -0800 Subject: [PATCH] Use the antlr plugin for gradle --- smali/build.gradle | 71 ++++--------------- .../src/main/{antlr3 => antlr}/smaliParser.g | 0 .../main/{antlr3 => antlr}/smaliTreeWalker.g | 0 .../org/jf/smali/expectedTokensTestGrammar.g | 0 4 files changed, 14 insertions(+), 57 deletions(-) rename smali/src/main/{antlr3 => antlr}/smaliParser.g (100%) rename smali/src/main/{antlr3 => antlr}/smaliTreeWalker.g (100%) rename smali/src/test/{antlr3 => antlr}/org/jf/smali/expectedTokensTestGrammar.g (100%) diff --git a/smali/build.gradle b/smali/build.gradle index 92fb1db4..bcacaf73 100644 --- a/smali/build.gradle +++ b/smali/build.gradle @@ -29,12 +29,9 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +apply plugin: 'antlr' apply plugin: 'jflex' -configurations { - antlr3 -} - buildscript { repositories { mavenCentral() @@ -46,21 +43,15 @@ buildscript { } 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 // that gets added by the jflex plugin 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 { module { excludeDirs -= buildDir @@ -85,52 +76,10 @@ dependencies { testCompile depends.junit - antlr3 depends.antlr + antlr depends.antlr 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.expand('version': version) @@ -156,6 +105,14 @@ task fatJar(type: Jar, dependsOn: jar) { } tasks.getByPath('build').dependsOn(fatJar) +generateTestGrammarSource { + outputDirectory = new File(outputDirectory, "org/jf/smali") +} + +generateGrammarSource { + outputDirectory = new File(outputDirectory, "org/jf/smali") +} + generateJFlexSource { outputDirectory = new File(outputDirectory, "org/jf/smali") } diff --git a/smali/src/main/antlr3/smaliParser.g b/smali/src/main/antlr/smaliParser.g similarity index 100% rename from smali/src/main/antlr3/smaliParser.g rename to smali/src/main/antlr/smaliParser.g diff --git a/smali/src/main/antlr3/smaliTreeWalker.g b/smali/src/main/antlr/smaliTreeWalker.g similarity index 100% rename from smali/src/main/antlr3/smaliTreeWalker.g rename to smali/src/main/antlr/smaliTreeWalker.g diff --git a/smali/src/test/antlr3/org/jf/smali/expectedTokensTestGrammar.g b/smali/src/test/antlr/org/jf/smali/expectedTokensTestGrammar.g similarity index 100% rename from smali/src/test/antlr3/org/jf/smali/expectedTokensTestGrammar.g rename to smali/src/test/antlr/org/jf/smali/expectedTokensTestGrammar.g