Skip to content

Commit

Permalink
Merge pull request #47 from benjamin-bader/master
Browse files Browse the repository at this point in the history
Revert #32, remove `@Input` annotation, add diagnostics
  • Loading branch information
benjamin-bader committed Jan 26, 2016
2 parents 28d1210 + bccaed8 commit 0071d17
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
0.4.1 (unreleased)
----------

* Change output-file extensions to '.json' and '.yml' for JSON and YAML outputs.
* Revert pull request #32 and remove `@Input` from `apkOrDex` (issues #40 and #46)

0.4.0 (released 23 January 2016)
----------

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ buildscript {
}
dependencies {
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.4.0-SNAPSHOT'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.4.1-SNAPSHOT'
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GROUP=com.getkeepsafe.dexcount
VERSION_NAME=0.4.0
VERSION_NAME=0.4.1-SNAPSHOT

POM_ARTIFACT_ID=dexcount-gradle-plugin
POM_NAME=Dexcount Gradle Plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,17 @@ class DexMethodCountPlugin implements Plugin<Project> {
path += "/${output.name}"
}

def ext = project.extensions['dexcount']
def ext = project.extensions['dexcount'] as DexMethodCountExtension
def format = ext.format

def task = project.tasks.create("count${slug}DexMethods", DexMethodCountTask)
task.description = "Outputs dex method count for ${variant.name}."
task.group = 'Reporting'
task.apkOrDexFile = output.outputFile
task.apkOrDex = output
task.mappingFile = variant.mappingFile
task.outputFile = project.file(path + '.txt')
task.outputFile = project.file(path + format.extension)
task.summaryFile = project.file(path + '.csv')
task.config = ext as DexMethodCountExtension
task.config = ext
variant.assemble.doLast { task.countMethods() }
}
}
Expand Down
27 changes: 23 additions & 4 deletions src/main/groovy/com/getkeepsafe/dexcount/DexMethodCountTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ class DexMethodCountTask extends DefaultTask {

def PackageTree tree;

@Input
def File apkOrDexFile
def BaseVariantOutput apkOrDex

@Nullable
def File mappingFile
Expand All @@ -53,6 +52,11 @@ class DexMethodCountTask extends DefaultTask {

def DexMethodCountExtension config

def long startTime
def long ioTime
def long treegenTime
def long outputTime

@TaskAction
void countMethods() {
generatePackageTree()
Expand All @@ -66,7 +70,7 @@ class DexMethodCountTask extends DefaultTask {
* @return
*/
def printSummary() {
def filename = apkOrDexFile.name
def filename = apkOrDex.outputFile.name
withStyledOutput(StyledTextOutput.Style.Info) { out ->
out.println("Total methods in ${filename}: ${tree.methodCount}")
out.println("Total fields in ${filename}: ${tree.fieldCount}")
Expand Down Expand Up @@ -103,6 +107,8 @@ class DexMethodCountTask extends DefaultTask {
appendableStream.close()
}
}

outputTime = System.currentTimeMillis()
}

/**
Expand All @@ -116,6 +122,13 @@ class DexMethodCountTask extends DefaultTask {

withStyledOutput(StyledTextOutput.Style.Info, level) { out ->
print(tree, out)

out.format("\n\nTask runtimes:\n")
out.format("--------------\n")
out.format("parsing: ${ioTime - startTime} ms\n")
out.format("counting: ${treegenTime - ioTime} ms\n")
out.format("printing: ${outputTime - treegenTime} ms\n")
out.format("total: ${outputTime - startTime} ms\n")
}
}

Expand All @@ -138,11 +151,15 @@ class DexMethodCountTask extends DefaultTask {
* counts of the current dex/apk file.
*/
private def generatePackageTree() {
startTime = System.currentTimeMillis()

// Create a de-obfuscator based on the current Proguard mapping file.
// If none is given, we'll get a default mapping.
def deobs = getDeobfuscator()

def dataList = DexFile.extractDexData(apkOrDexFile)
def dataList = DexFile.extractDexData(apkOrDex.outputFile)

ioTime = System.currentTimeMillis()
try {
tree = new PackageTree()

Expand All @@ -156,6 +173,8 @@ class DexMethodCountTask extends DefaultTask {
} finally {
dataList*.dispose()
}

treegenTime = System.currentTimeMillis()
}

static refListToClassNames(List<List<HasDeclaringClass>> refs, Deobfuscator deobfuscator) {
Expand Down
14 changes: 10 additions & 4 deletions src/main/groovy/com/getkeepsafe/dexcount/OutputFormat.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,26 @@ public enum OutputFormat {
/**
* Specifies that method counts will be printed in a flat list of packages.
*/
LIST,
LIST('.txt'),

/**
* Specifies that the output will be pretty-printed as an tree.
*/
TREE,
TREE('.txt'),

/**
* Specifies that the output will be a pretty-printed JSON object.
*/
JSON,
JSON('.json'),

/**
* Specifies that output will be a YAML document.
*/
YAML,
YAML('.yml');

public String extension

OutputFormat(String extension) {
this.extension = extension
}
}

0 comments on commit 0071d17

Please sign in to comment.