Skip to content

Commit

Permalink
Code changes added for maven executable path and fix for demo suggest…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
SuparnaSuresh committed Oct 28, 2024
1 parent 5b49790 commit 71f8c8d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 51 deletions.
6 changes: 0 additions & 6 deletions src/liberty/devCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {

// attempt to use the Maven executable path, if empty try using mvn or mvnw according to the preferMavenWrapper setting
const mavenExecutablePath: string | undefined = vscode.workspace.getConfiguration("maven").get<string>("executable.path");
if (mavenExecutablePath) {
return mavenExecutablePath;
}
const preferMavenWrapper: boolean | undefined = vscode.workspace.getConfiguration("maven").get<boolean>("executable.preferMavenWrapper");
if (preferMavenWrapper) {
const localMvnwPath: string | undefined = await getLocalMavenWrapper(Path.dirname(pomPath));
Expand Down
115 changes: 70 additions & 45 deletions src/util/commandUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {

// attempt to use the Maven executable path, if empty try using mvn or mvnw according to the preferMavenWrapper setting
const mavenExecutablePath: string | undefined = vscode.workspace.getConfiguration("maven").get<string>("executable.path");

if (mavenExecutablePath) {

if(customCommand)
{
return `${mavenExecutablePath} ` + `${command}`+` ${customCommand}` + ` -f "${pomPath}"`;
}
return `${mavenExecutablePath} ` + `${command}`+ ` -f "${pomPath}"`;
}

let mvnCmdStart = await mvnCmd(pomPath);

if(mvnCmdStart === "mvn"){
Expand All @@ -67,36 +80,36 @@ 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
}
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:
Expand All @@ -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<string> {
let gradleCmdStart = await gradleCmd(buildGradlePath);

Expand All @@ -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){
Expand All @@ -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) {
Expand All @@ -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}"`;
}
}

0 comments on commit 71f8c8d

Please sign in to comment.