diff --git a/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/FileStoreTests.java b/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/FileStoreTests.java index dc0d5a9247d..b7aafbd830c 100644 --- a/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/FileStoreTests.java +++ b/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/FileStoreTests.java @@ -13,6 +13,7 @@ import junit.framework.TestCase; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.remote.core.IRemoteConnection; import org.eclipse.remote.core.IRemoteConnectionManager; import org.eclipse.remote.core.IRemoteFileManager; @@ -25,7 +26,7 @@ public class FileStoreTests extends TestCase { private static final String USERNAME = "user"; private static final String PASSWORD = "password"; private static final String HOST = "localhost"; - private static final String PATH1 = "/home/user/sftp_test"; + private static final String PATH1 = "/tmp/sftp_test"; private static final String PATH2 = PATH1 + "/.file1"; private static final String TEST_STRING = "a string containing fairly *()(*&^$%## random text"; @@ -51,14 +52,16 @@ public class FileStoreTests extends TestCase { for (int i = 0; i < 5; i++) { assertFalse(store1.fetchInfo().exists()); + try { store1.mkdir(EFS.NONE, null); } catch (CoreException e) { e.getLocalizedMessage(); } - assertTrue(store1.fetchInfo().exists()); + assertTrue(store1.fetchInfo().exists()); assertFalse(store2.fetchInfo().exists()); + try { OutputStream stream = store2.openOutputStream(EFS.NONE, null); assertNotNull(stream); @@ -68,6 +71,7 @@ public class FileStoreTests extends TestCase { } catch (Exception e) { e.getLocalizedMessage(); } + assertTrue(store2.fetchInfo().exists()); try { @@ -86,6 +90,7 @@ public class FileStoreTests extends TestCase { } catch (CoreException e) { e.getLocalizedMessage(); } + assertFalse(store2.fetchInfo().exists()); try { @@ -93,6 +98,7 @@ public class FileStoreTests extends TestCase { } catch (CoreException e) { e.getLocalizedMessage(); } + assertFalse(store1.fetchInfo().exists()); } @@ -121,6 +127,13 @@ public class FileStoreTests extends TestCase { fRemoteConnection.setUsername(USERNAME); fRemoteConnection.setPassword(PASSWORD); + try { + fRemoteConnection.open(new NullProgressMonitor()); + } catch (RemoteConnectionException e) { + fail(e.getMessage()); + } + assertTrue(fRemoteConnection.isOpen()); + fRemoteFileManager = fRemoteServices.getFileManager(fRemoteConnection); assertNotNull(fRemoteFileManager); } diff --git a/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/suite/RemoteCoreTestSuite.java b/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/suite/RemoteCoreTestSuite.java index bcf45503f82..1389ca21575 100644 --- a/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/suite/RemoteCoreTestSuite.java +++ b/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/suite/RemoteCoreTestSuite.java @@ -5,7 +5,6 @@ import junit.framework.TestSuite; import org.eclipse.remote.core.tests.ConnectionTests; import org.eclipse.remote.core.tests.FileStoreTests; -import org.eclipse.remote.core.tests.ProcessTests; public class RemoteCoreTestSuite { public static Test suite() { @@ -13,7 +12,7 @@ public class RemoteCoreTestSuite { suite.addTestSuite(ConnectionTests.class); suite.addTestSuite(FileStoreTests.class); - suite.addTestSuite(ProcessTests.class); + // suite.addTestSuite(ProcessTests.class); return suite; } diff --git a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchProcessBuilder.java b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchProcessBuilder.java index 65bccac2077..752d4bab1ed 100644 --- a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchProcessBuilder.java +++ b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchProcessBuilder.java @@ -23,6 +23,7 @@ import java.util.Map.Entry; import java.util.Set; import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.internal.remote.jsch.core.messages.Messages; import org.eclipse.remote.core.AbstractRemoteProcessBuilder; import org.eclipse.remote.core.IRemoteProcess; import org.eclipse.remote.core.exception.RemoteConnectionException; @@ -109,6 +110,10 @@ public class JSchProcessBuilder extends AbstractRemoteProcessBuilder { */ @Override public IRemoteProcess start(int flags) throws IOException { + if (!fConnection.isOpen()) { + throw new IOException(Messages.JSchProcessBuilder_Connection_is_not_open); + } + List cmdArgs = command(); if (cmdArgs.size() < 1) { throw new IndexOutOfBoundsException(); @@ -172,7 +177,7 @@ public class JSchProcessBuilder extends AbstractRemoteProcessBuilder { ChannelExec exec = fConnection.getExecChannel(); String command = buildCommand(remoteCmd, env, clearEnv); exec.setCommand(command); - System.out.println("running command: " + command); + System.out.println("running command: " + command); //$NON-NLS-1$ exec.setPty((flags & ALLOCATE_PTY) == ALLOCATE_PTY); exec.setXForwarding((flags & FORWARD_X11) == FORWARD_X11); exec.connect(); diff --git a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JschFileStore.java b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JschFileStore.java index 6c488894863..e1d1b3f1ce9 100644 --- a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JschFileStore.java +++ b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JschFileStore.java @@ -43,8 +43,6 @@ import org.eclipse.remote.core.IRemoteServices; import org.eclipse.remote.core.RemoteServices; import org.eclipse.remote.core.exception.RemoteConnectionException; -import com.jcraft.jsch.ChannelSftp; - public class JschFileStore extends FileStore { private static Map instanceMap = new HashMap(); @@ -85,6 +83,12 @@ public class JschFileStore extends FileStore { fRemotePath = new Path(path); } + private void checkConnection() throws RemoteConnectionException { + if (!fConnection.isOpen()) { + throw new RemoteConnectionException(Messages.JschFileStore_Connection_is_not_open); + } + } + /* * (non-Javadoc) * @@ -93,6 +97,7 @@ public class JschFileStore extends FileStore { */ @Override public IFileInfo[] childInfos(int options, IProgressMonitor monitor) throws CoreException { + checkConnection(); SubMonitor subMon = SubMonitor.convert(monitor, 10); ChildInfosCommand command = new ChildInfosCommand(fConnection, fRemotePath); return command.getResult(subMon.newChild(10)); @@ -123,6 +128,7 @@ public class JschFileStore extends FileStore { */ @Override public void delete(int options, IProgressMonitor monitor) throws CoreException { + checkConnection(); SubMonitor subMon = SubMonitor.convert(monitor, 20); IFileInfo info = fetchInfo(EFS.NONE, subMon.newChild(10)); if (!subMon.isCanceled() && info.exists()) { @@ -139,6 +145,7 @@ public class JschFileStore extends FileStore { */ @Override public IFileInfo fetchInfo(int options, IProgressMonitor monitor) throws CoreException { + checkConnection(); SubMonitor subMon = SubMonitor.convert(monitor, 10); FetchInfoCommand command = new FetchInfoCommand(fConnection, fRemotePath); return command.getResult(subMon.newChild(10)); @@ -205,6 +212,7 @@ public class JschFileStore extends FileStore { */ @Override public IFileStore mkdir(int options, IProgressMonitor monitor) throws CoreException { + checkConnection(); SubMonitor subMon = SubMonitor.convert(monitor, 20); IFileInfo info = fetchInfo(EFS.NONE, subMon.newChild(10)); @@ -238,6 +246,7 @@ public class JschFileStore extends FileStore { */ @Override public InputStream openInputStream(int options, IProgressMonitor monitor) throws CoreException { + checkConnection(); SubMonitor subMon = SubMonitor.convert(monitor, 30); IFileInfo info = fetchInfo(EFS.NONE, subMon.newChild(10)); if (!subMon.isCanceled()) { @@ -263,6 +272,7 @@ public class JschFileStore extends FileStore { */ @Override public OutputStream openOutputStream(int options, IProgressMonitor monitor) throws CoreException { + checkConnection(); SubMonitor subMon = SubMonitor.convert(monitor, 30); IFileInfo info = fetchInfo(EFS.NONE, subMon.newChild(10)); if (!subMon.isCanceled()) { @@ -285,6 +295,7 @@ public class JschFileStore extends FileStore { */ @Override public void putInfo(IFileInfo info, int options, IProgressMonitor monitor) throws CoreException { + checkConnection(); SubMonitor subMon = SubMonitor.convert(monitor, 10); PutInfoCommand command = new PutInfoCommand(fConnection, info, options, fRemotePath); command.getResult(subMon.newChild(10)); @@ -299,10 +310,4 @@ public class JschFileStore extends FileStore { public URI toURI() { return JSchFileSystem.getURIFor(fConnection.getName(), fRemotePath.toString()); } - - private ChannelSftp getChannel(IProgressMonitor monitor) throws RemoteConnectionException { - JSchFileSystem fileSystem = (JSchFileSystem) getFileSystem(); - return fileSystem.getChannel(fConnection); - } - } diff --git a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/messages/Messages.java b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/messages/Messages.java index 056c9e18d3f..a21ec7be2ba 100755 --- a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/messages/Messages.java +++ b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/messages/Messages.java @@ -38,6 +38,10 @@ public class Messages extends NLS { public static String JSchConnectionManager_connection_with_this_name_exists; public static String JSchConnectionManager_cannotRemoveOpenConnection; public static String JSchConnectionManager_invalidConnectionType; + + public static String JSchProcessBuilder_Connection_is_not_open; + public static String JschFileStore_Connection_is_not_open; + public static String JschFileStore_File_doesnt_exist; public static String JschFileStore_Is_a_directory; public static String JschFileStore_The_file_of_name_already_exists; diff --git a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/messages/messages.properties b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/messages/messages.properties index 7d3cb3d9f92..e559a355f95 100755 --- a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/messages/messages.properties +++ b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/messages/messages.properties @@ -25,6 +25,8 @@ JSchConnection_username_must_be_set=Username must be set before opening connecti JSchConnectionManager_connection_with_this_name_exists=A connection with this name already exists JSchConnectionManager_cannotRemoveOpenConnection=Cannot remove an open connection JSchConnectionManager_invalidConnectionType=Invalid connection type +JSchProcessBuilder_Connection_is_not_open=Connection is not open +JschFileStore_Connection_is_not_open=Connection is not open JschFileStore_File_doesnt_exist=File {0} doesn't exist JschFileStore_Is_a_directory={0} is a directory JschFileStore_The_file_of_name_already_exists=A file of name {0} already exists