[Esbox-commits] r835 - in trunk/device: org.maemo.esbox.device.launch/src/org/maemo/esbox/device/launch org.maemo.esbox.device.launch.rse/META-INF org.maemo.esbox.device.launch.rse/src/org/maemo/esbox/device/launch/rse org.maemo.esbox.device.launch.rse/src/org/maemo/esbox/device/launch/rse/ui
lwang at garage.maemo.org
lwang at garage.maemo.org
Tue Oct 7 02:45:30 EEST 2008
Author: lwang
Date: 2008-10-07 02:45:30 +0300 (Tue, 07 Oct 2008)
New Revision: 835
Modified:
trunk/device/org.maemo.esbox.device.launch.rse/META-INF/MANIFEST.MF
trunk/device/org.maemo.esbox.device.launch.rse/src/org/maemo/esbox/device/launch/rse/RSELaunchProtocol.java
trunk/device/org.maemo.esbox.device.launch.rse/src/org/maemo/esbox/device/launch/rse/RSELaunchProtocolType.java
trunk/device/org.maemo.esbox.device.launch.rse/src/org/maemo/esbox/device/launch/rse/ui/RSEConnectionConfigPage.java
trunk/device/org.maemo.esbox.device.launch/src/org/maemo/esbox/device/launch/SSHLaunchProtocol.java
Log:
Implemented RSELaunchProtocol, utilizing RSE file copy capability and our SSH launcher.
Modified: trunk/device/org.maemo.esbox.device.launch/src/org/maemo/esbox/device/launch/SSHLaunchProtocol.java
===================================================================
--- trunk/device/org.maemo.esbox.device.launch/src/org/maemo/esbox/device/launch/SSHLaunchProtocol.java 2008-10-06 14:28:07 UTC (rev 834)
+++ trunk/device/org.maemo.esbox.device.launch/src/org/maemo/esbox/device/launch/SSHLaunchProtocol.java 2008-10-06 23:45:30 UTC (rev 835)
@@ -38,15 +38,15 @@
super(configuration);
String userName = ESboxLaunchUtils.getSDKTarget(configuration).getPreferenceValue(DevicePreferenceConstants.SSH_USERNAME);
- init(userName);
+ machine = initMachine(userName);
}
/**
- * Initialize the protocol for the given user
+ * Create SSHMachine for the given user and underlying launch configuration.
* @param userName
*/
- private void init(String userName) throws CoreException {
- machine = SSHLaunchProtocolType.createSSHMachineForLaunchConfiguration(
+ protected ISSHMachine initMachine(String userName) throws CoreException {
+ return SSHLaunchProtocolType.createSSHMachineForLaunchConfiguration(
getLaunchConfiguration(), userName);
}
@@ -149,6 +149,6 @@
* @see org.maemo.esbox.debug.ILaunchProtocol#requireRunAsRoot()
*/
public void requireRunAsRoot() throws CoreException {
- init("root");
+ machine = initMachine("root");
}
}
Modified: trunk/device/org.maemo.esbox.device.launch.rse/META-INF/MANIFEST.MF
===================================================================
--- trunk/device/org.maemo.esbox.device.launch.rse/META-INF/MANIFEST.MF 2008-10-06 14:28:07 UTC (rev 834)
+++ trunk/device/org.maemo.esbox.device.launch.rse/META-INF/MANIFEST.MF 2008-10-06 23:45:30 UTC (rev 835)
@@ -5,17 +5,16 @@
Bundle-Version: 1.5.0.qualifier
Bundle-Activator: org.maemo.esbox.internal.device.launch.rse.Activator
Bundle-Vendor: Nokia
-Require-Bundle: org.eclipse.ui,
- org.eclipse.core.runtime,
- org.eclipse.debug.core;bundle-version="3.4.0",
+Require-Bundle: org.eclipse.core.runtime,
org.eclipse.debug.ui;bundle-version="3.4.0",
org.eclipse.rse.core;bundle-version="3.0.1",
- org.eclipse.rse.subsystems.shells.core;bundle-version="3.0.0",
org.eclipse.rse.subsystems.files.core;bundle-version="3.0.1",
org.eclipse.rse.services;bundle-version="3.0.1",
org.maemo.esbox.launch;bundle-version="1.5.0",
org.maemo.esbox.core;bundle-version="1.5.0",
org.maemo.esbox.ui;bundle-version="1.5.0",
+ org.maemo.esbox.ssh;bundle-version="1.5.0",
+ org.maemo.esbox.device.core;bundle-version="1.5.0",
org.maemo.esbox.device.launch;bundle-version="1.5.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
Modified: trunk/device/org.maemo.esbox.device.launch.rse/src/org/maemo/esbox/device/launch/rse/RSELaunchProtocol.java
===================================================================
--- trunk/device/org.maemo.esbox.device.launch.rse/src/org/maemo/esbox/device/launch/rse/RSELaunchProtocol.java 2008-10-06 14:28:07 UTC (rev 834)
+++ trunk/device/org.maemo.esbox.device.launch.rse/src/org/maemo/esbox/device/launch/rse/RSELaunchProtocol.java 2008-10-06 23:45:30 UTC (rev 835)
@@ -6,11 +6,12 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Ling Wang (Nokia) - initial version. Sep 10, 2008
+ * Ling Wang (Nokia) - initial version. Sep, 2008
*******************************************************************************/
package org.maemo.esbox.device.launch.rse;
+import java.text.MessageFormat;
import java.util.List;
import java.util.Map;
@@ -18,79 +19,190 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.rse.core.model.IHost;
-import org.maemo.esbox.core.machine.IMachine;
-import org.maemo.esbox.launch.AbstractLaunchProtocol;
+import org.eclipse.rse.core.subsystems.IConnectorService;
+import org.eclipse.rse.core.subsystems.ISubSystem;
+import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
+import org.eclipse.rse.services.files.IFilePermissionsService;
+import org.eclipse.rse.services.files.IFileService;
+import org.eclipse.rse.services.files.IHostFilePermissions;
+import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
+import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
+import org.maemo.esbox.core.DevicePreferenceConstants;
+import org.maemo.esbox.core.sdk.ISDKTarget;
+import org.maemo.esbox.device.core.DeviceMachineFactory;
+import org.maemo.esbox.device.launch.SSHLaunchProtocol;
+import org.maemo.esbox.internal.device.launch.rse.Activator;
+import org.maemo.esbox.launch.ESboxLaunchUtils;
+import org.maemo.esbox.launch.IESboxLaunchConfigurationConstants;
+import org.maemo.esbox.ssh.ISSHMachine;
+import org.maemo.esbox.ssh.SSHConfiguration;
/**
* @author LWang
*
*/
-public class RSELaunchProtocol extends AbstractLaunchProtocol {
+public class RSELaunchProtocol extends SSHLaunchProtocol {
private IHost fRSEHost;
/**
* @param config
+ * @throws CoreException
*/
- public RSELaunchProtocol(ILaunchConfiguration config, IHost host) {
+ public RSELaunchProtocol(ILaunchConfiguration config) throws CoreException {
super(config);
- fRSEHost = host;
}
-
- /* (non-Javadoc)
- * @see org.maemo.esbox.launch.ILaunchProtocol#convertHostToTargetPath(org.eclipse.core.runtime.IPath)
- */
- public IPath convertHostToTargetPath(IPath hostPath) {
- // TODO Auto-generated method stub
- return null;
+
+ protected ISSHMachine initMachine(String userName) throws CoreException {
+ fRSEHost = RSELaunchProtocolType.getRSEConnection(getLaunchConfiguration());
+
+ SSHConfiguration sshConfiguration = createSSHConfigurationFromRSEConnection(fRSEHost, userName);
+
+ return DeviceMachineFactory.createSSHMachine("Device over RSE", sshConfiguration, null);
}
- /* (non-Javadoc)
- * @see org.maemo.esbox.launch.ILaunchProtocol#downloadFiles(org.eclipse.core.runtime.IProgressMonitor)
- */
- public IStatus downloadFiles(IProgressMonitor monitor) {
- // TODO Auto-generated method stub
- return null;
+ private SSHConfiguration createSSHConfigurationFromRSEConnection(
+ IHost host, String userName) throws CoreException {
+ SSHConfiguration sshConfiguration = new SSHConfiguration();
+
+ // Get target IP address from the IHost.
+ sshConfiguration.setTargetIPAddress(host.getHostName());
+
+ // The "useName" is from ESbox SSH preference panel or special caller requireRunAsRoot().
+ //
+ // Should we use name from RSE ? no. The default RSE user name is host
+ // user name, and the target one may not be available until the first attempt of
+ // connection. So neither apply.
+ sshConfiguration.setUserName(userName);
+
+ fRSEHost.setDefaultUserId(userName);
+
+
+ // Find SSH port number from RSE if we can.
+ //
+ int sshPort = Integer.parseInt(IESboxLaunchConfigurationConstants.DEFAULT_SSH_PORT_NUMBER);
+
+ // Find the SSH connector for the IHost
+ IConnectorService[] connectors = host.getConnectorServices();
+ IConnectorService sshConnector = null;
+ for (IConnectorService c : connectors)
+ // I don't see yet a good way to check if the connectorService is SSH.
+ if (c.getName().contains("SSH")) {
+ sshConnector = c;
+ break;
+ }
+
+ if (sshConnector != null)
+ if (sshConnector.getPort() > 0)
+ sshPort = sshConnector.getPort();
+
+ sshConfiguration.setTargetPort(sshPort);
+
+ // TODO: I've not seen RSE API for getting the connection timeout. So just use ESbox preference.
+ ISDKTarget sdkTarget = ESboxLaunchUtils.getSDKTarget(getLaunchConfiguration());
+ String connectionTimeout = sdkTarget.getPreferenceValue(DevicePreferenceConstants.SSH_CONNECTION_TIMEOUT);
+ sshConfiguration.setConnectionTimeout(Integer.parseInt(connectionTimeout));
+
+ // XXX: set user password if possible
+
+ return sshConfiguration;
}
-
- /* (non-Javadoc)
- * @see org.maemo.esbox.launch.ILaunchProtocol#downloadFiles(java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
- */
+
+ @Override
public IStatus downloadFiles(Map<IPath, List<IPath>> targetPathToHostFiles,
IProgressMonitor monitor) {
- // TODO Auto-generated method stub
- return null;
- }
+// return super.downloadFiles(targetPathToHostFiles, monitor);
+
+ ISubSystem[] subs = fRSEHost.getSubSystems();
+
+ IFileServiceSubSystem fss = null;
+ for (ISubSystem s : subs)
+ if (s instanceof IFileServiceSubSystem)
+ fss = (IFileServiceSubSystem)s;
+
+ if (fss == null)
+ return new Status(IStatus.ERROR, Activator.getUniqueIdentifier(),
+ "No file service is specified in the RSE connection: " + fRSEHost.getAliasName());
- /* (non-Javadoc)
- * @see org.maemo.esbox.launch.ILaunchProtocol#getFileLocationOnTarget(org.eclipse.core.runtime.IPath)
- */
- public IPath getFileLocationOnTarget(IPath filePath) {
- // TODO Auto-generated method stub
- return null;
- }
+ if (! fss.isConnected())
+ try {
+ fss.connect(monitor, false);
+ } catch (Exception e1) {
+ return new Status(IStatus.ERROR, Activator.getUniqueIdentifier(),
+ "The file service of the RSE connection fails to connect to target.");
+ }
+
+ IFileService fileService = fss.getFileService();
+ IFilePermissionsService fps = null;
+ if (fileService instanceof IFilePermissionsService)
+ fps = (IFilePermissionsService)fileService;
+
+ if (monitor == null)
+ monitor = new NullProgressMonitor();
- /* (non-Javadoc)
- * @see org.maemo.esbox.launch.ILaunchProtocol#getTargetFoldersForHostFileMappings()
- */
- public Map<IPath, List<IPath>> getTargetFoldersForHostFileMappings() {
- // TODO Auto-generated method stub
- return null;
- }
+ // Count total number of files
+ int total = 0;
+ for (Map.Entry<IPath, List<IPath>> p : targetPathToHostFiles.entrySet())
+ total += p.getValue().size();
- /* (non-Javadoc)
- * @see org.maemo.esbox.launch.ILaunchProtocol#requireRunAsRoot()
- */
- public void requireRunAsRoot() throws CoreException {
- // TODO Auto-generated method stub
+ monitor.beginTask("", total*2 + 1);
+
+ for (Map.Entry<IPath, List<IPath>> pathEntry : targetPathToHostFiles.entrySet()) {
- }
+ List<IPath> hostFilePaths = pathEntry.getValue();
- public IMachine getDeviceMachine() {
- // TODO Auto-generated method stub
- return null;
+ String targetPath = pathEntry.getKey().addTrailingSeparator().toPortableString();
+
+ for (IPath hostFilePath : hostFilePaths) {
+ String hostFile = hostFilePath.toPortableString();
+
+ String msg = MessageFormat.format("Download ''{0}'' to ''{1}''", hostFile, targetPath);
+ IProgressMonitor subMon = null;
+ if (monitor != null) {
+ monitor.subTask(msg);
+ subMon = new SubProgressMonitor(monitor, 2);
+ subMon.beginTask("", 100);
+ }
+
+ // TODO: check timestamps
+
+ try {
+ // full path with name is required.
+ String targetFile = targetPath + hostFilePath.lastSegment();
+
+ fss.upload(hostFile, null, targetFile, null, subMon);
+ subMon.worked(50);
+
+ // Set the file to be executable.
+ // Better check if the host file is executable first, but
+ // there is no simple way to do that in Java.
+ //
+ if (fps != null) {
+ IRemoteFile rfile = fss.getRemoteFileObject(targetFile, subMon);
+ subMon.worked(25);
+ IHostFilePermissions permissions = rfile.getPermissions();
+ if (! permissions.getPermission(IHostFilePermissions.PERM_USER_EXECUTE)) {
+ permissions.setPermission(IHostFilePermissions.PERM_USER_EXECUTE, true);
+ fps.setFilePermissions(rfile.getHostFile(), permissions, subMon);
+ }
+ subMon.worked(25);
+ }
+ } catch (SystemMessageException e) {
+ return new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), msg + " failed", e);
+ }
+
+ if (monitor.isCanceled())
+ return Status.CANCEL_STATUS;
+ }
+ }
+
+ monitor.done();
+
+ return Status.OK_STATUS;
}
-
}
Modified: trunk/device/org.maemo.esbox.device.launch.rse/src/org/maemo/esbox/device/launch/rse/RSELaunchProtocolType.java
===================================================================
--- trunk/device/org.maemo.esbox.device.launch.rse/src/org/maemo/esbox/device/launch/rse/RSELaunchProtocolType.java 2008-10-06 14:28:07 UTC (rev 834)
+++ trunk/device/org.maemo.esbox.device.launch.rse/src/org/maemo/esbox/device/launch/rse/RSELaunchProtocolType.java 2008-10-06 23:45:30 UTC (rev 835)
@@ -41,7 +41,7 @@
*
* @return
*/
- static public String[] getRSEConnectionIDs() {
+ static public String[] getAllRSEConnectionIDs() {
IHost[] hosts = SystemStartHere.getConnections();
String[] names = new String[hosts.length];
@@ -58,7 +58,7 @@
* @param configuration
* @return - connection ID or null if not available yet.
*/
- static public String getRSEConnection(ILaunchConfiguration configuration) {
+ static public String getRSEConnectionID(ILaunchConfiguration configuration) {
String rseConnectionID = null;
try {
rseConnectionID = configuration.getAttribute(ATTR_RSE_CONNECTION_ID, (String)null);
@@ -69,28 +69,25 @@
}
/**
- * Set RSE connection for the given launch configuration.
+ * Retrieve RSE connection (host) from the given launch configuration.
*
* @param configuration
+ * @return - IHost instance.
+ * @throws CoreException - on error, e.g. the connection in configuration is no longer
+ * available.
*/
- static public void setRSEConnection(ILaunchConfigurationWorkingCopy configuration, String rseConnection) {
- configuration.setAttribute(ATTR_RSE_CONNECTION_ID, rseConnection);
- }
-
- public RSELaunchProtocolType() {
- }
-
- public ILaunchProtocol getLaunchProtocol(ILaunchConfiguration configuration)
- throws CoreException {
-
- String rseConnectionID = getRSEConnection(configuration);
-
+ static public IHost getRSEConnection(ILaunchConfiguration configuration) throws CoreException {
+ String rseConnectionID = getRSEConnectionID(configuration);
if (rseConnectionID == null)
throw new CoreException(new Status(IStatus.ERROR, Activator.getUniqueIdentifier(),
- "No RSE Connection found in the launch configuration:" + configuration.getName()));
+ "No RSE Connection found in the launch configuration:" + configuration.getName()));
- IHost[] hosts = SystemStartHere.getConnections();
-
+ IHost[] hosts = SystemStartHere.getConnections();
+ for (IHost h : hosts) {
+ if (h.getAliasName().equals(rseConnectionID))
+ return h;
+ }
+
IHost foundConnection = null;
for (IHost h : hosts) {
if (h.getAliasName().equals(rseConnectionID)) {
@@ -98,14 +95,33 @@
break;
}
}
- if (rseConnectionID == null) {
+
+ if (foundConnection == null) {
String msg = MessageFormat.format(
- "The RSE connection ''{0}'' specified in the launch configuration ''{1}'' does not exist any more.",
+ "The RSE connection ''{0}'' specified in the launch configuration ''{1}'' does not " +
+ "exist any more. It's ususally because it's been deleted.",
rseConnectionID, configuration.getName());
throw new CoreException(new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), msg));
}
+
+ return foundConnection;
+ }
+
+ /**
+ * Set RSE connection for the given launch configuration.
+ *
+ * @param configuration
+ */
+ static public void setRSEConnection(ILaunchConfigurationWorkingCopy configuration, String rseConnection) {
+ configuration.setAttribute(ATTR_RSE_CONNECTION_ID, rseConnection);
+ }
+
+ public RSELaunchProtocolType() {
+ }
- return new RSELaunchProtocol(configuration, foundConnection);
+ public ILaunchProtocol getLaunchProtocol(ILaunchConfiguration configuration)
+ throws CoreException {
+ return new RSELaunchProtocol(configuration);
}
public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
Modified: trunk/device/org.maemo.esbox.device.launch.rse/src/org/maemo/esbox/device/launch/rse/ui/RSEConnectionConfigPage.java
===================================================================
--- trunk/device/org.maemo.esbox.device.launch.rse/src/org/maemo/esbox/device/launch/rse/ui/RSEConnectionConfigPage.java 2008-10-06 14:28:07 UTC (rev 834)
+++ trunk/device/org.maemo.esbox.device.launch.rse/src/org/maemo/esbox/device/launch/rse/ui/RSEConnectionConfigPage.java 2008-10-06 23:45:30 UTC (rev 835)
@@ -46,7 +46,7 @@
// We keep a record of existing RSE connections.
// XXX: what if user modified the RSE connections during or after the
// launch configuration is created ?
- fConnectionNames = RSELaunchProtocolType.getRSEConnectionIDs();
+ fConnectionNames = RSELaunchProtocolType.getAllRSEConnectionIDs();
fConnectionCombo.setItems(fConnectionNames);
fConnectionCombo.doFillIntoGrid(page, 2);
@@ -68,7 +68,7 @@
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
*/
public void initializeFrom(ILaunchConfiguration configuration) {
- String id = RSELaunchProtocolType.getRSEConnection(configuration);
+ String id = RSELaunchProtocolType.getRSEConnectionID(configuration);
int selection = -1; // default, nothing selected in the list.
@@ -115,7 +115,7 @@
setErrorMessage(null);
setMessage(null);
- String id = RSELaunchProtocolType.getRSEConnection(configuration);
+ String id = RSELaunchProtocolType.getRSEConnectionID(configuration);
// the connection stored in the configuration does not exist any more.
String msg = null;
More information about the Esbox-commits
mailing list