KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > launching > SootRunner


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Jennifer Lhotak
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 package ca.mcgill.sable.soot.launching;
21
22 import java.io.*;
23 import java.lang.reflect.InvocationTargetException JavaDoc;
24 import ca.mcgill.sable.soot.interaction.*;
25
26 import org.eclipse.core.runtime.IProgressMonitor;
27 import org.eclipse.jface.operation.IRunnableWithProgress;
28 import org.eclipse.swt.widgets.Display;
29 import ca.mcgill.sable.soot.util.*;
30 import java.util.*;
31 import org.eclipse.jface.dialogs.*;
32
33 /**
34  * Runs Soot and creates Handler for Soot output.
35  */

36 public class SootRunner implements IRunnableWithProgress {
37
38     Display display;
39     String JavaDoc [] cmd;
40     String JavaDoc mainClass;
41     ArrayList cfgList;
42     private SootLauncher parent;
43     
44     /**
45      * Constructor for SootRunner.
46      */

47     public SootRunner(String JavaDoc [] cmd, Display display , String JavaDoc mainClass) {
48         setDisplay(display);
49         setCmd(cmd);
50         setMainClass(mainClass);
51         
52     }
53
54     /**
55      * @see org.eclipse.jface.operation.IRunnableWithProgress#run(IProgressMonitor)
56      */

57     public void run(IProgressMonitor monitor)
58         throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
59         try {
60         
61             final PipedInputStream pis = new PipedInputStream();
62             
63             final PipedOutputStream pos = new PipedOutputStream(pis);
64             final PrintStream sootOut = new PrintStream(pos);
65             
66             final String JavaDoc [] cmdFinal = getCmd();
67             
68             SootThread sootThread = new SootThread(getDisplay(), getMainClass(), this);
69             
70             sootThread.setCmd(cmdFinal);
71             sootThread.setSootOut(sootOut);
72             sootThread.start();
73              
74             StreamGobbler out = new StreamGobbler(getDisplay(), pis, StreamGobbler.OUTPUT_STREAM_TYPE);
75             out.start();
76         
77             sootThread.join();
78             getParent().setCfgList(getCfgList());
79         }
80         catch (Exception JavaDoc e) {
81             System.out.println(e.getStackTrace());
82         }
83     }
84     
85
86     /**
87      * Returns the cmd.
88      * @return String[]
89      */

90     public String JavaDoc[] getCmd() {
91         return cmd;
92     }
93
94     /**
95      * Returns the display.
96      * @return Display
97      */

98     public Display getDisplay() {
99         return display;
100     }
101
102     /**
103      * Sets the cmd.
104      * @param cmd The cmd to set
105      */

106     public void setCmd(String JavaDoc[] cmd) {
107         this.cmd = cmd;
108     }
109
110     /**
111      * Sets the display.
112      * @param display The display to set
113      */

114     public void setDisplay(Display display) {
115         this.display = display;
116     }
117
118     /**
119      * @return
120      */

121     public String JavaDoc getMainClass() {
122         return mainClass;
123     }
124
125     /**
126      * @param string
127      */

128     public void setMainClass(String JavaDoc string) {
129         mainClass = string;
130     }
131
132     /**
133      * @return
134      */

135     public ArrayList getCfgList() {
136         return cfgList;
137     }
138
139     /**
140      * @param list
141      */

142     public void setCfgList(ArrayList list) {
143         cfgList = list;
144     }
145
146     /**
147      * @return
148      */

149     public SootLauncher getParent() {
150         return parent;
151     }
152
153     /**
154      * @param launcher
155      */

156     public void setParent(SootLauncher launcher) {
157         parent = launcher;
158     }
159
160 }
161
Popular Tags