diff --git a/brut.apktool.smali/build.gradle b/brut.apktool.smali/build.gradle index 42ca8595..4b96d6b2 100644 --- a/brut.apktool.smali/build.gradle +++ b/brut.apktool.smali/build.gradle @@ -82,6 +82,7 @@ subprojects { stringtemplate: 'org.antlr:stringtemplate:3.2.1', commons_cli: 'commons-cli:commons-cli:1.2', jflex: 'de.jflex:jflex:1.4.3', + jflex_plugin: 'co.tomlee.gradle.plugins:gradle-jflex-plugin:0.0.1', proguard_gradle: 'net.sf.proguard:proguard-gradle:5.1' ] } diff --git a/brut.apktool.smali/smali/build.gradle b/brut.apktool.smali/smali/build.gradle index 4dcf7f36..bd95fda4 100644 --- a/brut.apktool.smali/smali/build.gradle +++ b/brut.apktool.smali/smali/build.gradle @@ -28,32 +28,36 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - +apply plugin: 'jflex' + configurations { antlr3 - jflex } buildscript { repositories { mavenCentral() } + dependencies { + classpath depends.jflex_plugin classpath depends.proguard_gradle } } +configurations { + // 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.jflexSource = "src/main/jflex" -ext.jflexOutput = file("${buildDir}/generated-sources/jflex") - ext.testAntlrSource = 'src/test/antlr3' ext.testAntlrOutput = file("${buildDir}/generated-test-sources/antlr3") sourceSets.main.java.srcDir antlrOutput -sourceSets.main.java.srcDir jflexOutput sourceSets.test.java.srcDir testAntlrOutput @@ -124,21 +128,7 @@ task generateTestAntlrSource(type: JavaExec) { args grammars.files.join(' ') } -task generateJflexSource(type: JavaExec) { - inputs.dir file(jflexSource) - outputs.dir file(jflexOutput) - - mkdir(jflexOutput) - def grammars = fileTree(jflexSource).include('**/*.flex') - - classpath = configurations.jflex - main = 'JFlex.Main' - args '-q' - args '-d', relativePath("${jflexOutput}/org/jf/smali") - args grammars.files.join(' ') -} - -compileJava.dependsOn generateParserAntlrSource, generateTreeWalkerAntlrSource, generateJflexSource +compileJava.dependsOn generateParserAntlrSource, generateTreeWalkerAntlrSource compileTestJava.dependsOn generateTestAntlrSource processResources.inputs.property('version', version) @@ -153,6 +143,11 @@ task fatJar (type: Jar) { attributes("Main-Class": "org.jf.smali.main") } } +tasks.getByPath('build').dependsOn(fatJar) + +generateJFlexSource { + outputDirectory = new File(outputDirectory, "org/jf/smali") +} task proguard(type: proguard.gradle.ProGuardTask, dependsOn: fatJar) { def outFile = fatJar.destinationDir.getPath() + '/' + fatJar.baseName + '-' + diff --git a/brut.apktool.smali/smali/src/main/jflex/smaliLexer.flex b/brut.apktool.smali/smali/src/main/jflex/smaliLexer.jflex similarity index 100% rename from brut.apktool.smali/smali/src/main/jflex/smaliLexer.flex rename to brut.apktool.smali/smali/src/main/jflex/smaliLexer.jflex diff --git a/brut.apktool.smali/smali/src/test/java/LexerTest.java b/brut.apktool.smali/smali/src/test/java/LexerTest.java index c1b70435..d156015a 100644 --- a/brut.apktool.smali/smali/src/test/java/LexerTest.java +++ b/brut.apktool.smali/smali/src/test/java/LexerTest.java @@ -40,6 +40,7 @@ import org.junit.Test; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.util.HashMap; import java.util.List; @@ -158,7 +159,7 @@ public class LexerTest { if (smaliStream == null) { Assert.fail("Could not load " + smaliFile); } - smaliFlexLexer lexer = new smaliFlexLexer(smaliStream); + smaliFlexLexer lexer = new smaliFlexLexer(new InputStreamReader(smaliStream)); lexer.setSourceFile(new File(test + ".smali")); lexer.setSuppressErrors(true);