diff options
Diffstat (limited to 'org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java')
-rw-r--r-- | org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java | 1202 |
1 files changed, 601 insertions, 601 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java index 0514024ee..4c8d38382 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java @@ -98,43 +98,43 @@ import com.ibm.icu.text.MessageFormat; */ @SuppressWarnings("deprecation") public class ProcessConsole extends IOConsole implements IConsole, IDebugEventSetListener, IPropertyChangeListener { - private IProcess fProcess = null; + private IProcess fProcess = null; private List<StreamListener> fStreamListeners = new ArrayList<>(); - private IConsoleColorProvider fColorProvider; + private IConsoleColorProvider fColorProvider; private volatile InputStream fInput; - private FileOutputStream fFileOutputStream; + private FileOutputStream fFileOutputStream; - private boolean fAllocateConsole = true; + private boolean fAllocateConsole = true; private String fStdInFile = null; - private boolean fStreamsClosed = false; - - /** - * Proxy to a console document - */ - public ProcessConsole(IProcess process, IConsoleColorProvider colorProvider) { - this(process, colorProvider, null); - } - - /** - * Constructor - * @param process the process to associate with this console - * @param colorProvider the colour provider for this console - * @param encoding the desired encoding for this console - */ - public ProcessConsole(IProcess process, IConsoleColorProvider colorProvider, String encoding) { - super(IInternalDebugCoreConstants.EMPTY_STRING, IDebugUIConstants.ID_PROCESS_CONSOLE_TYPE, null, encoding, true); - fProcess = process; - - ILaunchConfiguration configuration = process.getLaunch().getLaunchConfiguration(); - String file = null; - boolean append = false; - if (configuration != null) { - try { + private boolean fStreamsClosed = false; + + /** + * Proxy to a console document + */ + public ProcessConsole(IProcess process, IConsoleColorProvider colorProvider) { + this(process, colorProvider, null); + } + + /** + * Constructor + * @param process the process to associate with this console + * @param colorProvider the colour provider for this console + * @param encoding the desired encoding for this console + */ + public ProcessConsole(IProcess process, IConsoleColorProvider colorProvider, String encoding) { + super(IInternalDebugCoreConstants.EMPTY_STRING, IDebugUIConstants.ID_PROCESS_CONSOLE_TYPE, null, encoding, true); + fProcess = process; + + ILaunchConfiguration configuration = process.getLaunch().getLaunchConfiguration(); + String file = null; + boolean append = false; + if (configuration != null) { + try { file = configuration.getAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_FILE, (String) null); fStdInFile = configuration.getAttribute(IDebugUIConstants.ATTR_CAPTURE_STDIN_FILE, (String) null); if (file != null || fStdInFile != null) { @@ -147,54 +147,54 @@ public class ProcessConsole extends IOConsole implements IConsole, IDebugEventSe if (fStdInFile != null) { fStdInFile = stringVariableManager.performStringSubstitution(fStdInFile); } - } - } catch (CoreException e) { - } - } - - if (file != null && configuration != null) { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - IWorkspaceRoot root = workspace.getRoot(); - Path path = new Path(file); - IFile ifile = root.getFileForLocation(path); - String message = null; - - try { - String fileLoc = null; - if (ifile != null) { - if (append && ifile.exists()) { - ifile.appendContents(new ByteArrayInputStream(new byte[0]), true, true, new NullProgressMonitor()); - } else { - if (ifile.exists()) { - ifile.delete(true, new NullProgressMonitor()); - } - ifile.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor()); - } - } - - File outputFile = new File(file); - fFileOutputStream = new FileOutputStream(outputFile, append); - fileLoc = outputFile.getAbsolutePath(); + } + } catch (CoreException e) { + } + } + + if (file != null && configuration != null) { + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IWorkspaceRoot root = workspace.getRoot(); + Path path = new Path(file); + IFile ifile = root.getFileForLocation(path); + String message = null; + + try { + String fileLoc = null; + if (ifile != null) { + if (append && ifile.exists()) { + ifile.appendContents(new ByteArrayInputStream(new byte[0]), true, true, new NullProgressMonitor()); + } else { + if (ifile.exists()) { + ifile.delete(true, new NullProgressMonitor()); + } + ifile.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor()); + } + } + + File outputFile = new File(file); + fFileOutputStream = new FileOutputStream(outputFile, append); + fileLoc = outputFile.getAbsolutePath(); message = MessageFormat.format(ConsoleMessages.ProcessConsole_1, new Object[] { fileLoc }); - addPatternMatchListener(new ConsoleLogFilePatternMatcher(fileLoc)); - } catch (FileNotFoundException e) { + addPatternMatchListener(new ConsoleLogFilePatternMatcher(fileLoc)); + } catch (FileNotFoundException e) { message = MessageFormat.format(ConsoleMessages.ProcessConsole_2, new Object[] { file }); - } catch (CoreException e) { - DebugUIPlugin.log(e); - } - if (message != null) { + } catch (CoreException e) { + DebugUIPlugin.log(e); + } + if (message != null) { try (IOConsoleOutputStream stream = newOutputStream()) { - stream.write(message); - } catch (IOException e) { - DebugUIPlugin.log(e); - } - } - try { - fAllocateConsole = configuration.getAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE, true); - } catch (CoreException e) { - } - } + stream.write(message); + } catch (IOException e) { + DebugUIPlugin.log(e); + } + } + try { + fAllocateConsole = configuration.getAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE, true); + } catch (CoreException e) { + } + } if (fStdInFile != null && configuration != null) { String message = null; try { @@ -214,501 +214,501 @@ public class ProcessConsole extends IOConsole implements IConsole, IDebugEventSe } } } - fColorProvider = colorProvider; + fColorProvider = colorProvider; if (fInput == null) { fInput = getInputStream(); } - colorProvider.connect(fProcess, this); + colorProvider.connect(fProcess, this); - setName(computeName()); + setName(computeName()); - Color color = fColorProvider.getColor(IDebugUIConstants.ID_STANDARD_INPUT_STREAM); + Color color = fColorProvider.getColor(IDebugUIConstants.ID_STANDARD_INPUT_STREAM); if (fInput instanceof IOConsoleInputStream) { ((IOConsoleInputStream)fInput).setColor(color); } - IConsoleLineTracker[] lineTrackers = DebugUIPlugin.getDefault().getProcessConsoleManager().getLineTrackers(process); - if (lineTrackers.length > 0) { - addPatternMatchListener(new ConsoleLineNotifier()); - } - } - - /** - * Computes and returns the image descriptor for this console. - * - * @return an image descriptor for this console or <code>null</code> - */ - protected ImageDescriptor computeImageDescriptor() { - ILaunchConfiguration configuration = getProcess().getLaunch().getLaunchConfiguration(); - if (configuration != null) { - ILaunchConfigurationType type; - try { - type = configuration.getType(); - return DebugPluginImages.getImageDescriptor(type.getIdentifier()); - } catch (CoreException e) { - DebugUIPlugin.log(e); - } - } - return null; - } - - /** - * Computes and returns the current name of this console. - * - * @return a name for this console - */ - protected String computeName() { - String label = null; - IProcess process = getProcess(); - ILaunchConfiguration config = process.getLaunch().getLaunchConfiguration(); - - label = process.getAttribute(IProcess.ATTR_PROCESS_LABEL); - if (label == null) { - if (config == null) { - label = process.getLabel(); - } else { - // check if PRIVATE config - if (DebugUITools.isPrivate(config)) { - label = process.getLabel(); - } else { - String type = null; - try { - type = config.getType().getName(); - } catch (CoreException e) { - } - StringBuilder buffer = new StringBuilder(); - buffer.append(config.getName()); - if (type != null) { - buffer.append(" ["); //$NON-NLS-1$ - buffer.append(type); - buffer.append("] "); //$NON-NLS-1$ - } - buffer.append(process.getLabel()); - label = buffer.toString(); - } - } - } - - if (process.isTerminated()) { + IConsoleLineTracker[] lineTrackers = DebugUIPlugin.getDefault().getProcessConsoleManager().getLineTrackers(process); + if (lineTrackers.length > 0) { + addPatternMatchListener(new ConsoleLineNotifier()); + } + } + + /** + * Computes and returns the image descriptor for this console. + * + * @return an image descriptor for this console or <code>null</code> + */ + protected ImageDescriptor computeImageDescriptor() { + ILaunchConfiguration configuration = getProcess().getLaunch().getLaunchConfiguration(); + if (configuration != null) { + ILaunchConfigurationType type; + try { + type = configuration.getType(); + return DebugPluginImages.getImageDescriptor(type.getIdentifier()); + } catch (CoreException e) { + DebugUIPlugin.log(e); + } + } + return null; + } + + /** + * Computes and returns the current name of this console. + * + * @return a name for this console + */ + protected String computeName() { + String label = null; + IProcess process = getProcess(); + ILaunchConfiguration config = process.getLaunch().getLaunchConfiguration(); + + label = process.getAttribute(IProcess.ATTR_PROCESS_LABEL); + if (label == null) { + if (config == null) { + label = process.getLabel(); + } else { + // check if PRIVATE config + if (DebugUITools.isPrivate(config)) { + label = process.getLabel(); + } else { + String type = null; + try { + type = config.getType().getName(); + } catch (CoreException e) { + } + StringBuilder buffer = new StringBuilder(); + buffer.append(config.getName()); + if (type != null) { + buffer.append(" ["); //$NON-NLS-1$ + buffer.append(type); + buffer.append("] "); //$NON-NLS-1$ + } + buffer.append(process.getLabel()); + label = buffer.toString(); + } + } + } + + if (process.isTerminated()) { return MessageFormat.format(ConsoleMessages.ProcessConsole_0, new Object[] { label }); - } - return label; - } - - /** - * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) - */ - @Override + } + return label; + } + + /** + * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) + */ + @Override public void propertyChange(PropertyChangeEvent evt) { - String property = evt.getProperty(); - IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore(); - if (property.equals(IDebugPreferenceConstants.CONSOLE_WRAP) || property.equals(IDebugPreferenceConstants.CONSOLE_WIDTH)) { - boolean fixedWidth = store.getBoolean(IDebugPreferenceConstants.CONSOLE_WRAP); - if (fixedWidth) { - int width = store.getInt(IDebugPreferenceConstants.CONSOLE_WIDTH); - setConsoleWidth(width); - } else { - setConsoleWidth(-1); - } - } else if (property.equals(IDebugPreferenceConstants.CONSOLE_LIMIT_CONSOLE_OUTPUT) || property.equals(IDebugPreferenceConstants.CONSOLE_HIGH_WATER_MARK) || property.equals(IDebugPreferenceConstants.CONSOLE_LOW_WATER_MARK)) { - boolean limitBufferSize = store.getBoolean(IDebugPreferenceConstants.CONSOLE_LIMIT_CONSOLE_OUTPUT); - if (limitBufferSize) { - int highWater = store.getInt(IDebugPreferenceConstants.CONSOLE_HIGH_WATER_MARK); - int lowWater = store.getInt(IDebugPreferenceConstants.CONSOLE_LOW_WATER_MARK); - if (highWater > lowWater) { - setWaterMarks(lowWater, highWater); - } - } else { - setWaterMarks(-1, -1); - } - } else if (property.equals(IDebugPreferenceConstants.CONSOLE_TAB_WIDTH)) { - int tabWidth = store.getInt(IDebugPreferenceConstants.CONSOLE_TAB_WIDTH); - setTabWidth(tabWidth); + String property = evt.getProperty(); + IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore(); + if (property.equals(IDebugPreferenceConstants.CONSOLE_WRAP) || property.equals(IDebugPreferenceConstants.CONSOLE_WIDTH)) { + boolean fixedWidth = store.getBoolean(IDebugPreferenceConstants.CONSOLE_WRAP); + if (fixedWidth) { + int width = store.getInt(IDebugPreferenceConstants.CONSOLE_WIDTH); + setConsoleWidth(width); + } else { + setConsoleWidth(-1); + } + } else if (property.equals(IDebugPreferenceConstants.CONSOLE_LIMIT_CONSOLE_OUTPUT) || property.equals(IDebugPreferenceConstants.CONSOLE_HIGH_WATER_MARK) || property.equals(IDebugPreferenceConstants.CONSOLE_LOW_WATER_MARK)) { + boolean limitBufferSize = store.getBoolean(IDebugPreferenceConstants.CONSOLE_LIMIT_CONSOLE_OUTPUT); + if (limitBufferSize) { + int highWater = store.getInt(IDebugPreferenceConstants.CONSOLE_HIGH_WATER_MARK); + int lowWater = store.getInt(IDebugPreferenceConstants.CONSOLE_LOW_WATER_MARK); + if (highWater > lowWater) { + setWaterMarks(lowWater, highWater); + } + } else { + setWaterMarks(-1, -1); + } + } else if (property.equals(IDebugPreferenceConstants.CONSOLE_TAB_WIDTH)) { + int tabWidth = store.getInt(IDebugPreferenceConstants.CONSOLE_TAB_WIDTH); + setTabWidth(tabWidth); } else if (property.equals(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT)) { - boolean activateOnOut = store.getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT); + boolean activateOnOut = store.getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT); @SuppressWarnings("resource") IOConsoleOutputStream stream = getStream(IDebugUIConstants.ID_STANDARD_OUTPUT_STREAM); - if (stream != null) { - stream.setActivateOnWrite(activateOnOut); - } - } else if (property.equals(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR)) { - boolean activateOnErr = store.getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR); + if (stream != null) { + stream.setActivateOnWrite(activateOnOut); + } + } else if (property.equals(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR)) { + boolean activateOnErr = store.getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR); @SuppressWarnings("resource") IOConsoleOutputStream stream = getStream(IDebugUIConstants.ID_STANDARD_ERROR_STREAM); - if (stream != null) { - stream.setActivateOnWrite(activateOnErr); - } - } else if (property.equals(IDebugPreferenceConstants.CONSOLE_SYS_OUT_COLOR)) { + if (stream != null) { + stream.setActivateOnWrite(activateOnErr); + } + } else if (property.equals(IDebugPreferenceConstants.CONSOLE_SYS_OUT_COLOR)) { @SuppressWarnings("resource") IOConsoleOutputStream stream = getStream(IDebugUIConstants.ID_STANDARD_OUTPUT_STREAM); - if (stream != null) { - stream.setColor(fColorProvider.getColor(IDebugUIConstants.ID_STANDARD_OUTPUT_STREAM)); - } - } else if (property.equals(IDebugPreferenceConstants.CONSOLE_SYS_ERR_COLOR)) { + if (stream != null) { + stream.setColor(fColorProvider.getColor(IDebugUIConstants.ID_STANDARD_OUTPUT_STREAM)); + } + } else if (property.equals(IDebugPreferenceConstants.CONSOLE_SYS_ERR_COLOR)) { @SuppressWarnings("resource") IOConsoleOutputStream stream = getStream(IDebugUIConstants.ID_STANDARD_ERROR_STREAM); - if (stream != null) { - stream.setColor(fColorProvider.getColor(IDebugUIConstants.ID_STANDARD_ERROR_STREAM)); - } - } else if (property.equals(IDebugPreferenceConstants.CONSOLE_SYS_IN_COLOR)) { + if (stream != null) { + stream.setColor(fColorProvider.getColor(IDebugUIConstants.ID_STANDARD_ERROR_STREAM)); + } + } else if (property.equals(IDebugPreferenceConstants.CONSOLE_SYS_IN_COLOR)) { if (fInput != null && fInput instanceof IOConsoleInputStream) { ((IOConsoleInputStream) fInput).setColor(fColorProvider.getColor(IDebugUIConstants.ID_STANDARD_INPUT_STREAM)); - } - } else if (property.equals(IDebugUIConstants.PREF_CONSOLE_FONT)) { - setFont(JFaceResources.getFont(IDebugUIConstants.PREF_CONSOLE_FONT)); - } else if (property.equals(IDebugPreferenceConstants.CONSOLE_BAKGROUND_COLOR)) { - setBackground(DebugUIPlugin.getPreferenceColor(IDebugPreferenceConstants.CONSOLE_BAKGROUND_COLOR)); - } - } - - @Override + } + } else if (property.equals(IDebugUIConstants.PREF_CONSOLE_FONT)) { + setFont(JFaceResources.getFont(IDebugUIConstants.PREF_CONSOLE_FONT)); + } else if (property.equals(IDebugPreferenceConstants.CONSOLE_BAKGROUND_COLOR)) { + setBackground(DebugUIPlugin.getPreferenceColor(IDebugPreferenceConstants.CONSOLE_BAKGROUND_COLOR)); + } + } + + @Override public IOConsoleOutputStream getStream(String streamIdentifier) { if (streamIdentifier == null) { return null; } for (StreamListener listener : fStreamListeners) { if (streamIdentifier.equals(listener.fStreamId)) { - return listener.fStream; - } - } - return null; - } - - /** - * @see org.eclipse.debug.ui.console.IConsole#getProcess() - */ - @Override + return listener.fStream; + } + } + return null; + } + + /** + * @see org.eclipse.debug.ui.console.IConsole#getProcess() + */ + @Override public IProcess getProcess() { - return fProcess; - } + return fProcess; + } - /** - * @see org.eclipse.ui.console.IOConsole#dispose() - */ - @Override + /** + * @see org.eclipse.ui.console.IOConsole#dispose() + */ + @Override protected void dispose() { - super.dispose(); - fColorProvider.disconnect(); - DebugPlugin.getDefault().removeDebugEventListener(this); - DebugUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this); - JFaceResources.getFontRegistry().removeListener(this); + super.dispose(); + fColorProvider.disconnect(); + DebugPlugin.getDefault().removeDebugEventListener(this); + DebugUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this); + JFaceResources.getFontRegistry().removeListener(this); closeStreams(); disposeStreams(); - } + } - /** + /** * cleanup method to close all of the open stream to this console */ - private synchronized void closeStreams() { - if (fStreamsClosed) { - return; - } + private synchronized void closeStreams() { + if (fStreamsClosed) { + return; + } for (StreamListener listener : fStreamListeners) { - listener.closeStream(); - } - if (fFileOutputStream != null) { - synchronized (fFileOutputStream) { - try { - fFileOutputStream.flush(); - fFileOutputStream.close(); - } catch (IOException e) { - } - } - } - try { - fInput.close(); - } catch (IOException e) { - } - fStreamsClosed = true; - } - - /** + listener.closeStream(); + } + if (fFileOutputStream != null) { + synchronized (fFileOutputStream) { + try { + fFileOutputStream.flush(); + fFileOutputStream.close(); + } catch (IOException e) { + } + } + } + try { + fInput.close(); + } catch (IOException e) { + } + fStreamsClosed = true; + } + + /** * disposes the listeners for each of the stream associated with this * console */ - private synchronized void disposeStreams() { + private synchronized void disposeStreams() { for (StreamListener listener : fStreamListeners) { - listener.dispose(); - } - fFileOutputStream = null; - fInput = null; - } - - /** - * @see org.eclipse.ui.console.AbstractConsole#init() - */ - @Override + listener.dispose(); + } + fFileOutputStream = null; + fInput = null; + } + + /** + * @see org.eclipse.ui.console.AbstractConsole#init() + */ + @Override protected void init() { - super.init(); + super.init(); DebugPlugin.getDefault().addDebugEventListener(this); - if (fProcess.isTerminated()) { - closeStreams(); - resetName(); + if (fProcess.isTerminated()) { + closeStreams(); + resetName(); DebugPlugin.getDefault().removeDebugEventListener(this); - } - IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore(); - store.addPropertyChangeListener(this); - JFaceResources.getFontRegistry().addListener(this); - if (store.getBoolean(IDebugPreferenceConstants.CONSOLE_WRAP)) { - setConsoleWidth(store.getInt(IDebugPreferenceConstants.CONSOLE_WIDTH)); - } - setTabWidth(store.getInt(IDebugPreferenceConstants.CONSOLE_TAB_WIDTH)); - - if (store.getBoolean(IDebugPreferenceConstants.CONSOLE_LIMIT_CONSOLE_OUTPUT)) { - int highWater = store.getInt(IDebugPreferenceConstants.CONSOLE_HIGH_WATER_MARK); - int lowWater = store.getInt(IDebugPreferenceConstants.CONSOLE_LOW_WATER_MARK); - setWaterMarks(lowWater, highWater); - } + } + IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore(); + store.addPropertyChangeListener(this); + JFaceResources.getFontRegistry().addListener(this); + if (store.getBoolean(IDebugPreferenceConstants.CONSOLE_WRAP)) { + setConsoleWidth(store.getInt(IDebugPreferenceConstants.CONSOLE_WIDTH)); + } + setTabWidth(store.getInt(IDebugPreferenceConstants.CONSOLE_TAB_WIDTH)); + + if (store.getBoolean(IDebugPreferenceConstants.CONSOLE_LIMIT_CONSOLE_OUTPUT)) { + int highWater = store.getInt(IDebugPreferenceConstants.CONSOLE_HIGH_WATER_MARK); + int lowWater = store.getInt(IDebugPreferenceConstants.CONSOLE_LOW_WATER_MARK); + setWaterMarks(lowWater, highWater); + } DebugUIPlugin.getStandardDisplay().asyncExec(() -> { setFont(JFaceResources.getFont(IDebugUIConstants.PREF_CONSOLE_FONT)); setBackground(DebugUIPlugin.getPreferenceColor(IDebugPreferenceConstants.CONSOLE_BAKGROUND_COLOR)); }); - } - - /** - * Notify listeners when name changes. - * - * @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent[]) - */ - @Override + } + + /** + * Notify listeners when name changes. + * + * @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent[]) + */ + @Override public void handleDebugEvents(DebugEvent[] events) { - for (int i = 0; i < events.length; i++) { - DebugEvent event = events[i]; - if (event.getSource().equals(getProcess())) { - - if (event.getKind() == DebugEvent.TERMINATE) { - closeStreams(); - DebugPlugin.getDefault().removeDebugEventListener(this); - } - - resetName(); - } - } - } - - /** - * resets the name of this console to the original computed name - */ + for (int i = 0; i < events.length; i++) { + DebugEvent event = events[i]; + if (event.getSource().equals(getProcess())) { + + if (event.getKind() == DebugEvent.TERMINATE) { + closeStreams(); + DebugPlugin.getDefault().removeDebugEventListener(this); + } + + resetName(); + } + } + } + + /** + * resets the name of this console to the original computed name + */ private synchronized void resetName() { - final String newName = computeName(); - String name = getName(); - if (!name.equals(newName)) { - UIJob job = new UIJob("Update console title") { //$NON-NLS-1$ + final String newName = computeName(); + String name = getName(); + if (!name.equals(newName)) { + UIJob job = new UIJob("Update console title") { //$NON-NLS-1$ @Override public IStatus runInUIThread(IProgressMonitor monitor) { ProcessConsole.this.setName(newName); - warnOfContentChange(); - return Status.OK_STATUS; + warnOfContentChange(); + return Status.OK_STATUS; } }; job.setSystem(true); job.schedule(); - } - } - - /** - * send notification of a change of content in this console - */ - private void warnOfContentChange() { - ConsolePlugin.getDefault().getConsoleManager().warnOfContentChange(DebugUITools.getConsole(fProcess)); - } - - /** - * @see org.eclipse.debug.ui.console.IConsole#connect(org.eclipse.debug.core.model.IStreamsProxy) - */ - @Override + } + } + + /** + * send notification of a change of content in this console + */ + private void warnOfContentChange() { + ConsolePlugin.getDefault().getConsoleManager().warnOfContentChange(DebugUITools.getConsole(fProcess)); + } + + /** + * @see org.eclipse.debug.ui.console.IConsole#connect(org.eclipse.debug.core.model.IStreamsProxy) + */ + @Override public void connect(IStreamsProxy streamsProxy) { - IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore(); - IStreamMonitor streamMonitor = streamsProxy.getErrorStreamMonitor(); - if (streamMonitor != null) { - connect(streamMonitor, IDebugUIConstants.ID_STANDARD_ERROR_STREAM, - store.getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR)); - } - streamMonitor = streamsProxy.getOutputStreamMonitor(); - if (streamMonitor != null) { - connect(streamMonitor, IDebugUIConstants.ID_STANDARD_OUTPUT_STREAM, - store.getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT)); - } - InputReadJob readJob = new InputReadJob(streamsProxy); - readJob.setSystem(true); - readJob.schedule(); - } - - /** - * @see org.eclipse.debug.ui.console.IConsole#connect(org.eclipse.debug.core.model.IStreamMonitor, java.lang.String) - */ - @Override + IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore(); + IStreamMonitor streamMonitor = streamsProxy.getErrorStreamMonitor(); + if (streamMonitor != null) { + connect(streamMonitor, IDebugUIConstants.ID_STANDARD_ERROR_STREAM, + store.getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR)); + } + streamMonitor = streamsProxy.getOutputStreamMonitor(); + if (streamMonitor != null) { + connect(streamMonitor, IDebugUIConstants.ID_STANDARD_OUTPUT_STREAM, + store.getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT)); + } + InputReadJob readJob = new InputReadJob(streamsProxy); + readJob.setSystem(true); + readJob.schedule(); + } + + /** + * @see org.eclipse.debug.ui.console.IConsole#connect(org.eclipse.debug.core.model.IStreamMonitor, java.lang.String) + */ + @Override public void connect(IStreamMonitor streamMonitor, String streamIdentifier) { - connect(streamMonitor, streamIdentifier, false); - } - - /** - * Connects the given stream monitor to a new output stream with the given identifier. - * - * @param streamMonitor stream monitor - * @param streamIdentifier stream identifier - * @param activateOnWrite whether the stream should displayed when written to - */ + connect(streamMonitor, streamIdentifier, false); + } + + /** + * Connects the given stream monitor to a new output stream with the given identifier. + * + * @param streamMonitor stream monitor + * @param streamIdentifier stream identifier + * @param activateOnWrite whether the stream should displayed when written to + */ @SuppressWarnings("resource") private void connect(IStreamMonitor streamMonitor, String streamIdentifier, boolean activateOnWrite) { - IOConsoleOutputStream stream = null; - if (fAllocateConsole) { + IOConsoleOutputStream stream = null; + if (fAllocateConsole) { stream = newOutputStream(); Color color = fColorProvider.getColor(streamIdentifier); stream.setColor(color); stream.setActivateOnWrite(activateOnWrite); - } - synchronized (streamMonitor) { - StreamListener listener = new StreamListener(streamIdentifier, streamMonitor, stream); - fStreamListeners.add(listener); - } - } - - /** - * @see org.eclipse.debug.ui.console.IConsole#addLink(org.eclipse.debug.ui.console.IConsoleHyperlink, int, int) - */ - @Override + } + synchronized (streamMonitor) { + StreamListener listener = new StreamListener(streamIdentifier, streamMonitor, stream); + fStreamListeners.add(listener); + } + } + + /** + * @see org.eclipse.debug.ui.console.IConsole#addLink(org.eclipse.debug.ui.console.IConsoleHyperlink, int, int) + */ + @Override public void addLink(IConsoleHyperlink link, int offset, int length) { - try { - addHyperlink(link, offset, length); - } catch (BadLocationException e) { - DebugUIPlugin.log(e); - } - } - - /** - * @see org.eclipse.debug.ui.console.IConsole#addLink(org.eclipse.ui.console.IHyperlink, int, int) - */ - @Override + try { + addHyperlink(link, offset, length); + } catch (BadLocationException e) { + DebugUIPlugin.log(e); + } + } + + /** + * @see org.eclipse.debug.ui.console.IConsole#addLink(org.eclipse.ui.console.IHyperlink, int, int) + */ + @Override public void addLink(IHyperlink link, int offset, int length) { - try { - addHyperlink(link, offset, length); - } catch (BadLocationException e) { - DebugUIPlugin.log(e); - } - } - - /** - * @see org.eclipse.debug.ui.console.IConsole#getRegion(org.eclipse.debug.ui.console.IConsoleHyperlink) - */ - @Override + try { + addHyperlink(link, offset, length); + } catch (BadLocationException e) { + DebugUIPlugin.log(e); + } + } + + /** + * @see org.eclipse.debug.ui.console.IConsole#getRegion(org.eclipse.debug.ui.console.IConsoleHyperlink) + */ + @Override public IRegion getRegion(IConsoleHyperlink link) { - return super.getRegion(link); - } + return super.getRegion(link); + } - /** - * This class listens to a specified IO stream - */ - private class StreamListener implements IStreamListener { + /** + * This class listens to a specified IO stream + */ + private class StreamListener implements IStreamListener { - private IOConsoleOutputStream fStream; + private IOConsoleOutputStream fStream; - private IStreamMonitor fStreamMonitor; + private IStreamMonitor fStreamMonitor; - private String fStreamId; + private String fStreamId; - private boolean fFlushed = false; + private boolean fFlushed = false; - private boolean fListenerRemoved = false; + private boolean fListenerRemoved = false; - public StreamListener(String streamIdentifier, IStreamMonitor monitor, IOConsoleOutputStream stream) { - this.fStreamId = streamIdentifier; - this.fStreamMonitor = monitor; - this.fStream = stream; - fStreamMonitor.addListener(this); - //fix to bug 121454. Ensure that output to fast processes is processed. - streamAppended(null, monitor); - } + public StreamListener(String streamIdentifier, IStreamMonitor monitor, IOConsoleOutputStream stream) { + this.fStreamId = streamIdentifier; + this.fStreamMonitor = monitor; + this.fStream = stream; + fStreamMonitor.addListener(this); + //fix to bug 121454. Ensure that output to fast processes is processed. + streamAppended(null, monitor); + } - @Override + @Override public void streamAppended(String text, IStreamMonitor monitor) { - String encoding = getEncoding(); - if (fFlushed) { - try { - if (fStream != null) { - if (encoding == null) { + String encoding = getEncoding(); + if (fFlushed) { + try { + if (fStream != null) { + if (encoding == null) { fStream.write(text); } else { fStream.write(text.getBytes(encoding)); } - } - if (fFileOutputStream != null) { - synchronized (fFileOutputStream) { - if (encoding == null) { + } + if (fFileOutputStream != null) { + synchronized (fFileOutputStream) { + if (encoding == null) { fFileOutputStream.write(text.getBytes()); } else { fFileOutputStream.write(text.getBytes(encoding)); } - } - } - } catch (IOException e) { - DebugUIPlugin.log(e); - } - } else { - String contents = null; - synchronized (fStreamMonitor) { - fFlushed = true; - contents = fStreamMonitor.getContents(); - if (fStreamMonitor instanceof IFlushableStreamMonitor) { - IFlushableStreamMonitor m = (IFlushableStreamMonitor) fStreamMonitor; - m.flushContents(); - m.setBuffered(false); - } - } - try { - if (contents != null && contents.length() > 0) { - if (fStream != null) { - fStream.write(contents); - } - if (fFileOutputStream != null) { - synchronized (fFileOutputStream) { - fFileOutputStream.write(contents.getBytes()); - } - } - } - } catch (IOException e) { - DebugUIPlugin.log(e); - } - } - } - - public void closeStream() { - if (fStreamMonitor == null) { - return; - } - synchronized (fStreamMonitor) { - fStreamMonitor.removeListener(this); - if (!fFlushed) { - String contents = fStreamMonitor.getContents(); - streamAppended(contents, fStreamMonitor); - } - fListenerRemoved = true; - try { - if (fStream != null) { - fStream.close(); - } - } catch (IOException e) { - } - } - } - - public void dispose() { - if (!fListenerRemoved) { - closeStream(); - } - fStream = null; - fStreamMonitor = null; - fStreamId = null; - } - } - - private class InputReadJob extends Job { - - private IStreamsProxy streamsProxy; + } + } + } catch (IOException e) { + DebugUIPlugin.log(e); + } + } else { + String contents = null; + synchronized (fStreamMonitor) { + fFlushed = true; + contents = fStreamMonitor.getContents(); + if (fStreamMonitor instanceof IFlushableStreamMonitor) { + IFlushableStreamMonitor m = (IFlushableStreamMonitor) fStreamMonitor; + m.flushContents(); + m.setBuffered(false); + } + } + try { + if (contents != null && contents.length() > 0) { + if (fStream != null) { + fStream.write(contents); + } + if (fFileOutputStream != null) { + synchronized (fFileOutputStream) { + fFileOutputStream.write(contents.getBytes()); + } + } + } + } catch (IOException e) { + DebugUIPlugin.log(e); + } + } + } + + public void closeStream() { + if (fStreamMonitor == null) { + return; + } + synchronized (fStreamMonitor) { + fStreamMonitor.removeListener(this); + if (!fFlushed) { + String contents = fStreamMonitor.getContents(); + streamAppended(contents, fStreamMonitor); + } + fListenerRemoved = true; + try { + if (fStream != null) { + fStream.close(); + } + } catch (IOException e) { + } + } + } + + public void dispose() { + if (!fListenerRemoved) { + closeStream(); + } + fStream = null; + fStreamMonitor = null; + fStreamId = null; + } + } + + private class InputReadJob extends Job { + + private IStreamsProxy streamsProxy; /** * The {@link InputStream} this job is currently reading from or maybe blocking @@ -716,10 +716,10 @@ public class ProcessConsole extends IOConsole implements IConsole, IDebugEventSe */ private InputStream readingStream; - InputReadJob(IStreamsProxy streamsProxy) { - super("Process Console Input Job"); //$NON-NLS-1$ - this.streamsProxy = streamsProxy; - } + InputReadJob(IStreamsProxy streamsProxy) { + super("Process Console Input Job"); //$NON-NLS-1$ + this.streamsProxy = streamsProxy; + } @Override protected void canceling() { @@ -736,7 +736,7 @@ public class ProcessConsole extends IOConsole implements IConsole, IDebugEventSe } } - @Override + @Override public boolean belongsTo(Object family) { return ProcessConsole.class == family; } @@ -750,7 +750,7 @@ public class ProcessConsole extends IOConsole implements IConsole, IDebugEventSe readingStream = fInput; InputStreamReader streamReader = (encoding == null ? new InputStreamReader(readingStream) : new InputStreamReader(readingStream, encoding)); - try { + try { char[] cbuf = new char[1024]; int charRead = 0; while (charRead >= 0 && !monitor.isCanceled()) { @@ -766,160 +766,160 @@ public class ProcessConsole extends IOConsole implements IConsole, IDebugEventSe charRead = streamReader.read(cbuf); if (charRead > 0) { String s = new String(cbuf, 0, charRead); - streamsProxy.write(s); - } - } - } catch (IOException e) { - DebugUIPlugin.log(e); - } + streamsProxy.write(s); + } + } + } catch (IOException e) { + DebugUIPlugin.log(e); + } readingStream = null; return monitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS; - } - } + } + } - @Override + @Override public ImageDescriptor getImageDescriptor() { - if (super.getImageDescriptor() == null) { - setImageDescriptor(computeImageDescriptor()); - } - return super.getImageDescriptor(); - } - - private class ConsoleLogFilePatternMatcher implements IPatternMatchListener { - String fFilePath; - - public ConsoleLogFilePatternMatcher(String filePath) { - fFilePath = escape(filePath); - } - - private String escape(String path) { - StringBuilder buffer = new StringBuilder(path); - int index = buffer.indexOf("\\"); //$NON-NLS-1$ - while (index >= 0) { - buffer.insert(index, '\\'); - index = buffer.indexOf("\\", index+2); //$NON-NLS-1$ - } - return buffer.toString(); - } - - @Override + if (super.getImageDescriptor() == null) { + setImageDescriptor(computeImageDescriptor()); + } + return super.getImageDescriptor(); + } + + private class ConsoleLogFilePatternMatcher implements IPatternMatchListener { + String fFilePath; + + public ConsoleLogFilePatternMatcher(String filePath) { + fFilePath = escape(filePath); + } + + private String escape(String path) { + StringBuilder buffer = new StringBuilder(path); + int index = buffer.indexOf("\\"); //$NON-NLS-1$ + while (index >= 0) { + buffer.insert(index, '\\'); + index = buffer.indexOf("\\", index+2); //$NON-NLS-1$ + } + return buffer.toString(); + } + + @Override public String getPattern() { - return fFilePath; - } + return fFilePath; + } - @Override + @Override public void matchFound(PatternMatchEvent event) { - try { - addHyperlink(new ConsoleLogFileHyperlink(fFilePath), event.getOffset(), event.getLength()); - removePatternMatchListener(this); - } catch (BadLocationException e) { - } - } - - @Override + try { + addHyperlink(new ConsoleLogFileHyperlink(fFilePath), event.getOffset(), event.getLength()); + removePatternMatchListener(this); + } catch (BadLocationException e) { + } + } + + @Override public int getCompilerFlags() { - return 0; - } + return 0; + } - @Override + @Override public String getLineQualifier() { - return null; - } + return null; + } - @Override + @Override public void connect(TextConsole console) { - } + } - @Override + @Override public void disconnect() { - } - } + } + } - private class ConsoleLogFileHyperlink implements IHyperlink { - String fFilePath; - ConsoleLogFileHyperlink(String filePath) { - fFilePath = filePath; - } + private class ConsoleLogFileHyperlink implements IHyperlink { + String fFilePath; + ConsoleLogFileHyperlink(String filePath) { + fFilePath = filePath; + } - @Override + @Override public void linkActivated() { - IEditorInput input; - Path path = new Path(fFilePath); - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - IFile ifile = root.getFileForLocation(path); - if (ifile == null) { // The file is not in the workspace - File file = new File(fFilePath); - LocalFileStorage lfs = new LocalFileStorage(file); - input = new StorageEditorInput(lfs, file); - - } else { - input = new FileEditorInput(ifile); - } - - IWorkbenchPage activePage = DebugUIPlugin.getActiveWorkbenchWindow().getActivePage(); - try { - activePage.openEditor(input, EditorsUI.DEFAULT_TEXT_EDITOR_ID, true); - } catch (PartInitException e) { - } - } - @Override + IEditorInput input; + Path path = new Path(fFilePath); + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IFile ifile = root.getFileForLocation(path); + if (ifile == null) { // The file is not in the workspace + File file = new File(fFilePath); + LocalFileStorage lfs = new LocalFileStorage(file); + input = new StorageEditorInput(lfs, file); + + } else { + input = new FileEditorInput(ifile); + } + + IWorkbenchPage activePage = DebugUIPlugin.getActiveWorkbenchWindow().getActivePage(); + try { + activePage.openEditor(input, EditorsUI.DEFAULT_TEXT_EDITOR_ID, true); + } catch (PartInitException e) { + } + } + @Override public void linkEntered() { - } - @Override + } + @Override public void linkExited() { - } - } + } + } - class StorageEditorInput extends PlatformObject implements IStorageEditorInput { - private File fFile; - private IStorage fStorage; + class StorageEditorInput extends PlatformObject implements IStorageEditorInput { + private File fFile; + private IStorage fStorage; - public StorageEditorInput(IStorage storage, File file) { - fStorage = storage; - fFile = file; - } + public StorageEditorInput(IStorage storage, File file) { + fStorage = storage; + fFile = file; + } - @Override + @Override public IStorage getStorage() { - return fStorage; - } + return fStorage; + } - @Override + @Override public ImageDescriptor getImageDescriptor() { - return null; - } + return null; + } - @Override + @Override public String getName() { - return getStorage().getName(); - } + return getStorage().getName(); + } - @Override + @Override public IPersistableElement getPersistable() { - return null; - } + return null; + } - @Override + @Override public String getToolTipText() { - return getStorage().getFullPath().toOSString(); - } + return getStorage().getFullPath().toOSString(); + } - @Override + @Override public boolean equals(Object object) { - return object instanceof StorageEditorInput && - getStorage().equals(((StorageEditorInput)object).getStorage()); - } + return object instanceof StorageEditorInput && + getStorage().equals(((StorageEditorInput)object).getStorage()); + } - @Override + @Override public int hashCode() { - return getStorage().hashCode(); - } + return getStorage().hashCode(); + } - @Override + @Override public boolean exists() { - return fFile.exists(); - } - } + return fFile.exists(); + } + } @Override public String getHelpContextId() { |