Skip to content

Commit

Permalink
Merge pull request #15 from somecho/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
somecho authored Aug 7, 2023
2 parents 5657bce + 368eabd commit 58f6154
Show file tree
Hide file tree
Showing 15 changed files with 245 additions and 60 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
- name: Run Unit Tests
run: clojure -M:test "$@" unit

- name: Test Dispatch
run: clojure -M:test "$@" dispatch

- name: Test Resolver
run: clojure -M:test "$@" resolver

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
.lsp
.nrepl-port
target
classes
.env
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ You can also use Depo as a library.
```
For more information, see the [API documentation](https://cljdoc.org/d/org.clojars.some/depo/0.0.12).

## Installation
Depo can be built and installed as a native image:
1. Install [GraalVM](https://github.com/graalvm/graalvm-ce-builds/releases/)
2. Clone this repo
3. Run `clj -T:build native-image` or, if you have babashka installed, `bb native-image`
4. The binary is now in `target/`. Copy it to somewhere on your path.

## Features / Commands
To see a list of commands, run `depo --help`.

Expand Down
11 changes: 11 additions & 0 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{:tasks
{:requires ([babashka.process :refer [shell]])
unit (shell "clojure" "-M:test" "unit")
e2e (shell "clojure" "-M:test" "e2e")
resolver (shell "clojure" "-M:test" "resolver")
dispatch (shell "clojure" "-M:test" "dispatch")
generate-snapshots (shell "clojure" "-T:generate all-snapshots")
native-image (shell "clojure" "-T:build" "native-image")}}



31 changes: 30 additions & 1 deletion build.clj
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
(ns build
(:require [clojure.tools.build.api :as b]
[clojure.java.shell :refer [sh]]
[deps-deploy.deps-deploy :as dd]))

(def lib 'org.clojars.some/depo)
(def version "0.4.31")
(def version "0.4.39")
(def jar-file (format "target/%s-%s.jar" (name lib) version))
(def class-dir "target/classes")
(def url "https://github.com/somecho/depo")
(def connection (str "scm:git:" url ".git"))
(def basis (b/create-basis {:project "deps.edn"}))

(defn clean [_]
(b/delete {:path "target"}))
Expand All @@ -31,3 +33,30 @@
(dd/deploy {:installer :remote
:artifact jar-file
:pom-file (b/pom-path {:lib lib :class-dir class-dir})}))

(defn uberjar [_]
(clean nil)
(b/copy-dir {:src-dirs ["src"]
:target-dir class-dir})
(b/compile-clj {:basis basis
:src-dirs ["src"]
:class-dir class-dir})
(b/uber {:class-dir class-dir
:uber-file jar-file
:basis basis
:main 'depo.core}))

(defn native-image [_]
(println "creating uberjar...")
(sh "clojure" "-T:build" "uberjar")
(println "Uberjar created")
(println "creating native image")
(sh "native-image"
"-jar" (str "target/depo-" version ".jar")
"--no-fallback"
"--features=clj_easy.graal_build_time.InitClojureClasses"
"--enable-https"
"-H:ReflectionConfigurationFiles=reflect-config.json"
"target/depo")
(println "Native image created"))

8 changes: 4 additions & 4 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{:paths ["src"],
:deps {rewrite-clj/rewrite-clj {:mvn/version "1.1.47"},
cli-matic/cli-matic {:mvn/version "0.5.4"},
clj-http/clj-http {:mvn/version "3.12.3"},
org.clj-commons/clj-http-lite {:mvn/version "1.0.13"}
metosin/malli {:mvn/version "0.11.0"},
zprint/zprint {:mvn/version "1.2.7"}}
zprint/zprint {:mvn/version "1.2.7"}
com.github.clj-easy/graal-build-time {:mvn/version "1.0.5"}}
:aliases
{:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.85.1342"}}
:main-opts ["-m" "kaocha.runner"]}
:build {:extra-deps {io.github.clojure/tools.build {:mvn/version
"0.9.4"},
:build {:extra-deps {io.github.clojure/tools.build {:mvn/version "0.9.4"},
slipset/deps-deploy {:mvn/version "RELEASE"}},
:ns-default build}
:generate {:ns-default generate}}}
8 changes: 8 additions & 0 deletions reflect-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[{
"name": "java.lang.String",
"allPublicMethods": true
},
{
"name": "com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl",
"allPublicMethods": true
}]
31 changes: 18 additions & 13 deletions src/depo/core.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(ns ^:no-doc depo.core
(:gen-class)
(:require [cli-matic.core :refer [run-cmd]]
[depo.dispatch :as dd]
[depo.errors :as e]
Expand All @@ -8,39 +9,43 @@
(let [args _arguments
config-path (if file file (dd/get-config))]
(if-not (empty? args)
(do (mapv #(dd/apply-operation {:config-path config-path
:id %
:operation :add}) args)
(do (mapv #(spit config-path
(dd/apply-operation {:config-path config-path
:id %
:operation :add})) args)
(println "Done!"))
(println (e/err :no-args)))))

(defn remove-cmd [{:keys [_arguments file]}]
(let [args _arguments
config-path (if file file (dd/get-config))]
(if-not (empty? args)
(do (mapv #(dd/apply-operation {:config-path config-path
:id %
:operation :remove}) args)
(do (mapv #(spit config-path
(dd/apply-operation {:config-path config-path
:id %
:operation :remove})) args)
(println "Done!"))
(println (e/err :no-args)))))

(defn update-cmd [{:keys [_arguments file]}]
(let [args _arguments
config-path (if file file (dd/get-config))]
(if (empty? args)
(do (mapv #(dd/apply-operation {:config-path config-path
:id %
:operation :update})
(do (mapv #(spit config-path
(dd/apply-operation {:config-path config-path
:id %
:operation :update}))
(zo/get-all-dependency-names config-path))
(println "Done!"))
(mapv #(dd/apply-operation {:config-path config-path
:id %
:operation :update}) args))))
(mapv #(spit config-path
(dd/apply-operation {:config-path config-path
:id %
:operation :update})) args))))

(def CONFIGURATION
{:command "depo"
:description "Manage dependencies for Clojure projects easily"
:version "0.4.31"
:version "0.4.39"
:opts [{:as "path to configuration file"
:default nil
:option "file"
Expand Down
80 changes: 45 additions & 35 deletions src/depo/dispatch.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"Functions related to the control flow of the CLI,
as well as IO operations, such as reading and writing the config."
(:require [clojure.java.io :as io]
[depo.errors :as e]
[depo.schema :as schema]
[depo.utils :as dutils]
[depo.zoperations :as zo]
Expand Down Expand Up @@ -39,20 +40,47 @@
- `:add`
- `:remove`
- `:update`"
[{:keys [operation dep-exists identifier]
[{:keys [argument operation dep-exists identifier zloc]
:as procedure}]
(case operation
:add (if dep-exists
(ignore-pass procedure
#(zo/update-dependency procedure))
(zo/append-dependency procedure))
:remove (if dep-exists
(zo/remove-dependency procedure)
(skip-procedure identifier "is not a dependency."))
:update (if dep-exists
(ignore-pass procedure
#(zo/update-dependency procedure))
(skip-procedure procedure identifier "is not a dependency."))))
(try (case operation
:add (if dep-exists
(ignore-pass procedure
#(zo/update-dependency procedure))
(zo/append-dependency procedure))
:remove (if dep-exists
(zo/remove-dependency procedure)
(skip-procedure procedure identifier "is not a dependency."))
:update (if dep-exists
(ignore-pass procedure
#(zo/update-dependency procedure))
(skip-procedure procedure identifier "is not a dependency.")))
(catch Exception e (do (-> e
ex-data
:status
str
keyword
(e/err {:argument argument})
println)
zloc))))

(defn create-procedure
[{:keys [config-path id operation]}]
(let [project-type (dutils/get-project-type config-path)
access-keys [(dutils/create-keys project-type)]
deps (zo/get-deps (z/of-string (slurp config-path)) access-keys project-type)
deps-type (cond (z/map? deps) :map
(z/vector? deps) :vector)
{:keys [groupID artifactID]} (dutils/parse id)
identifier (symbol (dutils/create-identifier groupID artifactID deps-type))
dep-data (zo/get-dependency-data deps identifier)]
{:operation operation
:project-type project-type
:identifier identifier
:argument id
:dep-data dep-data
:dep-exists (if dep-data true false)
:deps-type deps-type
:zloc deps}))

(defn apply-operation
"Takes in a map containing
Expand All @@ -62,32 +90,14 @@
Creates a `depo.schema/PROCEDURE` map to dispatch operations.
It writes the resulting configuration into `config-path`. "
[{:keys [config-path id operation]}]
(let [config-zip (z/of-string (slurp config-path))
project-type (dutils/get-project-type config-path)
access-keys [(dutils/create-keys project-type)]
deps (zo/get-deps config-zip access-keys project-type)
{:keys [groupID artifactID]} (dutils/parse id)
deps-type (cond
(z/map? deps) :map
(z/vector? deps) :vector)
identifier (symbol (dutils/create-identifier groupID artifactID deps-type))
dependency-data (zo/get-dependency-data deps identifier)
procedure {:operation operation
:dep-exists (if dependency-data true false)
:identifier identifier
:project-type project-type
:argument id
:dep-data dependency-data
:deps-type deps-type
:zloc deps}]
[args-in]
(let [procedure (create-procedure args-in)]
(if (m/validate schema/PROCEDURE procedure)
(-> (dispatch procedure)
(z/root-string)
(zp/zprint-str {:parse-string? true
:style :indent-only})
(as-> new-conf (spit config-path new-conf)))
(println "Failed to validate procedure."))))
:style :indent-only}))
(m/explain schema/PROCEDURE procedure))))

(defn get-config
"Looks in the current directory for the following files
Expand Down
5 changes: 4 additions & 1 deletion src/depo/errors.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
:invalid-argument
(str "The argument " (:argument opts) " is invalid")
:version-not-exist
(str (:artifactID opts) " version " (:version opts) " does not exist"))))
(str (:artifactID opts) " version " (:version opts) " does not exist")
:404
(str (:argument opts) " could not be found from Clojars or Maven")
"")))
2 changes: 1 addition & 1 deletion src/depo/resolver.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns depo.resolver
(:require [clojure.string :as s]
[clj-http.client :as client]
[clj-http.lite.client :as client]
[depo.errors :as e]
[depo.utils :as dutils]
[depo.schema :as schema]))
Expand Down
6 changes: 1 addition & 5 deletions test/depo/depo_e2e_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@
(for [{:keys [name]} tests]
(io/make-parents (str "test/resources/temp/" name "/FILE"))))

(defn delete-directories []
(for [{:keys [name]} tests]
(delete-directory (io/file (str "test/resources/temp/" name)))))

(defn before-after [f]
(setup-directories)
(f)
(delete-directories))
(delete-directory (io/file TEMP-FOLDER)))

(use-fixtures :once before-after)

Expand Down
Loading

0 comments on commit 58f6154

Please sign in to comment.