Skip to content

Commit

Permalink
First cut "pio new" command
Browse files Browse the repository at this point in the history
  • Loading branch information
dszeto committed Sep 11, 2014
1 parent d5d82a6 commit b8496da
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 4 deletions.
9 changes: 8 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@ fork in (ThisBuild, run) := true
javacOptions in ThisBuild ++= Seq("-source", "1.7", "-target", "1.7",
"-Xlint:deprecation", "-Xlint:unchecked")

sparkVersion in ThisBuild := "1.0.2"

lazy val pioBuildInfoSettings = buildInfoSettings ++ Seq(
sourceGenerators in Compile <+= buildInfo,
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
buildInfoKeys := Seq[BuildInfoKey](
name,
version,
scalaVersion,
sbtVersion,
sparkVersion),
buildInfoPackage := "io.prediction.core")

lazy val root = project in file(".") aggregate(
Expand Down
2 changes: 1 addition & 1 deletion core/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ libraryDependencies ++= Seq(
"io.spray" % "spray-can" % "1.2.1",
"io.spray" % "spray-routing" % "1.2.1",
"net.jodah" % "typetools" % "0.3.1",
"org.apache.spark" %% "spark-core" % "1.0.2" % "provided",
"org.apache.spark" %% "spark-core" % sparkVersion.value % "provided",
"org.clapper" %% "grizzled-slf4j" % "1.0.2",
"org.elasticsearch" % "elasticsearch" % "1.2.1",
"org.json4s" %% "json4s-native" % "3.2.6",
Expand Down
2 changes: 1 addition & 1 deletion engines/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ libraryDependencies ++= Seq(
"commons-io" % "commons-io" % "2.4",
"org.apache.commons" % "commons-math3" % "3.3",
"org.apache.mahout" % "mahout-core" % "0.9",
"org.apache.spark" %% "spark-core" % "1.0.2" % "provided",
"org.apache.spark" %% "spark-core" % sparkVersion.value % "provided",
"org.apache.spark" %% "spark-mllib" % "1.0.2"
exclude("org.apache.spark", "spark-core_2.10")
exclude("org.eclipse.jetty", "jetty-server"),
Expand Down
8 changes: 8 additions & 0 deletions project/Build.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import sbt._
import Keys._

object PIOBuild extends Build {
val sparkVersion = SettingKey[String](
"spark-version",
"The version of Apache Spark used for building.")
}
54 changes: 53 additions & 1 deletion tools/src/main/scala/Console.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io.prediction.data.api.DataAPI
import io.prediction.data.api.DataAPIConfig

import grizzled.slf4j.Logging
import org.apache.commons.io.FileUtils
import org.json4s._
import org.json4s.native.Serialization.{read, write}
import scalaj.http.Http
Expand Down Expand Up @@ -41,7 +42,8 @@ case class ConsoleArgs(
engineInstanceId: Option[String] = None,
ip: String = "localhost",
port: Int = 8000,
mainClass: Option[String] = None)
mainClass: Option[String] = None,
projectName: Option[String] = None)

object Console extends Logging {
def main(args: Array[String]): Unit = {
Expand Down Expand Up @@ -83,6 +85,18 @@ object Console extends Logging {
failure(s"${x.getCanonicalPath} does not exist.")
} text("Path to sbt. Default: sbt")
note("")
cmd("new").
text("Creates a new engine project in a subdirectory with the same " +
"name as the project. The project name will also be used as the " +
"default engine ID.").
action { (_, c) =>
c.copy(commands = c.commands :+ "new")
} children(
arg[String]("<project name>") action { (x, c) =>
c.copy(projectName = Some(x))
} text("Engine project name.")
)
note("")
cmd("register").
text("Build and register an engine at the current directory.").
action { (_, c) =>
Expand Down Expand Up @@ -278,6 +292,8 @@ object Console extends Logging {
parser.parse(consoleArgs, ConsoleArgs()) map { pca =>
val ca = pca.copy(passThrough = passThroughArgs)
ca.commands match {
case Seq("new") =>
createProject(ca)
case Seq("register") =>
register(ca)
case Seq("unregister") =>
Expand Down Expand Up @@ -308,6 +324,42 @@ object Console extends Logging {
sys.exit(0)
}

def createProject(ca: ConsoleArgs): Unit = {
val builtinEngines = Seq(
"io.prediction.engines.itemrank")
val engineJson = templates.txt.engine(
ca.projectName.get,
"0.0.1-SNAPSHOT",
ca.projectName.get,
ca.projectName.get)
val buildSbt = templates.txt.build(
ca.projectName.get,
BuildInfo.version,
BuildInfo.sparkVersion)
val assemblySbt = templates.txt.assembly()
new File(ca.projectName.get + File.separator + "project").mkdirs

FileUtils.writeStringToFile(
new File(ca.projectName.get + File.separator + "engine.json"),
engineJson.toString,
"ISO-8859-1")

FileUtils.writeStringToFile(
new File(ca.projectName.get + File.separator + "build.sbt"),
buildSbt.toString,
"ISO-8859-1")

FileUtils.writeStringToFile(
new File(Seq(
ca.projectName.get,
"project",
"assembly.sbt").mkString(File.separator)),
assemblySbt.toString,
"ISO-8859-1")

info(s"Engine project created in subdirectory ${ca.projectName.get}.")
}

def register(ca: ConsoleArgs): Unit = {
if (!RegisterEngine.builtinEngine(ca.engineJson)) {
val sbt = detectSbt(ca)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")
14 changes: 14 additions & 0 deletions tools/src/main/twirl/io/prediction/tools/templates/build.scala.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@(name: String, pioVersion: String, sparkVersion: String)
import AssemblyKeys._

assemblySettings

name := "@{name}"

organization := "myorg"

version := "0.0.1-SNAPSHOT"

libraryDependencies ++= Seq(
"io.prediction" %% "core" % "@{pioVersion}" % "provided",
"org.apache.spark" %% "spark-core" % "@{sparkVersion}" % "provided")
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@(id: String, version: String, name: String, engineFactory: String)
{
"id": "@{id}",
"version": "@{version}",
"name": "@{name}",
"engineFactory": "@{engineFactory}"
}

0 comments on commit b8496da

Please sign in to comment.