Skip to content

Commit

Permalink
Merge pull request #111 from sbt/sbt-1.0-paradox
Browse files Browse the repository at this point in the history
Support paradox for sbt 1.0
  • Loading branch information
metasim authored Sep 23, 2017
2 parents 7563a35 + 33fda84 commit 7efeec0
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 28 deletions.
61 changes: 35 additions & 26 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ libraryDependencies ++= Seq(
"org.asciidoctor" % "asciidoctorj" % "1.5.4"
)

addSbtPlugin("com.lightbend.paradox" % "sbt-paradox" % "0.3.0")

libraryDependencies ++= {
if ((sbtVersion in pluginCrossBuild).value.startsWith("0.13")) {
if ((sbtBinaryVersion in pluginCrossBuild).value == "0.13") {
Seq(
Defaults.sbtPluginExtra(
"com.lightbend.paradox" % "sbt-paradox" % "0.2.13",
(sbtBinaryVersion in pluginCrossBuild).value,
(scalaBinaryVersion in pluginCrossBuild).value
),
Defaults.sbtPluginExtra(
"org.planet42" % "laika-sbt" % "0.7.0",
(sbtBinaryVersion in pluginCrossBuild).value,
Expand All @@ -46,6 +43,9 @@ libraryDependencies ++= {
} else Nil
}

// fixed in https://github.com/sbt/sbt/pull/3397 (for sbt 0.13.17)
sbtBinaryVersion in update := (sbtBinaryVersion in pluginCrossBuild).value

enablePlugins(ParadoxSitePlugin)
sourceDirectory in Paradox := sourceDirectory.value / "main" / "paradox"
paradoxTheme := Some(builtinParadoxTheme("generic"))
Expand All @@ -62,27 +62,36 @@ git.remoteRepo := scmInfo.value.get.connection
scriptedSettings

TaskKey[Unit]("runScriptedTest") := Def.taskDyn {
if ((sbtVersion in pluginCrossBuild).value.startsWith("0.13")) {
Def.task{
scripted.toTask("").value
}
} else {
val base = sbtTestDirectory.value
val exclude = Seq(
base / "paradox" * AllPassFilter, // paradox does not support sbt 1.0
base / "laika" * AllPassFilter, // https://github.com/planet42/Laika/issues/57
base / "site" * ("can-run-generator-twice" || "plays-nice-with-tut") // use paradox
)

val allTests = base * AllPassFilter * AllPassFilter filter { _.isDirectory }
val tests = allTests --- exclude.reduce(_ +++ _)
val args = tests.get.map(Path.relativeTo(base)).flatten.mkString(" ", " ", "")
streams.value.log.info("scripted test args = " + args)

Def.task{
scripted.toTask(args).value
}
val sbtBinVersion = (sbtBinaryVersion in pluginCrossBuild).value
val base = sbtTestDirectory.value

def isCompatible(directory: File): Boolean = {
val buildProps = new java.util.Properties()
IO.load(buildProps, directory / "project" / "build.properties")
Option(buildProps.getProperty("sbt.version"))
.map { version =>
val requiredBinVersion = CrossVersion.binarySbtVersion(version)
val compatible = requiredBinVersion == sbtBinVersion
if (!compatible) {
val testName = directory.relativeTo(base).getOrElse(directory)
streams.value.log.warn(s"Skipping $testName since it requires sbt $requiredBinVersion")
}
compatible
}
.getOrElse(true)
}

val testDirectoryFinder = base * AllPassFilter * AllPassFilter filter { _.isDirectory }
val tests = for {
test <- testDirectoryFinder.get
if isCompatible(test)
path <- Path.relativeTo(base)(test)
} yield path.replace('\\', '/')

if (tests.nonEmpty)
Def.task(scripted.toTask(tests.mkString(" ", " ", "")).value)
else
Def.task(streams.value.log.warn("No tests can be run for this sbt version"))
}.value

scriptedLaunchOpts += "-Dproject.version="+version.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object ParadoxSitePlugin extends AutoPlugin {
mappings := {
val _ = paradox.value
val output = (target in paradox).value
output ** includeFilter.value --- output pair relativeTo(output)
output ** includeFilter.value --- output pair Path.relativeTo(output)
},
siteSubdirName := ""
)
Expand Down
1 change: 1 addition & 0 deletions src/sbt-test/laika/blog-post/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.16
1 change: 1 addition & 0 deletions src/sbt-test/laika/minimal/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.16
18 changes: 18 additions & 0 deletions src/sbt-test/site/plays-nice-with-tut-sbt-0.13/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name := "test"

enablePlugins(ParadoxSitePlugin, TutPlugin)
sourceDirectory in Paradox := tutTargetDirectory.value
makeSite := makeSite.dependsOn(tut).value

TaskKey[Unit]("checkContent") := {
val dest = (target in makeSite).value

def checkFileContent(file: File, expected: String) = {
assert(file.exists, s"${file.getAbsolutePath} did not exist")
val actual = IO.readLines(file)
assert(actual.exists(_.contains(expected)), s"Did not find $expected in:\n${actual.mkString("\n")}")
}

checkFileContent(dest / "index.html", "Here is how you add numbers")
checkFileContent(dest / "test.html", "scala.util.Try")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.16
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % sys.props("project.version"))
addSbtPlugin("org.tpolecat" % "tut-plugin" % "0.5.2")
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Tutorial

<!-- #tut -->
Here is how you add numbers:

```tut
1 + 1
```
<!-- #tut -->

@@@ index

- [test](test.md)

@@@
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Test

```tut:silent
import scala.util.Try
```
2 changes: 2 additions & 0 deletions src/sbt-test/site/plays-nice-with-tut-sbt-0.13/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> makeSite
> checkContent
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.0.0-RC2
2 changes: 1 addition & 1 deletion src/sbt-test/site/plays-nice-with-tut/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % sys.props("project.version"))
addSbtPlugin("org.tpolecat" % "tut-plugin" % "0.5.2")
addSbtPlugin("org.tpolecat" % "tut-plugin" % "0.6.1")

0 comments on commit 7efeec0

Please sign in to comment.