1 11 package org.eclipse.ant.internal.ui.antsupport.logger; 12 13 import java.io.File ; 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.apache.tools.ant.BuildEvent; 18 import org.apache.tools.ant.Location; 19 import org.eclipse.ant.internal.ui.antsupport.AntSupportMessages; 20 import org.eclipse.ant.internal.ui.antsupport.logger.util.AntDebugState; 21 import org.eclipse.ant.internal.ui.antsupport.logger.util.IDebugBuildLogger; 22 import org.eclipse.ant.internal.ui.debug.IAntDebugController; 23 import org.eclipse.ant.internal.ui.debug.model.AntDebugTarget; 24 import org.eclipse.ant.internal.ui.debug.model.AntThread; 25 import org.eclipse.ant.internal.ui.launchConfigurations.AntProcess; 26 import org.eclipse.core.resources.IFile; 27 import org.eclipse.core.runtime.CoreException; 28 import org.eclipse.core.runtime.OperationCanceledException; 29 import org.eclipse.debug.core.DebugEvent; 30 import org.eclipse.debug.core.ILaunch; 31 import org.eclipse.debug.core.model.IBreakpoint; 32 import org.eclipse.debug.core.model.ILineBreakpoint; 33 import org.eclipse.debug.core.model.IProcess; 34 35 public class AntProcessDebugBuildLogger extends AntProcessBuildLogger implements IAntDebugController, IDebugBuildLogger { 36 37 private AntDebugState fDebugState= null; 38 39 private List fBreakpoints= null; 40 41 private AntDebugTarget fAntDebugTarget; 42 private boolean fResumed= false; 43 44 47 public void buildStarted(BuildEvent event) { 48 fDebugState= new AntDebugState(this); 49 super.buildStarted(event); 50 IProcess process= getAntProcess(fProcessId); 51 ILaunch launch= process.getLaunch(); 52 fAntDebugTarget= new AntDebugTarget(launch, process, this); 53 launch.addDebugTarget(fAntDebugTarget); 54 55 fAntDebugTarget.buildStarted(); 56 fDebugState.buildStarted(); 57 } 58 59 62 public void taskFinished(BuildEvent event) { 63 super.taskFinished(event); 64 fDebugState.taskFinished(); 65 } 66 67 70 public void taskStarted(BuildEvent event) { 71 super.taskStarted(event); 72 fDebugState.taskStarted(event); 73 } 74 75 78 public synchronized void waitIfSuspended() { 79 fResumed= false; 80 IBreakpoint breakpoint= breakpointAtLineNumber(fDebugState.getBreakpointLocation()); 81 if (breakpoint != null) { 82 fAntDebugTarget.breakpointHit(breakpoint); 83 try { 84 while (!fResumed) { 85 wait(500); 86 checkCancelled(); 87 } 88 } catch (InterruptedException e) { 89 } 90 } else if (fDebugState.getCurrentTask() != null) { 91 int detail= -1; 92 boolean shouldSuspend= true; 93 if (fDebugState.isStepIntoSuspend()) { 94 detail= DebugEvent.STEP_END; 95 fDebugState.setStepIntoSuspend(false); 96 } else if ((fDebugState.getLastTaskFinished() != null && fDebugState.getLastTaskFinished() == fDebugState.getStepOverTask()) || fDebugState.shouldSuspend()) { 97 detail= DebugEvent.STEP_END; 98 fDebugState.setShouldSuspend(false); 99 fDebugState.setStepOverTask(null); 100 } else if (fDebugState.isClientSuspend()) { 101 detail= DebugEvent.CLIENT_REQUEST; 102 fDebugState.setClientSuspend(false); 103 } else { 104 shouldSuspend= false; 105 } 106 if (shouldSuspend) { 107 fAntDebugTarget.suspended(detail); 108 try { 109 while (!fResumed) { 110 wait(500); 111 checkCancelled(); 112 } 113 } catch (InterruptedException e) { 114 } 115 } 116 } 117 } 118 119 private void checkCancelled() { 120 AntProcess process= getAntProcess(fProcessId); 121 if (process != null && process.isCanceled()) { 122 throw new OperationCanceledException(AntSupportMessages.AntProcessDebugBuildLogger_1); 123 } 124 } 125 126 129 public synchronized void resume() { 130 fResumed= true; 131 notifyAll(); 132 } 133 134 137 public synchronized void suspend() { 138 fDebugState.setClientSuspend(true); 139 } 140 141 144 public synchronized void stepInto() { 145 fDebugState.setStepIntoSuspend(true); 146 fResumed= true; 147 notifyAll(); 148 } 149 150 153 public synchronized void stepOver() { 154 fResumed= true; 155 fDebugState.stepOver(); 156 } 157 158 161 public void handleBreakpoint(IBreakpoint breakpoint, boolean added) { 162 if (added) { 163 if (fBreakpoints == null) { 164 fBreakpoints= new ArrayList (); 165 } 166 if (!fBreakpoints.contains(breakpoint)) { 167 fBreakpoints.add(breakpoint); 168 } 169 } else { 170 if (fBreakpoints != null) { 171 fBreakpoints.remove(breakpoint); 172 } 173 } 174 } 175 176 179 public void getProperties() { 180 if (!fAntDebugTarget.isSuspended()) { 181 return; 182 } 183 StringBuffer propertiesRepresentation= new StringBuffer (); 184 fDebugState.marshallProperties(propertiesRepresentation, false); 185 if (fAntDebugTarget.getThreads().length > 0) { 186 ((AntThread) fAntDebugTarget.getThreads()[0]).newProperties(propertiesRepresentation.toString()); 187 } 188 } 189 190 193 public void getStackFrames() { 194 StringBuffer stackRepresentation= new StringBuffer (); 195 fDebugState.marshalStack(stackRepresentation); 196 ((AntThread) fAntDebugTarget.getThreads()[0]).buildStack(stackRepresentation.toString()); 197 } 198 199 private IBreakpoint breakpointAtLineNumber(Location location) { 200 if (fBreakpoints == null || location == null || location == Location.UNKNOWN_LOCATION) { 201 return null; 202 } 203 int lineNumber= fDebugState.getLineNumber(location); 204 File locationFile= new File (fDebugState.getFileName(location)); 205 for (int i = 0; i < fBreakpoints.size(); i++) { 206 ILineBreakpoint breakpoint = (ILineBreakpoint) fBreakpoints.get(i); 207 int breakpointLineNumber; 208 try { 209 if (!breakpoint.isEnabled()) { 210 continue; 211 } 212 breakpointLineNumber = breakpoint.getLineNumber(); 213 } catch (CoreException e) { 214 return null; 215 } 216 IFile resource= (IFile) breakpoint.getMarker().getResource(); 217 if (breakpointLineNumber == lineNumber && resource.getLocation().toFile().equals(locationFile)) { 218 return breakpoint; 219 } 220 } 221 return null; 222 } 223 224 227 public void targetStarted(BuildEvent event) { 228 fDebugState.targetStarted(event); 229 waitIfSuspended(); 230 super.targetStarted(event); 231 } 232 233 236 public void targetFinished(BuildEvent event) { 237 super.targetFinished(event); 238 fDebugState.setTargetExecuting(null); 239 } 240 241 244 public StringBuffer unescapeString(StringBuffer propertyValue) { 245 return propertyValue; 246 } 247 } 248 | Popular Tags |