mirror of https://github.com/sbt/sbt.git
Cleanup project/Transform.scala
This commit is contained in:
parent
964f7867b3
commit
02e26465f7
|
|
@ -930,7 +930,7 @@ lazy val vscodePlugin = (project in file("vscode-sbt-scala"))
|
||||||
crossScalaVersions := Seq(baseScalaVersion),
|
crossScalaVersions := Seq(baseScalaVersion),
|
||||||
skip in publish := true,
|
skip in publish := true,
|
||||||
compile in Compile := {
|
compile in Compile := {
|
||||||
val u = update.value
|
update.value: Unit
|
||||||
runNpm("run compile", baseDirectory.value, streams.value.log)
|
runNpm("run compile", baseDirectory.value, streams.value.log)
|
||||||
sbt.internal.inc.Analysis.empty
|
sbt.internal.inc.Analysis.empty
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import sbt._, Keys._
|
import sbt._
|
||||||
/*
|
/*
|
||||||
import StatusPlugin.autoImport._
|
import StatusPlugin.autoImport._
|
||||||
import com.typesafe.sbt.site.SitePlugin.autoImport._
|
import com.typesafe.sbt.site.SitePlugin.autoImport._
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,11 @@ import java.lang.reflect.InvocationTargetException
|
||||||
import sbt._
|
import sbt._
|
||||||
import sbt.internal.inc.ScalaInstance
|
import sbt.internal.inc.ScalaInstance
|
||||||
import sbt.internal.inc.classpath.{ ClasspathUtilities, FilteredLoader }
|
import sbt.internal.inc.classpath.{ ClasspathUtilities, FilteredLoader }
|
||||||
import sbt.ScriptedPlugin.autoImport._
|
|
||||||
|
|
||||||
object LocalScriptedPlugin extends AutoPlugin {
|
object LocalScriptedPlugin extends AutoPlugin {
|
||||||
override def requires = plugins.JvmPlugin
|
override def requires = plugins.JvmPlugin
|
||||||
|
|
||||||
object autoImport extends ScriptedKeys
|
object autoImport extends ScriptedKeys
|
||||||
import autoImport._
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trait ScriptedKeys {
|
trait ScriptedKeys {
|
||||||
|
|
|
||||||
|
|
@ -1,108 +1,49 @@
|
||||||
import sbt.io.Path._
|
|
||||||
import sbt._
|
import sbt._
|
||||||
import Keys._
|
import sbt.Keys._
|
||||||
|
|
||||||
object Transform {
|
object Transform {
|
||||||
lazy val transformSources = TaskKey[Seq[File]]("transform-sources")
|
private val conscriptConfigs = taskKey[Unit]("")
|
||||||
lazy val inputSourceDirectories = SettingKey[Seq[File]]("input-source-directories")
|
|
||||||
lazy val inputSourceDirectory = SettingKey[File]("input-source-directory")
|
|
||||||
lazy val inputSources = TaskKey[Seq[File]]("input-sources")
|
|
||||||
lazy val sourceProperties = TaskKey[Map[String, String]]("source-properties")
|
|
||||||
|
|
||||||
lazy val transformResources = TaskKey[Seq[File]]("transform-resources")
|
|
||||||
lazy val inputResourceDirectories = SettingKey[Seq[File]]("input-resource-directories")
|
|
||||||
lazy val inputResourceDirectory = SettingKey[File]("input-resource-directory")
|
|
||||||
lazy val inputResources = TaskKey[Seq[File]]("input-resources")
|
|
||||||
lazy val resourceProperties = TaskKey[Map[String, String]]("resource-properties")
|
|
||||||
|
|
||||||
lazy val conscriptConfigs = TaskKey[Unit]("conscript-configs")
|
|
||||||
|
|
||||||
def conscriptSettings(launch: Reference) = Seq(
|
def conscriptSettings(launch: Reference) = Seq(
|
||||||
conscriptConfigs := {
|
conscriptConfigs := {
|
||||||
val res = (managedResources in launch in Compile).value
|
val sourceFile = (launch / Compile / managedResources).value
|
||||||
val src = (sourceDirectory in Compile).value
|
.find(_.getName == "sbt.boot.properties")
|
||||||
val source = res.find(_.getName == "sbt.boot.properties") getOrElse sys.error(
|
.getOrElse(sys.error("No managed boot.properties file."))
|
||||||
"No managed boot.properties file.")
|
val source = IO.readLines(sourceFile)
|
||||||
copyConscriptProperties(source, src / "conscript")
|
val conscriptBase = (Compile / sourceDirectory).value / "conscript"
|
||||||
()
|
IO.delete(conscriptBase)
|
||||||
}
|
val pairs = Seq(
|
||||||
)
|
"sbt.xMain" -> "xsbt",
|
||||||
|
"sbt.ScriptMain" -> "scalas",
|
||||||
def copyConscriptProperties(source: File, conscriptBase: File): Seq[File] = {
|
"sbt.ConsoleMain" -> "screpl",
|
||||||
IO.delete(conscriptBase)
|
)
|
||||||
val pairs = Seq(
|
for ((main, dir) <- pairs) {
|
||||||
"sbt.xMain" -> "xsbt",
|
val lines = source.map(l => if (l.trim.startsWith("class:")) s" class: $main" else l)
|
||||||
"sbt.ScriptMain" -> "scalas",
|
IO.writeLines(conscriptBase / dir / "launchconfig", lines)
|
||||||
"sbt.ConsoleMain" -> "screpl"
|
}
|
||||||
)
|
|
||||||
for ((main, dir) <- pairs) yield {
|
|
||||||
val file = conscriptBase / dir / "launchconfig"
|
|
||||||
copyPropertiesFile(source, main, file)
|
|
||||||
file
|
|
||||||
}
|
|
||||||
}
|
|
||||||
def copyPropertiesFile(source: File, newMain: String, target: File): Unit = {
|
|
||||||
def subMain(line: String): String =
|
|
||||||
if (line.trim.startsWith("class:")) " class: " + newMain else line
|
|
||||||
IO.writeLines(target, IO.readLines(source) map subMain)
|
|
||||||
}
|
|
||||||
|
|
||||||
def crossGenSettings = transSourceSettings ++ Seq(
|
|
||||||
sourceProperties := Map("cross.package0" -> "sbt", "cross.package1" -> "cross")
|
|
||||||
)
|
|
||||||
def transSourceSettings = Seq(
|
|
||||||
inputSourceDirectory := sourceDirectory.value / "input_sources",
|
|
||||||
inputSourceDirectories := Seq(inputSourceDirectory.value),
|
|
||||||
inputSources := (inputSourceDirectories.value ** (-DirectoryFilter)).get,
|
|
||||||
fileMappings in transformSources := transformSourceMappings.value,
|
|
||||||
transformSources := {
|
|
||||||
val rs = (fileMappings in transformSources).value
|
|
||||||
val props = sourceProperties.value
|
|
||||||
rs map { case (in, out) => transform(in, out, props) }
|
|
||||||
},
|
},
|
||||||
sourceGenerators += transformSources.taskValue
|
|
||||||
)
|
)
|
||||||
def transformSourceMappings = Def task {
|
|
||||||
val ss = inputSources.value
|
|
||||||
val sdirs = inputSourceDirectories.value
|
|
||||||
val sm = sourceManaged.value
|
|
||||||
((ss --- sdirs) pair (rebase(sdirs, sm) | flat(sm))).toSeq
|
|
||||||
}
|
|
||||||
def configSettings = transResourceSettings ++ Seq(
|
|
||||||
resourceProperties :=
|
|
||||||
Map("org" -> organization.value,
|
|
||||||
"sbt.version" -> version.value,
|
|
||||||
"scala.version" -> scalaVersion.value)
|
|
||||||
)
|
|
||||||
def transResourceSettings = Seq(
|
|
||||||
inputResourceDirectory := sourceDirectory.value / "input_resources",
|
|
||||||
inputResourceDirectories := Seq(inputResourceDirectory.value),
|
|
||||||
inputResources := (inputResourceDirectories.value ** (-DirectoryFilter)).get,
|
|
||||||
fileMappings in transformResources := transformResourceMappings.value,
|
|
||||||
transformResources := {
|
|
||||||
val rs = (fileMappings in transformResources).value
|
|
||||||
val props = resourceProperties.value
|
|
||||||
rs map { case (in, out) => transform(in, out, props) }
|
|
||||||
},
|
|
||||||
resourceGenerators += transformResources.taskValue
|
|
||||||
)
|
|
||||||
def transformResourceMappings = Def task {
|
|
||||||
val rs = inputResources.value
|
|
||||||
val rdirs = inputResourceDirectories.value
|
|
||||||
val rm = resourceManaged.value
|
|
||||||
((rs --- rdirs) pair (rebase(rdirs, rm) | flat(rm))).toSeq
|
|
||||||
}
|
|
||||||
|
|
||||||
def transform(in: File, out: File, map: Map[String, String]): File = {
|
def configSettings = Seq(
|
||||||
def get(key: String): String =
|
resourceGenerators += Def.task {
|
||||||
map.getOrElse(key, sys.error("No value defined for key '" + key + "'"))
|
val rdirs = Seq(sourceDirectory.value / "input_resources")
|
||||||
val newString = Property.replaceAllIn(IO.read(in), mtch => get(mtch.group(1)))
|
val rm = resourceManaged.value
|
||||||
if (Some(newString) != read(out))
|
val paths = (rdirs ** (-DirectoryFilter)).get --- rdirs
|
||||||
IO.write(out, newString)
|
val rs = paths.pair(Path.rebase(rdirs, rm) | Path.flat(rm))
|
||||||
out
|
val props = Map(
|
||||||
}
|
"org" -> organization.value,
|
||||||
def read(file: File): Option[String] = try { Some(IO.read(file)) } catch {
|
"sbt.version" -> version.value,
|
||||||
case _: java.io.IOException => None
|
"scala.version" -> scalaVersion.value,
|
||||||
}
|
)
|
||||||
lazy val Property = """\$\{\{([\w.-]+)\}\}""".r
|
def get(key: String) = props.getOrElse(key, sys.error(s"No value defined for key '$key'"))
|
||||||
|
val Property = """\$\{\{([\w.-]+)\}\}""".r
|
||||||
|
val catcher = scala.util.control.Exception.catching(classOf[java.io.IOException])
|
||||||
|
rs.map { case (in, out) =>
|
||||||
|
val newString = Property.replaceAllIn(IO.read(in), mtch => get(mtch.group(1)))
|
||||||
|
if (Some(newString) != catcher.opt(IO.read(out)))
|
||||||
|
IO.write(out, newString)
|
||||||
|
out
|
||||||
|
}
|
||||||
|
}.taskValue,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,10 +105,10 @@ object Util {
|
||||||
def cleanPom(pomNode: scala.xml.Node) = {
|
def cleanPom(pomNode: scala.xml.Node) = {
|
||||||
import scala.xml._
|
import scala.xml._
|
||||||
def cleanNodes(nodes: Seq[Node]): Seq[Node] = nodes flatMap {
|
def cleanNodes(nodes: Seq[Node]): Seq[Node] = nodes flatMap {
|
||||||
case elem @ Elem(prefix, "dependency", attributes, scope, children @ _*)
|
case elem @ Elem(_, "dependency", _, _, _*)
|
||||||
if excludePomDependency(elem) =>
|
if excludePomDependency(elem) =>
|
||||||
NodeSeq.Empty
|
NodeSeq.Empty
|
||||||
case Elem(prefix, "classifier", attributes, scope, children @ _*) =>
|
case Elem(_, "classifier", _, _, _*) =>
|
||||||
NodeSeq.Empty
|
NodeSeq.Empty
|
||||||
case Elem(prefix, label, attributes, scope, children @ _*) =>
|
case Elem(prefix, label, attributes, scope, children @ _*) =>
|
||||||
val cleanedNodes = cleanNodes(children)
|
val cleanedNodes = cleanNodes(children)
|
||||||
|
|
@ -186,6 +186,6 @@ object Licensed {
|
||||||
if (!note.exists) Nil
|
if (!note.exists) Nil
|
||||||
else
|
else
|
||||||
try { seePaths(base, IO.read(note)) } catch {
|
try { seePaths(base, IO.read(note)) } catch {
|
||||||
case NonFatal(e) => s.log.warn("Could not read NOTICE"); Nil
|
case NonFatal(_) => s.log.warn("Could not read NOTICE"); Nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
scalacOptions ++= Seq("-feature", "-language:postfixOps")
|
scalacOptions ++= Seq("-feature", "-language:postfixOps", "-Ywarn-unused:_,-imports")
|
||||||
|
|
||||||
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.0.0")
|
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.0.0")
|
||||||
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.5")
|
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.5")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue