From d359414881d9cb8e23f550329e00256d677af689 Mon Sep 17 00:00:00 2001 From: Anna Dushistova Date: Wed, 25 Jan 2012 13:46:39 +0000 Subject: [PATCH] [331213] Checked in additional refactoring for scp. --- .../services/ssh/SshServiceResources.java | 23 ++- .../ssh/SshServiceResources.properties | 14 +- .../services/ssh/files/SftpFileService.java | 18 +-- .../ScpFileUtils.java => SshFileUtils.java} | 29 +++- .../services/ssh/files/scp/ScpFileAttr.java | 10 +- .../ssh/files/scp/ScpFileService.java | 131 +++++++++--------- .../subsystems/files/scp/ScpRemoteFile.java | 11 +- 7 files changed, 135 insertions(+), 101 deletions(-) rename rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/{scp/ScpFileUtils.java => SshFileUtils.java} (78%) diff --git a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/SshServiceResources.java b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/SshServiceResources.java index 93200bf273f..5b2ce266bc8 100644 --- a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/SshServiceResources.java +++ b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/SshServiceResources.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2009 Wind River Systems, Inc. + * Copyright (c) 2006, 2012 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 @@ -10,6 +10,7 @@ * Yu-Fen Kuo (MontaVista) - [170910] Integrate the TM Terminal View with RSE * Anna Dushistova (MontaVista) - [261478] Remove SshShellService, SshHostShell (or deprecate and schedule for removal in 3.2) * Martin Oberhuber (Wind River) - [227135] Cryptic exception when sftp-server is missing + * Anna Dushistova (MontaVista) - [331213] [scp] Provide UI-less scp IFileService in org.eclipse.rse.services.ssh *******************************************************************************/ package org.eclipse.rse.internal.services.ssh; @@ -19,6 +20,26 @@ import org.eclipse.osgi.util.NLS; public class SshServiceResources extends NLS { private static final String BUNDLE_NAME = "org.eclipse.rse.internal.services.ssh.SshServiceResources"; //$NON-NLS-1$ + public static String ScpFileService_AttributesError; + + public static String ScpFileService_Description; + + public static String ScpFileService_DownloadFileTaskName; + + public static String ScpFileService_LastModifiedNotSupportedError; + + public static String ScpFileService_Name; + + public static String ScpFileService_ReadAckError; + + public static String ScpFileService_UploadFileTaskName; + + public static String ScpFileService_DownloadException; + + public static String ScpFileService_DownloadException1; + + public static String ScpFileService_UploadException; + public static String SftpFileService_Name; public static String SftpFileService_Description; public static String SftpFileService_Error_JschSessionLost; diff --git a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/SshServiceResources.properties b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/SshServiceResources.properties index 2f7a35c168d..41e11c97136 100644 --- a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/SshServiceResources.properties +++ b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/SshServiceResources.properties @@ -1,5 +1,5 @@ ################################################################################ -# Copyright (c) 2006, 2009 Wind River Systems, Inc. and others. +# Copyright (c) 2006, 2012 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 @@ -10,11 +10,23 @@ # Yu-Fen Kuo (MontaVista) - [170910] Integrate the TM Terminal View with RSE # Anna Dushistova (MontaVista) - [261478] Remove SshShellService, SshHostShell (or deprecate and schedule for removal in 3.2) # Martin Oberhuber (Wind River) - [227135] Cryptic exception when sftp-server is missing +# Anna Dushistova (MontaVista) - [331213] [scp] Provide UI-less scp IFileService in org.eclipse.rse.services.ssh ################################################################################ # NLS_MESSAGEFORMAT_VAR # NLS_ENCODING=UTF-8 +ScpFileService_AttributesError=Can't get attribute of file +ScpFileService_Description=SSH/SCP File Service can be used to connect to embedded sshd implementations, which often lacks sftp service +ScpFileService_DownloadFileTaskName=Downloading file +ScpFileService_LastModifiedNotSupportedError=setLastModified() not supported +ScpFileService_Name=SCP File Service +ScpFileService_ReadAckError=upload: wrong Ack\! Last error: +ScpFileService_UploadFileTaskName=Uploading file +ScpFileService_DownloadException=Error happened while downloading {0}: {1} +ScpFileService_DownloadException1=Error happened while downloading {0}: Can't download file of type {1} +ScpFileService_UploadException=Error happened while uploading {0}: {1} + SshPlugin_Unexpected_Exception=Unexpected {0}: {1} SftpFileService_Name=Ssh / Sftp File Service diff --git a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpFileService.java b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpFileService.java index 73f83b358d0..e5153ee2301 100644 --- a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpFileService.java +++ b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpFileService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2012 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 @@ -39,9 +39,10 @@ * David McKnight (IBM) - [271244] [sftp files] "My Home" filter not working * David McKnight (IBM) - [272882] [api] Handle exceptions in IService.initService() * Martin Oberhuber (Wind River) - [274568] Dont use SftpMonitor for Streams transfer - * Patrick Tassé (Ericsson) - [285226] Empty directory shown as an error message + * Patrick Tass� (Ericsson) - [285226] Empty directory shown as an error message * Martin Oberhuber (Wind River) - [286129][api] RemoteFileException(String) violates API contract * Martin Tauber - [256581][performance] Re-use Sftp channels + * Anna Dushistova (MontaVista) - [331213] [scp] Provide UI-less scp IFileService in org.eclipse.rse.services.ssh *******************************************************************************/ package org.eclipse.rse.internal.services.ssh.files; @@ -607,18 +608,7 @@ public class SftpFileService extends AbstractFileService implements ISshService, * */ protected String concat(String parentDir, String fileName) { - // See also {@link SftpHostFile#getAbsolutePath()} - if (parentDir == null || parentDir.length() == 0) { - // Looking at a Root - return fileName; - } - StringBuffer path = new StringBuffer(parentDir); - if (!parentDir.endsWith("/")) //$NON-NLS-1$ - { - path.append('/'); - } - path.append(fileName); - return path.toString(); + return SshFileUtils.concat(parentDir, fileName); } public IHostFile getFile(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException diff --git a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/scp/ScpFileUtils.java b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SshFileUtils.java similarity index 78% rename from rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/scp/ScpFileUtils.java rename to rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SshFileUtils.java index 52e7b3a345e..151b9587a28 100644 --- a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/scp/ScpFileUtils.java +++ b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SshFileUtils.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Mentor Graphics Corporation and others. + * Copyright (c) 2009, 2012 Mentor Graphics Corporation 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 @@ -8,19 +8,24 @@ * Contributors: * Nikita Shulga - initial API and implementation * Anna Dushistova (Mentor Graphics) - [331213][scp] Provide UI-less scp IFileService in org.eclipse.rse.services.ssh + * Anna Dushistova (MontaVista) - [331213][scp] Provide UI-less scp IFileService in org.eclipse.rse.services.ssh *******************************************************************************/ -package org.eclipse.rse.internal.services.ssh.files.scp; +package org.eclipse.rse.internal.services.ssh.files; import java.io.IOException; import java.io.InputStream; +import org.eclipse.core.runtime.IStatus; + +import org.eclipse.rse.internal.services.ssh.Activator; +import org.eclipse.rse.services.clientserver.messages.SimpleSystemMessage; import org.eclipse.rse.services.clientserver.messages.SystemMessageException; import com.jcraft.jsch.ChannelExec; import com.jcraft.jsch.Session; -public class ScpFileUtils { +public class SshFileUtils { public static final String EOL_STRING = "\n"; //$NON-NLS-1$ public static final String TARGET_SEPARATOR = "/"; //$NON-NLS-1$ public static final String EXEC_CHANNEL = "exec"; //$NON-NLS-1$ @@ -33,10 +38,10 @@ public class ScpFileUtils { * Concatenate a parent directory with a file name to form a new proper path * name. * - * This method was cloned from + * This method was moved from * org.eclipse.rse.services.ssh / SftpFileService#concat() */ - protected static String concat(String parentDir, String fileName) { + public static String concat(String parentDir, String fileName) { // See also {@link SftpHostFile#getAbsolutePath()} if (parentDir == null || parentDir.length() == 0) { // Looking at a Root @@ -83,7 +88,7 @@ public class ScpFileUtils { try { rc = execCommand(session, command); } catch (Exception e) { - ScpFileService.throwSystemException(e); + throwSystemException(e); } return rc; } @@ -104,7 +109,7 @@ public class ScpFileUtils { * file name * @return escaped concatenated path to the file */ - protected static String concatEscape(String parentDir, String fileName) { + public static String concatEscape(String parentDir, String fileName) { return escapePath(concat(parentDir, fileName)); } @@ -133,4 +138,14 @@ public class ScpFileUtils { return rc; } + public static void throwSystemException(Exception e) + throws SystemMessageException { + Activator.warn("SshFileUtils.throwSystemException", e); //$NON-NLS-1$ + + if (e instanceof SystemMessageException) + throw (SystemMessageException) e; + throw new SystemMessageException(new SimpleSystemMessage( + Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e)); + } + } diff --git a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/scp/ScpFileAttr.java b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/scp/ScpFileAttr.java index d9a2b218265..471d6c76c8d 100644 --- a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/scp/ScpFileAttr.java +++ b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/scp/ScpFileAttr.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 Mentor Graphics Corporation and others. + * Copyright (c) 2009, 2012 Mentor Graphics Corporation 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 @@ -9,6 +9,7 @@ * Nikita Shulga - initial API and implementation * Nikita Shulga (Mentor Graphics) - [331109] Added long-iso time format support * Anna Dushistova (Mentor Graphics) - [331213][scp] Provide UI-less scp IFileService in org.eclipse.rse.services.ssh + * Anna Dushistova (MontaVista) - [331213] [scp] Provide UI-less scp IFileService in org.eclipse.rse.services.ssh *******************************************************************************/ package org.eclipse.rse.internal.services.ssh.files.scp; @@ -21,6 +22,7 @@ import java.util.Stack; import java.util.regex.Pattern; import org.eclipse.rse.internal.services.ssh.Activator; +import org.eclipse.rse.internal.services.ssh.files.SshFileUtils; import org.eclipse.rse.services.clientserver.messages.SystemMessageException; import org.eclipse.rse.services.files.HostFilePermissions; import org.eclipse.rse.services.files.IHostFilePermissions; @@ -133,7 +135,7 @@ public class ScpFileAttr { SplitAux(); } catch (Exception e) { Activator.warn( - "ScpFileAttr:Exception occured while splitting string " + "ScpFileAttr:Exception occured while splitting string " //$NON-NLS-1$ + lsString, e); } } @@ -260,8 +262,8 @@ public class ScpFileAttr { public static ScpFileAttr getAttr(Session sess, String path) throws SystemMessageException { - String attr = ScpFileUtils.execCommandSafe(sess, "ls -land " //$NON-NLS-1$ - + ScpFileUtils.escapePath(path)); + String attr = SshFileUtils.execCommandSafe(sess, "ls -land " //$NON-NLS-1$ + + SshFileUtils.escapePath(path)); if (attr == null || attr.length() < 9) return null; return new ScpFileAttr(attr); diff --git a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/scp/ScpFileService.java b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/scp/ScpFileService.java index 75a40b35680..4ea744ae593 100644 --- a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/scp/ScpFileService.java +++ b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/scp/ScpFileService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 Mentor Graphics Corporation and others. + * Copyright (c) 2009, 2012 Mentor Graphics Corporation 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 @@ -10,6 +10,7 @@ * Anna Dushistova (Mentor Graphics) - [331213][scp] Provide UI-less scp IFileService in org.eclipse.rse.services.ssh * Anna Dushistova (Mentor Graphics) - [331249][scp] incorrect home while logging in as root * Simon Bernard (Sierra Wireless) - [349947][scp] with scp IRemoteFile.exist() returns always true + * Anna Dushistova (MontaVista) - [331213] [scp] Provide UI-less scp IFileService in org.eclipse.rse.services.ssh *******************************************************************************/ package org.eclipse.rse.internal.services.ssh.files.scp; @@ -24,9 +25,12 @@ import java.util.List; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.osgi.util.NLS; import org.eclipse.rse.internal.services.ssh.Activator; import org.eclipse.rse.internal.services.ssh.ISshSessionProvider; +import org.eclipse.rse.internal.services.ssh.SshServiceResources; +import org.eclipse.rse.internal.services.ssh.files.SshFileUtils; import org.eclipse.rse.internal.services.ssh.files.SftpHostFile; import org.eclipse.rse.services.clientserver.FileTypeMatcher; import org.eclipse.rse.services.clientserver.IMatcher; @@ -67,16 +71,6 @@ public class ScpFileService extends AbstractFileService implements Activator.PLUGIN_ID, IStatus.ERROR, msg)); } - protected static void throwSystemException(Exception e) - throws SystemMessageException { - Activator.warn("ScpFileServie.throwSystemExcpeption", e); - - if (e instanceof SystemMessageException) - throw (SystemMessageException) e; - throw new SystemMessageException(new SimpleSystemMessage( - Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e)); - } - protected IHostFile[] internalFetch(String parentPath, String fileFilter, int fileType, IProgressMonitor monitor) throws SystemMessageException { @@ -93,17 +87,17 @@ public class ScpFileService extends AbstractFileService implements List results = new ArrayList(); Session sess = getSession(); - String cmd = "ls -lAn " + ScpFileUtils.escapePath(parentPath); //$NON-NLS-1$ + String cmd = "ls -lAn " + SshFileUtils.escapePath(parentPath); //$NON-NLS-1$ - String rc = ScpFileUtils.execCommandSafe(sess, cmd); - String[] lsStrings = rc.split(ScpFileUtils.EOL_STRING); + String rc = SshFileUtils.execCommandSafe(sess, cmd); + String[] lsStrings = rc.split(SshFileUtils.EOL_STRING); for (int i=0;i