Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Torregrosa Paez2016-04-07 05:37:32 -0400
committerPablo Torregrosa Paez2016-04-07 08:15:14 -0400
commit7e9010c1dfd9c377e72c7856589835f299f8ca2c (patch)
tree43c3b890035a178494a53653023dcfd865a5f361 /target_explorer
parent3d77e375e2cb90e661e58273dbff16f1591d2dcd (diff)
downloadorg.eclipse.tcf-7e9010c1dfd9c377e72c7856589835f299f8ca2c.tar.gz
org.eclipse.tcf-7e9010c1dfd9c377e72c7856589835f299f8ca2c.tar.xz
org.eclipse.tcf-7e9010c1dfd9c377e72c7856589835f299f8ca2c.zip
Target Explorer: Run commands before launch in the same shell instance
Change-Id: I6e78083fee1096ea58e4ba84ee0aa761b4005a6c Signed-off-by: Pablo Torregrosa Paez <pablo.torregrosa@windriver.com>
Diffstat (limited to 'target_explorer')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/interfaces/IRemoteLaunchDelegate.java17
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/launching/TEGdbAbstractLaunchDelegate.java64
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/launching/TERunLaunchDelegate.java60
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/nls/Messages.java3
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/nls/Messages.properties5
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/utils/TEHelper.java59
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/templates/prerun_template.sh10
7 files changed, 200 insertions, 18 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/interfaces/IRemoteLaunchDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/interfaces/IRemoteLaunchDelegate.java
new file mode 100644
index 000000000..8ea748a5e
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/interfaces/IRemoteLaunchDelegate.java
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Wind River Systems, Inc. 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:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.tcf.launch.cdt.interfaces;
+
+import org.eclipse.core.runtime.IPath;
+
+public interface IRemoteLaunchDelegate {
+
+ public IPath getPrerunTemplateRoot();
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/launching/TEGdbAbstractLaunchDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/launching/TEGdbAbstractLaunchDelegate.java
index dc8dcdd3b..675d721d3 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/launching/TEGdbAbstractLaunchDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/launching/TEGdbAbstractLaunchDelegate.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2015 Wind River Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2015, 2016 Wind River Systems, Inc. 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
@@ -9,9 +9,14 @@
*******************************************************************************/
package org.eclipse.tcf.te.tcf.launch.cdt.launching;
+import java.io.BufferedWriter;
import java.io.File;
+import java.io.FileWriter;
import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
@@ -47,6 +52,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.variables.VariablesPlugin;
@@ -154,12 +160,6 @@ public abstract class TEGdbAbstractLaunchDelegate extends GdbLaunchDelegate {
}
}
- // Perform prelaunch command
- if (!isAttachLaunch) {
- String prelaunchCmd = config.getAttribute(IRemoteTEConfigurationConstants.ATTR_PRERUN_COMMANDS, ""); //$NON-NLS-1$
- TEHelper.launchCmd(peer, null, prelaunchCmd, null, new SubProgressMonitor(monitor, 2), new Callback());
- }
-
// Launch gdbserver on target
final AtomicReference<String> gdbserverPortNumber = new AtomicReference<String>(config.getAttribute(IRemoteTEConfigurationConstants.ATTR_GDBSERVER_PORT, TEHelper.getStringPreferenceValue(isAttachLaunch ? IPreferenceKeys.PREF_GDBSERVER_PORT_ATTACH : IPreferenceKeys.PREF_GDBSERVER_PORT)));
final AtomicReference<String> gdbserverPortNumberMappedTo = new AtomicReference<String>(config.getAttribute(IRemoteTEConfigurationConstants.ATTR_GDBSERVER_PORT_MAPPED_TO, TEHelper.getStringPreferenceValue(isAttachLaunch ? IPreferenceKeys.PREF_GDBSERVER_PORT_ATTACH_MAPPED_TO : IPreferenceKeys.PREF_GDBSERVER_PORT_MAPPED_TO)));
@@ -276,8 +276,54 @@ public abstract class TEGdbAbstractLaunchDelegate extends GdbLaunchDelegate {
peerName = peer.getName() + ", PID " + remotePID; //$NON-NLS-1$
}
- String[] argv = StringUtil.tokenize(gdbserverCommand + ' ' + commandArguments, 0, false);
- launcher = TEHelper.launchCmdWithEnv(peer, peerName, argv[0], argv, commandEnv, listener, new SubProgressMonitor(monitor, 3), callback);
+
+ // If there are commands to run before launching, create a script for them
+ String gdbserverLaunchCommand = gdbserverCommand + ' ' + commandArguments;
+ String prelaunchCmd = config.getAttribute(IRemoteTEConfigurationConstants.ATTR_PRERUN_COMMANDS, ""); //$NON-NLS-1$
+ if (!isAttachLaunch && prelaunchCmd != null && prelaunchCmd.trim().length() > 0) {
+ SimpleDateFormat formatter = new SimpleDateFormat ("HH-mm-ss-S", Locale.US); //$NON-NLS-1$
+ String prerunScriptNamePreffix = formatter.format( Long.valueOf(Calendar.getInstance().getTime().getTime()) );
+ String prerunScriptName = prerunScriptNamePreffix + "_" + exePath.toFile().getName() + ".sh"; //$NON-NLS-1$ //$NON-NLS-2$
+
+ IPath rootLocation = Activator.getDefault().getStateLocation().append("prerun_temp_scripts"); //$NON-NLS-1$
+ if (!rootLocation.toFile().exists()) rootLocation.toFile().mkdirs();
+ IPath prerunScriptLocation = rootLocation.append(prerunScriptName);
+ if (prerunScriptLocation.toFile().exists()) prerunScriptLocation.toFile().delete();
+
+ // Create the script
+ BufferedWriter writer = null;
+ try {
+ writer = new BufferedWriter(new FileWriter(prerunScriptLocation.toFile()));
+ writer.write(NLS.bind(TEHelper.getPrerunTemplateContent(peer), prelaunchCmd.replaceAll("\\r", ""), gdbserverLaunchCommand.replaceAll("\\r", ""))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ } catch (Exception e) {
+ abort(NLS.bind(Messages.TEGdbAbstractLaunchDelegate_prerunScriptCreationFailed, prerunScriptLocation, e.getLocalizedMessage()), e, ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST);
+ } finally {
+ if (writer != null) {
+ try {
+ writer.close();
+ } catch (IOException e) { /* Ignored on purpose. */ }
+ }
+ }
+ // Grant execution permission
+ prerunScriptLocation.toFile().setExecutable(true, false);
+
+ // Download the script to the target
+ IPath remotePrerunScriptPath = new Path("/tmp").append(prerunScriptName); //$NON-NLS-1$
+ try {
+ TEHelper.remoteFileTransfer(peer, prerunScriptLocation.toString(), remotePrerunScriptPath.toString(), new SubProgressMonitor(monitor, 80));
+ } catch (IOException e) {
+ abort(NLS.bind(Messages.TEGdbAbstractLaunchDelegate_prerunScriptTransferFailed, remotePrerunScriptPath.toString(), e.getLocalizedMessage()), e, ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST);
+ } finally {
+ // Remove local temporal script
+ prerunScriptLocation.toFile().delete();
+ }
+
+ launcher = TEHelper.launchCmdWithEnv(peer, peerName, remotePrerunScriptPath.toString(), (String)null, commandEnv, listener, new SubProgressMonitor(monitor, 3), callback);
+ }
+ else {
+ String[] argv = StringUtil.tokenize(gdbserverLaunchCommand, 0, false);
+ launcher = TEHelper.launchCmdWithEnv(peer, peerName, argv[0], argv, commandEnv, listener, new SubProgressMonitor(monitor, 3), callback);
+ }
// Now wait until gdbserver is up and running on the remote host
while (!gdbServerReady.get() && !gdbServerExited.get()) {
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/launching/TERunLaunchDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/launching/TERunLaunchDelegate.java
index 55f392c91..79c305492 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/launching/TERunLaunchDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/launching/TERunLaunchDelegate.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013, 2015 MontaVista Software, LLC. and others. All rights reserved.
+ * Copyright (c) 2013, 2016 MontaVista Software, 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
@@ -9,10 +9,15 @@
*******************************************************************************/
package org.eclipse.tcf.te.tcf.launch.cdt.launching;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.MessageFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
import java.util.Date;
+import java.util.Locale;
import java.util.Map;
import org.eclipse.cdt.core.model.ICProject;
@@ -22,13 +27,13 @@ import org.eclipse.cdt.launch.AbstractCLaunchDelegate2;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.osgi.util.NLS;
import org.eclipse.tcf.protocol.IPeer;
-import org.eclipse.tcf.te.runtime.callback.Callback;
import org.eclipse.tcf.te.tcf.launch.cdt.activator.Activator;
import org.eclipse.tcf.te.tcf.launch.cdt.interfaces.IRemoteTEConfigurationConstants;
import org.eclipse.tcf.te.tcf.launch.cdt.nls.Messages;
@@ -50,8 +55,49 @@ public class TERunLaunchDelegate extends AbstractCLaunchDelegate2 {
Activator.getDefault().initializeTE();
// 0. Get the peer from the launch configuration
IPeer peer = TEHelper.getCurrentConnection(config).getPeer();
- // 1.Download binary if needed
+ // 1.1. If there are commands to run before, create a script for them
String remoteExePath = config.getAttribute(IRemoteTEConfigurationConstants.ATTR_REMOTE_PATH, ""); //$NON-NLS-1$
+ IPath remotePrerunScriptPath = null;
+ String prerunCommands = config.getAttribute(IRemoteTEConfigurationConstants.ATTR_PRERUN_COMMANDS, (String)null);
+ if (prerunCommands != null && prerunCommands.trim().length() > 0) {
+ SimpleDateFormat formatter = new SimpleDateFormat ("HH-mm-ss-S", Locale.US); //$NON-NLS-1$
+ String prerunScriptNamePreffix = formatter.format( Long.valueOf(Calendar.getInstance().getTime().getTime()) );
+ String prerunScriptName = prerunScriptNamePreffix + "_" + exePath.toFile().getName() + ".sh"; //$NON-NLS-1$ //$NON-NLS-2$
+
+ IPath localTempLocation = Activator.getDefault().getStateLocation().append("prerun_commands_scripts"); //$NON-NLS-1$
+ if (!localTempLocation.toFile().exists()) localTempLocation.toFile().mkdirs();
+ IPath prerunScriptLocation = localTempLocation.append(prerunScriptName);
+ if (prerunScriptLocation.toFile().exists()) prerunScriptLocation.toFile().delete();
+
+ BufferedWriter writer = null;
+ try {
+ writer = new BufferedWriter(new FileWriter(prerunScriptLocation.toFile()));
+ writer.write(NLS.bind(TEHelper.getPrerunTemplateContent(peer), prerunCommands.replaceAll("\\r", ""), remoteExePath.replaceAll("\\r", ""))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ } catch (Exception e) {
+ abort(NLS.bind(Messages.TEGdbAbstractLaunchDelegate_prerunScriptCreationFailed, prerunScriptLocation.toString(), e.getLocalizedMessage()), e, ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST);
+ } finally {
+ if (writer != null) {
+ try {
+ writer.close();
+ } catch (IOException e) { /* Ignored on purpose. */ }
+ }
+ }
+ // Grant execution permission
+ prerunScriptLocation.toFile().setExecutable(true, false);
+
+ // Download the script to the target
+ remotePrerunScriptPath = new Path("/tmp").append(prerunScriptName); //$NON-NLS-1$
+ try {
+ TEHelper.remoteFileTransfer(peer, prerunScriptLocation.toString(), remotePrerunScriptPath.toString(), new SubProgressMonitor(monitor, 80));
+ } catch (IOException e) {
+ abort(NLS.bind(Messages.TEGdbAbstractLaunchDelegate_prerunScriptTransferFailed, remotePrerunScriptPath.toString(), e.getLocalizedMessage()), e, ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST);
+ } finally {
+ // Remove local temporal script
+ prerunScriptLocation.toFile().delete();
+ }
+ }
+
+ // 1.2. Download binary if needed
monitor.setTaskName(Messages.TEGdbAbstractLaunchDelegate_downloading);
boolean skipDownload = config.getAttribute(IRemoteTEConfigurationConstants.ATTR_SKIP_DOWNLOAD_TO_TARGET, false);
@@ -66,11 +112,11 @@ public class TERunLaunchDelegate extends AbstractCLaunchDelegate2 {
// 2. Run the binary
monitor.setTaskName(Messages.TEGdbAbstractLaunchDelegate_starting_debugger);
String arguments = getProgramArguments(config);
- String prelaunchCmd = config.getAttribute(IRemoteTEConfigurationConstants.ATTR_PRERUN_COMMANDS, ""); //$NON-NLS-1$
Map<String,String> env = config.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map<String,String>)null);
-
- TEHelper.launchCmd(peer, null, prelaunchCmd, null, new SubProgressMonitor(monitor, 2), new Callback());
- new TERunProcess(launch, remoteExePath, arguments, env, renderProcessLabel(exePath.toOSString()), peer, new SubProgressMonitor(monitor, 20));
+ if (remotePrerunScriptPath != null) {
+ remoteExePath = remotePrerunScriptPath.toString();
+ }
+ new TERunProcess(launch, remoteExePath, arguments, env, renderProcessLabel(exePath.toString()), peer, new SubProgressMonitor(monitor, 20));
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/nls/Messages.java
index ba2668d24..2941f1d7f 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/nls/Messages.java
@@ -57,6 +57,9 @@ public class Messages extends NLS {
public static String TEGdbAbstractLaunchDelegate_gdbserverFailedToStartErrorWithDetails;
public static String TEGdbAbstractLaunchDelegate_error_addressInUse;
public static String TEGdbAbstractLaunchDelegate_error_nosuchfileordirectory;
+ public static String TEGdbAbstractLaunchDelegate_prerunScriptCreationFailed;
+ public static String TEGdbAbstractLaunchDelegate_prerunScriptTransferFailed;
+ public static String TEGdbAbstractLaunchDelegate_error_prerunScriptTemplate;
public static String GdbPreferencePage_label;
public static String GdbPreferencePage_portList_label;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/nls/Messages.properties
index d33b26f85..b88fb4d06 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/nls/Messages.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/nls/Messages.properties
@@ -1,5 +1,5 @@
################################################################################
-# Copyright (c) 2006, 2015 Wind River Systems, Inc. and others.
+# Copyright (c) 2006, 2016 Wind River Systems, Inc. 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
@@ -57,6 +57,9 @@ TEGdbAbstractLaunchDelegate_error_nosuchfileordirectory=The specified gdbserver
Please check the launch configuration if you have configured the gdbserver name correctly.\n\nTo do so, open the launch configuration dialog, select the launch \
configuration and switch to the "Debugger" tab. On the "Debugger" tab, switch to the "Gdbserver Settings" and check the "Gdbserver name" setting.\n\n\
Also check that the gdbserver package is installed on the target.
+TEGdbAbstractLaunchDelegate_prerunScriptCreationFailed=Failed to create script with the 'Commands before launch' in ''{0}''. Possibly caused by: {1}
+TEGdbAbstractLaunchDelegate_prerunScriptTransferFailed=Failed to download script with 'Commands before launch' to target ''{0}''. Possibly caused by: {1}
+TEGdbAbstractLaunchDelegate_error_prerunScriptTemplate=Failed to read the 'Commands before launch' script template ''{0}''.
TCFPeerSelector_0=Connection:
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/utils/TEHelper.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/utils/TEHelper.java
index 126054e44..b4ccf2094 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/utils/TEHelper.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/utils/TEHelper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2015 Wind River Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2012, 2016 Wind River Systems, Inc. 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
@@ -11,9 +11,11 @@
package org.eclipse.tcf.te.tcf.launch.cdt.utils;
+import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
@@ -25,6 +27,7 @@ import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
@@ -42,7 +45,10 @@ import org.eclipse.tcf.te.runtime.concurrent.util.ExecutorsUtil;
import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback;
import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
+import org.eclipse.tcf.te.runtime.services.ServiceManager;
import org.eclipse.tcf.te.runtime.services.filetransfer.FileTransferItem;
+import org.eclipse.tcf.te.runtime.services.interfaces.IDelegateService;
+import org.eclipse.tcf.te.runtime.services.interfaces.IService;
import org.eclipse.tcf.te.runtime.services.interfaces.filetransfer.IFileTransferItem;
import org.eclipse.tcf.te.runtime.utils.Host;
import org.eclipse.tcf.te.runtime.utils.net.IPAddressUtil;
@@ -51,6 +57,7 @@ import org.eclipse.tcf.te.tcf.core.streams.StreamsDataReceiver;
import org.eclipse.tcf.te.tcf.core.streams.StreamsDataReceiver.Listener;
import org.eclipse.tcf.te.tcf.filesystem.core.services.FileTransferService;
import org.eclipse.tcf.te.tcf.launch.cdt.activator.Activator;
+import org.eclipse.tcf.te.tcf.launch.cdt.interfaces.IRemoteLaunchDelegate;
import org.eclipse.tcf.te.tcf.launch.cdt.interfaces.IRemoteTEConfigurationConstants;
import org.eclipse.tcf.te.tcf.launch.cdt.nls.Messages;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode;
@@ -63,6 +70,9 @@ import org.eclipse.tm.terminal.view.core.interfaces.constants.ITerminalsConnecto
public class TEHelper {
+ private static final String LOCAL_TEMPLATE_ROOT = "templates"; //$NON-NLS-1$
+ private static final String PRERUN_TEMPLATE_NAME = "prerun_template.sh"; //$NON-NLS-1$
+
public static void remoteFileTransfer(IPeer peer, String localFilePath, String remoteFilePath, SubProgressMonitor monitor) throws IOException {
// Copy the host side file to a temporary location first before copying to the target,
// if the file size of the files are the same. If the remote file system is NFS mounted
@@ -359,4 +369,51 @@ public class TEHelper {
return list;
}
+ /**
+ * @param peer
+ * @return the content of the script template used to run
+ * commands before the launch.
+ * @throws Exception
+ */
+ public static String getPrerunTemplateContent(IPeer peer) throws Exception {
+ File templateFile = null;
+ BufferedReader reader = null;
+ StringBuilder sb = new StringBuilder();
+ try {
+ IPath templateRoot = null;
+ IRemoteLaunchDelegate launchDelegate = null;
+ IPeerNode peerNode = getPeerNode(peer.getID());
+ IService[] services = ServiceManager.getInstance().getServices(peerNode, IDelegateService.class, false);
+ for (IService service : services) {
+ if (service instanceof IDelegateService) {
+ launchDelegate = ((IDelegateService)service).getDelegate(peerNode, IRemoteLaunchDelegate.class);
+ if (launchDelegate != null) { break; }
+ }
+ }
+ if (launchDelegate != null) {
+ templateRoot = launchDelegate.getPrerunTemplateRoot();
+ }
+ if (templateRoot != null) {
+ templateFile = new File(templateRoot.append(PRERUN_TEMPLATE_NAME).toOSString());
+ }
+ // Fallback - Use built-in template
+ if (templateFile == null || !templateFile.exists()) {
+ templateFile = new File(FileLocator.resolve(Activator.getDefault().getBundle().getEntry(LOCAL_TEMPLATE_ROOT + File.separator + PRERUN_TEMPLATE_NAME)).toURI());
+ }
+
+ reader = new BufferedReader(new FileReader(templateFile));
+ String line;
+ while ((line = reader.readLine()) != null) {
+ sb.append(line);
+ sb.append('\n');
+ }
+ } catch (Exception e) {
+ throw new Exception(NLS.bind(Messages.TEGdbAbstractLaunchDelegate_error_prerunScriptTemplate, templateFile), e);
+ } finally {
+ if (reader != null) {
+ try { reader.close(); } catch (IOException e) { /* Ignored on purpose. */ }
+ }
+ }
+ return sb.toString();
+ }
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/templates/prerun_template.sh b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/templates/prerun_template.sh
new file mode 100644
index 000000000..b1b82884f
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/templates/prerun_template.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+# Commands
+{0}
+
+# Launch app
+{1}
+
+# Self-destruction
+rm -f "$0"

Back to the top