Skip to content

Commit

Permalink
Merge branch 'OpenLiberty:main' into issue124-AutomatedTestcaseLCLS
Browse files Browse the repository at this point in the history
  • Loading branch information
SuparnaSuresh authored Dec 4, 2024
2 parents 13498f5 + 344b47f commit 7ee5da3
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 27 deletions.
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const cp = require("child_process");
const libertyGroupId = "io.openliberty.tools";
const libertyVersion = "2.2";
const jakartaGroupId = "org.eclipse.lsp4jakarta";
const jakartaVersion = "0.2.1";
const jakartaVersion = "0.2.2";
var releaseLevel = "releases"; //"snapshots"; //snapshots or releases

const libertyLemminxName = "liberty-langserver-lemminx-" + libertyVersion + "-jar-with-dependencies.jar";
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "liberty-dev-vscode-ext",
"displayName": "Liberty Tools",
"description": "Liberty Tools for Visual Studio Code",
"version": "24.0.11-SNAPSHOT",
"version": "24.0.12",
"publisher": "Open-Liberty",
"repository": {
"type": "git",
Expand Down Expand Up @@ -50,7 +50,7 @@
],
"contributes": {
"javaExtensions": [
"./jars/org.eclipse.lsp4jakarta.jdt.core-0.2.1.jar"
"./jars/org.eclipse.lsp4jakarta.jdt.core-0.2.2.jar"
],
"xml.javaExtensions": [
"./jars/liberty-langserver-lemminx-2.2-jar-with-dependencies.jar"
Expand Down
3 changes: 2 additions & 1 deletion src/definitions/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2020, 2022 IBM Corporation.
* Copyright (c) 2020, 2024 IBM Corporation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -34,6 +34,7 @@ export const COMMAND_AND_PROJECT_TYPE_MAP: { [command: string]: string[] } = {
};
export const EXCLUDED_DIR_PATTERN = "**/{bin,classes,target}/**";
export const COMMAND_TITLES = new Map();
export const UNTITLED_WORKSPACE="Untitled (Workspace)";
COMMAND_TITLES.set(localize("hotkey.commands.title.refresh"), "liberty.explorer.refresh");

COMMAND_TITLES.set(localize("hotkey.commands.title.start"), "liberty.dev.start");
Expand Down
31 changes: 23 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2020, 2022 IBM Corporation.
* Copyright (c) 2020, 2024 IBM Corporation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -19,11 +19,12 @@ import { JAVA_EXTENSION_ID, waitForStandardMode } from "./util/javaServerMode";
import { localize } from "./util/i18nUtil";
import { RequirementsData, resolveRequirements, resolveLclsRequirements } from "./util/requirements";
import { prepareExecutable } from "./util/javaServerStarter";
import * as helperUtil from "./util/helperUtil";

const LIBERTY_CLIENT_ID = "LANGUAGE_ID_LIBERTY";
const JAKARTA_CLIENT_ID = "LANGUAGE_ID_JAKARTA";
export const LIBERTY_LS_JAR = "liberty-langserver-2.2-jar-with-dependencies.jar";
export const JAKARTA_LS_JAR = "org.eclipse.lsp4jakarta.ls-0.2.1-jar-with-dependencies.jar";
export const JAKARTA_LS_JAR = "org.eclipse.lsp4jakarta.ls-0.2.2-jar-with-dependencies.jar";

let libertyClient: LanguageClient;
let jakartaClient: LanguageClient;
Expand Down Expand Up @@ -62,7 +63,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
item.text = localize("liberty.ls.thumbs.up");
item.tooltip = localize("liberty.ls.started");
toggleItem(window.activeTextEditor, item);

handleWorkspaceSaveInProgress(context);
registerCommands(context);
}, (error: any) => {
console.log("Liberty client was not ready. Did not initialize");
Expand Down Expand Up @@ -104,11 +105,7 @@ function bindRequest(request: string) {
}

function registerCommands(context: ExtensionContext) {
let projectProvider = ProjectProvider.getInstance();
if ( !projectProvider ) {
projectProvider = new ProjectProvider(context);
ProjectProvider.setInstance(projectProvider);
}
let projectProvider = getProjectProvider(context);

if (vscode.workspace.workspaceFolders !== undefined) {
registerFileWatcher(projectProvider);
Expand Down Expand Up @@ -261,3 +258,21 @@ async function getJavaExtensionAPI(): Promise<JavaExtensionAPI> {
}
return Promise.resolve(api);
}

function handleWorkspaceSaveInProgress(context: vscode.ExtensionContext) {
let projectProvider = getProjectProvider(context);
if (projectProvider.getContext().globalState.get('workspaceSaveInProgress') &&
projectProvider.getContext().globalState.get('selectedProject') !== undefined) {
devCommands.addProjectsToTheDashBoard(projectProvider, projectProvider.getContext().globalState.get('selectedProject') as string);
helperUtil.clearDataSavedInGlobalState(projectProvider.getContext());
}
}

function getProjectProvider(context: vscode.ExtensionContext): ProjectProvider {
let projectProvider = ProjectProvider.getInstance();
if (!projectProvider) {
projectProvider = new ProjectProvider(context);
ProjectProvider.setInstance(projectProvider);
}
return projectProvider;
}
29 changes: 24 additions & 5 deletions src/liberty/devCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,18 @@ function showListOfPathsToAdd(uris: string[]) {
if (!selection) {
return;
}
const result = await projectProvider.addUserSelectedPath(selection, projectProvider.getProjects());
const message = localize(`add.project.manually.message.${result}`, selection);
(result !== 0) ? console.error(message) : console.info(message); projectProvider.fireChangeEvent();
vscode.window.showInformationMessage(message);
if (projectProvider.isMultiProjectUntitledWorkspace()) {
/**
* Saving the selected project to globalstate for adding it to the dashboard after
* reinitialization of the extension when workspace is saved
*/
await projectProvider.getContext().globalState.update('selectedProject', selection);
/*
if the workspace is untitled suggest the user to save the workspace first
*/
await projectProvider.checkUntitledWorkspaceAndSaveIt();
}
await addProjectsToTheDashBoard(projectProvider, selection);
});
}

Expand Down Expand Up @@ -539,7 +547,7 @@ function getReportFile(path: any, dir: string, filename: string): any {

/*
Function will check if the report is available within the given path and returns a boolean based on it and also
the report will be displayed if it is available
the report will be displayed if it is available
*/
function checkReportAndDisplay(report: any, reportType: string, reportTypeLabel: string, libProject: LibertyProject, showErrorMessage: boolean): Promise<boolean> {
return new Promise((resolve) => {
Expand All @@ -565,3 +573,14 @@ function checkReportAndDisplay(report: any, reportType: string, reportTypeLabel:
});
});
}

/*
Method adds a project which is selected by the user from the list to the liberty dashboard
*/
export async function addProjectsToTheDashBoard(projectProvider: ProjectProvider, selection: string): Promise<void> {
const result = await projectProvider.addUserSelectedPath(selection, projectProvider.getProjects());
const message = localize(`add.project.manually.message.${result}`, selection);
(result !== 0) ? console.error(message) : console.info(message); projectProvider.fireChangeEvent();
vscode.window.showInformationMessage(message);
return Promise.resolve();
}
52 changes: 51 additions & 1 deletion src/liberty/libertyProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import * as gradleUtil from "../util/gradleUtil";
import * as mavenUtil from "../util/mavenUtil";
import * as util from "../util/helperUtil";
import { localize } from "../util/i18nUtil";
import { EXCLUDED_DIR_PATTERN, LIBERTY_GRADLE_PROJECT, LIBERTY_GRADLE_PROJECT_CONTAINER, LIBERTY_MAVEN_PROJECT, LIBERTY_MAVEN_PROJECT_CONTAINER } from "../definitions/constants";
import { EXCLUDED_DIR_PATTERN, LIBERTY_GRADLE_PROJECT, LIBERTY_GRADLE_PROJECT_CONTAINER, LIBERTY_MAVEN_PROJECT, LIBERTY_MAVEN_PROJECT_CONTAINER, UNTITLED_WORKSPACE } from "../definitions/constants";
import { BuildFileImpl, GradleBuildFile } from "../util/buildFile";
import { DashboardData } from "./dashboard";
import { BaseLibertyProject } from "./baseLibertyProject";
Expand Down Expand Up @@ -203,6 +203,56 @@ export class ProjectProvider implements vscode.TreeDataProvider<LibertyProject>
statusMessage.dispose();
}

/**
* This method asks the user to save the workspace first if it is untitled and the workspace contains more than
* one project. If the workspace is not saved, there are chances that the project's state may not be saved and
* manually added projects may not be visible in the Liberty dashboard in a new VS Code session.
*/
public async checkUntitledWorkspaceAndSaveIt(): Promise<void> {
return new Promise((resolve) => {
try {
vscode.window.showInformationMessage(
localize("workspace.not.saved.projects.may.not.persist"),
{ modal: true },
'Save Workspace'
).then(async (selection) => {
if (selection === 'Save Workspace') {
/**
* setting workspaceSaveInProgress to true and storing it in globalstate for identifyting that the
* workspace is saved and needs to save the manually added projects to the dashboard
*/
await this._context.globalState.update('workspaceSaveInProgress', true);
//opens the saveWorkspace as dialog box
await vscode.commands.executeCommand('workbench.action.saveWorkspaceAs');
}
/**
* If the user cancels saving the workspace and exits without saving, the data stays in the global state,
* which is shared across all VS Code instances. To prevent this data from being mistakenly used in other
* sessions and added to the dashboard, it should be cleared if the user cancels the save.
*/
util.clearDataSavedInGlobalState(this._context);
resolve();
});
} catch (error) {
console.debug("exception while saving the workspace" + error);
util.clearDataSavedInGlobalState(this._context);
resolve();
}
});
}

/*
This method identifies a workspace that is untitled and contains more than one project
*/
public isMultiProjectUntitledWorkspace(): boolean {
const workspaceFolders = vscode.workspace.workspaceFolders;
if ((workspaceFolders && workspaceFolders.length > 1
&& vscode.workspace.name === UNTITLED_WORKSPACE)) {
return true;
}
return false;
}

public fireChangeEvent(): void {
this._onDidChangeTreeData.fire(undefined);
}
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@
"hotkey.commands.title.view.test.report": "Liberty: View test report",
"hotkey.commands.title.add.project": "Liberty: Add Project to Liberty Dashboard",
"hotkey.commands.title.remove.project": "Liberty: Remove Project from Liberty Dashboard",
"hotkey.commands.title.show.commands": "Liberty: Show Liberty commands"
"hotkey.commands.title.show.commands": "Liberty: Show Liberty commands",
"workspace.not.saved.projects.may.not.persist": "Please save the workspace first. Projects that are manually added to the Liberty dashboard may not persist in the next VS Code session if the workspace is not saved before adding the project."
}
26 changes: 21 additions & 5 deletions src/util/commandUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ export async function getCommandForMaven(pomPath: string, command: string, termi
// attempt to use the Maven executable path, if empty try using mvn or mvnw according to the preferMavenWrapper setting
const mavenExecutablePath: string | undefined = vscode.workspace.getConfiguration("maven").get<string>("executable.path");
if (mavenExecutablePath) {
return formDefaultCommand(mavenExecutablePath, pomPath, command, "-f ", customCommand);
if (isWin() && terminalType === ShellType.POWERSHELL) {
/**
* Function call to get the command for powershell in Windows OS
*/
return formPowershellCommand(mavenExecutablePath, pomPath, command, "-f ", customCommand);
}
return formDefaultCommandWithPath(mavenExecutablePath, pomPath, command, "-f ", customCommand);
}
let mvnCmdStart = await mvnCmd(pomPath);
if (mvnCmdStart === "mvn") {
Expand Down Expand Up @@ -60,7 +66,7 @@ export async function getCommandForGradle(buildGradlePath: string, command: stri
return getGradleCommandForWin(gradleCmdStart, buildGradlePath, command, terminalType, customCommand);
} else {
gradleCmdStart = Path.join(gradleCmdStart, "gradlew");
return formDefaultCommand(gradleCmdStart, buildGradlePath, command, "-b=", customCommand);
return formDefaultCommandWithPath(gradleCmdStart, buildGradlePath, command, "-b=", customCommand);
}
}

Expand Down Expand Up @@ -161,7 +167,7 @@ function getGradleCommandForWin(gradleCmdStart: string, buildGradlePath: string,
switch (terminalType) {
case ShellType.GIT_BASH:
gradleCmdStart = Path.join(gradleCmdStart, "gradlew");
return formDefaultCommand(gradleCmdStart, buildGradlePath, command, "-b=", customCommand); //Bash
return formDefaultCommandWithPath(gradleCmdStart, buildGradlePath, command, "-b=", customCommand); //Bash
case ShellType.POWERSHELL:
gradleCmdStart = Path.join(gradleCmdStart, "gradlew.bat");
return formPowershellCommand(gradleCmdStart, buildGradlePath, command, "-b=", customCommand);
Expand All @@ -170,7 +176,7 @@ function getGradleCommandForWin(gradleCmdStart: string, buildGradlePath: string,
default:
// The default case is ShellType CMD or OTHERS
gradleCmdStart = Path.join(gradleCmdStart, "gradlew.bat");
return formDefaultCommand(gradleCmdStart, buildGradlePath, command, "-b=", customCommand);
return formDefaultCommandWithPath(gradleCmdStart, buildGradlePath, command, "-b=", customCommand);
}
}

Expand All @@ -190,7 +196,7 @@ function getMavenCommandForWin(mvnCmdStart: string, pomPath: string, command: st
default:
// The default case is ShellType CMD or OTHERS
mvnCmdStart = Path.join(mvnCmdStart, "mvnw.cmd");
return formDefaultCommand(mvnCmdStart, pomPath, command, "-f ", customCommand);
return formDefaultCommandWithPath(mvnCmdStart, pomPath, command, "-f ", customCommand);
}
}

Expand Down Expand Up @@ -218,6 +224,16 @@ function formLinuxBasedCommand(cmdStart: string, command: string, wrapperType: S
* Returns default command
*/
function formDefaultCommand(projectPath: string, buildFilePath: String, command: string, cmdOption: String, customCommand?: string): string {
if (customCommand) {
return `${projectPath} ` + `${command}` + ` ${customCommand}` + ` ${cmdOption}"${buildFilePath}"`;
}
return `${projectPath} ` + `${command}` + ` ${cmdOption}"${buildFilePath}"`;
}

/**
* Returns default format for the command with Path
*/
function formDefaultCommandWithPath(projectPath: string, buildFilePath: String, command: string, cmdOption: String, customCommand?: string): string {
if (customCommand) {
return "\"" + projectPath + "\" " + `${command}` + ` ${customCommand}` + ` ${cmdOption}"${buildFilePath}"`;
}
Expand Down
10 changes: 9 additions & 1 deletion src/util/helperUtil.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2020, 2022 IBM Corporation.
* Copyright (c) 2020, 2024 IBM Corporation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -71,4 +71,12 @@ export function getStorageData(context: vscode.ExtensionContext): DashboardData
export async function saveStorageData(context: vscode.ExtensionContext, dasboardData: DashboardData): Promise<void>{
await context.workspaceState.update(LIBERTY_DASHBOARD_WORKSPACE_STORAGE_KEY, dasboardData);
}
/**
* clears the states saved in global state
* @param context
*/
export function clearDataSavedInGlobalState(context: vscode.ExtensionContext) {
context.globalState.update('workspaceSaveInProgress', false);
context.globalState.update('selectedProject', undefined);
}

0 comments on commit 7ee5da3

Please sign in to comment.