diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteDebugOptions.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteDebugOptions.java index f8944d8d77b..066e25e8903 100644 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteDebugOptions.java +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteDebugOptions.java @@ -17,6 +17,7 @@ import java.util.Hashtable; import org.eclipse.osgi.service.debug.DebugOptions; import org.eclipse.osgi.service.debug.DebugOptionsListener; import org.eclipse.osgi.service.debug.DebugTrace; +import org.eclipse.osgi.util.NLS; import org.osgi.framework.BundleContext; /** @@ -31,18 +32,15 @@ import org.osgi.framework.BundleContext; */ public class RemoteDebugOptions implements DebugOptionsListener { - private static final String DEBUG_FLAG = RemoteCorePlugin.getUniqueIdentifier() + "/debug"; //$NON-NLS-1$ - private static final String DEBUG_REMOTE_COMMANDS_FLAG = RemoteCorePlugin.getUniqueIdentifier() + "/debug/commands"; //$NON-NLS-1$ - - public static boolean DEBUG = false; - public static boolean DEBUG_REMOTE_COMMANDS = false; + public static final String DEBUG_REMOTE_COMMANDS = "/debug/commands"; //$NON-NLS-1$ private static DebugTrace fDebugTrace; - private static RemoteDebugOptions fDebugOptions; + private static DebugOptions fDebugOptions; + private static RemoteDebugOptions fRemoteDebugOptions; public static void configure(BundleContext context) { - if (fDebugOptions == null) { - fDebugOptions = new RemoteDebugOptions(context); + if (fRemoteDebugOptions == null) { + fRemoteDebugOptions = new RemoteDebugOptions(context); } } @@ -59,26 +57,27 @@ public class RemoteDebugOptions implements DebugOptionsListener { */ @Override public void optionsChanged(DebugOptions options) { + fDebugOptions = options; fDebugTrace = options.newDebugTrace(RemoteCorePlugin.getUniqueIdentifier()); - DEBUG = options.getBooleanOption(DEBUG_FLAG, false); - DEBUG_REMOTE_COMMANDS = DEBUG & options.getBooleanOption(DEBUG_REMOTE_COMMANDS_FLAG, false); } - /** - * Prints the given message to System.out and to the OSGi tracing (if started) - * - * @param option - * the option or null - * @param message - * the message to print or null - * @param throwable - * the {@link Throwable} or null - */ - public static void trace(String option, String message, Throwable throwable) { - System.out.print(message); - // then pass the original message to be traced into a file - if (fDebugTrace != null) { - fDebugTrace.trace(option, message, throwable); + public static boolean isDebugging() { + return RemoteCorePlugin.getDefault().isDebugging(); + } + + public static boolean isDebugging(String option) { + if (fDebugOptions == null) { + return false; + } + return fDebugOptions.getBooleanOption(RemoteCorePlugin.getUniqueIdentifier() + option, false); + } + + public static void setDebugging(String option, boolean value) { + if (fDebugOptions != null) { + if (value) { + fDebugOptions.setDebugEnabled(true); + } + fDebugOptions.setOption(option, Boolean.toString(value)); } } @@ -89,7 +88,30 @@ public class RemoteDebugOptions implements DebugOptionsListener { * the message or null */ public static void trace(String message) { - trace(null, message, null); + trace(null, message); + } + + /** + * Prints the given message to System.out and to the OSGi tracing (if enabled) + * + * @param option + * the option to determine if tracing is displayed + * @param message + * the message or null + * @param arguments + * optional arguments for the message or null + */ + public static void trace(String option, String message, String... arguments) { + String traceMsg = message; + if (arguments.length > 0) { + traceMsg = NLS.bind(message, arguments); + } + if ((option != null && isDebugging(option)) || isDebugging()) { + System.out.println(traceMsg); + if (fDebugTrace != null) { + fDebugTrace.trace(option, traceMsg, null); + } + } } } diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchProcessBuilder.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchProcessBuilder.java index d4aa6bd5151..5233ae6584d 100644 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchProcessBuilder.java +++ b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchProcessBuilder.java @@ -182,9 +182,7 @@ public class JSchProcessBuilder extends AbstractRemoteProcessBuilder { exec.setPty((flags & ALLOCATE_PTY) == ALLOCATE_PTY); exec.setXForwarding((flags & FORWARD_X11) == FORWARD_X11); exec.connect(); - if (RemoteDebugOptions.DEBUG_REMOTE_COMMANDS) { - RemoteDebugOptions.trace("executing command: " + command); //$NON-NLS-1$ - } + RemoteDebugOptions.trace(RemoteDebugOptions.DEBUG_REMOTE_COMMANDS, "executing command: " + command); //$NON-NLS-1$ return new JSchProcess(exec, redirectErrorStream()); } catch (RemoteConnectionException e) { throw new IOException(e.getMessage());