diff --git a/build.sbt b/build.sbt index ef1878c67..361c78838 100644 --- a/build.sbt +++ b/build.sbt @@ -930,7 +930,7 @@ lazy val vscodePlugin = (project in file("vscode-sbt-scala")) crossScalaVersions := Seq(baseScalaVersion), skip in publish := true, compile in Compile := { - val u = update.value + update.value: Unit runNpm("run compile", baseDirectory.value, streams.value.log) sbt.internal.inc.Analysis.empty }, diff --git a/project/Docs.scala b/project/Docs.scala index 806f9493d..0e79269c1 100644 --- a/project/Docs.scala +++ b/project/Docs.scala @@ -1,4 +1,4 @@ -import sbt._, Keys._ +import sbt._ /* import StatusPlugin.autoImport._ import com.typesafe.sbt.site.SitePlugin.autoImport._ diff --git a/project/Scripted.scala b/project/Scripted.scala index 10a52f10d..7c7fb2607 100644 --- a/project/Scripted.scala +++ b/project/Scripted.scala @@ -5,13 +5,11 @@ import java.lang.reflect.InvocationTargetException import sbt._ import sbt.internal.inc.ScalaInstance import sbt.internal.inc.classpath.{ ClasspathUtilities, FilteredLoader } -import sbt.ScriptedPlugin.autoImport._ object LocalScriptedPlugin extends AutoPlugin { override def requires = plugins.JvmPlugin object autoImport extends ScriptedKeys - import autoImport._ } trait ScriptedKeys { diff --git a/project/Transform.scala b/project/Transform.scala index 20a47347e..e6d61676d 100644 --- a/project/Transform.scala +++ b/project/Transform.scala @@ -1,108 +1,49 @@ -import sbt.io.Path._ import sbt._ -import Keys._ +import sbt.Keys._ object Transform { - lazy val transformSources = TaskKey[Seq[File]]("transform-sources") - 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") + private val conscriptConfigs = taskKey[Unit]("") def conscriptSettings(launch: Reference) = Seq( conscriptConfigs := { - val res = (managedResources in launch in Compile).value - val src = (sourceDirectory in Compile).value - val source = res.find(_.getName == "sbt.boot.properties") getOrElse sys.error( - "No managed boot.properties file.") - copyConscriptProperties(source, src / "conscript") - () - } - ) - - def copyConscriptProperties(source: File, conscriptBase: File): Seq[File] = { - IO.delete(conscriptBase) - val pairs = Seq( - "sbt.xMain" -> "xsbt", - "sbt.ScriptMain" -> "scalas", - "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) } + val sourceFile = (launch / Compile / managedResources).value + .find(_.getName == "sbt.boot.properties") + .getOrElse(sys.error("No managed boot.properties file.")) + val source = IO.readLines(sourceFile) + val conscriptBase = (Compile / sourceDirectory).value / "conscript" + IO.delete(conscriptBase) + val pairs = Seq( + "sbt.xMain" -> "xsbt", + "sbt.ScriptMain" -> "scalas", + "sbt.ConsoleMain" -> "screpl", + ) + for ((main, dir) <- pairs) { + val lines = source.map(l => if (l.trim.startsWith("class:")) s" class: $main" else l) + IO.writeLines(conscriptBase / dir / "launchconfig", lines) + } }, - 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 get(key: String): String = - map.getOrElse(key, sys.error("No value defined for key '" + key + "'")) - val newString = Property.replaceAllIn(IO.read(in), mtch => get(mtch.group(1))) - if (Some(newString) != read(out)) - IO.write(out, newString) - out - } - def read(file: File): Option[String] = try { Some(IO.read(file)) } catch { - case _: java.io.IOException => None - } - lazy val Property = """\$\{\{([\w.-]+)\}\}""".r + def configSettings = Seq( + resourceGenerators += Def.task { + val rdirs = Seq(sourceDirectory.value / "input_resources") + val rm = resourceManaged.value + val paths = (rdirs ** (-DirectoryFilter)).get --- rdirs + val rs = paths.pair(Path.rebase(rdirs, rm) | Path.flat(rm)) + val props = Map( + "org" -> organization.value, + "sbt.version" -> version.value, + "scala.version" -> scalaVersion.value, + ) + 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, + ) } diff --git a/project/Util.scala b/project/Util.scala index 80bd55008..09714ca15 100644 --- a/project/Util.scala +++ b/project/Util.scala @@ -105,10 +105,10 @@ object Util { def cleanPom(pomNode: scala.xml.Node) = { import scala.xml._ def cleanNodes(nodes: Seq[Node]): Seq[Node] = nodes flatMap { - case elem @ Elem(prefix, "dependency", attributes, scope, children @ _*) + case elem @ Elem(_, "dependency", _, _, _*) if excludePomDependency(elem) => NodeSeq.Empty - case Elem(prefix, "classifier", attributes, scope, children @ _*) => + case Elem(_, "classifier", _, _, _*) => NodeSeq.Empty case Elem(prefix, label, attributes, scope, children @ _*) => val cleanedNodes = cleanNodes(children) @@ -186,6 +186,6 @@ object Licensed { if (!note.exists) Nil else 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 } } diff --git a/project/plugins.sbt b/project/plugins.sbt index c5959a110..d07487ba2 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -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("org.foundweekends" % "sbt-bintray" % "0.5.5")