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

Fixes #337 - Command fix for project path with spaces #355

Merged
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f61c7d5
Update devCommands.ts
SuparnaSuresh Oct 21, 2024
595a16e
fixed wsl commands and added code for startinContainer and strat
SuparnaSuresh Oct 22, 2024
137798e
Copyright added in commandUtils
SuparnaSuresh Oct 22, 2024
8a642a7
Fix for the commands - using 'mvn' and 'gradle'
SuparnaSuresh Oct 22, 2024
5b49790
Removed unwanted spaces.
SuparnaSuresh Oct 22, 2024
71f8c8d
Code changes added for maven executable path and fix for demo suggest…
SuparnaSuresh Oct 28, 2024
2929bc2
Merge branch 'OpenLiberty:main' into issue337-FixExecutablePath
SuparnaSuresh Nov 1, 2024
ffb2fff
Changes after review comment incorporation
SuparnaSuresh Nov 5, 2024
9f3c36c
Removed export keyword
SuparnaSuresh Nov 5, 2024
955e735
code changes for switch default terminal
SuparnaSuresh Nov 11, 2024
1f768f3
Changed method - currentWindowsShell
SuparnaSuresh Nov 11, 2024
3a04468
Addressed review comments
SuparnaSuresh Nov 20, 2024
942493e
removed unwanted lines
SuparnaSuresh Nov 20, 2024
ec1f91a
removed space
SuparnaSuresh Nov 20, 2024
90558f5
Formatted the code
SuparnaSuresh Nov 20, 2024
13252a3
changes not reflecting in git since made one sample change in the line
SuparnaSuresh Nov 20, 2024
e792542
formatted the lines
SuparnaSuresh Nov 20, 2024
b11bea4
devCommands changes added
SuparnaSuresh Nov 20, 2024
9b40e61
create new terminal code modified
SuparnaSuresh Nov 20, 2024
32f452a
cmd shell type added
SuparnaSuresh Nov 21, 2024
1bf8fda
Update src/util/commandUtils.ts
SuparnaSuresh Nov 21, 2024
452d6ff
updated code for wrapper path
SuparnaSuresh Nov 21, 2024
84eb1b0
code updated for commant format
SuparnaSuresh Nov 21, 2024
0248dd0
Updated comments for the wrapper search methods
TrevCraw Nov 21, 2024
749f3d3
Merge branch 'main' into issue337-FixExecutablePath
TrevCraw Nov 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 24 additions & 104 deletions src/liberty/devCommands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2020, 2022 IBM Corporation.
* Copyright (c) 2020, 2024 IBM Corporation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -18,9 +18,9 @@ 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, defaultWindowsShell } from "../util/commandUtils";

export const terminals: { [libProjectId: number]: LibertyProject } = {};

Expand Down Expand Up @@ -99,22 +99,17 @@ 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());
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();
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 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 gradleCmdStart = await gradleCmd(libProject.getPath());
const cmd = `${gradleCmdStart} libertyDev -b="${libProject.getPath()}"`;
const cmd = await getCommandForGradle(libProject.getPath(), "libertyDev", libProject.getTerminalType());
terminal.sendText(cmd); // start dev mode on current project
}
}
Expand Down Expand Up @@ -358,11 +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());
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();
Expand Down Expand Up @@ -408,12 +400,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 = `${mvnCmdStart} io.openliberty.tools:liberty-maven-plugin:dev ${customCommand} -f "${libProject.getPath()}"`;
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 gradleCmdStart = await gradleCmd(libProject.getPath());
const cmd = `${gradleCmdStart} libertyDev ${customCommand} -b="${libProject.getPath()}"`;
const cmd = await getCommandForGradle(libProject.getPath(), "libertyDev", libProject.getTerminalType(), customCommand);
terminal.sendText(cmd);
}
}
Expand All @@ -433,22 +423,17 @@ export async function startContainerDevMode(libProject?: LibertyProject | undefi
if (libProject !== undefined) {
let terminal = libProject.getTerminal();
if (terminal === undefined) {
const path = Path.dirname(libProject.getPath());
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();
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 = 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 gradleCmdStart = await gradleCmd(libProject.getPath());
const cmd = `${gradleCmdStart} libertyDevc -b="${libProject.getPath()}"`;
const cmd = await getCommandForGradle(libProject.getPath(), "libertyDevc", libProject.getTerminalType());
terminal.sendText(cmd);
}
}
Expand Down Expand Up @@ -531,83 +516,18 @@ export function deleteTerminal(terminal: vscode.Terminal): void {
console.error(localize("unable.to.delete.terminal", terminal.name));
}
}


// 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));
if (localMvnwPath) {
return localMvnwPath;
}
}
return "mvn";
}

export async function gradleCmd(buildGradle: string): Promise<string> {
const preferGradleWrapper: boolean | undefined = vscode.workspace.getConfiguration("java").get<boolean>("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<string | undefined> {
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);
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
* function to create new terminal of default type
*/
async function getLocalGradleWrapper(projectFolder: string): Promise<string | undefined> {
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);
if (await pathExists(potentialGradlewPath)) {
return potentialGradlewPath;
}
current = Path.dirname(current);
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 undefined;
return terminal;
}

/**
* Reused from vscode-maven
* https://github.com/microsoft/vscode-maven/blob/2ab8f392f418c8e0fe2903387f2b0013a1c50e78/src/utils/mavenUtils.ts
*/
function isWin(): boolean {
return process.platform.startsWith("win");
}
10 changes: 9 additions & 1 deletion src/liberty/libertyProject.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Loading
Loading