-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
205 additions
and
12 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
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,6 @@ | ||
{:paths ["src" "test" "resource" "resources" "other"] | ||
:aliases {:some-alias {:extra-paths ["the-extra-path"] | ||
:extra-deps {refactor-nrepl/refactor-nrepl {:mvn/version "3.2.0"}}}} | ||
:deps {org.clojure/clojure {:mvn/version "1.10.3"} | ||
org.clojars.brenton/google-diff-match-patch {:mvn/version "0.1"} | ||
org.ow2.asm/asm-all {:mvn/version "5.2"}}} |
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,128 @@ | ||
(ns cider.enrich-classpath.clojure | ||
(:require | ||
[cider.enrich-classpath :as enrich-classpath] | ||
[clojure.java.io :as io] | ||
[clojure.string :as string] | ||
[clojure.tools.deps.alpha :as tools.deps]) | ||
(:import | ||
(java.io File))) | ||
|
||
(defn commandize [args clojure] | ||
(->> args | ||
(apply vector clojure) | ||
(string/join " "))) | ||
|
||
(defn impl ^String [clojure deps-edn-filename pwd args] | ||
{:pre [(vector? args)]} ;; for conj | ||
(let [aliases (into #{} | ||
(comp (mapcat (fn [^String s] | ||
(when (-> s (.startsWith "-A")) | ||
(-> s | ||
(string/replace #"-A:" "") | ||
(string/replace #"-A" "") | ||
(string/split #":"))))) | ||
(map keyword)) | ||
args) | ||
{:keys [paths deps] | ||
{:keys [extra-paths extra-deps]} :classpath-args | ||
:as basis} (tools.deps/create-basis {:project (-> pwd (io/file deps-edn-filename) str) | ||
:aliases aliases}) | ||
paths (into paths extra-paths) | ||
deps (into deps extra-deps) | ||
original-paths-set (set paths) | ||
original-deps-set (->> deps (map first) set) | ||
{:keys [dependencies | ||
resource-paths]} (enrich-classpath/middleware {:dependencies (->> deps | ||
(map (fn [[artifact-name {mv :mvn/version}]] | ||
[artifact-name mv])) | ||
(into {})) | ||
;; XXX | ||
;; :repositories repositories | ||
;; :managed-dependencies managed-dependencies | ||
:resource-paths paths}) | ||
{:keys [classpath]} (tools.deps/calc-basis {:paths paths | ||
:deps (->> dependencies | ||
(map (fn [[k v marker classifier]] | ||
[(cond-> k | ||
(#{:classifier} marker) | ||
(str "$" classifier) | ||
|
||
true symbol) | ||
{:mvn/version v}])) | ||
(into {}))}) | ||
;; Avoids | ||
;; `WARNING: Use of :paths external to the project has been deprecated, please remove: ...`: | ||
classpath (->> resource-paths | ||
(remove original-paths-set) | ||
(map (fn [entry] | ||
{entry {:path-key ::_}})) | ||
(into classpath)) | ||
classpath (->> classpath | ||
(sort-by (fn [[^String entry {:keys [lib-name path-key]}]] | ||
{:pre [(or lib-name path-key)]} | ||
(let [original-path? (and path-key (original-paths-set entry))] | ||
(cond | ||
(and original-path? | ||
(-> entry (.contains "src"))) | ||
(str "0" entry) | ||
|
||
(and original-path? | ||
(-> entry (.contains "test"))) | ||
(str "1" entry) | ||
|
||
(and original-path? | ||
(-> entry (.contains "resource"))) | ||
(str "3" entry) | ||
|
||
original-path? | ||
(str "2" entry) | ||
|
||
;; Let the original Clojure .clj libs go before any other deps - | ||
;; makes it less likely for other libs to overwrite Clojure stuff: | ||
(and lib-name | ||
(-> entry (.contains "/org/clojure/")) | ||
(not (-> lib-name str (.contains "$")))) | ||
(str "4" lib-name) | ||
|
||
(original-deps-set lib-name) | ||
(str "5" lib-name) | ||
|
||
(and lib-name | ||
(not (-> lib-name str (.contains "$")))) | ||
(str "6" lib-name) | ||
|
||
(and path-key | ||
(-> entry (.contains "unzipped-jdk-sources"))) | ||
(str "10" entry) | ||
|
||
path-key ;; JDK sources | ||
(str "7" entry) | ||
|
||
lib-name ;; artifacts with sources or javadocs | ||
(str "8" lib-name) | ||
|
||
true ;; shouldn't happen, anyway we leave something reasonable | ||
(str "9" (or lib-name path-key)))))) | ||
(map first) | ||
(string/join File/pathSeparator))] | ||
(-> args | ||
(conj "-Sforce" "-Srepro" "-J-XX:-OmitStackTraceInFastThrow" "-J-Dclojure.main.report=stderr" "-Scp" classpath) | ||
(commandize clojure)))) | ||
|
||
(defn -main [clojure pwd & args] | ||
(println (try | ||
(impl clojure "deps.edn" pwd (vec args)) | ||
(catch AssertionError e | ||
(-> e .printStackTrace) | ||
(commandize args clojure)) | ||
(catch Exception e | ||
(-> e .printStackTrace) | ||
(commandize args clojure)))) | ||
(shutdown-agents) | ||
(System/exit 0)) | ||
|
||
(comment | ||
(impl "clojure" | ||
"deps.edn" | ||
(System/getProperty "user.dir") | ||
["-Asome-alias"])) |
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,40 @@ | ||
#!/usr/bin/env bash | ||
set -Eeuxo pipefail | ||
|
||
clojure="$1" | ||
# remove it from "$@"/"$*": | ||
shift | ||
|
||
file="deps.edn" | ||
|
||
if [ ! -e $file ]; then | ||
echo "$file not found." | ||
$clojure "$@" | ||
elif [[ "$*" == *Spath* ]]; then | ||
echo "-Spath passed; skipping enrich-classpath." | ||
$clojure "$@" | ||
elif [[ "$*" == *Scp* ]]; then | ||
echo "-Scp passed; skipping enrich-classpath." | ||
$clojure "$@" | ||
else | ||
|
||
here="$PWD" | ||
|
||
# don't let local deps.edn files interfere: | ||
cd | ||
|
||
output=$("$clojure" -Sforce -Srepro -J-XX:-OmitStackTraceInFastThrow -J-Dclojure.main.report=stderr -Sdeps '{:deps {mx.cider/enrich-classpath {:mvn/version "1.7.0"}}}' -M -m cider.enrich-classpath.clojure "$clojure" "$here" "$@") | ||
cmd=$(tail -n1 <(echo "$output")) | ||
|
||
cd "$here" | ||
|
||
if grep --silent "^$clojure" <<< "$cmd"; then | ||
$cmd | ||
else | ||
# Print errors: | ||
echo "$output" | ||
$clojure "$@" | ||
fi | ||
# (System/getProperty "java.class.path") | ||
|
||
fi |
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,19 @@ | ||
(ns integration.cider.enrich-classpath.clojure | ||
(:require | ||
[cider.enrich-classpath.clojure :as sut] | ||
[clojure.test :refer [deftest is testing]])) | ||
|
||
(deftest works | ||
(testing "Returns a valid command with an -Scp specifying an enriched classpath, carefully sorted, and honoring aliases" | ||
(let [actual (sut/impl "clojure" "sample.deps.edn" | ||
(System/getProperty "user.dir") | ||
["-Asome-alias"])] | ||
(is (-> actual (.contains "src:test:other:the-extra-path:resource:resources"))) | ||
(is (-> actual (.contains "the-extra-path"))) | ||
(is (-> actual (.contains "refactor-nrepl"))) | ||
(is (-> actual (.contains "-Scp"))) | ||
(is (-> actual (.contains "src.zip"))) | ||
(is (-> actual (.contains "-sources.jar"))) | ||
(is (-> actual (.contains "-javadoc.jar"))) | ||
(when (re-find #"^1\.8\." (System/getProperty "java.version")) | ||
(is (-> actual (.contains "unzipped-jdk-sources"))))))) |