From 9a7cc6a988223cf9c2071996d8869d7bb981783f Mon Sep 17 00:00:00 2001
From: Abdelilah El Aissaoui <aeab13@gmail.com>
Date: Sat, 3 Jun 2023 02:02:00 +0200
Subject: [PATCH] Remove unused SSHD dependency

---
 build.gradle.kts                              |  1 -
 .../com/jetpackduba/gitnuro/AppConstants.kt   |  1 -
 .../gitnuro/credentials/GProcess.kt           | 66 -------------------
 .../gitnuro/credentials/GProcessLibSsh.kt     |  1 -
 .../gitnuro/credentials/GRemoteSession.kt     |  5 +-
 5 files changed, 1 insertion(+), 73 deletions(-)
 delete mode 100644 src/main/kotlin/com/jetpackduba/gitnuro/credentials/GProcess.kt

diff --git a/build.gradle.kts b/build.gradle.kts
index 809f8c0..dc89d97 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -40,7 +40,6 @@ dependencies {
     implementation(compose("org.jetbrains.compose.components:components-animatedimage"))
     implementation("org.eclipse.jgit:org.eclipse.jgit:$jgit")
     implementation("org.eclipse.jgit:org.eclipse.jgit.gpg.bc:$jgit")
-    implementation("org.apache.sshd:sshd-core:2.9.0")
     implementation("com.google.dagger:dagger:2.45")
     implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
     kapt("com.google.dagger:dagger-compiler:2.45")
diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/AppConstants.kt b/src/main/kotlin/com/jetpackduba/gitnuro/AppConstants.kt
index d13a1b2..50aa584 100644
--- a/src/main/kotlin/com/jetpackduba/gitnuro/AppConstants.kt
+++ b/src/main/kotlin/com/jetpackduba/gitnuro/AppConstants.kt
@@ -2,7 +2,6 @@ package com.jetpackduba.gitnuro
 
 object AppConstants {
     val openSourceProjects = listOf(
-        Project("Apache SSHD", "https://mina.apache.org/sshd-project/", apache__2_0),
         Project("Google Dagger", "https://dagger.dev/", apache__2_0),
         Project("Compose Multiplatform", "https://www.jetbrains.com/lp/compose-mpp/", apache__2_0),
         Project("JGit", "https://www.eclipse.org/jgit/", edl),
diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/credentials/GProcess.kt b/src/main/kotlin/com/jetpackduba/gitnuro/credentials/GProcess.kt
deleted file mode 100644
index 392447a..0000000
--- a/src/main/kotlin/com/jetpackduba/gitnuro/credentials/GProcess.kt
+++ /dev/null
@@ -1,66 +0,0 @@
-package com.jetpackduba.gitnuro.credentials
-
-import org.apache.sshd.client.channel.ChannelExec
-import org.apache.sshd.client.session.ClientSession
-import java.io.InputStream
-import java.io.OutputStream
-import java.io.PipedInputStream
-import java.io.PipedOutputStream
-import javax.inject.Inject
-
-class GProcess @Inject constructor() : Process() {
-    private lateinit var channel: ChannelExec
-    private val outputStream = PipedOutputStream()
-    private val inputStream = PipedInputStream()
-    private val errorOutputStream = PipedOutputStream()
-    private val pipedInputStream = PipedInputStream(outputStream)
-    private val pipedOutputStream = PipedOutputStream(inputStream)
-    private val pipedErrorInputStream = PipedInputStream(errorOutputStream)
-
-    override fun getOutputStream(): OutputStream {
-        return pipedOutputStream
-    }
-
-    override fun getInputStream(): InputStream {
-        return pipedInputStream
-    }
-
-    override fun getErrorStream(): InputStream {
-        return pipedErrorInputStream
-    }
-
-    override fun waitFor(): Int {
-        if (isRunning())
-            Thread.sleep(100)
-
-        return exitValue()
-    }
-
-    override fun exitValue(): Int {
-        check(!isRunning())
-
-        return channel.exitStatus
-    }
-
-    override fun destroy() {
-        if (channel.isOpen) {
-            channel.close()
-        }
-    }
-
-    private fun isRunning(): Boolean {
-        return channel.exitStatus < 0 && channel.isOpen
-    }
-
-    fun setup(session: ClientSession, commandName: String) {
-        val channel = session.createExecChannel(commandName)
-        channel.out = outputStream
-        channel.err = errorOutputStream
-        channel.`in` = inputStream
-
-        channel.open().verify()
-
-        this.channel = channel
-    }
-
-}
\ No newline at end of file
diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/credentials/GProcessLibSsh.kt b/src/main/kotlin/com/jetpackduba/gitnuro/credentials/GProcessLibSsh.kt
index ef8f95d..ecc681b 100644
--- a/src/main/kotlin/com/jetpackduba/gitnuro/credentials/GProcessLibSsh.kt
+++ b/src/main/kotlin/com/jetpackduba/gitnuro/credentials/GProcessLibSsh.kt
@@ -50,7 +50,6 @@ class GProcessLibSsh : Process() {
             channel.close()
         }
 
-        session.disconnect()
         println("Destroy called")
     }
 
diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/credentials/GRemoteSession.kt b/src/main/kotlin/com/jetpackduba/gitnuro/credentials/GRemoteSession.kt
index 8f13c90..67fe47f 100644
--- a/src/main/kotlin/com/jetpackduba/gitnuro/credentials/GRemoteSession.kt
+++ b/src/main/kotlin/com/jetpackduba/gitnuro/credentials/GRemoteSession.kt
@@ -3,7 +3,6 @@ package com.jetpackduba.gitnuro.credentials
 import com.jetpackduba.gitnuro.ssh.libssh.LibSshOptions
 import com.jetpackduba.gitnuro.ssh.libssh.LibSshSession
 import kotlinx.coroutines.CancellationException
-import org.apache.sshd.client.SshClient
 import org.eclipse.jgit.transport.RemoteSession
 import org.eclipse.jgit.transport.URIish
 import javax.inject.Inject
@@ -16,7 +15,6 @@ class GRemoteSession @Inject constructor(
     private val processSession: Provider<LibSshSession>,
     private val credentialsStateManager: CredentialsStateManager,
 ) : RemoteSession {
-    private val client = SshClient.setUpDefaultClient()
     private var session: LibSshSession? = null
 
     override fun exec(commandName: String, timeout: Int): Process {
@@ -29,9 +27,8 @@ class GRemoteSession @Inject constructor(
         return process
     }
 
-
     override fun disconnect() {
-        client.close()
+        session?.disconnect()
     }
 
     fun setup(uri: URIish) {