2012-09-14 04:58:39 +02:00
|
|
|
import sbt._
|
|
|
|
|
import Keys._
|
|
|
|
|
import Status.{isSnapshot, publishStatus}
|
2012-09-19 02:12:32 +02:00
|
|
|
import com.typesafe.sbt.{SbtGhPages,SbtGit,SbtSite,site=>sbtsite}
|
|
|
|
|
import SbtSite.{site, SiteKeys}
|
|
|
|
|
import SbtGhPages.{ghpages, GhPagesKeys => ghkeys}
|
|
|
|
|
import SbtGit.{git, GitKeys}
|
|
|
|
|
import sbtsite.SphinxSupport
|
2012-09-14 04:58:39 +02:00
|
|
|
import SiteKeys.{makeSite,siteMappings}
|
|
|
|
|
import Sxr.sxr
|
|
|
|
|
|
|
|
|
|
object Docs
|
|
|
|
|
{
|
2012-09-19 02:12:32 +02:00
|
|
|
val cnameFile = SettingKey[File]("cname-file", "Location of the CNAME file for the website.")
|
|
|
|
|
|
2012-09-14 04:58:39 +02:00
|
|
|
def settings: Seq[Setting[_]] =
|
|
|
|
|
site.settings ++
|
2012-09-19 02:12:32 +02:00
|
|
|
site.sphinxSupport("docs") ++
|
2012-09-14 04:58:39 +02:00
|
|
|
site.includeScaladoc("api") ++
|
2012-09-19 02:12:32 +02:00
|
|
|
siteIncludeSxr("sxr") ++
|
|
|
|
|
ghPagesSettings
|
2012-09-14 04:58:39 +02:00
|
|
|
|
2012-09-19 02:12:32 +02:00
|
|
|
def ghPagesSettings = ghpages.settings ++ Seq(
|
|
|
|
|
git.remoteRepo := "git@github.com:sbt/sbt.github.com.git",
|
|
|
|
|
ghkeys.synchLocal <<= synchLocalImpl,
|
|
|
|
|
cnameFile <<= (sourceDirectory in SphinxSupport.Sphinx) / "CNAME",
|
|
|
|
|
GitKeys.gitBranch in ghkeys.updatedRepository := Some("master")
|
2012-09-14 04:58:39 +02:00
|
|
|
)
|
|
|
|
|
|
2012-09-19 02:12:32 +02:00
|
|
|
def siteIncludeSxr(prefix: String) = Seq(
|
|
|
|
|
mappings in sxr <<= sxr.map(dir => Path.allSubpaths(dir).toSeq),
|
|
|
|
|
site.addMappingsToSiteDir(mappings in sxr, prefix)
|
|
|
|
|
)
|
2012-09-14 04:58:39 +02:00
|
|
|
|
2012-09-19 02:12:32 +02:00
|
|
|
def synchLocalImpl = (ghkeys.privateMappings, ghkeys.updatedRepository, version, isSnapshot, streams, cnameFile) map { (mappings, repo, v, snap, s, cname) =>
|
|
|
|
|
val versioned = repo / v
|
|
|
|
|
if(snap)
|
|
|
|
|
IO.delete(versioned)
|
|
|
|
|
else if(versioned.exists)
|
|
|
|
|
error("Site for " + v + " already exists: " + versioned.getAbsolutePath)
|
|
|
|
|
IO.copy(mappings map { case (file, target) => (file, versioned / target) })
|
|
|
|
|
IO.copyFile(cname, repo / cname.getName)
|
|
|
|
|
IO.touch(repo / ".nojekyll")
|
|
|
|
|
linkSite(repo, v, if(snap) "snapshot" else "release", s.log)
|
|
|
|
|
s.log.info("Copied site to " + versioned)
|
|
|
|
|
repo
|
|
|
|
|
}
|
2012-09-14 04:58:39 +02:00
|
|
|
|
|
|
|
|
def linkSite(base: File, to: String, from: String, log: Logger) {
|
|
|
|
|
val current = base / to
|
|
|
|
|
assert(current.isDirectory, "Versioned site not present at " + current.getAbsolutePath)
|
2012-09-19 02:12:32 +02:00
|
|
|
val symlinkDir = base / from
|
|
|
|
|
symlinkDir.delete()
|
|
|
|
|
symlink(path = to, file = symlinkDir, log = log)
|
2012-09-14 04:58:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: platform independence/use symlink from Java 7
|
2012-09-19 02:12:32 +02:00
|
|
|
def symlink(path: String, file: File, log: Logger): Unit =
|
|
|
|
|
"ln" :: "-s" :: path :: file.getAbsolutePath :: Nil ! log match {
|
2012-09-14 04:58:39 +02:00
|
|
|
case 0 => ()
|
2012-09-19 02:12:32 +02:00
|
|
|
case code => error("Could not create symbolic link '" + file.getAbsolutePath + "' with path " + path)
|
2012-09-14 04:58:39 +02:00
|
|
|
}
|
|
|
|
|
}
|