Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mvnCmd and gradleCmd should quote executable paths #337

Open
covener opened this issue Jul 21, 2024 · 4 comments · May be fixed by #355
Open

mvnCmd and gradleCmd should quote executable paths #337

covener opened this issue Jul 21, 2024 · 4 comments · May be fixed by #355
Assignees
Labels
bug Something isn't working must-fix
Milestone

Comments

@covener
Copy link
Member

covener commented Jul 21, 2024

When I try to start a server from the Liberty Dashboard, there is a shell quoting problem running the maven within the extension:

covener@cov-osx2-2 httpclients-jssehelper % /Users/covener/Library/Application Support/Code/User/globalStorage/pleiades.java-extension-pack-jdk/maven/latest/bin/mvn io.openliberty.tools:liberty-maven-plugin:dev -f 
"/Users/covener/SRC/httpclients-jssehelper/pom.xml"
zsh: no such file or directory: /Users/covener/Library/Application

AFAIK there is nothing special about my vscode and my project is based on a recent guide.

IIUC devCommands.ts should either return a quoted path (when not returning the "mvn" or "gradle" verbatim) or the callers of mvnCmd/gradleCmd need to wrap the returned value similar to how the maven plugin does with the references you can find to this utility function: https://github.com/microsoft/vscode-maven/blob/2ab8f392f418c8e0fe2903387f2b0013a1c50e78/src/utils/mavenUtils.ts#L170

https://github.com/OpenLiberty/liberty-tools-vscode/blob/main/src/liberty/devCommands.ts#L112

export async function mvnCmd(pomPath: string): Promise<string> {

@SuparnaSuresh
Copy link

SuparnaSuresh commented Oct 16, 2024

The problem while click on the start action in the LTV dashboard of the project if it has a space in the directory (eg : /Users/username/Documents/Application Support/newgradle/) is occurring for mac, windows and linux if it is using MavenWrapper/GradleWrapper to execute the command.
In the case of maven, if maven is already installed and configured in the environment, it is using mvn to execute the command as follows:
mvn io.openliberty.tools:liberty-maven-plugin:dev -f "/Users/username/Documents/Application Support/newmaven/pom.xml"

In the case of wrapper,
It will execute the command using “mvnw “(mac and linux) / “mvnw.cmd” (Windows).
Currently below command is using
/Users/username/Documents/Application Support/newmaven/mvnw io.openliberty.tools:liberty-maven-plugin:dev -f "/Users/username/Documents/Application Support/newmaven/pom.xml"

Similarly for Gradle, if gradle is already installed and configured in the  environment gradle is used  to form the command as below.
gradle  libertyDev -b="/Users/suparnasuresh/Documents/Application Support/newgradle/build.gradle"
For wrapper "gradlew.bat" (windows): "gradlew”(mac and windows) is used.

/Users/username/Documents/Application Support/newgradle/gradlew libertyDev -b="/Users/username/Documents/Application Support/newgradle/build.gradle"

For both maven and gradle, the case where it has space in the directory is failed to execute the command while click on start action due to below error.

zsh: no such file or directory: /Users/username/Documents/Applicatio

image (24)
Error screenshot for Mac and Linux

box-image
Error screenshot for Windows

The problem will occur with Liberty: Start, Liberty: Start in Container and, Liberty: Start ..

Below mentioned solutions tried.

Mac and Linux – Maven

Since it has a space in the directory path

  • Added quotes around the dir path and formed command as below:

  • "/Users/username/Documents/Application Support/newmaven/mvnw" io.openliberty.tools:liberty-maven-plugin:dev -f "/Users/username/Documents/Application Support/newmaven/pom.xml"

  • Added \ in the path where it has space and formed command as below:

  • /Users/username/Documents/Application\ Support/newmaven/mvnw io.openliberty.tools:liberty-maven-plugin:dev -f "/Users/username/Documents/Application Support/newmaven/pom.xml"

image (17)

Terminal is not responding for both the cases

  • Instead of specifying the path to form the command and execute, used cd command to go inside specific dir and access mvnw to execute it.

cd "/Users/username/Documents/Application Support/newmaven" && ./mvnw io.openliberty.tools:liberty-maven-plugin:dev -f "/Users/username/Documents/Application Support/newmaven/pom.xml"

box-image (1)

Implemented the above in such a way that it will be used only when we have spaces in the dir path. otherwise it will use the existing below command.

for eg if “/Users/username/Downloads/newmaven/mvnw” is directory, will execute below command.

"/Users/username/Downloads/newmaven/mvnw" io.openliberty.tools:liberty-maven-plugin:dev -f "/Users/username/Downloads/newmaven/pom.xml"

Mac and Linux – Gradle

  • Added quotes around the dir path as below and its working fine.

"/Users/username/Documents/Application Support/newgradle/gradlew" libertyDev -b="/Users/username/Documents/Application Support/newgradle/build.gradle"

image (23)

Windows - Gradle and Maven

OS was not recognizing the path with space even if we add quotes or \ for the dir path while executing gradle project.

  • with quotes

"c:\Users\Administrator\Downloads\Test issue\new-gradle\gradlew.bat" libertyDev -b="c:\Users\Administrator\Downloads\Test issue\new-gradle\build.gradle"

  • The commands seems to be working for gradle project in windows if it has space in the paths mentioned.

Gradle

c:"Users""Administrator""Downloads""Test issue""new-gradle""gradlew.bat" libertyDev -b="c:\Users\Administrator\Downloads\Test issue\new-gradle\build.gradle"

image (20)
OR
c:\Users\Administrator\Downloads\”Test issue”\new-gradle\gradlew.bat libertyDev -b="c:\Users\Administrator\Downloads\Test issue\new-gradle\build.gradle"

image (21)

Maven

C:\Users\Administrator\Downloads"Test issue"\new-maven\mvnw.cmd io.openliberty.tools:liberty-maven-plugin:dev -f "c:\Users\Administrator\Downloads\Test issue\new-maven\pom.xml"

image (19)

OR
C:\”Users”\”Administrator”\”Downloads”"Test issue"\”new-maven”\”mvnw.cmd” io.openliberty.tools:liberty-maven-plugin:dev -f "c:\Users\Administrator\Downloads\Test issue\new-maven\pom.xml"

image (22)

@TrevCraw
Copy link
Contributor

@SuparnaSuresh One thing to consider is that the format of the command should not be determined by the OS, but by the type of terminal that the user is starting Liberty in. For instance, in my VS Code environment on Windows, here are the options I have for types of terminals:
image
If a user on Windows runs with Git Bash or PowerShell, some Windows Command Prompt style commands may not work.

@SuparnaSuresh
Copy link

SuparnaSuresh commented Oct 21, 2024

@TrevCraw After considering above comment. Did analysis on the os+terminal combinations and tried executing the scenarios by configuring different terminals.

Mac

  • Mac + bash
  • Mac + zsh
  • Mac + csh
  • Mac + tcsh
  • Mac + dash
  • Mac + ksh
  • Mac + sh
    For all the combinations except ksh, below command is working
    cd "/Users/username/Documents/Application Support/newmaven" && ./mvnw io.openliberty.tools:liberty-maven-plugin:dev -f "/Users/username/Documents/Application Support/newmaven/pom.xml"

Windows

Also in the case of windows, format of the command is different in each terminal.

  • Windows + Poweshell

Maven
& "c:\Users\Administrator\Downloads\Test issue\mavenprj\mvnw.cmd" io.openliberty.tools:liberty-maven-plugin:dev -f "c:\Users\Administrator\Downloads\Test issue\mavenprj\pom.xml"

gradle
& "c:\Users\Administrator\Downloads\Test issue\graleprjct\gradlew.bat" libertyDev -b= "c:\Users\Administrator\Downloads\Test issue\graleprjct\build.gradle"

  • Windows + Command Prompt
    Maven
    "c:\Users\Administrator\Downloads\Test issue\mavenprj\mvnw.cmd" io.openliberty.tools:liberty-maven-plugin:dev -f "c:\Users\Administrator\Downloads\Test issue\mavenprj\pom.xml"

gradle
"c:\Users\Administrator\Downloads\Test issue\graleprjct\gradlew.bat" libertyDev -b= "c:\Users\Administrator\Downloads\Test issue\graleprjct\build.gradle"

  • Windows + Bash
    Even though it is windows OS, if bash terminal is configured in vscode, commands is not working if we form using mvnw.cmd/gradle.bat. Instead of that command are working if ./mvnw OR ./gradlew is used.

Maven
cd "/Users/username/Documents/Application Support/newmaven" && ./mvnw io.openliberty.tools:liberty-maven-plugin:dev -f "/Users/username/Documents/Application Support/newmaven/pom.xml"

Gradle
cd "/Users/username/Documents/Application Support/graleprjct" && ./gradlew libertyDev -b= "/Users/username/Documents/Application Support/graleprjct/build,gradle"

  • Windows + WSL

Able to identify the terminal using vscode.env.shell; And considered below shell types. [Referred vscode for maven code]
"cmd.exe": CMD;
"pwsh.exe","powershell.exe""pwsh": POWERSHELL
"bash.exe"'git-cmd.exe': GIT_BASH
'wsl.exe',ubuntu.exe','ubuntu1804.exe,'kali.exe','debian.exe','opensuse-42.exe','sles-12.exe':WSL

@SuparnaSuresh
Copy link

SuparnaSuresh commented Oct 28, 2024

Checks added before creating commands,

  1. Maven/Gradle type
  2. OS
    • Windows
    • Mac
    • Linux
  3. Terminal
    • cmd.exe: CMD;
    • pwsh.exe, powershell.exe : POWERSHELL
    • bash.exe, git-cmd.exe: GIT_BASH
    • wsl.exe, ubuntu.exe, ubuntu1804.exe, kali.exe, debian.exe, opensuse-42.exe, sles-12.exe:WSL

Sample command format for each OS and Terminal combination.

OS+Terminal Maven Command Gradle Command
Mac/Linux cd "/Users/username/Documents/Application Support/newmaven" && ./mvnw io.openliberty.tools:liberty-maven-plugin:dev "/Users/username/Downloads/newgradle/gradlew" libertyDev -b= "/Users/username/Downloads/newmaven/pom.xml"
Windows + Bash cd "/Users/username/Documents/Application Support/newmaven" && ./mvnw io.openliberty.tools:liberty-maven-plugin:dev cd "/Users/username/Documents/Application Support/graleprjct" && ./gradlew libertyDev
Windows + cmd "c:\Users\Administrator\Downloads\Test issue\mavenprj\mvnw.cmd" io.openliberty.tools:liberty-maven-plugin:dev -f "c:\Users\Administrator\Downloads\Test issue\mavenprj\pom.xml" "c:\Users\Administrator\Downloads\Test issue\graleprjct\gradlew.bat" libertyDev -b= "c:\Users\Administrator\Downloads\Test issue\graleprjct\build.gradle"
Windows + Powershell & "c:\Users\Administrator\Downloads\Test issue\mavenprj\mvnw.cmd" io.openliberty.tools:liberty-maven-plugin:dev -f "c:\Users\Administrator\Downloads\Test issue\mavenprj\pom.xml" & "c:\Users\Administrator\Downloads\Test issue\graleprjct\gradlew.bat" libertyDev -b= "c:\Users\Administrator\Downloads\Test issue\graleprjct\build.gradle"
Windows +WSL cd "/mnt/c/Users/Administrator/Downloads/Test issue/new-  maven" && ./mvnw io.openliberty.tools:liberty-maven-plugin:dev cd "/mnt/c/Users/Administrator/Downloads/Test issue/new-  gradle" && ./gradlew libertyDev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working must-fix
Projects
Development

Successfully merging a pull request may close this issue.

4 participants