Skip to content

Commit 6baf10b

Browse files
authored
Merge branch 'main' into wenyt/contextproviderapi
2 parents 276ac71 + 53fc823 commit 6baf10b

8 files changed

Lines changed: 86 additions & 22 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to the "vscode-java-dependency" extension will be documented
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## 0.25.2
8+
9+
- ux - Improve wording on project modernization by @FluoriteCafe-work in https://github.com/microsoft/vscode-java-dependency/pull/912
10+
- ux - Check extension existence on-the-fly when needed by @FluoriteCafe-work in https://github.com/microsoft/vscode-java-dependency/pull/911
11+
712
## 0.25.0
813
- feat - Remind users to upgrade old (<21) Java and EOL Spring Boot/Framework versions by @FluoriteCafe-work in https://github.com/microsoft/vscode-java-dependency/pull/901
914
- feat - Improve ProjectCommand.getMainClasses by @snjeza in https://github.com/microsoft/vscode-java-dependency/pull/883

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@
593593
},
594594
{
595595
"command": "_java.view.modernizeJavaProject",
596-
"when": "explorerResourceIsFolder && java:serverMode && isModernizationExtensionInstalled",
596+
"when": "explorerResourceIsFolder && java:serverMode",
597597
"group": "1_javaactions@40"
598598
},
599599
{

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: 13 additions & 8 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 { commands, type ExtensionContext, extensions, workspace, type WorkspaceFolder } from "vscode";
4+
import { commands, type ExtensionContext, workspace, type WorkspaceFolder } from "vscode";
55

66
import { Jdtls } from "../java/jdtls";
77
import { languageServerApiManager } from "../languageServerApi/languageServerApiManager";
@@ -11,28 +11,33 @@ import { Commands } from "../commands";
1111
import notificationManager from "./display/notificationManager";
1212
import { Settings } from "../settings";
1313
import assessmentManager from "./assessmentManager";
14+
import { checkOrInstallAppModExtensionForUpgrade, checkOrPopupToInstallAppModExtensionForModernization } from "./utility";
1415

1516
const DEFAULT_UPGRADE_PROMPT = "Upgrade Java project dependency to latest version.";
1617

1718

1819
function shouldRunCheckup() {
19-
return Settings.getEnableDependencyCheckup()
20-
&& !!extensions.getExtension(ExtensionName.APP_MODERNIZATION_UPGRADE_FOR_JAVA);
20+
return Settings.getEnableDependencyCheckup();
2121
}
2222

2323
class UpgradeManager {
2424
public static initialize(context: ExtensionContext) {
2525
notificationManager.initialize(context);
2626

27-
// Commands to be used
27+
// Upgrade project
2828
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.JAVA_UPGRADE_WITH_COPILOT, async (promptText?: string) => {
29+
await checkOrInstallAppModExtensionForUpgrade(ExtensionName.APP_MODERNIZATION_UPGRADE_FOR_JAVA);
2930
const promptToUse = promptText ?? DEFAULT_UPGRADE_PROMPT;
3031
await commands.executeCommand(Commands.GOTO_AGENT_MODE, { prompt: promptToUse });
3132
}));
32-
commands.executeCommand('setContext', 'isModernizationExtensionInstalled',
33-
!!extensions.getExtension(ExtensionName.APP_MODERNIZATION_FOR_JAVA));
34-
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_MODERNIZE_JAVA_PROJECT, () => {
35-
commands.executeCommand("workbench.view.extension.azureJavaMigrationExplorer");
33+
34+
// Show modernization view
35+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_MODERNIZE_JAVA_PROJECT, async () => {
36+
await checkOrPopupToInstallAppModExtensionForModernization(
37+
ExtensionName.APP_MODERNIZATION_FOR_JAVA,
38+
`${ExtensionName.APP_MODERNIZATION_EXTENSION_NAME} extension is required to modernize Java projects. Would you like to install it and modernize this project?`,
39+
"Install Extension and Modernize");
40+
await commands.executeCommand("workbench.view.extension.azureJavaMigrationExplorer");
3641
}));
3742

3843
UpgradeManager.scan();

src/upgrade/utility.ts

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

4-
import { Uri } from "vscode";
4+
import { commands, extensions, Uri, window } from "vscode";
55
import * as semver from "semver";
66
import { UpgradeReason, type UpgradeIssue } from "./type";
7-
import { Upgrade } from "../constants";
7+
import { ExtensionName, Upgrade } from "../constants";
8+
import { instrumentOperation } from "vscode-extension-telemetry-wrapper";
89

910

1011
function findEolDate(currentVersion: string, eolDate: Record<string, string>): string | null {
@@ -20,7 +21,7 @@ function findEolDate(currentVersion: string, eolDate: Record<string, string>): s
2021
return null;
2122
}
2223

23-
export function buildNotificationMessage(issue: UpgradeIssue): string {
24+
export function buildNotificationMessage(issue: UpgradeIssue, hasExtension: boolean): string {
2425
const {
2526
packageId,
2627
currentVersion,
@@ -29,21 +30,22 @@ export function buildNotificationMessage(issue: UpgradeIssue): string {
2930
packageDisplayName
3031
} = issue;
3132

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

3335
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}?`;
36+
return `This project is using an older Java runtime (${currentVersion}). Would you like to ${upgradeWord} it to ${suggestedVersionName} (latest LTS)?`;
3537
}
3638

3739
switch (reason) {
3840
case UpgradeReason.END_OF_LIFE: {
3941
const { eolDate } = issue;
4042
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})?`;
43+
return `This project is using ${packageDisplayName} ${currentVersion}, which has reached end of life${versionEolDate ? ` in ${versionEolDate}` : ""
44+
}. Would you like to ${upgradeWord} it to ${suggestedVersionName} (${suggestedVersionDescription})?`;
4345
}
4446
case UpgradeReason.DEPRECATED:
4547
default: {
46-
return `The current project is using ${packageDisplayName} ${currentVersion}, which has been deprecated. Do you want to upgrade to ${suggestedVersionName} (${suggestedVersionDescription})?`;
48+
return `This project is using ${packageDisplayName} ${currentVersion}, which has been deprecated. Would you like to ${upgradeWord} it to ${suggestedVersionName} (${suggestedVersionDescription})?`;
4749
}
4850
}
4951
}
@@ -73,3 +75,50 @@ export function normalizePath(path: string): string {
7375
return Uri.parse(path).toString();
7476
}
7577

78+
async function checkOrPromptToEnableAppModExtension(keyword: string) {
79+
if (extensions.getExtension(ExtensionName.APP_MODERNIZATION_FOR_JAVA)) {
80+
return;
81+
}
82+
83+
// The extension is in a disabled state since we cannot detect the extension after installing it.
84+
await instrumentOperation("java.dependency.extensionDisabled", async () => {
85+
await commands.executeCommand("workbench.extensions.search", ExtensionName.APP_MODERNIZATION_FOR_JAVA);
86+
const BTN_TEXT = "Show extension in sidebar";
87+
const choice2 = await window.showInformationMessage(
88+
`${ExtensionName.APP_MODERNIZATION_EXTENSION_NAME} extension is required to ${keyword} Java projects but it seems disabled. Please enable it manually and try again.`,
89+
{ modal: true },
90+
BTN_TEXT
91+
);
92+
if (choice2 === BTN_TEXT) {
93+
await commands.executeCommand("workbench.extensions.search", ExtensionName.APP_MODERNIZATION_FOR_JAVA);
94+
}
95+
})();
96+
}
97+
98+
export async function checkOrPopupToInstallAppModExtensionForModernization(
99+
extensionIdToCheck: string,
100+
notificationText: string,
101+
buttonText: string): Promise<void> {
102+
if (extensions.getExtension(extensionIdToCheck)) {
103+
return;
104+
}
105+
106+
const choice = await window.showInformationMessage(notificationText, { modal: true }, buttonText);
107+
if (choice === buttonText) {
108+
await commands.executeCommand("workbench.extensions.installExtension", ExtensionName.APP_MODERNIZATION_FOR_JAVA);
109+
} else {
110+
return;
111+
}
112+
113+
await checkOrPromptToEnableAppModExtension("modernize");
114+
}
115+
116+
export async function checkOrInstallAppModExtensionForUpgrade(
117+
extensionIdToCheck: string): Promise<void> {
118+
if (extensions.getExtension(extensionIdToCheck)) {
119+
return;
120+
}
121+
122+
await commands.executeCommand("workbench.extensions.installExtension", ExtensionName.APP_MODERNIZATION_FOR_JAVA);
123+
await checkOrPromptToEnableAppModExtension("upgrade");
124+
}

0 commit comments

Comments
 (0)