mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-29 11:55:40 +02:00
Improve tracing options.
Signed-off-by: Greg Watson <g.watson@computer.org>
This commit is contained in:
parent
b49fe0ca87
commit
49e6a62bb7
2 changed files with 49 additions and 29 deletions
|
@ -17,6 +17,7 @@ import java.util.Hashtable;
|
||||||
import org.eclipse.osgi.service.debug.DebugOptions;
|
import org.eclipse.osgi.service.debug.DebugOptions;
|
||||||
import org.eclipse.osgi.service.debug.DebugOptionsListener;
|
import org.eclipse.osgi.service.debug.DebugOptionsListener;
|
||||||
import org.eclipse.osgi.service.debug.DebugTrace;
|
import org.eclipse.osgi.service.debug.DebugTrace;
|
||||||
|
import org.eclipse.osgi.util.NLS;
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,18 +32,15 @@ import org.osgi.framework.BundleContext;
|
||||||
*/
|
*/
|
||||||
public class RemoteDebugOptions implements DebugOptionsListener {
|
public class RemoteDebugOptions implements DebugOptionsListener {
|
||||||
|
|
||||||
private static final String DEBUG_FLAG = RemoteCorePlugin.getUniqueIdentifier() + "/debug"; //$NON-NLS-1$
|
public static final String DEBUG_REMOTE_COMMANDS = "/debug/commands"; //$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;
|
|
||||||
|
|
||||||
private static DebugTrace fDebugTrace;
|
private static DebugTrace fDebugTrace;
|
||||||
private static RemoteDebugOptions fDebugOptions;
|
private static DebugOptions fDebugOptions;
|
||||||
|
private static RemoteDebugOptions fRemoteDebugOptions;
|
||||||
|
|
||||||
public static void configure(BundleContext context) {
|
public static void configure(BundleContext context) {
|
||||||
if (fDebugOptions == null) {
|
if (fRemoteDebugOptions == null) {
|
||||||
fDebugOptions = new RemoteDebugOptions(context);
|
fRemoteDebugOptions = new RemoteDebugOptions(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,26 +57,27 @@ public class RemoteDebugOptions implements DebugOptionsListener {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void optionsChanged(DebugOptions options) {
|
public void optionsChanged(DebugOptions options) {
|
||||||
|
fDebugOptions = options;
|
||||||
fDebugTrace = options.newDebugTrace(RemoteCorePlugin.getUniqueIdentifier());
|
fDebugTrace = options.newDebugTrace(RemoteCorePlugin.getUniqueIdentifier());
|
||||||
DEBUG = options.getBooleanOption(DEBUG_FLAG, false);
|
|
||||||
DEBUG_REMOTE_COMMANDS = DEBUG & options.getBooleanOption(DEBUG_REMOTE_COMMANDS_FLAG, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static boolean isDebugging() {
|
||||||
* Prints the given message to System.out and to the OSGi tracing (if started)
|
return RemoteCorePlugin.getDefault().isDebugging();
|
||||||
*
|
}
|
||||||
* @param option
|
|
||||||
* the option or <code>null</code>
|
public static boolean isDebugging(String option) {
|
||||||
* @param message
|
if (fDebugOptions == null) {
|
||||||
* the message to print or <code>null</code>
|
return false;
|
||||||
* @param throwable
|
}
|
||||||
* the {@link Throwable} or <code>null</code>
|
return fDebugOptions.getBooleanOption(RemoteCorePlugin.getUniqueIdentifier() + option, false);
|
||||||
*/
|
}
|
||||||
public static void trace(String option, String message, Throwable throwable) {
|
|
||||||
System.out.print(message);
|
public static void setDebugging(String option, boolean value) {
|
||||||
// then pass the original message to be traced into a file
|
if (fDebugOptions != null) {
|
||||||
if (fDebugTrace != null) {
|
if (value) {
|
||||||
fDebugTrace.trace(option, message, throwable);
|
fDebugOptions.setDebugEnabled(true);
|
||||||
|
}
|
||||||
|
fDebugOptions.setOption(option, Boolean.toString(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +88,30 @@ public class RemoteDebugOptions implements DebugOptionsListener {
|
||||||
* the message or <code>null</code>
|
* the message or <code>null</code>
|
||||||
*/
|
*/
|
||||||
public static void trace(String message) {
|
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 <code>null</code>
|
||||||
|
* @param arguments
|
||||||
|
* optional arguments for the message or <code>null</code>
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,9 +182,7 @@ public class JSchProcessBuilder extends AbstractRemoteProcessBuilder {
|
||||||
exec.setPty((flags & ALLOCATE_PTY) == ALLOCATE_PTY);
|
exec.setPty((flags & ALLOCATE_PTY) == ALLOCATE_PTY);
|
||||||
exec.setXForwarding((flags & FORWARD_X11) == FORWARD_X11);
|
exec.setXForwarding((flags & FORWARD_X11) == FORWARD_X11);
|
||||||
exec.connect();
|
exec.connect();
|
||||||
if (RemoteDebugOptions.DEBUG_REMOTE_COMMANDS) {
|
RemoteDebugOptions.trace(RemoteDebugOptions.DEBUG_REMOTE_COMMANDS, "executing command: " + command); //$NON-NLS-1$
|
||||||
RemoteDebugOptions.trace("executing command: " + command); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
return new JSchProcess(exec, redirectErrorStream());
|
return new JSchProcess(exec, redirectErrorStream());
|
||||||
} catch (RemoteConnectionException e) {
|
} catch (RemoteConnectionException e) {
|
||||||
throw new IOException(e.getMessage());
|
throw new IOException(e.getMessage());
|
||||||
|
|
Loading…
Add table
Reference in a new issue