diff options
15 files changed, 333 insertions, 164 deletions
@@ -1,3 +1,35 @@ +2013-11-05 Jiri Vanek <[email protected]> + + Java console resurrected and connected to new logging. + * NEWS: mentioned console for plugin and javaws + * Changelog: removed one wrong tab + * netx/net/sourceforge/jnlp/config/Defaults.java: added + DeploymentConfiguration.CONSOLE_SHOW_PLUGIN, + and DeploymentConfiguration.CONSOLE_SHOW_JAVAWS. + * netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java: + added and javadoc-ed CONSOLE_SHOW_PLUGIN,CONSOLE_SHOW_JAVAWS, DISABLE, + SHOW, HIDE, KEY_CONSOLE_STARTUP_MODE. + * netx/net/sourceforge/jnlp/resources/Messages.properties: localized console + * netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java : removed legacy STD*_FILE + * netx/net/sourceforge/jnlp/util/BasicExceptionDialog.java: Added button + to show console on demand. Added (getShowButton) method to share code with + * netx/net/sourceforge/jnlp/splashscreen/parts/JEditorPaneBasedExceptionDialog.java: + Added button to show console on demand and explaining line. + * netx/net/sourceforge/jnlp/util/logging/JavaConsole.java: moved from + plugin, and reworked. Especially get rid of perpetual loading of file. + Made singleton. + * netx/net/sourceforge/jnlp/util/logging/LogConfig.java: added (isLogToConsole) + returning (JavaConsole.isEnabled) status. + * netx/net/sourceforge/jnlp/util/logging/OutputController.java: added (Level.isError) + and (Level.isOutput) methods to determine original channel, and can log to console. + * plugin/icedteanp/java/sun/applet/JavaConsole.java: moved to netx + * plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java: + (streamhandler) made private with setter + * plugin/icedteanp/java/sun/applet/PluginMain.java : removed legacy STD*_FILE, + added set of classloaders information provider to console. (handlePluginMessage) + show and hide of console is checking it's status. (showConsole) and (hideConsole) + moved to JavaConsole. + 2013-11-05 Andrew Azores <[email protected]> * netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java: @@ -10,7 +42,7 @@ * netx/net/sourceforge/jnlp/util/logging/OutputController.java: (getHeader) added thread id and name to log header. * plugin/icedteanp/IcedTeaPluginUtils.h: (PLUGIN_DEBUG) (PLUGIN_ERROR) - headerrs generation code moved to macro (CREATE_HEADER0). Both + headers generation code moved to macro (CREATE_HEADER0). Both headers now contains pthread_self and g_thread_self. Fixed indentation. 2013-11-01 Jiri Vanek <[email protected]> @@ -63,7 +95,7 @@ TEST(PLUGIN_DEBUG_ERROR_PROFILING_debug_on_headers_on) TEST(PLUGIN_DEBUG_ERROR_PROFILING_debug_off_headers_on) (100x slower then without headers) - + 2013-10-25 Jiri Vanek <[email protected]> all output messages redirected to PLUGIN_{DEBUG,ERROR} macros @@ -12,6 +12,7 @@ New in release 1.5 (2013-XX-XX): * IcedTea-Web now using tagsoup as default (tagsoup dependence) sanitizer for input * JDK older then 1.5 no longer supported * IcedTea-Web is now following XDG .config and .cache specification(RH947647) +* A console for debugging plugin and javaws * Cache Viewer - Can be closed by ESC key - Enabling and disabling of operational buttons is handled properly diff --git a/netx/net/sourceforge/jnlp/config/Defaults.java b/netx/net/sourceforge/jnlp/config/Defaults.java index c3fdade..95b91d1 100644 --- a/netx/net/sourceforge/jnlp/config/Defaults.java +++ b/netx/net/sourceforge/jnlp/config/Defaults.java @@ -337,7 +337,9 @@ public class Defaults { BasicValueValidators.getStringValidator(new String[] { DeploymentConfiguration.CONSOLE_DISABLE, DeploymentConfiguration.CONSOLE_HIDE, - DeploymentConfiguration.CONSOLE_SHOW + DeploymentConfiguration.CONSOLE_SHOW, + DeploymentConfiguration.CONSOLE_SHOW_PLUGIN, + DeploymentConfiguration.CONSOLE_SHOW_JAVAWS }), DeploymentConfiguration.CONSOLE_HIDE }, diff --git a/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java b/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java index 3dbcaab..02a4933 100644 --- a/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java +++ b/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java @@ -64,14 +64,31 @@ public final class DeploymentConfiguration { public static final int JNLP_ASSOCIATION_ASK_USER = 2; public static final int JNLP_ASSOCIATION_REPLACE_ASK = 3; - /* - * FIXME these should be moved into JavaConsole, but there is a strange - * dependency in the build system. First all of netx is built. Then the - * plugin is built. So we cannot refer to plugin code in here :( + /** + * when set to as value of KEY_CONSOLE_STARTUP_MODE = "deployment.console.startup.mode", + * then console is not visible by default, but may be shown */ public static final String CONSOLE_HIDE = "HIDE"; + /** + * when set to as value of KEY_CONSOLE_STARTUP_MODE = "deployment.console.startup.mode", + * then console show for both javaws and plugin + */ public static final String CONSOLE_SHOW = "SHOW"; + /** + * when set to as value of KEY_CONSOLE_STARTUP_MODE = "deployment.console.startup.mode", + * then console is not visible by default, nop data are passed to it (save memory and cpu) but can not be shown + */ public static final String CONSOLE_DISABLE = "DISABLE"; + /** + * when set to as value of KEY_CONSOLE_STARTUP_MODE = "deployment.console.startup.mode", + * then console show for plugin + */ + public static final String CONSOLE_SHOW_PLUGIN = "SHOW_PLUGIN_ONLY"; + /** + * when set to as value of KEY_CONSOLE_STARTUP_MODE = "deployment.console.startup.mode", + * then console show for javaws + */ + public static final String CONSOLE_SHOW_JAVAWS = "SHOW_JAVAWS_ONLY"; public static final String KEY_USER_CACHE_DIR = "deployment.user.cachedir"; public static final String KEY_USER_PERSISTENCE_CACHE_DIR = "deployment.user.pcachedir"; @@ -156,10 +173,19 @@ public final class DeploymentConfiguration { public static final String KEY_ENABLE_LOGGING_TOSTREAMS = "deployment.log.stdstreams"; public static final String KEY_ENABLE_LOGGING_TOSYSTEMLOG = "deployment.log.system"; - /* - * Console + /** + * Console initial status. + * One of CONSOLE_* values + * See declaration above: + * CONSOLE_HIDE = "HIDE"; + * CONSOLE_SHOW = "SHOW"; + * CONSOLE_DISABLE = "DISABLE"; + * CONSOLE_SHOW_PLUGIN = "SHOW_PLUGIN_ONLY"; + * CONSOLE_SHOW_JAVAWS = "SHOW_JAVAWS_ONLY"; */ public static final String KEY_CONSOLE_STARTUP_MODE = "deployment.console.startup.mode"; + + /* * Desktop Integration diff --git a/netx/net/sourceforge/jnlp/controlpanel/DebuggingPanel.java b/netx/net/sourceforge/jnlp/controlpanel/DebuggingPanel.java index 003f486..bee0a53 100644 --- a/netx/net/sourceforge/jnlp/controlpanel/DebuggingPanel.java +++ b/netx/net/sourceforge/jnlp/controlpanel/DebuggingPanel.java @@ -91,9 +91,11 @@ public class DebuggingPanel extends NamedBorderPanel implements ItemListener { (Translator.R("DPEnableSyslogHint")) }; - ComboItem[] javaConsoleItems = { new ComboItem(Translator.R("DPDisable"), "DISABLE"), - new ComboItem(Translator.R("DPHide"), "HIDE"), - new ComboItem(Translator.R("DPShow"), "SHOW"), }; + ComboItem[] javaConsoleItems = { new ComboItem(Translator.R("DPDisable"), DeploymentConfiguration.CONSOLE_DISABLE), + new ComboItem(Translator.R("DPHide"), DeploymentConfiguration.CONSOLE_HIDE), + new ComboItem(Translator.R("DPShow"), DeploymentConfiguration.CONSOLE_SHOW), + new ComboItem(Translator.R("DPShowPluginOnly"), DeploymentConfiguration.CONSOLE_SHOW_PLUGIN), + new ComboItem(Translator.R("DPShowJavawsOnly"), DeploymentConfiguration.CONSOLE_SHOW_JAVAWS) }; JLabel consoleLabel = new JLabel(Translator.R("DPJavaConsole")); JComboBox consoleComboBox = new JComboBox(); diff --git a/netx/net/sourceforge/jnlp/resources/Messages.properties b/netx/net/sourceforge/jnlp/resources/Messages.properties index 8f1050a..5cea7d2 100644 --- a/netx/net/sourceforge/jnlp/resources/Messages.properties +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties @@ -415,7 +415,24 @@ DPEnableSyslogHint=output messages will be saved to system logs DPDisable=Disable DPHide=Hide on startup DPShow=Show on startup +DPShowPluginOnly=Show on plugin startup +DPShowJavawsOnly=Show on javaws startup DPJavaConsole=Java Console +DPJavaConsoleDisabledHint=Java console is disabled. Use itweb-settings to configure it out of disabled to any show or hide value. + +#conole itself labels +CONSOLErungc = Run GC +CONSOLErunFinalizers = Run Finalizers +CONSOLErunningFinalizers = Running finalization.... +CONSOLEmemoryInfo = Memory Info +CONSOLEsystemProperties = System Properties +CONSOLEclassLoaders = Available Classloaders +CONSOLEthreadList = Thread List +CONSOLEthread = Thread +CONSOLEnoClassLoaders = No Classloader info exists in system +CONSOLEmemoryMax = Max Memory +CONSOLEmemoryTotal = Total Memory +CONSOLEmemoryFree = Free Memory # Control Panel - DesktopShortcutPanel DSPNeverCreate=Never create @@ -525,6 +542,7 @@ SPLASHurlLooks = http://icedtea.classpath.org/wiki/IcedTea-Web SPLASHmainL3 = No further information available, try to launch the browser from the command line and examine the output. SPLASHcloseAndCopyShorter = Close and copy to clipboard SPLASHmainL4 = The folloing exception has occured. For more information, try to launch the browser from the command line and examine the output. +SPLASHmainL2 = Additional information may be available in the console or logs. Even more information is available if debugging is enabled. SPLASHexWas = Exception was: SPLASHcfl = Can't follow link to SPLASHvendorsInfo = Information from vendor of your application diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java index a0744a0..3a50f6c 100644 --- a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java +++ b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java @@ -67,8 +67,8 @@ import net.sourceforge.jnlp.security.SecurityDialogMessageHandler; import net.sourceforge.jnlp.security.VariableX509TrustManager; import net.sourceforge.jnlp.services.XServiceManagerStub; import net.sourceforge.jnlp.util.FileUtils; +import net.sourceforge.jnlp.util.logging.JavaConsole; import net.sourceforge.jnlp.util.logging.OutputController; -import net.sourceforge.jnlp.util.TeeOutputStream; import net.sourceforge.jnlp.util.logging.LogConfig; import sun.net.www.protocol.jar.URLJarFile; @@ -162,8 +162,7 @@ public class JNLPRuntime { /** a lock which is held to indicate that an instance of netx is running */ private static FileLock fileLock; - public static final String STDERR_FILE = "java.stderr"; - public static final String STDOUT_FILE = "java.stdout"; + /** @@ -196,6 +195,9 @@ public class JNLPRuntime { try { config.load(); config.copyTo(System.getProperties()); + if (JavaConsole.canShowOnStartup(isApplication)) { + JavaConsole.getConsole().showConsoleLater(); + } } catch (ConfigurationException e) { /* exit if there is a fatal exception loading the configuration */ if (isApplication) { diff --git a/netx/net/sourceforge/jnlp/splashscreen/parts/JEditorPaneBasedExceptionDialog.java b/netx/net/sourceforge/jnlp/splashscreen/parts/JEditorPaneBasedExceptionDialog.java index 02110ce..b726be4 100644 --- a/netx/net/sourceforge/jnlp/splashscreen/parts/JEditorPaneBasedExceptionDialog.java +++ b/netx/net/sourceforge/jnlp/splashscreen/parts/JEditorPaneBasedExceptionDialog.java @@ -40,8 +40,6 @@ import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; import java.awt.event.WindowEvent; -import java.io.PrintWriter; -import java.io.StringWriter; import java.text.DateFormat; import java.util.Date; import java.util.List; @@ -65,6 +63,7 @@ import javax.swing.event.HyperlinkListener; import net.sourceforge.jnlp.LaunchException; import net.sourceforge.jnlp.about.AboutDialog; import net.sourceforge.jnlp.runtime.Translator; +import net.sourceforge.jnlp.util.BasicExceptionDialog; import net.sourceforge.jnlp.util.logging.OutputController; public class JEditorPaneBasedExceptionDialog extends JDialog implements HyperlinkListener { @@ -74,6 +73,7 @@ public class JEditorPaneBasedExceptionDialog extends JDialog implements Hyperlin private JButton closeAndCopyButton; private JButton homeButton; private JButton aboutButton; + private JButton consoleButton; private JEditorPane htmlErrorAndHelpPanel; private JLabel exceptionLabel; private JLabel iconLabel; @@ -142,6 +142,7 @@ public class JEditorPaneBasedExceptionDialog extends JDialog implements Hyperlin htmlErrorAndHelpPanel = new JEditorPane(); homeButton = new JButton(); aboutButton = new JButton(); + consoleButton = BasicExceptionDialog.getShowButton(JEditorPaneBasedExceptionDialog.this); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); @@ -166,9 +167,27 @@ public class JEditorPaneBasedExceptionDialog extends JDialog implements Hyperlin GroupLayout jPanel2Layout = new GroupLayout(topPanel); topPanel.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( - jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addComponent(closeButton).addContainerGap().addComponent(aboutButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 314, Short.MAX_VALUE).addComponent(closeAndCopyButton).addContainerGap())); + jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(jPanel2Layout.createSequentialGroup() + .addContainerGap() + .addComponent(closeButton) + .addContainerGap() + .addComponent(aboutButton) + .addContainerGap() + .addComponent(consoleButton) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 314, Short.MAX_VALUE) + .addComponent(closeAndCopyButton) + .addContainerGap())); jPanel2Layout.setVerticalGroup( - jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup().addContainerGap(24, Short.MAX_VALUE).addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(closeButton).addComponent(aboutButton).addComponent(closeAndCopyButton)).addContainerGap())); + jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() + .addContainerGap(24, Short.MAX_VALUE) + .addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(closeButton) + .addComponent(aboutButton) + .addComponent(consoleButton) + .addComponent(closeAndCopyButton)) + .addContainerGap())); exceptionLabel.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N exceptionLabel.setHorizontalAlignment(SwingConstants.CENTER); @@ -204,7 +223,7 @@ public class JEditorPaneBasedExceptionDialog extends JDialog implements Hyperlin } } }); - + GroupLayout jPanel1Layout = new GroupLayout(mainPanel); mainPanel.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( @@ -271,6 +290,9 @@ public class JEditorPaneBasedExceptionDialog extends JDialog implements Hyperlin StringBuilder s = new StringBuilder("<html><body>"); String info = "<p>" + Translator.R(InfoItem.SPLASH + "mainL1", createLink()) + + " </p> \n" + + "<p>" + + Translator.R(InfoItem.SPLASH + "mainL2", createLink()) + " </p> \n"; String t = "<p>" + Translator.R(InfoItem.SPLASH + "mainL3") diff --git a/netx/net/sourceforge/jnlp/util/BasicExceptionDialog.java b/netx/net/sourceforge/jnlp/util/BasicExceptionDialog.java index 2fca402..752974f 100644 --- a/netx/net/sourceforge/jnlp/util/BasicExceptionDialog.java +++ b/netx/net/sourceforge/jnlp/util/BasicExceptionDialog.java @@ -41,6 +41,7 @@ import net.sourceforge.jnlp.util.logging.OutputController; import static net.sourceforge.jnlp.runtime.Translator.R; import java.awt.BorderLayout; +import java.awt.Component; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -55,6 +56,8 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; +import net.sourceforge.jnlp.runtime.Translator; +import net.sourceforge.jnlp.util.logging.JavaConsole; /** * A dialog that displays some basic information about an exception @@ -91,6 +94,10 @@ public class BasicExceptionDialog { viewDetails.setActionCommand("show"); quickInfoPanel.add(viewDetails); + final JButton consoleButton = getShowButton(errorDialog); + consoleButton.setAlignmentY(JComponent.LEFT_ALIGNMENT); + quickInfoPanel.add(consoleButton); + JTextArea textArea = new JTextArea(); textArea.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); textArea.setEditable(false); @@ -120,4 +127,26 @@ public class BasicExceptionDialog { errorDialog.setVisible(true); errorDialog.dispose(); } + + public static JButton getShowButton(final Component parent) { + JButton consoleButton = new JButton(); + consoleButton.setText(R("DPJavaConsole")); + consoleButton.addActionListener(new java.awt.event.ActionListener() { + + @Override + public void actionPerformed(java.awt.event.ActionEvent evt) { + try { + JavaConsole.getConsole().showConsoleLater(true); + } catch (Exception ex) { + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, ex); + JOptionPane.showConfirmDialog(parent, ex); + } + } + }); + if (!JavaConsole.isEnabled()) { + consoleButton.setEnabled(false); + consoleButton.setToolTipText(R("DPJavaConsoleDisabledHint")); + } + return consoleButton; + } } diff --git a/plugin/icedteanp/java/sun/applet/JavaConsole.java b/netx/net/sourceforge/jnlp/util/logging/JavaConsole.java index a7c7aab..939b755 100644 --- a/plugin/icedteanp/java/sun/applet/JavaConsole.java +++ b/netx/net/sourceforge/jnlp/util/logging/JavaConsole.java @@ -1,5 +1,5 @@ /* JavaConsole -- A java console for the plugin - Copyright (C) 2009 Red Hat +Copyright (C) 2009, 2013 Red Hat This file is part of IcedTea. @@ -34,8 +34,9 @@ or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ +package net.sourceforge.jnlp.util.logging; -package sun.applet; +import static net.sourceforge.jnlp.runtime.Translator.R; import java.awt.Dimension; import java.awt.Font; @@ -43,16 +44,11 @@ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; import java.util.Map; import java.util.Properties; import java.util.Set; - import javax.swing.JButton; +import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; @@ -62,38 +58,73 @@ import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.border.EmptyBorder; import javax.swing.border.TitledBorder; - import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.JNLPRuntime; import net.sourceforge.jnlp.util.ImageResources; -import net.sourceforge.jnlp.util.logging.OutputController; /** - * A simple Java console for IcedTeaPlugin + * A simple Java console for IcedTeaPlugin and JavaWS * */ public class JavaConsole { - private boolean initialized = false; + public static interface ClassLoaderInfoProvider { + + public Map<String, String> getLoaderInfo(); + } + private static JavaConsole console; + + public static JavaConsole getConsole() { + if (console == null) { + console = new JavaConsole(); + } + return console; + } + + public static boolean isEnabled() { + return isEnabled(JNLPRuntime.getConfiguration()); + } + + public static boolean isEnabled(DeploymentConfiguration config) { + return !DeploymentConfiguration.CONSOLE_DISABLE.equals(config.getProperty(DeploymentConfiguration.KEY_CONSOLE_STARTUP_MODE)) + && !JNLPRuntime.isHeadless(); + } - JFrame consoleWindow; - JTextArea stdErrText; - JTextArea stdOutText; + public static boolean canShowOnStartup(boolean isApplication) { + return canShowOnStartup(isApplication, JNLPRuntime.getConfiguration()); + } + + public static boolean canShowOnStartup(boolean isApplication, DeploymentConfiguration config) { + if (!isEnabled(config)) { + return false; + } + return DeploymentConfiguration.CONSOLE_SHOW.equals(config.getProperty(DeploymentConfiguration.KEY_CONSOLE_STARTUP_MODE)) + || (DeploymentConfiguration.CONSOLE_SHOW_PLUGIN.equals(config.getProperty(DeploymentConfiguration.KEY_CONSOLE_STARTUP_MODE)) + && !isApplication) + || (DeploymentConfiguration.CONSOLE_SHOW_JAVAWS.equals(config.getProperty(DeploymentConfiguration.KEY_CONSOLE_STARTUP_MODE)) + && isApplication); + } + private JDialog consoleWindow; + private JTextArea stdErrText; + private JTextArea stdOutText; + private ClassLoaderInfoProvider classLoaderInfoProvider; + + public JavaConsole() { + initialize(); + } /** * Initialize the console */ - public void initialize() { + private void initialize() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { - OutputController.getLogger().log(OutputController.Level.ERROR_ALL,e); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e); } - final String logDir = JNLPRuntime.getConfiguration().getProperty(DeploymentConfiguration.KEY_USER_LOG_DIR); - - consoleWindow = new JFrame("Java Console"); + consoleWindow = new JDialog((JFrame) null, R("DPJavaConsole")); consoleWindow.setIconImages(ImageResources.INSTANCE.getApplicationImages()); JPanel contentPanel = new JPanel(); @@ -103,7 +134,6 @@ public class JavaConsole { Font monoSpace = new Font("Monospaced", Font.PLAIN, 12); - /* std out */ stdOutText = new JTextArea(); JScrollPane stdOutScrollPane = new JScrollPane(stdOutText); @@ -112,12 +142,6 @@ public class JavaConsole { stdOutText.setEditable(false); stdOutText.setFont(monoSpace); - TextAreaUpdater stdOutUpdater = new TextAreaUpdater(new File(logDir, - PluginMain.PLUGIN_STDOUT_FILE), stdOutText); - stdOutUpdater.setName("IcedteaPlugin Console Thread(System.out)"); - - /* std err */ - stdErrText = new JTextArea(); JScrollPane stdErrScrollPane = new JScrollPane(stdErrText); stdErrScrollPane.setBorder(new TitledBorder( @@ -125,10 +149,6 @@ public class JavaConsole { stdErrText.setEditable(false); stdErrText.setFont(monoSpace); - TextAreaUpdater stdErrUpdater = new TextAreaUpdater(new File(logDir, - PluginMain.PLUGIN_STDERR_FILE), stdErrText); - stdErrUpdater.setName("IcedteaPlugin Console Thread(System.err)"); - JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, stdOutScrollPane, stdErrScrollPane); @@ -150,73 +170,75 @@ public class JavaConsole { JPanel buttonPanel = new JPanel(); contentPanel.add(buttonPanel, c); - JButton gcButton = new JButton("Run GC"); + JButton gcButton = new JButton(R("CONSOLErungc")); buttonPanel.add(gcButton); gcButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { printMemoryInfo(); OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, "Performing Garbage Collection...."); System.gc(); - OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, "Done"); + OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, R("ButDone")); printMemoryInfo(); } - }); - JButton finalizersButton = new JButton("Run Finalizers"); + JButton finalizersButton = new JButton(R("CONSOLErunFinalizers")); buttonPanel.add(finalizersButton); finalizersButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { printMemoryInfo(); - OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, "Running finalization...."); + OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, R("CONSOLErunningFinalizers")); Runtime.getRuntime().runFinalization(); - OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, "Done"); + OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, R("ButDone")); printMemoryInfo(); } }); - JButton memoryButton = new JButton("Memory Info"); + JButton memoryButton = new JButton(R("CONSOLEmemoryInfo")); buttonPanel.add(memoryButton); memoryButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { printMemoryInfo(); } - }); - JButton systemPropertiesButton = new JButton("System Properties"); + JButton systemPropertiesButton = new JButton(R("CONSOLEsystemProperties")); buttonPanel.add(systemPropertiesButton); systemPropertiesButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { printSystemProperties(); } - }); - JButton classloadersButton = new JButton("Classloaders"); + JButton classloadersButton = new JButton(R("CONSOLEclassLoaders")); buttonPanel.add(classloadersButton); classloadersButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { printClassLoaders(); } - }); - JButton threadListButton = new JButton("Thread List"); + JButton threadListButton = new JButton(R("CONSOLEthreadList")); buttonPanel.add(threadListButton); threadListButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { printThreadInfo(); } - }); - JButton closeButton = new JButton("Close"); + JButton closeButton = new JButton(R("ButClose")); buttonPanel.add(closeButton); closeButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { + public void run() { hideConsole(); } @@ -224,38 +246,56 @@ public class JavaConsole { } }); - stdOutUpdater.start(); - stdErrUpdater.start(); - consoleWindow.add(contentPanel); consoleWindow.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); consoleWindow.pack(); consoleWindow.setSize(new Dimension(900, 600)); consoleWindow.setMinimumSize(new Dimension(900, 300)); - initialized = true; - splitPane.setDividerLocation(0.5); splitPane.setResizeWeight(0.5); } public void showConsole() { + showConsole(false); + } - if (!initialized) { - initialize(); - } - + public void showConsole(boolean b) { + consoleWindow.setModal(b); consoleWindow.setVisible(true); } public void hideConsole() { + consoleWindow.setModal(false); consoleWindow.setVisible(false); } + public void showConsoleLater() { + showConsoleLater(false); + } + + public void showConsoleLater(final boolean b) { + SwingUtilities.invokeLater(new Runnable() { + + public void run() { + JavaConsole.getConsole().showConsole(b); + } + }); + } + + public void hideConsoleLater() { + SwingUtilities.invokeLater(new Runnable() { + + public void run() { + JavaConsole.getConsole().hideConsole(); + } + }); + } + protected void printSystemProperties() { OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, " ----"); - OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, "System Properties:"); + OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, R("CONSOLEsystemProperties") + ":"); OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, ""); Properties p = System.getProperties(); Set<Object> keys = p.keySet(); @@ -266,26 +306,34 @@ public class JavaConsole { OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, " ----"); } + public void setClassLoaderInfoProvider(ClassLoaderInfoProvider clip) { + classLoaderInfoProvider = clip; + } + private void printClassLoaders() { - OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, " ----"); - OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, "Available Classloaders: "); - Set<String> loaders = PluginAppletSecurityContext.getLoaderInfo().keySet(); - for (String loader : loaders) { - OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, loader + "\n" - + " codebase = " - + PluginAppletSecurityContext.getLoaderInfo().get(loader)); + if (classLoaderInfoProvider == null) { + OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, R("CONSOLEnoClassLoaders")); + } else { + OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, " ----"); + OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, R("CONSOLEclassLoaders") + ": "); + Set<String> loaders = classLoaderInfoProvider.getLoaderInfo().keySet(); + for (String loader : loaders) { + OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, loader + "\n" + + " codebase = " + + classLoaderInfoProvider.getLoaderInfo().get(loader)); + } + OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, " ----"); } - OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, " ----"); } private void printMemoryInfo() { OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, " ----- "); - OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, " Memory Info:"); - OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, " Max Memory: " + OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, " " + R("CONSOLEmemoryInfo") + ":"); + OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, " " + R("CONSOLEmemoryMax") + ": " + String.format("%1$10d", Runtime.getRuntime().maxMemory())); - OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, " Total Memory: " + OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, " " + R("CONSOLEmemoryTotal") + ": " + String.format("%1$10d", Runtime.getRuntime().totalMemory())); - OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, " Free Memory: " + OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, " " + R("CONSOLEmemoryFree") + ": " + String.format("%1$10d", Runtime.getRuntime().freeMemory())); OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, " ----"); @@ -295,7 +343,7 @@ public class JavaConsole { Map<Thread, StackTraceElement[]> map = Thread.getAllStackTraces(); Set<Thread> keys = map.keySet(); for (Thread key : keys) { - OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, "Thread " + key.getId() + ": " + key.getName()); + OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, R("CONSOLEthread") + " " + key.getId() + ": " + key.getName()); for (StackTraceElement element : map.get(key)) { OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, " " + element); } @@ -317,6 +365,7 @@ public class JavaConsole { if (toShowConsole) { SwingUtilities.invokeLater(new Runnable() { + public void run() { console.showConsole(); } @@ -325,47 +374,11 @@ public class JavaConsole { } - /** - * This thread updates the text on a JTextArea based on the text in a file - */ - class TextAreaUpdater extends Thread { - - File fileToRead; - JTextArea outputTextArea; - - public TextAreaUpdater(File file, JTextArea textArea) { - fileToRead = file; - outputTextArea = textArea; - setDaemon(true); - } - - public void run() { - - try { - BufferedReader reader = new BufferedReader(new FileReader( - fileToRead)); - String line; - while (true) { - while ((line = reader.readLine()) != null) { - outputTextArea.insert(line + "\n", outputTextArea - .getDocument().getLength()); - outputTextArea.setCaretPosition(outputTextArea - .getText().length()); - } - Thread.sleep(1000); - } - - } catch (FileNotFoundException e) { - OutputController.getLogger().log(OutputController.Level.ERROR_ALL,e); - } catch (IOException e) { - OutputController.getLogger().log(OutputController.Level.ERROR_ALL,e); - } catch (InterruptedException e) { - OutputController.getLogger().log(OutputController.Level.ERROR_ALL,e); - Thread.currentThread().interrupt(); - } - - } - + void logOutput(String s) { + stdOutText.setText(stdOutText.getText() + s + "\n"); } + void logError(String s) { + stdErrText.setText(stdErrText.getText() + s + "\n"); + } } diff --git a/netx/net/sourceforge/jnlp/util/logging/LogConfig.java b/netx/net/sourceforge/jnlp/util/logging/LogConfig.java index 70db30c..2c98cd2 100644 --- a/netx/net/sourceforge/jnlp/util/logging/LogConfig.java +++ b/netx/net/sourceforge/jnlp/util/logging/LogConfig.java @@ -156,6 +156,10 @@ public class LogConfig { void setLogToSysLog(boolean logToSysLog) { this.logToSysLog = logToSysLog; } + + boolean isLogToConsole() { + return JavaConsole.isEnabled(); + } diff --git a/netx/net/sourceforge/jnlp/util/logging/OutputController.java b/netx/net/sourceforge/jnlp/util/logging/OutputController.java index 7a78f58..3606e6c 100644 --- a/netx/net/sourceforge/jnlp/util/logging/OutputController.java +++ b/netx/net/sourceforge/jnlp/util/logging/OutputController.java @@ -45,16 +45,30 @@ import net.sourceforge.jnlp.runtime.JNLPRuntime; public class OutputController { - public static enum Level { + public static enum Level { MESSAGE_ALL, // - stdout/log in all cases MESSAGE_DEBUG, // - stdout/log in verbose/debug mode WARNING_ALL, // - stdout+stderr/log in all cases (default for WARNING_DEBUG, // - stdou+stde/logrr in verbose/debug mode ERROR_ALL, // - stderr/log in all cases (default for - ERROR_DEBUG, // - stderr/log in verbose/debug mode + ERROR_DEBUG; // - stderr/log in verbose/debug mode //ERROR_DEBUG is default for Throwable //MESSAGE_VERBOSE is defautrl for String + + private static boolean isOutput(MessageWithLevel s) { + return s.level == Level.MESSAGE_ALL + || s.level == Level.MESSAGE_DEBUG + || s.level == Level.WARNING_ALL + || s.level == Level.WARNING_DEBUG; + } + + private static boolean isError(MessageWithLevel s) { + return s.level == Level.ERROR_ALL + || s.level == Level.ERROR_DEBUG + || s.level == Level.WARNING_ALL + || s.level == Level.WARNING_DEBUG; + } } private static final class MessageWithLevel { @@ -134,16 +148,10 @@ public class OutputController { } } if (LogConfig.getLogConfig().isLogToStreams()) { - if (s.level == Level.MESSAGE_ALL - || s.level == Level.MESSAGE_DEBUG - || s.level == Level.WARNING_ALL - || s.level == Level.WARNING_DEBUG) { + if (Level.isOutput(s)) { outLog.log(message); } - if (s.level == Level.ERROR_ALL - || s.level == Level.ERROR_DEBUG - || s.level == Level.WARNING_ALL - || s.level == Level.WARNING_DEBUG) { + if (Level.isError(s)) { errLog.log(message); } } @@ -153,6 +161,14 @@ public class OutputController { if (LogConfig.getLogConfig().isLogToSysLog()) { getSystemLog().log(message); } + if (LogConfig.getLogConfig().isLogToConsole()) { + if (Level.isOutput(s)){ + JavaConsole.getConsole().logOutput(message); + } + if (Level.isError(s)){ + JavaConsole.getConsole().logError(message); + } + } } diff --git a/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java b/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java index fb343f3..2fc42d8 100644 --- a/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java +++ b/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java @@ -235,7 +235,7 @@ public class PluginAppletSecurityContext { private ClassLoader liveconnectLoader = ClassLoader.getSystemClassLoader(); int identifier = 0; - public static PluginStreamHandler streamhandler; + private static PluginStreamHandler streamhandler; long startTime = 0; @@ -321,6 +321,10 @@ public class PluginAppletSecurityContext { streamhandler = sh; } + public static PluginStreamHandler getStreamhandler() { + return streamhandler; + } + public static Map<String, String> getLoaderInfo() { Hashtable<String, String> map = new Hashtable<String, String>(); diff --git a/plugin/icedteanp/java/sun/applet/PluginMain.java b/plugin/icedteanp/java/sun/applet/PluginMain.java index cef5313..e6ba080 100644 --- a/plugin/icedteanp/java/sun/applet/PluginMain.java +++ b/plugin/icedteanp/java/sun/applet/PluginMain.java @@ -75,6 +75,7 @@ import java.net.URL; import java.net.URLStreamHandler; import java.util.Enumeration; import java.util.Hashtable; +import java.util.Map; import java.util.Properties; import sun.awt.AppContext; import sun.awt.SunToolkit; @@ -82,15 +83,13 @@ import sun.awt.SunToolkit; import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.JNLPRuntime; import net.sourceforge.jnlp.security.JNLPAuthenticator; +import net.sourceforge.jnlp.util.logging.JavaConsole; import net.sourceforge.jnlp.util.logging.OutputController; /** * The main entry point into PluginAppletViewer. */ public class PluginMain { - // the files where stdout/stderr are sent to - public static final String PLUGIN_STDERR_FILE = "java.stderr"; - public static final String PLUGIN_STDOUT_FILE = "java.stdout"; // This is used in init(). Getting rid of this is desirable but depends // on whether the property that uses it is necessary/standard. @@ -147,6 +146,13 @@ public class PluginMain { streamHandler.startProcessing(); setCookieHandler(streamHandler); + JavaConsole.getConsole().setClassLoaderInfoProvider(new JavaConsole.ClassLoaderInfoProvider() { + + @Override + public Map<String, String> getLoaderInfo() { + return PluginAppletSecurityContext.getLoaderInfo(); + } + }); } catch (Exception e) { OutputController.getLogger().log(e); diff --git a/plugin/icedteanp/java/sun/applet/PluginStreamHandler.java b/plugin/icedteanp/java/sun/applet/PluginStreamHandler.java index fb23755..e21b243 100644 --- a/plugin/icedteanp/java/sun/applet/PluginStreamHandler.java +++ b/plugin/icedteanp/java/sun/applet/PluginStreamHandler.java @@ -44,11 +44,12 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; -import java.net.MalformedURLException; import java.nio.charset.Charset; import javax.swing.SwingUtilities; import net.sourceforge.jnlp.runtime.JNLPRuntime; +import net.sourceforge.jnlp.runtime.Translator; +import net.sourceforge.jnlp.util.logging.JavaConsole; import net.sourceforge.jnlp.util.logging.OutputController; public class PluginStreamHandler { @@ -58,7 +59,6 @@ public class PluginStreamHandler { private RequestQueue queue = new RequestQueue(); - private JavaConsole console = new JavaConsole(); private PluginMessageConsumer consumer; private volatile boolean shuttingDown = false; @@ -242,9 +242,17 @@ public class PluginStreamHandler { private void handlePluginMessage(String message) { if (message.equals("plugin showconsole")) { - showConsole(); + if (JavaConsole.isEnabled()){ + JavaConsole.getConsole().showConsoleLater(); + } else { + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, Translator.R("DPJavaConsoleDisabledHint")); + } } else if (message.equals("plugin hideconsole")) { - hideConsole(); + if (JavaConsole.isEnabled()){ + JavaConsole.getConsole().hideConsoleLater(); + } else { + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, Translator.R("DPJavaConsoleDisabledHint")); + } } else { // else this is something that was specifically requested finishCallRequest(message); @@ -374,20 +382,4 @@ public class PluginStreamHandler { return; } - - private void showConsole() { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - console.showConsole(); - } - }); - } - - private void hideConsole() { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - console.hideConsole(); - } - }); - } } |