├── .gitignore ├── LICENSE ├── bb.edn ├── deps.edn ├── project.edn ├── resources └── weavejester │ └── build │ ├── bb.edn.tmpl │ ├── project.edn.tmpl │ └── tests.edn ├── src └── weavejester │ └── build │ ├── git.clj │ ├── project.clj │ ├── tasks.clj │ ├── tool.clj │ └── write_pom.clj ├── test └── weavejester │ └── build_test.clj └── tests.edn /.gitignore: -------------------------------------------------------------------------------- 1 | /.cpcache 2 | /pom.xml 3 | /target 4 | .rebel_readline_history 5 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /bb.edn: -------------------------------------------------------------------------------- 1 | {:deps {io.github.weavejester/build {:local/root "."}} 2 | :tasks 3 | {clean weavejester.build.tasks/clean 4 | deploy weavejester.build.tasks/deploy 5 | jar weavejester.build.tasks/jar 6 | lint weavejester.build.tasks/lint 7 | outdated weavejester.build.tasks/outdated 8 | repl weavejester.build.tasks/repl 9 | test weavejester.build.tasks/test 10 | uberjar weavejester.build.tasks/uberjar}} 11 | -------------------------------------------------------------------------------- /deps.edn: -------------------------------------------------------------------------------- 1 | {:tools/usage {:ns-default weavejester.build.tool} 2 | :paths ["resources" "src"] 3 | :deps {io.github.clojure/tools.build {:git/tag "v0.7.5" :git/sha "34727f7"} 4 | slipset/deps-deploy {:mvn/version "0.2.0"}} 5 | :aliases 6 | {:test 7 | {:extra-paths ["test"]} 8 | :build 9 | {:deps {io.github.clojure/tools.build {:git/tag "v0.7.5" :git/sha "34727f7"} 10 | slipset/deps-deploy {:mvn/version "0.2.0"}} 11 | :paths ["resources" "src"] 12 | :ns-default weavejester.build.tool}}} 13 | -------------------------------------------------------------------------------- /project.edn: -------------------------------------------------------------------------------- 1 | {:lib io.github.weavejester/build 2 | :description "Clojure build library for tools.deps" 3 | :url "https://github.com/weavejester/build" 4 | :licenses 5 | [{:name "Eclipse Public License" 6 | :url "http://www.eclipse.org/legal/epl-v10.html"}]} 7 | -------------------------------------------------------------------------------- /resources/weavejester/build/bb.edn.tmpl: -------------------------------------------------------------------------------- 1 | {:deps {io.github.weavejester/build VERSION} 2 | :tasks 3 | {clean weavejester.build.tasks/clean 4 | deploy weavejester.build.tasks/deploy 5 | jar weavejester.build.tasks/jar 6 | lint weavejester.build.tasks/lint 7 | outdated weavejester.build.tasks/outdated 8 | repl weavejester.build.tasks/repl 9 | test weavejester.build.tasks/test 10 | uberjar weavejester.build.tasks/uberjar}} 11 | -------------------------------------------------------------------------------- /resources/weavejester/build/project.edn.tmpl: -------------------------------------------------------------------------------- 1 | {:lib LIBRARY_NAME 2 | :description "FIXME" 3 | :url "https://FIXME" 4 | :licenses 5 | [{:name "Eclipse Public License" 6 | :url "http://www.eclipse.org/legal/epl-v10.html"}]} 7 | -------------------------------------------------------------------------------- /resources/weavejester/build/tests.edn: -------------------------------------------------------------------------------- 1 | #kaocha/v1 {:reporter [kaocha.report.progress/report]} 2 | -------------------------------------------------------------------------------- /src/weavejester/build/git.clj: -------------------------------------------------------------------------------- 1 | (ns weavejester.build.git 2 | (:require [clojure.string :as str] 3 | [clojure.java.shell :as sh])) 4 | 5 | (defn- git [& args] 6 | (some-> (apply sh/sh "git" args) :out str/trim)) 7 | 8 | (defn default-version [] 9 | (git "describe" "--exact-match" "--abbrev=0")) 10 | 11 | (defn git-head [] 12 | (git "rev-parse" "HEAD")) 13 | 14 | (defn git-origin [] 15 | (git "config" "--get" "remote.origin.url")) 16 | 17 | (defn- parse-github-url [url] 18 | (or (re-matches #"(?:[A-Za-z-]{2,}@)?github.com:([^/]+)/([^/]+).git" url) 19 | (re-matches #"[^:]+://(?:[A-Za-z-]{2,}@)?github.com/([^/]+)/([^/]+?)(?:.git)?" url))) 20 | 21 | (defn- github-urls [url] 22 | (when-let [[_ user repo] (parse-github-url url)] 23 | {:public-clone (str "git://github.com/" user "/" repo ".git") 24 | :dev-clone (str "ssh://git@github.com/" user "/" repo ".git") 25 | :browse (str "https://github.com/" user "/" repo)})) 26 | 27 | (defn github-scm-map [] 28 | (try 29 | (let [origin (git-origin) 30 | head (git-head) 31 | urls (github-urls origin)] 32 | (cond-> {:url (:browse urls)} 33 | (:public-clone urls) (assoc :connection (str "scm:git:" (:public-clone urls))) 34 | (:dev-clone urls) (assoc :developerConnection (str "scm:git:" (:dev-clone urls))) 35 | head (assoc :tag head))) 36 | (catch java.io.FileNotFoundException _))) 37 | -------------------------------------------------------------------------------- /src/weavejester/build/project.clj: -------------------------------------------------------------------------------- 1 | (ns weavejester.build.project 2 | (:require [clojure.java.io :as io] 3 | [weavejester.build.git :as git])) 4 | 5 | (defn- read-project [] 6 | (read-string (slurp "project.edn"))) 7 | 8 | (def ^:private default-project 9 | {:src-dirs ["src"] 10 | :resource-dirs ["resources"] 11 | :target-dir "target"}) 12 | 13 | (defn- default-class-dir [{:keys [target-dir]}] 14 | (str (io/file target-dir "classes"))) 15 | 16 | (defn- default-jar-file [{:keys [lib target-dir version]}] 17 | (str (io/file target-dir (str lib "-" version ".jar")))) 18 | 19 | (defn- default-uberjar-file [{:keys [lib target-dir version]}] 20 | (str (io/file target-dir (str lib "-" version "-uber.jar")))) 21 | 22 | (defn- update-derived-defaults 23 | [{:keys [class-dir jar-file uber-file version scm] :as project}] 24 | (cond-> project 25 | (nil? version) (assoc :version (git/default-version)) 26 | (nil? scm) (assoc :scm (git/github-scm-map)) 27 | (nil? class-dir) (as-> p (assoc p :class-dir (default-class-dir p))) 28 | (nil? jar-file) (as-> p (assoc p :jar-file (default-jar-file p))) 29 | (nil? uber-file) (as-> p (assoc p :uber-file (default-uberjar-file p))))) 30 | 31 | (def project 32 | (delay (->> (read-project) 33 | (merge default-project) 34 | (update-derived-defaults)))) 35 | -------------------------------------------------------------------------------- /src/weavejester/build/tasks.clj: -------------------------------------------------------------------------------- 1 | (ns weavejester.build.tasks 2 | (:refer-clojure :exclude [test]) 3 | (:require [babashka.fs :as fs] 4 | [babashka.pods :as pods] 5 | [babashka.tasks :as bb] 6 | [weavejester.build.project :as p])) 7 | 8 | (defn- run-clojure [deps ns args] 9 | (apply bb/clojure "-Sdeps" (pr-str {:deps deps}) "-M" "-m" (str ns) args)) 10 | 11 | (defn clean 12 | "Remove the target folder" 13 | [] 14 | (fs/delete-tree (:target-dir @p/project))) 15 | 16 | (defn jar 17 | "Create a jar file from the project" 18 | [] 19 | (bb/clojure "-Tbuild" "jar")) 20 | 21 | (defn lint 22 | "Lint the source files" 23 | [] 24 | (pods/load-pod "clj-kondo") 25 | (require 'pod.borkdude.clj-kondo) 26 | (let [lint-fn (resolve 'pod.borkdude.clj-kondo/run!) 27 | print-fn (resolve 'pod.borkdude.clj-kondo/print!) 28 | results (let [src (:src-dirs @p/project)] 29 | (-> (lint-fn {:lint src}) 30 | (doto print-fn)))] 31 | (when (-> results :findings seq) 32 | (throw (ex-info "Lint warnings found, exiting with status code 1" 33 | {:babashka/exit 1}))))) 34 | 35 | (defn outdated 36 | "Find outdated dependencies" 37 | [& args] 38 | (run-clojure '{com.github.liquidz/antq {:mvn/version "1.3.1"}} 39 | 'antq.core args)) 40 | 41 | (defn repl 42 | "Start a REPL for the project" 43 | [& args] 44 | (run-clojure '{com.bhauman/rebel-readline {:mvn/version "0.1.4"}} 45 | 'rebel-readline.main args)) 46 | 47 | (defn test 48 | "Run tests for the project" 49 | [& args] 50 | (run-clojure '{lambdaisland/kaocha {:mvn/version "1.60.945"}} 51 | 'kaocha.runner args)) 52 | 53 | (defn uberjar 54 | "Create an uberjar with the project and dependencies" 55 | [] 56 | (bb/clojure "-Tbuild" "uberjar")) 57 | 58 | (defn deploy 59 | "Deploy an uberjar to Clojars" 60 | [] 61 | (bb/clojure "-Tbuild" "deploy")) 62 | -------------------------------------------------------------------------------- /src/weavejester/build/tool.clj: -------------------------------------------------------------------------------- 1 | (ns weavejester.build.tool 2 | (:require [clojure.edn :as edn] 3 | [clojure.java.io :as io] 4 | [clojure.string :as str] 5 | [clojure.tools.build.api :as b] 6 | [deps-deploy.deps-deploy :as deploy] 7 | [weavejester.build.project :as p] 8 | [weavejester.build.write-pom :as pom])) 9 | 10 | (defn- find-self-version [] 11 | (let [basis (-> (System/getProperty "clojure.basis") slurp edn/read-string) 12 | lib (-> basis :libs (get 'com.github.weavejester/build))] 13 | (select-keys lib [:git/sha :git/tag]))) 14 | 15 | (defn- replace-template-vars [text vars] 16 | (reduce-kv (fn [s k v] (str/replace s k v)) text vars)) 17 | 18 | (defn- write-file 19 | ([src dest] 20 | (write-file src dest identity)) 21 | ([src dest xform] 22 | (if (.exists (io/file b/*project-root* dest)) 23 | (println "Skipping" dest "as it already exists") 24 | (let [text (xform (slurp (io/resource src)))] 25 | (b/write-file {:path dest, :string text}) 26 | (println "Written " dest))))) 27 | 28 | (defn- write-template [src dest vars] 29 | (write-file src dest #(replace-template-vars % vars))) 30 | 31 | (defn- write-bb-edn [] 32 | (write-template "weavejester/build/bb.edn.tmpl" "bb.edn" 33 | {"VERSION" (pr-str (find-self-version))})) 34 | 35 | (defn- write-project-edn [] 36 | (write-template "weavejester/build/project.edn.tmpl" "project.edn" 37 | {"LIBRARY_NAME" "test"})) 38 | 39 | (defn- write-tests-edn [] 40 | (write-file "weavejester/build/tests.edn" "tests.edn" )) 41 | 42 | (defn init [_] 43 | (write-bb-edn) 44 | (write-project-edn) 45 | (write-tests-edn)) 46 | 47 | (defn- copy-to-target [{:keys [src-dirs resource-dirs class-dir]}] 48 | (b/copy-dir {:src-dirs (into src-dirs resource-dirs) 49 | :target-dir class-dir})) 50 | 51 | (defn jar [_] 52 | (doto (assoc @p/project :basis (b/create-basis)) 53 | (pom/write-pom) 54 | (copy-to-target) 55 | (b/jar))) 56 | 57 | (defn uberjar [_] 58 | (doto (assoc @p/project :basis (b/create-basis)) 59 | (pom/write-pom) 60 | (copy-to-target) 61 | (b/compile-clj) 62 | (b/uber))) 63 | 64 | (defn deploy [m] 65 | (jar m) 66 | (deploy/deploy 67 | {:artifact (:jar-file @p/project) 68 | :pom-file (io/file (pom/pom-dir @p/project) "pom.xml") 69 | :installer :remote 70 | :sign-releases? true 71 | :repository 72 | {"clojars" {:url "https://clojars.org/repo" 73 | :username (System/getenv "CLOJARS_USERNAME") 74 | :password (System/getenv "CLOJARS_PASSWORD")}}})) 75 | 76 | (defn evalstr [{:keys [sexp]}] 77 | (eval sexp)) 78 | -------------------------------------------------------------------------------- /src/weavejester/build/write_pom.clj: -------------------------------------------------------------------------------- 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 weavejester.build.write-pom 10 | (:require [clojure.java.io :as jio] 11 | [clojure.string :as str] 12 | [clojure.data.xml :as xml] 13 | [clojure.tools.deps.alpha.util.maven :as maven] 14 | [clojure.tools.deps.alpha.util.io :refer [printerrln]] 15 | [clojure.tools.build.api :as api] 16 | [clojure.tools.build.util.file :as file])) 17 | 18 | (xml/alias-uri 'pom "http://maven.apache.org/POM/4.0.0") 19 | 20 | (defn- to-dep 21 | [[lib {:keys [mvn/version exclusions optional] :as coord}]] 22 | (let [[group-id artifact-id classifier] (maven/lib->names lib)] 23 | (if version 24 | (cond-> 25 | [::pom/dependency 26 | [::pom/groupId group-id] 27 | [::pom/artifactId artifact-id] 28 | [::pom/version version]] 29 | 30 | classifier 31 | (conj [::pom/classifier classifier]) 32 | 33 | (seq exclusions) 34 | (conj [::pom/exclusions 35 | (map (fn [excl] 36 | [::pom/exclusion 37 | [::pom/groupId (or (namespace excl) (name excl))] 38 | [::pom/artifactId (name excl)]]) 39 | exclusions)]) 40 | 41 | optional 42 | (conj [::pom/optional "true"])) 43 | (printerrln "Skipping coordinate:" coord)))) 44 | 45 | (defn- gen-deps [deps] 46 | [::pom/dependencies (map to-dep deps)]) 47 | 48 | (defn- gen-source-dir [path] 49 | [::pom/sourceDirectory path]) 50 | 51 | (defn- to-resource [resource] 52 | [::pom/resource [::pom/directory resource]]) 53 | 54 | (defn- gen-resources [rpaths] 55 | [::pom/resources (map to-resource rpaths)]) 56 | 57 | (defn- to-repo [[name repo]] 58 | [::pom/repository 59 | [::pom/id name] 60 | [::pom/url (:url repo)]]) 61 | 62 | (defn- gen-repos [repos] 63 | [::pom/repositories (map to-repo repos)]) 64 | 65 | (defn- gen-pom 66 | [{:keys [deps src-paths resource-paths repos group artifact version scm 67 | description url licenses] 68 | :or {version "0.1.0"}}] 69 | (let [[path & paths] src-paths] 70 | (xml/sexp-as-element 71 | [::pom/project 72 | {:xmlns "http://maven.apache.org/POM/4.0.0" 73 | (keyword "xmlns:xsi") "http://www.w3.org/2001/XMLSchema-instance" 74 | (keyword "xsi:schemaLocation") "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"} 75 | [::pom/modelVersion "4.0.0"] 76 | [::pom/packaging "jar"] 77 | [::pom/groupId group] 78 | [::pom/artifactId artifact] 79 | [::pom/version version] 80 | [::pom/name artifact] 81 | (when description 82 | [::pom/description description]) 83 | (when url 84 | [::pom/url url]) 85 | (when licenses 86 | [::pom/licenses 87 | (for [{:keys [name url]} licenses] 88 | [::pom/license 89 | [::pom/name name] 90 | [::pom/url url]])]) 91 | (gen-deps deps) 92 | (when (or path (seq resource-paths)) 93 | (when (seq paths) (apply printerrln "Skipping paths:" paths)) 94 | [::pom/build 95 | (when path (gen-source-dir path)) 96 | (when (seq resource-paths) (gen-resources resource-paths))]) 97 | (gen-repos repos) 98 | (when scm 99 | (let [{:keys [connection developerConnection tag url]} scm] 100 | [::pom/scm 101 | (when connection [::pom/connection connection]) 102 | (when developerConnection [::pom/developerConnection developerConnection]) 103 | (when tag [::pom/tag tag]) 104 | (when url [::pom/url url])]))]))) 105 | 106 | (defn- libs->deps [libs] 107 | (reduce-kv 108 | (fn [ret lib {:keys [dependents] :as coord}] 109 | (if (seq dependents) 110 | ret 111 | (assoc ret lib coord))) 112 | {} libs)) 113 | 114 | (defn- basis-repos [{:mvn/keys [repos]}] 115 | (remove #(= "https://repo1.maven.org/maven2/" (-> % val :url)) repos)) 116 | 117 | (defn meta-maven-path 118 | [params] 119 | (let [{:keys [lib]} params 120 | pom-file (jio/file "META-INF" "maven" (namespace lib) (name lib))] 121 | (.toString pom-file))) 122 | 123 | (defn pom-dir [{:keys [class-dir lib]}] 124 | (let [class-dir-file (api/resolve-path class-dir) 125 | pom-dir (meta-maven-path {:lib lib})] 126 | (file/ensure-dir (jio/file class-dir-file pom-dir)))) 127 | 128 | (defn write-pom 129 | [{:keys [basis lib version scm src-dirs resource-dirs repos description url 130 | licenses] :as opts}] 131 | (let [{:keys [libs]} basis 132 | root-deps (libs->deps libs) 133 | repos (or repos (basis-repos basis)) 134 | pom (gen-pom 135 | (cond-> {:deps root-deps 136 | :src-paths src-dirs 137 | :resource-paths resource-dirs 138 | :repos repos 139 | :group (namespace lib) 140 | :artifact (name lib)} 141 | version (assoc :version version) 142 | scm (assoc :scm scm) 143 | description (assoc :description description) 144 | url (assoc :url url) 145 | licenses (assoc :licenses licenses))) 146 | pom-dir-file (pom-dir opts)] 147 | (spit (jio/file pom-dir-file "pom.xml") (xml/indent-str pom)) 148 | (spit (jio/file pom-dir-file "pom.properties") 149 | (str/join (System/lineSeparator) 150 | ["# Generated by dev.weavejester/build" 151 | (format "# %tc" (java.util.Date.)) 152 | (format "version=%s" version) 153 | (format "groupId=%s" (namespace lib)) 154 | (format "artifactId=%s" (name lib))])))) 155 | -------------------------------------------------------------------------------- /test/weavejester/build_test.clj: -------------------------------------------------------------------------------- 1 | (ns weavejester.build-test 2 | (:require [clojure.test :refer [deftest is]])) 3 | 4 | (deftest success-test 5 | (is (= 1 1))) 6 | -------------------------------------------------------------------------------- /tests.edn: -------------------------------------------------------------------------------- 1 | #kaocha/v1 {:reporter [kaocha.report.progress/report]} 2 | --------------------------------------------------------------------------------