Skip to content

Commit 1afcdc5

Browse files
committed
pull commands into constants
1 parent 72d49d6 commit 1afcdc5

5 files changed

Lines changed: 113 additions & 72 deletions

File tree

src/definitions/constants.ts

Lines changed: 61 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
import { localize } from "../util/i18nUtil";
66

77
// ---------------------------------------------------------------------------
8-
// New contextValue scheme: libertyProject:{tool}[:{container|aggregator}]
9-
// Use the helpers below (isMaven, isGradle, isContainer, isAggregator) instead
10-
// of direct string comparisons throughout the codebase.
8+
// Project Context Values
9+
// contextValue scheme: libertyProject:{tool}[:{container|aggregator}]
10+
// Use the helpers below instead of direct string comparisons.
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). */
@@ -37,36 +37,64 @@ export function isAggregator(contextValue: string): boolean {
3737
return /^libertyProject.*:aggregator/.test(contextValue);
3838
}
3939

40-
export const TEST_REPORT_STRING = "Test Summary";
41-
export const LIBERTY_DASHBOARD_WORKSPACE_STORAGE_KEY = "liberty.dashboard.data";
42-
export const LIBERTY_MAVEN_PLUGIN_CONTAINER_VERSION = "3.3.0";
43-
export const LIBERTY_GRADLE_PLUGIN_CONTAINER_VERSION = "3.1.0";
44-
export const LIBERTY_SERVER_ENV_PORT_REGEX = /^WLP_DEBUG_ADDRESS=([\d]+)$/;
45-
46-
export const MAVEN_GOAL_DEV = "io.openliberty.tools:liberty-maven-plugin:dev";
40+
// ---------------------------------------------------------------------------
41+
// Dev Mode
42+
// Maven goals are passed to the Maven executable (mvn/mvnw) via terminal.
43+
// Gradle tasks are passed to the Gradle executable (gradle/gradlew) via terminal.
44+
// Container version thresholds gate whether devc is available for a project.
45+
// ---------------------------------------------------------------------------
46+
export const MAVEN_GOAL_DEV = "io.openliberty.tools:liberty-maven-plugin:dev";
4747
export const MAVEN_GOAL_DEVC = "io.openliberty.tools:liberty-maven-plugin:devc";
4848

49-
export const GRADLE_TASK_DEV = "libertyDev";
49+
export const GRADLE_TASK_DEV = "libertyDev";
5050
export const GRADLE_TASK_DEVC = "libertyDevc";
5151

52-
export const EXCLUDED_DIR_PATTERN = "**/{bin,classes,target,build}/**";
53-
export const COMMAND_TITLES = new Map();
54-
export const UNTITLED_WORKSPACE = "Untitled (Workspace)";
55-
COMMAND_TITLES.set(localize("hotkey.commands.title.refresh"), "liberty.explorer.refresh");
56-
57-
COMMAND_TITLES.set(localize("hotkey.commands.title.start"), "liberty.dev.start");
58-
COMMAND_TITLES.set(localize("hotkey.commands.title.start.custom"), "liberty.dev.custom");
59-
COMMAND_TITLES.set(localize("hotkey.commands.title.start.in.container"), "liberty.dev.start.container");
52+
export const LIBERTY_MAVEN_PLUGIN_CONTAINER_VERSION = "3.3.0";
53+
export const LIBERTY_GRADLE_PLUGIN_CONTAINER_VERSION = "3.1.0";
6054

61-
COMMAND_TITLES.set(localize("hotkey.commands.title.debug"), "liberty.dev.debug");
55+
// ---------------------------------------------------------------------------
56+
// VS Code Commands
57+
// Must match package.json contributes.commands[].command declarations.
58+
// ---------------------------------------------------------------------------
59+
export const CMD_EXPLORER_REFRESH = "liberty.explorer.refresh";
60+
export const CMD_SHOW_COMMANDS = "liberty.dev.show.commands";
61+
export const CMD_OPEN_BUILD_FILE = "liberty.dev.open.build.file";
62+
export const CMD_START = "liberty.dev.start";
63+
export const CMD_DEBUG = "liberty.dev.debug";
64+
export const CMD_STOP = "liberty.dev.stop";
65+
export const CMD_CUSTOM = "liberty.dev.custom";
66+
export const CMD_START_CONTAINER = "liberty.dev.start.container";
67+
export const CMD_RUN_TESTS = "liberty.dev.run.tests";
68+
export const CMD_OPEN_FAILSAFE_REPORT = "liberty.dev.open.failsafe.report";
69+
export const CMD_OPEN_SUREFIRE_REPORT = "liberty.dev.open.surefire.report";
70+
export const CMD_OPEN_GRADLE_TEST_REPORT = "liberty.dev.open.gradle.test.report";
71+
export const CMD_ADD_PROJECT = "liberty.dev.add.project";
72+
export const CMD_REMOVE_PROJECT = "liberty.dev.remove.project";
6273

63-
COMMAND_TITLES.set(localize("hotkey.commands.title.stop"), "liberty.dev.stop");
74+
export const COMMAND_TITLES = new Map();
75+
COMMAND_TITLES.set(localize("hotkey.commands.title.refresh"), CMD_EXPLORER_REFRESH);
76+
COMMAND_TITLES.set(localize("hotkey.commands.title.start"), CMD_START);
77+
COMMAND_TITLES.set(localize("hotkey.commands.title.start.custom"), CMD_CUSTOM);
78+
COMMAND_TITLES.set(localize("hotkey.commands.title.start.in.container"), CMD_START_CONTAINER);
79+
COMMAND_TITLES.set(localize("hotkey.commands.title.debug"), CMD_DEBUG);
80+
COMMAND_TITLES.set(localize("hotkey.commands.title.stop"), CMD_STOP);
81+
COMMAND_TITLES.set(localize("hotkey.commands.title.run.tests"), CMD_RUN_TESTS);
82+
COMMAND_TITLES.set(localize("hotkey.commands.title.view.integration.test.report"), CMD_OPEN_FAILSAFE_REPORT);
83+
COMMAND_TITLES.set(localize("hotkey.commands.title.view.unit.test.report"), CMD_OPEN_SUREFIRE_REPORT);
84+
COMMAND_TITLES.set(localize("hotkey.commands.title.view.test.report"), CMD_OPEN_GRADLE_TEST_REPORT);
85+
COMMAND_TITLES.set(localize("hotkey.commands.title.add.project"), CMD_ADD_PROJECT);
86+
COMMAND_TITLES.set(localize("hotkey.commands.title.remove.project"), CMD_REMOVE_PROJECT);
87+
COMMAND_TITLES.set(localize("hotkey.commands.title.open.build.file"), CMD_OPEN_BUILD_FILE);
6488

65-
COMMAND_TITLES.set(localize("hotkey.commands.title.run.tests"), "liberty.dev.run.tests");
66-
COMMAND_TITLES.set(localize("hotkey.commands.title.view.integration.test.report"), "liberty.dev.open.failsafe.report");
67-
COMMAND_TITLES.set(localize("hotkey.commands.title.view.unit.test.report"), "liberty.dev.open.surefire.report");
68-
COMMAND_TITLES.set(localize("hotkey.commands.title.view.test.report"), "liberty.dev.open.gradle.test.report");
89+
// ---------------------------------------------------------------------------
90+
// Project Discovery
91+
// ---------------------------------------------------------------------------
92+
export const EXCLUDED_DIR_PATTERN = "**/{bin,classes,target,build}/**";
6993

70-
COMMAND_TITLES.set(localize("hotkey.commands.title.add.project"), "liberty.dev.add.project");
71-
COMMAND_TITLES.set(localize("hotkey.commands.title.remove.project"), "liberty.dev.remove.project");
72-
COMMAND_TITLES.set(localize("hotkey.commands.title.open.build.file"), "liberty.dev.open.build.file");
94+
// ---------------------------------------------------------------------------
95+
// Runtime
96+
// ---------------------------------------------------------------------------
97+
export const LIBERTY_SERVER_ENV_PORT_REGEX = /^WLP_DEBUG_ADDRESS=([\d]+)$/;
98+
export const LIBERTY_DASHBOARD_WORKSPACE_STORAGE_KEY = "liberty.dashboard.data";
99+
export const TEST_REPORT_STRING = "Test Summary";
100+
export const UNTITLED_WORKSPACE = "Untitled (Workspace)";

src/extension.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ import { localize } from "./util/i18nUtil";
1616
import { RequirementsData, resolveRequirements, resolveLclsRequirements } from "./util/requirements";
1717
import { prepareExecutable } from "./util/javaServerStarter";
1818
import * as helperUtil from "./util/helperUtil";
19+
import {
20+
CMD_EXPLORER_REFRESH, CMD_SHOW_COMMANDS, CMD_OPEN_BUILD_FILE,
21+
CMD_START, CMD_DEBUG, CMD_STOP, CMD_CUSTOM, CMD_START_CONTAINER,
22+
CMD_RUN_TESTS, CMD_OPEN_FAILSAFE_REPORT, CMD_OPEN_SUREFIRE_REPORT,
23+
CMD_OPEN_GRADLE_TEST_REPORT, CMD_ADD_PROJECT, CMD_REMOVE_PROJECT,
24+
} from "./definitions/constants";
1925
import path = require('path');
2026
import * as fs from "fs";
2127

@@ -147,7 +153,7 @@ function registerCommands(context: ExtensionContext) {
147153
handleWorkspaceSaveInProgress(context);
148154

149155
context.subscriptions.push(
150-
vscode.commands.registerCommand("liberty.explorer.refresh", (async () => {
156+
vscode.commands.registerCommand(CMD_EXPLORER_REFRESH, (async () => {
151157
projectProvider.refresh();
152158
}))
153159
);
@@ -156,43 +162,43 @@ function registerCommands(context: ExtensionContext) {
156162
vscode.commands.registerCommand("extension.open.project", (pomPath) => devCommands.openProject(pomPath)),
157163
);
158164
context.subscriptions.push(
159-
vscode.commands.registerCommand("liberty.dev.open.build.file", (libProject?: LibertyProject) => devCommands.openBuildFile(libProject)),
165+
vscode.commands.registerCommand(CMD_OPEN_BUILD_FILE, (libProject?: LibertyProject) => devCommands.openBuildFile(libProject)),
160166
);
161167
context.subscriptions.push(
162-
vscode.commands.registerCommand("liberty.dev.show.commands", () => devCommands.listAllCommands()),
168+
vscode.commands.registerCommand(CMD_SHOW_COMMANDS, () => devCommands.listAllCommands()),
163169
);
164170
context.subscriptions.push(
165-
vscode.commands.registerCommand("liberty.dev.start", (libProject?: LibertyProject) => devCommands.startDevMode(libProject)),
171+
vscode.commands.registerCommand(CMD_START, (libProject?: LibertyProject) => devCommands.startDevMode(libProject)),
166172
);
167173
context.subscriptions.push(
168-
vscode.commands.registerCommand("liberty.dev.debug", (libProject?: LibertyProject) => devCommands.attachDebugger(libProject)),
174+
vscode.commands.registerCommand(CMD_DEBUG, (libProject?: LibertyProject) => devCommands.attachDebugger(libProject)),
169175
);
170176
context.subscriptions.push(
171-
vscode.commands.registerCommand("liberty.dev.stop", (libProject?: LibertyProject) => devCommands.stopDevMode(libProject)),
177+
vscode.commands.registerCommand(CMD_STOP, (libProject?: LibertyProject) => devCommands.stopDevMode(libProject)),
172178
);
173179
context.subscriptions.push(
174-
vscode.commands.registerCommand("liberty.dev.custom", (libProject?: LibertyProject) => devCommands.customDevModeWithHistory(libProject)),
180+
vscode.commands.registerCommand(CMD_CUSTOM, (libProject?: LibertyProject) => devCommands.customDevModeWithHistory(libProject)),
175181
);
176182
context.subscriptions.push(
177-
vscode.commands.registerCommand("liberty.dev.start.container", (libProject?: LibertyProject) => devCommands.startContainerDevMode(libProject)),
183+
vscode.commands.registerCommand(CMD_START_CONTAINER, (libProject?: LibertyProject) => devCommands.startContainerDevMode(libProject)),
178184
);
179185
context.subscriptions.push(
180-
vscode.commands.registerCommand("liberty.dev.run.tests", (libProject?: LibertyProject) => devCommands.runTests(libProject)),
186+
vscode.commands.registerCommand(CMD_RUN_TESTS, (libProject?: LibertyProject) => devCommands.runTests(libProject)),
181187
);
182188
context.subscriptions.push(
183-
vscode.commands.registerCommand("liberty.dev.open.failsafe.report", (libProject?: LibertyProject) => devCommands.openReport("failsafe", libProject)),
189+
vscode.commands.registerCommand(CMD_OPEN_FAILSAFE_REPORT, (libProject?: LibertyProject) => devCommands.openReport("failsafe", libProject)),
184190
);
185191
context.subscriptions.push(
186-
vscode.commands.registerCommand("liberty.dev.open.surefire.report", (libProject?: LibertyProject) => devCommands.openReport("surefire", libProject)),
192+
vscode.commands.registerCommand(CMD_OPEN_SUREFIRE_REPORT, (libProject?: LibertyProject) => devCommands.openReport("surefire", libProject)),
187193
);
188194
context.subscriptions.push(
189-
vscode.commands.registerCommand("liberty.dev.open.gradle.test.report", (libProject?: LibertyProject) => devCommands.openReport("gradle", libProject)),
195+
vscode.commands.registerCommand(CMD_OPEN_GRADLE_TEST_REPORT, (libProject?: LibertyProject) => devCommands.openReport("gradle", libProject)),
190196
);
191197
context.subscriptions.push(
192-
vscode.commands.registerCommand("liberty.dev.add.project", (uri: vscode.Uri) => devCommands.addProject(uri)),
198+
vscode.commands.registerCommand(CMD_ADD_PROJECT, (uri: vscode.Uri) => devCommands.addProject(uri)),
193199
);
194200
context.subscriptions.push(
195-
vscode.commands.registerCommand("liberty.dev.remove.project", () => devCommands.removeProject()),
201+
vscode.commands.registerCommand(CMD_REMOVE_PROJECT, () => devCommands.removeProject()),
196202
);
197203
context.subscriptions.push(
198204
vscode.window.onDidCloseTerminal((closedTerminal: vscode.Terminal) => {

src/liberty/devCommands.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ 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, MAVEN_GOAL_DEV, MAVEN_GOAL_DEVC, GRADLE_TASK_DEV, GRADLE_TASK_DEVC } from "../definitions/constants";
16+
import {
17+
COMMAND_TITLES, LIBERTY_SERVER_ENV_PORT_REGEX, isMaven, isGradle,
18+
MAVEN_GOAL_DEV, MAVEN_GOAL_DEVC, GRADLE_TASK_DEV, GRADLE_TASK_DEVC,
19+
CMD_OPEN_BUILD_FILE, CMD_START, CMD_STOP, CMD_DEBUG, CMD_CUSTOM,
20+
CMD_START_CONTAINER, CMD_RUN_TESTS,
21+
} from "../definitions/constants";
1722
import { getGradleTestReport } from "../util/gradleUtil";
1823
import { DashboardData } from "./dashboard";
1924
import { ProjectStartCmdParam } from "./projectStartCmdParam";
@@ -54,7 +59,7 @@ export async function openBuildFile(libProject?: LibertyProject): Promise<void>
5459
vscode.commands.executeCommand("vscode.open", vscode.Uri.file(libProject.getPath()));
5560
return;
5661
}
57-
const targetProject = await projectProvider.pickProject(undefined, "liberty.dev.open.build.file");
62+
const targetProject = await projectProvider.pickProject(undefined, CMD_OPEN_BUILD_FILE);
5863
if (targetProject === undefined) {
5964
return;
6065
}
@@ -126,7 +131,7 @@ export async function startDevMode(libProject?: LibertyProject | undefined): Pro
126131
vscode.window.showInformationMessage(message);
127132
return;
128133
}
129-
const targetProject = await projectProvider.pickProject(libProject, "liberty.dev.start");
134+
const targetProject = await projectProvider.pickProject(libProject, CMD_START);
130135
if (targetProject === undefined) {
131136
return;
132137
}
@@ -254,7 +259,7 @@ export async function stopDevMode(libProject?: LibertyProject | undefined): Prom
254259
vscode.window.showInformationMessage(message);
255260
return;
256261
}
257-
const targetProject = await projectProvider.pickProject(libProject, "liberty.dev.stop");
262+
const targetProject = await projectProvider.pickProject(libProject, CMD_STOP);
258263
if (targetProject === undefined) {
259264
return;
260265
}
@@ -282,7 +287,7 @@ export async function attachDebugger(libProject?: LibertyProject | undefined): P
282287
vscode.window.showErrorMessage(message);
283288
return;
284289
}
285-
const targetProject = await projectProvider.pickProject(libProject, "liberty.dev.debug");
290+
const targetProject = await projectProvider.pickProject(libProject, CMD_DEBUG);
286291
if (targetProject === undefined) {
287292
return;
288293
}
@@ -348,7 +353,7 @@ export async function customDevModeWithHistory(libProject?: LibertyProject | und
348353
vscode.window.showInformationMessage(message);
349354
return;
350355
}
351-
const targetProject = await projectProvider.pickProject(libProject, "liberty.dev.custom");
356+
const targetProject = await projectProvider.pickProject(libProject, CMD_CUSTOM);
352357
if (targetProject === undefined) {
353358
return;
354359
}
@@ -393,12 +398,12 @@ export async function customDevMode(libProject?: LibertyProject | undefined, par
393398
if (terminal !== undefined) {
394399

395400
let placeHolderStr = "";
396-
let promptString = localize("specify.custom.parms.maven");
401+
let promptString = localize("specify.custom.params.maven");
397402
if (isMaven(targetProject.getContextValue())) {
398403
placeHolderStr = "e.g. -DhotTests=true";
399404
} else if (isGradle(targetProject.getContextValue())) {
400405
placeHolderStr = "e.g. --hotTests";
401-
promptString = localize("specify.custom.parms.gradle");
406+
promptString = localize("specify.custom.params.gradle");
402407
}
403408

404409
// set focus on the Inputbox
@@ -445,7 +450,7 @@ export async function startContainerDevMode(libProject?: LibertyProject | undefi
445450
vscode.window.showInformationMessage(message);
446451
return;
447452
}
448-
const targetProject = await projectProvider.pickProject(libProject, "liberty.dev.start.container");
453+
const targetProject = await projectProvider.pickProject(libProject, CMD_START_CONTAINER);
449454
if (targetProject === undefined) {
450455
return;
451456
}
@@ -467,7 +472,7 @@ export async function runTests(libProject?: LibertyProject | undefined): Promise
467472
vscode.window.showInformationMessage(message);
468473
return;
469474
}
470-
const targetProject = await projectProvider.pickProject(libProject, "liberty.dev.run.tests");
475+
const targetProject = await projectProvider.pickProject(libProject, CMD_RUN_TESTS);
471476
if (targetProject === undefined) {
472477
return;
473478
}

src/locales/en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"cannot.stop.liberty.dev.on.undefined": "Cannot stop Liberty dev mode on an undefined project.",
2020
"params.must.start.with.dash": "Parameters must start with -",
2121
"starting.liberty.dev.with.custom.param": "Starting Liberty dev mode with custom parameters on {0}.",
22-
"specify.custom.parms.maven": "Specify custom parameters for 'mvn liberty:dev' command.",
23-
"specify.custom.parms.gradle": "Specify custom parameters for 'gradle libertyDev' command.",
22+
"specify.custom.params.maven": "Specify custom parameters for 'mvn liberty:dev' command.",
23+
"specify.custom.params.gradle": "Specify custom parameters for 'gradle libertyDev' command.",
2424
"cannot.custom.start.liberty.dev": "Cannot custom start Liberty dev mode on an undefined project.",
2525
"cannot.start.liberty.dev.in.container.on.undefined.project": "Cannot start Liberty dev mode in a container on an undefined project.",
2626
"running.liberty.dev.tests.on": "Running Liberty dev mode tests on {0}.",

0 commit comments

Comments
 (0)