[263] | 1 | package de.ugoe.cs.eventbench.jfcmonitor;
|
---|
[271] | 2 |
|
---|
[263] | 3 | import java.awt.AWTEvent;
|
---|
| 4 | import java.awt.Toolkit;
|
---|
| 5 | import java.awt.event.AWTEventListener;
|
---|
[303] | 6 | import java.io.FileOutputStream;
|
---|
[271] | 7 | import java.io.IOException;
|
---|
[268] | 8 | import java.io.OutputStreamWriter;
|
---|
[308] | 9 | import java.io.UnsupportedEncodingException;
|
---|
[263] | 10 | import java.util.Arrays;
|
---|
| 11 |
|
---|
[271] | 12 | /**
|
---|
| 13 | * <p>
|
---|
| 14 | * Start-up class of the application.
|
---|
| 15 | * </p>
|
---|
| 16 | * <p>
|
---|
| 17 | * Launches the application under test in the same JVM.
|
---|
| 18 | * </p>
|
---|
| 19 | *
|
---|
| 20 | * @author Steffen Herbold
|
---|
| 21 | * @version 1.0
|
---|
| 22 | */
|
---|
[263] | 23 | public class Runner {
|
---|
| 24 |
|
---|
[271] | 25 | /**
|
---|
| 26 | * <p>
|
---|
| 27 | * Debugging variable. If set to true, the logging is also written to the
|
---|
| 28 | * console.
|
---|
| 29 | * </p>
|
---|
| 30 | */
|
---|
| 31 | private final static boolean stdOutputWrite = true;
|
---|
| 32 |
|
---|
| 33 | /**
|
---|
| 34 | * <p>
|
---|
| 35 | * Main method of the application.
|
---|
| 36 | * </p>
|
---|
| 37 | *
|
---|
| 38 | * @param args
|
---|
| 39 | * the first parameter defines the Jar file that contains the
|
---|
| 40 | * start-up information of the application under test. The
|
---|
| 41 | * remaining parameters are passed on the toe application under
|
---|
| 42 | * test.
|
---|
| 43 | */
|
---|
| 44 | public static void main(String[] args) {
|
---|
[295] | 45 | String logfileName = "jfcmonitor_" + System.currentTimeMillis()
|
---|
| 46 | + ".log";
|
---|
| 47 |
|
---|
[303] | 48 | FileOutputStream fis;
|
---|
| 49 | OutputStreamWriter writer;
|
---|
[271] | 50 | try {
|
---|
| 51 | // the writer is not closed explicitly!
|
---|
[303] | 52 | fis = new FileOutputStream(logfileName, true);
|
---|
| 53 | writer = new OutputStreamWriter(fis, "UTF-16");
|
---|
[271] | 54 | } catch (IOException e) {
|
---|
| 55 | System.err.println("JFCMONITOR -- failure opening logfile: "
|
---|
| 56 | + e.getMessage());
|
---|
| 57 | return;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | AWTEventListener listenerFile = new JFCListener(writer);
|
---|
| 61 | Toolkit.getDefaultToolkit().addAWTEventListener(listenerFile,
|
---|
[263] | 62 | AWTEvent.KEY_EVENT_MASK);
|
---|
[271] | 63 | Toolkit.getDefaultToolkit().addAWTEventListener(listenerFile,
|
---|
| 64 | AWTEvent.MOUSE_EVENT_MASK);
|
---|
[355] | 65 | Toolkit.getDefaultToolkit().addAWTEventListener(new WindowMonitor(),
|
---|
| 66 | AWTEvent.WINDOW_EVENT_MASK);
|
---|
[271] | 67 |
|
---|
| 68 | if (stdOutputWrite) {
|
---|
[308] | 69 | AWTEventListener listenerStdOut;
|
---|
| 70 | try {
|
---|
| 71 | listenerStdOut = new JFCListener(new OutputStreamWriter(
|
---|
| 72 | System.out, "UTF-8"));
|
---|
| 73 | Toolkit.getDefaultToolkit().addAWTEventListener(listenerStdOut,
|
---|
| 74 | AWTEvent.KEY_EVENT_MASK);
|
---|
| 75 | Toolkit.getDefaultToolkit().addAWTEventListener(listenerStdOut,
|
---|
| 76 | AWTEvent.MOUSE_EVENT_MASK);
|
---|
| 77 | } catch (UnsupportedEncodingException e) {
|
---|
| 78 | System.err
|
---|
| 79 | .println("JFCMONITOR -- failure to create OutputStreamWriter with UTF-8 encoding to System.out");
|
---|
| 80 | }
|
---|
[271] | 81 | }
|
---|
| 82 |
|
---|
| 83 | JarLauncher launcher = new JarLauncher(args[0], Arrays.copyOfRange(
|
---|
| 84 | args, 1, args.length));
|
---|
[263] | 85 | launcher.exec();
|
---|
| 86 | }
|
---|
| 87 | }
|
---|