Skip to content

Commit 0503046

Browse files
feat: integrate the flow
1 parent 560048c commit 0503046

File tree

5 files changed

+60
-56
lines changed

5 files changed

+60
-56
lines changed

src/upgrade/display/notificationManager.ts

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,48 @@
22
// Licensed under the MIT license.
33

44
import { commands, window } from "vscode";
5-
import type { FileIssues } from "../type";
6-
import { buildFixPrompt, buildMessage } from "../utility";
5+
import type { UpgradeIssue } from "../type";
6+
import { buildFixPrompt } from "../utility";
77
import { Commands } from "../../commands";
88

99
class NotificationManager {
1010
private hasShown = false;
1111

12-
13-
async refresh(issues: FileIssues) {
14-
const targetIssue = Object.values(issues)[0];
15-
16-
if (!targetIssue) {
12+
async triggerNotification(projectIssues: Record<string, UpgradeIssue[]>) {
13+
if (!this.shouldShow()) {
1714
return;
1815
}
1916

20-
if (this.hasShown) {
21-
return;
17+
const lines = [
18+
"Fix the following version issues:",
19+
];
20+
for (const [pomPath, issues] of Object.entries(projectIssues)) {
21+
lines.push("");
22+
lines.push(`For project "${pomPath}":`);
23+
const linesForCurrentProject = new Set<string>();
24+
for (const issue of issues) {
25+
linesForCurrentProject.add(buildFixPrompt(issue));
26+
}
27+
lines.push(...linesForCurrentProject);
28+
lines.push("\n");
2229
}
2330

31+
const prompt = lines.join("\n");
32+
const projectCount = Object.keys(projectIssues).length;
33+
const issueCount = Object.values(projectIssues).map(x => x.length).reduce((a, b) => a + b, 0);
34+
2435
const buttonText = "Upgrade";
25-
const selection = await window.showInformationMessage(buildMessage(targetIssue), buttonText);
36+
const selection = await window.showInformationMessage(`${issueCount} version issue(s) found in ${projectCount} project(s).`, buttonText);
2637
this.hasShown = true;
2738
if (selection === buttonText) {
28-
commands.executeCommand(Commands.VIEW_TRIGGER_JAVA_UPGRADE_TOOL, buildFixPrompt(targetIssue));
39+
commands.executeCommand(Commands.VIEW_TRIGGER_JAVA_UPGRADE_TOOL, prompt);
2940
}
3041
}
42+
43+
private shouldShow() {
44+
// TODO: fix
45+
return !this.hasShown;
46+
}
3147
}
3248

3349
const notificationManager = new NotificationManager();

src/upgrade/metadataManager.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
import type { DependencyCheckMetadata, DependencyCheckResult } from "./type";
4+
import type { DependencyCheckMetadata, DependencyCheckItem } from "./type";
55
import { Upgrade } from "../constants";
66
import { buildPackageId } from "./utility";
77
import DEPENDENCIES_TO_SCAN from "./dependency.data";
@@ -10,7 +10,7 @@ import DEPENDENCIES_TO_SCAN from "./dependency.data";
1010
class MetadataManager {
1111
private dependencyCheckMetadata: DependencyCheckMetadata = DEPENDENCIES_TO_SCAN;
1212

13-
public getMetadataById(givenPackageId: string): DependencyCheckResult | undefined {
13+
public getMetadataById(givenPackageId: string): DependencyCheckItem | undefined {
1414
const splits = givenPackageId.split(":", 2);
1515
const groupId = splits[0];
1616
const artifactId = splits[1] ?? "";
@@ -19,7 +19,6 @@ class MetadataManager {
1919
return {
2020
name: Upgrade.DIAGNOSTICS_NAME_FOR_JAVA_ENGINE,
2121
supportedVersion: `>=${Upgrade.LATEST_JAVA_LTS_VESRION}`,
22-
packageRuleUsed: buildPackageId(Upgrade.DIAGNOSTICS_GROUP_ID_FOR_JAVA_ENGINE, "*"),
2322
};
2423
}
2524

@@ -28,7 +27,7 @@ class MetadataManager {
2827
return this.getMetadata(packageId) ?? this.getMetadata(packageIdWithWildcardArtifactId);
2928
}
3029

31-
private getMetadata(packageRuleUsed: string): DependencyCheckResult | undefined {
30+
private getMetadata(packageRuleUsed: string) {
3231
return this.dependencyCheckMetadata[packageRuleUsed] ? {
3332
...this.dependencyCheckMetadata[packageRuleUsed], packageRuleUsed
3433
} : undefined;

src/upgrade/type.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export type DependencyCheckItem = { name: string, supportedVersion: string };
22
export type DependencyCheckMetadata = Record<string, DependencyCheckItem>;
3-
export type DependencyCheckResult = DependencyCheckItem & { packageRuleUsed: string };
43

54
export enum UpgradeReason {
65
END_OF_LIFE,
@@ -14,6 +13,4 @@ export type UpgradeIssue = {
1413
reason: UpgradeReason;
1514
currentVersion: string;
1615
suggestedVersion?: string;
17-
};
18-
19-
export type FileIssues = Record</* packageId */string, UpgradeIssue>;
16+
};

src/upgrade/upgradeManager.ts

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-w
1212
import { Commands } from "../commands";
1313
import metadataManager from "./metadataManager";
1414
import { buildPackageId } from "./utility";
15+
import notificationManager from "./display/notificationManager";
1516

1617
const DEFAULT_UPGRADE_PROMPT = "Upgrade Java project dependency";
1718

@@ -65,20 +66,22 @@ async function getProjectIssues(projectNode: INodeData): Promise<UpgradeIssue[]>
6566
const issues: UpgradeIssue[] = [];
6667
issues.push(...getJavaIssues(projectNode));
6768
const packageData = await Jdtls.getPackageData({ kind: NodeKind.Project, projectUri: projectNode.uri });
68-
packageData
69-
.filter(x => x.kind === NodeKind.Container)
70-
.forEach(async (packageContainer) => {
71-
const packages = await Jdtls.getPackageData({
72-
kind: NodeKind.Container,
73-
projectUri: projectNode.uri,
74-
path: packageContainer.path,
75-
});
76-
packages.forEach(
77-
(pkg) => {
78-
issues.push(...getDependencyIssues(pkg))
79-
}
80-
);
81-
});
69+
await Promise.allSettled(
70+
packageData
71+
.filter(x => x.kind === NodeKind.Container)
72+
.map(async (packageContainer) => {
73+
const packages = await Jdtls.getPackageData({
74+
kind: NodeKind.Container,
75+
projectUri: projectNode.uri,
76+
path: packageContainer.path,
77+
});
78+
packages.forEach(
79+
(pkg) => {
80+
issues.push(...getDependencyIssues(pkg))
81+
}
82+
);
83+
})
84+
);
8285
return issues;
8386
}
8487

@@ -110,17 +113,23 @@ class UpgradeManager {
110113
const projectIssues: Record</* pomPath */string, UpgradeIssue[]> = {};
111114
const uri = folder.uri.toString();
112115
const projects = await Jdtls.getProjects(uri);
113-
projects.forEach(async (projectNode) => {
116+
let hasIssues = false;
117+
await Promise.allSettled(projects.map(async (projectNode) => {
114118
const pomPath = projectNode.metaData?.PomPath as string | undefined;
115119
if (!pomPath) {
116120
return;
117121
}
118122

119123
const issues = await getProjectIssues(projectNode);
124+
if (issues.length > 0) {
125+
hasIssues = true;
126+
}
120127
projectIssues[pomPath] = issues;
121-
});
128+
}));
122129

123-
// TODO: show notification
130+
if (hasIssues) {
131+
notificationManager.triggerNotification(projectIssues);
132+
}
124133
}
125134

126135

src/upgrade/utility.ts

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
import { Uri } from "vscode";
22
import { UpgradeReason, type UpgradeIssue } from "./type";
33

4-
export function buildMessage(issue: UpgradeIssue): string {
5-
const { packageId, packageDisplayName, currentVersion, reason } = issue;
6-
const name = packageDisplayName ?? packageId;
7-
8-
switch (reason) {
9-
case UpgradeReason.END_OF_LIFE: {
10-
return `Your project dependency ${name} (${currentVersion}) is in end-of-life. Consider upgrading using GitHub Copilot for better security and performance.`;
11-
}
12-
case UpgradeReason.CVE: {
13-
return `Your project dependency ${name} (${currentVersion}) has CVE. Consider upgrading using GitHub Copilot for better security.`;
14-
}
15-
case UpgradeReason.ENGINE_TOO_OLD: {
16-
return `Your project Java version (${currentVersion}) is too old. Consider upgrading using GitHub Copilot for better performance and features.`;
17-
}
18-
}
19-
}
20-
214
export function buildFixPrompt(issue: UpgradeIssue): string {
225
const { packageId, packageDisplayName, reason, suggestedVersion } = issue;
236
const name = packageDisplayName ?? packageId;
@@ -28,13 +11,13 @@ export function buildFixPrompt(issue: UpgradeIssue): string {
2811

2912
switch (reason) {
3013
case UpgradeReason.END_OF_LIFE: {
31-
return [`Upgrade the package ${name} using Java Upgrade Tool.`, ...suffix].join(" ");
14+
return [`Upgrade the package ${name}.`, ...suffix].join(" ");
3215
}
3316
case UpgradeReason.CVE: {
34-
return [`Upgrade the package ${name} to resolve CVE using Java Upgrade Tool.`, ...suffix].join(" ");
17+
return [`Upgrade the package ${name} to address CVE issues.`, ...suffix].join(" ");
3518
}
3619
case UpgradeReason.ENGINE_TOO_OLD: {
37-
return [`Upgrade Java version using Java Upgrade Tool.`, ...suffix].join(" ");
20+
return [`Upgrade the version of Java.`, ...suffix].join(" ");
3821
}
3922
}
4023
}

0 commit comments

Comments
 (0)