From 2989ee45370f5cde2cd03c5f3f5cca843930de8c Mon Sep 17 00:00:00 2001 From: David Inglis Date: Thu, 3 Jun 2004 15:52:16 +0000 Subject: [PATCH] fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=65564 --- .../ui/buildconsole/BuildConsoleManager.java | 38 +++++++++++++++---- .../buildconsole/BuildConsolePartitioner.java | 19 +++++----- .../ui/buildconsole/BuildConsoleStream.java | 12 ++++-- .../ui/buildconsole/CBuildConsole.java | 8 ++-- .../src/org/eclipse/cdt/ui/IBuildConsole.java | 21 ---------- .../eclipse/cdt/ui/IBuildConsoleManager.java | 3 +- 6 files changed, 55 insertions(+), 46 deletions(-) delete mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IBuildConsole.java diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleManager.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleManager.java index 23bb897cdc0..bf425555de1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleManager.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleManager.java @@ -11,15 +11,18 @@ package org.eclipse.cdt.internal.ui.buildconsole; import java.util.HashMap; import java.util.Map; +import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.cdt.internal.ui.preferences.BuildConsolePreferencePage; import org.eclipse.cdt.ui.CUIPlugin; -import org.eclipse.cdt.ui.IBuildConsole; import org.eclipse.cdt.ui.IBuildConsoleListener; import org.eclipse.cdt.ui.IBuildConsoleManager; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceChangeEvent; import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.text.Assert; import org.eclipse.jface.text.IDocument; @@ -45,8 +48,12 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang BuildConsole fConsole; private Map fConsoleMap = new HashMap(); private Color infoColor, outputColor, errorColor; - public BuildConsoleStream infoStream, outputStream, errorStream; + private BuildConsoleStream infoStream, outputStream, errorStream; + static public final int BUILD_STREAM_TYPE_INFO = 0; + static public final int BUILD_STREAM_TYPE_OUTPUT = 1; + static public final int BUILD_STREAM_TYPE_ERROR = 2; + public BuildConsoleManager() { } @@ -161,11 +168,9 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang } public void startup() { - fConsole = new BuildConsole(this); - ConsolePlugin.getDefault().getConsoleManager().addConsoles(new org.eclipse.ui.console.IConsole[]{fConsole}); - infoStream = new BuildConsoleStream(fConsole); - outputStream = new BuildConsoleStream(fConsole); - errorStream = new BuildConsoleStream(fConsole); + infoStream = new BuildConsoleStream(); + outputStream = new BuildConsoleStream(); + errorStream = new BuildConsoleStream(); runUI(new Runnable() { @@ -176,10 +181,15 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang */ public void run() { // install colors + fConsole = new BuildConsole(BuildConsoleManager.this); + ConsolePlugin.getDefault().getConsoleManager().addConsoles(new org.eclipse.ui.console.IConsole[]{fConsole}); + infoStream.setConsole(fConsole); infoColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_INFO_COLOR); infoStream.setColor(infoColor); + outputStream.setConsole(fConsole); outputColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_OUTPUT_COLOR); outputStream.setColor(outputColor); + errorStream.setConsole(fConsole); errorColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_ERROR_COLOR); errorStream.setColor(errorColor); } @@ -213,6 +223,18 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang errorColor = newColor; } } + + public BuildConsoleStream getStream(int type) throws CoreException { + switch(type) { + case BUILD_STREAM_TYPE_ERROR: + return errorStream; + case BUILD_STREAM_TYPE_INFO: + return infoStream; + case BUILD_STREAM_TYPE_OUTPUT: + return outputStream; + } + throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, -1, "No Such Console", null)); //$NON-NLS-1$ + } /** * Returns a color instance based on data from a preference field. @@ -225,7 +247,7 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang * Returns the console for the project, or null if none. */ - public IBuildConsole getConsole(IProject project) { + public IConsole getConsole(IProject project) { Assert.isNotNull(project); return getConsolePartioner(project).getConsole(); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsolePartitioner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsolePartitioner.java index 0d867746e6c..463e9fc1a08 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsolePartitioner.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsolePartitioner.java @@ -14,10 +14,11 @@ import java.util.Iterator; import java.util.List; import org.eclipse.cdt.core.ConsoleOutputStream; +import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.cdt.internal.ui.preferences.BuildConsolePreferencePage; import org.eclipse.cdt.ui.CUIPlugin; -import org.eclipse.cdt.ui.IBuildConsole; import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.DocumentEvent; import org.eclipse.jface.text.IDocument; @@ -34,7 +35,7 @@ public class BuildConsolePartitioner implements IDocumentPartitioner, IDocumentPartitionerExtension, - IBuildConsole, + IConsole, IPropertyChangeListener { /** @@ -271,7 +272,7 @@ public class BuildConsolePartitioner return partition; } - public IBuildConsole getConsole() { + public IConsole getConsole() { return this; } @@ -311,16 +312,16 @@ public class BuildConsolePartitioner } } - public ConsoleOutputStream getOutputStream() { - return new BuildOutputStream(fManager.outputStream); + public ConsoleOutputStream getOutputStream() throws CoreException { + return new BuildOutputStream(fManager.getStream(BuildConsoleManager.BUILD_STREAM_TYPE_OUTPUT)); } - public ConsoleOutputStream getInfoStream() { - return new BuildOutputStream(fManager.infoStream); + public ConsoleOutputStream getInfoStream() throws CoreException { + return new BuildOutputStream(fManager.getStream(BuildConsoleManager.BUILD_STREAM_TYPE_INFO)); } - public ConsoleOutputStream getErrorStream() { - return new BuildOutputStream(fManager.errorStream); + public ConsoleOutputStream getErrorStream() throws CoreException { + return new BuildOutputStream(fManager.getStream(BuildConsoleManager.BUILD_STREAM_TYPE_INFO)); } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleStream.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleStream.java index f36dc270661..e1962bfb72a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleStream.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleStream.java @@ -21,12 +21,14 @@ public class BuildConsoleStream { /** * Constructs a new stream connected to the given console. * - * @param console the console to write messages to */ - public BuildConsoleStream(BuildConsole console) { + public BuildConsoleStream() { + } + + public void setConsole(BuildConsole console) { fConsole = console; } - + /** * Sets the color of this message stream * @@ -35,7 +37,9 @@ public class BuildConsoleStream { public void setColor(Color color) { Color old = fColor; fColor = color; - fConsole.firePropertyChange(this, BuildConsole.P_STREAM_COLOR, old, color); + if (fConsole != null) { + fConsole.firePropertyChange(this, BuildConsole.P_STREAM_COLOR, old, color); + } } /** diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/CBuildConsole.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/CBuildConsole.java index d96455f78a4..c771b0787d6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/CBuildConsole.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/CBuildConsole.java @@ -15,6 +15,7 @@ import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.IBuildConsoleManager; import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; public class CBuildConsole implements IConsole { IProject project; @@ -33,17 +34,18 @@ public class CBuildConsole implements IConsole { } /** + * @throws CoreException * @see org.eclipse.cdt.core.resources.IConsole#getOutputStream() */ - public ConsoleOutputStream getOutputStream() { + public ConsoleOutputStream getOutputStream() throws CoreException { return fConsoleManager.getConsole(project).getOutputStream(); } - public ConsoleOutputStream getInfoStream() { + public ConsoleOutputStream getInfoStream() throws CoreException { return fConsoleManager.getConsole(project).getInfoStream(); } - public ConsoleOutputStream getErrorStream() { + public ConsoleOutputStream getErrorStream() throws CoreException { return fConsoleManager.getConsole(project).getErrorStream(); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IBuildConsole.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IBuildConsole.java deleted file mode 100644 index 1127ce66efd..00000000000 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IBuildConsole.java +++ /dev/null @@ -1,21 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003,2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation -***********************************************************************/ -package org.eclipse.cdt.ui; - -import org.eclipse.cdt.core.ConsoleOutputStream; -import org.eclipse.core.resources.IProject; - -public interface IBuildConsole { - void start(IProject project); - ConsoleOutputStream getOutputStream(); - ConsoleOutputStream getInfoStream(); - ConsoleOutputStream getErrorStream(); -} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IBuildConsoleManager.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IBuildConsoleManager.java index c4ae161ea73..5a9e2b1d072 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IBuildConsoleManager.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IBuildConsoleManager.java @@ -10,11 +10,12 @@ ***********************************************************************/ package org.eclipse.cdt.ui; +import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.core.resources.IProject; import org.eclipse.jface.text.IDocument; public interface IBuildConsoleManager { - IBuildConsole getConsole(IProject project); + IConsole getConsole(IProject project); IDocument getConsoleDocument(IProject project); void addConsoleListener(IBuildConsoleListener listener); void removeConsoleListener(IBuildConsoleListener listener);