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