From ccc2c8c4df5a70c484e308831b57a7edc63dc05a Mon Sep 17 00:00:00 2001 From: Shiang Date: Mon, 12 Jul 2021 14:23:42 +0800 Subject: [PATCH 1/2] fix quark execution problem --- src/tools/quark-engine.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/tools/quark-engine.ts b/src/tools/quark-engine.ts index ecda882..ed5864a 100644 --- a/src/tools/quark-engine.ts +++ b/src/tools/quark-engine.ts @@ -1,3 +1,4 @@ +import * as os from "os"; import * as path from "path"; import * as fs from "fs"; import * as child_process from "child_process"; @@ -285,13 +286,13 @@ export namespace Quark { projectDir: string ): Promise { const jsonReportPath = path.join(projectDir, `quarkReport.json`); - + const cmd = `cd ${path.join(os.homedir(), ".quark-engine")} ; quark`; await executeProcess({ name: "Quark analysis", report: `Analyzing ${apkFilePath}`, - command: "quark", + command: cmd, args: ["-a", apkFilePath, "-o", jsonReportPath], - shouldExist: jsonReportPath, + shell: true, }); } From 26797cef0ca60258dd27cec4302cbf34969dc84d Mon Sep 17 00:00:00 2001 From: Shiang Date: Tue, 13 Jul 2021 13:49:24 +0800 Subject: [PATCH 2/2] add tree map graph --- src/tools/quark-engine.ts | 39 +++++++++++++++++++++++++++++++++--- src/utils/quark-html.ts | 42 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/src/tools/quark-engine.ts b/src/tools/quark-engine.ts index ed5864a..8c3f416 100644 --- a/src/tools/quark-engine.ts +++ b/src/tools/quark-engine.ts @@ -262,7 +262,9 @@ export namespace Quark { * @return if quark installed or not */ export function checkQuarkInstalled(): boolean { - const cmd = "quark"; + const cmd = `cd ${path.join(os.homedir(), ".quark-engine")} ${ + process.platform.startsWith("win") ? "&&" : ";" + } quark`; outputChannel.appendLine(`exec: ${cmd}`); @@ -286,16 +288,45 @@ export namespace Quark { projectDir: string ): Promise { const jsonReportPath = path.join(projectDir, `quarkReport.json`); - const cmd = `cd ${path.join(os.homedir(), ".quark-engine")} ; quark`; + const projectQuarkDir = path.join(projectDir, `quark`); + + if (!fs.existsSync(projectQuarkDir)) { + fs.mkdirSync(projectQuarkDir); + } + + const cmd = `cd ${projectQuarkDir} ${ + process.platform.startsWith("win") ? "&&" : ";" + } quark`; await executeProcess({ name: "Quark analysis", report: `Analyzing ${apkFilePath}`, command: cmd, - args: ["-a", apkFilePath, "-o", jsonReportPath], + args: ["-a", apkFilePath, "-s", "-c", "-o", jsonReportPath], shell: true, }); } + export async function showTreeMap(projectDir: string): Promise { + const treeMapPath = path.join( + projectDir, + `quark`, + `rules_classification.png` + ); + + if (!fs.existsSync(treeMapPath)) { + vscode.window.showErrorMessage( + "APKLab: The tree map file doesn't exist!" + ); + return; + } + const uri = vscode.Uri.file(treeMapPath); + await vscode.commands.executeCommand( + "vscode.open", + uri, + vscode.ViewColumn.One + ); + } + /** * Show Quark APK analysis report in WebView panel. * @param reportPath the path of the `quarkReport.json` file. @@ -332,6 +363,8 @@ export namespace Quark { ] ); break; + case "treemap": + showTreeMap(projectDir); } }); } diff --git a/src/utils/quark-html.ts b/src/utils/quark-html.ts index b6b33c6..d2c1274 100644 --- a/src/utils/quark-html.ts +++ b/src/utils/quark-html.ts @@ -252,6 +252,34 @@ export function quarkSummaryReportHTML(report: { [key: string]: any }): string { .vscode-dark .api a{ color: #ff9696; } + + .treemap-btn { + margin-top: 15px; + background: none; + border: 1px solid rgb(0, 196, 104); + color: rgb(0, 196, 104); + padding: 15px 32px; + text-align: center; + text-decoration: none; + display: inline-block; + font-size: 16px; + border-radius: 10px; + cursor: pointer; + } + + .treemap-btn:hover { + background-color: rgb(0, 97, 52); + border: 1px solid rgb(0, 97, 52); + color: white; + border: none; + } + + .treemap-container { + font-size: 18px; + text-align: center; + align-items: center; + justify-content: center; + } `; const reportHTML = ` @@ -267,6 +295,7 @@ ${style}
+

Quark Analysis

@@ -289,7 +318,13 @@ ${style}
+
+
+

See the reference treemap graph for rule classification

+ +
+