add gradle cache extractor
parent
bdd59cc199
commit
7531d14192
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/env bb
|
||||
|
||||
;;based on: https://github.com/sinsongdev/gradle-cash-to-maven-repo/blob/master/gradle_cache_to_repo.py
|
||||
|
||||
(require '[clojure.tools.cli :refer [parse-opts]])
|
||||
|
||||
(def cli-options
|
||||
[["-s" "--src DIRECTORY" "Gradle cache directory"
|
||||
:missing "Must provide a source directory"]
|
||||
["-d" "--dest DIRECTORY" "Maven repository directory"
|
||||
:missing "Must provide a destination directory"]
|
||||
["-a" "--artifact ARTIFACT" "Artifact id"]])
|
||||
|
||||
(def parsed-args (parse-opts *command-line-args* cli-options))
|
||||
(def options (:options parsed-args))
|
||||
|
||||
(def src (:src options))
|
||||
(def dest (:dest options))
|
||||
|
||||
(def filter
|
||||
(if-let [filter-option (:artifact options)]
|
||||
(str/split filter-option #":")))
|
||||
|
||||
(def group-filter (nth filter 0 nil))
|
||||
(def artifact-filter (nth filter 1 nil))
|
||||
(def version-filter (nth filter 2 nil))
|
||||
|
||||
(defn- create-path-string [& segments]
|
||||
(str/join fs/file-separator segments))
|
||||
|
||||
(defn- get-dest-dir-string [group artifact version]
|
||||
(create-path-string
|
||||
dest
|
||||
(str/replace group #"\." fs/file-separator)
|
||||
artifact
|
||||
version))
|
||||
|
||||
(defn- process-version [group artifact version]
|
||||
(if (or (nil? version-filter) (= version version-filter))
|
||||
(let [version-dir-string (create-path-string src group artifact version)
|
||||
version-dir (fs/file version-dir-string)
|
||||
hash-dirs (fs/list-dir version-dir)
|
||||
dest-dir-string (get-dest-dir-string group artifact version)]
|
||||
(fs/create-dirs (fs/file dest-dir-string))
|
||||
(doseq [hash-dir hash-dirs
|
||||
file (fs/list-dir hash-dir)]
|
||||
(fs/copy file (fs/file (create-path-string dest-dir-string (fs/file-name file))) {:replace-existing true})))))
|
||||
|
||||
(defn- process-artifact [group artifact]
|
||||
(if (or (nil? artifact-filter) (= artifact artifact-filter))
|
||||
(let [artifact-dir-string (create-path-string src group artifact)
|
||||
artifact-dir (fs/file artifact-dir-string)]
|
||||
(doseq [version-dir (fs/list-dir artifact-dir)]
|
||||
(process-version group artifact (fs/file-name version-dir))))))
|
||||
|
||||
(defn- process-group [group]
|
||||
(if (or (nil? group-filter) (= group group-filter))
|
||||
(let [group-dir-string (create-path-string src group)
|
||||
group-dir (fs/file group-dir-string)]
|
||||
(doseq [artifact-dir (fs/list-dir group-dir)]
|
||||
(process-artifact group (fs/file-name artifact-dir))))))
|
||||
|
||||
(defn- process-cache []
|
||||
(doseq [group-dir (fs/list-dir (fs/file src))]
|
||||
(process-group (fs/file-name group-dir))))
|
||||
|
||||
(if-let [errors (:errors parsed-args)]
|
||||
(doseq [error errors] (println (str "Error: " error)))
|
||||
(process-cache))
|
|
@ -0,0 +1,9 @@
|
|||
# Gradle Cache Extractor
|
||||
Extracts dependencies from your Gradle cache so you can provide them on your self-hosted Maven repository.
|
||||
You can optionally provide a dependency with `-a` so only that dependency will be extracted. It's also possible to just specify a group id or artifact id, just leave out the parts you're not interested in.
|
||||
|
||||
## Example Usage
|
||||
```bash
|
||||
./gce.clj -s "/home/schrofi/.gradle/caches/modules-2/files-2.1" -d "/home/schrofi/Documents/maven_repo" -a "org.bitbucket.consentmanager:android-consentmanager:1.3.3"
|
||||
|
||||
./gce.clj -s "/home/schrofi/.gradle/caches/modules-2/files-2.1" -d "/home/schrofi/Documents/maven_repo" -a "org.bitbucket.consentmanager:android-consentmanager"
|
Loading…
Reference in New Issue