1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-30 04:15:35 +02:00

fixed NPE in build console when console manager was not finsihed being initialized and the console was being written to.

This commit is contained in:
David Inglis 2004-05-31 14:13:50 +00:00
parent 01619cd230
commit 92b484a970
3 changed files with 39 additions and 45 deletions

View file

@ -163,6 +163,9 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
public void startup() { public void startup() {
fConsole = new BuildConsole(this); fConsole = new BuildConsole(this);
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new org.eclipse.ui.console.IConsole[]{fConsole}); ConsolePlugin.getDefault().getConsoleManager().addConsoles(new org.eclipse.ui.console.IConsole[]{fConsole});
infoStream = new BuildConsoleStream(fConsole);
outputStream = new BuildConsoleStream(fConsole);
errorStream = new BuildConsoleStream(fConsole);
runUI(new Runnable() { runUI(new Runnable() {
@ -174,13 +177,10 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
public void run() { public void run() {
// install colors // install colors
infoColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_INFO_COLOR); infoColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_INFO_COLOR);
infoStream = new BuildConsoleStream(fConsole);
infoStream.setColor(infoColor); infoStream.setColor(infoColor);
outputColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_OUTPUT_COLOR); outputColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_OUTPUT_COLOR);
outputStream = new BuildConsoleStream(fConsole);
outputStream.setColor(outputColor); outputStream.setColor(outputColor);
errorColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_ERROR_COLOR); errorColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_ERROR_COLOR);
errorStream = new BuildConsoleStream(fConsole);
errorStream.setColor(errorColor); errorStream.setColor(errorColor);
} }
}); });

View file

@ -234,7 +234,7 @@ public class BuildConsolePage extends Page implements ISelectionListener, IPrope
action.setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( action.setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
ISharedImages.IMG_TOOL_COPY_DISABLED)); ISharedImages.IMG_TOOL_COPY_DISABLED));
action.setHoverImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( action.setHoverImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
ISharedImages.IMG_TOOL_COPY_HOVER)); ISharedImages.IMG_TOOL_COPY));
setGlobalAction(actionBars, ActionFactory.COPY.getId(), action); setGlobalAction(actionBars, ActionFactory.COPY.getId(), action);
action = new TextViewerAction(getViewer(), ITextOperationTarget.SELECT_ALL); action = new TextViewerAction(getViewer(), ITextOperationTarget.SELECT_ALL);
action.configureAction(ConsoleMessages.getString("BuildConsolePage.Select_&All@Ctrl+A_12"), //$NON-NLS-1$ action.configureAction(ConsoleMessages.getString("BuildConsolePage.Select_&All@Ctrl+A_12"), //$NON-NLS-1$

View file

@ -1,13 +1,11 @@
/********************************************************************** /*******************************************************************************
* Copyright (c) 2002,2003,2004 QNX Software Systems and others. * Copyright (c) 2002,2003,2004 QNX Software Systems and others. All rights
* All rights reserved. This program and the accompanying materials * reserved. This program and the accompanying materials are made available
* are made available under the terms of the Common Public License v1.0 * under the terms of the Common Public License v1.0 which accompanies this
* which accompanies this distribution, and is available at * distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html
* http://www.eclipse.org/legal/cpl-v10.html
* *
* Contributors: * Contributors: QNX Software Systems - Initial API and implementation
* QNX Software Systems - Initial API and implementation ******************************************************************************/
***********************************************************************/
package org.eclipse.cdt.internal.ui.buildconsole; package org.eclipse.cdt.internal.ui.buildconsole;
import java.io.IOException; import java.io.IOException;
@ -103,7 +101,7 @@ public class BuildConsolePartitioner
nLines = fDocument.getNumberOfLines(); nLines = fDocument.getNumberOfLines();
checkOverflow(); checkOverflow();
} }
public void connect(IDocument document) { public void connect(IDocument document) {
CUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this); CUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this);
} }
@ -145,20 +143,19 @@ public class BuildConsolePartitioner
*/ */
public ITypedRegion[] computePartitioning(int offset, int length) { public ITypedRegion[] computePartitioning(int offset, int length) {
if (offset == 0 && length == fDocument.getLength()) { if (offset == 0 && length == fDocument.getLength()) {
return (ITypedRegion[]) fPartitions.toArray(new ITypedRegion[fPartitions.size()]); return (ITypedRegion[])fPartitions.toArray(new ITypedRegion[fPartitions.size()]);
} else {
int end = offset + length;
List list = new ArrayList();
for (int i = 0; i < fPartitions.size(); i++) {
ITypedRegion partition = (ITypedRegion) fPartitions.get(i);
int partitionStart = partition.getOffset();
int partitionEnd = partitionStart + partition.getLength();
if ((offset >= partitionStart && offset <= partitionEnd) || (offset < partitionStart && end >= partitionStart)) {
list.add(partition);
}
}
return (ITypedRegion[]) list.toArray(new ITypedRegion[list.size()]);
} }
int end = offset + length;
List list = new ArrayList();
for (int i = 0; i < fPartitions.size(); i++) {
ITypedRegion partition = (ITypedRegion)fPartitions.get(i);
int partitionStart = partition.getOffset();
int partitionEnd = partitionStart + partition.getLength();
if ( (offset >= partitionStart && offset <= partitionEnd) || (offset < partitionStart && end >= partitionStart)) {
list.add(partition);
}
}
return (ITypedRegion[])list.toArray(new ITypedRegion[list.size()]);
} }
/** /**
@ -166,7 +163,7 @@ public class BuildConsolePartitioner
*/ */
public ITypedRegion getPartition(int offset) { public ITypedRegion getPartition(int offset) {
for (int i = 0; i < fPartitions.size(); i++) { for (int i = 0; i < fPartitions.size(); i++) {
ITypedRegion partition = (ITypedRegion) fPartitions.get(i); ITypedRegion partition = (ITypedRegion)fPartitions.get(i);
int start = partition.getOffset(); int start = partition.getOffset();
int end = start + partition.getLength(); int end = start + partition.getLength();
if (offset >= start && offset < end) { if (offset >= start && offset < end) {
@ -199,7 +196,7 @@ public class BuildConsolePartitioner
return new Region(affectedRegions[0].getOffset(), affectedLength); return new Region(affectedRegions[0].getOffset(), affectedLength);
} }
/** /**
* Checks to see if the console buffer has overflowed, and empties the * Checks to see if the console buffer has overflowed, and empties the
* overflow if needed, updating partitions and hyperlink positions. * overflow if needed, updating partitions and hyperlink positions.
@ -210,14 +207,14 @@ public class BuildConsolePartitioner
if (nLines > fMaxLines + 1) { if (nLines > fMaxLines + 1) {
int overflow = 0; int overflow = 0;
try { try {
overflow = fDocument.getLineOffset(nLines - fMaxLines); overflow = fDocument.getLineOffset(nLines - fMaxLines);
} catch (BadLocationException e1) { } catch (BadLocationException e1) {
} }
// update partitions // update partitions
List newParitions = new ArrayList(fPartitions.size()); List newParitions = new ArrayList(fPartitions.size());
Iterator partitions = fPartitions.iterator(); Iterator partitions = fPartitions.iterator();
while (partitions.hasNext()) { while (partitions.hasNext()) {
ITypedRegion region = (ITypedRegion) partitions.next(); ITypedRegion region = (ITypedRegion)partitions.next();
if (region instanceof BuildConsolePartition) { if (region instanceof BuildConsolePartition) {
BuildConsolePartition messageConsolePartition = (BuildConsolePartition)region; BuildConsolePartition messageConsolePartition = (BuildConsolePartition)region;
@ -234,7 +231,8 @@ public class BuildConsolePartitioner
} }
} else { } else {
// modify parition offset // modify parition offset
newPartition = messageConsolePartition.createNewPartition(messageConsolePartition.getOffset()-overflow, messageConsolePartition.getLength()); newPartition = messageConsolePartition.createNewPartition(messageConsolePartition.getOffset()
- overflow, messageConsolePartition.getLength());
} }
if (newPartition != null) { if (newPartition != null) {
newParitions.add(newPartition); newParitions.add(newPartition);
@ -242,28 +240,25 @@ public class BuildConsolePartitioner
} }
} }
fPartitions = newParitions; fPartitions = newParitions;
//called from GUI Thread (see startUpdaterThread()), no asyncExec needed.
try { try {
fDocument.replace(0, overflow, ""); //$NON-NLS-1$ fDocument.replace(0, overflow, ""); //$NON-NLS-1$
} catch (BadLocationException e) { } catch (BadLocationException e) {
} }
} }
} }
} }
/** /**
* Adds a new colored input partition, combining with the previous * Adds a new colored input partition, combining with the previous partition
* partition if possible. * if possible.
*/ */
private BuildConsolePartition addPartition(BuildConsolePartition partition) { private BuildConsolePartition addPartition(BuildConsolePartition partition) {
if (fPartitions.isEmpty()) { if (fPartitions.isEmpty()) {
fPartitions.add(partition); fPartitions.add(partition);
} else { } else {
int index = fPartitions.size() - 1; int index = fPartitions.size() - 1;
BuildConsolePartition last = (BuildConsolePartition) fPartitions.get(index); BuildConsolePartition last = (BuildConsolePartition)fPartitions.get(index);
if (last.canBeCombinedWith(partition)) { if (last.canBeCombinedWith(partition)) {
// replace with a single partition // replace with a single partition
partition = last.combineWith(partition); partition = last.combineWith(partition);
@ -305,12 +300,11 @@ public class BuildConsolePartitioner
appendToDocument(readBuffer(), fStream); appendToDocument(readBuffer(), fStream);
fManager.showConsole(); fManager.showConsole();
} }
public void close() throws IOException { public void close() throws IOException {
flush(); flush();
} }
public synchronized void write(byte[] b, int off, int len) throws IOException { public synchronized void write(byte[] b, int off, int len) throws IOException {
super.write(b, off, len); super.write(b, off, len);
flush(); flush();
@ -329,4 +323,4 @@ public class BuildConsolePartitioner
return new BuildOutputStream(fManager.errorStream); return new BuildOutputStream(fManager.errorStream);
} }
} }