/defold-robot/src/lein_plugins/tar_install.clj

https://github.com/defold/defold · Clojure · 51 lines · 35 code · 5 blank · 11 comment · 0 complexity · bf25d46590dff3fd05bb9a39a8b6ffc1 MD5 · raw file

  1. ;; Copyright 2020 The Defold Foundation
  2. ;; Licensed under the Defold License version 1.0 (the "License"); you may not use
  3. ;; this file except in compliance with the License.
  4. ;;
  5. ;; You may obtain a copy of the License, together with FAQs at
  6. ;; https://www.defold.com/license
  7. ;;
  8. ;; Unless required by applicable law or agreed to in writing, software distributed
  9. ;; under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  10. ;; CONDITIONS OF ANY KIND, either express or implied. See the License for the
  11. ;; specific language governing permissions and limitations under the License.
  12. (ns lein-plugins.tar-install
  13. (:require [clojure.java.io :as io]
  14. [clojure.string :as string])
  15. (:import [java.io ByteArrayOutputStream File FileOutputStream]
  16. [java.util.zip GZIPOutputStream]
  17. [org.apache.tools.tar TarEntry TarOutputStream]))
  18. (defn- out-stream ^TarOutputStream [tar-file]
  19. (let [os (-> tar-file
  20. (FileOutputStream.)
  21. (GZIPOutputStream.)
  22. (TarOutputStream.))]
  23. (.setLongFileMode os TarOutputStream/LONGFILE_GNU)
  24. os))
  25. (defn- add-file [os path name]
  26. (let [f (File. path)
  27. dir-names (-> name
  28. (string/split #"/")
  29. butlast
  30. vec)]
  31. (dotimes [i (count dir-names)]
  32. (let [dir (->> (subvec dir-names 0 (inc i))
  33. (string/join "/")
  34. (format "%s/"))]
  35. (.putNextEntry os (TarEntry. dir))
  36. (.closeEntry os)))
  37. (.putNextEntry os (TarEntry. f name))
  38. (io/copy f os)
  39. (.closeEntry os)))
  40. (defn tar-install [name version target-path]
  41. (let [tar-file (File. (format "../packages/%s-%s-common.tar.gz" name version))]
  42. (with-open [os (out-stream tar-file)]
  43. (add-file os (format "%s/%s-%s-standalone.jar" target-path name version) (format "share/java/%s.jar" name)))
  44. (println "Wrote" (.getCanonicalPath tar-file))))
  45. (defn -main [name version target-path]
  46. (tar-install name version target-path))