Skip to content

Commit 777fa83

Browse files
Adam WisniewskiAdam Wisniewski
authored andcommitted
Add custom start command config
Signed-off-by: Adam Wisniewski <[email protected]>
1 parent 8387f4b commit 777fa83

File tree

9 files changed

+336
-90
lines changed

9 files changed

+336
-90
lines changed

bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/DevModeOperations.java

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ public class DevModeOperations {
8181
"stopJobCompletionOutput");
8282
private Map<Job, Boolean> runningJobs = new ConcurrentHashMap<Job, Boolean>();
8383

84+
/** Default Maven devc command */
85+
public static final String DEFAULT_MAVEN_DEVC = "io.openliberty.tools:liberty-maven-plugin:devc";
86+
87+
/** Default Maven dev command */
88+
public static final String DEFAULT_MAVEN_DEV = "io.openliberty.tools:liberty-maven-plugin:dev";
89+
90+
/** Default Gradle devc command */
91+
public static final String DEFAULT_GRADLE_DEVC = "libertyDevc";
92+
93+
/** Default Gradle dev command */
94+
public static final String DEFAULT_GRADLE_DEV = "libertyDev";
95+
8496
/**
8597
* Project terminal tab controller instance.
8698
*/
@@ -149,10 +161,10 @@ public static DevModeOperations getInstance() {
149161
* @param javaHomePath The configuration java installation home to be set in the terminal running dev mode.
150162
* @param mode The configuration mode.
151163
*/
152-
public void start(IProject iProject, String preStartGoals, String parms, String javaHomePath, String mode) {
164+
public void start(IProject iProject, String launchCommand, String javaHomePath, String mode) {
153165

154166
if (Trace.isEnabled()) {
155-
Trace.getTracer().traceEntry(Trace.TRACE_TOOLS, new Object[] { iProject, preStartGoals, parms, javaHomePath, mode });
167+
Trace.getTracer().traceEntry(Trace.TRACE_TOOLS, new Object[] { iProject, launchCommand, javaHomePath, mode });
156168
}
157169

158170
if (iProject == null) {
@@ -207,28 +219,21 @@ public void start(IProject iProject, String preStartGoals, String parms, String
207219
throw new Exception("Unable to find the path to selected project " + projectName);
208220
}
209221

210-
String userPreStartGoals = (preStartGoals == null) ? "" : preStartGoals.trim();
211-
212-
// If in debug mode, adjust the start parameters.
213-
String userParms = (parms == null) ? "" : parms.trim();
214-
String startParms = null;
215222
String debugPort = null;
216223
if (ILaunchManager.DEBUG_MODE.equals(mode)) {
217-
debugPort = debugModeHandler.calculateDebugPort(project, userParms);
218-
startParms = debugModeHandler.addDebugDataToStartParms(project, debugPort, userParms);
219-
} else {
220-
startParms = userParms;
224+
debugPort = debugModeHandler.calculateDebugPort(project, launchCommand);
225+
launchCommand = debugModeHandler.addDebugDataToStartParms(project, debugPort, launchCommand);
221226
}
222227

223228
// Prepare the Liberty plugin container dev mode command.
224229
String cmd = "";
225230
BuildType buildType = project.getBuildType();
226231
if (buildType == Project.BuildType.MAVEN) {
227-
cmd = CommandBuilder.getMavenCommandLine(projectPath, userPreStartGoals.trim() +
228-
" io.openliberty.tools:liberty-maven-plugin:dev " + startParms,
232+
cmd = CommandBuilder.getMavenCommandLine(projectPath, launchCommand,
229233
pathEnv, true);
230234
} else if (buildType == Project.BuildType.GRADLE) {
231-
cmd = CommandBuilder.getGradleCommandLine(projectPath, "libertyDev " + startParms, pathEnv, true);
235+
cmd = CommandBuilder.getGradleCommandLine(projectPath, launchCommand,
236+
pathEnv, true);
232237
} else {
233238
throw new Exception("Unexpected project build type: " + buildType + ". Project " + projectName
234239
+ "does not appear to be a Maven or Gradle built project.");
@@ -265,14 +270,14 @@ public void start(IProject iProject, String preStartGoals, String parms, String
265270
* Starts the Liberty server in dev mode in a container.
266271
*
267272
* @param iProject The project instance to associate with this action.
268-
* @param parms The configuration parameters to be used when starting dev mode.
273+
* @param launchCommand The configuration launch comand to be used when starting dev mode.
269274
* @param javaHomePath The configuration java installation home to be set in the terminal running dev mode.
270275
* @param mode The configuration mode.
271276
*/
272-
public void startInContainer(IProject iProject, String preStartGoals, String parms, String javaHomePath, String mode) {
277+
public void startInContainer(IProject iProject, String launchCommand, String javaHomePath, String mode) {
273278

274279
if (Trace.isEnabled()) {
275-
Trace.getTracer().traceEntry(Trace.TRACE_TOOLS, new Object[] { iProject, parms, javaHomePath, mode });
280+
Trace.getTracer().traceEntry(Trace.TRACE_TOOLS, new Object[] { iProject, launchCommand, javaHomePath, mode });
276281
}
277282

278283
if (iProject == null) {
@@ -328,25 +333,19 @@ public void startInContainer(IProject iProject, String preStartGoals, String par
328333
}
329334

330335
// If in debug mode, adjust the start parameters.
331-
String userParms = (parms == null) ? "" : parms.trim();
332-
String startParms = null;
333336
String debugPort = null;
334337
if (ILaunchManager.DEBUG_MODE.equals(mode)) {
335-
debugPort = debugModeHandler.calculateDebugPort(project, userParms);
336-
startParms = debugModeHandler.addDebugDataToStartParms(project, debugPort, userParms);
337-
} else {
338-
startParms = userParms;
338+
debugPort = debugModeHandler.calculateDebugPort(project, launchCommand);
339+
launchCommand = debugModeHandler.addDebugDataToStartParms(project, debugPort, launchCommand);
339340
}
340341

341342
// Prepare the Liberty plugin container dev mode command.
342343
String cmd = "";
343344
BuildType buildType = project.getBuildType();
344345
if (buildType == Project.BuildType.MAVEN) {
345-
cmd = CommandBuilder.getMavenCommandLine(projectPath,
346-
preStartGoals.trim() + " io.openliberty.tools:liberty-maven-plugin:devc " + startParms,
347-
pathEnv, true);
346+
cmd = CommandBuilder.getMavenCommandLine(projectPath, launchCommand, pathEnv, true);
348347
} else if (buildType == Project.BuildType.GRADLE) {
349-
cmd = CommandBuilder.getGradleCommandLine(projectPath, "libertyDevc " + startParms, pathEnv, true);
348+
cmd = CommandBuilder.getGradleCommandLine(projectPath, launchCommand, pathEnv, true);
350349
} else {
351350
throw new Exception("Unexpected project build type: " + buildType + ". Project " + projectName
352351
+ "does not appear to be a Maven or Gradle built project.");

bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/WorkspaceProjectsModel.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
import org.eclipse.core.resources.IWorkspaceRoot;
2626
import org.eclipse.core.resources.ResourcesPlugin;
2727

28+
import io.openliberty.tools.eclipse.Project.BuildType;
2829
import io.openliberty.tools.eclipse.logging.Trace;
30+
import io.openliberty.tools.eclipse.ui.launch.LaunchConfigurationDelegateLauncher.RuntimeEnv;
2931
import io.openliberty.tools.eclipse.utils.ErrorHandler;
3032

3133
/**
@@ -250,6 +252,44 @@ public String getDefaultStartParameters(IProject iProject) {
250252
return retVal;
251253
}
252254

255+
/**
256+
* @param iProject
257+
*
258+
* @return start command to serve as default populating something like a Run Configuration
259+
*/
260+
public String getDefaultStartCommand(IProject iProject, RuntimeEnv runtimeEnv) {
261+
262+
if (Trace.isEnabled()) {
263+
Trace.getTracer().traceEntry(Trace.TRACE_TOOLS, new Object[] { iProject });
264+
}
265+
266+
String retVal = null;
267+
268+
Project project = projectsByName.get(iProject.getName());
269+
BuildType buildType = project.getBuildType();
270+
271+
if (buildType == Project.BuildType.MAVEN) {
272+
273+
if (runtimeEnv.equals(RuntimeEnv.CONTAINER)) {
274+
retVal = DevModeOperations.DEFAULT_MAVEN_DEVC;
275+
} else {
276+
retVal = DevModeOperations.DEFAULT_MAVEN_DEV;
277+
}
278+
} else if (buildType == Project.BuildType.GRADLE) {
279+
280+
if (runtimeEnv.equals(RuntimeEnv.CONTAINER)) {
281+
retVal = DevModeOperations.DEFAULT_GRADLE_DEVC;
282+
} else {
283+
retVal = DevModeOperations.DEFAULT_GRADLE_DEV;
284+
}
285+
}
286+
if (Trace.isEnabled()) {
287+
Trace.getTracer().traceExit(Trace.TRACE_TOOLS, retVal);
288+
}
289+
290+
return retVal;
291+
}
292+
253293
private String getModuleNameSegment(IProject iProject) {
254294
return iProject.getRawLocation().lastSegment();
255295
}

bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/ui/launch/LaunchConfigurationHelper.java

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,37 @@ public ILaunchConfiguration getLaunchConfiguration(IProject iProject, String mod
6969
List<ILaunchConfiguration> matchingConfigList = filterLaunchConfigurations(existingConfigs, iProject.getName(), runtimeEnv);
7070

7171
switch (matchingConfigList.size()) {
72-
case 0:
73-
// Create a new configuration.
74-
String newName = iLaunchMgr.generateLaunchConfigurationName(iProject.getName());
75-
ILaunchConfigurationWorkingCopy workingCopy = iLaunchConfigType.newInstance(null, newName);
76-
workingCopy.setAttribute(StartTab.PROJECT_NAME, iProject.getName());
77-
workingCopy.setAttribute(StartTab.PROJECT_START_PARM, devModeOps.getProjectModel().getDefaultStartParameters(iProject));
78-
//default to 'false', no container
79-
boolean runInContainer = runtimeEnv.equals(RuntimeEnv.CONTAINER);
80-
workingCopy.setAttribute(StartTab.PROJECT_RUN_IN_CONTAINER, runInContainer);
81-
82-
String defaultJavaDef = JRETab.getDefaultJavaFromBuildPath(iProject);
83-
if (defaultJavaDef != null) {
84-
workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, defaultJavaDef);
85-
}
72+
case 0:
73+
// Create a new configuration.
74+
String newName = iLaunchMgr.generateLaunchConfigurationName(iProject.getName());
75+
ILaunchConfigurationWorkingCopy workingCopy = iLaunchConfigType.newInstance(null, newName);
76+
workingCopy.setAttribute(StartTab.PROJECT_NAME, iProject.getName());
77+
workingCopy.setAttribute(StartTab.PROJECT_START_PARM, devModeOps.getProjectModel().getDefaultStartParameters(iProject));
78+
workingCopy.setAttribute(StartTab.PROJECT_PRE_START_GOALS, (String) null);
79+
80+
workingCopy.setAttribute(StartTab.PROJECT_LAUNCH_COMMAND,
81+
devModeOps.getProjectModel().getDefaultStartCommand(iProject, runtimeEnv) + " "
82+
+ devModeOps.getProjectModel().getDefaultStartParameters(iProject));
83+
84+
// default to 'false', no container
85+
boolean runInContainer = runtimeEnv.equals(RuntimeEnv.CONTAINER);
86+
workingCopy.setAttribute(StartTab.PROJECT_RUN_IN_CONTAINER, runInContainer);
87+
88+
String defaultJavaDef = JRETab.getDefaultJavaFromBuildPath(iProject);
89+
if (defaultJavaDef != null) {
90+
workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, defaultJavaDef);
91+
}
8692

87-
configuration = workingCopy.doSave();
88-
break;
89-
case 1:
90-
// Return the found configuration.
91-
configuration = matchingConfigList.get(0);
92-
break;
93-
default:
94-
// Return the configuration that was run last.
95-
configuration = getLastRunConfiguration(matchingConfigList);
96-
break;
93+
configuration = workingCopy.doSave();
94+
break;
95+
case 1:
96+
// Return the found configuration.
97+
configuration = matchingConfigList.get(0);
98+
break;
99+
default:
100+
// Return the configuration that was run last.
101+
configuration = getLastRunConfiguration(matchingConfigList);
102+
break;
97103
}
98104

99105
return configuration;

0 commit comments

Comments
 (0)