Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## 0.25.2

- ux - Improve wording on project modernization by @FluoriteCafe-work in https://github.com/microsoft/vscode-java-dependency/pull/912
- ux - Check extension existence on-the-fly when needed by @FluoriteCafe-work in https://github.com/microsoft/vscode-java-dependency/pull/911

## 0.25.0
Expand Down
8 changes: 4 additions & 4 deletions src/upgrade/upgradeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Commands } from "../commands";
import notificationManager from "./display/notificationManager";
import { Settings } from "../settings";
import assessmentManager from "./assessmentManager";
import { checkOrInstallAppModExtension, checkOrPromptToInstallAppModExtension } from "./utility";
import { checkOrInstallAppModExtensionForUpgrade, checkOrPopupToInstallAppModExtensionForModernization } from "./utility";

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

Expand All @@ -26,16 +26,16 @@ class UpgradeManager {

// Upgrade project
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.JAVA_UPGRADE_WITH_COPILOT, async (promptText?: string) => {
await checkOrInstallAppModExtension(ExtensionName.APP_MODERNIZATION_UPGRADE_FOR_JAVA);
await checkOrInstallAppModExtensionForUpgrade(ExtensionName.APP_MODERNIZATION_UPGRADE_FOR_JAVA);
const promptToUse = promptText ?? DEFAULT_UPGRADE_PROMPT;
await commands.executeCommand(Commands.GOTO_AGENT_MODE, { prompt: promptToUse });
}));

// Show modernization view
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_MODERNIZE_JAVA_PROJECT, async () => {
await checkOrPromptToInstallAppModExtension(
await checkOrPopupToInstallAppModExtensionForModernization(
ExtensionName.APP_MODERNIZATION_FOR_JAVA,
"Install GitHub Copilot app modernization to modernize the Java project.",
`${ExtensionName.APP_MODERNIZATION_EXTENSION_NAME} extension is required to modernize Java projects. Would you like to install it and modernize this project?`,
"Install Extension and Modernize");
await commands.executeCommand("workbench.view.extension.azureJavaMigrationExplorer");
}));
Expand Down
34 changes: 19 additions & 15 deletions src/upgrade/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { commands, extensions, Uri, window } from "vscode";
import * as semver from "semver";
import { UpgradeReason, type UpgradeIssue } from "./type";
import { ExtensionName, Upgrade } from "../constants";
import { instrumentOperation } from "vscode-extension-telemetry-wrapper";


function findEolDate(currentVersion: string, eolDate: Record<string, string>): string | null {
Expand Down Expand Up @@ -74,47 +75,50 @@ export function normalizePath(path: string): string {
return Uri.parse(path).toString();
}

async function checkOrPromptToEnableAppModExtension() {
async function checkOrPromptToEnableAppModExtension(keyword: string) {
if (extensions.getExtension(ExtensionName.APP_MODERNIZATION_FOR_JAVA)) {
return;
}

// The extension is disabled if we cannot detect the extension after installing it.
await commands.executeCommand("workbench.extensions.search", ExtensionName.APP_MODERNIZATION_FOR_JAVA);
const BTN_TEXT = "Show extension in sidebar";
const choice2 = await window.showInformationMessage(
`${ExtensionName.APP_MODERNIZATION_EXTENSION_NAME} extension is needed for the feature to work but it seems disabled. Please enable it manually and try again.`,
BTN_TEXT
);
if (choice2 === BTN_TEXT) {
// The extension is in a disabled state since we cannot detect the extension after installing it.
await instrumentOperation("java.dependency.extensionDisabled", async () => {
await commands.executeCommand("workbench.extensions.search", ExtensionName.APP_MODERNIZATION_FOR_JAVA);
}
const BTN_TEXT = "Show extension in sidebar";
const choice2 = await window.showInformationMessage(
`${ExtensionName.APP_MODERNIZATION_EXTENSION_NAME} extension is required to ${keyword} Java projects but it seems disabled. Please enable it manually and try again.`,
{ modal: true },
BTN_TEXT
);
if (choice2 === BTN_TEXT) {
await commands.executeCommand("workbench.extensions.search", ExtensionName.APP_MODERNIZATION_FOR_JAVA);
}
})();
}

export async function checkOrPromptToInstallAppModExtension(
export async function checkOrPopupToInstallAppModExtensionForModernization(
extensionIdToCheck: string,
notificationText: string,
buttonText: string): Promise<void> {
if (extensions.getExtension(extensionIdToCheck)) {
return;
}

const choice = await window.showInformationMessage(notificationText, buttonText);
const choice = await window.showInformationMessage(notificationText, { modal: true }, buttonText);
if (choice === buttonText) {
await commands.executeCommand("workbench.extensions.installExtension", ExtensionName.APP_MODERNIZATION_FOR_JAVA);
} else {
return;
}

await checkOrPromptToEnableAppModExtension();
await checkOrPromptToEnableAppModExtension("modernize");
}

export async function checkOrInstallAppModExtension(
export async function checkOrInstallAppModExtensionForUpgrade(
extensionIdToCheck: string): Promise<void> {
if (extensions.getExtension(extensionIdToCheck)) {
return;
}

await commands.executeCommand("workbench.extensions.installExtension", ExtensionName.APP_MODERNIZATION_FOR_JAVA);
await checkOrPromptToEnableAppModExtension();
await checkOrPromptToEnableAppModExtension("upgrade");
}
Loading