Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support sbt 1.0 #107

Merged
merged 1 commit into from
Aug 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
language: scala
scala:
- 2.10.6
jdk:
- openjdk7

before_script:
- export PATH=$PATH:$HOME/bin/

script:
- sbt ++$TRAVIS_SCALA_VERSION --warn update compile scripted make-site
- sbt ";$SBT_CROSS_ENV; update; compile; runScriptedTest; makeSite"

sudo: false
dist: trusty
matrix:
include:
- jdk: openjdk7
env: SBT_CROSS_ENV="^^0.13.16"
- jdk: oraclejdk8
env: SBT_CROSS_ENV="^^1.0.0"

addons:
apt:
Expand Down
65 changes: 54 additions & 11 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,39 @@ licenses += ("BSD 3-Clause", url("http://opensource.org/licenses/BSD-3-Clause"))
scmInfo := Some(ScmInfo(url("https://github.com/sbt/sbt-site"), "git@github.com:sbt/sbt-site.git"))
//#scm-info

scalaVersion := "2.10.6"

scalaVersion in Global := "2.10.6"

scalacOptions ++= Seq("-deprecation", "-unchecked")

resolvers += Resolver.sonatypeRepo("releases")

val unfilteredVersion = "0.9.1"

libraryDependencies ++= Seq(
"net.databinder" %% "unfiltered-directives" % "0.8.4",
"net.databinder" %% "unfiltered-filter" % "0.8.4",
"net.databinder" %% "unfiltered-jetty" % "0.8.4",
"net.databinder" %% "unfiltered-specs2" % "0.8.4" % "test",
"ws.unfiltered" %% "unfiltered-directives" % unfilteredVersion,
"ws.unfiltered" %% "unfiltered-filter" % unfilteredVersion,
"ws.unfiltered" %% "unfiltered-jetty" % unfilteredVersion,
"ws.unfiltered" %% "unfiltered-specs2" % unfilteredVersion % "test",
"org.foundweekends" %% "pamflet-library" % "0.7.1",
"org.yaml" % "snakeyaml" % "1.13",
"com.typesafe" % "config" % "1.2.1", // Last version to support Java 1.6
"org.asciidoctor" % "asciidoctorj" % "1.5.4"
)

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

addSbtPlugin("org.planet42" % "laika-sbt" % "0.7.0")
libraryDependencies ++= {
if((sbtVersion in pluginCrossBuild).value.startsWith("0.13")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Laika and Paradox are fairly new additions.

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,
(scalaBinaryVersion in pluginCrossBuild).value
)
)
} else Nil
}

enablePlugins(ParadoxSitePlugin)
sourceDirectory in Paradox := sourceDirectory.value / "main" / "paradox"
Expand All @@ -50,6 +61,38 @@ 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 {
case class Test(group: String, name: Option[String])

val exclude = Seq(
Test("paradox", None), // paradox does not support sbt 1.0
Test("laika", None), // https://github.com/planet42/Laika/issues/57
Test("site", Some("can-run-generator-twice")), // use paradox
Test("site", Some("plays-nice-with-tut")), // use paradox
Test("site", Some("plays-nice-with-ghpages")) // https://github.com/sbt/sbt-ghpages/issues/36
)

val groups = file("src/sbt-test").listFiles.map(_.getName).toList
val runAll: Seq[String] = groups.filterNot(exclude.map(_.group).toSet).map(_ + "/*")
val runPartial: Seq[String] = exclude.collect{ case Test(g, Some(t)) => (g, t) }.groupBy(_._1).flatMap {
case (g, tests) =>
val excludeTests = tests.map(_._2).toSet
(file("src/sbt-test") / g).listFiles.map(_.getName).filterNot(excludeTests).map(g + "/" + _)
}.toList
val args = (runAll ++ runPartial).mkString(" ", " ", "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice, I didn't know this was possible.

streams.value.log.info("scripted test args =" + args)

Def.task{
scripted.toTask(args).value
}
}
}.value

scriptedLaunchOpts += "-Dproject.version="+version.value

// scriptedBufferLog := false
31 changes: 31 additions & 0 deletions src/main/scala-sbt-0.13/com/typesafe/sbt/site/Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.typesafe.sbt.site

import sbt._
import sbt.Keys._
import sbt.FilesInfo.Style

object Compat {

type Process = sbt.Process
val Process = sbt.Process
type ProcessLogger = sbt.ProcessLogger

def cached(cacheBaseDirectory: File, inStyle: Style, outStyle: Style)(action: (ChangeReport[File], ChangeReport[File]) => Set[File]): Set[File] => Set[File] =
FileFunction.cached(cacheBaseDirectory = cacheBaseDirectory)(inStyle = inStyle, outStyle = outStyle)(action = action)

val genSources = (s: State) => {
Preview.runTask(watchSources, s)
}

def watchSettings(config: Configuration): Seq[Setting[_]] =
Seq(
watchSources in Global ++= (sourceDirectory in config).value.***.get
)

def CacheStore(file: File) = file

implicit class FileOps(file: File) {
def allPaths = file.***
}

}
57 changes: 57 additions & 0 deletions src/main/scala-sbt-1.0/com/typesafe/sbt/site/Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.typesafe.sbt.site

import java.nio.file.Files

import sbt._
import sbt.Keys._
import sbt.util.CacheStoreFactory
import FileInfo.Style
import sbt.internal.io.Source

object Compat {

type Process = scala.sys.process.Process
val Process = scala.sys.process.Process
type ProcessLogger = scala.sys.process.ProcessLogger

def cached(cacheBaseDirectory: File, inStyle: Style, outStyle: Style)(action: (ChangeReport[File], ChangeReport[File]) => Set[File]): Set[File] => Set[File] =
sbt.util.FileFunction.cached(CacheStoreFactory(cacheBaseDirectory), inStyle = inStyle, outStyle = outStyle)(action = action)

val genSources: State => Seq[File] = {
import scala.collection.JavaConverters._

def sourceField[A](name: String): Source => A = {
val f = classOf[Source].getDeclaredField(name)
f.setAccessible(true)
src => f.get(src).asInstanceOf[A]
}

val baseField = sourceField[File]("base")
val includeField = sourceField[FileFilter]("includeFilter")
val excludeField = sourceField[FileFilter]("excludeFilter")

(s: State) => Preview.runTask(watchSources, s).flatMap { src =>
val base = baseField(src)
val include = includeField(src)
val exclude = excludeField(src)

Files.find(
base.toPath,
64,
(f, _) => include.accept(f.toFile) && !exclude.accept(f.toFile)
).iterator().asScala.map(_.toFile).toList
}
}

def watchSettings(config: Configuration): Seq[Setting[_]] =
Seq(
watchSources in Global += new Source(
base = (sourceDirectory in config).value,
includeFilter = (includeFilter in config).value,
excludeFilter = (excludeFilter in config).value
)
)

val CacheStore = sbt.util.CacheStore

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object SitePreviewPlugin extends AutoPlugin {
val port = previewFixedPort.value getOrElse Port.any
val browser = previewLaunchBrowser.value

Preview(port, (target in previewAuto).value, makeSite, watchSources, state.value) run { server =>
Preview(port, (target in previewAuto).value, makeSite, Compat.genSources, state.value) run { server =>
if(browser)
Browser open(server.portBindings.head.url)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.typesafe.sbt.site.gitbook

import sbt._
import Keys._
import com.typesafe.sbt.site.Compat.Process
import com.typesafe.sbt.site.SitePlugin.autoImport.siteSubdirName
import com.typesafe.sbt.site.SitePlugin
import com.typesafe.sbt.site.util.SiteHelpers
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/com/typesafe/sbt/site/hugo/HugoPlugin.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.typesafe.sbt.site.hugo

import com.typesafe.sbt.site.Compat.Process
import com.typesafe.sbt.site.SitePlugin.autoImport.siteSubdirName
import com.typesafe.sbt.site.SitePreviewPlugin.autoImport.previewFixedPort
import com.typesafe.sbt.site.SitePlugin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.typesafe.sbt.site.jekyll

import com.typesafe.sbt.site.Compat.Process
import com.typesafe.sbt.site.SitePlugin.autoImport.siteSubdirName
import com.typesafe.sbt.site.SitePlugin
import com.typesafe.sbt.site.util.RubyHelpers.RubyKeys
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.typesafe.sbt.site.nanoc

import java.io.FileReader
import com.typesafe.sbt.site.Compat.Process
import com.typesafe.sbt.site.SitePlugin.autoImport.siteSubdirName
import com.typesafe.sbt.site.SitePlugin
import com.typesafe.sbt.site.util.RubyHelpers.RubyKeys
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.typesafe.sbt.site.preprocess

import com.typesafe.sbt.site.SitePlugin
import com.typesafe.sbt.site.{Compat, SitePlugin}
import com.typesafe.sbt.site.SitePlugin.autoImport._
import com.typesafe.sbt.site.util.SiteHelpers
import sbt.Keys._
Expand Down Expand Up @@ -77,7 +77,7 @@ object PreprocessPlugin extends AutoPlugin {
transform: (File, File) => Unit,
cache: File,
log: Logger): File = {
val runTransform = FileFunction.cached(cache)(FilesInfo.hash, FilesInfo.exists) { (in, out) =>
val runTransform = Compat.cached(cache, FilesInfo.hash, FilesInfo.exists) { (in, out) =>
val map = Path.rebase(sourceDir, targetDir)
if (in.removed.nonEmpty || in.modified.nonEmpty) {
log.info("Preprocessing directory %s..." format sourceDir)
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/com/typesafe/sbt/site/preview.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import java.io.OutputStream
import collection.mutable.Map

object Preview {
def apply(port: Int, base: File, genSite: TaskKey[File], genSources: TaskKey[Seq[File]], state: State): Server = {
def apply(port: Int, base: File, genSite: TaskKey[File], genSources: State => Seq[File], state: State): Server = {
val rootFile = runTask(genSite, state)
val rootSources = runTask(genSources, state)
val rootSources = genSources(state)

val rootPage: Option[URL] = startPageURL(rootFile)
var mapSources: Map[File, Long] = mapFileToLastModified(rootSources)

val plan: Plan = unfiltered.filter.Planify {
case GET(unfiltered.request.Path(Seg(path))) => {
val newSources = runTask(genSources, state)
val newSources = genSources(state)
val newMapSources = mapFileToLastModified(newSources)
if(mapSources != newMapSources) {
val _ = runTask(genSite, state)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.typesafe.sbt.site.sphinx

import sbt._
import com.typesafe.sbt.site.Compat
import com.typesafe.sbt.site.Compat.{Process, _}


/**
Expand Down Expand Up @@ -99,7 +101,7 @@ private[sphinx] class CommandLineSphinxRunner extends SphinxRunner {
val target = baseTarget / builder
val doctrees = baseTarget / "doctrees" / builder
val cache = cacheDir / "sphinx" / builder
val cached = FileFunction.cached(cache)(FilesInfo.hash, FilesInfo.exists) { (in, out) =>
val cached = Compat.cached(cache, FilesInfo.hash, FilesInfo.exists) { (in, out) =>
val changes = in.modified
if (changes.nonEmpty) {
val tagList = if (tags.isEmpty) "" else tags.mkString(" (", ", ", ")")
Expand All @@ -117,7 +119,7 @@ private[sphinx] class CommandLineSphinxRunner extends SphinxRunner {
val exitCode = Process(command, src, env.toSeq : _*) ! logger
if (exitCode != 0) sys.error("Failed to build Sphinx %s documentation." format desc)
log.info("Sphinx %s documentation generated: %s" format (desc, target))
(target ***).get.toSet
target.allPaths.get.toSet
} else Set.empty
}
val inputs = src.descendantsExcept(include, exclude).get.toSet
Expand Down Expand Up @@ -154,6 +156,8 @@ private[sphinx] class CommandLineSphinxRunner extends SphinxRunner {
new ProcessLogger {
def info(i: => String): Unit = redirect(i)
def error(e: => String): Unit = redirect(e)
def err(e: => String): Unit = redirect(e)
def out(e: => String): Unit = redirect(e)
def buffer[T](f: => T): T = f
def redirect(message: String): Unit = {
if (message contains "ERROR") log.error(message)
Expand Down
13 changes: 8 additions & 5 deletions src/main/scala/com/typesafe/sbt/site/sphinx/SphinxPlugin.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.typesafe.sbt.site.sphinx

import com.typesafe.sbt.site.Compat._
import com.typesafe.sbt.site.SitePlugin.autoImport.siteSubdirName
import com.typesafe.sbt.site.SitePlugin
import com.typesafe.sbt.site.util.SiteHelpers
Expand Down Expand Up @@ -56,15 +57,16 @@ object SphinxPlugin extends AutoPlugin {
}

def defaultVersionProperties(version: String) = {
val binV = CrossVersion.binaryVersion(version, "")
val binV = CrossVersion.binarySbtVersion(version)
Map("version" -> binV, "release" -> version)
}

def installPackagesTask = Def.task {
val runner = sphinxRunner.value
val packages = sphinxPackages.value
val s = streams.value
packages map { p => runner.installPackage(p, target.value, s.log) }
val t = target.value
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

packages map { p => runner.installPackage(p, t, s.log) }
}

def combineSphinxInputs = Def.task {
Expand Down Expand Up @@ -112,8 +114,9 @@ object SphinxPlugin extends AutoPlugin {
key: TaskKey[S],
f: Task[S] => Task[T],
nil: T): Def.Initialize[Task[T]] = Def.task{
if ((enableOutput in key in key.scope).value) f(key.taskValue) else task {nil}
}.flatMap(identity)
val t = key.taskValue
if ((enableOutput in key in key.scope).value) f(t) else task {nil}
}.flatMap(identity(_))

def generateTask = Def.task {
val htmlOutput = generatedHtml.value
Expand All @@ -131,7 +134,7 @@ object SphinxPlugin extends AutoPlugin {
(epub ** "*.epub").get pair Path.rebase(epub, t)
}
val mapping = htmlMapping ++ pdfMapping ++ epubMapping
Sync(cache)(mapping)
Sync(CacheStore(cache))(mapping)
s.log.info("Sphinx documentation generated: %s" format t)
t
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.typesafe.sbt.site.util

import com.typesafe.sbt.site.Compat.Process
import sbt.Keys._
import sbt._

Expand Down
Loading