Make Jetty restart when OSGi configuration is not cleaned up.
[lgpl/argeo-commons.git] / org.argeo.core / src / org / argeo / sync / fs / SshSync.java
index 43af4503678213a37e7872d649ea6ebf106e3185..9b15a32ea5ac3a365ec5ff31f4d2f5c424e5b9a6 100644 (file)
@@ -6,13 +6,8 @@ import java.io.OutputStream;
 import java.nio.file.DirectoryStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.security.KeyPair;
-import java.security.PublicKey;
-import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Scanner;
-import java.util.Set;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
@@ -22,16 +17,10 @@ import org.apache.sshd.agent.SshAgentFactory;
 import org.apache.sshd.agent.local.LocalAgentFactory;
 import org.apache.sshd.agent.unix.UnixAgentFactory;
 import org.apache.sshd.client.SshClient;
-import org.apache.sshd.client.channel.ClientChannel;
-import org.apache.sshd.client.channel.ClientChannelEvent;
-import org.apache.sshd.client.config.keys.ClientIdentityLoader;
 import org.apache.sshd.client.future.ConnectFuture;
 import org.apache.sshd.client.session.ClientSession;
-import org.apache.sshd.client.subsystem.sftp.SftpFileSystem;
-import org.apache.sshd.client.subsystem.sftp.SftpFileSystemProvider;
-import org.apache.sshd.common.config.keys.FilePasswordProvider;
-import org.apache.sshd.common.util.io.NoCloseInputStream;
-import org.apache.sshd.common.util.io.NoCloseOutputStream;
+import org.apache.sshd.client.subsystem.sftp.fs.SftpFileSystem;
+import org.apache.sshd.client.subsystem.sftp.fs.SftpFileSystemProvider;
 
 public class SshSync {
        private final static Log log = LogFactory.getLog(SshSync.class);
@@ -40,7 +29,7 @@ public class SshSync {
 
                try (SshClient client = SshClient.setUpDefaultClient()) {
                        client.start();
-                       boolean osAgent = false;
+                       boolean osAgent = true;
                        SshAgentFactory agentFactory = osAgent ? new UnixAgentFactory() : new LocalAgentFactory();
                        // SshAgentFactory agentFactory = new LocalAgentFactory();
                        client.setAgentFactory(agentFactory);
@@ -55,15 +44,15 @@ public class SshSync {
                                System.out.print(keyPath + ": ");
                                Scanner s = new Scanner(System.in);
                                String password = s.next();
-                               KeyPair keyPair = ClientIdentityLoader.DEFAULT.loadClientIdentity(keyPath,
-                                               FilePasswordProvider.of(password));
-                               sshAgent.addIdentity(keyPair, "NO COMMENT");
+//                             KeyPair keyPair = ClientIdentityLoader.DEFAULT.loadClientIdentity(keyPath,
+//                                             FilePasswordProvider.of(password));
+//                             sshAgent.addIdentity(keyPair, "NO COMMENT");
                        }
 
-                       List<? extends Map.Entry<PublicKey, String>> identities = sshAgent.getIdentities();
-                       for (Map.Entry<PublicKey, String> entry : identities) {
-                               System.out.println(entry.getValue() + " : " + entry.getKey());
-                       }
+//                     List<? extends Map.Entry<PublicKey, String>> identities = sshAgent.getIdentities();
+//                     for (Map.Entry<PublicKey, String> entry : identities) {
+//                             System.out.println(entry.getValue() + " : " + entry.getKey());
+//                     }
 
                        ConnectFuture connectFuture = client.connect(login, host, port);
                        connectFuture.await();
@@ -143,21 +132,4 @@ public class SshSync {
 
        }
 
-       static void openShell(ClientSession session) {
-               try (ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL)) {
-                       channel.setIn(new NoCloseInputStream(System.in));
-                       channel.setOut(new NoCloseOutputStream(System.out));
-                       channel.setErr(new NoCloseOutputStream(System.err));
-                       channel.open();
-
-                       Set<ClientChannelEvent> events = new HashSet<>();
-                       events.add(ClientChannelEvent.CLOSED);
-                       channel.waitFor(events, 0);
-               } catch (IOException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               } finally {
-                       session.close(false);
-               }
-       }
 }