Skip to content
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 68b34e59d92b7abae7176649d9d96a5b9ead652b @technomancy committed
7 .gitignore
@@ -0,0 +1,7 @@
+pom.xml
+*jar
+/lib/
+/classes/
+.lein-deps-sum
+/.lein-plugins/checksum
+/test-project/.lein-plugins/checksum
22 README.md
@@ -0,0 +1,22 @@
+# lein-scalac
+
+Compile Scala source from Leiningen.
+
+## Usage
+
+Add [lein-scalac "0.1.0"] to `:plugins` project.clj. (Or
+`:dev-dependencies` on Leiningen versions earlier than 1.7.0)
+
+Set `:scala-source-path` in project.clj, usually to "src/scala", and
+place your `.scala` source files in there.
+
+Run `lein scalac` to compile them to `.class` files.
+
+If you'd like `scalac` to run before every `compile` invocation you
+can add `leiningen.hooks.scalac` to `:hooks` in project.clj.
+
+## License
+
+Copyright © 2012 Phil Hagelberg and Scott Clasen
+
+Distributed under the Eclipse Public License, the same as Clojure.
4 project.clj
@@ -0,0 +1,4 @@
+(defproject lein-scalac "0.1.0"
+ :eval-in-leiningen true
+ :dependencies [[org.scala-lang/scala-compiler "2.9.1"]
+ [lancet "1.0.1"]])
10 src/leiningen/hooks/scalac.clj
@@ -0,0 +1,10 @@
+(ns leiningen.hooks.scalac
+ (:require [robert.hooke]
+ [leiningen.compile]))
+
+(robert.hooke/add-hook (resolve 'leiningen.compile/prep)
+ (fn [f project & args]
+ ;; Don't load scalac at every lein launch.
+ (require 'leiningen.scalac)
+ ((resolve 'leiningen.scalac/scalac) project)
+ (apply f project args)))
26 src/leiningen/scalac.clj
@@ -0,0 +1,26 @@
+(ns leiningen.scalac
+ (:require [lancet.core :as lancet]
+ [leiningen.classpath :as classpath])
+ (:import (org.apache.tools.ant.types Path)))
+
+(defn task-props [project]
+ (merge {:srcdir (:scala-source-path project)
+ :destdir (:compile-path project)}
+ (:scalac-options project)))
+
+(.addTaskDefinition lancet/ant-project "scalac" scala.tools.ant.Scalac)
+
+(lancet/define-ant-task ant-scalac scalac)
+
+(defn scalac
+ "Compile Scala source in :scala-source-path to :compile-path.
+
+Set :scalac-options in project.clj to pass options to the Scala compiler.
+See http://www.scala-lang.org/node/98 for details."
+ [project]
+ (let [classpath (classpath/get-classpath-string project)
+ task (doto (lancet/instantiate-task lancet/ant-project "scalac"
+ (task-props project))
+ (.setClasspath (Path. lancet/ant-project classpath)))]
+ (lancet/mkdir {:dir (:compile-path project)})
+ (.execute task)))
5 test-project/.gitignore
@@ -0,0 +1,5 @@
+pom.xml
+*jar
+/lib/
+/classes/
+.lein-deps-sum
13 test-project/README.md
@@ -0,0 +1,13 @@
+# test-project
+
+I'm an app. I sure don't do much.
+
+## Usage
+
+FIXME
+
+## License
+
+Copyright © 2012 FIXME
+
+Distributed under the Eclipse Public License, the same as Clojure.
8 test-project/project.clj
@@ -0,0 +1,8 @@
+(defproject test-project "0.1.0"
+ :description "test project with some scala"
+ :dependencies [[org.clojure/clojure "1.3.0"]
+ [org.scala-lang/scala-library "2.9.1"]]
+ :plugins [[lein-scalac "0.1.0"]]
+ :hooks [leiningen.hooks.scalac]
+ :source-path "src/clj"
+ :scala-source-path "src/scala")
7 test-project/src/clj/test_project/core.clj
@@ -0,0 +1,7 @@
+(ns test-project.core)
+
+(defn -main
+ "I don't do a whole lot."
+ [& args]
+ (test.Test/main (into-array String []))
+ (println "Hello from Clojure!"))
7 test-project/src/scala/Test.scala
@@ -0,0 +1,7 @@
+package test
+
+object Test {
+ def main (args: Array[String]) {
+ println("Hello from Scala!")
+ }
+}

0 comments on commit 68b34e5

Please sign in to comment.
Something went wrong with that request. Please try again.