runaction.java.svn-base
来自「cqME :java framework for TCK test.」· SVN-BASE 代码 · 共 485 行 · 第 1/2 页
SVN-BASE
485 行
// ex.printStackTrace();
// } catch (Main.Fault ex) {
// ex.printStackTrace();
// }
}
};
ExecutionEngine engine = ExecutionEngine.getDefault();
InputOutput testIO = IOProvider.getDefault().getIO("Run tests", false);
try {
testIO.getOut().reset();
} catch (IOException e) {
}
ExecutorTask task = engine.execute("Run tests", r2, testIO);
InputOutput agentIO = IOProvider.getDefault().getIO("Run agent", false);
try {
agentIO.getOut().reset();
} catch (IOException e) {
}
engine.execute("Run agent", r, agentIO);
task.waitFinished();
if (SwingUtilities.isEventDispatchThread() ) {
showJTViewer();
} else {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
showJTViewer();
}
});
}
}
private static void showJTViewer() {
JTViewerTopComponent win = (JTViewerTopComponent)JTViewerTopComponent.findInstance();
win.initWD();
if (!win.isOpened()) {
win.open();
}
win.requestActive();
}
protected int mode() {
return CookieAction.MODE_EXACTLY_ONE;
}
public String getName() {
return NbBundle.getMessage(RunAction.class, "CTL_RunAction");
}
protected Class[] cookieClasses() {
return new Class[] {
DataObject.class
};
}
protected void initialize() {
super.initialize();
// see org.openide.util.actions.SystemAction.iconResource() javadoc for more details
putValue("noIconInMenu", Boolean.TRUE);
}
public HelpCtx getHelpCtx() {
return HelpCtx.DEFAULT_HELP;
}
protected boolean asynchronous() {
return false;
}
protected boolean enable(Node[] activatedNodes) {
if (activatedNodes == null) {
return false;
}
if (activatedNodes.length == 0) {
return false;
}
DataObject c = (DataObject) activatedNodes[0].getCookie(DataObject.class);
if (c == null) {
return false;
}
if ("tests".equals(c.getName())) {
return true;
} else {
return false;
}
}
}
class Exec {
private static boolean verbose = true;
/** Determines if the Exec class should print which commands
* are being executed, and prints error messages if a problem
* is found. Default is true.
*
* @param verboseFlag true: print messages, false: don�t.
*/
public static void setVerbose(boolean verboseFlag) {
verbose = verboseFlag;
}
/** Will Exec print status messages? */
public static boolean getVerbose() {
return(verbose);
}
/** Starts a process to execute the command. Returns
* immediately, even if the new process is still running.
*
* @param command The <B>full</B> pathname of the command to
* be executed. No shell built-ins (e.g., "cd") or shell
* meta-chars (e.g. ">") are allowed.
* @return false if a problem is known to occur, but since
* this returns immediately, problems aren�t usually found
* in time. Returns true otherwise.
*/
public static boolean exec(String command) {
return(exec(command, false, false));
}
/** Starts a process to execute the command. Waits for the
* process to finish before returning.
*
* @param command The <B>full</B> pathname of the command to
* be executed. No shell built-ins or shell metachars are
* allowed.
* @return false if a problem is known to occur, either due
* to an exception or from the subprocess returning a
* nonzero value. Returns true otherwise.
*/
public static boolean execWait(String command) {
return(exec(command, false, true));
}
/** Starts a process to execute the command. Prints any output
* the command produces.
*
* @param command The <B>full</B> pathname of the command to
* be executed. No shell built-ins or shell meta-chars are
* allowed.
* @return false if a problem is known to occur, either due
* to an exception or from the subprocess returning a
* nonzero value. Returns true otherwise.
*/
public static boolean execPrint(String command) {
return(exec(command, true, true));
}
/** This creates a Process object via Runtime.getRuntime.exec()
* Depending on the flags, it may call waitFor on the process
* to avoid continuing until the process terminates, and open
* an input stream from the process to read the results.
*/
private static boolean exec(String command,
boolean printResults,
boolean wait) {
if (verbose) {
printSeparator();
System.out.println("Executing '" + command + "'.");
}
try {
// Start running command, returning immediately.
Process p = Runtime.getRuntime().exec(command);
// Print the output. Since we read until there is no more
// input, this causes us to wait until the process is
// completed.
if(printResults) {
BufferedReader buffer = new BufferedReader(
new InputStreamReader(p.getInputStream()));
String s = null;
try {
while ((s = buffer.readLine()) != null) {
System.out.println("Output: " + s);
}
buffer.close();
if (p.exitValue() != 0) {
if (verbose) {
printError(command + " -- p.exitValue() != 0");
}
return(false);
}
} catch (Exception e) {
// Ignore read errors; they mean the process is done.
}
// If not printing the results, then we should call waitFor
// to stop until the process is completed.
} else if (wait) {
try {
System.out.println(" ");
int returnVal = p.waitFor();
if (returnVal != 0) {
if (verbose) {
printError(command);
}
return(false);
}
} catch (Exception e) {
if (verbose) {
printError(command, e);
}
return(false);
}
}
} catch (Exception e) {
if (verbose) {
printError(command, e);
}
return(false);
}
return(true);
}
private static void printError(String command,
Exception e) {
System.out.println("Error doing exec(" + command + "): " +
e.getMessage());
System.out.println("Did you specify the full " +
"pathname?");
}
private static void printError(String command) {
System.out.println("Error executing �" + command + "�.");
}
private static void printSeparator() {
System.out.println
("==============================================");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?