Skip to content
This repository was archived by the owner on Mar 26, 2024. It is now read-only.

Commit 098087c

Browse files
committed
Report generator added
1 parent 6858e08 commit 098087c

14 files changed

+140
-29
lines changed

ado-extension.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifestVersion": 1,
33
"id": "android-app-size-diff",
44
"name": "Android app size changes",
5-
"version": "0.0.19",
5+
"version": "0.0.20",
66
"publisher": "PraveenPendyala",
77
"targets": [
88
{

bumpVersion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const supportedBumps = ["major", "minor", "patch"]
55

66
const nodePackagJsonPath = 'package.json';
77
const adoExtensionJsonPath = 'ado-extension.json';
8-
const adoTaskJsonPath = 'ado-task.json';
8+
const adoTaskJsonPath = 'src/task.json';
99

1010
if (process.argv.length != 3) {
1111
throw "Need exactly one argument!"

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "android-app-size-ado",
3-
"version": "0.0.19",
3+
"version": "0.0.20",
44
"description": "Azure DevOps task to measure the size in Android app size by looking at 2 given APKs and AABs",
55
"main": "index.js",
66
"scripts": {
@@ -50,4 +50,4 @@
5050
"ts-node": "^8.5.4",
5151
"typescript": "^3.7.4"
5252
}
53-
}
53+
}

src/adoTask/adoTaskRunner.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as adoTask from 'azure-pipelines-task-lib/task';
22
import * as util from 'util';
33
import ApkAnalyzer from '../apkAnalyzer/ApkAnalyzer';
4+
import ComparisionReportGenerator from '../apkAnalyzer/ComparisionReportGenerator';
5+
import { MarkdownReporter } from '../apkAnalyzer/reporter/MarkdownReporter';
46

57
export default class AdoTaskRunner {
68

@@ -10,16 +12,25 @@ export default class AdoTaskRunner {
1012
const targetAppPath: string | undefined = adoTask.getInput('targetAppPath', true);
1113
const summaryOutputPath: string | undefined = adoTask.getInput('summaryOutputPath', false);
1214

13-
if (util.isUndefined(baseAppPath) || util.isUndefined(targetAppPath)) {
14-
adoTask.setResult(adoTask.TaskResult.Failed, 'Invalid app paths supplied!');
15-
return;
15+
if (util.isUndefined(baseAppPath)
16+
|| util.isUndefined(targetAppPath)
17+
|| util.isUndefined(summaryOutputPath)) {
18+
throw 'App paths not supplied!'
1619
}
1720

18-
const baseSizeSummary = await new ApkAnalyzer().analyse(baseAppPath);
19-
const targetSizeSummary = await new ApkAnalyzer().analyse(targetAppPath);
21+
const apkAnalyzer = new ApkAnalyzer();
22+
const markdownReportor = new MarkdownReporter();
23+
const compareReportGenerator = new ComparisionReportGenerator(
24+
apkAnalyzer, markdownReportor);
2025

21-
console.log(baseSizeSummary);
22-
console.log(targetSizeSummary);
26+
console.log(await compareReportGenerator.generateComparisionReport(
27+
baseAppPath,
28+
targetAppPath,
29+
summaryOutputPath,
30+
'Base APK',
31+
'Target APK',
32+
['apkSize', 'installSize', 'dexFiles', 'arscFile']
33+
));
2334
}
2435
catch (err) {
2536
adoTask.setResult(adoTask.TaskResult.Failed, err.message);

src/apkAnalyzer/ApkAnalyzer.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import AdmZip from 'adm-zip';
22
import * as path from 'path'
33
import * as util from 'util';
44
import MetaMfParser from './MetaMfParser';
5-
import ApkSizeSummary from './ApkSizeSummary';
5+
import ApkSizeSummary from './model/ApkSizeSummary';
66
import { FilesSizeCalculator } from './FilesSizeCalculator';
77

88
export default class ApkAnalyzer {
99

10-
public async analyse(apkPath: string, workingDir?: string) : Promise<ApkSizeSummary> {
10+
public async analyse(apkPath: string, apkLabel: string, workingDir?: string) : Promise<ApkSizeSummary> {
1111
if (util.isUndefined(workingDir)) {
1212
workingDir = path.join(path.dirname(apkPath), 'extracted');
1313
}
@@ -25,11 +25,12 @@ export default class ApkAnalyzer {
2525
const fileSizeCalc = new FilesSizeCalculator();
2626
const sizeSummary = new ApkSizeSummary();
2727

28-
sizeSummary.apkFile = fileSizeCalc.getFileSize(apkPath);
29-
sizeSummary.arscFile = fileSizeCalc.getFilesSize(mfParser.getFiles('.arsc'));
30-
sizeSummary.dexFiles = fileSizeCalc.getFilesSize(mfParser.getFiles('.dex'));
31-
sizeSummary.nativeLibs = fileSizeCalc.getFilesSize(mfParser.getFiles('.so'));
32-
sizeSummary.installSize = sizeSummary.apkFile + sizeSummary.dexFiles;
28+
sizeSummary.apkLabel = apkLabel;
29+
sizeSummary.sizeMetrics['apkSize'] = fileSizeCalc.getFileSize(apkPath);
30+
sizeSummary.sizeMetrics['arscFile'] = fileSizeCalc.getFilesSize(mfParser.getFiles('.arsc'));
31+
sizeSummary.sizeMetrics['dexFiles'] = fileSizeCalc.getFilesSize(mfParser.getFiles('.dex'));
32+
sizeSummary.sizeMetrics['nativeLibs'] = fileSizeCalc.getFilesSize(mfParser.getFiles('.so'));
33+
sizeSummary.sizeMetrics['installSize'] = sizeSummary.sizeMetrics['apkSize'] + sizeSummary.sizeMetrics['dexFiles'];
3334

3435
return sizeSummary;
3536
}

src/apkAnalyzer/ApkSizeSummary.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import ApkAnalyzer from "./ApkAnalyzer";
2+
import ComparisionReport from "./model/ComparisionReport";
3+
import IReportor from './reporter/IReporter';
4+
5+
/**
6+
* Generates a report comparsing two different APks
7+
*/
8+
9+
export default class ComparisionReportGenerator {
10+
apkAnalyser: ApkAnalyzer;
11+
reporter: IReportor;
12+
13+
public constructor(apkAnalyser : ApkAnalyzer, reporter: IReportor) {
14+
this.apkAnalyser = apkAnalyser;
15+
this.reporter = reporter;
16+
}
17+
18+
public async generateComparisionReport(
19+
baseApkPath: string,
20+
targetApkPath: string,
21+
reportOutputPath: string,
22+
baseApkLabel: string = 'Base APK',
23+
targetApkLabel: string = 'Target APK',
24+
includeMetrics: Array<string> = ['apkSize', 'installSize', 'dexFiles']) : Promise<ComparisionReport> {
25+
const baseSummary = await this.apkAnalyser.analyse(baseApkPath, baseApkLabel);
26+
const targetSummary = await this.apkAnalyser.analyse(targetApkPath, targetApkLabel);
27+
28+
const comparisionReport = new ComparisionReport();
29+
comparisionReport.baseApkLabel = baseSummary.apkLabel;
30+
comparisionReport.targetApkLabel = targetSummary.apkLabel;
31+
32+
includeMetrics.forEach(metric => {
33+
const baseMetric = baseSummary.sizeMetrics[metric];
34+
const targetMetric = baseSummary.sizeMetrics[metric];
35+
const difference = targetMetric - baseMetric;
36+
37+
comparisionReport.comparisionMetrics.push({
38+
metricName: metric,
39+
baseValue: baseMetric,
40+
targetValue: targetMetric,
41+
difference: difference
42+
});
43+
});
44+
45+
this.reporter.writeReport(comparisionReport, reportOutputPath);
46+
47+
return comparisionReport;
48+
}
49+
50+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default class ApkSizeSummary {
2+
apkLabel: string = '';
3+
sizeMetrics: {[key: string]: number} = {};
4+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export interface ComparisionMetric {
2+
metricName: string;
3+
baseValue: number;
4+
targetValue: number;
5+
difference: number;
6+
}
7+
8+
export default class ComparisionReport {
9+
baseApkLabel: string = '';
10+
targetApkLabel: string = '';
11+
comparisionMetrics: Array<ComparisionMetric> = [];
12+
}

src/apkAnalyzer/reporter/IReporter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import ComparisionReport from '../model/ComparisionReport'
2+
3+
export default interface IReporter {
4+
5+
writeReport(comparisionReport: ComparisionReport, outputPath: string) : Promise<any>;
6+
}

0 commit comments

Comments
 (0)