/* * Created on Jun 25, 2003 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package CDBuilder.console; /** * @author ssim * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Path; import org.eclipse.swt.widgets.Display; public class StreamHandler extends Thread { InputStream is; String type; boolean print,inputTask=false; boolean isError = false; ConsoleDocument cdos; String line; IWorkspaceRoot resource; public class conWrite implements Runnable { String line; public conWrite(String line) { this.line = line; } public void run() { ConsoleDocument.getCDOS().set(line + "\n"); } } public StreamHandler(InputStream is, String type, boolean print) { this.is = is; this.type = type; this.print = print; resource=null; //cdos = ConsoleDocument.getCDOS(); } public StreamHandler(InputStream is, String type, boolean print, IResource resource, boolean inputTask) { this(is,type,print); this.resource=(IWorkspaceRoot)resource; this.inputTask=inputTask; //cdos = ConsoleDocument.getCDOS(); } synchronized public void run() { try{ InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String msg,path,line=null; int firstIndex, lastIndex,lineNumber,currentLine=0; if(inputTask==true){ int depth = IResource.DEPTH_INFINITE; try { resource.deleteMarkers(null, true, depth); } catch (CoreException e) { // something went wrong } } while ( (line = br.readLine()) != null) { System.out.println(type + ">" + line); if (print==true) Display.getDefault().syncExec(new conWrite(line)); if (inputTask == true){ try{ int pathIndex=line.indexOf("workspace"); firstIndex=line.indexOf(":"); lastIndex=line.indexOf(":",firstIndex+1); msg=line.substring(lastIndex+2); path=line.substring(pathIndex,firstIndex); path=path.substring(path.indexOf("/")); String msgType=line.substring(firstIndex,lastIndex); if(msgType.startsWith("warning",5)){ IMarker marker = resource.createMarker(IMarker.PROBLEM); marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING); marker.setAttribute(IMarker.MESSAGE,msg); }else{ msgType=msgType.trim(); if (msgType.length()!=0){ lineNumber=new Integer(msgType.substring(1)).intValue(); if(lineNumber==currentLine) continue; IFile file=resource.getFile(new Path(path)); IMarker marker = file.createMarker(IMarker.PROBLEM); marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); currentLine=lineNumber; marker.setAttribute(IMarker.LINE_NUMBER,lineNumber); marker.setAttribute(IMarker.MESSAGE,msg); } isError=true; } }catch (Exception e){ // System.out.println("exception here"); continue; } } } } catch (IOException ioe){ ioe.printStackTrace(); } catch (Exception e) { System.out.println("The action has caused: " + e); } } public boolean getErrors() { return isError; } }