1
/* $Id: ProGuardRunnable.java,v 1.5 2004/08/15 12:39:30 eric Exp $
3
* ProGuard -- shrinking, optimization, and obfuscation of Java class files.
5
* Copyright (c) 2002-2004 Eric Lafortune (eric@graphics.cornell.edu)
7
* This program is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU General Public License as published by the Free
9
* Software Foundation; either version 2 of the License, or (at your option)
12
* This program is distributed in the hope that it will be useful, but WITHOUT
13
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17
* You should have received a copy of the GNU General Public License along
18
* with this program; if not, write to the Free Software Foundation, Inc.,
19
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32
* This <code>Runnable</code> runs ProGuard, sending console output to a text
33
* area and any exceptions to message dialogs.
36
* @author Eric Lafortune
38
class ProGuardRunnable implements Runnable
40
private JTextArea consoleTextArea;
41
private Configuration configuration;
42
private String configurationFileName;
46
* Creates a new ProGuardRunnable object.
47
* @param consoleTextArea the text area to send the console output to.
48
* @param configuration the ProGuard configuration.
49
* @param configurationFileName the optional file name of the configuration,
50
* for informational purposes.
52
public ProGuardRunnable(JTextArea consoleTextArea,
53
Configuration configuration,
54
String configurationFileName)
56
this.consoleTextArea = consoleTextArea;
57
this.configuration = configuration;
58
this.configurationFileName = configurationFileName;
62
// Implementation for Runnable.
66
consoleTextArea.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
67
consoleTextArea.setText("");
69
// Redirect the System's out and err streams to the console text area.
70
PrintStream oldOut = System.out;
71
PrintStream oldErr = System.err;
73
PrintStream printStream =
74
new PrintStream(new TextAreaOutputStream(consoleTextArea), true);
76
System.setOut(printStream);
77
System.setErr(printStream);
81
// Create a new ProGuard object with the GUI's configuration.
82
ProGuard proGuard = new ProGuard(configuration);
89
// Print out the exception message.
90
System.out.println(ex.getMessage());
92
// Show a dialog as well.
93
MessageDialogRunnable.showMessageDialog(consoleTextArea,
95
msg("errorProcessing"),
96
JOptionPane.ERROR_MESSAGE);
98
catch (OutOfMemoryError er)
100
// Forget about the ProGuard object as quickly as possible.
103
// Print out a message suggesting what to do next.
104
System.out.println(msg("outOfMemoryInfo", configurationFileName));
106
// Show a dialog as well.
107
MessageDialogRunnable.showMessageDialog(consoleTextArea,
109
msg("errorProcessing"),
110
JOptionPane.ERROR_MESSAGE);
113
// Make sure all output has been sent to the console text area.
116
// Restore the old System's out and err streams.
117
System.setOut(oldOut);
118
System.setErr(oldErr);
120
consoleTextArea.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
122
// Reset the global static redirection lock.
123
ProGuardGUI.systemOutRedirected = false;
127
// Small utility methods.
130
* Returns the message from the GUI resources that corresponds to the given
133
private String msg(String messageKey)
135
return GUIResources.getMessage(messageKey);
140
* Returns the message from the GUI resources that corresponds to the given
143
private String msg(String messageKey,
144
Object messageArgument)
146
return GUIResources.getMessage(messageKey, new Object[] {messageArgument});