aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEduardo Julian2015-10-04 19:59:22 -0400
committerEduardo Julian2015-10-04 19:59:22 -0400
commit72d9dc02b2a6978ff0905843019bc563e4db8767 (patch)
tree5fea1a7aac28ebd9f9d74e6dd7846c1cae4f9db9 /src
parent171b856f378e09e8e5e6dd3528c404eb9cf9560e (diff)
- Removed the Lux source from the repo, as it now belongs to the lux/stdlib package.
- Removed de Apacke Commons Compress library, as Lux libraries will now be packaged as .jar files instead of as .tar.gz files. - The compiler no longer packages libraries, as that task will now be left for the build system.
Diffstat (limited to '')
-rw-r--r--src/lux.clj5
-rw-r--r--src/lux/lib/loader.clj24
-rw-r--r--src/lux/packager/lib.clj41
-rw-r--r--src/lux/packager/program.clj42
4 files changed, 37 insertions, 75 deletions
diff --git a/src/lux.clj b/src/lux.clj
index 4b1c15ef7..eb8729053 100644
--- a/src/lux.clj
+++ b/src/lux.clj
@@ -8,7 +8,6 @@
(:require [lux.base :as & :refer [|let |do return fail return* fail* |case]]
[lux.compiler.base :as &compiler-base]
[lux.compiler :as &compiler]
- [lux.packager.lib :as &lib]
:reload-all)
(:import (java.io File)))
@@ -19,9 +18,6 @@
(time (&compiler/compile-program program-module))
(println "Please provide a module name to compile."))
- (&/$Cons "lib" (&/$Cons lib-module (&/$Nil)))
- (&lib/package lib-module (new File &compiler-base/input-dir))
-
_
(println "Can't understand command."))
(System/exit 0)
@@ -29,5 +25,4 @@
(comment
(-main "compile" "program")
- (-main "lib" "lux")
)
diff --git a/src/lux/lib/loader.clj b/src/lux/lib/loader.clj
index 13810238a..e70576c24 100644
--- a/src/lux/lib/loader.clj
+++ b/src/lux/lib/loader.clj
@@ -11,9 +11,7 @@
FileInputStream
ByteArrayInputStream
ByteArrayOutputStream)
- java.util.zip.GZIPInputStream
- (org.apache.commons.compress.archivers.tar TarArchiveEntry
- TarArchiveInputStream)))
+ java.util.jar.JarInputStream))
;; [Utils]
(defn ^:private fetch-libs []
@@ -21,7 +19,7 @@
(.getURLs)
seq
(map #(.getFile ^java.net.URL %))
- (filter #(.endsWith ^String % ".tar.gz"))
+ (filter #(.endsWith ^String % ".jar"))
(map #(new File ^String %))))
(let [init-capacity (* 100 1024)
@@ -38,23 +36,19 @@
(defn ^:private unpackage [^File lib-file]
(let [is (->> lib-file
(new FileInputStream)
- (new GZIPInputStream)
- (new TarArchiveInputStream))]
+ (new JarInputStream))]
(loop [lib-data {}
- entry (.getNextTarEntry is)]
+ entry (.getNextJarEntry is)]
(if entry
- (recur (assoc lib-data (.getName entry) (new String (read-stream is)))
- (.getNextTarEntry is))
+ (if (.endsWith (.getName entry) ".lux")
+ (recur (assoc lib-data (.substring (.getName entry) 1) (new String (read-stream is)))
+ (.getNextJarEntry is))
+ (recur lib-data
+ (.getNextJarEntry is)))
lib-data))))
;; [Exports]
-(def lib-ext ".tar.gz")
-
(defn load []
(->> (fetch-libs)
(map unpackage)
(reduce merge {})))
-
-(comment
- (->> &/lib-dir load keys)
- )
diff --git a/src/lux/packager/lib.clj b/src/lux/packager/lib.clj
deleted file mode 100644
index af48e31eb..000000000
--- a/src/lux/packager/lib.clj
+++ /dev/null
@@ -1,41 +0,0 @@
-;; Copyright (c) Eduardo Julian. All rights reserved.
-;; This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-;; If a copy of the MPL was not distributed with this file,
-;; You can obtain one at http://mozilla.org/MPL/2.0/.
-
-(ns lux.packager.lib
- (:require [lux.lib.loader :as &lib])
- (:import (java.io File
- FileOutputStream)
- java.util.zip.GZIPOutputStream
- (org.apache.commons.compress.archivers.tar TarArchiveEntry
- TarArchiveOutputStream)
- ))
-
-;; [Utils]
-(defn ^:private read-file ^objects [^File file]
- (with-open [is (java.io.FileInputStream. file)]
- (let [data (byte-array (.length file))]
- (.read is data)
- data)))
-
-(defn ^:private add-to-tar! [prefix ^File file ^TarArchiveOutputStream os]
- "(-> Text File TarArchiveOutputStream Unit)"
- (let [file-name (str prefix "/" (.getName file))]
- (if (.isDirectory file)
- (doseq [file (seq (.listFiles file))]
- (add-to-tar! file-name file os))
- (let [data (read-file file)]
- (doto os
- (.putArchiveEntry (doto (new TarArchiveEntry file-name)
- (.setSize (.length file))))
- (.write data 0 (alength data))
- (.closeArchiveEntry))))))
-
-;; [Exports]
-(defn package [output-lib-name ^File source-dir]
- "(-> Text File Unit)"
- (with-open [out (->> (str output-lib-name &lib/lib-ext) (new FileOutputStream) (new GZIPOutputStream) (new TarArchiveOutputStream))]
- (doseq [file (seq (.listFiles source-dir))]
- (add-to-tar! "" file out))
- ))
diff --git a/src/lux/packager/program.clj b/src/lux/packager/program.clj
index 83927ba0d..0ff06a453 100644
--- a/src/lux/packager/program.clj
+++ b/src/lux/packager/program.clj
@@ -74,19 +74,29 @@
(recur (.read is buffer 0 buffer-size)))))
(.toByteArray os)))))
-(defn ^:private add-jar! [^File jar-file ^JarOutputStream out]
+(defn ^:private add-jar! [^File jar-file seen ^JarOutputStream out]
(with-open [is (->> jar-file (new FileInputStream) (new JarInputStream))]
- (loop [^JarEntry entry (.getNextJarEntry is)]
- (when entry
- (when (and (not (.isDirectory entry))
- (not (.startsWith (.getName entry) "META-INF/")))
- (let [entry-data (read-stream is)]
- (doto out
- (.putNextEntry entry)
- (.write entry-data 0 (alength entry-data))
- (.flush)
- (.closeEntry))))
- (recur (.getNextJarEntry is))))))
+ (loop [^JarEntry entry (.getNextJarEntry is)
+ seen seen]
+ (if entry
+ (let [entry-name (.getName entry)]
+ (if (and (not (.isDirectory entry))
+ (not (.startsWith entry-name "META-INF/"))
+ (.endsWith entry-name ".class")
+ (not (contains? seen entry-name)))
+ (let [;; _ (prn 'entry entry-name)
+ entry-data (read-stream is)]
+ (doto out
+ (.putNextEntry entry)
+ (.write entry-data 0 (alength entry-data))
+ (.flush)
+ (.closeEntry))
+ (recur (.getNextJarEntry is)
+ (conj seen entry-name)))
+ (recur (.getNextJarEntry is)
+ seen)))
+ seen
+ ))))
;; [Resources]
(defn package [module]
@@ -94,6 +104,10 @@
(with-open [out (new JarOutputStream (->> &&/output-package (new File) (new FileOutputStream)) (manifest module))]
(doseq [$group (.listFiles (new File &&/output-dir))]
(write-module! $group out))
- (doseq [^String jar-file (fetch-available-jars)]
- (add-jar! (new File jar-file) out))
+ (->> (fetch-available-jars)
+ (filter #(and (not (.endsWith % "luxc.jar"))
+ (not (.endsWith % "tools.nrepl-0.2.3.jar"))
+ (not (.endsWith % "clojure-complete-0.2.3.jar"))))
+ (reduce (fn [s ^String j] (add-jar! (new File ^String j) s out))
+ #{}))
))