Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quark integration improvement #135

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions src/tools/quark-engine.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -261,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}`);

Expand All @@ -285,16 +288,45 @@ export namespace Quark {
projectDir: string
): Promise<void> {
const jsonReportPath = path.join(projectDir, `quarkReport.json`);
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: "quark",
args: ["-a", apkFilePath, "-o", jsonReportPath],
shouldExist: jsonReportPath,
command: cmd,
args: ["-a", apkFilePath, "-s", "-c", "-o", jsonReportPath],
shell: true,
});
}

export async function showTreeMap(projectDir: string): Promise<void> {
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.
Expand Down Expand Up @@ -331,6 +363,8 @@ export namespace Quark {
]
);
break;
case "treemap":
showTreeMap(projectDir);
}
});
}
Expand Down
42 changes: 42 additions & 0 deletions src/utils/quark-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand All @@ -267,6 +295,7 @@ ${style}
</head>
<body>
<div class="container-table100">
<h1>Quark Analysis</h1>
<div class="wrap-table100">
<div class="table100 ver5 m-b-110">
<div class="table100-head">
Expand All @@ -289,7 +318,13 @@ ${style}
</div>
</div>
</div>
<div class="treemap-container">
<hr>
<p>See the reference treemap graph for rule classification</p>
<button class="treemap-btn" onclick="treemap()">Reference Tree</button>
</div>
</div>

</body>
</html>
<script>
Expand All @@ -308,6 +343,13 @@ ${style}
cid: cid
});
}

function treemap() {
vscode.postMessage({
command: 'treemap',
});
}

function a(id){
const matcher = "[id^='" + id + "-']"
var elements = document.querySelectorAll(matcher);
Expand Down