Skip to content

Commit

Permalink
Fix for the commands - using 'mvn' and 'gradle'
Browse files Browse the repository at this point in the history
  • Loading branch information
SuparnaSuresh committed Oct 22, 2024
1 parent 137798e commit 8a642a7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 35 deletions.
26 changes: 10 additions & 16 deletions src/liberty/devCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -608,4 +602,4 @@ async function getLocalGradleWrapper(projectFolder: string): Promise<string | un
*/
export function isWin(): boolean {
return process.platform.startsWith("win");
}
}
56 changes: 37 additions & 19 deletions src/util/commandUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import * as Path from "path";
import * as vscode from "vscode";
import { isWin } from "../liberty/devCommands";
import { isWin,mvnCmd,gradleCmd } from "../liberty/devCommands";

/**
* Reused from vscode-maven
Expand Down Expand Up @@ -56,8 +56,17 @@ function currentWindowsShell(): ShellType {
/**
* 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 {
export async function getCommandForMaven(pomPath: string,command:string,customCommand?: string) : Promise<string> {

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:
Expand All @@ -67,31 +76,31 @@ 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..
}
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}"`;
}
Expand All @@ -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<string> {
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}"`;
}
Expand All @@ -169,4 +186,5 @@ function toDefaultWslPath(p: string): string {
} else {
return p.replace(/\\/g, "/");
}
}
}

0 comments on commit 8a642a7

Please sign in to comment.