lucid.package project packaging and dependencies

Author: Chris Zheng  (z@caudate.me)
Date: 29 June 2017
Repository: https://www.github.com/zcaudate/lucidity
Version: 1.3.13

1    Introduction

lucid.package allows for of the project, either through installlation, deployment or dependency management

1.1    Installation

Add to project.clj dependencies:

[im.chit/lucid.package "1.3.13"]

All functionality is in the lucid.package namespace:

(use 'lucid.package)

2    Index

3    API

3.1    Dependencies



list-dependencies ^

list the dependencies for a particular coordinate

v 1.2
(defn list-dependencies
  ([coordinates]
   (list-dependencies coordinates {}))
  ([coordinates {:keys [repositories] :as opts}]
   (->> coordinates
        (map (fn [coord]
               (-> (aether/aether opts)
                   (aether/resolve-dependencies coord))))
        (apply set/union)
        sort
        vec)))
link
(list-dependencies '[[im.chit/hara.test "2.4.8"]]) => '[[im.chit/hara.class.enum "2.4.8"] [im.chit/hara.class.inheritance "2.4.8"] [im.chit/hara.common.checks "2.4.8"] [im.chit/hara.common.error "2.4.8"] [im.chit/hara.common.primitives "2.4.8"] [im.chit/hara.common.string "2.4.8"] [im.chit/hara.data.map "2.4.8"] [im.chit/hara.data.seq "2.4.8"] [im.chit/hara.event "2.4.8"] [im.chit/hara.io.ansii "2.4.8"] [im.chit/hara.io.file "2.4.8"] [im.chit/hara.io.project "2.4.8"] [im.chit/hara.namespace.import "2.4.8"] [im.chit/hara.protocol.string "2.4.8"] [im.chit/hara.string.case "2.4.8"] [im.chit/hara.test "2.4.8"]]

resolve-with-dependencies ^

resolves an entry with all artifact dependencies

v 1.2
(defn resolve-with-dependencies
  ([x context] (resolve-with-dependencies x context {}))
  ([x context {:keys [repositories] :as opts}]
   (let [resolve-entry (fn [x context]
                         (classpath/resolve-entry x context {:tag :coord}))]
     (cond (string? context)
           (->> (list-dependencies [context] opts)
                (resolve-entry x))

           (vector? context)
           (let [n (first context)]
             (cond (or (string? n)
                       (instance? IPersistentVector n))
                   (resolve-entry x context)

                   (symbol? n)
                   (->> (list-dependencies [context] repositories)
                        (resolve-entry x))))

           :else
           (throw (Exception. (str "Not supported: " x " " context)))))))
link
(resolve-with-dependencies 'hara.data.map '[im.chit/hara.test "2.4.8"]) => '[[im.chit/hara.data.map "2.4.8"] "hara/data/map.clj"]

3.2    Pull



pull ^

pulls down the necessary dependencies from maven and adds it to the project

v 1.1
(defn pull
  [coord]
  (let [deps (list-dependencies [coord])]
    (doseq [dep deps]
      (add-url (.getClassLoader clojure.lang.RT)
               (java.net.URL. (str "file:" (classpath/artifact :path dep)))))
    deps))
link
(pull '[org.clojure/core.match "0.2.2"]) => '[[org.clojure/core.cache "0.6.3"] [org.clojure/core.match "0.2.2"] [org.clojure/core.memoize "0.5.6"] [org.clojure/data.priority-map "0.0.2"] [org.clojure/tools.analyzer "0.1.0-beta12"] [org.clojure/tools.analyzer.jvm "0.1.0-beta12"] [org.ow2.asm/asm-all "4.1"]]

pull is one of the most useful functions for exploring any clojure library. How many times have you forgotten a library dependency for project.clj and then had to restart your nrepl? pull takes care of the dependencies for the project:

(require 'schema.core)
;; java.io.FileNotFoundException: Could not locate hiccup/core__init.class or hiccup/core.clj on classpath:
  
(pull '[prismatic/schema "1.1.3"])
=> '[[prismatic/schema "1.1.3"]]
  
(use 'schema.core)
  
(validate Num "hello")
=> (throws)

3.3    Project



compile-project ^

creates the jar and pom files

v 1.2
(defn compile-project
  [project]
  (let [jar-file (jar/generate-jar project)
        pom-file (pom/generate-pom project)]
    [jar-file pom-file]))
link
(compile-project (project/project))

deploy-project ^

creates the jar and pom files and deploys to clojars

v 1.2
(defn deploy-project
  ([project]
   (deploy-project project {}))
  ([project {:keys [id authentication]
             :or {id "clojars"}}]
   (let [[jar-file pom-file] (compile-project project)
         aether   (aether/aether)
         repository (->> (:repositories aether)
                         (filter #(-> % :id (= id)))
                         first)
         repository (add-authentication repository {:manual authentication})
         artifacts  [{:file jar-file
                      :extension "jar"}
                     {:file pom-file
                      :extension "pom"}]
         signing  (-> user/LEIN-PROFILE
                      slurp
                      read-string
                      (get-in [:user :signing :gpg-key]))
         
         artifacts (cond-> artifacts
                     signing
                     (->> (map #(sign-file % {:signing signing}))
                          (concat artifacts))
                     true
                     (add-digest))]
     (-> project
         (select-keys [:group :artifact :version])
         (->> (classpath/artifact :coord))
         (aether/deploy-artifact {:artifacts artifacts
                                  :repository repository})))))
link
(deploy-project (project/project))

install-project ^

creates the jar and pom files and installs to local-repo

v 1.2
(defn install-project
  [project]
  (let [[jar-file pom-file] (compile-project project)]
    (-> project
        (select-keys [:group :artifact :version])
        (aether/install-artifact {:artifacts [{:file jar-file
                                               :extension "jar"}
                                              {:file pom-file
                                               :extension "pom"}]}))))
link
(install-project (project/project))

generate-jar ^

creates a jar file for the project

v 1.2
(defn generate-jar
  [project]
  (let [jar-path (str (:root project)
                      "/target/"
                      (:artifact project)
                      "-"
                      (:version project) ".jar")
        _   (generate-manifest project)
        _   (fs/delete jar-path)
        jar (archive/open jar-path)]
    
    (archive/archive jar
                     (str (:root project) "/resources")
                     (fs/select (str (:root project) "/resources")
                                {:exclude [".DS_Store" fs/directory?]}))
    (archive/archive jar
                     (str (:root project) "/src")
                     (fs/select (str (:root project) "/src")
                                {:include [".clj$"]}))
    (archive/archive jar
                     (str (:root project) "/target/classes")
                     (fs/select (str (:root project) "/target/classes")
                                {:exclude [".DS_Store" fs/directory?]}))
    (archive/insert jar
                    "project.clj"
                    (str (:root project) "/project.clj"))
    (.close jar)
    jar-path))
link
(generate-jar (project/project))

generate-pom ^

generates all the pom information for the project

v 1.2
(defn generate-pom
  [project]
  (let [root (:root project)
        output (str "target/classes/META-INF/maven/"
                    (:group project)
                    "/"
                    (:artifact project))
        pom-path (str root "/target/" (:artifact project) "-" (:version project) ".pom.xml")
        xml    (pom-xml project)]
    (fs/create-directory (fs/path root output))
    (spit (str (fs/path root output "pom.xml")) xml)
    (spit (str (fs/path root output "pom.properties")) (pom-properties project))
    (spit pom-path xml)
    pom-path))
link
(pom-xml (project/project))