Skip to content

Commit 9893729

Browse files
committed
Remove use of monolithic contrib
In preparation for clojure 1.3. Use slingshot instead of contrib.condition. Use local copy of contrib.reflect.
1 parent de68632 commit 9893729

File tree

4 files changed

+70
-53
lines changed

4 files changed

+70
-53
lines changed

pom.xml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@
9090
<dependency>
9191
<groupId>org.clojure</groupId>
9292
<artifactId>clojure</artifactId>
93-
<version>1.2.0</version>
93+
<version>${clojure.version}</version>
9494
</dependency>
9595
<dependency>
96-
<groupId>org.clojure</groupId>
97-
<artifactId>clojure-contrib</artifactId>
98-
<version>1.2.0</version>
96+
<groupId>slingshot</groupId>
97+
<artifactId>slingshot</artifactId>
98+
<version>0.2.0</version>
9999
</dependency>
100100
<dependency>
101101
<groupId>org.clojure</groupId>
@@ -110,18 +110,19 @@
110110
<dependency>
111111
<groupId>log4j</groupId>
112112
<artifactId>log4j</artifactId>
113-
<version>1.2.14</version>
113+
<version>1.2.14</version>
114114
<optional>true</optional>
115115
<scope>test</scope>
116116
</dependency>
117117
<dependency>
118118
<groupId>swank-clojure</groupId>
119119
<artifactId>swank-clojure</artifactId>
120-
<version>1.2.1</version>
120+
<version>1.3.1</version>
121121
<optional>true</optional>
122122
<scope>test</scope>
123123
</dependency>
124124
</dependencies>
125+
125126
<profiles>
126127
<profile>
127128
<id>testuser</id>
@@ -138,8 +139,16 @@
138139
</plugins>
139140
</build>
140141
</profile>
142+
<profile>
143+
<id>clojure-1.3</id>
144+
<properties>
145+
<clojure.version>1.3.0-beta1</clojure.version>
146+
</properties>
147+
</profile>
141148
</profiles>
149+
142150
<properties>
143151
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
152+
<clojure.version>1.2.0</clojure.version>
144153
</properties>
145154
</project>

project.clj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
(defproject clj-ssh "0.2.0"
1+
(defproject clj-ssh "0.3.0"
22
:description "ssh from clojure"
3-
:dependencies [[org.clojure/clojure "1.1.0"]
4-
[org.clojure/clojure-contrib "1.1.0"]
5-
[com.jcraft/jsch "0.1.42"]]
3+
:dependencies [[org.clojure/clojure "1.2.0"]
4+
[org.clojure/tools.logging "0.1.2"]
5+
[slingshot "0.2.0"]
6+
[com.jcraft/jsch "0.1.44-1"]]
67
:dev-dependencies [[swank-clojure "1.2.1"]
78
[autodoc "0.7.1"]
89
[log4j/log4j "1.2.14"]]
910
:autodoc {:name "clj-ssh"
1011
:description "Library for using SSH from clojure."
11-
:copyright "Copyright Hugo Duncan 2010. All rights reserved."
12+
:copyright "Copyright Hugo Duncan 2010, 2011. All rights reserved."
1213
:web-src-dir "http://github.com/hugoduncan/clj-ssh/blob/"
1314
:web-home "http://hugoduncan.github.com/clj-ssh/" })

src/clj_ssh/keychain.clj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
moment."
44
(:require
55
[clojure.tools.logging :as logging]
6-
[clojure.contrib.shell :as shell]))
6+
[clojure.java.shell :as shell]))
77

88
(defn ask-passphrase [path]
99
(when-let [console (. System console)]
@@ -21,7 +21,6 @@
2121
(defmethod keychain-passphrase "Mac OS X"
2222
[system path]
2323
(let [result (shell/sh
24-
:return-map true
2524
"/usr/bin/security" "find-generic-password" "-a"
2625
(format "%s" path)
2726
"-g")]

src/clj_ssh/ssh.clj

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,24 @@ Leiningen (http://github.com/technomancy/leiningen).
3737
## License
3838
3939
Licensed under EPL (http://www.eclipse.org/legal/epl-v10.html)"
40-
(:use
41-
[clojure.contrib.def :only [defvar defvar- defunbound]])
4240
(:require
4341
[clj-ssh.keychain :as keychain]
44-
[clojure.contrib.condition :as condition]
45-
[clojure.tools.logging :as logging]
46-
[clojure.contrib.reflect :as reflect]
42+
[clj-ssh.reflect :as reflect]
4743
[clojure.java.io :as io]
48-
[clojure.string :as string])
44+
[clojure.string :as string]
45+
[clojure.tools.logging :as logging]
46+
[slingshot.core :as slingshot])
4947
(:import [com.jcraft.jsch
5048
JSch Session Channel ChannelShell ChannelExec ChannelSftp
5149
Identity IdentityFile Logger KeyPair]))
5250

53-
(defunbound *ssh-agent* "SSH agent used to manage identities.")
54-
(defvar *default-session-options* {} "Default SSH options")
51+
(def ^{:doc "SSH agent used to manage identities." :dynamic true}
52+
*ssh-agent*)
53+
54+
(def
55+
^{:doc "Default SSH options"
56+
:dynamic true}
57+
*default-session-options* {})
5558

5659
(def ^{:dynamic true}
5760
ssh-log-levels
@@ -97,7 +100,7 @@ Licensed under EPL (http://www.eclipse.org/legal/epl-v10.html)"
97100
(defn- default-user []
98101
(. System getProperty "user.name"))
99102

100-
(def ^String *default-identity*
103+
(def ^{:dynamic true} ^String *default-identity*
101104
(.getPath (io/file (. System getProperty "user.home") ".ssh" "id_rsa")))
102105

103106
(defmacro with-default-identity
@@ -261,8 +264,13 @@ keys. All other option key pairs will be passed as SSH config options."
261264

262265
(defn disconnect
263266
"Disconnect a session."
264-
([session]
265-
(.disconnect session)))
267+
[session]
268+
(.disconnect session)
269+
(when (instance? com.jcraft.jsch.Session session)
270+
(when-let [t (reflect/get-field
271+
com.jcraft.jsch.Session 'connectThread session)]
272+
(when (.isAlive t)
273+
(.interrupt t)))))
266274

267275
(defn connected?
268276
"Predicate used to test for a connected session."
@@ -275,10 +283,11 @@ keys. All other option key pairs will be passed as SSH config options."
275283
[session & body]
276284
`(let [session# ~session]
277285
(try
278-
(when-not (connected? session#)
279-
(connect session#))
280-
~@body
281-
(finally (disconnect session#)))))
286+
(when-not (connected? session#)
287+
(connect session#))
288+
~@body
289+
(finally
290+
(disconnect session#)))))
282291

283292
(defn open-channel
284293
"Open a channel of the specified type in the session."
@@ -478,10 +487,9 @@ Options are
478487
5 (. target#
479488
(~name (first args#) (second args#) (nth args# 2) (nth args# 3)
480489
(nth args# 4)))
481-
(throw
490+
(slingshot/throw+
482491
(java.lang.IllegalArgumentException.
483-
(str
484-
"too many arguments passed. Limit 5, passed " (count args#)))))))
492+
(str "Too many arguments passed. Limit 5, passed " (count args#)))))))
485493

486494
(def sftp-modemap { :overwrite ChannelSftp/OVERWRITE
487495
:resume ChannelSftp/RESUME
@@ -525,8 +533,8 @@ Options are
525533
(conj args (sftp-modemap (options :mode)))
526534
args)]
527535
((memfn-varargs put) channel args))
528-
(throw (java.lang.IllegalArgumentException.
529-
(str "Unknown SFTP command " cmd)))))
536+
(slingshot/throw+
537+
(java.lang.IllegalArgumentException. (str "Unknown SFTP command " cmd)))))
530538

531539
(defn sftp
532540
"Execute SFTP commands.
@@ -597,15 +605,15 @@ Options are
597605
[in]
598606
(let [code (.read in)]
599607
(when-not (zero? code)
600-
(condition/raise
601-
:type :clj-ssh/scp-failure
602-
:message (format
603-
"clj-ssh scp failure: %s"
604-
(case code
605-
1 "scp error"
606-
2 "scp fatal error"
607-
-1 "disconnect error"
608-
"unknown error"))))))
608+
(slingshot/throw+
609+
{:type :clj-ssh/scp-failure
610+
:message (format
611+
"clj-ssh scp failure: %s"
612+
(case code
613+
1 "scp error"
614+
2 "scp fatal error"
615+
-1 "disconnect error"
616+
"unknown error"))}))))
609617

610618
(defn- scp-send-command
611619
"Send command to the specified output stream"
@@ -677,11 +685,11 @@ Options are
677685
(fn [path]
678686
(let [file (java.io.File. path)]
679687
(when (.isDirectory file)
680-
(condition/raise
681-
:type :clj-ssh/scp-directory-copy-requested
682-
:message (format
683-
"Copy of dir %s requested without recursive flag"
684-
path)))
688+
(slingshot/throw+
689+
{:type :clj-ssh/scp-directory-copy-requested
690+
:message (format
691+
"Copy of dir %s requested without recursive flag"
692+
path)}))
685693
file)))]
686694
(map f paths)))
687695

@@ -830,11 +838,11 @@ Options are
830838
_ (when (and (.exists file)
831839
(not (.isDirectory file))
832840
(> (count remote-paths) 1))
833-
(condition/raise
834-
:type :clj-ssh/scp-copy-multiple-files-to-file-requested
835-
:message (format
836-
"Copy of multiple files to file %s requested"
837-
local-path)))
841+
(slingshot/throw+
842+
{:type :clj-ssh/scp-copy-multiple-files-to-file-requested
843+
:message (format
844+
"Copy of multiple files to file %s requested"
845+
local-path)}))
838846
session-given (instance? com.jcraft.jsch.Session session-or-hostname)
839847
session (if session-given
840848
session-or-hostname
@@ -878,7 +886,7 @@ Options are
878886
(when-not session-given
879887
(disconnect session))))))
880888

881-
(defvar- key-types {:rsa KeyPair/RSA :dsa KeyPair/DSA})
889+
(def ^{:private true} key-types {:rsa KeyPair/RSA :dsa KeyPair/DSA})
882890

883891
(defn generate-keypair
884892
"Generate a keypair, returned as [private public] byte arrays.

0 commit comments

Comments
 (0)