From f61c7d5cc5a07247c09db206399dd23671acdcd9 Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Mon, 21 Oct 2024 19:22:10 +0530 Subject: [PATCH 01/23] Update devCommands.ts Fix added for the command with space in dir. --- src/liberty/devCommands.ts | 144 +++++++++++++++++++++++++++++++------ 1 file changed, 124 insertions(+), 20 deletions(-) diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index 456fbea9..a2100375 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -109,12 +109,12 @@ export async function startDevMode(libProject?: LibertyProject | undefined): Pro terminal.show(); libProject.setTerminal(terminal); if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT || libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) { - const mvnCmdStart = await mvnCmd(libProject.getPath()); - const cmd = `${mvnCmdStart} io.openliberty.tools:liberty-maven-plugin:dev -f "${libProject.getPath()}"`; + const mvnCmdStart= await mvnCmd(libProject.getPath()); + const cmd = getCommandForMaven(mvnCmdStart,libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:dev"); terminal.sendText(cmd); // start dev mode on current project } else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT || libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) { - const gradleCmdStart = await gradleCmd(libProject.getPath()); - const cmd = `${gradleCmdStart} libertyDev -b="${libProject.getPath()}"`; + let gradleCmdStart = await gradleCmd(libProject.getPath()); + const cmd=getCommandForGradle(gradleCmdStart,libProject.getPath(),"libertyDev"); terminal.sendText(cmd); // start dev mode on current project } } @@ -409,11 +409,11 @@ export async function customDevMode(libProject?: LibertyProject | undefined, par if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT || libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) { const mvnCmdStart = await mvnCmd(libProject.getPath()); - const cmd = `${mvnCmdStart} io.openliberty.tools:liberty-maven-plugin:dev ${customCommand} -f "${libProject.getPath()}"`; + const cmd = getCommandForMaven(mvnCmdStart,libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:dev"); terminal.sendText(cmd); } else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT || libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) { const gradleCmdStart = await gradleCmd(libProject.getPath()); - const cmd = `${gradleCmdStart} libertyDev ${customCommand} -b="${libProject.getPath()}"`; + const cmd=getCommandForGradle(gradleCmdStart,libProject.getPath(),"libertyDev"); terminal.sendText(cmd); } } @@ -444,11 +444,11 @@ export async function startContainerDevMode(libProject?: LibertyProject | undefi libProject.setTerminal(terminal); if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) { const mvnCmdStart = await mvnCmd(libProject.getPath()); - const cmd = `${mvnCmdStart} io.openliberty.tools:liberty-maven-plugin:devc -f "${libProject.getPath()}"`; + const cmd = getCommandForMaven(mvnCmdStart,libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:dev"); terminal.sendText(cmd); } else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) { - const gradleCmdStart = await gradleCmd(libProject.getPath()); - const cmd = `${gradleCmdStart} libertyDevc -b="${libProject.getPath()}"`; + let gradleCmdStart = await gradleCmd(libProject.getPath()); + const cmd=getCommandForGradle(gradleCmdStart,libProject.getPath(),"libertyDev"); terminal.sendText(cmd); } } @@ -545,7 +545,7 @@ export async function mvnCmd(pomPath: string): Promise { if (preferMavenWrapper) { const localMvnwPath: string | undefined = await getLocalMavenWrapper(Path.dirname(pomPath)); if (localMvnwPath) { - return localMvnwPath; + return `${localMvnwPath}`; } } return "mvn"; @@ -556,7 +556,7 @@ export async function gradleCmd(buildGradle: string): Promise { if (preferGradleWrapper) { const localGradlewPath: string | undefined = await getLocalGradleWrapper(Path.dirname(buildGradle)); if (localGradlewPath) { - return localGradlewPath; + return `${localGradlewPath}`; } } return "gradle"; @@ -570,14 +570,13 @@ export async function gradleCmd(buildGradle: string): Promise { * @param projectFolder */ async function getLocalMavenWrapper(projectFolder: string): Promise { - const mvnw: string = isWin() ? "mvnw.cmd" : "mvnw"; - - // walk up parent folders + let current: string = projectFolder; while (Path.basename(current)) { - const potentialMvnwPath: string = Path.join(current, mvnw); + const potentialMvnwPath: string = Path.join(current); + if (await pathExists(potentialMvnwPath)) { - return potentialMvnwPath; + return potentialMvnwPath; } current = Path.dirname(current); } @@ -590,16 +589,14 @@ async function getLocalMavenWrapper(projectFolder: string): Promise { - const gradlew: string = isWin() ? "gradlew.bat" : "gradlew"; - // walk up parent folders let current: string = projectFolder; while (Path.basename(current)) { - const potentialGradlewPath: string = Path.join(current, gradlew); + const potentialGradlewPath: string = Path.join(current); if (await pathExists(potentialGradlewPath)) { return potentialGradlewPath; } - current = Path.dirname(current); + current = Path.dirname(current); } return undefined; } @@ -610,4 +607,111 @@ async function getLocalGradleWrapper(projectFolder: string): Promise { + return dir.indexOf(' ') !== -1 ? `"${dir}"` : dir; + }); + const modifiedPath=quotedDir.join('\\'); + + const cmd = `${modifiedPath} ${command} -b="${path}"`; + return cmd; +} +/** + * Reused from vscode-maven + * https://github.com/microsoft/vscode-maven/blob/main/src/mavenTerminal.ts + */ +enum ShellType { + CMD = "Command Prompt", + POWERSHELL = "PowerShell", + GIT_BASH = "Git Bash", + WSL = "WSL Bash", + OTHERS = "Others" +} +function currentWindowsShell(): ShellType { + const currentWindowsShellPath: string = vscode.env.shell; + const executable: string = Path.basename(currentWindowsShellPath); + switch (executable.toLowerCase()) { + case "cmd.exe": + return ShellType.CMD; + case "pwsh.exe": + case "powershell.exe": + case "pwsh": // pwsh on mac/linux + return ShellType.POWERSHELL; + case "bash.exe": + case 'git-cmd.exe': + return ShellType.GIT_BASH; + case 'wsl.exe': + case 'ubuntu.exe': + case 'ubuntu1804.exe': + case 'kali.exe': + case 'debian.exe': + case 'opensuse-42.exe': + case 'sles-12.exe': + return ShellType.WSL; + default: + return ShellType.OTHERS; + } +} + +/** + * Return the maven commands based on the windows and Terminal + */ +function getCommandForMaven(mvnCmdStart: string, pomPath: string,command:string) : string { + +if (isWin()) { + switch (currentWindowsShell()) { + case ShellType.GIT_BASH: + return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` -f "${pomPath}"`; //Bash + case ShellType.POWERSHELL: { + + mvnCmdStart=Path.join(mvnCmdStart, "mvnw.cmd"); + return "& \""+ mvnCmdStart +"\"" + `${command}`+ ` -f "${pomPath}"`; // PowerShell + } + case ShellType.CMD: + mvnCmdStart=Path.join(mvnCmdStart, "mvnw.cmd"); + return "\""+ mvnCmdStart +"\"" + `${command}`+ ` -f "${pomPath}"`; // CMD + case ShellType.WSL: + // return + default: + mvnCmdStart=Path.join(mvnCmdStart, "mvnw.cmd"); + return "\""+ mvnCmdStart +"\"" + `${command}`+ ` -f "${pomPath}"`; + } +} else { + return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` -f "${pomPath}"`;; +} + +} + +/** + * Return the Gradle commands based on the windows and Terminal + */ +function getCommandForGradle(gradleCmdStart: string, buildGradlePath: string,command: string) : string { + +if (isWin()) { + switch (currentWindowsShell()) { + case ShellType.GIT_BASH: + gradleCmdStart=Path.join(gradleCmdStart, "gradlew"); + return "\""+ gradleCmdStart +"\"" + `${command}` + ` -b=" "${buildGradlePath}"`; //Bash + case ShellType.POWERSHELL: { + + gradleCmdStart=Path.join(gradleCmdStart, "gradlew.bat"); + return "& \""+ gradleCmdStart +"\" " + `${command}` + ` -b=" "${buildGradlePath}"`;// PowerShell + } + case ShellType.CMD: + gradleCmdStart=Path.join(gradleCmdStart, "gradlew.bat"); + return "\""+ gradleCmdStart +"\"" + `${command}` + ` -b=" "${buildGradlePath}"`; // CMD + case ShellType.WSL: + // return + default: + gradleCmdStart=Path.join(gradleCmdStart, "gradlew.bat"); + return "\""+ gradleCmdStart +"\"" + `${command}` + ` -b=" "${buildGradlePath}"`;; + } +} else { + gradleCmdStart=Path.join(gradleCmdStart, "gradlew"); + return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b=" "${buildGradlePath}"`; +} + } \ No newline at end of file From 595a16e3b33cf58835fcf69320da55d68145a366 Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Tue, 22 Oct 2024 10:34:32 +0530 Subject: [PATCH 02/23] fixed wsl commands and added code for startinContainer and strat --- src/liberty/devCommands.ts | 118 ++------------------------- src/util/commandUtils.ts | 159 +++++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+), 112 deletions(-) create mode 100644 src/util/commandUtils.ts diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index a2100375..8a5a9a19 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -21,6 +21,7 @@ import { getGradleTestReport } from "../util/gradleUtil"; import { pathExists } from "fs-extra"; import { DashboardData } from "./dashboard"; import { ProjectStartCmdParam } from "./projectStartCmdParam"; +import { getCommandForMaven, getCommandForGradle } from "../util/commandUtils"; export const terminals: { [libProjectId: number]: LibertyProject } = {}; @@ -409,11 +410,11 @@ export async function customDevMode(libProject?: LibertyProject | undefined, par if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT || libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) { const mvnCmdStart = await mvnCmd(libProject.getPath()); - const cmd = getCommandForMaven(mvnCmdStart,libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:dev"); + const cmd = getCommandForMaven(mvnCmdStart,libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:dev",customCommand); terminal.sendText(cmd); } else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT || libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) { const gradleCmdStart = await gradleCmd(libProject.getPath()); - const cmd=getCommandForGradle(gradleCmdStart,libProject.getPath(),"libertyDev"); + const cmd=getCommandForGradle(gradleCmdStart,libProject.getPath(),"libertyDev",customCommand); terminal.sendText(cmd); } } @@ -444,11 +445,11 @@ export async function startContainerDevMode(libProject?: LibertyProject | undefi libProject.setTerminal(terminal); if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) { const mvnCmdStart = await mvnCmd(libProject.getPath()); - const cmd = getCommandForMaven(mvnCmdStart,libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:dev"); + const cmd = getCommandForMaven(mvnCmdStart,libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:devc"); terminal.sendText(cmd); } else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) { let gradleCmdStart = await gradleCmd(libProject.getPath()); - const cmd=getCommandForGradle(gradleCmdStart,libProject.getPath(),"libertyDev"); + const cmd=getCommandForGradle(gradleCmdStart,libProject.getPath(),"libertyDevc"); terminal.sendText(cmd); } } @@ -605,113 +606,6 @@ async function getLocalGradleWrapper(projectFolder: string): Promise { - return dir.indexOf(' ') !== -1 ? `"${dir}"` : dir; - }); - const modifiedPath=quotedDir.join('\\'); - - const cmd = `${modifiedPath} ${command} -b="${path}"`; - return cmd; -} -/** - * Reused from vscode-maven - * https://github.com/microsoft/vscode-maven/blob/main/src/mavenTerminal.ts - */ -enum ShellType { - CMD = "Command Prompt", - POWERSHELL = "PowerShell", - GIT_BASH = "Git Bash", - WSL = "WSL Bash", - OTHERS = "Others" -} -function currentWindowsShell(): ShellType { - const currentWindowsShellPath: string = vscode.env.shell; - const executable: string = Path.basename(currentWindowsShellPath); - switch (executable.toLowerCase()) { - case "cmd.exe": - return ShellType.CMD; - case "pwsh.exe": - case "powershell.exe": - case "pwsh": // pwsh on mac/linux - return ShellType.POWERSHELL; - case "bash.exe": - case 'git-cmd.exe': - return ShellType.GIT_BASH; - case 'wsl.exe': - case 'ubuntu.exe': - case 'ubuntu1804.exe': - case 'kali.exe': - case 'debian.exe': - case 'opensuse-42.exe': - case 'sles-12.exe': - return ShellType.WSL; - default: - return ShellType.OTHERS; - } -} - -/** - * Return the maven commands based on the windows and Terminal - */ -function getCommandForMaven(mvnCmdStart: string, pomPath: string,command:string) : string { - -if (isWin()) { - switch (currentWindowsShell()) { - case ShellType.GIT_BASH: - return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` -f "${pomPath}"`; //Bash - case ShellType.POWERSHELL: { - - mvnCmdStart=Path.join(mvnCmdStart, "mvnw.cmd"); - return "& \""+ mvnCmdStart +"\"" + `${command}`+ ` -f "${pomPath}"`; // PowerShell - } - case ShellType.CMD: - mvnCmdStart=Path.join(mvnCmdStart, "mvnw.cmd"); - return "\""+ mvnCmdStart +"\"" + `${command}`+ ` -f "${pomPath}"`; // CMD - case ShellType.WSL: - // return - default: - mvnCmdStart=Path.join(mvnCmdStart, "mvnw.cmd"); - return "\""+ mvnCmdStart +"\"" + `${command}`+ ` -f "${pomPath}"`; - } -} else { - return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` -f "${pomPath}"`;; -} - -} - -/** - * Return the Gradle commands based on the windows and Terminal - */ -function getCommandForGradle(gradleCmdStart: string, buildGradlePath: string,command: string) : string { - -if (isWin()) { - switch (currentWindowsShell()) { - case ShellType.GIT_BASH: - gradleCmdStart=Path.join(gradleCmdStart, "gradlew"); - return "\""+ gradleCmdStart +"\"" + `${command}` + ` -b=" "${buildGradlePath}"`; //Bash - case ShellType.POWERSHELL: { - - gradleCmdStart=Path.join(gradleCmdStart, "gradlew.bat"); - return "& \""+ gradleCmdStart +"\" " + `${command}` + ` -b=" "${buildGradlePath}"`;// PowerShell - } - case ShellType.CMD: - gradleCmdStart=Path.join(gradleCmdStart, "gradlew.bat"); - return "\""+ gradleCmdStart +"\"" + `${command}` + ` -b=" "${buildGradlePath}"`; // CMD - case ShellType.WSL: - // return - default: - gradleCmdStart=Path.join(gradleCmdStart, "gradlew.bat"); - return "\""+ gradleCmdStart +"\"" + `${command}` + ` -b=" "${buildGradlePath}"`;; - } -} else { - gradleCmdStart=Path.join(gradleCmdStart, "gradlew"); - return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b=" "${buildGradlePath}"`; -} - -} \ No newline at end of file diff --git a/src/util/commandUtils.ts b/src/util/commandUtils.ts new file mode 100644 index 00000000..1df77a22 --- /dev/null +++ b/src/util/commandUtils.ts @@ -0,0 +1,159 @@ +import * as Path from "path"; +import * as vscode from "vscode"; +import { isWin } from "../liberty/devCommands"; + +/** + * Reused from vscode-maven + * https://github.com/microsoft/vscode-maven/blob/main/src/mavenTerminal.ts + */ +enum ShellType { + CMD = "Command Prompt", + POWERSHELL = "PowerShell", + GIT_BASH = "Git Bash", + WSL = "WSL Bash", + OTHERS = "Others" +} +/** + * Reused from vscode-maven + * https://github.com/microsoft/vscode-maven/blob/main/src/mavenTerminal.ts + */ +function currentWindowsShell(): ShellType { + const currentWindowsShellPath: string = vscode.env.shell; + const executable: string = Path.basename(currentWindowsShellPath); + switch (executable.toLowerCase()) { + case "cmd.exe": + return ShellType.CMD; + case "pwsh.exe": + case "powershell.exe": + case "pwsh": // pwsh on mac/linux + return ShellType.POWERSHELL; + case "bash.exe": + case 'git-cmd.exe': + return ShellType.GIT_BASH; + case 'wsl.exe': + case 'ubuntu.exe': + case 'ubuntu1804.exe': + case 'kali.exe': + case 'debian.exe': + case 'opensuse-42.exe': + case 'sles-12.exe': + return ShellType.WSL; + default: + return ShellType.OTHERS; + } +} + +/** + * Return the maven commands based on the OS and Terminal + */ +export function getCommandForMaven(mvnCmdStart: string, pomPath: string,command:string,customCommand?: string) : string { + + if (isWin()) { + switch (currentWindowsShell()) { + case ShellType.GIT_BASH: + if(customCommand){ + return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` ${customCommand}` +` -f "${pomPath}"`; //Bash + } + return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` -f "${pomPath}"`; //Bash for start.. + + case ShellType.POWERSHELL: { + mvnCmdStart=Path.join(mvnCmdStart, "mvnw.cmd"); + if(customCommand){ + + return "& \""+ mvnCmdStart +"\" " + `${command}`+` ${customCommand}` +` -f "${pomPath}"`; //Poweshell for start.. + } + return "& \""+ mvnCmdStart +"\" " + `${command}`+ ` -f "${pomPath}"`; // PowerShell + } + case ShellType.CMD: + mvnCmdStart=Path.join(mvnCmdStart, "mvnw.cmd"); + if(customCommand){ + + return "\""+ mvnCmdStart +"\" " + `${command}`+` ${customCommand}` + ` -f "${pomPath}"`; //cmd for start.. + } + return "\""+ mvnCmdStart +"\" " + `${command}`+ ` -f "${pomPath}"`; // CMD + case ShellType.WSL: + mvnCmdStart=toDefaultWslPath(mvnCmdStart); + pomPath=toDefaultWslPath(pomPath); + if(customCommand){ + return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` ${customCommand}` +` -f "${pomPath}"`; //Bash + } + return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` -f "${pomPath}"`; //Bash for start.. + + + default: + mvnCmdStart=Path.join(mvnCmdStart, "mvnw.cmd"); + if(customCommand){ + return "\""+ mvnCmdStart +"\" " + `${command}`+` ${customCommand}` + ` -f "${pomPath}"`; + } + return "\""+ mvnCmdStart +"\" " + `${command}`+ ` -f "${pomPath}"`; + } + } else { + if(customCommand){ + return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+` ${customCommand}` + ` -f "${pomPath}"`; + } + return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` -f "${pomPath}"`; + } + +} + +/** + * Return the Gradle commands based on the OS and Terminal + */ +export function getCommandForGradle(gradleCmdStart: string, buildGradlePath: string, command: string, customCommand?: string) : string { + + if (isWin()) { + switch (currentWindowsShell()) { + case ShellType.GIT_BASH: + gradleCmdStart=Path.join(gradleCmdStart, "gradlew"); + if(customCommand){ + return "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; //bash start.. + } + return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; //Bash + case ShellType.POWERSHELL: { + gradleCmdStart=Path.join(gradleCmdStart, "gradlew.bat"); + if(customCommand){ + return "& \""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`;// PowerShell strat.. + } + return "& \""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`;// PowerShell + } + case ShellType.CMD: + gradleCmdStart=Path.join(gradleCmdStart, "gradlew.bat"); + if(customCommand){ + return "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; // CMD start.. + } + return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; // CMD + case ShellType.WSL: + buildGradlePath=toDefaultWslPath(buildGradlePath); + gradleCmdStart=toDefaultWslPath(gradleCmdStart) + gradleCmdStart=Path.join(gradleCmdStart, "gradlew"); + if(customCommand){ + return "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; //wsl start.. + } + return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; //wsl + default: + gradleCmdStart=Path.join(gradleCmdStart, "gradlew.bat"); + if(customCommand){ + "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; + } + return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; + } + } else { + gradleCmdStart=Path.join(gradleCmdStart, "gradlew"); + if(customCommand){ + return "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; + } + return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; + } + +} + +function toDefaultWslPath(p: string): string { + const arr: string[] = p.split(":\\"); + if (arr.length === 2) { + const drive: string = arr[0].toLowerCase(); + const dir: string = arr[1].replace(/\\/g, "/"); + return `/mnt/${drive}/${dir}`; + } else { + return p.replace(/\\/g, "/"); + } +} \ No newline at end of file From 137798e42583c3f5e829cf93acac9e2060465552 Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Tue, 22 Oct 2024 15:59:24 +0530 Subject: [PATCH 03/23] Copyright added in commandUtils --- src/liberty/devCommands.ts | 2 +- src/util/commandUtils.ts | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index 8a5a9a19..2f0ea42b 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -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 diff --git a/src/util/commandUtils.ts b/src/util/commandUtils.ts index 1df77a22..780ccbd9 100644 --- a/src/util/commandUtils.ts +++ b/src/util/commandUtils.ts @@ -1,3 +1,13 @@ +/** + * Copyright (c) 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 + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ + import * as Path from "path"; import * as vscode from "vscode"; import { isWin } from "../liberty/devCommands"; @@ -44,7 +54,7 @@ function currentWindowsShell(): ShellType { } /** - * Return the maven commands based on the OS and Terminal + * Return the maven commands based on the OS and Terminal for start, startinContainer, start.. */ export function getCommandForMaven(mvnCmdStart: string, pomPath: string,command:string,customCommand?: string) : string { @@ -97,7 +107,7 @@ export function getCommandForMaven(mvnCmdStart: string, pomPath: string,command: } /** - * Return the Gradle commands based on the OS and Terminal + * Return the Gradle commands based on the OS and Terminal for start, startinContainer, start.. */ export function getCommandForGradle(gradleCmdStart: string, buildGradlePath: string, command: string, customCommand?: string) : string { @@ -146,7 +156,10 @@ export function getCommandForGradle(gradleCmdStart: string, buildGradlePath: str } } - +/** + * Reused from vscode-maven + * https://github.com/microsoft/vscode-maven/blob/main/src/mavenTerminal.ts + */ function toDefaultWslPath(p: string): string { const arr: string[] = p.split(":\\"); if (arr.length === 2) { From 8a642a78d73f3c881bfdf1e2b9ceab52faa77cd9 Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Tue, 22 Oct 2024 22:14:59 +0530 Subject: [PATCH 04/23] Fix for the commands - using 'mvn' and 'gradle' --- src/liberty/devCommands.ts | 26 +++++++----------- src/util/commandUtils.ts | 56 +++++++++++++++++++++++++------------- 2 files changed, 47 insertions(+), 35 deletions(-) diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index 2f0ea42b..ef082764 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -110,12 +110,10 @@ export async function startDevMode(libProject?: LibertyProject | undefined): Pro terminal.show(); libProject.setTerminal(terminal); if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT || libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) { - const mvnCmdStart= await mvnCmd(libProject.getPath()); - const cmd = getCommandForMaven(mvnCmdStart,libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:dev"); + const cmd = await getCommandForMaven(libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:dev"); terminal.sendText(cmd); // start dev mode on current project } else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT || libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) { - let gradleCmdStart = await gradleCmd(libProject.getPath()); - const cmd=getCommandForGradle(gradleCmdStart,libProject.getPath(),"libertyDev"); + const cmd = await getCommandForGradle(libProject.getPath(),"libertyDev"); terminal.sendText(cmd); // start dev mode on current project } } @@ -409,12 +407,10 @@ export async function customDevMode(libProject?: LibertyProject | undefined, par } if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT || libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) { - const mvnCmdStart = await mvnCmd(libProject.getPath()); - const cmd = getCommandForMaven(mvnCmdStart,libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:dev",customCommand); + const cmd = await getCommandForMaven(libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:dev",customCommand); terminal.sendText(cmd); } else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT || libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) { - const gradleCmdStart = await gradleCmd(libProject.getPath()); - const cmd=getCommandForGradle(gradleCmdStart,libProject.getPath(),"libertyDev",customCommand); + const cmd = await getCommandForGradle(libProject.getPath(),"libertyDev",customCommand); terminal.sendText(cmd); } } @@ -444,12 +440,10 @@ export async function startContainerDevMode(libProject?: LibertyProject | undefi terminal.show(); libProject.setTerminal(terminal); if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) { - const mvnCmdStart = await mvnCmd(libProject.getPath()); - const cmd = getCommandForMaven(mvnCmdStart,libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:devc"); + const cmd = await getCommandForMaven(libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:devc"); terminal.sendText(cmd); } else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) { - let gradleCmdStart = await gradleCmd(libProject.getPath()); - const cmd=getCommandForGradle(gradleCmdStart,libProject.getPath(),"libertyDevc"); + const cmd = await getCommandForGradle(libProject.getPath(),"libertyDevc"); terminal.sendText(cmd); } } @@ -509,9 +503,9 @@ export async function openReport(reportType: string, libProject?: LibertyProject ); panel.webview.html = getReport(report); // display HTML content } else { - const message = localize("test.report.does.not.exist.run.test.first", report); - vscode.window.showInformationMessage(message); - } + const message = localize("test.report.does.not.exist.run.test.first", report); + vscode.window.showInformationMessage(message); + } }); } } else if (ProjectProvider.getInstance() && reportType) { @@ -608,4 +602,4 @@ async function getLocalGradleWrapper(projectFolder: string): Promise { + let mvnCmdStart = await mvnCmd(pomPath); + + if(mvnCmdStart === "mvn"){ + if(customCommand) + { + return `${mvnCmdStart} ` + `${command}`+` ${customCommand}` + ` -f "${pomPath}"`; + } + return `${mvnCmdStart} ` + `${command}`+ ` -f "${pomPath}"`; + } if (isWin()) { switch (currentWindowsShell()) { case ShellType.GIT_BASH: @@ -67,7 +76,7 @@ export function getCommandForMaven(mvnCmdStart: string, pomPath: string,command: return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` -f "${pomPath}"`; //Bash for start.. case ShellType.POWERSHELL: { - mvnCmdStart=Path.join(mvnCmdStart, "mvnw.cmd"); + mvnCmdStart = Path.join(mvnCmdStart, "mvnw.cmd"); if(customCommand){ return "& \""+ mvnCmdStart +"\" " + `${command}`+` ${customCommand}` +` -f "${pomPath}"`; //Poweshell for start.. @@ -75,23 +84,23 @@ export function getCommandForMaven(mvnCmdStart: string, pomPath: string,command: return "& \""+ mvnCmdStart +"\" " + `${command}`+ ` -f "${pomPath}"`; // PowerShell } case ShellType.CMD: - mvnCmdStart=Path.join(mvnCmdStart, "mvnw.cmd"); + mvnCmdStart = Path.join(mvnCmdStart, "mvnw.cmd"); if(customCommand){ return "\""+ mvnCmdStart +"\" " + `${command}`+` ${customCommand}` + ` -f "${pomPath}"`; //cmd for start.. } return "\""+ mvnCmdStart +"\" " + `${command}`+ ` -f "${pomPath}"`; // CMD case ShellType.WSL: - mvnCmdStart=toDefaultWslPath(mvnCmdStart); - pomPath=toDefaultWslPath(pomPath); + mvnCmdStart = toDefaultWslPath(mvnCmdStart); + pomPath = toDefaultWslPath(pomPath); if(customCommand){ - return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` ${customCommand}` +` -f "${pomPath}"`; //Bash + return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` ${customCommand}` +` -f "${pomPath}"`; //Wsl start .. } - return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` -f "${pomPath}"`; //Bash for start.. + return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` -f "${pomPath}"`; //Wsl default: - mvnCmdStart=Path.join(mvnCmdStart, "mvnw.cmd"); + mvnCmdStart = Path.join(mvnCmdStart, "mvnw.cmd"); if(customCommand){ return "\""+ mvnCmdStart +"\" " + `${command}`+` ${customCommand}` + ` -f "${pomPath}"`; } @@ -109,46 +118,54 @@ export function getCommandForMaven(mvnCmdStart: string, pomPath: string,command: /** * Return the Gradle commands based on the OS and Terminal for start, startinContainer, start.. */ -export function getCommandForGradle(gradleCmdStart: string, buildGradlePath: string, command: string, customCommand?: string) : string { +export async function getCommandForGradle(buildGradlePath: string, command: string, customCommand?: string) : Promise { + let gradleCmdStart = await gradleCmd(buildGradlePath); + if(gradleCmdStart === "gradle"){ + if(customCommand) + { + return `${gradleCmdStart} ` + `${command}`+` ${customCommand}` + ` -b="${buildGradlePath}"`; + } + return `${gradleCmdStart} ` + `${command}`+ ` -b="${buildGradlePath}"`; + } if (isWin()) { switch (currentWindowsShell()) { case ShellType.GIT_BASH: - gradleCmdStart=Path.join(gradleCmdStart, "gradlew"); + gradleCmdStart = Path.join(gradleCmdStart, "gradlew"); if(customCommand){ return "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; //bash start.. } return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; //Bash case ShellType.POWERSHELL: { - gradleCmdStart=Path.join(gradleCmdStart, "gradlew.bat"); + gradleCmdStart = Path.join(gradleCmdStart, "gradlew.bat"); if(customCommand){ return "& \""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`;// PowerShell strat.. } return "& \""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`;// PowerShell } case ShellType.CMD: - gradleCmdStart=Path.join(gradleCmdStart, "gradlew.bat"); + gradleCmdStart = Path.join(gradleCmdStart, "gradlew.bat"); if(customCommand){ return "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; // CMD start.. } return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; // CMD case ShellType.WSL: - buildGradlePath=toDefaultWslPath(buildGradlePath); - gradleCmdStart=toDefaultWslPath(gradleCmdStart) - gradleCmdStart=Path.join(gradleCmdStart, "gradlew"); + buildGradlePath = toDefaultWslPath(buildGradlePath); + gradleCmdStart = toDefaultWslPath(gradleCmdStart) + gradleCmdStart = Path.join(gradleCmdStart, "gradlew"); if(customCommand){ return "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; //wsl start.. } return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; //wsl default: - gradleCmdStart=Path.join(gradleCmdStart, "gradlew.bat"); + gradleCmdStart = Path.join(gradleCmdStart, "gradlew.bat"); if(customCommand){ "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; } return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; } } else { - gradleCmdStart=Path.join(gradleCmdStart, "gradlew"); + gradleCmdStart = Path.join(gradleCmdStart, "gradlew"); if(customCommand){ return "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; } @@ -169,4 +186,5 @@ function toDefaultWslPath(p: string): string { } else { return p.replace(/\\/g, "/"); } -} \ No newline at end of file +} + From 5b497904ceff4e820e48fc3c0417dfc6995760cd Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Tue, 22 Oct 2024 22:28:42 +0530 Subject: [PATCH 05/23] Removed unwanted spaces. --- src/liberty/devCommands.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index ef082764..a4724178 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -503,9 +503,9 @@ export async function openReport(reportType: string, libProject?: LibertyProject ); panel.webview.html = getReport(report); // display HTML content } else { - const message = localize("test.report.does.not.exist.run.test.first", report); - vscode.window.showInformationMessage(message); - } + const message = localize("test.report.does.not.exist.run.test.first", report); + vscode.window.showInformationMessage(message); + } }); } } else if (ProjectProvider.getInstance() && reportType) { @@ -571,7 +571,7 @@ async function getLocalMavenWrapper(projectFolder: string): Promise Date: Mon, 28 Oct 2024 12:32:51 +0530 Subject: [PATCH 06/23] Code changes added for maven executable path and fix for demo suggestions --- src/liberty/devCommands.ts | 6 -- src/util/commandUtils.ts | 115 ++++++++++++++++++++++--------------- 2 files changed, 70 insertions(+), 51 deletions(-) diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index a4724178..efedb1d9 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -530,12 +530,6 @@ export function deleteTerminal(terminal: vscode.Terminal): void { // return Maven executable path, Maven wrapper, or mvn export async function mvnCmd(pomPath: string): Promise { - - // 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("executable.path"); - if (mavenExecutablePath) { - return mavenExecutablePath; - } const preferMavenWrapper: boolean | undefined = vscode.workspace.getConfiguration("maven").get("executable.preferMavenWrapper"); if (preferMavenWrapper) { const localMvnwPath: string | undefined = await getLocalMavenWrapper(Path.dirname(pomPath)); diff --git a/src/util/commandUtils.ts b/src/util/commandUtils.ts index 2bf02775..d001be5a 100644 --- a/src/util/commandUtils.ts +++ b/src/util/commandUtils.ts @@ -56,8 +56,21 @@ function currentWindowsShell(): ShellType { /** * Return the maven commands based on the OS and Terminal for start, startinContainer, start.. */ + export async function getCommandForMaven(pomPath: string,command:string,customCommand?: string) : Promise { + // 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("executable.path"); + + if (mavenExecutablePath) { + + if(customCommand) + { + return `${mavenExecutablePath} ` + `${command}`+` ${customCommand}` + ` -f "${pomPath}"`; + } + return `${mavenExecutablePath} ` + `${command}`+ ` -f "${pomPath}"`; + } + let mvnCmdStart = await mvnCmd(pomPath); if(mvnCmdStart === "mvn"){ @@ -67,18 +80,19 @@ function currentWindowsShell(): ShellType { } return `${mvnCmdStart} ` + `${command}`+ ` -f "${pomPath}"`; } + //checking the OS type for command customization if (isWin()) { switch (currentWindowsShell()) { case ShellType.GIT_BASH: if(customCommand){ - return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` ${customCommand}` +` -f "${pomPath}"`; //Bash + return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` ${customCommand}`; //Bash } - return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` -f "${pomPath}"`; //Bash for start.. + return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`; //Bash for start.. case ShellType.POWERSHELL: { mvnCmdStart = Path.join(mvnCmdStart, "mvnw.cmd"); if(customCommand){ - + return "& \""+ mvnCmdStart +"\" " + `${command}`+` ${customCommand}` +` -f "${pomPath}"`; //Poweshell for start.. } return "& \""+ mvnCmdStart +"\" " + `${command}`+ ` -f "${pomPath}"`; // PowerShell @@ -86,17 +100,16 @@ function currentWindowsShell(): ShellType { case ShellType.CMD: mvnCmdStart = Path.join(mvnCmdStart, "mvnw.cmd"); if(customCommand){ - - return "\""+ mvnCmdStart +"\" " + `${command}`+` ${customCommand}` + ` -f "${pomPath}"`; //cmd for start.. + return "\""+ mvnCmdStart +"\" " + `${command}`+` ${customCommand}` + ` -f "${pomPath}"`; //cmd for start.. } return "\""+ mvnCmdStart +"\" " + `${command}`+ ` -f "${pomPath}"`; // CMD case ShellType.WSL: mvnCmdStart = toDefaultWslPath(mvnCmdStart); pomPath = toDefaultWslPath(pomPath); if(customCommand){ - return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` ${customCommand}` +` -f "${pomPath}"`; //Wsl start .. + return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` ${customCommand}`; //Wsl start .. } - return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` -f "${pomPath}"`; //Wsl + return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`; //Wsl default: @@ -108,16 +121,17 @@ function currentWindowsShell(): ShellType { } } else { if(customCommand){ - return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+` ${customCommand}` + ` -f "${pomPath}"`; + return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+` ${customCommand}`; } - return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` -f "${pomPath}"`; + return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`; } - + } /** * Return the Gradle commands based on the OS and Terminal for start, startinContainer, start.. */ + export async function getCommandForGradle(buildGradlePath: string, command: string, customCommand?: string) : Promise { let gradleCmdStart = await gradleCmd(buildGradlePath); @@ -128,42 +142,9 @@ export async function getCommandForGradle(buildGradlePath: string, command: stri } return `${gradleCmdStart} ` + `${command}`+ ` -b="${buildGradlePath}"`; } + //checking the OS type for command customization if (isWin()) { - switch (currentWindowsShell()) { - case ShellType.GIT_BASH: - gradleCmdStart = Path.join(gradleCmdStart, "gradlew"); - if(customCommand){ - return "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; //bash start.. - } - return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; //Bash - case ShellType.POWERSHELL: { - gradleCmdStart = Path.join(gradleCmdStart, "gradlew.bat"); - if(customCommand){ - return "& \""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`;// PowerShell strat.. - } - return "& \""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`;// PowerShell - } - case ShellType.CMD: - gradleCmdStart = Path.join(gradleCmdStart, "gradlew.bat"); - if(customCommand){ - return "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; // CMD start.. - } - return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; // CMD - case ShellType.WSL: - buildGradlePath = toDefaultWslPath(buildGradlePath); - gradleCmdStart = toDefaultWslPath(gradleCmdStart) - gradleCmdStart = Path.join(gradleCmdStart, "gradlew"); - if(customCommand){ - return "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; //wsl start.. - } - return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; //wsl - default: - gradleCmdStart = Path.join(gradleCmdStart, "gradlew.bat"); - if(customCommand){ - "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; - } - return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; - } + return getGradleCommandsForWin(gradleCmdStart, buildGradlePath, command, customCommand); } else { gradleCmdStart = Path.join(gradleCmdStart, "gradlew"); if(customCommand){ @@ -173,10 +154,12 @@ export async function getCommandForGradle(buildGradlePath: string, command: stri } } + /** * Reused from vscode-maven * https://github.com/microsoft/vscode-maven/blob/main/src/mavenTerminal.ts */ + function toDefaultWslPath(p: string): string { const arr: string[] = p.split(":\\"); if (arr.length === 2) { @@ -188,3 +171,45 @@ function toDefaultWslPath(p: string): string { } } +/** + * Return the Gradle commands for windows OS based on the terminal configured + */ + +function getGradleCommandsForWin(gradleCmdStart : string, buildGradlePath : string, command : string, customCommand?: string): string { + switch (currentWindowsShell()) { + case ShellType.GIT_BASH: + gradleCmdStart = Path.join(gradleCmdStart, "gradlew"); + if(customCommand){ + return "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; //bash start.. + } + return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; //Bash + case ShellType.POWERSHELL: { + gradleCmdStart = Path.join(gradleCmdStart, "gradlew.bat"); + if(customCommand){ + return "& \""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`;// PowerShell strat.. + } + return "& \""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`;// PowerShell + } + case ShellType.CMD: + gradleCmdStart = Path.join(gradleCmdStart, "gradlew.bat"); + if(customCommand){ + return "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; // CMD start.. + } + return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; // CMD + case ShellType.WSL: + buildGradlePath = toDefaultWslPath(buildGradlePath); + gradleCmdStart = toDefaultWslPath(gradleCmdStart) + gradleCmdStart = Path.join(gradleCmdStart, "gradlew"); + if(customCommand){ + return "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; //wsl start.. + } + return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; //wsl + default: + gradleCmdStart = Path.join(gradleCmdStart, "gradlew.bat"); + if(customCommand){ + "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; + } + return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; + } +} + From ffb2fff7fa0c9520fb1c5a73ad9a145b84b57134 Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Tue, 5 Nov 2024 14:57:17 +0530 Subject: [PATCH 07/23] Changes after review comment incorporation --- src/liberty/devCommands.ts | 74 +------------- src/util/commandUtils.ts | 195 ++++++++++++++++++++++++------------- 2 files changed, 131 insertions(+), 138 deletions(-) diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index efedb1d9..d07048c6 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -18,7 +18,6 @@ import { LibertyProject, ProjectProvider } from "./libertyProject"; import { getReport, filterProjects } from "../util/helperUtil"; import { COMMAND_TITLES, LIBERTY_MAVEN_PROJECT, LIBERTY_GRADLE_PROJECT, LIBERTY_MAVEN_PROJECT_CONTAINER, LIBERTY_GRADLE_PROJECT_CONTAINER, LIBERTY_SERVER_ENV_PORT_REGEX } from "../definitions/constants"; import { getGradleTestReport } from "../util/gradleUtil"; -import { pathExists } from "fs-extra"; import { DashboardData } from "./dashboard"; import { ProjectStartCmdParam } from "./projectStartCmdParam"; import { getCommandForMaven, getCommandForGradle } from "../util/commandUtils"; @@ -525,75 +524,4 @@ export function deleteTerminal(terminal: vscode.Terminal): void { } catch { console.error(localize("unable.to.delete.terminal", terminal.name)); } -} - - -// return Maven executable path, Maven wrapper, or mvn -export async function mvnCmd(pomPath: string): Promise { - const preferMavenWrapper: boolean | undefined = vscode.workspace.getConfiguration("maven").get("executable.preferMavenWrapper"); - if (preferMavenWrapper) { - const localMvnwPath: string | undefined = await getLocalMavenWrapper(Path.dirname(pomPath)); - if (localMvnwPath) { - return `${localMvnwPath}`; - } - } - return "mvn"; -} - -export async function gradleCmd(buildGradle: string): Promise { - const preferGradleWrapper: boolean | undefined = vscode.workspace.getConfiguration("java").get("import.gradle.wrapper.enabled"); - if (preferGradleWrapper) { - const localGradlewPath: string | undefined = await getLocalGradleWrapper(Path.dirname(buildGradle)); - if (localGradlewPath) { - return `${localGradlewPath}`; - } - } - return "gradle"; -} - -/** - * Search for potential Maven wrapper, return undefined if does not exist - * - * Reused from vscode-maven - * https://github.com/microsoft/vscode-maven/blob/2ab8f392f418c8e0fe2903387f2b0013a1c50e78/src/utils/mavenUtils.ts - * @param projectFolder - */ -async function getLocalMavenWrapper(projectFolder: string): Promise { - - let current: string = projectFolder; - while (Path.basename(current)) { - const potentialMvnwPath: string = Path.join(current); - - if (await pathExists(potentialMvnwPath)) { - return potentialMvnwPath; - } - current = Path.dirname(current); - } - return undefined; -} - -/** - * Search for potential Gradle wrapper, return undefined if it does not exist - * Modified from vscode-maven, see getLocalMavenWrapper method above - * @param projectFolder - */ -async function getLocalGradleWrapper(projectFolder: string): Promise { - - let current: string = projectFolder; - while (Path.basename(current)) { - const potentialGradlewPath: string = Path.join(current); - if (await pathExists(potentialGradlewPath)) { - return potentialGradlewPath; - } - current = Path.dirname(current); - } - return undefined; -} - -/** - * Reused from vscode-maven - * https://github.com/microsoft/vscode-maven/blob/2ab8f392f418c8e0fe2903387f2b0013a1c50e78/src/utils/mavenUtils.ts - */ -export function isWin(): boolean { - return process.platform.startsWith("win"); -} +} \ No newline at end of file diff --git a/src/util/commandUtils.ts b/src/util/commandUtils.ts index d001be5a..49703a7d 100644 --- a/src/util/commandUtils.ts +++ b/src/util/commandUtils.ts @@ -10,7 +10,7 @@ import * as Path from "path"; import * as vscode from "vscode"; -import { isWin,mvnCmd,gradleCmd } from "../liberty/devCommands"; +import { pathExists } from "fs-extra"; /** * Reused from vscode-maven @@ -36,7 +36,7 @@ function currentWindowsShell(): ShellType { case "pwsh.exe": case "powershell.exe": case "pwsh": // pwsh on mac/linux - return ShellType.POWERSHELL; + return ShellType.POWERSHELL; case "bash.exe": case 'git-cmd.exe': return ShellType.GIT_BASH; @@ -57,100 +57,97 @@ function currentWindowsShell(): ShellType { * Return the maven commands based on the OS and Terminal for start, startinContainer, start.. */ - export async function getCommandForMaven(pomPath: string,command:string,customCommand?: string) : Promise { +export async function getCommandForMaven(pomPath: string, command: string, customCommand?: string): Promise { // 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("executable.path"); - + if (mavenExecutablePath) { - if(customCommand) - { - return `${mavenExecutablePath} ` + `${command}`+` ${customCommand}` + ` -f "${pomPath}"`; - } - return `${mavenExecutablePath} ` + `${command}`+ ` -f "${pomPath}"`; + if (customCommand) { + return `${mavenExecutablePath} ` + `${command}` + ` ${customCommand}` + ` -f "${pomPath}"`; + } + return `${mavenExecutablePath} ` + `${command}` + ` -f "${pomPath}"`; } - let mvnCmdStart = await mvnCmd(pomPath); - - if(mvnCmdStart === "mvn"){ - if(customCommand) - { - return `${mvnCmdStart} ` + `${command}`+` ${customCommand}` + ` -f "${pomPath}"`; + let mvnCmdStart = await mvnCmd(pomPath); + + if (mvnCmdStart === "mvn") { + if (customCommand) { + return `${mvnCmdStart} ` + `${command}` + ` ${customCommand}` + ` -f "${pomPath}"`; } - return `${mvnCmdStart} ` + `${command}`+ ` -f "${pomPath}"`; + return `${mvnCmdStart} ` + `${command}` + ` -f "${pomPath}"`; } - //checking the OS type for command customization + //checking the OS type for command customization if (isWin()) { switch (currentWindowsShell()) { case ShellType.GIT_BASH: - if(customCommand){ - return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` ${customCommand}`; //Bash + if (customCommand) { + return "cd \"" + mvnCmdStart + "\" && " + "./mvnw " + `${command}` + ` ${customCommand}`; //Bash } - return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`; //Bash for start.. - + return "cd \"" + mvnCmdStart + "\" && " + "./mvnw " + `${command}`; //Bash for start.. + case ShellType.POWERSHELL: { mvnCmdStart = Path.join(mvnCmdStart, "mvnw.cmd"); - if(customCommand){ - - return "& \""+ mvnCmdStart +"\" " + `${command}`+` ${customCommand}` +` -f "${pomPath}"`; //Poweshell for start.. + if (customCommand) { + + return "& \"" + mvnCmdStart + "\" " + `${command}` + ` ${customCommand}` + ` -f "${pomPath}"`; //Poweshell for start.. } - return "& \""+ mvnCmdStart +"\" " + `${command}`+ ` -f "${pomPath}"`; // PowerShell + return "& \"" + mvnCmdStart + "\" " + `${command}` + ` -f "${pomPath}"`; // PowerShell } case ShellType.CMD: mvnCmdStart = Path.join(mvnCmdStart, "mvnw.cmd"); - if(customCommand){ - return "\""+ mvnCmdStart +"\" " + `${command}`+` ${customCommand}` + ` -f "${pomPath}"`; //cmd for start.. + if (customCommand) { + return "\"" + mvnCmdStart + "\" " + `${command}` + ` ${customCommand}` + ` -f "${pomPath}"`; //cmd for start.. } - return "\""+ mvnCmdStart +"\" " + `${command}`+ ` -f "${pomPath}"`; // CMD + return "\"" + mvnCmdStart + "\" " + `${command}` + ` -f "${pomPath}"`; // CMD case ShellType.WSL: mvnCmdStart = toDefaultWslPath(mvnCmdStart); pomPath = toDefaultWslPath(pomPath); - if(customCommand){ - return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+ ` ${customCommand}`; //Wsl start .. + if (customCommand) { + return "cd \"" + mvnCmdStart + "\" && " + "./mvnw " + `${command}` + ` ${customCommand}`; //Wsl start .. } - return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`; //Wsl - - + return "cd \"" + mvnCmdStart + "\" && " + "./mvnw " + `${command}`; //Wsl + + default: mvnCmdStart = Path.join(mvnCmdStart, "mvnw.cmd"); - if(customCommand){ - return "\""+ mvnCmdStart +"\" " + `${command}`+` ${customCommand}` + ` -f "${pomPath}"`; + if (customCommand) { + return "\"" + mvnCmdStart + "\" " + `${command}` + ` ${customCommand}` + ` -f "${pomPath}"`; } - return "\""+ mvnCmdStart +"\" " + `${command}`+ ` -f "${pomPath}"`; + return "\"" + mvnCmdStart + "\" " + `${command}` + ` -f "${pomPath}"`; } } else { - if(customCommand){ - return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`+` ${customCommand}`; + if (customCommand) { + return "cd \"" + mvnCmdStart + "\" && " + "./mvnw " + `${command}` + ` ${customCommand}`; } - return "cd \""+ mvnCmdStart +"\" && "+"./mvnw "+`${command}`; + return "cd \"" + mvnCmdStart + "\" && " + "./mvnw " + `${command}`; } - + } /** * Return the Gradle commands based on the OS and Terminal for start, startinContainer, start.. */ -export async function getCommandForGradle(buildGradlePath: string, command: string, customCommand?: string) : Promise { +export async function getCommandForGradle(buildGradlePath: string, command: string, customCommand?: string): Promise { let gradleCmdStart = await gradleCmd(buildGradlePath); - if(gradleCmdStart === "gradle"){ - if(customCommand) - { - return `${gradleCmdStart} ` + `${command}`+` ${customCommand}` + ` -b="${buildGradlePath}"`; + if (gradleCmdStart === "gradle") { + if (customCommand) { + return `${gradleCmdStart} ` + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; } - return `${gradleCmdStart} ` + `${command}`+ ` -b="${buildGradlePath}"`; + return `${gradleCmdStart} ` + `${command}` + ` -b="${buildGradlePath}"`; } //checking the OS type for command customization if (isWin()) { return getGradleCommandsForWin(gradleCmdStart, buildGradlePath, command, customCommand); } else { gradleCmdStart = Path.join(gradleCmdStart, "gradlew"); - if(customCommand){ - return "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; + if (customCommand) { + return "\"" + gradleCmdStart + "\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; } - return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; + return "\"" + gradleCmdStart + "\" " + `${command}` + ` -b="${buildGradlePath}"`; } } @@ -175,41 +172,109 @@ function toDefaultWslPath(p: string): string { * Return the Gradle commands for windows OS based on the terminal configured */ -function getGradleCommandsForWin(gradleCmdStart : string, buildGradlePath : string, command : string, customCommand?: string): string { +function getGradleCommandsForWin(gradleCmdStart: string, buildGradlePath: string, command: string, customCommand?: string): string { switch (currentWindowsShell()) { case ShellType.GIT_BASH: gradleCmdStart = Path.join(gradleCmdStart, "gradlew"); - if(customCommand){ - return "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; //bash start.. + if (customCommand) { + return "\"" + gradleCmdStart + "\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; //bash start.. } - return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; //Bash + return "\"" + gradleCmdStart + "\" " + `${command}` + ` -b="${buildGradlePath}"`; //Bash case ShellType.POWERSHELL: { gradleCmdStart = Path.join(gradleCmdStart, "gradlew.bat"); - if(customCommand){ - return "& \""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`;// PowerShell strat.. + if (customCommand) { + return "& \"" + gradleCmdStart + "\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`;// PowerShell strat.. } - return "& \""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`;// PowerShell + return "& \"" + gradleCmdStart + "\" " + `${command}` + ` -b="${buildGradlePath}"`;// PowerShell } case ShellType.CMD: gradleCmdStart = Path.join(gradleCmdStart, "gradlew.bat"); - if(customCommand){ - return "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; // CMD start.. + if (customCommand) { + return "\"" + gradleCmdStart + "\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; // CMD start.. } - return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; // CMD + return "\"" + gradleCmdStart + "\" " + `${command}` + ` -b="${buildGradlePath}"`; // CMD case ShellType.WSL: buildGradlePath = toDefaultWslPath(buildGradlePath); gradleCmdStart = toDefaultWslPath(gradleCmdStart) gradleCmdStart = Path.join(gradleCmdStart, "gradlew"); - if(customCommand){ - return "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; //wsl start.. + if (customCommand) { + return "\"" + gradleCmdStart + "\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; //wsl start.. } - return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; //wsl + return "\"" + gradleCmdStart + "\" " + `${command}` + ` -b="${buildGradlePath}"`; //wsl default: gradleCmdStart = Path.join(gradleCmdStart, "gradlew.bat"); - if(customCommand){ - "\""+ gradleCmdStart +"\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; + if (customCommand) { + "\"" + gradleCmdStart + "\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; } - return "\""+ gradleCmdStart +"\" " + `${command}` + ` -b="${buildGradlePath}"`; + return "\"" + gradleCmdStart + "\" " + `${command}` + ` -b="${buildGradlePath}"`; + } +} +/** + * Reused from vscode-maven + * https://github.com/microsoft/vscode-maven/blob/2ab8f392f418c8e0fe2903387f2b0013a1c50e78/src/utils/mavenUtils.ts + */ +export function isWin(): boolean { + return process.platform.startsWith("win"); +} + + +// return Maven executable path, Maven wrapper, or mvn +export async function mvnCmd(pomPath: string): Promise { + const preferMavenWrapper: boolean | undefined = vscode.workspace.getConfiguration("maven").get("executable.preferMavenWrapper"); + if (preferMavenWrapper) { + const localMvnwPath: string | undefined = await getLocalMavenWrapper(Path.dirname(pomPath)); + if (localMvnwPath) { + return `${localMvnwPath}`; + } } + return "mvn"; } +export async function gradleCmd(buildGradle: string): Promise { + const preferGradleWrapper: boolean | undefined = vscode.workspace.getConfiguration("java").get("import.gradle.wrapper.enabled"); + if (preferGradleWrapper) { + const localGradlewPath: string | undefined = await getLocalGradleWrapper(Path.dirname(buildGradle)); + if (localGradlewPath) { + return `${localGradlewPath}`; + } + } + return "gradle"; +} +/** + * Search for potential Maven wrapper, return undefined if does not exist + * Reused from vscode-maven + * https://github.com/microsoft/vscode-maven/blob/2ab8f392f418c8e0fe2903387f2b0013a1c50e78/src/utils/mavenUtils.ts + * @param projectFolder + */ +export async function getLocalMavenWrapper(projectFolder: string): Promise { + + let current: string = projectFolder; + while (Path.basename(current)) { + const potentialMvnwPath: string = Path.join(current); + + if (await pathExists(potentialMvnwPath)) { + return potentialMvnwPath; + } + current = Path.dirname(current); + } + return undefined; +} +/** + * Search for potential Gradle wrapper, return undefined if it does not exist + * Modified from vscode-maven, see getLocalMavenWrapper method above + * @param projectFolder + */ +export async function getLocalGradleWrapper(projectFolder: string): Promise { + + let current: string = projectFolder; + while (Path.basename(current)) { + const potentialGradlewPath: string = Path.join(current); + if (await pathExists(potentialGradlewPath)) { + return potentialGradlewPath; + } + current = Path.dirname(current); + } + return undefined; +} + + From 9f3c36cc76247f2fb4c9d9e2e41f15577598b70e Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Tue, 5 Nov 2024 15:22:09 +0530 Subject: [PATCH 08/23] Removed export keyword --- src/util/commandUtils.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/util/commandUtils.ts b/src/util/commandUtils.ts index 49703a7d..1148361a 100644 --- a/src/util/commandUtils.ts +++ b/src/util/commandUtils.ts @@ -213,13 +213,13 @@ function getGradleCommandsForWin(gradleCmdStart: string, buildGradlePath: string * Reused from vscode-maven * https://github.com/microsoft/vscode-maven/blob/2ab8f392f418c8e0fe2903387f2b0013a1c50e78/src/utils/mavenUtils.ts */ -export function isWin(): boolean { +function isWin(): boolean { return process.platform.startsWith("win"); } // return Maven executable path, Maven wrapper, or mvn -export async function mvnCmd(pomPath: string): Promise { +async function mvnCmd(pomPath: string): Promise { const preferMavenWrapper: boolean | undefined = vscode.workspace.getConfiguration("maven").get("executable.preferMavenWrapper"); if (preferMavenWrapper) { const localMvnwPath: string | undefined = await getLocalMavenWrapper(Path.dirname(pomPath)); @@ -230,7 +230,7 @@ export async function mvnCmd(pomPath: string): Promise { return "mvn"; } -export async function gradleCmd(buildGradle: string): Promise { +async function gradleCmd(buildGradle: string): Promise { const preferGradleWrapper: boolean | undefined = vscode.workspace.getConfiguration("java").get("import.gradle.wrapper.enabled"); if (preferGradleWrapper) { const localGradlewPath: string | undefined = await getLocalGradleWrapper(Path.dirname(buildGradle)); @@ -246,7 +246,7 @@ export async function gradleCmd(buildGradle: string): Promise { * https://github.com/microsoft/vscode-maven/blob/2ab8f392f418c8e0fe2903387f2b0013a1c50e78/src/utils/mavenUtils.ts * @param projectFolder */ -export async function getLocalMavenWrapper(projectFolder: string): Promise { +async function getLocalMavenWrapper(projectFolder: string): Promise { let current: string = projectFolder; while (Path.basename(current)) { @@ -264,7 +264,7 @@ export async function getLocalMavenWrapper(projectFolder: string): Promise { +async function getLocalGradleWrapper(projectFolder: string): Promise { let current: string = projectFolder; while (Path.basename(current)) { From 955e735a29ab587e75a17b57116a781812e511d8 Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Mon, 11 Nov 2024 12:04:41 +0530 Subject: [PATCH 09/23] code changes for switch default terminal --- src/liberty/devCommands.ts | 53 +++++++++++++++++++++++++++++------ src/liberty/libertyProject.ts | 8 ++++++ src/util/commandUtils.ts | 45 ++++++----------------------- 3 files changed, 61 insertions(+), 45 deletions(-) diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index d07048c6..98a551d3 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -20,7 +20,7 @@ import { COMMAND_TITLES, LIBERTY_MAVEN_PROJECT, LIBERTY_GRADLE_PROJECT, LIBERTY_ import { getGradleTestReport } from "../util/gradleUtil"; import { DashboardData } from "./dashboard"; import { ProjectStartCmdParam } from "./projectStartCmdParam"; -import { getCommandForMaven, getCommandForGradle } from "../util/commandUtils"; +import { getCommandForMaven, getCommandForGradle,ShellType } from "../util/commandUtils"; export const terminals: { [libProjectId: number]: LibertyProject } = {}; @@ -100,6 +100,8 @@ export async function startDevMode(libProject?: LibertyProject | undefined): Pro let terminal = libProject.getTerminal(); if (terminal === undefined) { const path = Path.dirname(libProject.getPath()); + const terminalType = currentWindowsShell(); + libProject.setTerminalType(terminalType); terminal = libProject.createTerminal(path); if (terminal !== undefined) { terminals[Number(terminal.processId)] = libProject; @@ -109,10 +111,10 @@ export async function startDevMode(libProject?: LibertyProject | undefined): Pro terminal.show(); libProject.setTerminal(terminal); if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT || libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) { - const cmd = await getCommandForMaven(libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:dev"); + const cmd = await getCommandForMaven(libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:dev", libProject.getTerminalType()); terminal.sendText(cmd); // start dev mode on current project } else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT || libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) { - const cmd = await getCommandForGradle(libProject.getPath(),"libertyDev"); + const cmd = await getCommandForGradle(libProject.getPath(),"libertyDev", libProject.getTerminalType()); terminal.sendText(cmd); // start dev mode on current project } } @@ -357,6 +359,8 @@ export async function customDevMode(libProject?: LibertyProject | undefined, par let terminal = libProject.getTerminal(); if (terminal === undefined) { const path = Path.dirname(libProject.getPath()); + const terminalType = currentWindowsShell(); + libProject.setTerminalType(terminalType); terminal = libProject.createTerminal(path); if (terminal !== undefined) { terminals[Number(terminal.processId)] = libProject; @@ -406,10 +410,10 @@ export async function customDevMode(libProject?: LibertyProject | undefined, par } if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT || libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) { - const cmd = await getCommandForMaven(libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:dev",customCommand); + const cmd = await getCommandForMaven(libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:dev", libProject.getTerminalType(), customCommand); terminal.sendText(cmd); } else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT || libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) { - const cmd = await getCommandForGradle(libProject.getPath(),"libertyDev",customCommand); + const cmd = await getCommandForGradle(libProject.getPath(),"libertyDev", libProject.getTerminalType(), customCommand); terminal.sendText(cmd); } } @@ -430,6 +434,8 @@ export async function startContainerDevMode(libProject?: LibertyProject | undefi let terminal = libProject.getTerminal(); if (terminal === undefined) { const path = Path.dirname(libProject.getPath()); + const terminalType = currentWindowsShell(); + libProject.setTerminalType(terminalType); terminal = libProject.createTerminal(path); if (terminal !== undefined) { terminals[Number(terminal.processId)] = libProject; @@ -439,10 +445,10 @@ export async function startContainerDevMode(libProject?: LibertyProject | undefi terminal.show(); libProject.setTerminal(terminal); if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) { - const cmd = await getCommandForMaven(libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:devc"); + const cmd = await getCommandForMaven(libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:devc", libProject.getTerminalType()); terminal.sendText(cmd); } else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) { - const cmd = await getCommandForGradle(libProject.getPath(),"libertyDevc"); + const cmd = await getCommandForGradle(libProject.getPath(),"libertyDevc", libProject.getTerminalType()); terminal.sendText(cmd); } } @@ -524,4 +530,35 @@ export function deleteTerminal(terminal: vscode.Terminal): void { } catch { console.error(localize("unable.to.delete.terminal", terminal.name)); } -} \ No newline at end of file +} + +/** + * Reused from vscode-maven + * https://github.com/microsoft/vscode-maven/blob/main/src/mavenTerminal.ts + */ + +function currentWindowsShell(): ShellType { + const currentWindowsShellPath: string = vscode.env.shell; + const executable: string = Path.basename(currentWindowsShellPath); + switch (executable.toLowerCase()) { + case "cmd.exe": + return ShellType.CMD; + case "pwsh.exe": + case "powershell.exe": + case "pwsh": // pwsh on mac/linux + return ShellType.POWERSHELL; + case "bash.exe": + case 'git-cmd.exe': + return ShellType.GIT_BASH; + case 'wsl.exe': + case 'ubuntu.exe': + case 'ubuntu1804.exe': + case 'kali.exe': + case 'debian.exe': + case 'opensuse-42.exe': + case 'sles-12.exe': + return ShellType.WSL; + default: + return ShellType.OTHERS; + } +} diff --git a/src/liberty/libertyProject.ts b/src/liberty/libertyProject.ts index 8c860c09..a949eb46 100644 --- a/src/liberty/libertyProject.ts +++ b/src/liberty/libertyProject.ts @@ -442,6 +442,7 @@ export class LibertyProject extends vscode.TreeItem { public contextValue: string, public terminal?: vscode.Terminal, public readonly command?: vscode.Command, // ? indicates optional param + public terminalType?: string, ) { super(label, collapsibleState); this.tooltip = this.path; @@ -488,6 +489,13 @@ export class LibertyProject extends vscode.TreeItem { public setTerminal(terminal: vscode.Terminal): void { this.terminal = terminal; } + public getTerminalType(): string | undefined { + return this.terminalType; + } + + public setTerminalType(terminalType: string): void { + this.terminalType = terminalType; + } public createTerminal(projectHome: string): vscode.Terminal | undefined { if (this.terminal === undefined) { diff --git a/src/util/commandUtils.ts b/src/util/commandUtils.ts index 1148361a..0c9290fe 100644 --- a/src/util/commandUtils.ts +++ b/src/util/commandUtils.ts @@ -16,48 +16,19 @@ import { pathExists } from "fs-extra"; * Reused from vscode-maven * https://github.com/microsoft/vscode-maven/blob/main/src/mavenTerminal.ts */ -enum ShellType { +export enum ShellType { CMD = "Command Prompt", POWERSHELL = "PowerShell", GIT_BASH = "Git Bash", WSL = "WSL Bash", OTHERS = "Others" } -/** - * Reused from vscode-maven - * https://github.com/microsoft/vscode-maven/blob/main/src/mavenTerminal.ts - */ -function currentWindowsShell(): ShellType { - const currentWindowsShellPath: string = vscode.env.shell; - const executable: string = Path.basename(currentWindowsShellPath); - switch (executable.toLowerCase()) { - case "cmd.exe": - return ShellType.CMD; - case "pwsh.exe": - case "powershell.exe": - case "pwsh": // pwsh on mac/linux - return ShellType.POWERSHELL; - case "bash.exe": - case 'git-cmd.exe': - return ShellType.GIT_BASH; - case 'wsl.exe': - case 'ubuntu.exe': - case 'ubuntu1804.exe': - case 'kali.exe': - case 'debian.exe': - case 'opensuse-42.exe': - case 'sles-12.exe': - return ShellType.WSL; - default: - return ShellType.OTHERS; - } -} /** * Return the maven commands based on the OS and Terminal for start, startinContainer, start.. */ -export async function getCommandForMaven(pomPath: string, command: string, customCommand?: string): Promise { +export async function getCommandForMaven(pomPath: string, command: string, terminalType?: string, customCommand?: string): Promise { // 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("executable.path"); @@ -80,7 +51,7 @@ export async function getCommandForMaven(pomPath: string, command: string, custo } //checking the OS type for command customization if (isWin()) { - switch (currentWindowsShell()) { + switch (terminalType) { case ShellType.GIT_BASH: if (customCommand) { return "cd \"" + mvnCmdStart + "\" && " + "./mvnw " + `${command}` + ` ${customCommand}`; //Bash @@ -130,7 +101,7 @@ export async function getCommandForMaven(pomPath: string, command: string, custo * Return the Gradle commands based on the OS and Terminal for start, startinContainer, start.. */ -export async function getCommandForGradle(buildGradlePath: string, command: string, customCommand?: string): Promise { +export async function getCommandForGradle(buildGradlePath: string, command: string, terminalType?: String, customCommand?: string): Promise { let gradleCmdStart = await gradleCmd(buildGradlePath); if (gradleCmdStart === "gradle") { @@ -141,7 +112,7 @@ export async function getCommandForGradle(buildGradlePath: string, command: stri } //checking the OS type for command customization if (isWin()) { - return getGradleCommandsForWin(gradleCmdStart, buildGradlePath, command, customCommand); + return getGradleCommandsForWin(gradleCmdStart, buildGradlePath, command, terminalType, customCommand); } else { gradleCmdStart = Path.join(gradleCmdStart, "gradlew"); if (customCommand) { @@ -172,8 +143,8 @@ function toDefaultWslPath(p: string): string { * Return the Gradle commands for windows OS based on the terminal configured */ -function getGradleCommandsForWin(gradleCmdStart: string, buildGradlePath: string, command: string, customCommand?: string): string { - switch (currentWindowsShell()) { +function getGradleCommandsForWin(gradleCmdStart: string, buildGradlePath: string, command: string, terminalType?: String, customCommand?: string): string { + switch (terminalType) { case ShellType.GIT_BASH: gradleCmdStart = Path.join(gradleCmdStart, "gradlew"); if (customCommand) { @@ -213,7 +184,7 @@ function getGradleCommandsForWin(gradleCmdStart: string, buildGradlePath: string * Reused from vscode-maven * https://github.com/microsoft/vscode-maven/blob/2ab8f392f418c8e0fe2903387f2b0013a1c50e78/src/utils/mavenUtils.ts */ -function isWin(): boolean { +export function isWin(): boolean { return process.platform.startsWith("win"); } From 1f768f31329b33d6ef28ca99eb651571ff7d0790 Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Mon, 11 Nov 2024 12:22:43 +0530 Subject: [PATCH 10/23] Changed method - currentWindowsShell --- src/liberty/devCommands.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index 98a551d3..55c2091a 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -92,7 +92,6 @@ export async function listAllCommands(): Promise { }); } - // start dev mode export async function startDevMode(libProject?: LibertyProject | undefined): Promise { if (libProject !== undefined) { @@ -100,7 +99,8 @@ export async function startDevMode(libProject?: LibertyProject | undefined): Pro let terminal = libProject.getTerminal(); if (terminal === undefined) { const path = Path.dirname(libProject.getPath()); - const terminalType = currentWindowsShell(); + //fetch the default terminal details and store it in LibertyProject object + const terminalType = defaultWindowsShell(); libProject.setTerminalType(terminalType); terminal = libProject.createTerminal(path); if (terminal !== undefined) { @@ -359,7 +359,8 @@ export async function customDevMode(libProject?: LibertyProject | undefined, par let terminal = libProject.getTerminal(); if (terminal === undefined) { const path = Path.dirname(libProject.getPath()); - const terminalType = currentWindowsShell(); + //fetch the default terminal details and store it in LibertyProject object + const terminalType = defaultWindowsShell(); libProject.setTerminalType(terminalType); terminal = libProject.createTerminal(path); if (terminal !== undefined) { @@ -434,7 +435,8 @@ export async function startContainerDevMode(libProject?: LibertyProject | undefi let terminal = libProject.getTerminal(); if (terminal === undefined) { const path = Path.dirname(libProject.getPath()); - const terminalType = currentWindowsShell(); + //fetch the default terminal details and store it in LibertyProject object + const terminalType = defaultWindowsShell(); libProject.setTerminalType(terminalType); terminal = libProject.createTerminal(path); if (terminal !== undefined) { @@ -533,13 +535,14 @@ export function deleteTerminal(terminal: vscode.Terminal): void { } /** - * Reused from vscode-maven + * Reused from vscode-maven - currentWindowsShell() * https://github.com/microsoft/vscode-maven/blob/main/src/mavenTerminal.ts + * method to fetch default terminal configured */ -function currentWindowsShell(): ShellType { - const currentWindowsShellPath: string = vscode.env.shell; - const executable: string = Path.basename(currentWindowsShellPath); +function defaultWindowsShell(): ShellType { + const defaultWindowsShellPath: string = vscode.env.shell; + const executable: string = Path.basename(defaultWindowsShellPath); switch (executable.toLowerCase()) { case "cmd.exe": return ShellType.CMD; From 3a04468c7d397521e34407fb6eae49baa61ff6cf Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Wed, 20 Nov 2024 12:24:10 +0530 Subject: [PATCH 11/23] Addressed review comments --- src/liberty/devCommands.ts | 74 +++------- src/liberty/libertyProject.ts | 2 +- src/util/commandUtils.ts | 252 +++++++++++++++++----------------- 3 files changed, 151 insertions(+), 177 deletions(-) diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index 55c2091a..538d7127 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -20,7 +20,7 @@ import { COMMAND_TITLES, LIBERTY_MAVEN_PROJECT, LIBERTY_GRADLE_PROJECT, LIBERTY_ import { getGradleTestReport } from "../util/gradleUtil"; import { DashboardData } from "./dashboard"; import { ProjectStartCmdParam } from "./projectStartCmdParam"; -import { getCommandForMaven, getCommandForGradle,ShellType } from "../util/commandUtils"; +import { getCommandForMaven, getCommandForGradle, defaultWindowsShell } from "../util/commandUtils"; export const terminals: { [libProjectId: number]: LibertyProject } = {}; @@ -77,18 +77,18 @@ export async function openProject(pomPath: string): Promise { export async function listAllCommands(): Promise { const libertyCommands = Array.from(COMMAND_TITLES.keys()); vscode.window.showQuickPick(libertyCommands).then(selection => { - if (!selection) { - return; - } - const command = COMMAND_TITLES.get(selection); + if (!selection) { + return; + } + const command = COMMAND_TITLES.get(selection); if ( command !== undefined ) { - vscode.commands.executeCommand(command); - } else { - // should never happen - console.error("Unable to find corresponding command for " + selection); - } - + vscode.commands.executeCommand(command); + } else { + // should never happen + console.error("Unable to find corresponding command for " + selection); + } + }); } @@ -111,10 +111,10 @@ export async function startDevMode(libProject?: LibertyProject | undefined): Pro terminal.show(); libProject.setTerminal(terminal); if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT || libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) { - const cmd = await getCommandForMaven(libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:dev", libProject.getTerminalType()); + const cmd = await getCommandForMaven(libProject.getPath(), "io.openliberty.tools:liberty-maven-plugin:dev", libProject.getTerminalType()); terminal.sendText(cmd); // start dev mode on current project } else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT || libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) { - const cmd = await getCommandForGradle(libProject.getPath(),"libertyDev", libProject.getTerminalType()); + const cmd = await getCommandForGradle(libProject.getPath(), "libertyDev", libProject.getTerminalType()); terminal.sendText(cmd); // start dev mode on current project } } @@ -130,7 +130,7 @@ export async function startDevMode(libProject?: LibertyProject | undefined): Pro export async function removeProject(): Promise { const projectProvider: ProjectProvider = ProjectProvider.getInstance(); - + // clicked on the empty space and workspace has more than one folders, or // from command palette // Display the list of current user added projects for user to select. @@ -163,7 +163,7 @@ export async function removeProject(): Promise { } }); }); - + } } @@ -197,7 +197,7 @@ export async function addProject(uri: vscode.Uri): Promise { // present the list to add showListOfPathsToAdd(uris); } - + } else { // clicked on the empty space and workspace has more than one folders, or @@ -411,10 +411,10 @@ export async function customDevMode(libProject?: LibertyProject | undefined, par } if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT || libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) { - const cmd = await getCommandForMaven(libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:dev", libProject.getTerminalType(), customCommand); + const cmd = await getCommandForMaven(libProject.getPath(), "io.openliberty.tools:liberty-maven-plugin:dev", libProject.getTerminalType(), customCommand); terminal.sendText(cmd); } else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT || libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) { - const cmd = await getCommandForGradle(libProject.getPath(),"libertyDev", libProject.getTerminalType(), customCommand); + const cmd = await getCommandForGradle(libProject.getPath(), "libertyDev", libProject.getTerminalType(), customCommand); terminal.sendText(cmd); } } @@ -447,10 +447,10 @@ export async function startContainerDevMode(libProject?: LibertyProject | undefi terminal.show(); libProject.setTerminal(terminal); if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) { - const cmd = await getCommandForMaven(libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:devc", libProject.getTerminalType()); + const cmd = await getCommandForMaven(libProject.getPath(), "io.openliberty.tools:liberty-maven-plugin:devc", libProject.getTerminalType()); terminal.sendText(cmd); } else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) { - const cmd = await getCommandForGradle(libProject.getPath(),"libertyDevc", libProject.getTerminalType()); + const cmd = await getCommandForGradle(libProject.getPath(), "libertyDevc", libProject.getTerminalType()); terminal.sendText(cmd); } } @@ -512,7 +512,7 @@ export async function openReport(reportType: string, libProject?: LibertyProject } else { const message = localize("test.report.does.not.exist.run.test.first", report); vscode.window.showInformationMessage(message); - } + } }); } } else if (ProjectProvider.getInstance() && reportType) { @@ -533,35 +533,3 @@ export function deleteTerminal(terminal: vscode.Terminal): void { console.error(localize("unable.to.delete.terminal", terminal.name)); } } - -/** - * Reused from vscode-maven - currentWindowsShell() - * https://github.com/microsoft/vscode-maven/blob/main/src/mavenTerminal.ts - * method to fetch default terminal configured - */ - -function defaultWindowsShell(): ShellType { - const defaultWindowsShellPath: string = vscode.env.shell; - const executable: string = Path.basename(defaultWindowsShellPath); - switch (executable.toLowerCase()) { - case "cmd.exe": - return ShellType.CMD; - case "pwsh.exe": - case "powershell.exe": - case "pwsh": // pwsh on mac/linux - return ShellType.POWERSHELL; - case "bash.exe": - case 'git-cmd.exe': - return ShellType.GIT_BASH; - case 'wsl.exe': - case 'ubuntu.exe': - case 'ubuntu1804.exe': - case 'kali.exe': - case 'debian.exe': - case 'opensuse-42.exe': - case 'sles-12.exe': - return ShellType.WSL; - default: - return ShellType.OTHERS; - } -} diff --git a/src/liberty/libertyProject.ts b/src/liberty/libertyProject.ts index a949eb46..8abae9ff 100644 --- a/src/liberty/libertyProject.ts +++ b/src/liberty/libertyProject.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2020, 2023 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 diff --git a/src/util/commandUtils.ts b/src/util/commandUtils.ts index 0c9290fe..9d8dccde 100644 --- a/src/util/commandUtils.ts +++ b/src/util/commandUtils.ts @@ -16,8 +16,7 @@ import { pathExists } from "fs-extra"; * Reused from vscode-maven * https://github.com/microsoft/vscode-maven/blob/main/src/mavenTerminal.ts */ -export enum ShellType { - CMD = "Command Prompt", +enum ShellType { POWERSHELL = "PowerShell", GIT_BASH = "Git Bash", WSL = "WSL Bash", @@ -25,109 +24,49 @@ export enum ShellType { } /** - * Return the maven commands based on the OS and Terminal for start, startinContainer, start.. + * Return the maven command based on the OS and Terminal for start, start in container, start.. */ - export async function getCommandForMaven(pomPath: string, command: string, terminalType?: string, customCommand?: string): Promise { // 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("executable.path"); - if (mavenExecutablePath) { - - if (customCommand) { - return `${mavenExecutablePath} ` + `${command}` + ` ${customCommand}` + ` -f "${pomPath}"`; - } - return `${mavenExecutablePath} ` + `${command}` + ` -f "${pomPath}"`; + return formDefaultCommand(mavenExecutablePath, pomPath, command, "-f ", customCommand); } - let mvnCmdStart = await mvnCmd(pomPath); - if (mvnCmdStart === "mvn") { - if (customCommand) { - return `${mvnCmdStart} ` + `${command}` + ` ${customCommand}` + ` -f "${pomPath}"`; - } - return `${mvnCmdStart} ` + `${command}` + ` -f "${pomPath}"`; + return formDefaultCommand(mvnCmdStart, pomPath, command, "-f ", customCommand); } //checking the OS type for command customization if (isWin()) { - switch (terminalType) { - case ShellType.GIT_BASH: - if (customCommand) { - return "cd \"" + mvnCmdStart + "\" && " + "./mvnw " + `${command}` + ` ${customCommand}`; //Bash - } - return "cd \"" + mvnCmdStart + "\" && " + "./mvnw " + `${command}`; //Bash for start.. - - case ShellType.POWERSHELL: { - mvnCmdStart = Path.join(mvnCmdStart, "mvnw.cmd"); - if (customCommand) { - - return "& \"" + mvnCmdStart + "\" " + `${command}` + ` ${customCommand}` + ` -f "${pomPath}"`; //Poweshell for start.. - } - return "& \"" + mvnCmdStart + "\" " + `${command}` + ` -f "${pomPath}"`; // PowerShell - } - case ShellType.CMD: - mvnCmdStart = Path.join(mvnCmdStart, "mvnw.cmd"); - if (customCommand) { - return "\"" + mvnCmdStart + "\" " + `${command}` + ` ${customCommand}` + ` -f "${pomPath}"`; //cmd for start.. - } - return "\"" + mvnCmdStart + "\" " + `${command}` + ` -f "${pomPath}"`; // CMD - case ShellType.WSL: - mvnCmdStart = toDefaultWslPath(mvnCmdStart); - pomPath = toDefaultWslPath(pomPath); - if (customCommand) { - return "cd \"" + mvnCmdStart + "\" && " + "./mvnw " + `${command}` + ` ${customCommand}`; //Wsl start .. - } - return "cd \"" + mvnCmdStart + "\" && " + "./mvnw " + `${command}`; //Wsl - - - default: - mvnCmdStart = Path.join(mvnCmdStart, "mvnw.cmd"); - if (customCommand) { - return "\"" + mvnCmdStart + "\" " + `${command}` + ` ${customCommand}` + ` -f "${pomPath}"`; - } - return "\"" + mvnCmdStart + "\" " + `${command}` + ` -f "${pomPath}"`; - } + return getMavenCommandForWin(mvnCmdStart, pomPath, command, terminalType, customCommand); } else { - if (customCommand) { - return "cd \"" + mvnCmdStart + "\" && " + "./mvnw " + `${command}` + ` ${customCommand}`; - } - return "cd \"" + mvnCmdStart + "\" && " + "./mvnw " + `${command}`; + return formLinuxBasedCommand(mvnCmdStart, command, "./mvnw ", customCommand); } - } /** - * Return the Gradle commands based on the OS and Terminal for start, startinContainer, start.. + * Return the gradle command based on the OS and Terminal for start, start in container, start.. */ - export async function getCommandForGradle(buildGradlePath: string, command: string, terminalType?: String, customCommand?: string): Promise { let gradleCmdStart = await gradleCmd(buildGradlePath); if (gradleCmdStart === "gradle") { - if (customCommand) { - return `${gradleCmdStart} ` + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; - } - return `${gradleCmdStart} ` + `${command}` + ` -b="${buildGradlePath}"`; + return formDefaultCommand(gradleCmdStart, buildGradlePath, command, "-b=", customCommand); } //checking the OS type for command customization if (isWin()) { - return getGradleCommandsForWin(gradleCmdStart, buildGradlePath, command, terminalType, customCommand); + return getGradleCommandForWin(gradleCmdStart, buildGradlePath, command, terminalType, customCommand); } else { gradleCmdStart = Path.join(gradleCmdStart, "gradlew"); - if (customCommand) { - return "\"" + gradleCmdStart + "\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; - } - return "\"" + gradleCmdStart + "\" " + `${command}` + ` -b="${buildGradlePath}"`; + return formDefaultCommand(gradleCmdStart, buildGradlePath, command, "-b=", customCommand); } - } /** * Reused from vscode-maven * https://github.com/microsoft/vscode-maven/blob/main/src/mavenTerminal.ts */ - function toDefaultWslPath(p: string): string { const arr: string[] = p.split(":\\"); if (arr.length === 2) { @@ -139,47 +78,6 @@ function toDefaultWslPath(p: string): string { } } -/** - * Return the Gradle commands for windows OS based on the terminal configured - */ - -function getGradleCommandsForWin(gradleCmdStart: string, buildGradlePath: string, command: string, terminalType?: String, customCommand?: string): string { - switch (terminalType) { - case ShellType.GIT_BASH: - gradleCmdStart = Path.join(gradleCmdStart, "gradlew"); - if (customCommand) { - return "\"" + gradleCmdStart + "\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; //bash start.. - } - return "\"" + gradleCmdStart + "\" " + `${command}` + ` -b="${buildGradlePath}"`; //Bash - case ShellType.POWERSHELL: { - gradleCmdStart = Path.join(gradleCmdStart, "gradlew.bat"); - if (customCommand) { - return "& \"" + gradleCmdStart + "\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`;// PowerShell strat.. - } - return "& \"" + gradleCmdStart + "\" " + `${command}` + ` -b="${buildGradlePath}"`;// PowerShell - } - case ShellType.CMD: - gradleCmdStart = Path.join(gradleCmdStart, "gradlew.bat"); - if (customCommand) { - return "\"" + gradleCmdStart + "\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; // CMD start.. - } - return "\"" + gradleCmdStart + "\" " + `${command}` + ` -b="${buildGradlePath}"`; // CMD - case ShellType.WSL: - buildGradlePath = toDefaultWslPath(buildGradlePath); - gradleCmdStart = toDefaultWslPath(gradleCmdStart) - gradleCmdStart = Path.join(gradleCmdStart, "gradlew"); - if (customCommand) { - return "\"" + gradleCmdStart + "\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; //wsl start.. - } - return "\"" + gradleCmdStart + "\" " + `${command}` + ` -b="${buildGradlePath}"`; //wsl - default: - gradleCmdStart = Path.join(gradleCmdStart, "gradlew.bat"); - if (customCommand) { - "\"" + gradleCmdStart + "\" " + `${command}` + ` ${customCommand}` + ` -b="${buildGradlePath}"`; - } - return "\"" + gradleCmdStart + "\" " + `${command}` + ` -b="${buildGradlePath}"`; - } -} /** * Reused from vscode-maven * https://github.com/microsoft/vscode-maven/blob/2ab8f392f418c8e0fe2903387f2b0013a1c50e78/src/utils/mavenUtils.ts @@ -188,8 +86,9 @@ export function isWin(): boolean { return process.platform.startsWith("win"); } - -// return Maven executable path, Maven wrapper, or mvn +/** + * Returns maven wrapper path or mvn + */ async function mvnCmd(pomPath: string): Promise { const preferMavenWrapper: boolean | undefined = vscode.workspace.getConfiguration("maven").get("executable.preferMavenWrapper"); if (preferMavenWrapper) { @@ -201,6 +100,9 @@ async function mvnCmd(pomPath: string): Promise { return "mvn"; } +/** + * Returns gradle wrapper path or gradle + */ async function gradleCmd(buildGradle: string): Promise { const preferGradleWrapper: boolean | undefined = vscode.workspace.getConfiguration("java").get("import.gradle.wrapper.enabled"); if (preferGradleWrapper) { @@ -211,41 +113,145 @@ async function gradleCmd(buildGradle: string): Promise { } return "gradle"; } + /** * Search for potential Maven wrapper, return undefined if does not exist * Reused from vscode-maven * https://github.com/microsoft/vscode-maven/blob/2ab8f392f418c8e0fe2903387f2b0013a1c50e78/src/utils/mavenUtils.ts * @param projectFolder */ -async function getLocalMavenWrapper(projectFolder: string): Promise { +async function getLocalGradleWrapper(projectFolder: string): Promise { + const gradlew: string = isWin() ? "gradlew.bat" : "gradlew"; + // walk up parent folders let current: string = projectFolder; while (Path.basename(current)) { - const potentialMvnwPath: string = Path.join(current); - - if (await pathExists(potentialMvnwPath)) { - return potentialMvnwPath; + const potentialGradlewFullPath: string = Path.join(current, gradlew); + const potentialGradlewPath: string = Path.join(current); + if (await pathExists(potentialGradlewFullPath)) { + return potentialGradlewPath; } current = Path.dirname(current); } return undefined; } + /** * Search for potential Gradle wrapper, return undefined if it does not exist * Modified from vscode-maven, see getLocalMavenWrapper method above * @param projectFolder */ -async function getLocalGradleWrapper(projectFolder: string): Promise { +async function getLocalMavenWrapper(projectFolder: string): Promise { + const mvnw: string = isWin() ? "mvnw.cmd" : "mvnw"; + // walk up parent folders let current: string = projectFolder; while (Path.basename(current)) { - const potentialGradlewPath: string = Path.join(current); - if (await pathExists(potentialGradlewPath)) { - return potentialGradlewPath; + const potentialMvnwfullPath: string = Path.join(current, mvnw); + const potentialMvnwPath: string = Path.join(current); + if (await pathExists(potentialMvnwfullPath)) { + return potentialMvnwPath; } current = Path.dirname(current); } return undefined; } +/** + * Returns the gradle command for windows OS based on the terminal configured + */ +function getGradleCommandForWin(gradleCmdStart: string, buildGradlePath: string, command: string, terminalType?: String, customCommand?: string): string { + switch (terminalType) { + case ShellType.GIT_BASH: + gradleCmdStart = Path.join(gradleCmdStart, "gradlew"); + return formDefaultCommand(gradleCmdStart, buildGradlePath, command, "-b=", customCommand); //Bash + case ShellType.POWERSHELL: + gradleCmdStart = Path.join(gradleCmdStart, "gradlew.bat"); + return formPowershellCommand(gradleCmdStart, buildGradlePath, command, "-b=", customCommand); + case ShellType.WSL: + return formLinuxBasedCommand(toDefaultWslPath(gradleCmdStart), command, "./gradlew ", customCommand); //Wsl + default: + gradleCmdStart = Path.join(gradleCmdStart, "gradlew.bat"); + return formDefaultCommand(gradleCmdStart, buildGradlePath, command, "-b=", customCommand); + } +} + +/** + * Returns the maven command for windows OS based on the terminal configured + */ +function getMavenCommandForWin(mvnCmdStart: string, pomPath: string, command: string, terminalType?: String, customCommand?: string): string { + switch (terminalType) { + case ShellType.GIT_BASH: + return formLinuxBasedCommand(mvnCmdStart, command, "./mvnw ", customCommand); + case ShellType.POWERSHELL: + mvnCmdStart = Path.join(mvnCmdStart, "mvnw.cmd"); + return formPowershellCommand(mvnCmdStart, pomPath, command, "-f ", customCommand); + case ShellType.WSL: + mvnCmdStart = toDefaultWslPath(mvnCmdStart); + return formLinuxBasedCommand(mvnCmdStart, command, "./mvnw ", customCommand); + default: + mvnCmdStart = Path.join(mvnCmdStart, "mvnw.cmd"); + return formDefaultCommand(mvnCmdStart, pomPath, command, "-f ", customCommand); + } +} + +/** + * Returns the Powershell based command for windows OS + */ +function formPowershellCommand(cmdStart: string, projectPath: string, command: string, cmdOption: String, customCommand?: string): string { + if (customCommand) { + return "& \"" + cmdStart + "\" " + `${command}` + ` ${customCommand}` + ` ${cmdOption}"${projectPath}"`; //Powershell for start.. + } + return "& \"" + cmdStart + "\" " + `${command}` + ` ${cmdOption}"${projectPath}"`; //PowerShell +} + +/** + * Returns the Linux based command + */ +function formLinuxBasedCommand(mvnCmdStart: string, command: string, wrapperType: String, customCommand?: string): string { + if (customCommand) { + return "cd \"" + mvnCmdStart + "\" && " + `${wrapperType}` + `${command}` + ` ${customCommand}`; //Bash or WSL for start.. + } + return "cd \"" + mvnCmdStart + "\" && " + `${wrapperType}` + `${command}`; //Bash or WSL command +} + +/** + * Returns default command + */ +function formDefaultCommand(mvnProjectPath: string, pomPath: String, command: string, cmdOption: String, customCommand?: string): string { + if (customCommand) { + return "\"" + mvnProjectPath + "\" " + `${command}` + ` ${customCommand}` + ` ${cmdOption}"${pomPath}"`; + } + return "\"" + mvnProjectPath + "\" " + `${command}` + ` ${cmdOption}"${pomPath}"`; +} + +/** + * Reused from vscode-maven - currentWindowsShell() + * https://github.com/microsoft/vscode-maven/blob/main/src/mavenTerminal.ts + * method to fetch default terminal configured + */ +export function defaultWindowsShell(): ShellType { + const defaultWindowsShellPath: string = vscode.env.shell; + const executable: string = Path.basename(defaultWindowsShellPath); + switch (executable.toLowerCase()) { + case "pwsh.exe": + case "powershell.exe": + case "pwsh": // pwsh on mac/linux + return ShellType.POWERSHELL; + case "bash.exe": + case 'git-cmd.exe': + return ShellType.GIT_BASH; + case 'wsl.exe': + case 'ubuntu.exe': + case 'ubuntu1804.exe': + case 'kali.exe': + case 'debian.exe': + case 'opensuse-42.exe': + case 'sles-12.exe': + return ShellType.WSL; + default: + return ShellType.OTHERS; + } +} + From 942493ec20f8a35282bd36a1731fa3b5acebd172 Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Wed, 20 Nov 2024 12:36:39 +0530 Subject: [PATCH 12/23] removed unwanted lines --- src/util/commandUtils.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/util/commandUtils.ts b/src/util/commandUtils.ts index 9d8dccde..dcc4b8cc 100644 --- a/src/util/commandUtils.ts +++ b/src/util/commandUtils.ts @@ -122,7 +122,6 @@ async function gradleCmd(buildGradle: string): Promise { */ async function getLocalGradleWrapper(projectFolder: string): Promise { const gradlew: string = isWin() ? "gradlew.bat" : "gradlew"; - // walk up parent folders let current: string = projectFolder; while (Path.basename(current)) { @@ -143,7 +142,6 @@ async function getLocalGradleWrapper(projectFolder: string): Promise { const mvnw: string = isWin() ? "mvnw.cmd" : "mvnw"; - // walk up parent folders let current: string = projectFolder; while (Path.basename(current)) { From ec1f91a7a70dced420530fb6b0b658f53e79d8aa Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Wed, 20 Nov 2024 12:42:41 +0530 Subject: [PATCH 13/23] removed space --- src/liberty/devCommands.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index 538d7127..306e3c08 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -411,7 +411,7 @@ export async function customDevMode(libProject?: LibertyProject | undefined, par } if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT || libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) { - const cmd = await getCommandForMaven(libProject.getPath(), "io.openliberty.tools:liberty-maven-plugin:dev", libProject.getTerminalType(), customCommand); + const cmd = await getCommandForMaven(libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:dev", libProject.getTerminalType(), customCommand); terminal.sendText(cmd); } else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT || libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) { const cmd = await getCommandForGradle(libProject.getPath(), "libertyDev", libProject.getTerminalType(), customCommand); From 90558f545e515f95e26897f6503d906f91472aa5 Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Wed, 20 Nov 2024 12:46:39 +0530 Subject: [PATCH 14/23] Formatted the code --- src/liberty/devCommands.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index 306e3c08..538d7127 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -411,7 +411,7 @@ export async function customDevMode(libProject?: LibertyProject | undefined, par } if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT || libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) { - const cmd = await getCommandForMaven(libProject.getPath(),"io.openliberty.tools:liberty-maven-plugin:dev", libProject.getTerminalType(), customCommand); + const cmd = await getCommandForMaven(libProject.getPath(), "io.openliberty.tools:liberty-maven-plugin:dev", libProject.getTerminalType(), customCommand); terminal.sendText(cmd); } else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT || libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) { const cmd = await getCommandForGradle(libProject.getPath(), "libertyDev", libProject.getTerminalType(), customCommand); From 13252a3b2aa6783254f1ccd20a353d2321ad0747 Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Wed, 20 Nov 2024 15:02:59 +0530 Subject: [PATCH 15/23] changes not reflecting in git since made one sample change in the line --- src/liberty/devCommands.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index 538d7127..b899f2d8 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -111,8 +111,8 @@ export async function startDevMode(libProject?: LibertyProject | undefined): Pro terminal.show(); libProject.setTerminal(terminal); if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT || libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) { - const cmd = await getCommandForMaven(libProject.getPath(), "io.openliberty.tools:liberty-maven-plugin:dev", libProject.getTerminalType()); - terminal.sendText(cmd); // start dev mode on current project + // const cmd = await getCommandForMaven(libProject.getPath(), "io.openliberty.tools:liberty-maven-plugin:dev", libProject.getTerminalType()); + // terminal.sendText(cmd); // start dev mode on current project } else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT || libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) { const cmd = await getCommandForGradle(libProject.getPath(), "libertyDev", libProject.getTerminalType()); terminal.sendText(cmd); // start dev mode on current project From e79254239a95904a59267d4a20ccea59eb0a36f7 Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Wed, 20 Nov 2024 15:06:36 +0530 Subject: [PATCH 16/23] formatted the lines --- src/liberty/devCommands.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index b899f2d8..538d7127 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -111,8 +111,8 @@ export async function startDevMode(libProject?: LibertyProject | undefined): Pro terminal.show(); libProject.setTerminal(terminal); if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT || libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) { - // const cmd = await getCommandForMaven(libProject.getPath(), "io.openliberty.tools:liberty-maven-plugin:dev", libProject.getTerminalType()); - // terminal.sendText(cmd); // start dev mode on current project + const cmd = await getCommandForMaven(libProject.getPath(), "io.openliberty.tools:liberty-maven-plugin:dev", libProject.getTerminalType()); + terminal.sendText(cmd); // start dev mode on current project } else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT || libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) { const cmd = await getCommandForGradle(libProject.getPath(), "libertyDev", libProject.getTerminalType()); terminal.sendText(cmd); // start dev mode on current project From b11bea4afd1439f8993ba29fa1779a68a27cee90 Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Wed, 20 Nov 2024 15:22:40 +0530 Subject: [PATCH 17/23] devCommands changes added --- src/liberty/devCommands.ts | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index 538d7127..77e97fd4 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -77,21 +77,22 @@ export async function openProject(pomPath: string): Promise { export async function listAllCommands(): Promise { const libertyCommands = Array.from(COMMAND_TITLES.keys()); vscode.window.showQuickPick(libertyCommands).then(selection => { - if (!selection) { - return; - } - const command = COMMAND_TITLES.get(selection); + if (!selection) { + return; + } + const command = COMMAND_TITLES.get(selection); if ( command !== undefined ) { - vscode.commands.executeCommand(command); - } else { - // should never happen - console.error("Unable to find corresponding command for " + selection); - } - + vscode.commands.executeCommand(command); + } else { + // should never happen + console.error("Unable to find corresponding command for " + selection); + } + }); } + // start dev mode export async function startDevMode(libProject?: LibertyProject | undefined): Promise { if (libProject !== undefined) { @@ -130,7 +131,7 @@ export async function startDevMode(libProject?: LibertyProject | undefined): Pro export async function removeProject(): Promise { const projectProvider: ProjectProvider = ProjectProvider.getInstance(); - + // clicked on the empty space and workspace has more than one folders, or // from command palette // Display the list of current user added projects for user to select. @@ -163,7 +164,7 @@ export async function removeProject(): Promise { } }); }); - + } } @@ -197,7 +198,7 @@ export async function addProject(uri: vscode.Uri): Promise { // present the list to add showListOfPathsToAdd(uris); } - + } else { // clicked on the empty space and workspace has more than one folders, or From 9b40e611b1b29f73182f9aaa2ee105b951861d3b Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Wed, 20 Nov 2024 18:07:38 +0530 Subject: [PATCH 18/23] create new terminal code modified --- src/liberty/devCommands.ts | 45 ++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/liberty/devCommands.ts b/src/liberty/devCommands.ts index 77e97fd4..5e591e58 100644 --- a/src/liberty/devCommands.ts +++ b/src/liberty/devCommands.ts @@ -99,14 +99,8 @@ export async function startDevMode(libProject?: LibertyProject | undefined): Pro console.log(localize("starting.liberty.dev.on", libProject.getLabel())); let terminal = libProject.getTerminal(); if (terminal === undefined) { - const path = Path.dirname(libProject.getPath()); - //fetch the default terminal details and store it in LibertyProject object - const terminalType = defaultWindowsShell(); - libProject.setTerminalType(terminalType); - terminal = libProject.createTerminal(path); - if (terminal !== undefined) { - terminals[Number(terminal.processId)] = libProject; - } + //function call to create new terminal for LTV + terminal = createTerminalforLiberty(libProject, terminal); } if (terminal !== undefined) { terminal.show(); @@ -359,14 +353,8 @@ export async function customDevMode(libProject?: LibertyProject | undefined, par if (libProject !== undefined) { let terminal = libProject.getTerminal(); if (terminal === undefined) { - const path = Path.dirname(libProject.getPath()); - //fetch the default terminal details and store it in LibertyProject object - const terminalType = defaultWindowsShell(); - libProject.setTerminalType(terminalType); - terminal = libProject.createTerminal(path); - if (terminal !== undefined) { - terminals[Number(terminal.processId)] = libProject; - } + //function call to create new terminal for LTV + terminal = createTerminalforLiberty(libProject, terminal); } if (terminal !== undefined) { terminal.show(); @@ -435,14 +423,8 @@ export async function startContainerDevMode(libProject?: LibertyProject | undefi if (libProject !== undefined) { let terminal = libProject.getTerminal(); if (terminal === undefined) { - const path = Path.dirname(libProject.getPath()); - //fetch the default terminal details and store it in LibertyProject object - const terminalType = defaultWindowsShell(); - libProject.setTerminalType(terminalType); - terminal = libProject.createTerminal(path); - if (terminal !== undefined) { - terminals[Number(terminal.processId)] = libProject; - } + //function call to create new terminal for LTV + terminal = createTerminalforLiberty(libProject, terminal); } if (terminal !== undefined) { terminal.show(); @@ -534,3 +516,18 @@ export function deleteTerminal(terminal: vscode.Terminal): void { console.error(localize("unable.to.delete.terminal", terminal.name)); } } +/** + * function to create new terminal of default type + */ +function createTerminalforLiberty(libProject: LibertyProject, terminal: vscode.Terminal | undefined) { + const path = Path.dirname(libProject.getPath()); + //fetch the default terminal details and store it in LibertyProject object + const terminalType = defaultWindowsShell(); + libProject.setTerminalType(terminalType); + terminal = libProject.createTerminal(path); + if (terminal !== undefined) { + terminals[Number(terminal.processId)] = libProject; + } + return terminal; +} + From 32f452a375af52a1e27b5d1545b91b4c495fc11e Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Thu, 21 Nov 2024 13:57:52 +0530 Subject: [PATCH 19/23] cmd shell type added --- src/util/commandUtils.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/util/commandUtils.ts b/src/util/commandUtils.ts index dcc4b8cc..ffed4d46 100644 --- a/src/util/commandUtils.ts +++ b/src/util/commandUtils.ts @@ -17,6 +17,7 @@ import { pathExists } from "fs-extra"; * https://github.com/microsoft/vscode-maven/blob/main/src/mavenTerminal.ts */ enum ShellType { + CMD = "Command Prompt", POWERSHELL = "PowerShell", GIT_BASH = "Git Bash", WSL = "WSL Bash", @@ -169,6 +170,7 @@ function getGradleCommandForWin(gradleCmdStart: string, buildGradlePath: string, case ShellType.WSL: return formLinuxBasedCommand(toDefaultWslPath(gradleCmdStart), command, "./gradlew ", customCommand); //Wsl default: + // The default case is ShellType CMD or OTHERS gradleCmdStart = Path.join(gradleCmdStart, "gradlew.bat"); return formDefaultCommand(gradleCmdStart, buildGradlePath, command, "-b=", customCommand); } @@ -188,6 +190,7 @@ function getMavenCommandForWin(mvnCmdStart: string, pomPath: string, command: st mvnCmdStart = toDefaultWslPath(mvnCmdStart); return formLinuxBasedCommand(mvnCmdStart, command, "./mvnw ", customCommand); default: + // The default case is ShellType CMD or OTHERS mvnCmdStart = Path.join(mvnCmdStart, "mvnw.cmd"); return formDefaultCommand(mvnCmdStart, pomPath, command, "-f ", customCommand); } @@ -232,6 +235,8 @@ export function defaultWindowsShell(): ShellType { const defaultWindowsShellPath: string = vscode.env.shell; const executable: string = Path.basename(defaultWindowsShellPath); switch (executable.toLowerCase()) { + case "cmd.exe": + return ShellType.CMD; case "pwsh.exe": case "powershell.exe": case "pwsh": // pwsh on mac/linux From 1bf8fda43b1dfdc4506bf8b81f87d2f06adba36d Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Thu, 21 Nov 2024 14:01:16 +0530 Subject: [PATCH 20/23] Update src/util/commandUtils.ts Co-authored-by: Trevor Crawford --- src/util/commandUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/commandUtils.ts b/src/util/commandUtils.ts index ffed4d46..200c9d4a 100644 --- a/src/util/commandUtils.ts +++ b/src/util/commandUtils.ts @@ -121,7 +121,7 @@ async function gradleCmd(buildGradle: string): Promise { * https://github.com/microsoft/vscode-maven/blob/2ab8f392f418c8e0fe2903387f2b0013a1c50e78/src/utils/mavenUtils.ts * @param projectFolder */ -async function getLocalGradleWrapper(projectFolder: string): Promise { +async function getLocalGradleWrapperDir(projectFolder: string): Promise { const gradlew: string = isWin() ? "gradlew.bat" : "gradlew"; // walk up parent folders let current: string = projectFolder; From 452d6ffda1a166a69cb45a9bae5b8e3334ca42a9 Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Thu, 21 Nov 2024 14:13:35 +0530 Subject: [PATCH 21/23] updated code for wrapper path --- src/util/commandUtils.ts | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/util/commandUtils.ts b/src/util/commandUtils.ts index 200c9d4a..a2bb78cc 100644 --- a/src/util/commandUtils.ts +++ b/src/util/commandUtils.ts @@ -93,7 +93,7 @@ export function isWin(): boolean { async function mvnCmd(pomPath: string): Promise { const preferMavenWrapper: boolean | undefined = vscode.workspace.getConfiguration("maven").get("executable.preferMavenWrapper"); if (preferMavenWrapper) { - const localMvnwPath: string | undefined = await getLocalMavenWrapper(Path.dirname(pomPath)); + const localMvnwPath: string | undefined = await getLocalMavenWrapperDir(Path.dirname(pomPath)); if (localMvnwPath) { return `${localMvnwPath}`; } @@ -107,7 +107,7 @@ async function mvnCmd(pomPath: string): Promise { async function gradleCmd(buildGradle: string): Promise { const preferGradleWrapper: boolean | undefined = vscode.workspace.getConfiguration("java").get("import.gradle.wrapper.enabled"); if (preferGradleWrapper) { - const localGradlewPath: string | undefined = await getLocalGradleWrapper(Path.dirname(buildGradle)); + const localGradlewPath: string | undefined = await getLocalGradleWrapperDir(Path.dirname(buildGradle)); if (localGradlewPath) { return `${localGradlewPath}`; } @@ -124,14 +124,13 @@ async function gradleCmd(buildGradle: string): Promise { async function getLocalGradleWrapperDir(projectFolder: string): Promise { const gradlew: string = isWin() ? "gradlew.bat" : "gradlew"; // walk up parent folders - let current: string = projectFolder; - while (Path.basename(current)) { - const potentialGradlewFullPath: string = Path.join(current, gradlew); - const potentialGradlewPath: string = Path.join(current); - if (await pathExists(potentialGradlewFullPath)) { - return potentialGradlewPath; + let currentDir: string = projectFolder; + while (Path.basename(currentDir)) { + const potentialGradlewPath: string = Path.join(currentDir, gradlew); + if (await pathExists(potentialGradlewPath)) { + return currentDir; } - current = Path.dirname(current); + currentDir = Path.dirname(currentDir); } return undefined; } @@ -141,17 +140,16 @@ async function getLocalGradleWrapperDir(projectFolder: string): Promise { +async function getLocalMavenWrapperDir(projectFolder: string): Promise { const mvnw: string = isWin() ? "mvnw.cmd" : "mvnw"; // walk up parent folders - let current: string = projectFolder; - while (Path.basename(current)) { - const potentialMvnwfullPath: string = Path.join(current, mvnw); - const potentialMvnwPath: string = Path.join(current); - if (await pathExists(potentialMvnwfullPath)) { - return potentialMvnwPath; + let currentDir: string = projectFolder; + while (Path.basename(currentDir)) { + const potentialMvnwPath: string = Path.join(currentDir, mvnw); + if (await pathExists(potentialMvnwPath)) { + return currentDir; } - current = Path.dirname(current); + currentDir = Path.dirname(currentDir); } return undefined; } From 84eb1b06883d7dcc0935c93ddecb83310e6cd10a Mon Sep 17 00:00:00 2001 From: SuparnaSuresh Date: Thu, 21 Nov 2024 14:17:36 +0530 Subject: [PATCH 22/23] code updated for commant format --- src/util/commandUtils.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/util/commandUtils.ts b/src/util/commandUtils.ts index a2bb78cc..215e6bcd 100644 --- a/src/util/commandUtils.ts +++ b/src/util/commandUtils.ts @@ -207,21 +207,21 @@ function formPowershellCommand(cmdStart: string, projectPath: string, command: s /** * Returns the Linux based command */ -function formLinuxBasedCommand(mvnCmdStart: string, command: string, wrapperType: String, customCommand?: string): string { +function formLinuxBasedCommand(cmdStart: string, command: string, wrapperType: String, customCommand?: string): string { if (customCommand) { - return "cd \"" + mvnCmdStart + "\" && " + `${wrapperType}` + `${command}` + ` ${customCommand}`; //Bash or WSL for start.. + return "cd \"" + cmdStart + "\" && " + `${wrapperType}` + `${command}` + ` ${customCommand}`; //Bash or WSL for start.. } - return "cd \"" + mvnCmdStart + "\" && " + `${wrapperType}` + `${command}`; //Bash or WSL command + return "cd \"" + cmdStart + "\" && " + `${wrapperType}` + `${command}`; //Bash or WSL command } /** * Returns default command */ -function formDefaultCommand(mvnProjectPath: string, pomPath: String, command: string, cmdOption: String, customCommand?: string): string { +function formDefaultCommand(projectPath: string, buildFilePath: String, command: string, cmdOption: String, customCommand?: string): string { if (customCommand) { - return "\"" + mvnProjectPath + "\" " + `${command}` + ` ${customCommand}` + ` ${cmdOption}"${pomPath}"`; + return "\"" + projectPath + "\" " + `${command}` + ` ${customCommand}` + ` ${cmdOption}"${buildFilePath}"`; } - return "\"" + mvnProjectPath + "\" " + `${command}` + ` ${cmdOption}"${pomPath}"`; + return "\"" + projectPath + "\" " + `${command}` + ` ${cmdOption}"${buildFilePath}"`; } /** From 0248dd06abace9eef698bd99da93b7876c6af5da Mon Sep 17 00:00:00 2001 From: Trevor Crawford Date: Thu, 21 Nov 2024 16:52:20 -0500 Subject: [PATCH 23/23] Updated comments for the wrapper search methods --- src/util/commandUtils.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/util/commandUtils.ts b/src/util/commandUtils.ts index 215e6bcd..bfa2ac99 100644 --- a/src/util/commandUtils.ts +++ b/src/util/commandUtils.ts @@ -116,9 +116,8 @@ async function gradleCmd(buildGradle: string): Promise { } /** - * Search for potential Maven wrapper, return undefined if does not exist - * Reused from vscode-maven - * https://github.com/microsoft/vscode-maven/blob/2ab8f392f418c8e0fe2903387f2b0013a1c50e78/src/utils/mavenUtils.ts + * Search for potential Gradle wrapper, return undefined if does not exist + * Modified from vscode-maven, see getLocalMavenWrapperDir method below * @param projectFolder */ async function getLocalGradleWrapperDir(projectFolder: string): Promise { @@ -136,8 +135,9 @@ async function getLocalGradleWrapperDir(projectFolder: string): Promise {