├── .gitignore ├── deps.edn ├── CONTRIBUTING.md ├── README.md ├── src ├── main │ └── clojure │ │ └── clojure │ │ └── tools │ │ └── deps │ │ └── cli │ │ ├── help.cljc │ │ └── api.cljc └── test │ └── clojure │ └── clojure │ └── tools │ └── deps │ └── cli │ └── api_test.cljc ├── LICENSE └── epl-v10.html /.gitignore: -------------------------------------------------------------------------------- 1 | pom.xml 2 | pom.xml.asc 3 | *.jar 4 | *.class 5 | /lib/ 6 | /classes/ 7 | /target/ 8 | /checkouts/ 9 | .lein-deps-sum 10 | .lein-repl-history 11 | .lein-plugins/ 12 | .lein-failures 13 | .nrepl-port 14 | .cpcache/ 15 | -------------------------------------------------------------------------------- /deps.edn: -------------------------------------------------------------------------------- 1 | { 2 | :paths ["src/main/clojure"] 3 | :deps { io.github.clojure/clr.tools.deps {:git/tag "v0.1.8" :git/sha "1cb01c7"}} 4 | :aliases 5 | {:test 6 | {:extra-paths ["src/test/clojure"] 7 | :extra-deps {io.github.dmiller/test-runner {:git/tag "v0.5.3clr" :git/sha "ae91dd2"}} 8 | ;; :main-opts {"-m" "cognitect.test-runner" "-d" "src/test/clojure"} 9 | :exec-fn cognitect.test-runner.api/test 10 | :exec-args {:dirs ["src/test/clojure"]}}} 11 | 12 | } -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | This is a [Clojure contrib] project. 2 | 3 | Under the Clojure contrib [guidelines], this project cannot accept 4 | pull requests. All patches must be submitted via [JIRA]. 5 | 6 | See [Contributing] on the Clojure website for 7 | more information on how to contribute. 8 | 9 | [Clojure contrib]: https://clojure.org/community/contrib_libs 10 | [Contributing]: https://clojure.org/community/contributing 11 | [JIRA]: https://clojure.atlassian.net/browse/TNS 12 | [guidelines]: https://clojure.org/community/contrib_howto -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # clr.tools.deps.cli 2 | 3 | A port of the [clojure/tools.deps.cli](https://github.com/clojure/tool.deps.cli) library to ClojureCLR. 4 | 5 | See that repository for documentation. 6 | 7 | # Release 8 | 9 | The current release is 0.1.7. 10 | 11 | 12 | [CLI/`deps.edn`](https://clojure.org/reference/deps_edn) dependency information: 13 | ```clojure 14 | io.github.clojure/clr.tools.deps.cli {:git/tag "v0.1.6" :git/sha "e8e5491" } 15 | ``` 16 | 17 | ## License 18 | 19 | This version: 20 | 21 | Copyright (C) Rich Hickey, David Miller & ClojureCLR contributors 22 | Distributed under the Eclipse Public License, the same as Clojure. 23 | 24 | The parent project has this: 25 | 26 | > Copyright © 2017-2023 Rich Hickey, Alex Miller, and contributors 27 | 28 | > All rights reserved. The use and distribution terms for this software are covered by the Eclipse Public License 1.0 which can be found in the file LICENSE at the root of this distribution. By using this software in any fashion, you are agreeing to be bound by the terms of this license. You must not remove this notice, or any other, from this software. -------------------------------------------------------------------------------- /src/main/clojure/clojure/tools/deps/cli/help.cljc: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.tools.deps.cli.help 10 | (:require 11 | [clojure.string :as str] 12 | [clojure.repl :as repl])) 13 | 14 | (defn- garner-ns-defaults [] 15 | (try 16 | (require 'clojure.run.exec) 17 | (let [nsd (some-> "clojure.run.exec/*ns-default*" symbol resolve deref) 18 | nsa (some-> "clojure.run.exec/*ns-aliases*" symbol resolve deref)] 19 | (cond-> {} 20 | nsd (assoc :ns-default nsd) 21 | nsa (assoc :ns-aliases nsa))) 22 | (catch Exception e 23 | (throw (ex-info (.getMessage e) {} e))))) 24 | 25 | (defn- qualify-fn 26 | "Compute function symbol based on exec-fn, ns-aliases, and ns-default" 27 | [fsym ns-aliases ns-default] 28 | ;; validation - make specs? 29 | (when (and fsym (not (symbol? fsym))) 30 | (throw (ex-info (str "Expected function symbol:" fsym) {}))) 31 | 32 | (when fsym 33 | (if (qualified-ident? fsym) 34 | (let [nsym (get ns-aliases (symbol (namespace fsym)))] 35 | (if nsym 36 | (symbol (str nsym) (name fsym)) 37 | fsym)) 38 | (if ns-default 39 | (symbol (str ns-default) (str fsym)) 40 | (throw (ex-info (str "Unqualified function can't be resolved:" fsym) {})))))) 41 | 42 | (defn doc 43 | "Print doc for the specified namespace or function. If neither is specified, print docs 44 | for :ns-default. 45 | 46 | Options: 47 | :ns Print docs for namespace 48 | :fn Print docs for function" 49 | [{:keys [ns fn] :as args}] 50 | (let [{:keys [ns-default ns-aliases]} (merge args (garner-ns-defaults))] 51 | (if fn 52 | (#'repl/print-doc (meta (requiring-resolve (qualify-fn fn ns-aliases ns-default)))) 53 | (let [ns-maybe (or ns ns-default) 54 | ns (if ns-aliases (get ns-aliases ns-maybe ns-maybe) ns-maybe)] 55 | (when (nil? ns) 56 | (throw (ex-info "No namespace or function specified" {}))) 57 | (require ns) 58 | (let [my-ns (the-ns ns) 59 | ns-doc (:doc (meta my-ns))] 60 | ;; Print namespace docs 61 | (when (not (str/blank? ns-doc)) 62 | (println ns-doc) 63 | (println)) 64 | ;; Print function docs 65 | (doseq [[k v] (->> my-ns ns-publics (sort-by key))] 66 | (when (instance? clojure.lang.Fn @v) 67 | (#'repl/print-doc (meta v))))))))) 68 | 69 | (defn dir 70 | "Prints a sorted directory of public vars in a namespace. If a namespace is not 71 | specified :ns-default is used instead." 72 | [{:keys [ns] :as args}] 73 | (let [{:keys [ns-default ns-aliases]} (merge args (garner-ns-defaults)) 74 | ns-maybe (or ns ns-default) 75 | ns (if ns-aliases (get ns-aliases ns-maybe ns-maybe) ns-maybe) 76 | _ (require ns) 77 | my-ns (the-ns ns)] 78 | (doseq [[s v] (->> my-ns ns-publics (sort-by key))] 79 | (when (instance? clojure.lang.Fn @v) 80 | (println s))))) 81 | 82 | (comment 83 | (doc {:ns 'clojure.tools.cli.help}) 84 | (doc {:fn 'clojure.tools.cli.help/doc}) 85 | (dir {:ns 'clojure.tools.cli.help}) 86 | ) -------------------------------------------------------------------------------- /src/test/clojure/clojure/tools/deps/cli/api_test.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.tools.deps.cli.api-test 2 | (:require 3 | #?(:clj [clojure.java.io :as jio] 4 | :cljr [clojure.clr.io :as cio]) 5 | [clojure.string :as str] 6 | [clojure.test :refer [deftest is] :as test] 7 | [clojure.tools.deps.cli.api :as api] 8 | [clojure.tools.deps] ;; ensure extensions loaded 9 | #?(:clj [clojure.tools.deps.util.maven :as mvn]) 10 | [clojure.tools.deps.util.dir :as dir]) 11 | (:import 12 | #?(:clj [java.io File] 13 | :cljr [System.IO DirectoryInfo]))) 14 | 15 | (def ^:dynamic ^#?(:clj File :cljr DirectoryInfo) *test-dir*) 16 | 17 | (defmacro with-test-dir 18 | [& body] 19 | `(let [name# (-> test/*testing-vars* last symbol str) 20 | dir# (#?(:clj jio/file :cljr cio/dir-info) "test-out" name#)] 21 | (#?(:clj .delete :cljr .Delete) dir#) 22 | (#?(:clj .mkdirs :cljr .Create) dir#) 23 | (binding [*test-dir* dir#] 24 | ~@body))) 25 | 26 | (defn get-file-info [dirname filename] 27 | (#?(:cljr cio/file-info :clj jio/file) dirname filename)) 28 | 29 | #?( 30 | :clj 31 | (defn make-parents [dir] 32 | (make-parents dir)) 33 | 34 | :cljr 35 | (defn make-parents [file-path] 36 | (.Create (.Directory file-path))) 37 | 38 | ) 39 | 40 | ;;; NEED TO FIGURE OUT HOW TO PORT THIS TEST 41 | #_(deftest test-prep-with-aliases 42 | (with-test-dir 43 | (let [p1deps (get-file-info *test-dir* "p1/deps.edn") 44 | p2deps (get-file-info *test-dir* "p2/deps.edn")] 45 | 46 | ;; set up p1 with an alias that, if used, pulls p2 47 | (make-parents p1deps) 48 | (spit p1deps 49 | (pr-str {:aliases {:x {:extra-deps {'foo/bar {:local/root "../p2"}}}}})) 50 | 51 | ;; set up p2 to prep 52 | (make-parents p2deps) 53 | #?(:clj (spit (get-file-info *test-dir* "p2/build.clj") 54 | "(ns build 55 | (:require [clojure.java.io :as jio])) 56 | (defn prep [_] 57 | (make-parents \"prepped/out\"))") 58 | :cljr (spit (cio/file-info *test-dir* "p2/build.clj") 59 | "(ns build 60 | (:require [clojure.clr.io :as cio])) 61 | (defn prep [_] 62 | (.Create (cio/dir-info \"prepped/out\")))") 63 | ) 64 | (spit p2deps 65 | (pr-str {:deps/prep-lib {:ensure "prepped" 66 | :alias :build 67 | :fn 'prep} 68 | :aliases {:build {:ns-default 'build}}})) 69 | 70 | ;; prep p1 with aliases 71 | (dir/with-dir (get-file-info *test-dir* "p1") 72 | (api/prep 73 | {#?(:clj :root) #?(:clj {:mvn/repos mvn/standard-repos}) 74 | :user nil 75 | :project :standard 76 | :aliases [:x] 77 | :force true})) 78 | 79 | ;; check that it prepped p2 80 | #?(:clj (is (true? (.exists (get-file-info *test-dir* "p2/prepped")))) 81 | :cljr (is (true? (.Exists (cio/file-info *test-dir* "p2/prepped"))))) 82 | 83 | ))) 84 | 85 | ;;; NEED TO FIGURE OUT HOW TO PORT THIS TEST 86 | #_(deftest test-prep-across-modules 87 | (with-test-dir 88 | (spit (get-file-info *test-dir* "deps.edn") 89 | (pr-str {:deps {'mono/moda {:local/root "mod/a"} 90 | 'mono/modb {:local/root "mod/b"}}})) 91 | (let [adeps (get-file-info *test-dir* "mod/a/deps.edn")] 92 | (make-parents adeps) 93 | (spit adeps "{}")) 94 | (let [bdeps (get-file-info *test-dir* "mod/b/deps.edn")] 95 | (make-parents bdeps) 96 | (spit bdeps 97 | (pr-str {:paths ["src"] 98 | :deps/prep-lib {:alias :resources 99 | :fn 'bcore/generate 100 | :ensure "target/resources"} 101 | :aliases {:resources {:deps {'mono/moda {:local/root "../a"}} :paths ["src"]}}}))) 102 | (let [bgen (get-file-info *test-dir* "mod/b/src/bcore.clj") 103 | cp-path (.getCanonicalPath (get-file-info *test-dir* "mod/b/target/resources/cp"))] 104 | (make-parents bgen) 105 | (spit bgen 106 | (str 107 | "(ns bcore)" 108 | (format "(defn generate [_] (.mkdirs (.getParentFile (java.io.File. \"%s\"))) (spit \"%s\" (System/getProperty \"java.class.path\")))" 109 | cp-path cp-path))) 110 | (api/prep 111 | {:root {:mvn/repos mvn/standard-repos} 112 | :user nil 113 | :project {:deps {'org.clojure/clojure {:mvn/version "1.11.1"} 114 | 'mono/root {:local/root (.getPath *test-dir*)}}} 115 | ;; :log :debug 116 | :force true}) 117 | (let [cp-out (slurp cp-path)] 118 | (is (true? (str/includes? cp-out (.getCanonicalPath (get-file-info *test-dir* "mod/a/src"))))))))) 119 | 120 | ;;; NEED TO FIGURE OUT HOW TO PORT THIS TEST 121 | #_(deftest test-prep-exec-args 122 | (with-test-dir 123 | (let [p1deps (get-file-info *test-dir* "p1/deps.edn") 124 | p2deps (get-file-info *test-dir* "p2/deps.edn")] 125 | 126 | ;; set up p1 to depend on p2 127 | (make-parents p1deps) 128 | (spit p1deps (pr-str {:deps {'foo/p2 {:local/root "../p2"}}})) 129 | 130 | ;; set up p2 to prep 131 | (make-parents p2deps) 132 | (spit (get-file-info *test-dir* "p2/build.clj") 133 | "(ns build 134 | (:require [clojure.java.io :as jio])) 135 | (defn prep [args] 136 | (make-parents \"prepped/out\") 137 | (spit \"prepped/out\" args))") 138 | (spit p2deps 139 | (pr-str {:deps/prep-lib {:ensure "prepped" 140 | :alias :build 141 | :fn 'prep} 142 | :aliases {:build {:ns-default 'build 143 | :exec-args {:hi :there}}}})) 144 | 145 | ;; prep p1 with aliases 146 | (dir/with-dir (get-file-info *test-dir* "p1") 147 | (api/prep 148 | {:root {:mvn/repos mvn/standard-repos} 149 | :user nil 150 | :project :standard 151 | :force true})) 152 | 153 | ;; check that it prepped p2 and received the args 154 | (is (= "{:hi :there}" (slurp (get-file-info *test-dir* "p2/prepped/out"))))))) 155 | 156 | ;;; NEED TO FIGURE OUT HOW TO PORT THIS TEST 157 | #_(deftest test-self-prep 158 | (with-test-dir 159 | (let [p1deps (get-file-info *test-dir* "p1/deps.edn") 160 | p2deps (get-file-info *test-dir* "p2/deps.edn")] 161 | 162 | ;; set up p1 to depend on p2 but also need self prep 163 | (make-parents p1deps) 164 | (spit (get-file-info *test-dir* "p1/build.clj") 165 | "(ns build 166 | (:require [clojure.java.io :as jio])) 167 | (defn prep [args] 168 | (make-parents \"prepped/out\"))") 169 | (spit p1deps 170 | (pr-str {:deps {'foo/p2 {:local/root "../p2"}} 171 | :deps/prep-lib {:ensure "prepped" 172 | :alias :build 173 | :fn 'prep} 174 | :aliases {:build {:ns-default 'build}}})) 175 | 176 | ;; set up p2 to prep 177 | (make-parents p2deps) 178 | (spit (get-file-info *test-dir* "p2/build.clj") 179 | "(ns build 180 | (:require [clojure.java.io :as jio])) 181 | (defn prep [args] 182 | (make-parents \"prepped/out\"))") 183 | (spit p2deps 184 | (pr-str {:deps/prep-lib {:ensure "prepped" 185 | :alias :build 186 | :fn 'prep} 187 | :aliases {:build {:ns-default 'build}}})) 188 | 189 | ;; prep p1 190 | (dir/with-dir (get-file-info *test-dir* "p1") 191 | (api/prep 192 | {:root {:mvn/repos mvn/standard-repos} 193 | :user nil 194 | :project :standard 195 | ;; :log :debug 196 | :force true 197 | :current true})) 198 | 199 | ;; check that it prepped p1 and p2 200 | (is (true? (.exists (get-file-info *test-dir* "p1/prepped")))) 201 | (is (true? (.exists (get-file-info *test-dir* "p2/prepped"))))))) 202 | 203 | 204 | #_(deftest test-find-maven-version 205 | (let [s (with-out-str (api/find-versions {:lib 'org.clojure/clojure :n :all}))] 206 | (is (str/includes? s "1.10.3"))) 207 | 208 | (is (= "" (with-out-str (api/find-versions {:lib 'bogus.taco/slurpee}))))) 209 | 210 | (deftest test-find-git-version 211 | (let [s (with-out-str (api/find-versions {:lib 'io.github.clojure/tools.build :n :all}))] 212 | (is (str/includes? s "v0.8.2"))) 213 | 214 | (is (= "" (with-out-str (api/find-versions {:lib 'io.github.clojure/bogus-taco-slurpee}))))) 215 | 216 | (comment 217 | (test-find-maven-version) 218 | (test-find-git-version) 219 | ) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Eclipse Public License - v 1.0 2 | 3 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC 4 | LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM 5 | CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 6 | 7 | 1. DEFINITIONS 8 | 9 | "Contribution" means: 10 | 11 | a) in the case of the initial Contributor, the initial code and documentation 12 | distributed under this Agreement, and 13 | b) in the case of each subsequent Contributor: 14 | i) changes to the Program, and 15 | ii) additions to the Program; 16 | 17 | where such changes and/or additions to the Program originate from and are 18 | distributed by that particular Contributor. A Contribution 'originates' 19 | from a Contributor if it was added to the Program by such Contributor 20 | itself or anyone acting on such Contributor's behalf. Contributions do not 21 | include additions to the Program which: (i) are separate modules of 22 | software distributed in conjunction with the Program under their own 23 | license agreement, and (ii) are not derivative works of the Program. 24 | 25 | "Contributor" means any person or entity that distributes the Program. 26 | 27 | "Licensed Patents" mean patent claims licensable by a Contributor which are 28 | necessarily infringed by the use or sale of its Contribution alone or when 29 | combined with the Program. 30 | 31 | "Program" means the Contributions distributed in accordance with this 32 | Agreement. 33 | 34 | "Recipient" means anyone who receives the Program under this Agreement, 35 | including all Contributors. 36 | 37 | 2. GRANT OF RIGHTS 38 | a) Subject to the terms of this Agreement, each Contributor hereby grants 39 | Recipient a non-exclusive, worldwide, royalty-free copyright license to 40 | reproduce, prepare derivative works of, publicly display, publicly 41 | perform, distribute and sublicense the Contribution of such Contributor, 42 | if any, and such derivative works, in source code and object code form. 43 | b) Subject to the terms of this Agreement, each Contributor hereby grants 44 | Recipient a non-exclusive, worldwide, royalty-free patent license under 45 | Licensed Patents to make, use, sell, offer to sell, import and otherwise 46 | transfer the Contribution of such Contributor, if any, in source code and 47 | object code form. This patent license shall apply to the combination of 48 | the Contribution and the Program if, at the time the Contribution is 49 | added by the Contributor, such addition of the Contribution causes such 50 | combination to be covered by the Licensed Patents. The patent license 51 | shall not apply to any other combinations which include the Contribution. 52 | No hardware per se is licensed hereunder. 53 | c) Recipient understands that although each Contributor grants the licenses 54 | to its Contributions set forth herein, no assurances are provided by any 55 | Contributor that the Program does not infringe the patent or other 56 | intellectual property rights of any other entity. Each Contributor 57 | disclaims any liability to Recipient for claims brought by any other 58 | entity based on infringement of intellectual property rights or 59 | otherwise. As a condition to exercising the rights and licenses granted 60 | hereunder, each Recipient hereby assumes sole responsibility to secure 61 | any other intellectual property rights needed, if any. For example, if a 62 | third party patent license is required to allow Recipient to distribute 63 | the Program, it is Recipient's responsibility to acquire that license 64 | before distributing the Program. 65 | d) Each Contributor represents that to its knowledge it has sufficient 66 | copyright rights in its Contribution, if any, to grant the copyright 67 | license set forth in this Agreement. 68 | 69 | 3. REQUIREMENTS 70 | 71 | A Contributor may choose to distribute the Program in object code form under 72 | its own license agreement, provided that: 73 | 74 | a) it complies with the terms and conditions of this Agreement; and 75 | b) its license agreement: 76 | i) effectively disclaims on behalf of all Contributors all warranties 77 | and conditions, express and implied, including warranties or 78 | conditions of title and non-infringement, and implied warranties or 79 | conditions of merchantability and fitness for a particular purpose; 80 | ii) effectively excludes on behalf of all Contributors all liability for 81 | damages, including direct, indirect, special, incidental and 82 | consequential damages, such as lost profits; 83 | iii) states that any provisions which differ from this Agreement are 84 | offered by that Contributor alone and not by any other party; and 85 | iv) states that source code for the Program is available from such 86 | Contributor, and informs licensees how to obtain it in a reasonable 87 | manner on or through a medium customarily used for software exchange. 88 | 89 | When the Program is made available in source code form: 90 | 91 | a) it must be made available under this Agreement; and 92 | b) a copy of this Agreement must be included with each copy of the Program. 93 | Contributors may not remove or alter any copyright notices contained 94 | within the Program. 95 | 96 | Each Contributor must identify itself as the originator of its Contribution, 97 | if 98 | any, in a manner that reasonably allows subsequent Recipients to identify the 99 | originator of the Contribution. 100 | 101 | 4. COMMERCIAL DISTRIBUTION 102 | 103 | Commercial distributors of software may accept certain responsibilities with 104 | respect to end users, business partners and the like. While this license is 105 | intended to facilitate the commercial use of the Program, the Contributor who 106 | includes the Program in a commercial product offering should do so in a manner 107 | which does not create potential liability for other Contributors. Therefore, 108 | if a Contributor includes the Program in a commercial product offering, such 109 | Contributor ("Commercial Contributor") hereby agrees to defend and indemnify 110 | every other Contributor ("Indemnified Contributor") against any losses, 111 | damages and costs (collectively "Losses") arising from claims, lawsuits and 112 | other legal actions brought by a third party against the Indemnified 113 | Contributor to the extent caused by the acts or omissions of such Commercial 114 | Contributor in connection with its distribution of the Program in a commercial 115 | product offering. The obligations in this section do not apply to any claims 116 | or Losses relating to any actual or alleged intellectual property 117 | infringement. In order to qualify, an Indemnified Contributor must: 118 | a) promptly notify the Commercial Contributor in writing of such claim, and 119 | b) allow the Commercial Contributor to control, and cooperate with the 120 | Commercial Contributor in, the defense and any related settlement 121 | negotiations. The Indemnified Contributor may participate in any such claim at 122 | its own expense. 123 | 124 | For example, a Contributor might include the Program in a commercial product 125 | offering, Product X. That Contributor is then a Commercial Contributor. If 126 | that Commercial Contributor then makes performance claims, or offers 127 | warranties related to Product X, those performance claims and warranties are 128 | such Commercial Contributor's responsibility alone. Under this section, the 129 | Commercial Contributor would have to defend claims against the other 130 | Contributors related to those performance claims and warranties, and if a 131 | court requires any other Contributor to pay any damages as a result, the 132 | Commercial Contributor must pay those damages. 133 | 134 | 5. NO WARRANTY 135 | 136 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN 137 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR 138 | IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, 139 | NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each 140 | Recipient is solely responsible for determining the appropriateness of using 141 | and distributing the Program and assumes all risks associated with its 142 | exercise of rights under this Agreement , including but not limited to the 143 | risks and costs of program errors, compliance with applicable laws, damage to 144 | or loss of data, programs or equipment, and unavailability or interruption of 145 | operations. 146 | 147 | 6. DISCLAIMER OF LIABILITY 148 | 149 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY 150 | CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, 151 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION 152 | LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 153 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 154 | ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE 155 | EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY 156 | OF SUCH DAMAGES. 157 | 158 | 7. GENERAL 159 | 160 | If any provision of this Agreement is invalid or unenforceable under 161 | applicable law, it shall not affect the validity or enforceability of the 162 | remainder of the terms of this Agreement, and without further action by the 163 | parties hereto, such provision shall be reformed to the minimum extent 164 | necessary to make such provision valid and enforceable. 165 | 166 | If Recipient institutes patent litigation against any entity (including a 167 | cross-claim or counterclaim in a lawsuit) alleging that the Program itself 168 | (excluding combinations of the Program with other software or hardware) 169 | infringes such Recipient's patent(s), then such Recipient's rights granted 170 | under Section 2(b) shall terminate as of the date such litigation is filed. 171 | 172 | All Recipient's rights under this Agreement shall terminate if it fails to 173 | comply with any of the material terms or conditions of this Agreement and does 174 | not cure such failure in a reasonable period of time after becoming aware of 175 | such noncompliance. If all Recipient's rights under this Agreement terminate, 176 | Recipient agrees to cease use and distribution of the Program as soon as 177 | reasonably practicable. However, Recipient's obligations under this Agreement 178 | and any licenses granted by Recipient relating to the Program shall continue 179 | and survive. 180 | 181 | Everyone is permitted to copy and distribute copies of this Agreement, but in 182 | order to avoid inconsistency the Agreement is copyrighted and may only be 183 | modified in the following manner. The Agreement Steward reserves the right to 184 | publish new versions (including revisions) of this Agreement from time to 185 | time. No one other than the Agreement Steward has the right to modify this 186 | Agreement. The Eclipse Foundation is the initial Agreement Steward. The 187 | Eclipse Foundation may assign the responsibility to serve as the Agreement 188 | Steward to a suitable separate entity. Each new version of the Agreement will 189 | be given a distinguishing version number. The Program (including 190 | Contributions) may always be distributed subject to the version of the 191 | Agreement under which it was received. In addition, after a new version of the 192 | Agreement is published, Contributor may elect to distribute the Program 193 | (including its Contributions) under the new version. Except as expressly 194 | stated in Sections 2(a) and 2(b) above, Recipient receives no rights or 195 | licenses to the intellectual property of any Contributor under this Agreement, 196 | whether expressly, by implication, estoppel or otherwise. All rights in the 197 | Program not expressly granted under this Agreement are reserved. 198 | 199 | This Agreement is governed by the laws of the State of New York and the 200 | intellectual property laws of the United States of America. No party to this 201 | Agreement will bring a legal action under this Agreement more than one year 202 | after the cause of action arose. Each party waives its rights to a jury trial in 203 | any resulting litigation. 204 | 205 | -------------------------------------------------------------------------------- /epl-v10.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Eclipse Public License - Version 1.0 8 | 25 | 26 | 27 | 28 | 29 | 30 |

Eclipse Public License - v 1.0

31 | 32 |

THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE 33 | PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR 34 | DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS 35 | AGREEMENT.

36 | 37 |

1. DEFINITIONS

38 | 39 |

"Contribution" means:

40 | 41 |

a) in the case of the initial Contributor, the initial 42 | code and documentation distributed under this Agreement, and

43 |

b) in the case of each subsequent Contributor:

44 |

i) changes to the Program, and

45 |

ii) additions to the Program;

46 |

where such changes and/or additions to the Program 47 | originate from and are distributed by that particular Contributor. A 48 | Contribution 'originates' from a Contributor if it was added to the 49 | Program by such Contributor itself or anyone acting on such 50 | Contributor's behalf. Contributions do not include additions to the 51 | Program which: (i) are separate modules of software distributed in 52 | conjunction with the Program under their own license agreement, and (ii) 53 | are not derivative works of the Program.

54 | 55 |

"Contributor" means any person or entity that distributes 56 | the Program.

57 | 58 |

"Licensed Patents" mean patent claims licensable by a 59 | Contributor which are necessarily infringed by the use or sale of its 60 | Contribution alone or when combined with the Program.

61 | 62 |

"Program" means the Contributions distributed in accordance 63 | with this Agreement.

64 | 65 |

"Recipient" means anyone who receives the Program under 66 | this Agreement, including all Contributors.

67 | 68 |

2. GRANT OF RIGHTS

69 | 70 |

a) Subject to the terms of this Agreement, each 71 | Contributor hereby grants Recipient a non-exclusive, worldwide, 72 | royalty-free copyright license to reproduce, prepare derivative works 73 | of, publicly display, publicly perform, distribute and sublicense the 74 | Contribution of such Contributor, if any, and such derivative works, in 75 | source code and object code form.

76 | 77 |

b) Subject to the terms of this Agreement, each 78 | Contributor hereby grants Recipient a non-exclusive, worldwide, 79 | royalty-free patent license under Licensed Patents to make, use, sell, 80 | offer to sell, import and otherwise transfer the Contribution of such 81 | Contributor, if any, in source code and object code form. This patent 82 | license shall apply to the combination of the Contribution and the 83 | Program if, at the time the Contribution is added by the Contributor, 84 | such addition of the Contribution causes such combination to be covered 85 | by the Licensed Patents. The patent license shall not apply to any other 86 | combinations which include the Contribution. No hardware per se is 87 | licensed hereunder.

88 | 89 |

c) Recipient understands that although each Contributor 90 | grants the licenses to its Contributions set forth herein, no assurances 91 | are provided by any Contributor that the Program does not infringe the 92 | patent or other intellectual property rights of any other entity. Each 93 | Contributor disclaims any liability to Recipient for claims brought by 94 | any other entity based on infringement of intellectual property rights 95 | or otherwise. As a condition to exercising the rights and licenses 96 | granted hereunder, each Recipient hereby assumes sole responsibility to 97 | secure any other intellectual property rights needed, if any. For 98 | example, if a third party patent license is required to allow Recipient 99 | to distribute the Program, it is Recipient's responsibility to acquire 100 | that license before distributing the Program.

101 | 102 |

d) Each Contributor represents that to its knowledge it 103 | has sufficient copyright rights in its Contribution, if any, to grant 104 | the copyright license set forth in this Agreement.

105 | 106 |

3. REQUIREMENTS

107 | 108 |

A Contributor may choose to distribute the Program in object code 109 | form under its own license agreement, provided that:

110 | 111 |

a) it complies with the terms and conditions of this 112 | Agreement; and

113 | 114 |

b) its license agreement:

115 | 116 |

i) effectively disclaims on behalf of all Contributors 117 | all warranties and conditions, express and implied, including warranties 118 | or conditions of title and non-infringement, and implied warranties or 119 | conditions of merchantability and fitness for a particular purpose;

120 | 121 |

ii) effectively excludes on behalf of all Contributors 122 | all liability for damages, including direct, indirect, special, 123 | incidental and consequential damages, such as lost profits;

124 | 125 |

iii) states that any provisions which differ from this 126 | Agreement are offered by that Contributor alone and not by any other 127 | party; and

128 | 129 |

iv) states that source code for the Program is available 130 | from such Contributor, and informs licensees how to obtain it in a 131 | reasonable manner on or through a medium customarily used for software 132 | exchange.

133 | 134 |

When the Program is made available in source code form:

135 | 136 |

a) it must be made available under this Agreement; and

137 | 138 |

b) a copy of this Agreement must be included with each 139 | copy of the Program.

140 | 141 |

Contributors may not remove or alter any copyright notices contained 142 | within the Program.

143 | 144 |

Each Contributor must identify itself as the originator of its 145 | Contribution, if any, in a manner that reasonably allows subsequent 146 | Recipients to identify the originator of the Contribution.

147 | 148 |

4. COMMERCIAL DISTRIBUTION

149 | 150 |

Commercial distributors of software may accept certain 151 | responsibilities with respect to end users, business partners and the 152 | like. While this license is intended to facilitate the commercial use of 153 | the Program, the Contributor who includes the Program in a commercial 154 | product offering should do so in a manner which does not create 155 | potential liability for other Contributors. Therefore, if a Contributor 156 | includes the Program in a commercial product offering, such Contributor 157 | ("Commercial Contributor") hereby agrees to defend and 158 | indemnify every other Contributor ("Indemnified Contributor") 159 | against any losses, damages and costs (collectively "Losses") 160 | arising from claims, lawsuits and other legal actions brought by a third 161 | party against the Indemnified Contributor to the extent caused by the 162 | acts or omissions of such Commercial Contributor in connection with its 163 | distribution of the Program in a commercial product offering. The 164 | obligations in this section do not apply to any claims or Losses 165 | relating to any actual or alleged intellectual property infringement. In 166 | order to qualify, an Indemnified Contributor must: a) promptly notify 167 | the Commercial Contributor in writing of such claim, and b) allow the 168 | Commercial Contributor to control, and cooperate with the Commercial 169 | Contributor in, the defense and any related settlement negotiations. The 170 | Indemnified Contributor may participate in any such claim at its own 171 | expense.

172 | 173 |

For example, a Contributor might include the Program in a commercial 174 | product offering, Product X. That Contributor is then a Commercial 175 | Contributor. If that Commercial Contributor then makes performance 176 | claims, or offers warranties related to Product X, those performance 177 | claims and warranties are such Commercial Contributor's responsibility 178 | alone. Under this section, the Commercial Contributor would have to 179 | defend claims against the other Contributors related to those 180 | performance claims and warranties, and if a court requires any other 181 | Contributor to pay any damages as a result, the Commercial Contributor 182 | must pay those damages.

183 | 184 |

5. NO WARRANTY

185 | 186 |

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS 187 | PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 188 | OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, 189 | ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY 190 | OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely 191 | responsible for determining the appropriateness of using and 192 | distributing the Program and assumes all risks associated with its 193 | exercise of rights under this Agreement , including but not limited to 194 | the risks and costs of program errors, compliance with applicable laws, 195 | damage to or loss of data, programs or equipment, and unavailability or 196 | interruption of operations.

197 | 198 |

6. DISCLAIMER OF LIABILITY

199 | 200 |

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT 201 | NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, 202 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING 203 | WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF 204 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 205 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR 206 | DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED 207 | HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

208 | 209 |

7. GENERAL

210 | 211 |

If any provision of this Agreement is invalid or unenforceable under 212 | applicable law, it shall not affect the validity or enforceability of 213 | the remainder of the terms of this Agreement, and without further action 214 | by the parties hereto, such provision shall be reformed to the minimum 215 | extent necessary to make such provision valid and enforceable.

216 | 217 |

If Recipient institutes patent litigation against any entity 218 | (including a cross-claim or counterclaim in a lawsuit) alleging that the 219 | Program itself (excluding combinations of the Program with other 220 | software or hardware) infringes such Recipient's patent(s), then such 221 | Recipient's rights granted under Section 2(b) shall terminate as of the 222 | date such litigation is filed.

223 | 224 |

All Recipient's rights under this Agreement shall terminate if it 225 | fails to comply with any of the material terms or conditions of this 226 | Agreement and does not cure such failure in a reasonable period of time 227 | after becoming aware of such noncompliance. If all Recipient's rights 228 | under this Agreement terminate, Recipient agrees to cease use and 229 | distribution of the Program as soon as reasonably practicable. However, 230 | Recipient's obligations under this Agreement and any licenses granted by 231 | Recipient relating to the Program shall continue and survive.

232 | 233 |

Everyone is permitted to copy and distribute copies of this 234 | Agreement, but in order to avoid inconsistency the Agreement is 235 | copyrighted and may only be modified in the following manner. The 236 | Agreement Steward reserves the right to publish new versions (including 237 | revisions) of this Agreement from time to time. No one other than the 238 | Agreement Steward has the right to modify this Agreement. The Eclipse 239 | Foundation is the initial Agreement Steward. The Eclipse Foundation may 240 | assign the responsibility to serve as the Agreement Steward to a 241 | suitable separate entity. Each new version of the Agreement will be 242 | given a distinguishing version number. The Program (including 243 | Contributions) may always be distributed subject to the version of the 244 | Agreement under which it was received. In addition, after a new version 245 | of the Agreement is published, Contributor may elect to distribute the 246 | Program (including its Contributions) under the new version. Except as 247 | expressly stated in Sections 2(a) and 2(b) above, Recipient receives no 248 | rights or licenses to the intellectual property of any Contributor under 249 | this Agreement, whether expressly, by implication, estoppel or 250 | otherwise. All rights in the Program not expressly granted under this 251 | Agreement are reserved.

252 | 253 |

This Agreement is governed by the laws of the State of New York and 254 | the intellectual property laws of the United States of America. No party 255 | to this Agreement will bring a legal action under this Agreement more 256 | than one year after the cause of action arose. Each party waives its 257 | rights to a jury trial in any resulting litigation.

258 | 259 | 260 | 261 | 262 | -------------------------------------------------------------------------------- /src/main/clojure/clojure/tools/deps/cli/api.cljc: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.tools.deps.cli.api 10 | "This api provides functions that can be executed from the Clojure tools using -X:deps." 11 | (:refer-clojure :exclude [list]) 12 | (:require 13 | [clojure.edn :as edn] 14 | #?(:clj [clojure.java.io :as jio] 15 | :cljr [clojure.clr.io :as cio]) 16 | [clojure.pprint :as pprint] 17 | [clojure.string :as str] 18 | [clojure.tools.deps :as deps] 19 | [clojure.tools.deps.tool :as tool] 20 | [clojure.tools.deps.tree :as tree] 21 | [clojure.tools.deps.script.resolve-tags :as resolve-tags] 22 | [clojure.tools.deps.extensions :as ext] 23 | #?(:clj [clojure.tools.deps.extensions.pom :as pom]) 24 | [clojure.tools.deps.extensions.local :as local] 25 | #?(:clj [clojure.tools.deps.gen.pom :as gen-pom]) 26 | #?(:clj [clojure.tools.deps.util.maven :as mvn]) 27 | [clojure.tools.deps.util.io :as io :refer [printerrln]] 28 | [clojure.set :as set]) 29 | (:import 30 | #?(:clj [java.io File FileNotFoundException IOException]) 31 | #?(:clj [java.nio.file Files]) 32 | #?(:clj [java.nio.file.attribute FileAttribute]) 33 | #?(:clj [java.util.jar JarFile]) 34 | #?(:clj [org.apache.maven.model Model]) 35 | #?(:clj [org.eclipse.aether.artifact DefaultArtifact]) 36 | #?(:clj [org.eclipse.aether.installation InstallRequest]) 37 | [clojure.lang IExceptionInfo])) 38 | 39 | (set! *warn-on-reflection* true) 40 | 41 | (defn prep 42 | "Prep the unprepped libs found in the transitive lib set of basis. 43 | 44 | This program accepts the same basis-modifying arguments from the `basis` program. 45 | Each dep source value can be :standard, a string path, a deps edn map, or nil. 46 | Sources are merged in the order - :root, :user, :project, :extra. 47 | 48 | Options: 49 | :force - flag on whether to force prepped libs to re-prep (default = false) 50 | :current - flag on whether to prep current project too (default = false) 51 | :log - :none, :info (default), or :debug 52 | 53 | Basis options: 54 | :root - dep source, default = :standard 55 | :user - dep source, default = :standard 56 | :project - dep source, default = :standard (\"./deps.edn\") 57 | :extra - dep source, default = nil 58 | :aliases - coll of kw aliases of argmaps to apply to subprocesses 59 | 60 | Returns params used." 61 | [{:keys [force log current] :or {log :info, current false} :as params}] 62 | (let [basis (deps/create-basis params) 63 | opts {:action (if force :force :prep) 64 | :log log 65 | :current current}] 66 | (deps/prep-libs! (:libs basis) opts basis) 67 | params)) 68 | 69 | (comment 70 | (do 71 | (prep 72 | {:root {:mvn/repos mvn/standard-repos, :deps nil} 73 | :project {:deps '{org.clojure/clojure {:mvn/version "1.10.3"} 74 | io.github.puredanger/cool-lib 75 | {:git/sha "657d5ce88be340ab2a6c0befeae998366105be84"}}} 76 | :log :debug 77 | :force true}) 78 | nil) 79 | ) 80 | 81 | (defn tree 82 | "Print deps tree for the current project's deps.edn built from either the 83 | a basis, or if provided, the trace file. 84 | 85 | This program accepts the same basis-modifying arguments from the `basis` program. 86 | Each dep source value can be :standard, a string path, a deps edn map, or nil. 87 | Sources are merged in the order - :root, :user, :project, :extra. 88 | 89 | By default, :format will :print to the console in a human friendly tree. Use 90 | :edn mode to print the tree to edn. 91 | 92 | In print mode, deps are printed with prefix of either . (included) or X (excluded). 93 | A reason code for inclusion/exclusion may be added at the end of the line. 94 | 95 | Basis options: 96 | :root - dep source, default = :standard 97 | :user - dep source, default = :standard 98 | :project - dep source, default = :standard (\"./deps.edn\") 99 | :extra - dep source, default = nil 100 | :aliases - coll of kw aliases of argmaps to apply to subprocesses 101 | 102 | Input options (if provided, basis options ignored): 103 | :file Path to trace.edn file (from clj -Strace) to use in computing the tree 104 | 105 | Output mode: 106 | :format :print (default) or :edn 107 | 108 | Print output mode modifiers: 109 | :indent Indent spacing (default = 2) 110 | :hide-libs Set of libs to hide as deps (if not top dep), default = #{org.clojure/clojure}" 111 | [opts] 112 | (try 113 | (let [{:keys [file format] :or {format :print}} opts 114 | trace (if file 115 | (io/slurp-edn file) 116 | (tree/calc-trace opts)) 117 | tree (tree/trace->tree trace)] 118 | (case format 119 | :print (tree/print-tree tree opts) 120 | :edn (pprint/pprint tree) 121 | (throw (ex-info (str "Unknown format " format) {})))) 122 | (catch #?(:clj Throwable :cljr Exception) t 123 | (printerrln "Error generating tree:" (#?(:clj .getMessage :cljr .Message) t)) 124 | (when-not (instance? IExceptionInfo t) 125 | #?(:clj (.printStackTrace t) 126 | :cljr (System.Console/WriteLine (.StackTrace t)))) 127 | (#?(:clj System/exit :cljr Environment/Exit) 1)))) 128 | 129 | (comment 130 | (tree nil) 131 | (tree {:extra {:aliases {:foo {:extra-deps {'criterium/criterium {:mvn/version "0.4.0"}}}}} 132 | :aliases [:foo]}) 133 | ) 134 | 135 | (def ^:private cli-alias-keys 136 | #{:deps :replace-deps :extra-deps :override-deps :default-deps 137 | :paths :replace-paths :extra-paths :classpath-overrides 138 | :exec-fn :exec-args :ns-default :ns-aliases 139 | :main-opts :jvm-opts}) 140 | 141 | (defn aliases 142 | "List all aliases available for use with the CLI using -M, -X or -T execution 143 | (note that some aliases may be usable with more than one of these). Also, the 144 | deps.edn sources of the alias are specified. 145 | 146 | This program accepts the same basis-modifying arguments from the `basis` program. 147 | Each dep source value can be :standard, a string path, a deps edn map, or nil. 148 | Sources are merged in the order - :root, :user, :project, :extra. 149 | 150 | For example, to print only aliases defined in this project: 151 | clj -X:deps aliases :root nil :user nil 152 | 153 | Basis options: 154 | :root - dep source, default = :standard 155 | :user - dep source, default = :standard 156 | :project - dep source, default = :standard (\"./deps.edn\") 157 | :extra - dep source, default = nil 158 | 159 | The aliases are printed to the console." 160 | [params] 161 | (let [edn-srcs (deps/create-edn-maps params) 162 | src-aliases (reduce-kv #(assoc %1 %2 (:aliases %3)) {} edn-srcs) 163 | cli-aliases (reduce-kv 164 | (fn [m src aliases] 165 | (assoc m 166 | src 167 | (reduce-kv 168 | (fn [a alias alias-defn] 169 | (cond-> a 170 | (pos? (count (set/intersection cli-alias-keys (set (keys alias-defn))))) 171 | (assoc alias alias-defn))) 172 | {} aliases))) 173 | {} src-aliases) 174 | all-aliases (->> cli-aliases (map val) (mapcat #(-> % keys sort)) distinct)] 175 | (doseq [alias all-aliases] 176 | (let [srcs (reduce-kv (fn [srcs src deps-edn] 177 | (if (contains? (:aliases deps-edn) alias) 178 | (conj srcs src) 179 | srcs)) 180 | [] edn-srcs)] 181 | (println alias (str "(" (str/join ", " (map name srcs)) ")")))))) 182 | 183 | #?( 184 | :clj 185 | (def ^:private license-abbrev 186 | (delay 187 | (-> "clojure/tools/deps/license-abbrev.edn" jio/resource slurp edn/read-string))) 188 | 189 | :cljr 190 | (def ^:private license-abbrev 191 | (delay 192 | (letfn [(find-file [x] (clojure.lang.RT/FindFile x))] 193 | (-> "clojure/tools/deps/license-abbrev.edn" find-file slurp edn/read-string)))) 194 | ) 195 | 196 | (defn- license-string 197 | [info license-mode] 198 | (let [abbrevs @license-abbrev 199 | license-name (when (#{:full :short} license-mode) (:name info))] 200 | (if (and license-name (= license-mode :short)) 201 | (get abbrevs license-name license-name) 202 | license-name))) 203 | 204 | (defn list 205 | "List all deps on the classpath, optimized for knowing the final set of included 206 | libs. The `tree` program can provide more info on why or why not a particular 207 | lib is included. 208 | 209 | Licenses will be printed in short form by default but can also be listed as 210 | in :full or :none for none at all using the :license key. 211 | 212 | By default, :format will :print to the console in a human friendly tree. Use 213 | :edn mode to print the tree to edn. 214 | 215 | This program accepts the same basis-modifying arguments from the `basis` program. 216 | Each dep source value can be :standard, a string path, a deps edn map, or nil. 217 | Sources are merged in the order - :root, :user, :project, :extra. 218 | 219 | Options: 220 | :license - :full, :short (default), :none 221 | 222 | Output mode options: 223 | :format :print (default) or :edn 224 | 225 | Basis options: 226 | :root - dep source, default = :standard 227 | :user - dep source, default = :standard 228 | :project - dep source, default = :standard (\"./deps.edn\") 229 | :extra - dep source, default = nil 230 | :aliases - coll of kw aliases of argmaps to apply to subprocesses 231 | 232 | The libs are printed to the console." 233 | [params] 234 | (let [{license-mode :license, format :format 235 | :or {license-mode :short, format :print}} params 236 | basis (deps/create-basis params) 237 | libs (:libs basis) 238 | data (into (sorted-map) 239 | (map (fn [lib] 240 | (let [coord (get libs lib) 241 | info (ext/license-info lib coord basis)] 242 | [lib (cond-> coord info (assoc :license info))])) 243 | (-> libs keys sort)))] 244 | (if (= format :edn) 245 | (binding [*print-namespace-maps* false] 246 | (pprint/pprint data)) 247 | (doseq [[lib coord] data] 248 | (let [summary (ext/coord-summary lib coord) 249 | info (:license coord) 250 | license-string (license-string info license-mode)] 251 | (println summary (if license-string (str " (" license-string ")") ""))))))) 252 | 253 | (comment 254 | (list nil) 255 | @license-abbrev 256 | ) 257 | 258 | ;;;; git resolve-tags 259 | 260 | (defn git-resolve-tags 261 | "Resolve git tags in deps.edn git deps to full shas." 262 | [_] 263 | (resolve-tags/exec {:deps-file "deps.edn"})) 264 | 265 | ;;;; Generate pom 266 | 267 | #?( 268 | :clj 269 | (defn mvn-pom 270 | "Sync or create pom.xml from deps.edn. 271 | 272 | This program accepts the same basis-modifying arguments from the `basis` program. 273 | Each dep source value can be :standard, a string path, a deps edn map, or nil. 274 | Sources are merged in the order - :root, :user, :project, :extra. 275 | 276 | Basis options: 277 | :root - dep source, default = :standard 278 | :user - dep source, default = :standard 279 | :project - dep source, default = :standard (\"./deps.edn\") 280 | :extra - dep source, default = nil 281 | :aliases - coll of kw aliases of argmaps to apply to subprocesses 282 | 283 | Deprecated options (use the basis :aliases above instead): 284 | :argmaps - vector of aliases to combine into argmaps to resolve-deps and make-classpath" 285 | [{:keys [argmaps] :as opts}] 286 | (try 287 | (let [opts' (if argmaps (assoc opts :aliases (vec (concat argmaps (:aliases opts)))) opts) 288 | basis (deps/create-basis opts') 289 | ;; treat all transitive deps as top-level deps 290 | updated-deps (reduce-kv (fn [m lib {:keys [dependents] :as coord}] 291 | (if (seq dependents) m (assoc m lib coord))) 292 | {} (:libs basis))] 293 | (gen-pom/sync-pom (merge basis {:deps updated-deps}) (jio/file "."))) 294 | (catch Throwable t 295 | (printerrln "Error generating pom manifest:" (.getMessage t)) 296 | (when-not (instance? IExceptionInfo t) 297 | (.printStackTrace t)) 298 | (System/exit 1)))) 299 | ) 300 | 301 | ;;;; Install jar into local repository 302 | #?( 303 | :clj 304 | (defn- read-pom-file 305 | [pom] 306 | (let [pom-file (jio/file pom)] 307 | (if (.exists pom-file) 308 | (let [^Model model (pom/read-model-file pom-file (deps/root-deps))] 309 | {:group-id (.getGroupId model) 310 | :artifact-id (.getArtifactId model) 311 | :version (.getVersion model) 312 | :pom-file pom}) 313 | (throw (FileNotFoundException. (str "Pom file not found: " (str pom))))))) 314 | ) 315 | 316 | #?( 317 | :clj 318 | (defn- gen-pom-file 319 | [lib version classifier] 320 | (let [group-id (namespace lib) 321 | artifact-id (name lib) 322 | temp-dir (.toString (Files/createTempDirectory "pom" (make-array FileAttribute 0))) 323 | pom-file (str temp-dir "/pom.xml")] 324 | (gen-pom/sync-pom {:params {:target-dir temp-dir 325 | :src-pom pom-file 326 | :lib lib 327 | :version version}}) 328 | {:group-id group-id 329 | :artifact-id artifact-id 330 | :version version 331 | :classifier classifier 332 | :pom-file pom-file})) 333 | ) 334 | 335 | #?( 336 | :clj 337 | (defn- read-pom-in-jar 338 | [jar-name] 339 | (let [jar-file (jio/file jar-name)] 340 | (when (or (nil? jar-name) (not (.exists jar-file))) 341 | (throw (FileNotFoundException. (str "Jar file not found: " jar-name)))) 342 | (let [jar (JarFile. jar-file)] 343 | (if-let [path (local/find-pom jar)] 344 | (let [entry (.getJarEntry jar path) 345 | jis (.getInputStream jar entry) 346 | tmp (File/createTempFile "pom" ".xml")] 347 | (jio/copy jis tmp) 348 | (read-pom-file tmp)) 349 | (throw (IOException. (str "Jar file does not contain pom: " jar-name))))))) 350 | ) 351 | 352 | #?( 353 | :clj 354 | (defn- output-path 355 | [local-repo group-id artifact-id version] 356 | (let [path-parts (concat 357 | [(or local-repo @mvn/cached-local-repo)] 358 | (str/split group-id #"\.") 359 | [artifact-id version])] 360 | (.getAbsolutePath ^File (apply jio/file path-parts)))) 361 | ) 362 | 363 | #?( 364 | :clj 365 | 366 | (defn mvn-install 367 | "Install a jar and pom to the Maven local cache. 368 | The pom file must either be supplied, or generated based 369 | on provided lib/version/classifier, or provided inside the jar. 370 | The group/artifact/version coordinate will be pulled from the 371 | pom source as above. 372 | 373 | Required: 374 | :jar (reqired) - path to jar file (embedded pom used by default) 375 | 376 | Explicit pom options: 377 | :pom - path to pom file (pom in jar ignored) 378 | 379 | Generated pom options: 380 | :lib - qualified symbol like my.org/lib 381 | :version - string 382 | :classifier - string 383 | 384 | Other options: 385 | :local-repo (optional) - path to local repo (default = ~/.m2/repository) 386 | 387 | Execute ad-hoc: 388 | clj -X:deps mvn/install :jar '\"foo-1.2.3.jar\"'" 389 | [{:keys [jar pom lib version classifier local-repo]}] 390 | (println "Installing" jar (if pom (str "and " pom) "")) 391 | (let [{:keys [pom-file group-id artifact-id version classifier]} 392 | (cond 393 | pom (read-pom-file pom) 394 | lib (gen-pom-file lib version classifier) 395 | :else (read-pom-in-jar jar)) 396 | jar-file (jio/file jar) 397 | pom-file (jio/file pom-file) 398 | system (mvn/make-system) 399 | settings (mvn/get-settings) 400 | session (mvn/make-session system settings (or local-repo @mvn/cached-local-repo)) 401 | artifacts [(.setFile (DefaultArtifact. group-id artifact-id classifier "jar" version) jar-file) 402 | (.setFile (DefaultArtifact. group-id artifact-id classifier "pom" version) pom-file)] 403 | install-request (.setArtifacts (InstallRequest.) artifacts)] 404 | (.install system session install-request) 405 | (println "Installed to" (output-path local-repo group-id artifact-id version)))) 406 | ) 407 | 408 | (defn find-versions 409 | "Find available tool versions given either a lib (with :lib) or 410 | existing installed tool (with :tool). If lib, check all registered 411 | procurers and print one coordinate per line when found. 412 | 413 | Options: 414 | :lib Qualified lib symbol 415 | :tool Tool name for installed tool 416 | :n Number of coordinates to return, default = 8, :all for all" 417 | [{:keys [lib tool n] :or {n 8} :as args}] 418 | (let [{:keys [root-edn user-edn]} (deps/find-edn-maps) 419 | master-edn (deps/merge-edns [root-edn user-edn]) 420 | trunc-fn (fn [n x] 421 | (if (= n :all) 422 | x 423 | (mapcat #(take-last n %) (vals (group-by keys x))))) 424 | coords (cond 425 | tool 426 | (if-let [{:keys [lib coord]} (tool/resolve-tool (name tool))] 427 | (ext/find-versions lib coord (ext/coord-type coord) master-edn) 428 | (throw (ex-info (str "Unknown tool: " tool) {:tool tool}))) 429 | 430 | lib 431 | (ext/find-all-versions lib {} master-edn) 432 | 433 | :else 434 | (throw (ex-info "Either :lib or :tool must be provided to find versions" (or args {}))))] 435 | (run! #(binding [*print-namespace-maps* false] (prn %)) (trunc-fn n coords)))) 436 | 437 | (comment 438 | (find-versions '{:lib org.clojure/tools.gitlibs :n 4}) 439 | (find-versions '{:lib io.github.clojure/tools.gitlibs :n 10}) 440 | (find-versions '{:tool tools :n 3}) 441 | (find-versions nil) 442 | ) --------------------------------------------------------------------------------