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