Skip to content

Commit a729010

Browse files
committed
Port conscript-plugin over as an auto plugin
1 parent 46b6a46 commit a729010

File tree

4 files changed

+103
-11
lines changed

4 files changed

+103
-11
lines changed

README.markdown

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,32 @@ itself can. Specify a credentials properties file, such as
116116
`SBT_CREDENTIALS` environment variable. The launcher will use these
117117
credentials when accessing protected resources in the specified realm.
118118

119-
Mailing List
120-
------------
119+
Making a conscripted app
120+
------------------------
121121

122-
Join the [Conscript mailing list][list] to ask questions and stay up to
123-
date on the project.
122+
We hope you'll make your own programs that use conscript. The
123+
`ConscriptPlugin` makes these easier to build and test.
124124

125-
[list]: https://groups.google.com/forum/?hl=en#!forum/conscript-scala
125+
Add this to the following `project/conscript.sbt`:
126126

127-
Conscripting
128-
------------
127+
```scala
128+
addSbtPlugin("org.foundweekends.conscript" % "sbt-conscript" % "0.5.0")
129+
```
129130

130-
We hope you'll make your own programs that use conscript. The
131-
[conscript-plugin][cplug] makes these easier to build and test.
131+
Next, add your sbt launchconfig file to `src/main/conscript/XYZ/launchconfig` (substitue `XYZ` with your script name such as `g8` and `cs`):
132+
133+
```
134+
[app]
135+
version: 0.6.9-SNAPSHOT
136+
org: org.foundweekends.giter8
137+
name: giter8
138+
class: giter8.Giter8
139+
[scala]
140+
version: 2.10.6
141+
[repositories]
142+
local
143+
maven-central
144+
sonatype-releases: https://oss.sonatype.org/content/repositories/releases/
145+
```
132146

133-
[cplug]: https://github.com/foundweekends/conscript-plugin
147+
You can test the app by calling `csRun XYZ` command.

build.sbt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import Dependencies._
22

33
lazy val root = (project in file(".")).
4+
enablePlugins(BuildInfoPlugin, CrossPerProjectPlugin).
5+
aggregate(plugin).
46
settings(
57
inThisBuild(List(
68
organization := "org.foundweekends.conscript",
@@ -19,6 +21,7 @@ lazy val root = (project in file(".")).
1921
scmInfo := Some(ScmInfo(url("https://github.com/foundweekends/conscript"), "[email protected]:foundweekends/conscript.git"))
2022
)),
2123
name := "conscript",
24+
crossScalaVersions := List("2.11.8"),
2225
libraryDependencies ++= List(launcherInterface, scalaSwing, dispatchCore, scopt, liftJson, slf4jJdk14),
2326
bintrayPackage := (bintrayPackage in ThisBuild).value,
2427
bintrayRepository := (bintrayRepository in ThisBuild).value,
@@ -67,4 +70,16 @@ lazy val root = (project in file(".")).
6770
buildInfoPackage := "conscript",
6871
publishMavenStyle := true,
6972
publishArtifact in Test := false
70-
).enablePlugins(BuildInfoPlugin)
73+
)
74+
75+
lazy val plugin = (project in file("sbt-conscript")).
76+
enablePlugins(CrossPerProjectPlugin).
77+
settings(
78+
name := "sbt-conscript",
79+
scalaVersion := "2.10.6",
80+
crossScalaVersions := List("2.10.6"),
81+
sbtPlugin := true,
82+
bintrayOrganization := Some("sbt"),
83+
bintrayRepository := "sbt-plugin-releases",
84+
bintrayPackage := "sbt-conscript"
85+
)

project/doge.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("com.eed3si9n" % "sbt-doge" % "0.1.5")
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package sbtconscript
2+
3+
import sbt._
4+
import Keys._
5+
6+
object ConscriptPlugin extends AutoPlugin {
7+
lazy val conscriptStr = "conscript"
8+
override lazy val requires = plugins.JvmPlugin
9+
object autoImport {
10+
lazy val csBoot = settingKey[File]("Boot directory used by csRun")
11+
lazy val csWrite = taskKey[Unit]("Write test launchconfig files to conscript-output")
12+
lazy val csRun = inputKey[Unit]("Run a named launchconfig, with parameters")
13+
}
14+
15+
import autoImport._
16+
override def projectSettings: Seq[Def.Setting[_]] =
17+
List(
18+
libraryDependencies += "org.scala-sbt" % "launcher" % "1.0.0" % "provided",
19+
sourceDirectory in csRun := { (sourceDirectory in Compile).value / conscriptStr },
20+
target in csRun := { target.value / conscriptStr },
21+
csBoot := { (target in csRun).value / "boot" },
22+
csWrite := csWriteTask.value,
23+
csRun := csRunTask.evaluated,
24+
(aggregate in csRun) := false
25+
)
26+
27+
private def configs(path: File) = (path ** "launchconfig").get
28+
private def configName(path: File) = file(path.getParent).getName
29+
lazy val csWriteTask = Def.task {
30+
val base = (sourceDirectory in csRun).value
31+
val output = (target in csRun).value
32+
val boot = csBoot.value
33+
IO.delete(output)
34+
IO.copyDirectory(base, output)
35+
configs(output).map { path =>
36+
IO.append(path,
37+
"""
38+
|[boot]
39+
| directory: %s
40+
|""".stripMargin.format(boot)
41+
)
42+
}
43+
}
44+
lazy val csRunTask = Def.inputTask {
45+
import sbt.Process._
46+
val args = Def.spaceDelimited().parsed
47+
val x = csWrite.value
48+
val y = publishLocal.value
49+
val output = (target in csRun).value
50+
val config = args.headOption.map { name =>
51+
configs(output).find {
52+
p => configName(p) == name
53+
}.getOrElse { sys.error("No launchconfig found for " + name) }
54+
}.getOrElse { sys.error("Usage: cs-run <appname> [args ...]") }
55+
"sbt @%s %s".format(config,
56+
args.toList.tail.mkString(" ")
57+
) ! match {
58+
case 0 => ()
59+
case n => sys.error("Launched app error code: " + n)
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)