aboutsummaryrefslogtreecommitdiff
path: root/lux-lein
diff options
context:
space:
mode:
authorEduardo Julian2016-12-01 11:00:44 -0400
committerEduardo Julian2016-12-01 11:00:44 -0400
commit7f66c54f4c9753b94dbf46ec50b8b16549daf324 (patch)
tree1b5b896cfba870a66a99a03315b09df842eb5737 /lux-lein
parent9c30546af022f8fe36b73e7e93414257ff28ee75 (diff)
- Collected the Lux compiler's repo, the Standard Library's, the Leiningen plugin's and the Emacs mode's into a big monorepo, to keep development unified.
Diffstat (limited to '')
-rw-r--r--lux-lein/LICENSE214
-rw-r--r--lux-lein/README.md27
-rw-r--r--lux-lein/license.txt (renamed from license.txt)0
-rw-r--r--lux-lein/project.clj21
-rw-r--r--lux-lein/src/leiningen/luxc.clj27
-rw-r--r--lux-lein/src/leiningen/luxc/compiler.clj19
-rw-r--r--lux-lein/src/leiningen/luxc/packager.clj212
-rw-r--r--lux-lein/src/leiningen/luxc/repl.clj35
-rw-r--r--lux-lein/src/leiningen/luxc/test.clj27
-rw-r--r--lux-lein/src/leiningen/luxc/utils.clj97
10 files changed, 679 insertions, 0 deletions
diff --git a/lux-lein/LICENSE b/lux-lein/LICENSE
new file mode 100644
index 000000000..786edf6b2
--- /dev/null
+++ b/lux-lein/LICENSE
@@ -0,0 +1,214 @@
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
+LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
+CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
+
+1. DEFINITIONS
+
+"Contribution" means:
+
+a) in the case of the initial Contributor, the initial code and
+documentation distributed under this Agreement, and
+
+b) in the case of each subsequent Contributor:
+
+i) changes to the Program, and
+
+ii) additions to the Program;
+
+where such changes and/or additions to the Program originate from and are
+distributed by that particular Contributor. A Contribution 'originates' from
+a Contributor if it was added to the Program by such Contributor itself or
+anyone acting on such Contributor's behalf. Contributions do not include
+additions to the Program which: (i) are separate modules of software
+distributed in conjunction with the Program under their own license
+agreement, and (ii) are not derivative works of the Program.
+
+"Contributor" means any person or entity that distributes the Program.
+
+"Licensed Patents" mean patent claims licensable by a Contributor which are
+necessarily infringed by the use or sale of its Contribution alone or when
+combined with the Program.
+
+"Program" means the Contributions distributed in accordance with this
+Agreement.
+
+"Recipient" means anyone who receives the Program under this Agreement,
+including all Contributors.
+
+2. GRANT OF RIGHTS
+
+a) Subject to the terms of this Agreement, each Contributor hereby grants
+Recipient a non-exclusive, worldwide, royalty-free copyright license to
+reproduce, prepare derivative works of, publicly display, publicly perform,
+distribute and sublicense the Contribution of such Contributor, if any, and
+such derivative works, in source code and object code form.
+
+b) Subject to the terms of this Agreement, each Contributor hereby grants
+Recipient a non-exclusive, worldwide, royalty-free patent license under
+Licensed Patents to make, use, sell, offer to sell, import and otherwise
+transfer the Contribution of such Contributor, if any, in source code and
+object code form. This patent license shall apply to the combination of the
+Contribution and the Program if, at the time the Contribution is added by the
+Contributor, such addition of the Contribution causes such combination to be
+covered by the Licensed Patents. The patent license shall not apply to any
+other combinations which include the Contribution. No hardware per se is
+licensed hereunder.
+
+c) Recipient understands that although each Contributor grants the licenses
+to its Contributions set forth herein, no assurances are provided by any
+Contributor that the Program does not infringe the patent or other
+intellectual property rights of any other entity. Each Contributor disclaims
+any liability to Recipient for claims brought by any other entity based on
+infringement of intellectual property rights or otherwise. As a condition to
+exercising the rights and licenses granted hereunder, each Recipient hereby
+assumes sole responsibility to secure any other intellectual property rights
+needed, if any. For example, if a third party patent license is required to
+allow Recipient to distribute the Program, it is Recipient's responsibility
+to acquire that license before distributing the Program.
+
+d) Each Contributor represents that to its knowledge it has sufficient
+copyright rights in its Contribution, if any, to grant the copyright license
+set forth in this Agreement.
+
+3. REQUIREMENTS
+
+A Contributor may choose to distribute the Program in object code form under
+its own license agreement, provided that:
+
+a) it complies with the terms and conditions of this Agreement; and
+
+b) its license agreement:
+
+i) effectively disclaims on behalf of all Contributors all warranties and
+conditions, express and implied, including warranties or conditions of title
+and non-infringement, and implied warranties or conditions of merchantability
+and fitness for a particular purpose;
+
+ii) effectively excludes on behalf of all Contributors all liability for
+damages, including direct, indirect, special, incidental and consequential
+damages, such as lost profits;
+
+iii) states that any provisions which differ from this Agreement are offered
+by that Contributor alone and not by any other party; and
+
+iv) states that source code for the Program is available from such
+Contributor, and informs licensees how to obtain it in a reasonable manner on
+or through a medium customarily used for software exchange.
+
+When the Program is made available in source code form:
+
+a) it must be made available under this Agreement; and
+
+b) a copy of this Agreement must be included with each copy of the Program.
+
+Contributors may not remove or alter any copyright notices contained within
+the Program.
+
+Each Contributor must identify itself as the originator of its Contribution,
+if any, in a manner that reasonably allows subsequent Recipients to identify
+the originator of the Contribution.
+
+4. COMMERCIAL DISTRIBUTION
+
+Commercial distributors of software may accept certain responsibilities with
+respect to end users, business partners and the like. While this license is
+intended to facilitate the commercial use of the Program, the Contributor who
+includes the Program in a commercial product offering should do so in a
+manner which does not create potential liability for other Contributors.
+Therefore, if a Contributor includes the Program in a commercial product
+offering, such Contributor ("Commercial Contributor") hereby agrees to defend
+and indemnify every other Contributor ("Indemnified Contributor") against any
+losses, damages and costs (collectively "Losses") arising from claims,
+lawsuits and other legal actions brought by a third party against the
+Indemnified Contributor to the extent caused by the acts or omissions of such
+Commercial Contributor in connection with its distribution of the Program in
+a commercial product offering. The obligations in this section do not apply
+to any claims or Losses relating to any actual or alleged intellectual
+property infringement. In order to qualify, an Indemnified Contributor must:
+a) promptly notify the Commercial Contributor in writing of such claim, and
+b) allow the Commercial Contributor tocontrol, and cooperate with the
+Commercial Contributor in, the defense and any related settlement
+negotiations. The Indemnified Contributor may participate in any such claim
+at its own expense.
+
+For example, a Contributor might include the Program in a commercial product
+offering, Product X. That Contributor is then a Commercial Contributor. If
+that Commercial Contributor then makes performance claims, or offers
+warranties related to Product X, those performance claims and warranties are
+such Commercial Contributor's responsibility alone. Under this section, the
+Commercial Contributor would have to defend claims against the other
+Contributors related to those performance claims and warranties, and if a
+court requires any other Contributor to pay any damages as a result, the
+Commercial Contributor must pay those damages.
+
+5. NO WARRANTY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON
+AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER
+EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR
+CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A
+PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the
+appropriateness of using and distributing the Program and assumes all risks
+associated with its exercise of rights under this Agreement , including but
+not limited to the risks and costs of program errors, compliance with
+applicable laws, damage to or loss of data, programs or equipment, and
+unavailability or interruption of operations.
+
+6. DISCLAIMER OF LIABILITY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
+CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
+LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
+EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGES.
+
+7. GENERAL
+
+If any provision of this Agreement is invalid or unenforceable under
+applicable law, it shall not affect the validity or enforceability of the
+remainder of the terms of this Agreement, and without further action by the
+parties hereto, such provision shall be reformed to the minimum extent
+necessary to make such provision valid and enforceable.
+
+If Recipient institutes patent litigation against any entity (including a
+cross-claim or counterclaim in a lawsuit) alleging that the Program itself
+(excluding combinations of the Program with other software or hardware)
+infringes such Recipient's patent(s), then such Recipient's rights granted
+under Section 2(b) shall terminate as of the date such litigation is filed.
+
+All Recipient's rights under this Agreement shall terminate if it fails to
+comply with any of the material terms or conditions of this Agreement and
+does not cure such failure in a reasonable period of time after becoming
+aware of such noncompliance. If all Recipient's rights under this Agreement
+terminate, Recipient agrees to cease use and distribution of the Program as
+soon as reasonably practicable. However, Recipient's obligations under this
+Agreement and any licenses granted by Recipient relating to the Program shall
+continue and survive.
+
+Everyone is permitted to copy and distribute copies of this Agreement, but in
+order to avoid inconsistency the Agreement is copyrighted and may only be
+modified in the following manner. The Agreement Steward reserves the right to
+publish new versions (including revisions) of this Agreement from time to
+time. No one other than the Agreement Steward has the right to modify this
+Agreement. The Eclipse Foundation is the initial Agreement Steward. The
+Eclipse Foundation may assign the responsibility to serve as the Agreement
+Steward to a suitable separate entity. Each new version of the Agreement will
+be given a distinguishing version number. The Program (including
+Contributions) may always be distributed subject to the version of the
+Agreement under which it was received. In addition, after a new version of
+the Agreement is published, Contributor may elect to distribute the Program
+(including its Contributions) under the new version. Except as expressly
+stated in Sections 2(a) and 2(b) above, Recipient receives no rights or
+licenses to the intellectual property of any Contributor under this
+Agreement, whether expressly, by implication, estoppel or otherwise. All
+rights in the Program not expressly granted under this Agreement are
+reserved.
+
+This Agreement is governed by the laws of the State of Washington and the
+intellectual property laws of the United States of America. No party to this
+Agreement will bring a legal action under this Agreement more than one year
+after the cause of action arose. Each party waives its rights to a jury trial
+in any resulting litigation.
diff --git a/lux-lein/README.md b/lux-lein/README.md
new file mode 100644
index 000000000..6d024a58f
--- /dev/null
+++ b/lux-lein/README.md
@@ -0,0 +1,27 @@
+# How to use it
+
+You'll need a project.clj that imports the lein-luxc plugin.
+
+Here's an example:
+
+```
+(defproject com.github.luxlang/lux-stdlib "0.4.0"
+ :description "Standard library for the Lux programming language."
+ :url "https://github.com/LuxLang/stdlib"
+ :license {:name "Mozilla Public License (Version 2.0)"
+ :url "https://www.mozilla.org/en-US/MPL/2.0/"}
+ :plugins [[com.github.luxlang/lein-luxc "0.3.0"]]
+ :source-paths ["source"]
+ )
+
+```
+
+Now, all you need to do is run the plugin like this:
+
+ lein luxc compile
+
+And, if you want to run unit-tests, you can do:
+
+ lein luxc test
+
+Those unit tests must be in the `test` directory on your project root.
diff --git a/license.txt b/lux-lein/license.txt
index 52d135112..52d135112 100644
--- a/license.txt
+++ b/lux-lein/license.txt
diff --git a/lux-lein/project.clj b/lux-lein/project.clj
new file mode 100644
index 000000000..69cc7ff17
--- /dev/null
+++ b/lux-lein/project.clj
@@ -0,0 +1,21 @@
+;; 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/.
+
+(defproject com.github.luxlang/lein-luxc "0.5.0-SNAPSHOT"
+ :description "The Leiningen plugin for the Lux programming language."
+ :url "https://github.com/LuxLang/lein-luxc"
+ :license {:name "Mozilla Public License"
+ :url "https://www.mozilla.org/en-US/MPL/2.0/"}
+ :dependencies [[org.clojure/clojure "1.6.0"]
+ [com.github.luxlang/luxc-jvm "0.5.0-SNAPSHOT"]
+ [com.github.luxlang/lux-stdlib "0.5.0-SNAPSHOT"]]
+ :deploy-repositories [["releases" {:url "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
+ :creds :gpg}]
+ ["snapshots" {:url "https://oss.sonatype.org/content/repositories/snapshots/"
+ :creds :gpg}]]
+ :pom-addition [:developers [:developer
+ [:name "Eduardo Julian"]
+ [:url "https://github.com/eduardoejp"]]]
+ :eval-in :leiningen)
diff --git a/lux-lein/src/leiningen/luxc.clj b/lux-lein/src/leiningen/luxc.clj
new file mode 100644
index 000000000..b04e4997a
--- /dev/null
+++ b/lux-lein/src/leiningen/luxc.clj
@@ -0,0 +1,27 @@
+;; 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 leiningen.luxc
+ (:require [leiningen.pom :as pom]
+ [leiningen.core.classpath :as classpath]
+ (leiningen.luxc [compiler :as &compiler]
+ [test :as &test]
+ [repl :as &repl])))
+
+;; [Exports]
+(defn luxc [project & args]
+ (case (first args)
+ "compile"
+ (&compiler/compile project)
+
+ "test"
+ (&test/test project)
+
+ "repl"
+ (&repl/repl project)
+
+ ;; default...
+ (println "Commands available: compile, test, repl"))
+ )
diff --git a/lux-lein/src/leiningen/luxc/compiler.clj b/lux-lein/src/leiningen/luxc/compiler.clj
new file mode 100644
index 000000000..18eef63a0
--- /dev/null
+++ b/lux-lein/src/leiningen/luxc/compiler.clj
@@ -0,0 +1,19 @@
+;; 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 leiningen.luxc.compiler
+ (:refer-clojure :exclude [compile])
+ (:require [leiningen.core.classpath :as classpath]
+ (leiningen.luxc [utils :as &utils]
+ [packager :as &packager])))
+
+(defn compile [project]
+ (if-let [program-module (get-in project [:lux :program])]
+ (do (&utils/run-process (&utils/compile-path project program-module (get project :source-paths (list)))
+ nil
+ "[COMPILATION BEGIN]"
+ "[COMPILATION END]")
+ (&packager/package project program-module (get project :resource-paths (list))))
+ (println "Please provide a program main module in [:lux :program]")))
diff --git a/lux-lein/src/leiningen/luxc/packager.clj b/lux-lein/src/leiningen/luxc/packager.clj
new file mode 100644
index 000000000..e7b1d71d8
--- /dev/null
+++ b/lux-lein/src/leiningen/luxc/packager.clj
@@ -0,0 +1,212 @@
+;; 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 leiningen.luxc.packager
+ (:require [clojure.string :as string]
+ [leiningen.core.classpath :as classpath]
+ [leiningen.uberjar]
+ [leiningen.luxc.utils :as &utils])
+ (:import (java.io InputStream
+ File
+ FileInputStream
+ FileOutputStream
+ BufferedInputStream
+ ByteArrayInputStream
+ ByteArrayOutputStream)
+ (java.util.jar Manifest
+ Attributes$Name
+ JarEntry
+ JarInputStream
+ JarOutputStream
+ )))
+
+;; [Utils]
+(def ^:private kilobyte 1024)
+(def ^:private buffer-size (* 10 kilobyte))
+
+(defn ^:private manifest
+ "(-> Project Text Bool Manifest)"
+ [project module includes-android?]
+ (doto (new Manifest)
+ (-> .getMainAttributes
+ (doto (-> (.put Attributes$Name/MAIN_CLASS (str module "._"))
+ (->> (when (not includes-android?))))
+ (.put Attributes$Name/MANIFEST_VERSION "1.0")
+ (.put (new Attributes$Name "LUX_JAR") "true")
+ (-> (.put (new Attributes$Name name) real-v)
+ (->> (doseq [[name v] (get project :manifest)
+ :let [real-v (if (string? v) v (v project))]])))))))
+
+(defn ^:private write-class!
+ "(-> Text File JarOutputStream Null)"
+ [^String path ^File file ^JarOutputStream out]
+ (with-open [in (new BufferedInputStream (new FileInputStream file))]
+ (let [buffer (byte-array buffer-size)]
+ (doto out
+ (.putNextEntry (new JarEntry (str path "/" (.getName file))))
+ (-> (.write buffer 0 bytes-read)
+ (->> (when (not= -1 bytes-read))
+ (loop [bytes-read (.read in buffer)])))
+ (.flush)
+ (.closeEntry)
+ ))
+ ))
+
+(defn ^:private write-module!
+ "(-> File JarOutputStream Null)"
+ [^File file ^JarOutputStream out output-dir]
+ (let [output-dir-size (inc (.length output-dir))
+ module-name (.substring (.getPath file) output-dir-size)
+ inner-files (.listFiles file)
+ inner-modules (filter #(.isDirectory ^File %) inner-files)
+ inner-classes (filter #(not (.isDirectory ^File %)) inner-files)]
+ (doseq [$class inner-classes]
+ (write-class! module-name $class out))
+ (doseq [$module inner-modules]
+ (write-module! $module out output-dir))))
+
+(defn ^:private write-resources!
+ "(-> JarOutputStream (List Text) Null)"
+ [^JarOutputStream out resources-dirs]
+ (doseq [resources-dir resources-dirs
+ :let [resources-dir (new File resources-dir)]
+ :when (.exists resources-dir)
+ ^File res (.listFiles resources-dir)
+ :let [buffer (byte-array buffer-size)]]
+ (with-open [in (->> res (new FileInputStream) (new BufferedInputStream))]
+ (doto out
+ (.putNextEntry (new JarEntry (.getName res)))
+ (-> (.write buffer 0 bytes-read)
+ (->> (when (not= -1 bytes-read))
+ (loop [bytes-read (.read in buffer)])))
+ (.flush)
+ (.closeEntry))
+ )))
+
+(let [init-capacity (* 100 1024)
+ buffer-size 1024]
+ (defn ^:private ^"[B" read-stream [^InputStream is]
+ (let [buffer (byte-array buffer-size)]
+ (with-open [os (new ByteArrayOutputStream init-capacity)]
+ (loop [bytes-read (.read is buffer 0 buffer-size)]
+ (when (not= -1 bytes-read)
+ (do (.write os buffer 0 bytes-read)
+ (recur (.read is buffer 0 buffer-size)))))
+ (.toByteArray os)))))
+
+(defn ^:private add-jar! [^File jar-file project !all-jar-files]
+ (with-open [is (->> jar-file (new FileInputStream) (new JarInputStream))]
+ (loop [^JarEntry entry (.getNextJarEntry is)]
+ (when entry
+ (let [entry-name (.getName entry)]
+ (if (and (not (.isDirectory entry))
+ (not (.startsWith entry-name "META-INF/maven/"))
+ (not (some (fn [exclusion]
+ (re-find exclusion entry-name))
+ (get project :uberjar-exclusions))))
+ (let [entry-data (read-stream is)
+ entry-data (or (some (fn [[pattern [read fuse write]]]
+ (let [matches? (if (string? pattern)
+ (= pattern entry-name)
+ (re-find pattern entry-name))]
+ (when matches?
+ (let [os (new ByteArrayOutputStream 1024)
+ [_data _entry] (get @!all-jar-files entry-name [(byte-array 0) nil])
+ _ (write os (fuse (read (new ByteArrayInputStream _data))
+ (read (new ByteArrayInputStream entry-data))))]
+ (.toByteArray os)))))
+ (eval (get project :uberjar-merge-with)))
+ entry-data)]
+ (swap! !all-jar-files assoc entry-name [entry-data entry])
+ (recur (.getNextJarEntry is)))
+ (recur (.getNextJarEntry is))))
+ ))))
+
+(def default-manifest-file "./AndroidManifest.xml")
+
+;; [Resources]
+(defn package
+ "(-> Text (List Text) Null)"
+ [project module resources-dirs]
+ (let [output-dir (get-in project [:lux :target] &utils/output-dir)
+ output-package (str (get-in project [:lux :target] &utils/output-dir) "/"
+ (get project :jar-name &utils/output-package))
+ !all-jar-files (atom {})
+ includes-android? (boolean (some #(-> % first (= 'com.google.android/android))
+ (get project :dependencies)))
+ project* (-> project
+ (update-in [:dependencies] (fn [_deps]
+ ;; Skip the last two,
+ ;; because they are:
+ ;; tools.nrepl-0.2.12.jar and
+ ;; clojure-complete-0.2.4.jar
+ ;; and they belong to Leiningen.
+ (take (- (count _deps) 2) _deps))))
+ deps (->> project*
+ (classpath/resolve-managed-dependencies :dependencies :managed-dependencies)
+ (map #(.getAbsolutePath ^File %)))]
+ (do (.delete (new File output-package))
+ (with-open [out (new JarOutputStream
+ (->> output-package (new File) (new FileOutputStream))
+ (manifest project module includes-android?))]
+ (do (doseq [$group (.listFiles (new File output-dir))]
+ (write-module! $group out output-dir))
+ (when (not (get-in project [:lux :android]))
+ (write-resources! out resources-dirs))
+ (doseq [^String file-path deps]
+ (add-jar! (new File file-path) project !all-jar-files))
+ (doseq [[_ [entry-data entry]] @!all-jar-files]
+ (doto out
+ (.putNextEntry (doto entry (.setCompressedSize -1)))
+ (.write entry-data 0 (alength entry-data))
+ (.flush)
+ (.closeEntry)))
+ nil))
+ (when (get-in project [:lux :android])
+ (let [output-dex "classes.dex"
+ _ (do (.delete (new File output-dex))
+ (&utils/run-process (str "dx --dex --output=" output-dex " " output-package)
+ (new File (get-in project [:lux :target] &utils/output-dir))
+ "[DX BEGIN]"
+ "[DX END]"))
+ manifest-path (get-in project [:lux :android :manifest] default-manifest-file)
+ sdk-path (get-in project [:lux :android :sdk])
+ android-path (str sdk-path "/platforms/android-" (get-in project [:lux :android :version]) "/android.jar")
+ _ (assert (.exists (new File android-path))
+ (str "Can't find Android JAR: " android-path))
+ output-apk-unaligned (string/replace output-package #"\.jar$" ".apk.unaligned")
+ output-apk (string/replace output-package #"\.jar$" ".apk")
+ current-working-dir (.getCanonicalPath (new File "."))
+ _ (do (&utils/run-process (str "aapt package -f -M " manifest-path " -I " android-path " -F " output-apk-unaligned
+ (apply str " " (interleave (repeat (count resources-dirs)
+ "-A ")
+ (filter #(.exists (new File %))
+ resources-dirs)))
+ (apply str " " (interleave (repeat (count resources-dirs)
+ "-S ")
+ (->> (get-in project [:lux :android :resources] ["android-resources"])
+ (map (partial str current-working-dir "/"))
+ (filter #(.exists (new File %)))))))
+ nil
+ "[AAPT PACKAGE BEGIN]"
+ "[AAPT PACKAGE END]")
+ (&utils/run-process (str "aapt add -f " output-apk-unaligned " " output-dex)
+ (new File (get-in project [:lux :target] &utils/output-dir))
+ "[AAPT ADD BEGIN]"
+ "[AAPT ADD END]")
+ (when-let [path (get-in project [:lux :android :keystore :path])]
+ (when-let [alias (get-in project [:lux :android :keystore :alias])]
+ (when-let [password (get-in project [:lux :android :keystore :password])]
+ (&utils/run-process (str "jarsigner -storepass " password " -keystore " path " " output-apk-unaligned " " alias)
+ nil
+ "[JARSIGNER BEGIN]"
+ "[JARSIGNER END]"))))
+ (&utils/run-process (str "zipalign 4 " output-apk-unaligned " " output-apk)
+ nil
+ "[ZIPALIGN BEGIN]"
+ "[ZIPALIGN END]")
+ )
+ ]
+ nil)))))
diff --git a/lux-lein/src/leiningen/luxc/repl.clj b/lux-lein/src/leiningen/luxc/repl.clj
new file mode 100644
index 000000000..2bfb281e6
--- /dev/null
+++ b/lux-lein/src/leiningen/luxc/repl.clj
@@ -0,0 +1,35 @@
+;; 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 leiningen.luxc.repl
+ (:require [leiningen.core.classpath :as classpath]
+ [leiningen.luxc.utils :as &utils])
+ (:import (java.io InputStreamReader
+ BufferedReader
+ PrintStream)))
+
+(defn repl [project]
+ (println (&utils/repl-path project (:source-paths project)))
+ ;; (let [process (.exec (Runtime/getRuntime) (&utils/repl-path project (:source-paths project)))]
+ ;; (with-open [std-in (->> System/in (new InputStreamReader) (new BufferedReader))
+ ;; process-in (->> process .getOutputStream (new PrintStream))
+ ;; process-out (->> process .getInputStream (new InputStreamReader) (new BufferedReader))
+ ;; process-err (->> process .getErrorStream (new InputStreamReader) (new BufferedReader))]
+ ;; (loop []
+ ;; (do (loop []
+ ;; (when (.ready process-out)
+ ;; (println (.readLine process-out))
+ ;; (recur)))
+ ;; (loop [had-error? false]
+ ;; (if (.ready process-out)
+ ;; (do (println (.readLine process-err))
+ ;; (recur true))
+ ;; (when had-error?
+ ;; (System/exit 1))))
+ ;; (when-let [input (.readLine std-in)]
+ ;; (do (.println process-in input)
+ ;; (recur)))))
+ ;; ))
+ )
diff --git a/lux-lein/src/leiningen/luxc/test.clj b/lux-lein/src/leiningen/luxc/test.clj
new file mode 100644
index 000000000..a1b5a830c
--- /dev/null
+++ b/lux-lein/src/leiningen/luxc/test.clj
@@ -0,0 +1,27 @@
+;; 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 leiningen.luxc.test
+ (:refer-clojure :exclude [test])
+ (:require [leiningen.core.classpath :as classpath]
+ (leiningen.luxc [utils :as &utils]
+ [packager :as &packager])))
+
+(defn test [project]
+ (if-let [tests-module (get-in project [:lux :tests])]
+ (do (&utils/run-process (&utils/compile-path project tests-module (concat (:test-paths project) (:source-paths project)))
+ nil
+ "[COMPILATION BEGIN]"
+ "[COMPILATION END]")
+ (let [java-cmd (get project :java-cmd "java")
+ jvm-opts (->> (get project :jvm-opts) (interpose " ") (reduce str ""))
+ output-package (str (get-in project [:lux :target] &utils/output-dir) "/"
+ (get project :jar-name &utils/output-package))]
+ (do (&packager/package project tests-module (get project :resource-paths (list)))
+ (&utils/run-process (str java-cmd " " jvm-opts " -jar " output-package)
+ nil
+ "[TEST BEGIN]"
+ "[TEST END]"))))
+ (println "Please provide a test module in [:lux :tests]")))
diff --git a/lux-lein/src/leiningen/luxc/utils.clj b/lux-lein/src/leiningen/luxc/utils.clj
new file mode 100644
index 000000000..bae02d365
--- /dev/null
+++ b/lux-lein/src/leiningen/luxc/utils.clj
@@ -0,0 +1,97 @@
+;; 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 leiningen.luxc.utils
+ (:refer-clojure :exclude [compile])
+ (:require [leiningen.core.classpath :as classpath])
+ (:import (java.io File
+ InputStreamReader
+ BufferedReader)))
+
+(def ^:const ^String output-dir "target/jvm")
+(def ^:const ^String output-package "program.jar")
+
+(def ^:private unit-separator (str (char 31)))
+
+(def ^:private vm-options "-server -Xms2048m -Xmx2048m -XX:+OptimizeStringConcat")
+
+(defn compile-path [project module source-paths]
+ (let [output-dir (get-in project [:lux :target] output-dir)
+ jar-paths (->> ^java.net.URLClassLoader (ClassLoader/getSystemClassLoader)
+ (.getURLs)
+ (map #(.getFile ^java.net.URL %))
+ (filter #(.endsWith ^String % ".jar")))
+ compiler-path (some (fn [^:private path]
+ (if (.contains path "com/github/luxlang/luxc-jvm")
+ path
+ nil))
+ jar-paths)
+ stdlib-path (some (fn [^:private path]
+ (if (.contains path "com/github/luxlang/lux-stdlib")
+ path
+ nil))
+ jar-paths)
+ deps-paths (filter (fn [^:private path]
+ (or (.contains path "org/ow2/asm/asm-all")
+ (.contains path "org/clojure/core.match")
+ (.contains path "org/clojure/clojure")))
+ jar-paths)
+ sdk-path (get-in project [:lux :android :sdk])
+ android-path (str sdk-path "/platforms/android-" (get-in project [:lux :android :version]) "/android.jar")
+ deps-paths (if (.exists (new File android-path))
+ (cons android-path deps-paths)
+ deps-paths)]
+ (let [class-path (->> (classpath/get-classpath project)
+ (filter #(.endsWith % ".jar"))
+ (concat deps-paths)
+ (list* stdlib-path)
+ (interpose java.io.File/pathSeparator)
+ (reduce str ""))
+ java-cmd (get project :java-cmd "java")
+ jvm-opts (->> (get project :jvm-opts) (interpose " ") (reduce str ""))]
+ (str java-cmd " " jvm-opts " " vm-options " -cp " (str compiler-path ":" class-path)
+ " lux release " module
+ " " (->> (get project :resource-paths (list)) (interpose unit-separator) (apply str))
+ " " (->> source-paths (interpose unit-separator) (apply str))
+ " " output-dir))))
+
+(defn repl-path [project source-paths]
+ (let [jar-paths (->> ^java.net.URLClassLoader (ClassLoader/getSystemClassLoader)
+ (.getURLs)
+ (map #(.getFile ^java.net.URL %))
+ (filter #(.endsWith ^String % ".jar")))
+ compiler-path (some (fn [^:private path]
+ (if (.contains path "com/github/luxlang/luxc-jvm")
+ path
+ nil))
+ jar-paths)
+ deps-paths (filter (fn [^:private path]
+ (or (.contains path "org/ow2/asm/asm-all")
+ (.contains path "org/clojure/core.match")
+ (.contains path "org/clojure/clojure")))
+ jar-paths)]
+ (let [class-path (->> (classpath/get-classpath project) (filter #(.endsWith % ".jar")) (concat deps-paths) (interpose ":") (reduce str ""))
+ java-cmd (get project :java-cmd "java")
+ jvm-opts (->> (get project :jvm-opts) (interpose " ") (reduce str ""))]
+ (str java-cmd " " jvm-opts " " vm-options " -cp " (str compiler-path ":" class-path)
+ " lux repl " (->> source-paths (interpose unit-separator) (apply str))))))
+
+(defn run-process [command working-directory pre post]
+ (let [process (.exec (Runtime/getRuntime) command nil working-directory)]
+ (with-open [std-out (->> process .getInputStream (new InputStreamReader) (new BufferedReader))
+ std-err (->> process .getErrorStream (new InputStreamReader) (new BufferedReader))]
+ (println pre)
+ (loop [line (.readLine std-out)]
+ (when line
+ (println line)
+ (recur (.readLine std-out))))
+ (loop [had-error? false
+ line (.readLine std-err)]
+ (if line
+ (do (println line)
+ (recur true (.readLine std-err)))
+ (when had-error?
+ (System/exit 1))))
+ (println post))))