Skip to content

Commit

Permalink
Parse arguments and URLs in executor instead of monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
gabegorelick committed Apr 17, 2011
1 parent 5273415 commit 8955e23
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 58 deletions.
30 changes: 28 additions & 2 deletions src/edu/umd/cs/guitar/ripper/SWTGuitarExecutor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package edu.umd.cs.guitar.ripper;

import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -84,13 +86,37 @@ protected SWTGuitarExecutor(SWTGuitarConfiguration config, Thread guiThread) {
}

this.config = config;
this.application = new SWTApplication(config.getMainClass(), guiThread);

this.application = initSWTApplication(config, guiThread);
this.xmlConfig = loadXmlConfig();

System.setProperty(GUITARLog.LOGFILE_NAME_SYSTEM_PROPERTY, config.getLogFile());
}

private SWTApplication initSWTApplication(SWTGuitarConfiguration config, Thread guiThread) {
SWTApplication app = new SWTApplication(config.getMainClass(), guiThread);

// add arguments
if (config.getArgumentList() != null) {
String[] args = config.getArgumentList().split(GUITARConstants.CMD_ARGUMENT_SEPARATOR);
app.setArgsToApp(args);
}

// add URLs
try {
if (config.getUrlList() != null) {
String[] urls = config.getUrlList().split(
GUITARConstants.CMD_ARGUMENT_SEPARATOR);
for (String s : urls) {
app.addURL(new URL(s));
}
}
} catch (MalformedURLException e) {
GUITARLog.log.error(e);
}

return app;
}

private Configuration loadXmlConfig() {
Configuration conf = null;

Expand Down
4 changes: 3 additions & 1 deletion src/edu/umd/cs/guitar/ripper/SWTRipper.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import edu.umd.cs.guitar.model.GIDGenerator;
import edu.umd.cs.guitar.model.IO;
import edu.umd.cs.guitar.model.SWTApplication;
import edu.umd.cs.guitar.model.SWTDefaultIDGenerator;
import edu.umd.cs.guitar.model.data.ComponentListType;
import edu.umd.cs.guitar.model.data.GUIStructure;
Expand Down Expand Up @@ -94,7 +95,8 @@ public SWTRipper(SWTRipperConfiguration config, Thread guiThread) {
this.config = config;
}

monitor = new SWTRipperMonitor(config, guiThread);
SWTApplication app = new SWTApplication(this.config.getMainClass(), guiThread);
monitor = new SWTRipperMonitor(this.config, app);
ripper = initRipper();
}

Expand Down
61 changes: 6 additions & 55 deletions src/edu/umd/cs/guitar/ripper/SWTRipperMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
*/
package edu.umd.cs.guitar.ripper;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -54,60 +52,27 @@ public class SWTRipperMonitor extends GRipperMonitor {
*
*/
private volatile LinkedList<Shell> tempOpenedWinStack = new LinkedList<Shell>();

// TODO I don't think these have to be volatile
private volatile LinkedList<Shell> tempClosedWinStack = new LinkedList<Shell>();

/**
* Construct a new <code>SWTRipperMonitor</code>. This constructor is
* equivalent to
* <code>SWTRipperMonitor(configuration, Thread.getCurrentThread())</code>.
* Consequently, this constructor must be called on the same thread that the
* application under test is running on (usually the <code>main</code>
* thread).
*
* @param configuration
* ripper configuration
*/
public SWTRipperMonitor(SWTRipperConfiguration configuration) {
this(configuration, Thread.currentThread());
}

/**
* Constructor
*
* @param configuration
* ripper configuration
* @param appThread
* thread the SWT GUI is running on (almost always the
* <code>main</code> thread)
* @param app
*/
public SWTRipperMonitor(SWTRipperConfiguration configuration, Thread appThread) {
public SWTRipperMonitor(SWTRipperConfiguration configuration, SWTApplication app) {
super();

if (configuration == null) {
configuration = new SWTRipperConfiguration();
}

this.configuration = configuration;
this.application = app;

// don't store application.getDisplay because it's still null at this point

String[] URLs;
if (configuration.getUrlList() != null) {
URLs = configuration.getUrlList().split(GUITARConstants.CMD_ARGUMENT_SEPARATOR);
} else {
URLs = new String[0];
}

try {
application = new SWTApplication(configuration.getMainClass(), appThread);
application.setArgsToApp(parseArgumentList());
for (String s : URLs) {
application.addURL(new URL(s));
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
// don't store application.getDisplay because it's still null at this point
}

@Override
Expand Down Expand Up @@ -143,6 +108,7 @@ public void run() {
}

try {
// TODO this doesn't seem to do anything
Thread.sleep(50);
} catch (InterruptedException e) {
GUITARLog.log.error(e);
Expand Down Expand Up @@ -189,21 +155,6 @@ public void setUp() {
application.connect();
}

/**
* Convert <code>String</code> of
* {@link GUITARConstants.CMD_ARGUMENT_SEPERATOR}-separated arguments from
* {@link SWTRipperConfiguration} into an array of <code>Strings</code>.
*
* @return array of arguments to be passed to the SWT application
*/
private String[] parseArgumentList() {
if (configuration.getArgumentList() != null) {
return configuration.getArgumentList().split(GUITARConstants.CMD_ARGUMENT_SEPARATOR);
} else {
return new String[0];
}
}

@Override
public void cleanUp() {
application.getDisplay().syncExec(new Runnable() {
Expand Down

0 comments on commit 8955e23

Please sign in to comment.