Skip to content

Commit 8336857

Browse files
committed
Add console coloring config option
Signed-off-by: Adam Wisniewski <awisniew@us.ibm.com>
1 parent 047a542 commit 8336857

File tree

4 files changed

+89
-10
lines changed

4 files changed

+89
-10
lines changed

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

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,12 @@ public static DevModeOperations getInstance() {
158158
/**
159159
* @param iProject The project instance to associate with this action.
160160
* @param parms The configuration parameters to be used when starting dev mode.
161+
* @param colorOutput Flag indicating if the output of the console should be colored
161162
* @param javaHomePath The configuration java installation home to be set in the process running dev mode.
163+
* @param launch The launch associated with this run.
162164
* @param mode The configuration mode.
163165
*/
164-
public void start(IProject iProject, String parms, String javaHomePath, ILaunch launch, String mode) {
166+
public void start(IProject iProject, String parms, boolean colorOutput, String javaHomePath, ILaunch launch, String mode) {
165167

166168
if (Trace.isEnabled()) {
167169
Trace.getTracer().traceEntry(Trace.TRACE_TOOLS, new Object[] { iProject, parms, javaHomePath, mode });
@@ -215,9 +217,24 @@ public void start(IProject iProject, String parms, String javaHomePath, ILaunch
215217
startParms = userParms;
216218
}
217219

220+
// Append color styling to start parms
221+
BuildType buildType = project.getBuildType();
222+
if (buildType == Project.BuildType.MAVEN) {
223+
StringBuffer updateStartParms = new StringBuffer(startParms);
224+
updateStartParms.append(" ");
225+
226+
if (colorOutput) {
227+
updateStartParms.append("-Dstyle.color=always");
228+
} else {
229+
updateStartParms.append("-Dstyle.color=never");
230+
}
231+
232+
startParms = updateStartParms.toString();
233+
}
234+
218235
// Prepare the Liberty plugin container dev mode command.
219236
String cmd = "";
220-
BuildType buildType = project.getBuildType();
237+
221238
if (buildType == Project.BuildType.MAVEN) {
222239
cmd = CommandBuilder.getMavenCommandLine(projectPath, "io.openliberty.tools:liberty-maven-plugin:dev " + startParms,
223240
pathEnv);
@@ -259,10 +276,12 @@ public void start(IProject iProject, String parms, String javaHomePath, ILaunch
259276
*
260277
* @param iProject The project instance to associate with this action.
261278
* @param parms The configuration parameters to be used when starting dev mode.
279+
* @param colorOutput Flag indicating if the output of the console should be colored
262280
* @param javaHomePath The configuration java installation home to be set in the process running dev mode.
281+
* @param launch The launch associated with this run.
263282
* @param mode The configuration mode.
264283
*/
265-
public void startInContainer(IProject iProject, String parms, String javaHomePath, ILaunch launch, String mode) {
284+
public void startInContainer(IProject iProject, String parms, boolean colorOutput, String javaHomePath, ILaunch launch, String mode) {
266285

267286
if (Trace.isEnabled()) {
268287
Trace.getTracer().traceEntry(Trace.TRACE_TOOLS, new Object[] { iProject, parms, javaHomePath, mode });
@@ -316,9 +335,23 @@ public void startInContainer(IProject iProject, String parms, String javaHomePat
316335
startParms = userParms;
317336
}
318337

338+
// Append color styling to start parms
339+
BuildType buildType = project.getBuildType();
340+
if (buildType == Project.BuildType.MAVEN) {
341+
StringBuffer updateStartParms = new StringBuffer(startParms);
342+
updateStartParms.append(" ");
343+
344+
if (colorOutput) {
345+
updateStartParms.append("-Dstyle.color=always");
346+
} else {
347+
updateStartParms.append("-Dstyle.color=never");
348+
}
349+
350+
startParms = updateStartParms.toString();
351+
}
352+
319353
// Prepare the Liberty plugin container dev mode command.
320354
String cmd = "";
321-
BuildType buildType = project.getBuildType();
322355
if (buildType == Project.BuildType.MAVEN) {
323356
cmd = CommandBuilder.getMavenCommandLine(projectPath, "io.openliberty.tools:liberty-maven-plugin:devc " + startParms,
324357
pathEnv);
@@ -886,7 +919,9 @@ public void run() {
886919
job.setUser(true);
887920
runningJobs.put(job, Boolean.TRUE);
888921
job.schedule();
889-
} catch (Exception e) {
922+
} catch (
923+
924+
Exception e) {
890925
String msg = "An error was detected while processing the Liberty Maven or Gradle stop command on project " + projectName;
891926
if (Trace.isEnabled()) {
892927
Trace.getTracer().trace(Trace.TRACE_TOOLS, msg, e);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,15 @@ private void launchDevMode(IProject iProject, ILaunchConfiguration iConfiguratio
153153

154154
// Retrieve configuration data.
155155
boolean runInContainer = configuration.getAttribute(StartTab.PROJECT_RUN_IN_CONTAINER, false);
156+
boolean colorOutput = configuration.getAttribute(StartTab.PROJECT_COLOR_OUTPUT, true);
156157
String configParms = configuration.getAttribute(StartTab.PROJECT_START_PARM, (String) null);
157158
String javaHomePath = JRETab.resolveJavaHome(configuration);
158159

159160
// Process the action.
160161
if (runInContainer) {
161-
devModeOps.startInContainer(iProject, configParms, javaHomePath, launch, mode);
162+
devModeOps.startInContainer(iProject, configParms, colorOutput, javaHomePath, launch, mode);
162163
} else {
163-
devModeOps.start(iProject, configParms, javaHomePath, launch, mode);
164+
devModeOps.start(iProject, configParms, colorOutput, javaHomePath, launch, mode);
164165
}
165166

166167
if (Trace.isEnabled()) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public ILaunchConfiguration getLaunchConfiguration(IProject iProject, String mod
7979
ILaunchConfigurationWorkingCopy workingCopy = iLaunchConfigType.newInstance(null, newName);
8080
workingCopy.setAttribute(StartTab.PROJECT_NAME, iProject.getName());
8181
workingCopy.setAttribute(StartTab.PROJECT_START_PARM, devModeOps.getProjectModel().getDefaultStartParameters(iProject));
82+
workingCopy.setAttribute(StartTab.PROJECT_COLOR_OUTPUT, true);
8283
// default to 'false', no container
8384
boolean runInContainer = runtimeEnv.equals(RuntimeEnv.CONTAINER);
8485
workingCopy.setAttribute(StartTab.PROJECT_RUN_IN_CONTAINER, runInContainer);

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

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public class StartTab extends AbstractLaunchConfigurationTab {
6262
/** Configuration map key with a value stating whether or not the associated project ran in a container. */
6363
public static final String PROJECT_RUN_IN_CONTAINER = "io.openliberty.tools.eclipse.launch.project.container.run";
6464

65+
/** Configuration map key with a value stating whether or not the console has colored output. */
66+
public static final String PROJECT_COLOR_OUTPUT = "io.openliberty.tools.eclipse.launch.project.color.output";
67+
6568
/** Main preference page ID. */
6669
public static final String MAIN_PREFERENCE_PAGE_ID = "io.openliberty.tools.eclipse.ui.preferences.page";
6770

@@ -70,6 +73,8 @@ public class StartTab extends AbstractLaunchConfigurationTab {
7073

7174
private static final String EXAMPLE_START_PARMS = "Example: -DhotTests=true";
7275

76+
private static final String COLOR_STYLE_PARM = "-Dstyle.color";
77+
7378
/** The font to use for the contents of this Tab. */
7479
private Font font;
7580

@@ -85,6 +90,9 @@ public class StartTab extends AbstractLaunchConfigurationTab {
8590
/** Holds the run in container check box. */
8691
private Button runInContainerCheckBox;
8792

93+
/** Holds the color output check box. */
94+
private Button colorOutputCheckBox;
95+
8896
/** DevModeOperations instance. */
8997
private DevModeOperations devModeOps = DevModeOperations.getInstance();
9098

@@ -112,6 +120,7 @@ public void createControl(Composite parent) {
112120
Composite parmsGroupComposite = createGroupComposite(mainComposite, "", 2);
113121
createInputParmText(parmsGroupComposite);
114122
createRunInContainerButton(parmsGroupComposite);
123+
createColorOutputButton(parmsGroupComposite);
115124

116125
createLabelWithPreferenceLink(mainComposite);
117126
}
@@ -136,6 +145,8 @@ public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
136145

137146
configuration.setAttribute(PROJECT_RUN_IN_CONTAINER, false);
138147

148+
configuration.setAttribute(PROJECT_COLOR_OUTPUT, true);
149+
139150
if (Trace.isEnabled()) {
140151
Trace.getTracer().traceExit(Trace.TRACE_UI);
141152
}
@@ -160,6 +171,9 @@ public void initializeFrom(ILaunchConfiguration configuration) {
160171
boolean runInContainer = configuration.getAttribute(PROJECT_RUN_IN_CONTAINER, false);
161172
runInContainerCheckBox.setSelection(runInContainer);
162173

174+
boolean colorOutput = configuration.getAttribute(PROJECT_COLOR_OUTPUT, true);
175+
colorOutputCheckBox.setSelection(colorOutput);
176+
163177
String projectName = configuration.getAttribute(PROJECT_NAME, (String) null);
164178
if (projectName == null) {
165179
super.setErrorMessage(
@@ -236,16 +250,17 @@ public boolean isValid(ILaunchConfiguration config) {
236250
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
237251

238252
String startParamStr = startParmText.getText();
253+
configuration.setAttribute(PROJECT_START_PARM, startParamStr);
239254

240255
boolean runInContainerBool = runInContainerCheckBox.getSelection();
241-
242256
configuration.setAttribute(PROJECT_RUN_IN_CONTAINER, runInContainerBool);
243257

244-
configuration.setAttribute(PROJECT_START_PARM, startParamStr);
258+
boolean colorOutputBool = colorOutputCheckBox.getSelection();
259+
configuration.setAttribute(PROJECT_COLOR_OUTPUT, colorOutputBool);
245260

246261
if (Trace.isEnabled()) {
247262
Trace.getTracer().trace(Trace.TRACE_UI, "In performApply with project name = " + projectNameLabel.getText() + ", text = "
248-
+ startParamStr + ", runInContainer = " + runInContainerBool);
263+
+ startParamStr + ", runInContainer = " + runInContainerBool + ", colorOutput = " + colorOutputBool);
249264
}
250265
}
251266

@@ -399,6 +414,33 @@ public void widgetSelected(SelectionEvent event) {
399414
GridDataFactory.swtDefaults().applyTo(emptyColumnLabel);
400415
}
401416

417+
/**
418+
* Creates the button entry that indicates whether or not the console should run with color styling.
419+
*
420+
* @param parent The parent composite.
421+
*/
422+
private void createColorOutputButton(Composite parent) {
423+
colorOutputCheckBox = new Button(parent, SWT.CHECK);
424+
colorOutputCheckBox.setText("Color Output");
425+
colorOutputCheckBox.setSelection(true);
426+
colorOutputCheckBox.setFont(font);
427+
colorOutputCheckBox.addSelectionListener(new SelectionAdapter() {
428+
429+
/**
430+
* {@inheritDoc}
431+
*/
432+
@Override
433+
public void widgetSelected(SelectionEvent event) {
434+
setDirty(true);
435+
updateLaunchConfigurationDialog();
436+
}
437+
});
438+
GridDataFactory.swtDefaults().applyTo(colorOutputCheckBox);
439+
440+
Label emptyColumnLabel = new Label(parent, SWT.NONE);
441+
GridDataFactory.swtDefaults().applyTo(emptyColumnLabel);
442+
}
443+
402444
/**
403445
* Returns the default start parameters.
404446
*

0 commit comments

Comments
 (0)