diff --git a/bundles/org.eclipse.remote.core/.options b/bundles/org.eclipse.remote.core/.options index 4ae7220a34b..2ebe6916eba 100644 --- a/bundles/org.eclipse.remote.core/.options +++ b/bundles/org.eclipse.remote.core/.options @@ -1 +1,2 @@ org.eclipse.remote.core/debug=false +org.eclipse.remote.core/debug/commands=false diff --git a/bundles/org.eclipse.remote.core/META-INF/MANIFEST.MF b/bundles/org.eclipse.remote.core/META-INF/MANIFEST.MF index d2f8426c1d7..53d8c27a8e8 100644 --- a/bundles/org.eclipse.remote.core/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.remote.core/META-INF/MANIFEST.MF @@ -12,7 +12,7 @@ Require-Bundle: org.eclipse.core.runtime, Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.remote.core, org.eclipse.remote.core.exception, - org.eclipse.remote.internal.core;x-friends:="org.eclipse.remote.ui", + org.eclipse.remote.internal.core;x-friends:="org.eclipse.remote.ui,org.eclipse.remote.jsch.core", org.eclipse.remote.internal.core.messages;x-internal:=true, org.eclipse.remote.internal.core.preferences;x-friends:="org.eclipse.remote.ui", org.eclipse.remote.internal.core.services.local;x-internal:=true diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteCorePlugin.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteCorePlugin.java index 0bfe0e3c316..cf64a5dd73d 100644 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteCorePlugin.java +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteCorePlugin.java @@ -93,6 +93,7 @@ public class RemoteCorePlugin extends Plugin { public void start(BundleContext context) throws Exception { super.start(context); plugin = this; + new RemoteDebugOptions(context); ResourcesPlugin.getWorkspace().addSaveParticipant(getUniqueIdentifier(), new ISaveParticipant() { @Override public void saving(ISaveContext saveContext) throws CoreException { 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 new file mode 100644 index 00000000000..adff18d1144 --- /dev/null +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteDebugOptions.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2012 Sage Electronic Engineering, LLC. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Jason Litton (Sage Electronic Engineering, LLC) - initial API and implementation + * Greg Watson (IBM) - adapted for remote core + *******************************************************************************/ + +package org.eclipse.remote.internal.core; + +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.osgi.framework.BundleContext; + +/** + * Hooks our debug options to the Platform trace functonality. + * In essence, we can open Window -> Preferences -> Tracing + * and turn on debug options for this package. The debug output + * will come out on the console and can be saved directly to + * a file. Classes that need to be debugged can call into + * RemoteDebugOptions to get debug flags. If new flags need to be + * created, they will need to have a unique identifier and added to + * the .options file in this plugin + */ +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; + + /** + * The {@link DebugTrace} object to print to OSGi tracing + */ + private static DebugTrace fDebugTrace; + + /** + * Constructor + */ + public RemoteDebugOptions(BundleContext context) { + Hashtable props = new Hashtable(2); + props.put(DebugOptions.LISTENER_SYMBOLICNAME, RemoteCorePlugin.getUniqueIdentifier()); + context.registerService(DebugOptionsListener.class.getName(), this, props); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.osgi.service.debug.DebugOptionsListener#optionsChanged(org.eclipse.osgi.service.debug.DebugOptions) + */ + @Override + public void optionsChanged(DebugOptions 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); + } + } + + /** + * Prints the given message to System.out and to the OSGi tracing (if enabled) + * + * @param message + * the message or null + */ + public static void trace(String message) { + trace(null, message, 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 4ae3cbef4f5..d4aa6bd5151 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 @@ -27,6 +27,7 @@ import org.eclipse.remote.core.AbstractRemoteProcessBuilder; import org.eclipse.remote.core.IRemoteFileManager; import org.eclipse.remote.core.IRemoteProcess; import org.eclipse.remote.core.exception.RemoteConnectionException; +import org.eclipse.remote.internal.core.RemoteDebugOptions; import org.eclipse.remote.internal.jsch.core.messages.Messages; import com.jcraft.jsch.ChannelExec; @@ -181,6 +182,9 @@ 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$ + } return new JSchProcess(exec, redirectErrorStream()); } catch (RemoteConnectionException e) { throw new IOException(e.getMessage()); diff --git a/bundles/org.eclipse.remote.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.remote.ui/META-INF/MANIFEST.MF index 5df97b3b2e4..819c1f83ee5 100644 --- a/bundles/org.eclipse.remote.ui/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.remote.ui/META-INF/MANIFEST.MF @@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.remote.core, org.eclipse.core.filesystem, - org.eclipse.core.resources + org.eclipse.core.resources, + org.eclipse.ui.trace Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.remote.internal.ui;x-internal:=true, diff --git a/bundles/org.eclipse.remote.ui/plugin.xml b/bundles/org.eclipse.remote.ui/plugin.xml index cff76c03644..0a6f43d4994 100644 --- a/bundles/org.eclipse.remote.ui/plugin.xml +++ b/bundles/org.eclipse.remote.ui/plugin.xml @@ -27,5 +27,16 @@ name="%ConnectionsPreferencePage.name"> + + + + + +