Skip to content

Commit 84d99f2

Browse files
authored
Add some documentation and consistency to use of info vs output stream (#1060)
With some better Javadocs the cross referencing between IConsole and the UI aspects of the console is a little easier to follow. This resolves #1059 in two parts: 1. For Core Build System this update consistently uses info stream to show information messages and output stream to be stdout of launched build tool. This resolves the "Build Complete" appearing as the output color when doing clean (See screenshots in #1059) 2. CBuildConfiguration.watchProcess(IConsole, IProgressMonitor) incorrectly passed the info stream as the output stream. Mostly this was used for the clean stage of builds. This resolves the CMake output like ("Cleaning all built files...") appearing as the info color when doing clean (See screenshots in #1059) Fixes #1059
1 parent 0564831 commit 84d99f2

File tree

8 files changed

+62
-25
lines changed

8 files changed

+62
-25
lines changed

build/org.eclipse.cdt.core.autotools.core/src/org/eclipse/cdt/core/autotools/core/AutotoolsBuildConfiguration.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,16 @@ protected void executeRemote(List<String> command, IPath processCwd, IConsole co
9090
try {
9191
project.deleteMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE);
9292

93-
ConsoleOutputStream outStream = console.getOutputStream();
93+
ConsoleOutputStream infoStream = console.getInfoStream();
9494

9595
try (ErrorParserManager epm = new ErrorParserManager(project, getBuildDirectoryURI(), this,
9696
getToolChain().getErrorParserIds())) {
9797
epm.setOutputStream(console.getOutputStream());
9898

9999
IEnvironmentVariable[] env = new IEnvironmentVariable[0];
100100

101-
outStream.write("Building in: " + processCwd.toString() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
102-
outStream.write("Running: " + commandJoined + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
101+
infoStream.write("Building in: " + processCwd.toString() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
102+
infoStream.write("Running: " + commandJoined + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
103103
Process p = startBuildProcess(command, env, processCwd, console, monitor);
104104
if (p == null) {
105105
console.getErrorStream().write("Error executing: " + commandJoined); //$NON-NLS-1$

build/org.eclipse.cdt.meson.core/src/org/eclipse/cdt/internal/meson/core/MesonBuildConfiguration.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ public IProject[] build(int kind, Map<String, String> args, String[] ninjaEnv, S
119119
try {
120120
project.deleteMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE);
121121

122-
ConsoleOutputStream outStream = console.getOutputStream();
122+
ConsoleOutputStream infoStream = console.getInfoStream();
123123

124124
Path buildDir = getBuildDirectory();
125125

126-
outStream.write(String.format(Messages.MesonBuildConfiguration_BuildingIn, buildDir.toString()));
126+
infoStream.write(String.format(Messages.MesonBuildConfiguration_BuildingIn, buildDir.toString()));
127127

128128
// Make sure we have a toolchain file if cross
129129
if (toolChainFile == null && !isLocal()) {
@@ -169,7 +169,7 @@ public IProject[] build(int kind, Map<String, String> args, String[] ninjaEnv, S
169169

170170
monitor.subTask(Messages.MesonBuildConfiguration_RunningMeson);
171171

172-
outStream.write(String.join(" ", envStr != null ? ("env " + envStr) : "", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
172+
infoStream.write(String.join(" ", envStr != null ? ("env " + envStr) : "", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
173173
"sh -c \"meson", userArgs != null ? userArgs : "", projOptions != null ? projOptions : "", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
174174
getBuildDirectory().getParent().getParent().toString() + "\"\n")); //$NON-NLS-1$
175175

@@ -246,7 +246,7 @@ public IProject[] build(int kind, Map<String, String> args, String[] ninjaEnv, S
246246
// Process compile_commands.json file and generate Scanner info
247247
refreshScannerInfo();
248248

249-
outStream.write(String.format(Messages.MesonBuildConfiguration_BuildingComplete, buildDir.toString()));
249+
infoStream.write(String.format(Messages.MesonBuildConfiguration_BuildingComplete, buildDir.toString()));
250250

251251
return new IProject[] { project };
252252
} catch (IOException e) {
@@ -261,11 +261,11 @@ public void clean(IConsole console, IProgressMonitor monitor) throws CoreExcepti
261261
try {
262262
project.deleteMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE);
263263

264-
ConsoleOutputStream outStream = console.getOutputStream();
264+
ConsoleOutputStream infoStream = console.getInfoStream();
265265

266266
Path buildDir = getBuildDirectory();
267267

268-
outStream.write(String.format(Messages.MesonBuildConfiguration_BuildingIn, buildDir.toString()));
268+
infoStream.write(String.format(Messages.MesonBuildConfiguration_BuildingIn, buildDir.toString()));
269269

270270
if (!Files.exists(buildDir.resolve("build.ninja"))) { //$NON-NLS-1$
271271
console.getOutputStream().write(Messages.MesonBuildConfiguration_NoNinjaFileToClean);
@@ -290,7 +290,7 @@ public void clean(IConsole console, IProgressMonitor monitor) throws CoreExcepti
290290

291291
IEnvironmentVariable[] env = new IEnvironmentVariable[0];
292292

293-
outStream.write(String.join(" ", commandList) + '\n'); //$NON-NLS-1$
293+
infoStream.write(String.join(" ", commandList) + '\n'); //$NON-NLS-1$
294294
Process p = startBuildProcess(commandList, env, workingDir, console, monitor);
295295
if (p == null) {
296296
console.getErrorStream()
@@ -301,7 +301,7 @@ public void clean(IConsole console, IProgressMonitor monitor) throws CoreExcepti
301301
watchProcess(console, monitor);
302302
}
303303

304-
outStream.write(String.format(Messages.MesonBuildConfiguration_BuildingComplete, buildDir.toString()));
304+
infoStream.write(String.format(Messages.MesonBuildConfiguration_BuildingComplete, buildDir.toString()));
305305

306306
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
307307
} catch (IOException e) {

cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeBuildConfiguration.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -309,16 +309,16 @@ public void clean(IConsole console, IProgressMonitor monitor) throws CoreExcepti
309309
ICMakeProperties cmakeProperties = getCMakeProperties();
310310
CommandDescriptorBuilder cmdBuilder = new CommandDescriptorBuilder(cmakeProperties);
311311
CommandDescriptor command = cmdBuilder.makeCMakeBuildCommandline(cmakeProperties.getCleanTarget());
312-
ConsoleOutputStream outStream = console.getOutputStream();
312+
ConsoleOutputStream infoStream = console.getInfoStream();
313313

314314
Path buildDir = getBuildDirectory();
315315

316316
if (!Files.exists(buildDir.resolve("CMakeFiles"))) { //$NON-NLS-1$
317-
outStream.write(Messages.CMakeBuildConfiguration_NotFound);
317+
infoStream.write(Messages.CMakeBuildConfiguration_NotFound);
318318
return;
319319
}
320320

321-
outStream.write(String.join(" ", command.getArguments()) + '\n'); //$NON-NLS-1$
321+
infoStream.write(String.join(" ", command.getArguments()) + '\n'); //$NON-NLS-1$
322322

323323
org.eclipse.core.runtime.Path workingDir = new org.eclipse.core.runtime.Path(
324324
getBuildDirectory().toString());
@@ -341,7 +341,7 @@ public void clean(IConsole console, IProgressMonitor monitor) throws CoreExcepti
341341
addMarker(project, -1, msg, IMarkerGenerator.SEVERITY_ERROR_BUILD, null);
342342
}
343343

344-
outStream.write(Messages.CMakeBuildConfiguration_BuildComplete);
344+
infoStream.write(Messages.CMakeBuildConfiguration_BuildComplete);
345345

346346
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
347347
} catch (IOException e) {

core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICommandLauncher.java

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.io.OutputStream;
1717
import java.util.Properties;
1818

19+
import org.eclipse.cdt.core.resources.IConsole;
1920
import org.eclipse.core.resources.IProject;
2021
import org.eclipse.core.runtime.CoreException;
2122
import org.eclipse.core.runtime.IPath;
@@ -113,6 +114,11 @@ public Process execute(IPath commandPath, String[] args, String[] env, IPath wor
113114
* polled to test if the cancel button has been pressed. Destroys the
114115
* process if the monitor becomes canceled override to implement a different
115116
* way to read the process inputs
117+
*
118+
* @param output the output stream that the command's stdout should be directed to.
119+
* Typically connected to {@link IConsole#getOutputStream()}
120+
* @param err the output stream that the command's stderr should be directed to.
121+
* Typically connected to {@link IConsole#getErrorStream()}
116122
*/
117123
public int waitAndRead(OutputStream output, OutputStream err, IProgressMonitor monitor);
118124
}

core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ public Process startBuildProcess(List<String> commands, IEnvironmentVariable[] e
596596
*/
597597
protected int watchProcess(IConsole console, IProgressMonitor monitor) throws CoreException {
598598
assertLauncherNotNull(launcher);
599-
return launcher.waitAndRead(console.getInfoStream(), console.getErrorStream(), monitor);
599+
return launcher.waitAndRead(console.getOutputStream(), console.getErrorStream(), monitor);
600600
}
601601

602602
/**

core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/StandardBuildConfiguration.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@
3131
import org.eclipse.cdt.internal.core.build.Messages;
3232
import org.eclipse.core.resources.IBuildConfiguration;
3333
import org.eclipse.core.resources.IContainer;
34-
import org.eclipse.core.resources.IFolder;
3534
import org.eclipse.core.resources.IProject;
3635
import org.eclipse.core.resources.IResource;
3736
import org.eclipse.core.resources.ResourcesPlugin;
3837
import org.eclipse.core.runtime.CoreException;
3938
import org.eclipse.core.runtime.IPath;
4039
import org.eclipse.core.runtime.IProgressMonitor;
4140
import org.eclipse.core.runtime.IStatus;
42-
import org.eclipse.core.runtime.NullProgressMonitor;
4341
import org.eclipse.core.runtime.Status;
4442

4543
/**
@@ -238,11 +236,11 @@ public IProject[] build(int kind, Map<String, String> args, IConsole console, IP
238236
try {
239237
project.deleteMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE);
240238

241-
ConsoleOutputStream outStream = console.getOutputStream();
239+
ConsoleOutputStream infoStream = console.getInfoStream();
242240

243241
Path buildDir = getBuildDirectory();
244242

245-
outStream.write(String.format(Messages.StandardBuildConfiguration_0, buildDir.toString()));
243+
infoStream.write(String.format(Messages.StandardBuildConfiguration_0, buildDir.toString()));
246244

247245
List<String> command = new ArrayList<>();
248246
command.add(buildCommand[0]);
@@ -278,7 +276,7 @@ public IProject[] build(int kind, Map<String, String> args, IConsole console, IP
278276

279277
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
280278

281-
outStream.write(String.format(Messages.StandardBuildConfiguration_1, epm.getErrorCount(),
279+
infoStream.write(String.format(Messages.StandardBuildConfiguration_1, epm.getErrorCount(),
282280
epm.getWarningCount(), buildDir.toString()));
283281
}
284282
return new IProject[] { project };
@@ -294,11 +292,11 @@ public void clean(IConsole console, IProgressMonitor monitor) throws CoreExcepti
294292
try {
295293
project.deleteMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE);
296294

297-
ConsoleOutputStream outStream = console.getOutputStream();
295+
ConsoleOutputStream infoStream = console.getInfoStream();
298296

299297
Path buildDir = getBuildDirectory();
300298

301-
outStream.write(String.format(Messages.StandardBuildConfiguration_0, buildDir.toString()));
299+
infoStream.write(String.format(Messages.StandardBuildConfiguration_0, buildDir.toString()));
302300

303301
List<String> command = new ArrayList<>();
304302
List<String> buildCommand;
@@ -323,7 +321,7 @@ public void clean(IConsole console, IProgressMonitor monitor) throws CoreExcepti
323321
}
324322

325323
// run make
326-
outStream.write(String.format("%s\n", String.join(" ", command))); //$NON-NLS-1$ //$NON-NLS-2$
324+
infoStream.write(String.format("%s\n", String.join(" ", command))); //$NON-NLS-1$ //$NON-NLS-2$
327325

328326
org.eclipse.core.runtime.Path workingDir = new org.eclipse.core.runtime.Path(
329327
getBuildDirectory().toString());
@@ -335,7 +333,7 @@ public void clean(IConsole console, IProgressMonitor monitor) throws CoreExcepti
335333

336334
watchProcess(console, monitor);
337335

338-
outStream.write(Messages.CBuildConfiguration_BuildComplete);
336+
infoStream.write(Messages.CBuildConfiguration_BuildComplete);
339337

340338
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
341339
} catch (IOException e) {

core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IConsole.java

+23
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,32 @@ public interface IConsole {
2929
*/
3030
void start(IProject project);
3131

32+
/**
33+
* Get the stream that shows up as output in the console. This
34+
* is typically connected to the output of the build process.
35+
*/
3236
ConsoleOutputStream getOutputStream() throws CoreException;
3337

38+
/**
39+
* Get the stream that shows up as information messages in
40+
* the console. This is typically not connected to the output
41+
* of the build process. Typically information messages, such
42+
* as build started and build completed messages are written
43+
* to the info stream.
44+
*
45+
* @apiNote Whether the command line used to launch the process
46+
* is written to the info stream or to the output stream is
47+
* very inconsistent in CDT's code base. Core Build mostly
48+
* uses the info stream for this purpose, but MBS typically
49+
* uses output stream.
50+
*/
3451
ConsoleOutputStream getInfoStream() throws CoreException;
3552

53+
/**
54+
* Get the stream that shows up as output in the console. This
55+
* is typically connected to the error output of the build process
56+
* and errors detected when launching the process can be output
57+
* to here as well.
58+
*/
3659
ConsoleOutputStream getErrorStream() throws CoreException;
3760
}

core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/BuildConsolePreferencePage.java

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*******************************************************************************/
1515
package org.eclipse.cdt.internal.ui.preferences;
1616

17+
import org.eclipse.cdt.core.resources.IConsole;
1718
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
1819
import org.eclipse.cdt.ui.CUIPlugin;
1920
import org.eclipse.jface.preference.BooleanFieldEditor;
@@ -49,8 +50,17 @@ public class BuildConsolePreferencePage extends FieldEditorPreferencePage implem
4950
public static final String PREF_BUILDCONSOLE_TAB_WIDTH = "buildConsoleTabWith"; //$NON-NLS-1$
5051
public static final String PREF_BUILDCONSOLE_LINES = "buildConsoleLines"; //$NON-NLS-1$
5152
public static final String PREF_BUILDCONSOLE_UPDATE_DELAY_MS = "buildConsoleUpdateDelayMs"; //$NON-NLS-1$
53+
/**
54+
* The color of the {@link IConsole#getInfoStream()}
55+
*/
5256
public static final String PREF_BUILDCONSOLE_INFO_COLOR = "buildConsoleInfoStreamColor"; //$NON-NLS-1$
57+
/**
58+
* The color of the {@link IConsole#getOutputStream()}
59+
*/
5360
public static final String PREF_BUILDCONSOLE_OUTPUT_COLOR = "buildConsoleOutputStreamColor"; //$NON-NLS-1$
61+
/**
62+
* The color of the {@link IConsole#getErrorStream()}
63+
*/
5464
public static final String PREF_BUILDCONSOLE_ERROR_COLOR = "buildConsoleErrorStreamColor"; //$NON-NLS-1$
5565
public static final String PREF_BUILDCONSOLE_BACKGROUND_COLOR = "buildConsoleBackgroundColor"; //$NON-NLS-1$
5666
public static final String PREF_BUILDCONSOLE_PROBLEM_BACKGROUND_COLOR = "buildConsoleProblemBackgroundColor"; //$NON-NLS-1$

0 commit comments

Comments
 (0)