Skip to content

Commit

Permalink
Change logs to println
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan3d committed Sep 4, 2023
1 parent b57aa15 commit 0eb1805
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Publish.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.gradle.plugins.signing.SigningExtension
import java.net.URI

const val RULER_PLUGIN_GROUP = "com.spotify.ruler"
const val RULER_PLUGIN_VERSION = "2.0.0-alpha-12" // Also adapt this version in the README
const val RULER_PLUGIN_VERSION = "2.0.0-alpha-13" // Also adapt this version in the README
const val EXT_POM_NAME = "POM_NAME"
const val EXT_POM_DESCRIPTION = "POM_DESCRIPTION"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@ import com.android.tools.apk.analyzer.ApkSizeCalculator
import com.android.tools.apk.analyzer.dex.DexFiles
import com.spotify.ruler.common.bloaty.Bloaty
import java.io.File
import java.util.logging.Level
import java.util.logging.Logger
import java.util.zip.ZipFile

/** Responsible for parsing and extracting entries from APK files. */
class ApkParser(private val unstrippedNativeLibraryPaths: List<File> = emptyList(),
private val logger: Logger = Logger.getLogger("Ruler")
class ApkParser(
private val unstrippedNativeLibraryPaths: List<File> = emptyList()
) {

/** Parses and returns the list of entries contained in the given [apkFile]. */
fun parse(apkFile: File) : List<ApkEntry> {
logger.log(Level.INFO, unstrippedNativeLibraryPaths.map { it.path }.joinToString { ", " })
println(unstrippedNativeLibraryPaths.map { it.path }.joinToString { ", " })
val sizeCalculator = ApkSizeCalculator.getDefault()
val downloadSizePerFile = sizeCalculator.getDownloadSizePerFile(apkFile.toPath())
val installSizePerFile = sizeCalculator.getRawSizePerFile(apkFile.toPath())
Expand Down Expand Up @@ -98,7 +96,7 @@ class ApkParser(private val unstrippedNativeLibraryPaths: List<File> = emptyList
val result = unstrippedNativeLibraryPaths.find {
it.name.contains(entryFileName)
}
logger.info("Looking for unstripped file for $entryName. Matched: $result")
println("Looking for unstripped file for $entryName. Matched: $result")
return result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import com.spotify.ruler.common.apk.ApkEntry
import java.io.BufferedReader
import java.io.File
import java.io.InputStreamReader
import java.util.logging.Level.INFO
import java.util.logging.Level.WARNING
import java.util.logging.Logger

private const val COLUMN_SIZE = 3
/**
Expand All @@ -22,15 +19,14 @@ private const val COLUMN_SIZE = 3
object Bloaty {

private val bloatyPath: String? by lazy { findBloatyPath() }
private val logger = Logger.getLogger("Ruler")

private fun findBloatyPath(): String? {
val path = executeCommandAndGetOutput("which bloaty").singleOrNull()
return if (path.isNullOrEmpty()) {
logger.log(WARNING, "Could not find Bloaty. Install Bloaty for more information about native libraries.")
println("Could not find Bloaty. Install Bloaty for more information about native libraries.")
null
} else {
logger.log(INFO, "Bloaty detected at: $path")
println( "Bloaty detected at: $path")
path
}
}
Expand Down Expand Up @@ -61,9 +57,9 @@ object Bloaty {
* @return A list of [ApkEntry.Default] representing the compiled units in the native library.
*/
fun parseNativeLibraryEntry(bytes: ByteArray, debugFile: File?): List<ApkEntry.Default> {
logger.log(INFO, "Parsing unstripped library at: $debugFile")
println("Parsing unstripped library at: $debugFile")
if (bloatyPath == null || debugFile == null) {
logger.log(INFO, "Unable to parse library")
println("Unable to parse library")
return emptyList()
}

Expand All @@ -77,8 +73,8 @@ object Bloaty {
val command =
"$bloatyPath --debug-file=${debugFile.absolutePath} ${tmpFile.absolutePath} -d compileunits -n 0 --csv"

logger.log(INFO, "Running bloaty command:")
logger.log(INFO, command)
println("Running bloaty command:")
println(command)

return parseBloatyOutputToApkEntry(command)
}
Expand Down Expand Up @@ -106,7 +102,7 @@ object Bloaty {
rows.add(entry)
}
}
logger.log(INFO, "Parsed ${rows.count()} APK entries")
println("Parsed ${rows.count()} APK entries")
return rows
}

Expand Down

0 comments on commit 0eb1805

Please sign in to comment.