From bc00ef39fb69caf44f5bf21e23105c1f981143f1 Mon Sep 17 00:00:00 2001 From: xuwei-k <6b656e6a69@gmail.com> Date: Fri, 6 Jun 2014 21:52:33 +0900 Subject: [PATCH 1/4] Scala 2.11 --- build.sbt | 34 ++++---- project/build.properties | 2 +- project/plugins.sbt | 7 +- setup.sh | 2 +- src/main/conscript/cs/launchconfig | 6 +- src/main/scala/authorize.scala | 29 +++---- src/main/scala/conscript.scala | 84 ++++++++++--------- src/main/scala/credentials.scala | 4 +- src/main/scala/github.scala | 28 ++++--- src/main/scala/{liftjson.scala => json.scala} | 6 +- src/main/scala/launch.scala | 40 +++++---- 11 files changed, 123 insertions(+), 119 deletions(-) rename src/main/scala/{liftjson.scala => json.scala} (67%) diff --git a/build.sbt b/build.sbt index 890f9b4..ccd06cb 100644 --- a/build.sbt +++ b/build.sbt @@ -1,27 +1,29 @@ -seq(conscriptSettings :_*) +conscriptSettings -seq(lsSettings :_*) +lsSettings organization := "net.databinder.conscript" -version := "0.4.4" +version := "0.4.5-SNAPSHOT" name := "conscript" -scalaVersion := "2.9.2" +scalaVersion := "2.11.1" -libraryDependencies <<= (libraryDependencies, scalaVersion, sbtVersion) { - (deps, sv, sbtv) => deps ++ Seq( - "net.databinder.dispatch" %% "dispatch-core" % "0.9.5", - "com.github.scopt" %% "scopt" % "2.1.0", - "org.scala-lang" % "scala-swing" % sv, - "net.liftweb" %% "lift-json" % "2.5", - "org.slf4j" % "slf4j-jdk14" % "1.6.2" - ) -} +scalacOptions ++= Seq("-deprecation", "-language:_") + +libraryDependencies ++= Seq( + "net.databinder.dispatch" %% "dispatch-core" % "0.11.1", + "com.github.scopt" %% "scopt" % "3.2.0", + "org.scala-lang.modules" %% "scala-swing" % "1.0.1", + "org.json4s" %% "json4s-native" % "3.2.10", + "org.slf4j" % "slf4j-jdk14" % "1.6.2" +) proguardSettings +ProguardKeys.proguardVersion in Proguard := "4.11" + ProguardKeys.options in Proguard ++= Seq( "-keep class conscript.* { *; }", "-keep class dispatch.* { *; }", @@ -52,7 +54,7 @@ ProguardKeys.outputs in Proguard <<= op / ("conscript-" + v + ".jar") :: Nil } -seq(buildInfoSettings: _*) +buildInfoSettings sourceGenerators in Compile <+= buildInfo @@ -79,8 +81,8 @@ licenses := Seq("LGPL v3" -> url("http://www.gnu.org/licenses/lgpl.txt")) pomExtra := ( - git@github.com:dispatch/reboot.git - scm:git:git@github.com:dispatch/reboot.git + git@github.com:n8han/conscript.git + scm:git:git@github.com:n8han/conscript.git diff --git a/project/build.properties b/project/build.properties index 8cbb522..be6c454 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.0 \ No newline at end of file +sbt.version=0.13.5 diff --git a/project/plugins.sbt b/project/plugins.sbt index 409b111..1e8e6d4 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,14 +1,13 @@ addSbtPlugin("net.databinder" % "conscript-plugin" % "0.3.5") -addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.2.5") +addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.3.2") addSbtPlugin("me.lessis" % "ls-sbt" % "0.1.3") addSbtPlugin("com.typesafe.sbt" % "sbt-proguard" % "0.2.2") -resolvers += Resolver.url("sbt-plugin-releases", - url("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns) - resolvers ++= Seq( "less is" at "http://repo.lessis.me", "coda" at "http://repo.codahale.com") + +scalacOptions ++= Seq("-deprecation") diff --git a/setup.sh b/setup.sh index 6531a19..492b993 100755 --- a/setup.sh +++ b/setup.sh @@ -23,7 +23,7 @@ java -jar $CS/sbt-launch.jar @$CLC \"\$@\"" > $BIN/cs chmod a+x $BIN/cs -LJV=0.13.0 +LJV=0.13.5 LJ="sbt-launch-$LJV.jar" if [ ! -f $CS/$LJ ]; then echo " diff --git a/src/main/conscript/cs/launchconfig b/src/main/conscript/cs/launchconfig index 26830b7..ff9b53c 100644 --- a/src/main/conscript/cs/launchconfig +++ b/src/main/conscript/cs/launchconfig @@ -1,11 +1,11 @@ [app] - version: 0.4.4 + version: 0.4.5-SNAPSHOT org: net.databinder.conscript name: conscript class: conscript.Conscript [scala] - version: 2.9.2 + version: 2.11.1 [repositories] local sonatype-releases: https://oss.sonatype.org/content/repositories/releases/ - maven-central \ No newline at end of file + maven-central diff --git a/src/main/scala/authorize.scala b/src/main/scala/authorize.scala index 1fe5ae8..b402e3d 100644 --- a/src/main/scala/authorize.scala +++ b/src/main/scala/authorize.scala @@ -1,36 +1,31 @@ package conscript import dispatch._ -import net.liftweb.json._ -import net.liftweb.json.JsonDSL._ +import org.json4s._ +import org.json4s.JsonDSL._ +import org.json4s.native.{renderJValue, compactJson} +import scala.concurrent.Future +import scala.concurrent.ExecutionContext.Implicits.global object Authorize { def auths = :/("api.github.com").secure.POST / "authorizations" - // rm when avaialable in released dispatch - import com.ning.http.client.RequestBuilder - import com.ning.http.client.Realm.{RealmBuilder,AuthScheme} - def as_!(subject: RequestBuilder, user: String, password: String) = - subject.setRealm(new RealmBuilder() - .setPrincipal(user) - .setPassword(password) - .setUsePreemptiveAuth(true) - .setScheme(AuthScheme.BASIC) - .build()) - import Conscript.http - def apply(user: String, pass: String): Promise[Either[String, String]] = + def apply(user: String, pass: String): Future[Either[String, String]] = http( - as_!(auths, user, pass).setBody(compact(render( + auths.as_!(user, pass).setBody(compactJson(renderJValue( ("note" -> "Conscript") ~ ("note_url" -> "https://github.com/n8han/conscript") ~ ("scopes" -> ("repo" :: Nil)) - ))) OK LiftJson.As + ))) OK Json.As ).either.left.map { case StatusCode(401) => "Unrecognized github login and password" case e => "Unexpected error: " + e.getMessage }.map { _.right.flatMap { js => - (for (JField("token", JString(token)) <- js) yield { + (for { + JObject(fields) <- js + JField("token", JString(token)) <- fields + } yield { Config.properties { _.setProperty("gh.access", token) } diff --git a/src/main/scala/conscript.scala b/src/main/scala/conscript.scala index 070c2f9..065f2e1 100644 --- a/src/main/scala/conscript.scala +++ b/src/main/scala/conscript.scala @@ -1,9 +1,11 @@ package conscript import scala.util.control.Exception.allCatch +import scala.concurrent.ExecutionContext.Implicits.global +import scala.concurrent.duration._ +import scala.concurrent.Await object Conscript { - import dispatch._ import Apply.exec val http = dispatch.Http @@ -30,41 +32,38 @@ object Conscript { /** Shared by the launched version and the runnable version */ def run(args: Array[String]): Int = { import scopt._ - var config = Config() - val parser = new OptionParser("cs", BuildInfo.version) { - opt("clean-boot", "clears boot dir", { - config = config.copy(clean_boot = true) - }) - opt("setup", "installs sbt launcher", { - config = config.copy(setup = true) - }) - opt("b", "branch", "github branch (default: master)", { b => - config = config.copy(branch = Some(b)) - }) - opt("a", "auth", "obtain oauth token with :", { b => - config = config.copy(auth = Some(b)) - }) - opt("local", "include local repos", { - config = config.copy(entries = config.entries :+ InsertLocalRepository) - }) - opt("no-local", "exclude local and maven-local repos", { - config = config.copy(entries = config.entries ++ Seq(RemoveLocalRepository, RemoveMavenLocalRepository)) - }) - opt("version", "print current version", { - config = config.copy(usage = true) - }) - opt("no-exec", "don't execute program after install", { - config = config.copy(shouldExec = false) - }) - argOpt("[/[/]]", "github project", { p => - config = config.copy(project = p) - }) + val parser = new OptionParser[Config]("cs") { + opt[Unit]("clean-boot").text("clears boot dir").action( + (_, c) => c.copy(clean_boot = true) + ) + opt[Unit]("setup").text("installs sbt launcher").action( + (_, c) => c.copy(setup = true) + ) + opt[String]('b', "branch").text("github branch (default: master)").action( + (b, c) => c.copy(branch = Some(b)) + ) + opt[String]('a', "auth").text("obtain oauth token with :").action( + (b, c) => c.copy(auth = Some(b)) + ) + opt[Unit]("local").text("include local repos").action( + (_, c) => c.copy(entries = c.entries :+ InsertLocalRepository) + ) + opt[Unit]("no-local").text("exclude local and maven-local repos").action( + (_, c) => c.copy(entries = c.entries ++ Seq(RemoveLocalRepository, RemoveMavenLocalRepository)) + ) + opt[Unit]("version").text("print current version").action( + (_, c) => c.copy(usage = true) + ) + opt[Unit]("no-exec").text("don't execute program after install").action( + (_, c) => c.copy(shouldExec = false) + ) + arg[String]("[/[/]]").optional.text("github project").action( + (p, c) => c.copy(project = p) + ) } - val parsed = - if (parser.parse(args)) Some(config) - else None + val parsed = parser.parse(args, new Config()) val display = - if (config.setup) + if (parsed.exists(_.setup)) allCatch.opt { SplashDisplay }.getOrElse(ConsoleDisplay) @@ -79,7 +78,7 @@ object Conscript { Right(parser.usage) case c if !c.auth.isEmpty => c.auth.get.split(":",2) match { - case Array(name, pass) => Authorize(name, pass)() + case Array(name, pass) => Await.result(Authorize(name, pass), 30.seconds) case _ => Left("-a / --auth requires :") } case c if c.setup => @@ -88,7 +87,7 @@ object Conscript { configure("n8han", "conscript", true, - configoverrides = Seq(ConfigVersion(BuildInfo.version)) + configoverrides = Seq(ConfigVersion(conscript.BuildInfo.version)) ).right.flatMap { msg => display.info(msg) examine("cs") @@ -120,15 +119,15 @@ object Conscript { case _ => Left("Installed: %s\nError reported; run from terminal for details.".format(pathed)) } - } + } } def configure(user: String, repo: String, shouldExec: Boolean, branch: Option[String] = None, - configoverrides: Seq[ConfigEntry] = Nil) = - Github.lookup(user, repo, branch).map { result => + configoverrides: Seq[ConfigEntry] = Nil) = { + val future = Github.lookup(user, repo, branch).map { result => result.right.flatMap { scripts => ((Right(""): Either[String,String]) /: scripts) { case (either, (name, launch)) => @@ -140,8 +139,11 @@ object Conscript { } } } - }() - val GhProject = "([^/]+)/([^/]+)(/[^/]+)?".r + } + Await.result(future, 30.seconds) + } + + private val GhProject = "([^/]+)/([^/]+)(/[^/]+)?".r } /** The launched conscript entry point */ diff --git a/src/main/scala/credentials.scala b/src/main/scala/credentials.scala index cf42195..474540a 100644 --- a/src/main/scala/credentials.scala +++ b/src/main/scala/credentials.scala @@ -1,9 +1,9 @@ package conscript -import com.ning.http.client.RequestBuilder +import dispatch.Req trait Credentials extends OsDetect { - def withCredentials(req: RequestBuilder) = + def withCredentials(req: Req) = (oauth map { case token => req.addHeader("Authorization", "token %s".format(token)) }).getOrElse { req } diff --git a/src/main/scala/github.scala b/src/main/scala/github.scala index b8feddf..f0c6015 100644 --- a/src/main/scala/github.scala +++ b/src/main/scala/github.scala @@ -1,17 +1,17 @@ package conscript import dispatch._ -import net.liftweb.json.JsonAST._ -import java.io.File -import com.ning.http.client.{RequestBuilder=>Req} +import org.json4s.JsonAST._ import com.ning.http.client.ProxyServer +import scala.concurrent.ExecutionContext.Implicits.global +import scala.concurrent.Future object Github extends Credentials { import Conscript.http val DefaultBranch = "master" def lookup(user: String, repo: String, branch: Option[String]) - : Promise[Either[String, Iterable[(String, Launchconfig)]]] = { + : Future[Either[String, Iterable[(String, Launchconfig)]]] = { def base = gh(user, repo) for { ref <- refname(branch, base) @@ -22,10 +22,11 @@ object Github extends Credentials { } def shas(base: Req, ref: String) = http( - base / "git" / "refs" / "heads" / ref OK LiftJson.As + base / "git" / "refs" / "heads" / ref OK Json.As ).either.right.map { js => for { - JField("object", JObject(obj)) <- js + JObject(fields) <- js + JField("object", JObject(obj)) <- fields JField("sha", JString(sha)) <- obj } yield sha }.left.map { @@ -35,10 +36,11 @@ object Github extends Credentials { def trees(base: Req, sha: String) = http(base / "git" / "trees" / sha < "1" - ) OK LiftJson.As).either.left.map(unknownError).map { eth => + ) OK Json.As).either.left.map(unknownError).map { eth => eth.right.flatMap { js => (for { - JField("tree", JArray(ary)) <- js + JObject(fields) <- js + JField("tree", JArray(ary)) <- fields JObject(obj) <- ary JField("path", JString(name)) <- obj JField("sha", JString(hash)) <- obj @@ -50,7 +52,7 @@ object Github extends Credentials { } } def guaranteed[L, R](value: R) = - http.promise((Right(value): Either[L, R])) + Future.successful(Right(value): Either[L, R]) def refname(given: Option[String], base: Req) = given match { case Some(branch) => guaranteed[String, String](branch).right @@ -59,16 +61,16 @@ object Github extends Credentials { }.right } def masterBranch(base: Req) = - http(base OK LiftJson.As).either.left.map { + http(base OK Json.As).either.left.map { case StatusCode(404) => "Repository not found on github" case e => unknownError(e) }.map { eth => eth.right.flatMap { js => (for{ JObject(obj) <- js - JField("master_branch", JString(branch)) <- obj + JField("default_branch", JString(branch)) <- obj } yield branch) match { - case Seq() => Left("Default master branch not found on github") + case Seq() => Left("Default branch not found on github") case seq => Right(seq.head) } } @@ -88,7 +90,7 @@ object Github extends Credentials { req.setProxyServer(new ProxyServer(host, port.toInt)) } - return req + req } diff --git a/src/main/scala/liftjson.scala b/src/main/scala/json.scala similarity index 67% rename from src/main/scala/liftjson.scala rename to src/main/scala/json.scala index 5bf4dda..40a50ad 100644 --- a/src/main/scala/liftjson.scala +++ b/src/main/scala/json.scala @@ -1,10 +1,8 @@ package conscript import com.ning.http.client.Response +import org.json4s.native.JsonParser -import net.liftweb.json._ -import JsonDSL._ - -object LiftJson { +object Json { def As(res: Response) = JsonParser.parse(dispatch.as.String(res)) } diff --git a/src/main/scala/launch.scala b/src/main/scala/launch.scala index 0b2e06d..6948a4b 100644 --- a/src/main/scala/launch.scala +++ b/src/main/scala/launch.scala @@ -1,17 +1,20 @@ package conscript +import conscript.BuildInfo.sbtVersion import dispatch._ import java.io.{FileOutputStream, File} import util.control.Exception._ +import scala.concurrent.Await +import scala.concurrent.ExecutionContext.Implicits.global +import scala.concurrent.duration._ trait Launch extends Credentials { import Conscript.http - val sbtversion = "0.13.0" val sbtlaunchalias = "sbt-launch.jar" def launchJar(display: Display): Either[String, String] = - configdir("sbt-launch-%s.jar" format sbtversion) match { + configdir("sbt-launch-%s.jar" format sbtVersion) match { case jar if jar.exists => Right("Launcher already up to date, fetching next...") case jar => try { @@ -20,24 +23,27 @@ trait Launch extends Credentials { if (!launchalias.getParentFile.exists) mkdir(launchalias) else () - val req = url("http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/%s/sbt-launch.jar" format sbtversion) - - http(req > as.File(jar))() - windows map { _ => - if (launchalias.exists) launchalias.delete - else () - // should copy the one we already downloaded, but I don't - // have a windows box to test any changes - http(req > as.File(launchalias))() - } getOrElse { - val rt = Runtime.getRuntime - rt.exec("ln -sf %s %s" format (jar, launchalias)).waitFor - } - Right("Fetching Conscript...") + val req = url("http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/%s/sbt-launch.jar" format sbtVersion) + + val future = for { + _ <- http(req > as.File(jar)) + _ <- windows.map { _ => + if (launchalias.exists) launchalias.delete + else () + // should copy the one we already downloaded, but I don't + // have a windows box to test any changes + http(req > as.File(launchalias)) + } getOrElse { + val rt = Runtime.getRuntime + Future.successful(rt.exec("ln -sf %s %s" format (jar, launchalias)).waitFor) + } + } yield Right("Fetching Conscript...") + + Await.result(future, 30.seconds) } catch { case e: Exception => Left("Error downloading sbt-launch-%s: %s".format( - sbtversion, e.toString + sbtVersion, e.toString )) } } From 841ee0b01c16712583b72fa65275070a5e3d489a Mon Sep 17 00:00:00 2001 From: Nathan Hamblen Date: Sun, 8 Jun 2014 20:28:58 -0400 Subject: [PATCH 2/4] Update launchconfig --- src/main/conscript/cs/launchconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/conscript/cs/launchconfig b/src/main/conscript/cs/launchconfig index ff9b53c..566316e 100644 --- a/src/main/conscript/cs/launchconfig +++ b/src/main/conscript/cs/launchconfig @@ -1,10 +1,10 @@ [app] - version: 0.4.5-SNAPSHOT + version: 0.4.4 org: net.databinder.conscript name: conscript class: conscript.Conscript [scala] - version: 2.11.1 + version: 2.10.3 [repositories] local sonatype-releases: https://oss.sonatype.org/content/repositories/releases/ From afed5dbd746755e00dbc63cf4af1d829888e5f88 Mon Sep 17 00:00:00 2001 From: Nathan Hamblen Date: Mon, 9 Jun 2014 08:37:12 -0400 Subject: [PATCH 3/4] Update launchconfig --- src/main/conscript/cs/launchconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/conscript/cs/launchconfig b/src/main/conscript/cs/launchconfig index 566316e..26d9c87 100644 --- a/src/main/conscript/cs/launchconfig +++ b/src/main/conscript/cs/launchconfig @@ -1,10 +1,10 @@ [app] - version: 0.4.4 + version: 0.4.5-SNAPSHOT org: net.databinder.conscript name: conscript class: conscript.Conscript [scala] - version: 2.10.3 + version: 2.9.2 [repositories] local sonatype-releases: https://oss.sonatype.org/content/repositories/releases/ From 088f396dc04d36b6728f20cc5fd0878beaa208b7 Mon Sep 17 00:00:00 2001 From: Nathan Hamblen Date: Mon, 9 Jun 2014 08:37:54 -0400 Subject: [PATCH 4/4] Update launchconfig --- src/main/conscript/cs/launchconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/conscript/cs/launchconfig b/src/main/conscript/cs/launchconfig index 26d9c87..97a15e7 100644 --- a/src/main/conscript/cs/launchconfig +++ b/src/main/conscript/cs/launchconfig @@ -1,5 +1,5 @@ [app] - version: 0.4.5-SNAPSHOT + version: 0.4.4 org: net.databinder.conscript name: conscript class: conscript.Conscript