-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from liquidz/dev
0.16.0
- Loading branch information
Showing
13 changed files
with
283 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{:rules {:indentation {:list-indent 1} | ||
:blank-lines {:insert-padding? false} | ||
:types {:enabled? false} | ||
:namespaces {:indent-size 1}}} | ||
:namespaces {:indent-size 1}} | ||
:files {:ignore #{"target"}}} | ||
; vim:ft=clojure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
/target | ||
**/.clj-kondo/.cache | ||
**/.lsp | ||
**/.gradle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
= Work with Gradle | ||
|
||
WARNING: Gradle support is experimental | ||
|
||
== Requirements | ||
|
||
* `gradle` command must be installed. | ||
** antq alone does not work. | ||
|
||
== build.gradle | ||
|
||
To work with gradle, you should update your `build.gradle` as following. | ||
|
||
[source,build.gradle] | ||
---- | ||
plugins { | ||
id 'java-library' | ||
} | ||
repositories { | ||
mavenCentral() | ||
maven { | ||
name = 'clojars' | ||
url = 'https://repo.clojars.org' | ||
} | ||
} | ||
dependencies { | ||
runtimeOnly 'org.clojure:clojure:1.10.3' | ||
runtimeOnly 'com.github.liquidz:antq:latest.release' | ||
} | ||
// OPTIONAL: Used to support detecting repositories | ||
task antq_list_repositories { | ||
doLast { | ||
project.repositories.each { println "ANTQ;" + it.name + ";" + it.url } | ||
} | ||
} | ||
// Main task to run antq | ||
task outdated(type: JavaExec) { | ||
classpath = sourceSets.main.runtimeClasspath | ||
mainClass = "clojure.main" | ||
args = ['-m', 'antq.core'] | ||
} | ||
---- | ||
|
||
Then, run `gradle outdated`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
(ns antq.dep.gradle | ||
(:require | ||
[antq.log :as log] | ||
[antq.record :as r] | ||
[antq.util.dep :as u.dep] | ||
[clojure.java.io :as io] | ||
[clojure.java.shell :as sh] | ||
[clojure.string :as str])) | ||
|
||
(def gradle-command "gradle") | ||
(def ^:private project-file "build.gradle") | ||
(def ^:private dep-regexp #"^[^-]\-+\s") | ||
|
||
(defn- get-repositories | ||
[file-path] | ||
(let [{:keys [exit out]} (sh/sh gradle-command "--build-file" file-path | ||
"antq_list_repositories")] | ||
(when (= 0 exit) | ||
(->> (str/split-lines out) | ||
(filter #(str/starts-with? % "ANTQ;")) | ||
(map #(str/split % #";" 3)) | ||
(reduce (fn [accm [_ repo-name url]] | ||
(assoc accm repo-name {:url url})) {}))))) | ||
|
||
(defn- filter-deps-from-gradle-dependencies | ||
[file-path] | ||
(let [{:keys [exit out]} (sh/sh gradle-command | ||
"--build-file" file-path | ||
"--quiet" | ||
"dependencies")] | ||
(if (= 0 exit) | ||
(->> (str/split-lines out) | ||
(filter seq) | ||
(filter #(re-seq dep-regexp %)) | ||
(map #(str/replace % dep-regexp "")) | ||
(map #(first (str/split % #" " 2))) | ||
(set)) | ||
(throw (ex-info "Failed to run gradle" {:exit exit}))))) | ||
|
||
(defn- convert-grandle-dependency | ||
"e.g. dep-str: 'org.clojure:clojure:1.10.0'" | ||
[file-path dep-str] | ||
(let [[group-id artifact-id version] (str/split dep-str #":" 3)] | ||
(when (and group-id artifact-id version) | ||
(r/map->Dependency {:project :gradle | ||
:type :java | ||
:file file-path | ||
:name (str group-id "/" artifact-id) | ||
:version version})))) | ||
|
||
(defn extract-deps | ||
[relative-file-path absolute-file-path] | ||
(try | ||
(let [repos (get-repositories absolute-file-path) | ||
deps (filter-deps-from-gradle-dependencies absolute-file-path) | ||
deps (keep #(convert-grandle-dependency relative-file-path %) deps) | ||
deps (map #(assoc % :repositories repos) deps)] | ||
deps) | ||
(catch Exception ex | ||
(log/error (.getMessage ex)) | ||
nil))) | ||
|
||
(defn load-deps | ||
([] (load-deps ".")) | ||
([dir] | ||
(let [file (io/file dir project-file)] | ||
(when (.exists file) | ||
(extract-deps (u.dep/relative-path file) | ||
(.getAbsolutePath file)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
(ns antq.dep.gradle-test | ||
(:require | ||
[antq.dep.gradle :as sut] | ||
[antq.record :as r] | ||
[clojure.java.io :as io] | ||
[clojure.test :as t])) | ||
|
||
(def ^:private file-path | ||
"path/to/build.gradle") | ||
|
||
(def ^:private expected-repos | ||
{"MavenRepo" {:url "https://repo.maven.apache.org/maven2/"} | ||
"clojars" {:url "https://repo.clojars.org"}}) | ||
|
||
(defn- java-dependency | ||
[m] | ||
(r/map->Dependency (merge {:project :gradle | ||
:type :java | ||
:file file-path | ||
:repositories expected-repos} | ||
m))) | ||
|
||
(def ^:private defined-deps | ||
[(java-dependency {:name "org.ajoberstar/jovial" :version "0.3.0"}) | ||
(java-dependency {:name "org.clojure/tools.namespace" :version "1.0.0"}) | ||
(java-dependency {:name "org.clojure/clojure" :version "1.10.0"})]) | ||
|
||
(t/deftest extract-deps-test | ||
(let [deps (sut/extract-deps | ||
file-path | ||
(.getPath (io/resource "dep/build.gradle"))) | ||
defined-deps (set defined-deps) | ||
actual-deps (set deps)] | ||
;; NOTE: Gradle on local additionally detects `nrepl/nrepl` | ||
;; And also, gradle on GitHub Actions additionally detects `org.clojure/java.classpath` | ||
;; So we check only dependencies which is explicitly defined in buld.gradle. | ||
(t/is (every? #(contains? actual-deps %) defined-deps)))) | ||
|
||
(t/deftest extract-deps-without-repositories-test | ||
(let [deps (sut/extract-deps | ||
file-path | ||
(.getPath (io/resource "dep/build_no_repo.gradle"))) | ||
defined-deps (->> defined-deps | ||
(map #(assoc % :repositories nil)) | ||
(set)) | ||
actual-deps (set deps)] | ||
(t/is (every? #(contains? actual-deps %) defined-deps)))) | ||
|
||
(t/deftest extract-deps-command-error-test | ||
(with-redefs [sut/gradle-command "__non-existing-command__"] | ||
(let [deps (sut/extract-deps | ||
file-path | ||
(.getPath (io/resource "dep/build.gradle")))] | ||
(t/is (nil? deps))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
plugins { | ||
id 'java-library' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
maven { | ||
name = 'clojars' | ||
url = 'https://repo.clojars.org' | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation 'org.clojure:clojure:1.10.0' | ||
|
||
testRuntimeOnly 'org.ajoberstar:jovial:0.3.0' | ||
|
||
testImplementation 'org.clojure:tools.namespace:1.0.0' | ||
} | ||
|
||
task antq_list_repositories { | ||
doLast { | ||
project.repositories.each { println "ANTQ;" + it.name + ";" + it.url } | ||
} | ||
} |
Oops, something went wrong.