Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@
},
{
"command": "_java.view.modernizeJavaProject",
"when": "explorerResourceIsFolder && java:serverMode && isModernizationExtensionInstalled",
"when": "explorerResourceIsFolder && java:serverMode",
"group": "1_javaactions@40"
},
{
Expand Down
14 changes: 7 additions & 7 deletions src/upgrade/upgradeManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import { commands, type ExtensionContext, extensions, workspace, type WorkspaceFolder } from "vscode";
import { commands, type ExtensionContext, workspace, type WorkspaceFolder } from "vscode";

import { Jdtls } from "../java/jdtls";
import { languageServerApiManager } from "../languageServerApi/languageServerApiManager";
Expand All @@ -11,13 +11,13 @@ import { Commands } from "../commands";
import notificationManager from "./display/notificationManager";
import { Settings } from "../settings";
import assessmentManager from "./assessmentManager";
import { checkOrInstallExtension } from "./utility";

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


function shouldRunCheckup() {
return Settings.getEnableDependencyCheckup()
&& !!extensions.getExtension(ExtensionName.APP_MODERNIZATION_UPGRADE_FOR_JAVA);
return Settings.getEnableDependencyCheckup();
}

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

// Commands to be used
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.JAVA_UPGRADE_WITH_COPILOT, async (promptText?: string) => {
await checkOrInstallExtension(ExtensionName.APP_MODERNIZATION_UPGRADE_FOR_JAVA, ExtensionName.APP_MODERNIZATION_FOR_JAVA);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to confirm this part of design. So we still keep upgrade manager command, but you will check the installation of app mod extension?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes; the command depends on another command (javaupgrade.gotoAgentMode) which is provided by AppMod extension.

const promptToUse = promptText ?? DEFAULT_UPGRADE_PROMPT;
await commands.executeCommand(Commands.GOTO_AGENT_MODE, { prompt: promptToUse });
}));
commands.executeCommand('setContext', 'isModernizationExtensionInstalled',
!!extensions.getExtension(ExtensionName.APP_MODERNIZATION_FOR_JAVA));
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_MODERNIZE_JAVA_PROJECT, () => {
commands.executeCommand("workbench.view.extension.azureJavaMigrationExplorer");
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_MODERNIZE_JAVA_PROJECT, async () => {
await checkOrInstallExtension(ExtensionName.APP_MODERNIZATION_FOR_JAVA);
await commands.executeCommand("workbench.view.extension.azureJavaMigrationExplorer");
}));

UpgradeManager.scan();
Expand Down
37 changes: 36 additions & 1 deletion src/upgrade/utility.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import { Uri } from "vscode";
import { commands, extensions, Uri, window } from "vscode";
import * as semver from "semver";
import { UpgradeReason, type UpgradeIssue } from "./type";
import { Upgrade } from "../constants";
Expand Down Expand Up @@ -73,3 +73,38 @@ export function normalizePath(path: string): string {
return Uri.parse(path).toString();
}

export async function checkOrInstallExtension(extensionIdToCheck: string, extensionIdToInstall?: string): Promise<void> {
if (extensions.getExtension(extensionIdToCheck)) {
return;
}

const actualExtensionIdToInstall = extensionIdToInstall ?? extensionIdToCheck;

{
const BTN_TEXT = "Install extension";
const choice = await window.showInformationMessage(
"An extension is needed for the feature to work. Please install it and try again.",
BTN_TEXT
);
if (choice === BTN_TEXT) {
await commands.executeCommand("workbench.extensions.installExtension", actualExtensionIdToInstall);
}
}

if (extensions.getExtension(actualExtensionIdToInstall)) {
return;
}

// In this case the extension is disabled.
await commands.executeCommand("workbench.extensions.search", actualExtensionIdToInstall);
{
const BTN_TEXT = "Show extension in sidebar";
const choice = await window.showInformationMessage(
"An extension is needed for the feature to work but it seems disabled. Please enable it manually and try again.",
BTN_TEXT
);
if (choice === BTN_TEXT) {
await commands.executeCommand("workbench.extensions.search", actualExtensionIdToInstall);
}
}
}
Loading