source: trunk/autoquest-jfcmonitor/src/main/java/de/ugoe/cs/autoquest/jfcmonitor/Runner.java @ 927

Last change on this file since 927 was 927, checked in by sherbold, 12 years ago
  • added copyright under the Apache License, Version 2.0
  • Property svn:mime-type set to text/plain
File size: 4.6 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.autoquest.jfcmonitor;
16
17import java.awt.AWTEvent;
18import java.awt.Toolkit;
19import java.awt.event.AWTEventListener;
20import java.awt.event.FocusEvent;
21import java.io.FileOutputStream;
22import java.io.IOException;
23import java.io.OutputStreamWriter;
24import java.io.UnsupportedEncodingException;
25import java.util.Arrays;
26
27/**
28 * <p>
29 * Start-up class of the application.
30 * </p>
31 * <p>
32 * Launches the application under test in the same JVM.
33 * </p>
34 *
35 * @author Steffen Herbold
36 * @author Fabian Glaser
37 * @version 1.0
38 */
39public class Runner {
40
41    /**
42     * <p>
43     * Debugging variable. If set to true, the logging is also written to the console.
44     * </p>
45     */
46    private final static boolean stdOutputWrite = true;
47
48    /**
49     * <p>
50     * Main method of the application.
51     * </p>
52     *
53     * @param args
54     *            the first parameter defines the Jar file that contains the start-up information of
55     *            the application under test. The remaining parameters are passed on the toe
56     *            application under test.
57     */
58    public static void main(String[] args) {
59        String logfileName = "jfcmonitor_" + System.currentTimeMillis() + ".log";
60
61        FileOutputStream fis;
62        OutputStreamWriter writer;
63        try {
64            // the writer is not closed explicitly!
65            fis = new FileOutputStream(logfileName, true);
66            writer = new OutputStreamWriter(fis, "UTF-8");
67        }
68        catch (IOException e) {
69            System.err.println("JFCMONITOR -- failure opening logfile: " + e.getMessage());
70            return;
71        }
72
73        JFCMonitorOutputWriter jfcWriter = new JFCMonitorOutputWriter(writer);
74        AWTEventListener listenerFile = new JFCListener(jfcWriter);
75        Toolkit.getDefaultToolkit().addAWTEventListener(listenerFile, AWTEvent.KEY_EVENT_MASK);
76        Toolkit.getDefaultToolkit().addAWTEventListener(listenerFile, AWTEvent.MOUSE_EVENT_MASK);
77        Toolkit.getDefaultToolkit().addAWTEventListener(listenerFile, FocusEvent.FOCUS_EVENT_MASK);
78        Toolkit.getDefaultToolkit().addAWTEventListener(new JFCWindowMonitor(jfcWriter),
79                                                        AWTEvent.WINDOW_EVENT_MASK);
80        JFCComponent.addPropertyChangeListener(new JFCNameChangeListener(jfcWriter));
81        JFCComponent.addContainerListener(new JFCContainerListener(jfcWriter));
82
83        if (stdOutputWrite) {
84            AWTEventListener listenerStdOut;
85            try {
86                OutputStreamWriter stdOutputWriter = new OutputStreamWriter(System.out, "UTF-8");
87                JFCMonitorOutputWriter stdJfcWriter = new JFCMonitorOutputWriter(stdOutputWriter);
88                listenerStdOut = new JFCListener(stdJfcWriter);
89                Toolkit.getDefaultToolkit().addAWTEventListener(listenerStdOut,
90                                                                AWTEvent.KEY_EVENT_MASK);
91                Toolkit.getDefaultToolkit().addAWTEventListener(listenerStdOut,
92                                                                AWTEvent.MOUSE_EVENT_MASK);
93                Toolkit.getDefaultToolkit().addAWTEventListener(listenerStdOut,
94                                                                FocusEvent.FOCUS_EVENT_MASK);
95                Toolkit.getDefaultToolkit().addAWTEventListener(new JFCWindowMonitor(stdJfcWriter),
96                        AWTEvent.WINDOW_EVENT_MASK);
97                JFCComponent.addPropertyChangeListener(new JFCNameChangeListener(stdJfcWriter));
98                JFCComponent.addContainerListener(new JFCContainerListener(stdJfcWriter));
99            }
100            catch (UnsupportedEncodingException e) {
101                System.err
102                    .println("JFCMONITOR -- failure to create OutputStreamWriter with UTF-8 encoding to System.out");
103            }
104        }
105
106        JarLauncher launcher = new JarLauncher(args[0], Arrays.copyOfRange(args, 1, args.length));
107        launcher.exec();
108    }
109}
Note: See TracBrowser for help on using the repository browser.