From 152cd61440126a5882bf1243bd34971c8347cd68 Mon Sep 17 00:00:00 2001 From: axelcl Date: Mon, 14 Feb 2005 20:53:53 +0000 Subject: [PATCH] Using the standard console for "PHPConsole" output now! --- .../src/net/sourceforge/phpeclipse/PHPConsole.java | 107 ++++ .../phpeclipse/actions/ExternalPHPParser.java | 622 ++++++++++---------- .../phpeclipse/actions/PHPEclipseShowAction.java | 1 - .../phpeclipse/actions/PHPStartApacheAction.java | 6 +- .../sourceforge/phpeclipse/views/PHPConsole.java | 483 --------------- 5 files changed, 406 insertions(+), 813 deletions(-) create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPConsole.java delete mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPConsole.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPConsole.java new file mode 100644 index 0000000..b4d4a3f --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPConsole.java @@ -0,0 +1,107 @@ +package net.sourceforge.phpeclipse; + +import java.io.IOException; +import java.io.InputStream; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.MessageConsole; +import org.eclipse.ui.console.MessageConsoleStream; + +public class PHPConsole { + private MessageConsole myConsole; + + private MessageConsoleStream stream; + + private boolean hasMessages; + + public PHPConsole() { + hasMessages = false; + myConsole = new MessageConsole("PHPeclipse Console", null); + ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { myConsole }); + ConsolePlugin.getDefault().getConsoleManager().showConsoleView(myConsole); + // layout.addView(IConsoleConstants.ID_CONSOLE_VIEW, IPageLayout.BOTTOM, .5f,IPageLayout.ID_EDITOR_AREA); + stream = myConsole.newMessageStream(); + } + + /** + * @return + */ + public Color getColor() { + return stream.getColor(); + } + + /** + * @return + */ + public MessageConsole getConsole() { + return stream.getConsole(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + return stream.hashCode(); + } + + /** + * @param message + */ + public void print(String message) { + hasMessages = true; + stream.print(message); + } + + /** + * + */ + public void println() { + hasMessages = true; + stream.println(); + } + + /** + * @param message + */ + public void println(String message) { + hasMessages = true; + stream.println(message); + } + + /** + * @param color + */ + public void setColor(Color color) { + stream.setColor(color); + } + + // public void reportError(String title, String message) { + // if (hasMessages) { + // WikiEditorPlugin.getDefault().reportError(title, message); + // } + // } + + // public void reportError() { + // reportError("Problems listed", "Open console view for problems log!"); + // } + /** + * Creates a string buffer from the given input stream + */ + public static String getStringFromStream(InputStream stream) throws IOException { + StringBuffer buffer = new StringBuffer(); + byte[] b = new byte[100]; + int finished = 0; + while (finished != -1) { + finished = stream.read(b); + if (finished != -1) { + String current = new String(b, 0, finished); + buffer.append(current); + } + } + return buffer.toString(); + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/ExternalPHPParser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/ExternalPHPParser.java index 17c7535..6841740 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/ExternalPHPParser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/ExternalPHPParser.java @@ -6,8 +6,8 @@ import java.text.MessageFormat; import java.util.Hashtable; import net.sourceforge.phpdt.internal.ui.util.StringUtil; +import net.sourceforge.phpeclipse.PHPConsole; import net.sourceforge.phpeclipse.PHPeclipsePlugin; -import net.sourceforge.phpeclipse.views.PHPConsole; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; @@ -20,329 +20,299 @@ import org.eclipse.ui.texteditor.MarkerUtilities; * Calls the external parser and generates problem markers if necessary */ public class ExternalPHPParser { - private final static String PROBLEM_ID = "net.sourceforge.phpeclipse.problem"; - // strings for external parser call - private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$ - private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$ - public static final int ERROR = 2; - public static final int WARNING = 1; - public static final int INFO = 0; - public static final int TASK = 3; - // TODO design error? Analyze why fileToParse must be static ??? - final protected IFile fFileToParse; - - public ExternalPHPParser(IFile file) { - fFileToParse = file; - } - /** - * Call the php parse command ( php -l -f <filename> ) and create - * markers according to the external parser output. - * - * @param file - * the file that will be parsed - */ - public void phpExternalParse() { - //IFile file = (IFile) resource; - // final IPath path = file.getFullPath(); - final IPreferenceStore store = PHPeclipsePlugin.getDefault() - .getPreferenceStore(); - final String filename = fFileToParse.getLocation().toString(); - - final String[] arguments = {filename}; - final MessageFormat form = new MessageFormat(store - .getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF)); - final String command = form.format(arguments); - - final String parserResult = getParserOutput(command, - "External parser: "); - - try { - // parse the buffer to find the errors and warnings - createMarkers(parserResult, fFileToParse); - } catch (CoreException e) { - } - } - - /** - * Create markers according to the external parser output. - * - * @param output - * the external parser output - * @param file - * the file that was parsed. - */ - protected void createMarkers(final String output, final IFile file) - throws CoreException { - // delete all markers - file.deleteMarkers(PROBLEM_ID, false, 0); - - int indx = 0; - int brIndx; - boolean flag = true; - while ((brIndx = output.indexOf("
", indx)) != -1) { - // newer php error output (tested with 4.2.3) - scanLine(output, file, indx, brIndx); - indx = brIndx + 6; - flag = false; - } - if (flag) { - while ((brIndx = output.indexOf("
", indx)) != -1) { - // older php error output (tested with 4.2.3) - scanLine(output, file, indx, brIndx); - indx = brIndx + 4; - } - } - } - - private void scanLine(final String output, final IFile file, - final int indx, final int brIndx) throws CoreException { - String current; - // String outLineNumberString; never used - final StringBuffer lineNumberBuffer = new StringBuffer(10); - char ch; - current = output.substring(indx, brIndx); - - if (current.indexOf(PARSE_WARNING_STRING) != -1 - || current.indexOf(PARSE_ERROR_STRING) != -1) { - final int onLine = current.indexOf("on line "); - if (onLine != -1) { - lineNumberBuffer.delete(0, lineNumberBuffer.length()); - for (int i = onLine; i < current.length(); i++) { - ch = current.charAt(i); - if ('0' <= ch && '9' >= ch) { - lineNumberBuffer.append(ch); - } - } - - final int lineNumber = Integer.parseInt(lineNumberBuffer - .toString()); - - final Hashtable attributes = new Hashtable(); - - current = StringUtil.replaceAll(current, "\n", ""); - current = StringUtil.replaceAll(current, "", ""); - current = StringUtil.replaceAll(current, "", ""); - MarkerUtilities.setMessage(attributes, current); - - if (current.indexOf(PARSE_ERROR_STRING) != -1) - attributes.put(IMarker.SEVERITY, new Integer( - IMarker.SEVERITY_ERROR)); - else if (current.indexOf(PARSE_WARNING_STRING) != -1) - attributes.put(IMarker.SEVERITY, new Integer( - IMarker.SEVERITY_WARNING)); - else - attributes.put(IMarker.SEVERITY, new Integer( - IMarker.SEVERITY_INFO)); - MarkerUtilities.setLineNumber(attributes, lineNumber); - MarkerUtilities.createMarker(file, attributes, PROBLEM_ID); - } - } - } - - /** - * This will set a marker. - * - * @param file - * the file that generated the marker - * @param message - * the message - * @param charStart - * the starting character - * @param charEnd - * the end character - * @param errorLevel - * the error level ({@link ExternalPHPParser#ERROR}, - * {@link ExternalPHPParser#INFO}, - * {@link ExternalPHPParser#WARNING}), - * {@link ExternalPHPParser#TASK}) - * @throws CoreException - * an exception throwed by the MarkerUtilities - */ - private void setMarker(final IFile file, final String message, - final int charStart, final int charEnd, final int errorLevel) - throws CoreException { - if (file != null) { - final Hashtable attributes = new Hashtable(); - MarkerUtilities.setMessage(attributes, message); - switch (errorLevel) { - case ERROR : - attributes.put(IMarker.SEVERITY, new Integer( - IMarker.SEVERITY_ERROR)); - break; - case WARNING : - attributes.put(IMarker.SEVERITY, new Integer( - IMarker.SEVERITY_WARNING)); - break; - case INFO : - attributes.put(IMarker.SEVERITY, new Integer( - IMarker.SEVERITY_INFO)); - break; - case TASK : - attributes.put(IMarker.SEVERITY, new Integer(IMarker.TASK)); - break; - } - MarkerUtilities.setCharStart(attributes, charStart); - MarkerUtilities.setCharEnd(attributes, charEnd); - MarkerUtilities.createMarker(file, attributes, PROBLEM_ID); - } - } - - /** - * This will set a marker. - * - * @param file - * the file that generated the marker - * @param message - * the message - * @param line - * the line number - * @param errorLevel - * the error level ({@link ExternalPHPParser#ERROR}, - * {@link ExternalPHPParser#INFO}, - * {@link ExternalPHPParser#WARNING}) - * @throws CoreException - * an exception throwed by the MarkerUtilities - */ - private void setMarker(final IFile file, final String message, - final int line, final int errorLevel, final String location) - throws CoreException { - if (file != null) { - String markerKind = PROBLEM_ID; - final Hashtable attributes = new Hashtable(); - MarkerUtilities.setMessage(attributes, message); - switch (errorLevel) { - case ERROR : - attributes.put(IMarker.SEVERITY, new Integer( - IMarker.SEVERITY_ERROR)); - break; - case WARNING : - attributes.put(IMarker.SEVERITY, new Integer( - IMarker.SEVERITY_WARNING)); - break; - case INFO : - attributes.put(IMarker.SEVERITY, new Integer( - IMarker.SEVERITY_INFO)); - break; - case TASK : - attributes.put(IMarker.SEVERITY, new Integer( - IMarker.SEVERITY_INFO)); - markerKind = IMarker.TASK; - break; - } - attributes.put(IMarker.LOCATION, location); - MarkerUtilities.setLineNumber(attributes, line); - MarkerUtilities.createMarker(file, attributes, markerKind); - } - } - - /** - * This will set a marker. - * - * @param message - * the message - * @param charStart - * the starting character - * @param charEnd - * the end character - * @param errorLevel - * the error level ({@link ExternalPHPParser#ERROR}, - * {@link ExternalPHPParser#INFO}, - * {@link ExternalPHPParser#WARNING}) - * @throws CoreException - * an exception throwed by the MarkerUtilities - */ - private void setMarker(final String message, final int charStart, - final int charEnd, final int errorLevel, final String location) - throws CoreException { - if (fFileToParse != null) { - setMarker(fFileToParse, message, charStart, charEnd, errorLevel, - location); - } - } - - /** - * This will set a marker. - * - * @param file - * the file that generated the marker - * @param message - * the message - * @param charStart - * the starting character - * @param charEnd - * the end character - * @param errorLevel - * the error level ({@link ExternalPHPParser#ERROR}, - * {@link ExternalPHPParser#INFO}, - * {@link ExternalPHPParser#WARNING}) - * @param location - * the location of the error - * @throws CoreException - * an exception throwed by the MarkerUtilities - */ - private void setMarker(final IFile file, final String message, - final int charStart, final int charEnd, final int errorLevel, - final String location) throws CoreException { - if (file != null) { - final Hashtable attributes = new Hashtable(); - MarkerUtilities.setMessage(attributes, message); - switch (errorLevel) { - case ERROR : - attributes.put(IMarker.SEVERITY, new Integer( - IMarker.SEVERITY_ERROR)); - break; - case WARNING : - attributes.put(IMarker.SEVERITY, new Integer( - IMarker.SEVERITY_WARNING)); - break; - case INFO : - attributes.put(IMarker.SEVERITY, new Integer( - IMarker.SEVERITY_INFO)); - break; - case TASK : - attributes.put(IMarker.SEVERITY, new Integer(IMarker.TASK)); - break; - } - attributes.put(IMarker.LOCATION, location); - MarkerUtilities.setCharStart(attributes, charStart); - MarkerUtilities.setCharEnd(attributes, charEnd); - MarkerUtilities.createMarker(file, attributes, PROBLEM_ID); //IMarker.PROBLEM); - } - } - - private String getParserOutput(String command, String consoleMessage) { - try { - PHPConsole console = null; - try { - console = PHPConsole.getInstance(); - if (console != null) { - console.write(consoleMessage + command + "\n"); - } - } catch (Throwable th) { - - } - - Runtime runtime = Runtime.getRuntime(); - - // runs the command - Process p = runtime.exec(command); - - // gets the input stream to have the post-compile-time information - InputStream stream = p.getInputStream(); - - // get the string from Stream - String consoleOutput = PHPConsole.getStringFromStream(stream); - - // prints out the information - if (console != null) { - console.write(consoleOutput); - } - return consoleOutput; - - } catch (IOException e) { - MessageDialog - .openInformation(null, "IOException: ", e.getMessage()); - } - return ""; - } + private final static String PROBLEM_ID = "net.sourceforge.phpeclipse.problem"; + + // strings for external parser call + private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$ + + private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$ + + public static final int ERROR = 2; + + public static final int WARNING = 1; + + public static final int INFO = 0; + + public static final int TASK = 3; + + // TODO design error? Analyze why fileToParse must be static ??? + final protected IFile fFileToParse; + + public ExternalPHPParser(IFile file) { + fFileToParse = file; + } + + /** + * Call the php parse command ( php -l -f <filename> ) and create markers according to the external parser output. + * + * @param file + * the file that will be parsed + */ + public void phpExternalParse() { + //IFile file = (IFile) resource; + // final IPath path = file.getFullPath(); + final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); + final String filename = fFileToParse.getLocation().toString(); + + final String[] arguments = { filename }; + final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF)); + final String command = form.format(arguments); + + final String parserResult = getParserOutput(command, "External parser: "); + + try { + // parse the buffer to find the errors and warnings + createMarkers(parserResult, fFileToParse); + } catch (CoreException e) { + } + } + + /** + * Create markers according to the external parser output. + * + * @param output + * the external parser output + * @param file + * the file that was parsed. + */ + protected void createMarkers(final String output, final IFile file) throws CoreException { + // delete all markers + file.deleteMarkers(PROBLEM_ID, false, 0); + + int indx = 0; + int brIndx; + boolean flag = true; + while ((brIndx = output.indexOf("
", indx)) != -1) { + // newer php error output (tested with 4.2.3) + scanLine(output, file, indx, brIndx); + indx = brIndx + 6; + flag = false; + } + if (flag) { + while ((brIndx = output.indexOf("
", indx)) != -1) { + // older php error output (tested with 4.2.3) + scanLine(output, file, indx, brIndx); + indx = brIndx + 4; + } + } + } + + private void scanLine(final String output, final IFile file, final int indx, final int brIndx) throws CoreException { + String current; + // String outLineNumberString; never used + final StringBuffer lineNumberBuffer = new StringBuffer(10); + char ch; + current = output.substring(indx, brIndx); + + if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) { + final int onLine = current.indexOf("on line "); + if (onLine != -1) { + lineNumberBuffer.delete(0, lineNumberBuffer.length()); + for (int i = onLine; i < current.length(); i++) { + ch = current.charAt(i); + if ('0' <= ch && '9' >= ch) { + lineNumberBuffer.append(ch); + } + } + + final int lineNumber = Integer.parseInt(lineNumberBuffer.toString()); + + final Hashtable attributes = new Hashtable(); + + current = StringUtil.replaceAll(current, "\n", ""); + current = StringUtil.replaceAll(current, "", ""); + current = StringUtil.replaceAll(current, "", ""); + MarkerUtilities.setMessage(attributes, current); + + if (current.indexOf(PARSE_ERROR_STRING) != -1) + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); + else if (current.indexOf(PARSE_WARNING_STRING) != -1) + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING)); + else + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); + MarkerUtilities.setLineNumber(attributes, lineNumber); + MarkerUtilities.createMarker(file, attributes, PROBLEM_ID); + } + } + } + + /** + * This will set a marker. + * + * @param file + * the file that generated the marker + * @param message + * the message + * @param charStart + * the starting character + * @param charEnd + * the end character + * @param errorLevel + * the error level ({@link ExternalPHPParser#ERROR},{@link ExternalPHPParser#INFO},{@link ExternalPHPParser#WARNING}), + * {@link ExternalPHPParser#TASK}) + * @throws CoreException + * an exception throwed by the MarkerUtilities + */ + private void setMarker(final IFile file, final String message, final int charStart, final int charEnd, final int errorLevel) + throws CoreException { + if (file != null) { + final Hashtable attributes = new Hashtable(); + MarkerUtilities.setMessage(attributes, message); + switch (errorLevel) { + case ERROR: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); + break; + case WARNING: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING)); + break; + case INFO: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); + break; + case TASK: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.TASK)); + break; + } + MarkerUtilities.setCharStart(attributes, charStart); + MarkerUtilities.setCharEnd(attributes, charEnd); + MarkerUtilities.createMarker(file, attributes, PROBLEM_ID); + } + } + + /** + * This will set a marker. + * + * @param file + * the file that generated the marker + * @param message + * the message + * @param line + * the line number + * @param errorLevel + * the error level ({@link ExternalPHPParser#ERROR},{@link ExternalPHPParser#INFO},{@link ExternalPHPParser#WARNING}) + * @throws CoreException + * an exception throwed by the MarkerUtilities + */ + private void setMarker(final IFile file, final String message, final int line, final int errorLevel, final String location) + throws CoreException { + if (file != null) { + String markerKind = PROBLEM_ID; + final Hashtable attributes = new Hashtable(); + MarkerUtilities.setMessage(attributes, message); + switch (errorLevel) { + case ERROR: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); + break; + case WARNING: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING)); + break; + case INFO: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); + break; + case TASK: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); + markerKind = IMarker.TASK; + break; + } + attributes.put(IMarker.LOCATION, location); + MarkerUtilities.setLineNumber(attributes, line); + MarkerUtilities.createMarker(file, attributes, markerKind); + } + } + + /** + * This will set a marker. + * + * @param message + * the message + * @param charStart + * the starting character + * @param charEnd + * the end character + * @param errorLevel + * the error level ({@link ExternalPHPParser#ERROR},{@link ExternalPHPParser#INFO},{@link ExternalPHPParser#WARNING}) + * @throws CoreException + * an exception throwed by the MarkerUtilities + */ + private void setMarker(final String message, final int charStart, final int charEnd, final int errorLevel, final String location) + throws CoreException { + if (fFileToParse != null) { + setMarker(fFileToParse, message, charStart, charEnd, errorLevel, location); + } + } + + /** + * This will set a marker. + * + * @param file + * the file that generated the marker + * @param message + * the message + * @param charStart + * the starting character + * @param charEnd + * the end character + * @param errorLevel + * the error level ({@link ExternalPHPParser#ERROR},{@link ExternalPHPParser#INFO},{@link ExternalPHPParser#WARNING}) + * @param location + * the location of the error + * @throws CoreException + * an exception throwed by the MarkerUtilities + */ + private void setMarker(final IFile file, final String message, final int charStart, final int charEnd, final int errorLevel, + final String location) throws CoreException { + if (file != null) { + final Hashtable attributes = new Hashtable(); + MarkerUtilities.setMessage(attributes, message); + switch (errorLevel) { + case ERROR: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); + break; + case WARNING: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING)); + break; + case INFO: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); + break; + case TASK: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.TASK)); + break; + } + attributes.put(IMarker.LOCATION, location); + MarkerUtilities.setCharStart(attributes, charStart); + MarkerUtilities.setCharEnd(attributes, charEnd); + MarkerUtilities.createMarker(file, attributes, PROBLEM_ID); //IMarker.PROBLEM); + } + } + + private String getParserOutput(String command, String consoleMessage) { + try { + PHPConsole console = new PHPConsole(); + try { + console.println(consoleMessage + command); + } catch (Throwable th) { + + } + + Runtime runtime = Runtime.getRuntime(); + + // runs the command + Process p = runtime.exec(command); + + // gets the input stream to have the post-compile-time information + InputStream stream = p.getInputStream(); + + // get the string from Stream + String consoleOutput = PHPConsole.getStringFromStream(stream); + + // prints out the information + if (console != null) { + console.print(consoleOutput); + } + return consoleOutput; + + } catch (IOException e) { + MessageDialog.openInformation(null, "IOException: ", e.getMessage()); + } + return ""; + } } \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java index e0169ee..bfda727 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java @@ -61,7 +61,6 @@ public class PHPEclipseShowAction implements IObjectActionDelegate { selectionProvider = workbenchPart.getSite().getSelectionProvider(); StructuredSelection selection = null; selection = (StructuredSelection) selectionProvider.getSelection(); - // PHPConsole console = PHPConsole.getInstance(); IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); Shell shell = null; Iterator iterator = null; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartApacheAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartApacheAction.java index 5d47f96..a87c8a1 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartApacheAction.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartApacheAction.java @@ -14,9 +14,9 @@ package net.sourceforge.phpeclipse.actions; import java.text.MessageFormat; import net.sourceforge.phpdt.externaltools.launchConfigurations.ExternalToolsUtil; +import net.sourceforge.phpeclipse.PHPConsole; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.ui.WebUI; -import net.sourceforge.phpeclipse.views.PHPConsole; import org.eclipse.jface.action.IAction; import org.eclipse.jface.preference.IPreferenceStore; @@ -55,7 +55,7 @@ public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate { String executable, String arguments, boolean background) { - PHPConsole console = PHPConsole.getInstance(); + PHPConsole console = new PHPConsole(); String consoleMessage; if (background) { consoleMessage = @@ -74,7 +74,7 @@ public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate { + " " + arguments; } - console.write(consoleMessage + "\n"); + console.println(consoleMessage); ExternalToolsUtil.execute(command, executable, arguments, background); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java deleted file mode 100644 index 2e98d5d..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java +++ /dev/null @@ -1,483 +0,0 @@ -package net.sourceforge.phpeclipse.views; - -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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: - IBM Corporation - Initial implementation - www.phpeclipse.de -**********************************************************************/ - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -import net.sourceforge.phpdt.internal.ui.PHPUiImages; -import net.sourceforge.phpeclipse.PHPeclipsePlugin; -import net.sourceforge.phpeclipse.actions.PHPActionMessages; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.TextViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.part.ViewPart; - -/** - * The PHPConsole is used to display the output if you start MySQL/Apache - * @see ViewPart - */ -public class PHPConsole extends ViewPart { - - public static final String CONSOLE_ID = - "net.sourceforge.phpeclipse.views.phpconsoleview"; - private int COMMAND_COMBO_SIZE = 10; - - private TextViewer fViewer = null; - private Document fDocument = null; - private StyledText fStyledText; - // private Combo fCommandCombo; - // private ProcessOutputWriter consoleOut; - // private ProcessOutputWriter consoleErr; - - // private Action goAction; - - private Action cutAction = new Action() { - public void run() { - fViewer.getTextWidget().cut(); - } - }; - private Action copyAction = new Action() { - public void run() { - fStyledText.copy(); - } - }; - // private Action pasteAction = new Action() { - // public void run() { - // fViewer.getTextWidget().paste(); - // } - // }; - private Action selectAllAction = new Action() { - public void run() { - fStyledText.selectAll(); - } - }; - private Action clearAction = new Action() { - public void run() { - fStyledText.setText(""); - } - }; - /** - * The constructor. - */ - public PHPConsole() { - } - - /** - * Insert the method's description here. - * @see ViewPart#createPartControl - */ - public void createPartControl(Composite parent) { - // Composite container = new Composite(parent, SWT.NULL); - // // control = container; - // GridLayout layout = new GridLayout(); - // layout.marginWidth = 0; - // layout.marginHeight = 0; - // layout.verticalSpacing = 0; - // container.setLayout(layout); - // Composite navContainer = new Composite(container, SWT.NONE); - // layout = new GridLayout(); - // layout.numColumns = 2; - // layout.marginHeight = 1; - // navContainer.setLayout(layout); - // createCommandBar(navContainer); - // navContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - fViewer = new TextViewer(parent, SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL); - GridData viewerData = new GridData(GridData.FILL_BOTH); - fViewer.getControl().setLayoutData(viewerData); - fViewer.setEditable(false); - - fStyledText = fViewer.getTextWidget(); - fStyledText.setFont( - JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT)); - - cutAction.setText("Cut"); - copyAction.setText("Copy"); - // pasteAction.setText("Paste"); - selectAllAction.setText("Select All"); - clearAction.setText("Clear PHP Console"); - clearAction.setImageDescriptor(PHPUiImages.DESC_CLEAR); - clearAction.setToolTipText("Clear PHP Console"); - - IActionBars bars = this.getViewSite().getActionBars(); - bars.setGlobalActionHandler(IWorkbenchActionConstants.CUT, cutAction); - bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction); - // bars.setGlobalActionHandler(IWorkbenchActionConstants.PASTE, pasteAction); - - hookContextMenu(); - // hookDoubleClickAction(); - contributeToActionBars(); - - // appendOutputText("This is the PHP console.\n"); - // appendOutputText("Type: \"php $f\" to run the current editor file.\n"); - - } - - private void createCommandBar(Composite parent) { - // Label addressLabel = new Label(parent, SWT.NONE); - // addressLabel.setText("Command:"); - - // fCommandCombo = new Combo(parent, SWT.DROP_DOWN | SWT.BORDER); - // fCommandCombo.addModifyListener(new ModifyListener() { - // public void modifyText(ModifyEvent e) { - // String text = fCommandCombo.getText(); - // // goAction.setEnabled(text.length() > 0); - // } - // }); - // fCommandCombo.addSelectionListener(new SelectionListener() { - // public void widgetSelected(SelectionEvent e) { - // String text = fCommandCombo.getItem(fCommandCombo.getSelectionIndex()); - // if (text.length() > 0) { - // fCommandCombo.setText(text); - // // executeCommand(text); - // } - // } - // public void widgetDefaultSelected(SelectionEvent e) { - // executeCommand(fCommandCombo.getText()); - // } - // }); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - // fCommandCombo.setLayoutData(gd); - } - - // private void executeCommand(String command) { - // command.trim(); - // if (command.equals("")) { - // fCommandCombo.forceFocus(); - // return; - // } - // execute(command); - // - // fCommandCombo.forceFocus(); - // // add to Combo history - // String[] items = fCommandCombo.getItems(); - // int loc = -1; - // String normURL = command; - // for (int i = 0; i < items.length; i++) { - // String normItem = items[i]; - // if (normURL.equals(normItem)) { - // // match - // loc = i; - // break; - // } - // } - // if (loc != -1) { - // fCommandCombo.remove(loc); - // } - // fCommandCombo.add(command, 0); - // if (fCommandCombo.getItemCount() > COMMAND_COMBO_SIZE) { - // fCommandCombo.remove(fCommandCombo.getItemCount() - 1); - // } - // fCommandCombo.getParent().layout(true); - // } - - // private void execute(String command) { - // - // ArrayList args = new ArrayList(); - // - // command = command.replace('\\', '§'); - // - // StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(command)); - // tokenizer.resetSyntax(); - // - // tokenizer.whitespaceChars(0, ' '); - // tokenizer.wordChars('!', 255); - // - // tokenizer.quoteChar('"'); - // tokenizer.quoteChar('\''); - // - // int token; - // try { - // while ((token = tokenizer.nextToken()) != StreamTokenizer.TT_EOF) { - // if (token == StreamTokenizer.TT_WORD) { - // args.add(tokenizer.sval); - // } - // } - // } catch (IOException e) { - // // - // } - // String arg = ""; - // // replace variables in arguments - // - //// IFile file = getFile(); - // IFile file = PHPeclipsePlugin.getDefault().getLastEditorFile(); - // if (file != null) { - // String fileLocation = file.getLocation().toString(); - // for (int i = 0; i < args.size(); i++) { - // arg = args.get(i).toString(); - // if (arg.equals("$f")) { - // //current php editor file - // if (File.separatorChar == '\\') { - // fileLocation = fileLocation.replace('/', '\\'); - // } - // args.set(i, fileLocation); - // } - // } - // } - // - // final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); - // - // String arg0 = ""; - // String temp; - // StringBuffer commandBuffer = new StringBuffer(1024); - // // Program.launch(command); - // if (args.size() > 0) { - // arg0 = (String) args.get(0); - // arg0 = arg0.replace('§', '\\'); - // args.remove(0); - // if (arg0.equals("php")) { - // temp = store.getString(PHPeclipsePlugin.PHP_RUN_PREF); - // if (temp != null) { - // arg0 = temp; - // } - // } - // commandBuffer.append(arg0 + " "); - // } - // String[] stringArgs = new String[args.size()]; - // for (int i = 0; i < args.size(); i++) { - // arg = (String) args.get(i); - // arg = arg.replace('§', '\\'); - // stringArgs[i] = arg; - // commandBuffer.append(arg + " "); - // } - // commandBuffer.append("\n"); - // - // try { - // command = commandBuffer.toString(); - // write(command+"\n"); - // Runtime runtime = Runtime.getRuntime(); - // - // // runs the command - // Process process = runtime.exec(command); - // - // consoleOut = new ProcessOutputWriter(process.getInputStream()); - // consoleOut.start(); - // consoleErr = new ProcessOutputWriter(process.getErrorStream()); - // consoleErr.start(); - // - // //process.waitFor(); - //// InputStream in = process.getInputStream(); - //// String output = getStringFromStream(in); - //// write(output); - //// in.close(); - //// } catch (InterruptedException e) { - //// write(e.toString()); - // } catch (IOException e) { - // write(e.toString()); - // } - // } - - private void hookContextMenu() { - MenuManager menuMgr = new MenuManager("#PopupMenu"); - menuMgr.setRemoveAllWhenShown(true); - menuMgr.addMenuListener(new IMenuListener() { - public void menuAboutToShow(IMenuManager manager) { - PHPConsole.this.fillContextMenu(manager); - } - }); - Menu menu = menuMgr.createContextMenu(fViewer.getControl()); - fViewer.getControl().setMenu(menu); - getSite().registerContextMenu(menuMgr, fViewer); - } - - private void contributeToActionBars() { - IActionBars bars = getViewSite().getActionBars(); - fillLocalPullDown(bars.getMenuManager()); - fillLocalToolBar(bars.getToolBarManager()); - } - - private void fillLocalPullDown(IMenuManager manager) { - manager.add(cutAction); - manager.add(copyAction); - // manager.add(pasteAction); - manager.add(selectAllAction); - } - - private void fillContextMenu(IMenuManager manager) { - manager.add(cutAction); - manager.add(copyAction); - // manager.add(pasteAction); - manager.add(selectAllAction); - // Other plug-ins can contribute there actions here - manager.add(new Separator("Additions")); - } - - private void fillLocalToolBar(IToolBarManager manager) { - manager.add(clearAction); - } - /** - * Insert the method's description here. - * @see ViewPart#setFocus - */ - public void setFocus() { - // fCommandCombo.forceFocus(); - } - - /** - * Set the text for the viewer - */ - public void setOutputText(String text) { - fDocument = new Document(text); - fViewer.setDocument(fDocument); - } - - public void appendOutputText(String text) { - try { - if (fDocument == null) { - fDocument = new Document(text); - fViewer.setDocument(fDocument); - } else { - fDocument.replace(fDocument.getLength(), 0, text); - } - } catch (BadLocationException e) { - } - // viewer.setDocument(document); - } - - public static PHPConsole getInstance() { - // IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - IWorkbenchPage page = - PHPeclipsePlugin - .getDefault() - .getWorkbench() - .getActiveWorkbenchWindow() - .getActivePage(); - PHPConsole console = (PHPConsole) page.findView(PHPConsole.CONSOLE_ID); - - if (PHPeclipsePlugin - .getDefault() - .getPreferenceStore() - .getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) - == true) { - try { - page.showView(PHPConsole.CONSOLE_ID); - if (console == null) { - console = (PHPConsole) page.findView(PHPConsole.CONSOLE_ID); - } - } catch (PartInitException e) { - PHPeclipsePlugin.getDefault().getLog().log( - new Status( - IStatus.ERROR, - PHPeclipsePlugin.getPluginId(), - 0, - PHPActionMessages.getString( - "PHPStartApacheAction.consoleViewOpeningProblem"), - e)); - } - } - return console; - } - - /** - * Prints out the string represented by the string - */ - public synchronized void write(String output) { - appendOutputText(output); - } - - /** - * Creates a string buffer from the given input stream - */ - public static String getStringFromStream(InputStream stream) - throws IOException { - StringBuffer buffer = new StringBuffer(); - byte[] b = new byte[100]; - int finished = 0; - while (finished != -1) { - finished = stream.read(b); - if (finished != -1) { - String current = new String(b, 0, finished); - buffer.append(current); - } - } - return buffer.toString(); - } - - /** - * Finds the file that's currently opened in the PHP Text Editor - */ - // protected IFile getFile() { - // ITextEditor editor = PHPeclipsePlugin.getDefault().getLastEditorFile(); - // - // IEditorInput editorInput = null; - // if (editor != null) { - // editorInput = editor.getEditorInput(); - // } - // - // if (editorInput instanceof IFileEditorInput) - // return ((IFileEditorInput) editorInput).getFile(); - // - // // if nothing was found, which should never happen - // return null; - // } - - class ProcessOutputWriter extends Thread { - boolean fStreamClosed; - InputStream fInputStream; - - ProcessOutputWriter(InputStream inputStream) { - fInputStream = inputStream; - fStreamClosed = false; - } - - public void closeStream() { - fStreamClosed = true; - try { - fInputStream.close(); - } catch (IOException io) { - } - } - - public void run() { - try { - BufferedReader in = - new BufferedReader(new InputStreamReader(fInputStream)); - - String line; - while ((line = in.readLine()) != null) { - write(line); - } - in.close(); - } catch (Exception e) { - e.printStackTrace(System.out); - if (!fStreamClosed) { - // write("\nPHP Console Exception: "+ e.toString() ); - } - } finally { - } - } - } - -} -- 1.7.1