Skip to content

Commit 105182c

Browse files
chore: UX update
1 parent cab8f49 commit 105182c

File tree

5 files changed

+45
-28
lines changed

5 files changed

+45
-28
lines changed

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export namespace ExtensionName {
3535
export const JAVA_LANGUAGE_SUPPORT: string = "redhat.java";
3636
export const APP_MODERNIZATION_FOR_JAVA = "vscjava.migrate-java-to-azure";
3737
export const APP_MODERNIZATION_UPGRADE_FOR_JAVA = "vscjava.vscode-java-upgrade";
38+
export const APP_MODERNIZATION_EXTENSION_NAME = "GitHub Copilot app modernization";
3839
}
3940

4041
export namespace Upgrade {

src/upgrade/dependency.metadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const DEPENDENCY_JAVA_RUNTIME = {
1111
"reason": UpgradeReason.JRE_TOO_OLD,
1212
"supportedVersion": `>=${LATEST_JAVA_LTS_VESRION}`,
1313
"suggestedVersion": {
14-
"name": String(LATEST_JAVA_LTS_VESRION),
14+
"name": `Java ${LATEST_JAVA_LTS_VESRION}`,
1515
"description": "latest LTS version",
1616
},
1717
} as const;

src/upgrade/display/notificationManager.ts

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

4-
import { commands, ExtensionContext, window } from "vscode";
4+
import { commands, ExtensionContext, extensions, window } from "vscode";
55
import type { IUpgradeIssuesRenderer, UpgradeIssue } from "../type";
66
import { buildFixPrompt, buildNotificationMessage } from "../utility";
77
import { Commands } from "../../commands";
88
import { Settings } from "../../settings";
99
import { instrumentOperation, sendInfo } from "vscode-extension-telemetry-wrapper";
10+
import { ExtensionName } from "../../constants";
1011

1112
const KEY_PREFIX = 'javaupgrade.notificationManager';
1213
const NEXT_SHOW_TS_KEY = `${KEY_PREFIX}.nextShowTs`;
1314

1415
const BUTTON_TEXT_UPGRADE = "Upgrade Now";
16+
const BUTTON_TEXT_INSTALL_AND_UPGRADE = "Install Extension and Upgrade";
1517
const BUTTON_TEXT_NOT_NOW = "Not Now";
1618

1719
const SECONDS_IN_A_DAY = 24 * 60 * 60;
@@ -47,19 +49,21 @@ class NotificationManager implements IUpgradeIssuesRenderer {
4749
}
4850
this.hasShown = true;
4951

52+
const hasExtension = !!extensions.getExtension(ExtensionName.APP_MODERNIZATION_UPGRADE_FOR_JAVA);
5053
const prompt = buildFixPrompt(issue);
51-
const notificationMessage = buildNotificationMessage(issue);
54+
const notificationMessage = buildNotificationMessage(issue, hasExtension);
55+
const upgradeButtonText = hasExtension ? BUTTON_TEXT_UPGRADE : BUTTON_TEXT_INSTALL_AND_UPGRADE;
5256
const selection = await window.showInformationMessage(
5357
notificationMessage,
54-
BUTTON_TEXT_UPGRADE,
58+
upgradeButtonText,
5559
BUTTON_TEXT_NOT_NOW);
5660
sendInfo(operationId, {
5761
operationName: "java.dependency.upgradeNotification.runUpgrade",
5862
choice: selection ?? "",
5963
});
6064

6165
switch (selection) {
62-
case BUTTON_TEXT_UPGRADE: {
66+
case upgradeButtonText: {
6367
commands.executeCommand(Commands.JAVA_UPGRADE_WITH_COPILOT, prompt);
6468
break;
6569
}

src/upgrade/upgradeManager.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Commands } from "../commands";
1111
import notificationManager from "./display/notificationManager";
1212
import { Settings } from "../settings";
1313
import assessmentManager from "./assessmentManager";
14-
import { checkOrPromptToInstallAppModExtension } from "./utility";
14+
import { checkOrInstallAppModExtension, checkOrPromptToInstallAppModExtension } from "./utility";
1515

1616
const DEFAULT_UPGRADE_PROMPT = "Upgrade Java project dependency to latest version.";
1717

@@ -26,10 +26,7 @@ class UpgradeManager {
2626

2727
// Upgrade project
2828
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.JAVA_UPGRADE_WITH_COPILOT, async (promptText?: string) => {
29-
await checkOrPromptToInstallAppModExtension(
30-
ExtensionName.APP_MODERNIZATION_UPGRADE_FOR_JAVA,
31-
"To upgrade the Java project, we need to use the App Modernization extension.",
32-
"Install extension and upgrade");
29+
await checkOrInstallAppModExtension(ExtensionName.APP_MODERNIZATION_UPGRADE_FOR_JAVA);
3330
const promptToUse = promptText ?? DEFAULT_UPGRADE_PROMPT;
3431
await commands.executeCommand(Commands.GOTO_AGENT_MODE, { prompt: promptToUse });
3532
}));
@@ -38,8 +35,8 @@ class UpgradeManager {
3835
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_MODERNIZE_JAVA_PROJECT, async () => {
3936
await checkOrPromptToInstallAppModExtension(
4037
ExtensionName.APP_MODERNIZATION_FOR_JAVA,
41-
"To modernize the Java project, we need to use the App Modernization extension.",
42-
"Install extension and modernize");
38+
"Install GitHub Copilot app modernization to modernize the Java project.",
39+
"Install Extension and Modernize");
4340
await commands.executeCommand("workbench.view.extension.azureJavaMigrationExplorer");
4441
}));
4542

src/upgrade/utility.ts

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function findEolDate(currentVersion: string, eolDate: Record<string, string>): s
2020
return null;
2121
}
2222

23-
export function buildNotificationMessage(issue: UpgradeIssue): string {
23+
export function buildNotificationMessage(issue: UpgradeIssue, hasExtension: boolean): string {
2424
const {
2525
packageId,
2626
currentVersion,
@@ -29,21 +29,22 @@ export function buildNotificationMessage(issue: UpgradeIssue): string {
2929
packageDisplayName
3030
} = issue;
3131

32+
const upgradeWord = hasExtension ? "upgrade" : `install ${ExtensionName.APP_MODERNIZATION_EXTENSION_NAME} extension and upgrade`;
3233

3334
if (packageId === Upgrade.PACKAGE_ID_FOR_JAVA_RUNTIME) {
34-
return `The current project is using an older Java runtime (${currentVersion}). Do you want to upgrade to the latest LTS version ${suggestedVersionName}?`;
35+
return `This project is using an older Java runtime (${currentVersion}). Would you like to ${upgradeWord} it to ${suggestedVersionName} (latest LTS)?`;
3536
}
3637

3738
switch (reason) {
3839
case UpgradeReason.END_OF_LIFE: {
3940
const { eolDate } = issue;
4041
const versionEolDate = findEolDate(currentVersion, eolDate);
41-
return `The current project is using ${packageDisplayName} ${currentVersion}, which has reached end of life${versionEolDate ? ` in ${versionEolDate}` : ""
42-
}. Do you want to upgrade to ${suggestedVersionName} (${suggestedVersionDescription})?`;
42+
return `This project is using ${packageDisplayName} ${currentVersion}, which has reached end of life${versionEolDate ? ` in ${versionEolDate}` : ""
43+
}. Would you like to ${upgradeWord} it to ${suggestedVersionName} (${suggestedVersionDescription})?`;
4344
}
4445
case UpgradeReason.DEPRECATED:
4546
default: {
46-
return `The current project is using ${packageDisplayName} ${currentVersion}, which has been deprecated. Do you want to upgrade to ${suggestedVersionName} (${suggestedVersionDescription})?`;
47+
return `This project is using ${packageDisplayName} ${currentVersion}, which has been deprecated. Would you like to ${upgradeWord} it to ${suggestedVersionName} (${suggestedVersionDescription})?`;
4748
}
4849
}
4950
}
@@ -73,6 +74,23 @@ export function normalizePath(path: string): string {
7374
return Uri.parse(path).toString();
7475
}
7576

77+
async function checkOrPromptToEnableAppModExtension() {
78+
if (extensions.getExtension(ExtensionName.APP_MODERNIZATION_FOR_JAVA)) {
79+
return;
80+
}
81+
82+
// The extension is disabled if we cannot detect the extension after installing it.
83+
await commands.executeCommand("workbench.extensions.search", ExtensionName.APP_MODERNIZATION_FOR_JAVA);
84+
const BTN_TEXT = "Show extension in sidebar";
85+
const choice2 = await window.showInformationMessage(
86+
`${ExtensionName.APP_MODERNIZATION_EXTENSION_NAME} extension is needed for the feature to work but it seems disabled. Please enable it manually and try again.`,
87+
BTN_TEXT
88+
);
89+
if (choice2 === BTN_TEXT) {
90+
await commands.executeCommand("workbench.extensions.search", ExtensionName.APP_MODERNIZATION_FOR_JAVA);
91+
}
92+
}
93+
7694
export async function checkOrPromptToInstallAppModExtension(
7795
extensionIdToCheck: string,
7896
notificationText: string,
@@ -88,18 +106,15 @@ export async function checkOrPromptToInstallAppModExtension(
88106
return;
89107
}
90108

91-
if (extensions.getExtension(ExtensionName.APP_MODERNIZATION_FOR_JAVA)) {
109+
await checkOrPromptToEnableAppModExtension();
110+
}
111+
112+
export async function checkOrInstallAppModExtension(
113+
extensionIdToCheck: string): Promise<void> {
114+
if (extensions.getExtension(extensionIdToCheck)) {
92115
return;
93116
}
94117

95-
// In this case the extension is disabled.
96-
await commands.executeCommand("workbench.extensions.search", ExtensionName.APP_MODERNIZATION_FOR_JAVA);
97-
const BTN_TEXT = "Show extension in sidebar";
98-
const choice2 = await window.showInformationMessage(
99-
"App Modernization extension is needed for the feature to work but it seems disabled. Please enable it manually and try again.",
100-
BTN_TEXT
101-
);
102-
if (choice2 === BTN_TEXT) {
103-
await commands.executeCommand("workbench.extensions.search", ExtensionName.APP_MODERNIZATION_FOR_JAVA);
104-
}
118+
await commands.executeCommand("workbench.extensions.installExtension", ExtensionName.APP_MODERNIZATION_FOR_JAVA);
119+
await checkOrPromptToEnableAppModExtension();
105120
}

0 commit comments

Comments
 (0)