Skip to content

Commit 72d49d6

Browse files
committed
pull dev/devc commands, terminal helper
1 parent 37cb3b1 commit 72d49d6

2 files changed

Lines changed: 56 additions & 76 deletions

File tree

src/definitions/constants.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import { localize } from "../util/i18nUtil";
99
// Use the helpers below (isMaven, isGradle, isContainer, isAggregator) instead
1010
// of direct string comparisons throughout the codebase.
1111
// ---------------------------------------------------------------------------
12-
export const LIBERTY_PROJECT_MAVEN = "libertyProject:maven";
13-
export const LIBERTY_PROJECT_GRADLE = "libertyProject:gradle";
14-
export const LIBERTY_PROJECT_MAVEN_CONTAINER = "libertyProject:maven:container";
15-
export const LIBERTY_PROJECT_GRADLE_CONTAINER = "libertyProject:gradle:container";
16-
export const LIBERTY_PROJECT_MAVEN_AGGREGATOR = "libertyProject:maven:aggregator";
12+
export const LIBERTY_PROJECT_MAVEN = "libertyProject:maven";
13+
export const LIBERTY_PROJECT_GRADLE = "libertyProject:gradle";
14+
export const LIBERTY_PROJECT_MAVEN_CONTAINER = "libertyProject:maven:container";
15+
export const LIBERTY_PROJECT_GRADLE_CONTAINER = "libertyProject:gradle:container";
16+
export const LIBERTY_PROJECT_MAVEN_AGGREGATOR = "libertyProject:maven:aggregator";
1717
export const LIBERTY_PROJECT_GRADLE_AGGREGATOR = "libertyProject:gradle:aggregator";
1818

1919
/** Returns true for any libertyProject contextValue (maven or gradle, any variant). */
@@ -43,9 +43,15 @@ export const LIBERTY_MAVEN_PLUGIN_CONTAINER_VERSION = "3.3.0";
4343
export const LIBERTY_GRADLE_PLUGIN_CONTAINER_VERSION = "3.1.0";
4444
export const LIBERTY_SERVER_ENV_PORT_REGEX = /^WLP_DEBUG_ADDRESS=([\d]+)$/;
4545

46+
export const MAVEN_GOAL_DEV = "io.openliberty.tools:liberty-maven-plugin:dev";
47+
export const MAVEN_GOAL_DEVC = "io.openliberty.tools:liberty-maven-plugin:devc";
48+
49+
export const GRADLE_TASK_DEV = "libertyDev";
50+
export const GRADLE_TASK_DEVC = "libertyDevc";
51+
4652
export const EXCLUDED_DIR_PATTERN = "**/{bin,classes,target,build}/**";
4753
export const COMMAND_TITLES = new Map();
48-
export const UNTITLED_WORKSPACE="Untitled (Workspace)";
54+
export const UNTITLED_WORKSPACE = "Untitled (Workspace)";
4955
COMMAND_TITLES.set(localize("hotkey.commands.title.refresh"), "liberty.explorer.refresh");
5056

5157
COMMAND_TITLES.set(localize("hotkey.commands.title.start"), "liberty.dev.start");

src/liberty/devCommands.ts

Lines changed: 44 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { LibertyProject } from "./libertyProject";
1313
import { ProjectRegistry } from "./projectRegistry";
1414
import { ProjectTreeProvider } from "./projectTreeProvider";
1515
import { getReport } from "../util/helperUtil";
16-
import { COMMAND_TITLES, LIBERTY_SERVER_ENV_PORT_REGEX, isMaven, isGradle, isContainer } from "../definitions/constants";
16+
import { COMMAND_TITLES, LIBERTY_SERVER_ENV_PORT_REGEX, isMaven, isGradle, MAVEN_GOAL_DEV, MAVEN_GOAL_DEVC, GRADLE_TASK_DEV, GRADLE_TASK_DEVC } from "../definitions/constants";
1717
import { getGradleTestReport } from "../util/gradleUtil";
1818
import { DashboardData } from "./dashboard";
1919
import { ProjectStartCmdParam } from "./projectStartCmdParam";
@@ -80,6 +80,43 @@ export async function listAllCommands(): Promise<void> {
8080
}
8181

8282

83+
/**
84+
* Ensures a terminal exists for the project, creates one if needed, shows it,
85+
* and registers it. Returns the terminal, or undefined if creation failed.
86+
*/
87+
function ensureTerminal(project: LibertyProject): vscode.Terminal | undefined {
88+
let terminal = project.getTerminal();
89+
if (terminal === undefined) {
90+
const terminalPath = project.parent
91+
? Path.dirname(project.parent.getPath())
92+
: Path.dirname(project.getPath());
93+
terminal = createTerminalforLiberty(project, terminal, terminalPath);
94+
}
95+
if (terminal !== undefined) {
96+
terminal.show();
97+
project.setTerminal(terminal);
98+
}
99+
return terminal;
100+
}
101+
102+
async function sendDevModeCommand(
103+
terminal: vscode.Terminal,
104+
project: LibertyProject,
105+
mavenGoal: string,
106+
gradleTask: string,
107+
customCommand?: string
108+
): Promise<void> {
109+
if (isMaven(project.getContextValue())) {
110+
const pomPath = project.parent ? project.parent.getPath() : project.getPath();
111+
const artifactId = project.parent ? project.artifactId : undefined;
112+
const cmd = await getCommandForMaven(pomPath, mavenGoal, project.getTerminalType(), customCommand, artifactId);
113+
terminal.sendText(cmd);
114+
} else if (isGradle(project.getContextValue())) {
115+
const cmd = await getCommandForGradle(project.getPath(), gradleTask, project.getTerminalType(), customCommand);
116+
terminal.sendText(cmd);
117+
}
118+
}
119+
83120
// start dev mode
84121
export async function startDevMode(libProject?: LibertyProject | undefined): Promise<void> {
85122
const projectProvider: ProjectTreeProvider = ProjectTreeProvider.getInstance();
@@ -94,32 +131,10 @@ export async function startDevMode(libProject?: LibertyProject | undefined): Pro
94131
return;
95132
}
96133

97-
// Check if user selected a child from an aggregator
98-
const originalIsAggregator = libProject?.isAggregator ?? false;
99-
const clickedDirectlyOnChild = !originalIsAggregator && targetProject.parent;
100-
101134
console.log(localize("starting.liberty.dev.on", targetProject.getLabel()));
102-
let terminal = targetProject.getTerminal();
103-
if (terminal === undefined) {
104-
const terminalPath = targetProject.parent
105-
? Path.dirname(targetProject.parent.getPath())
106-
: Path.dirname(targetProject.getPath());
107-
terminal = createTerminalforLiberty(targetProject, terminal, terminalPath);
108-
}
135+
const terminal = ensureTerminal(targetProject);
109136
if (terminal !== undefined) {
110-
terminal.show();
111-
targetProject.setTerminal(terminal);
112-
if (isMaven(targetProject.getContextValue())) {
113-
const pomPath = targetProject.parent ? targetProject.parent.getPath() : targetProject.getPath();
114-
const artifactId = (targetProject.parent && (clickedDirectlyOnChild || ProjectRegistry.getInstance().findLibertyDescendants(targetProject.parent).length > 1))
115-
? targetProject.artifactId
116-
: undefined;
117-
const cmd = await getCommandForMaven(pomPath, "io.openliberty.tools:liberty-maven-plugin:dev", targetProject.getTerminalType(), undefined, artifactId);
118-
terminal.sendText(cmd);
119-
} else if (isGradle(targetProject.getContextValue())) {
120-
const cmd = await getCommandForGradle(targetProject.getPath(), "libertyDev", targetProject.getTerminalType());
121-
terminal.sendText(cmd);
122-
}
137+
await sendDevModeCommand(terminal, targetProject, MAVEN_GOAL_DEV, GRADLE_TASK_DEV);
123138
targetProject.isDevMode = true;
124139
projectProvider.notifyDevModeChanged(targetProject);
125140
}
@@ -374,19 +389,8 @@ export async function customDevMode(libProject?: LibertyProject | undefined, par
374389
const registry = ProjectRegistry.getInstance();
375390
const targetProject = libProject;
376391

377-
// Check if this is a child of an aggregator
378-
const clickedDirectlyOnChild = targetProject.parent !== undefined;
379-
380-
let terminal = targetProject.getTerminal();
381-
if (terminal === undefined) {
382-
const terminalPath = targetProject.parent
383-
? Path.dirname(targetProject.parent.getPath())
384-
: Path.dirname(targetProject.getPath());
385-
terminal = createTerminalforLiberty(targetProject, terminal, terminalPath);
386-
}
392+
const terminal = ensureTerminal(targetProject);
387393
if (terminal !== undefined) {
388-
terminal.show();
389-
targetProject.setTerminal(terminal);
390394

391395
let placeHolderStr = "";
392396
let promptString = localize("specify.custom.parms.maven");
@@ -425,17 +429,7 @@ export async function customDevMode(libProject?: LibertyProject | undefined, par
425429
await helperUtil.saveStorageData(registry.getContext(), dashboardData);
426430
}
427431

428-
if (isMaven(targetProject.getContextValue())) {
429-
const pomPath = targetProject.parent ? targetProject.parent.getPath() : targetProject.getPath();
430-
const artifactId = (targetProject.parent && (clickedDirectlyOnChild || registry.findLibertyDescendants(targetProject.parent).length > 1))
431-
? targetProject.artifactId
432-
: undefined;
433-
const cmd = await getCommandForMaven(pomPath, "io.openliberty.tools:liberty-maven-plugin:dev", targetProject.getTerminalType(), customCommand, artifactId);
434-
terminal.sendText(cmd);
435-
} else if (isGradle(targetProject.getContextValue())) {
436-
const cmd = await getCommandForGradle(targetProject.getPath(), "libertyDev", targetProject.getTerminalType(), customCommand);
437-
terminal.sendText(cmd);
438-
}
432+
await sendDevModeCommand(terminal, targetProject, MAVEN_GOAL_DEV, GRADLE_TASK_DEV, customCommand);
439433
targetProject.isDevMode = true;
440434
projectProvider.notifyDevModeChanged(targetProject);
441435
}
@@ -456,29 +450,9 @@ export async function startContainerDevMode(libProject?: LibertyProject | undefi
456450
return;
457451
}
458452

459-
const clickedDirectlyOnChild = !(libProject?.isAggregator ?? false) && targetProject.parent;
460-
461-
let terminal = targetProject.getTerminal();
462-
if (terminal === undefined) {
463-
const terminalPath = targetProject.parent
464-
? Path.dirname(targetProject.parent.getPath())
465-
: Path.dirname(targetProject.getPath());
466-
terminal = createTerminalforLiberty(targetProject, terminal, terminalPath);
467-
}
453+
const terminal = ensureTerminal(targetProject);
468454
if (terminal !== undefined) {
469-
terminal.show();
470-
targetProject.setTerminal(terminal);
471-
if (isContainer(targetProject.getContextValue()) && isMaven(targetProject.getContextValue())) {
472-
const pomPath = targetProject.parent ? targetProject.parent.getPath() : targetProject.getPath();
473-
const artifactId = (targetProject.parent && (clickedDirectlyOnChild || ProjectRegistry.getInstance().findLibertyDescendants(targetProject.parent).length > 1))
474-
? targetProject.artifactId
475-
: undefined;
476-
const cmd = await getCommandForMaven(pomPath, "io.openliberty.tools:liberty-maven-plugin:devc", targetProject.getTerminalType(), undefined, artifactId);
477-
terminal.sendText(cmd);
478-
} else if (isContainer(targetProject.getContextValue()) && isGradle(targetProject.getContextValue())) {
479-
const cmd = await getCommandForGradle(targetProject.getPath(), "libertyDevc", targetProject.getTerminalType());
480-
terminal.sendText(cmd);
481-
}
455+
await sendDevModeCommand(terminal, targetProject, MAVEN_GOAL_DEVC, GRADLE_TASK_DEVC);
482456
targetProject.isDevMode = true;
483457
projectProvider.notifyDevModeChanged(targetProject);
484458
}

0 commit comments

Comments
 (0)