1 19 20 package ca.mcgill.sable.soot.launching; 21 22 import org.eclipse.ui.*; 23 import org.eclipse.ui.texteditor.AbstractTextEditor; 24 import org.eclipse.jface.dialogs.*; 25 import org.eclipse.jface.operation.IRunnableWithProgress; 26 import org.eclipse.jface.operation.ModalContext; 27 import org.eclipse.jface.text.ITextOperationTarget; 28 import org.eclipse.jface.text.source.SourceViewer; 29 import org.eclipse.jface.viewers.*; 30 import org.eclipse.jface.action.*; 31 import org.eclipse.core.resources.IResource; 32 import org.eclipse.core.runtime.*; 33 import java.lang.reflect.InvocationTargetException ; 34 import ca.mcgill.sable.soot.*; 35 import ca.mcgill.sable.soot.attributes.AbstractAttributesComputer; 36 import ca.mcgill.sable.soot.attributes.JavaAttributesComputer; 37 import ca.mcgill.sable.soot.attributes.JimpleAttributesComputer; 38 import ca.mcgill.sable.soot.attributes.SootAttributesJavaColorer; 39 import ca.mcgill.sable.soot.editors.*; 40 import org.eclipse.swt.widgets.*; 41 import org.eclipse.jdt.core.*; 42 import ca.mcgill.sable.soot.cfg.*; 43 import ca.mcgill.sable.graph.testing.*; 44 import ca.mcgill.sable.graph.*; 45 46 import java.util.*; 47 import soot.jimple.toolkits.annotation.callgraph.*; 48 49 53 public abstract class SootLauncher implements IWorkbenchWindowActionDelegate { 54 55 private IWorkbenchPart part; 56 protected IWorkbenchWindow window; 57 private ISelection selection; 58 private IStructuredSelection structured; 59 protected String platform_location; 60 protected String external_jars_location; 61 public SootClasspath sootClasspath = new SootClasspath(); 62 public SootSelection sootSelection; 63 private SootCommandList sootCommandList; 64 private String outputLocation; 65 private SootDefaultCommands sdc; 66 private SootOutputFilesHandler fileHandler; 67 private DavaHandler davaHandler; 68 private ArrayList cfgList; 69 70 public void run(IAction action) { 71 72 setSootSelection(new SootSelection(structured)); 73 getSootSelection().initialize(); 74 setFileHandler(new SootOutputFilesHandler(window)); 75 getFileHandler().resetSootOutputFolder(getSootSelection().getProject()); 76 setDavaHandler(new DavaHandler()); 77 getDavaHandler().setSootOutputFolder(getFileHandler().getSootOutputFolder()); 78 getDavaHandler().handleBefore(); 79 initPaths(); 80 initCommandList(); 81 82 83 } 84 85 86 private void initCommandList() { 87 setSootCommandList(new SootCommandList()); 88 } 89 90 protected void runSootDirectly(){ 91 runSootDirectly("soot.Main"); 92 } 93 94 private void sendSootOutputEvent(String toSend){ 95 SootOutputEvent send = new SootOutputEvent(this, ISootOutputEventConstants.SOOT_NEW_TEXT_EVENT); 96 send.setTextToAppend(toSend); 97 final SootOutputEvent sendFinal = send; 98 99 Display.getCurrent().asyncExec(new Runnable (){ 100 public void run() { 101 SootPlugin.getDefault().fireSootOutputEvent(sendFinal); 102 }; 103 }); 104 } 105 106 protected void runSootDirectly(String mainClass) { 107 108 int length = getSootCommandList().getList().size(); 109 String temp [] = new String [length]; 110 111 getSootCommandList().getList().toArray(temp); 112 113 sendSootOutputEvent(mainClass); 114 sendSootOutputEvent(" "); 115 116 final String [] cmdAsArray = temp; 117 118 for (int i = 0; i < temp.length; i++) { 119 120 sendSootOutputEvent(temp[i]); 121 sendSootOutputEvent(" "); 122 } 123 sendSootOutputEvent("\n"); 124 125 126 IRunnableWithProgress op; 127 try { 128 newProcessStarting(); 129 op = new SootRunner(temp, Display.getCurrent(), mainClass); 130 ((SootRunner)op).setParent(this); 131 ModalContext.run(op, true, new NullProgressMonitor(), Display.getCurrent()); 132 } 133 catch (InvocationTargetException e1) { 134 System.out.println("InvocationTargetException: "+e1.getMessage()); 136 System.out.println("InvocationTargetException: "+e1.getTargetException()); 137 System.out.println(e1.getStackTrace()); 138 } 139 catch (InterruptedException e2) { 140 System.out.println("InterruptedException: "+e2.getMessage()); 142 } 143 144 } 145 146 protected void runSootAsProcess(String cmd) { 147 148 SootProcessRunner op; 149 try { 150 newProcessStarting(); 151 op = new SootProcessRunner(Display.getCurrent(), cmd, sootClasspath); 152 153 if (window == null) { 154 window = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow(); 155 } 156 new ProgressMonitorDialog(window.getShell()).run(true, true, op); 157 158 159 } 160 catch (InvocationTargetException e1) { 161 } 163 catch (InterruptedException e2) { 164 System.out.println(e2.getMessage()); 166 } 167 168 169 170 } 171 private void newProcessStarting() { 172 SootOutputEvent clear_event = new SootOutputEvent(this, ISootOutputEventConstants.SOOT_CLEAR_EVENT); 173 SootPlugin.getDefault().fireSootOutputEvent(clear_event); 174 SootOutputEvent se = new SootOutputEvent(this, ISootOutputEventConstants.SOOT_NEW_TEXT_EVENT); 175 se.setTextToAppend("Starting ..."); 176 SootPlugin.getDefault().fireSootOutputEvent(se); 177 } 178 179 private String [] formCmdLine(String cmd) { 180 181 182 StringTokenizer st = new StringTokenizer(cmd); 183 int count = st.countTokens(); 184 String [] cmdLine = new String [count]; 185 count = 0; 186 187 while(st.hasMoreTokens()) { 188 cmdLine[count++] = st.nextToken(); 189 } 190 191 return cmdLine; 192 } 193 194 private void initPaths() { 195 196 sootClasspath.initialize(); 197 198 platform_location = getSootSelection().getJavaProject().getProject().getLocation().toOSString(); 200 platform_location = platform_location.substring(0, platform_location.lastIndexOf(System.getProperty("file.separator"))); 201 setOutputLocation(platform_location+getFileHandler().getSootOutputFolder().getFullPath().toOSString()); 203 204 } 205 206 protected void addJars(){ 207 try { 208 209 IPackageFragmentRoot [] roots = getSootSelection().getJavaProject().getAllPackageFragmentRoots(); 210 211 for (int i = 0; i < roots.length; i++){ 212 if (roots[i].isArchive()){ 213 if (roots[i].getResource() != null){ 214 215 setClasspathAppend(platform_location+roots[i].getPath().toOSString()); 216 } 217 else { 218 setClasspathAppend(roots[i].getPath().toOSString()); 219 220 } 221 } 222 } 223 } 224 catch (JavaModelException e){ 225 } 226 } 227 228 public abstract void setClasspathAppend(String ca); 229 230 public void runFinish() { 231 getFileHandler().refreshFolder(); 232 getFileHandler().refreshAll(getSootSelection().getProject()); 233 SootPlugin.getDefault().getManager().updateSootRanFlag(); 235 final IEditorPart activeEdPart = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); 236 SootPlugin.getDefault().getPartManager().updatePart(activeEdPart); 237 if (getCfgList() != null){ 239 GraphGenerator generator = new GraphGenerator(); 241 generator.setChildren(convertPkgList(getCfgList())); 242 GraphPlugin.getDefault().setGenerator(generator); 243 244 generator.run(null); 245 } 246 } 247 248 HashMap alreadyDone = new HashMap(); 249 250 private ArrayList convertPkgList(ArrayList pkgList){ 251 ArrayList conList = new ArrayList(); 252 Iterator it = pkgList.iterator(); 253 while(it.hasNext()){ 254 CallData cd = (CallData)it.next(); 255 TestNode tn = null; 256 if (alreadyDone.containsKey(cd)){ 257 tn = (TestNode)alreadyDone.get(cd); 258 } 259 else { 260 tn = new TestNode(); 261 tn.setData(cd.getData()); 262 alreadyDone.put(cd, tn); 263 if (cd.getChildren().size() != 0){ 264 tn.setChildren(convertPkgList(cd.getChildren())); 265 } 266 if (cd.getOutputs().size() != 0){ 267 tn.setOutputs(convertPkgList(cd.getOutputs())); 268 } 269 } 270 conList.add(tn); 271 272 } 273 274 return conList; 275 } 276 277 278 public IStructuredSelection getStructured() { 279 return structured; 280 } 281 282 private void setStructured(IStructuredSelection struct) { 283 structured = struct; 284 } 285 286 public void init(IWorkbenchWindow window) { 287 this.window = window; 288 } 289 290 public void dispose() { 291 } 292 293 public void selectionChanged(IAction action, ISelection selection) { 294 this.selection = selection; 295 296 if (selection instanceof IStructuredSelection){ 297 setStructured((IStructuredSelection)selection); 298 } 299 } 300 301 305 public SootClasspath getSootClasspath() { 306 return sootClasspath; 307 } 308 309 313 public void setSootClasspath(SootClasspath sootClasspath) { 314 this.sootClasspath = sootClasspath; 315 } 316 317 321 public SootSelection getSootSelection() { 322 return sootSelection; 323 } 324 325 329 public void setSootSelection(SootSelection sootSelection) { 330 this.sootSelection = sootSelection; 331 } 332 333 334 335 339 public IWorkbenchWindow getWindow() { 340 return window; 341 } 342 343 347 public SootCommandList getSootCommandList() { 348 return sootCommandList; 349 } 350 351 355 public void setSootCommandList(SootCommandList sootCommandList) { 356 this.sootCommandList = sootCommandList; 357 } 358 359 363 public String getOutputLocation() { 364 return outputLocation; 365 } 366 367 371 public void setOutputLocation(String outputLocation) { 372 this.outputLocation = outputLocation; 373 } 374 375 379 public SootDefaultCommands getSdc() { 380 return sdc; 381 } 382 383 387 public void setSdc(SootDefaultCommands sdc) { 388 this.sdc = sdc; 389 } 390 391 395 public SootOutputFilesHandler getFileHandler() { 396 return fileHandler; 397 } 398 399 403 public void setFileHandler(SootOutputFilesHandler fileHandler) { 404 this.fileHandler = fileHandler; 405 } 406 407 410 public DavaHandler getDavaHandler() { 411 return davaHandler; 412 } 413 414 417 public void setDavaHandler(DavaHandler handler) { 418 davaHandler = handler; 419 } 420 421 424 public ArrayList getCfgList() { 425 return cfgList; 426 } 427 428 431 public void setCfgList(ArrayList list) { 432 cfgList = list; 433 } 434 435 } 436 | Popular Tags |