pax_global_header00006660000000000000000000000064117303376640014524gustar00rootroot0000000000000052 comment=ed51bae5ba661ab973707199738ed853bc32e021 ato-lein-clojars-ed51bae/000077500000000000000000000000001173033766400154375ustar00rootroot00000000000000ato-lein-clojars-ed51bae/.gitignore000066400000000000000000000000221173033766400174210ustar00rootroot00000000000000lib *.jar pom.xml ato-lein-clojars-ed51bae/README.md000066400000000000000000000013361173033766400167210ustar00rootroot00000000000000Clojars.org Leiningen Plugin ============================ This is a simple plugn for interacting with Clojars.org directly from Leiningen. Setup ----- Add lein-clojars as Leiningen plugin: lein plugin install lein-clojars 0.7.0 Create a Clojars account and paste your SSH public key into your [profile] [1]. If you don't have ssh-keygen available -- perhaps you're using Windows -- then you can use: lein keygen SSH keys will searched for in ~/.leiningen and ~/.ssh under the names id_rsa, id_dsa and identity. [1]: http://clojars.org/profile Usage ----- To push your project to the Clojars repository, simply type: lein push TODO ----- Some ideas for extra commands include: search, register and add-dep. ato-lein-clojars-ed51bae/project.clj000066400000000000000000000002231173033766400175740ustar00rootroot00000000000000(defproject lein-clojars "0.8.0" :description "Leiningen plugin for interacting with Clojars.org." :dependencies [[com.jcraft/jsch "0.1.42"]]) ato-lein-clojars-ed51bae/src/000077500000000000000000000000001173033766400162265ustar00rootroot00000000000000ato-lein-clojars-ed51bae/src/leiningen/000077500000000000000000000000001173033766400201765ustar00rootroot00000000000000ato-lein-clojars-ed51bae/src/leiningen/keygen.clj000066400000000000000000000020701173033766400221510ustar00rootroot00000000000000(ns leiningen.keygen (:import (com.jcraft.jsch JSch KeyPair) (java.io File) (java.net InetAddress UnknownHostException))) (defn- get-hostname [] (try (.getHostName (InetAddress/getLocalHost)) (catch UnknownHostException e "localhost"))) (defn keygen "Generate an SSH key pair for authentication with Clojars.org" [& args] (println "Generating a new SSH keypair...") (let [confdir (File. (System/getProperty "user.home") ".leiningen") privfile (str (File. confdir "id_rsa")) pubfile (str (File. confdir "id_rsa.pub")) keypair (KeyPair/genKeyPair (JSch.) KeyPair/RSA)] (.mkdirs confdir) (.writePrivateKey keypair privfile) (println "Private key written to" privfile) (.writePublicKey keypair pubfile (str (System/getProperty "user.name") "@" (get-hostname) " (Leiningen)")) (println "Public key written to" pubfile) (println "\nPaste the public key below into your profile at http://clojars.org/profile") (println (slurp pubfile)))) ato-lein-clojars-ed51bae/src/leiningen/push.clj000066400000000000000000000063151173033766400216540ustar00rootroot00000000000000(ns leiningen.push (:require [clojure.java.io :as io]) (:use [leiningen.jar :only [jar get-jar-filename]] [leiningen.pom :only [pom]]) (:import (com.jcraft.jsch JSch JSchException Logger) (java.io File FileInputStream))) (let [re-repo #"(?:([^@]+)@)?([^:]+)(?::(\d+))?(?::(.*))?"] (defn parse-repo [repo] (let [[_ user host port path] (re-matches re-repo (or repo "clojars@clojars.org"))] [(or user (System/getProperty "user.name")) host (if port (Integer/parseInt port) 22) (or path ".")]))) (defn- add-identities [jsch] (let [homedir (File. (System/getProperty "user.home")) leindir (File. homedir ".leiningen") sshdir (File. homedir ".ssh")] (doseq [dir [leindir sshdir] name ["id_rsa" "id_dsa" "identity"] :let [file (File. dir name)] :when (.exists file)] (try (.addIdentity jsch (str file)) (println "Using SSH identity" (str file)) (catch JSchException e (println "Skipping invalid SSH key" (str file))))))) (defn- read-ack [in] (let [b (.read in)] (when-not (zero? b) (throw (Exception. (str "scp expected ACK but got " b)))))) (defn scp-send [repo & files] (let [jsch (doto (JSch.) (add-identities)) [user host port path] (parse-repo repo) session (doto (.getSession jsch user host port) (.setConfig "StrictHostKeyChecking" "no") (.connect)) channel (doto (.openChannel session "exec") (.setCommand (str "scp -p -t " \" path \")) (.setErrStream System/err true)) in (.getInputStream channel) out (.getOutputStream channel)] (try (.connect channel) (read-ack in) (doseq [path files] (let [file (io/file path)] (.write out (.getBytes (str "C0644 " (.length file) " " (.getName file) "\n"))) (.flush out) (read-ack in) (io/copy file out) (.write out 0) (.flush out) (read-ack in))) (.close out) (.read in) ; wait for remote close (finally (.disconnect channel) (.disconnect session))))) (defn push "Push a jar to the Clojars.org repository over scp" [project & [repo]] (when (System/getProperty "scp.verbose") (JSch/setLogger (proxy [Logger] [] (isEnabled [level] true) (log [level message] (println level message))))) (let [jarfile (get-jar-filename project) targetpath (.getParentFile (io/file jarfile)) pomfile (io/file targetpath "pom.xml")] (pom project) (jar project) (try (scp-send repo pomfile jarfile) (catch JSchException e (.printStackTrace e) (when (= (.getMessage e) "Auth fail") (println (str "\nIf you're having trouble authenticating, try using\n" "a key generated by 'lein keygen'. lein-clojars doesn't\n" "work yet with DSA or passphrased keys. I'm working\n" "on fixing this. You can also push directly with scp:\n\n" "lein pom\n" "scp " pomfile " " jarfile " clojars@clojars.org:" )))))))