Skip to content
Closed
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
37 changes: 27 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,21 @@ lazy val scaffold = (projectMatrix in file("scaffold"))
commonSettings,
name := "sbt-giter8-scaffold",
description := "sbt plugin for scaffolding giter8 templates",
sbtPlugin := true,
scriptedLaunchOpts ++= javaVmArgs.filter(a => Seq("-Xmx", "-Xms", "-XX").exists(a.startsWith)),
scriptedBufferLog := false,
scriptedLaunchOpts += ("-Dplugin.version=" + version.value)
sbtPlugin := true
)
.jvmPlatform(
scalaVersions = Seq(scala212, scala3)
scalaVersions = Seq(scala212),
settings = Seq(
scriptedLaunchOpts ++= javaVmArgs.filter(a => Seq("-Xmx", "-Xms", "-XX").exists(a.startsWith)),
scriptedBufferLog := false,
scriptedLaunchOpts += ("-Dplugin.version=" + version.value)
)
)
.jvmPlatform(
scalaVersions = Seq(scala3),
settings = Seq(
scripted := Def.task(()).value
)
)

lazy val plugin = (projectMatrix in file("plugin"))
Expand All @@ -131,13 +139,22 @@ lazy val plugin = (projectMatrix in file("plugin"))
commonSettings,
name := "sbt-giter8",
description := "sbt plugin for testing giter8 templates",
sbtPlugin := true,
scriptedLaunchOpts ++= javaVmArgs.filter(a => Seq("-Xmx", "-Xms", "-XX").exists(a.startsWith)),
scriptedBufferLog := false,
scriptedLaunchOpts += ("-Dplugin.version=" + version.value)
sbtPlugin := true
)
.jvmPlatform(
scalaVersions = Seq(scala212, scala3)
scalaVersions = Seq(scala212),
settings = Seq(
scriptedLaunchOpts ++= javaVmArgs.filter(a => Seq("-Xmx", "-Xms", "-XX").exists(a.startsWith)),
scriptedBufferLog := false,
scriptedLaunchOpts += ("-Dplugin.version=" + version.value)
)
)
.jvmPlatform(
scalaVersions = Seq(scala3),
// sbt 2.x scripted-sbt resolution does not match sbt 1.x fixture projects; giter8 scripted is exercised on 2.12.
settings = Seq(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't disable sbt 2 tests.

scripted := Def.task(()).value
)
)

lazy val gitsupport = (projectMatrix in file("cli-git"))
Expand Down
8 changes: 6 additions & 2 deletions library/src/main/scala/g8.scala
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,17 @@ object G8 {
case x => x
}

val ignored = relative
// `relative` may use '\' on Windows; normalize so we split path segments correctly and
// StringTemplate does not interpret '\$' as an escape before a property.
val relNorm = relative.replace('\\', '/')

val ignored = relNorm
.split("/")
.map(part => applyTemplate(formatize(part), fileParams))
.exists(_.isEmpty)

if (ignored) None
else Some(new File(toPath, applyTemplate(formatize(relative), fileParams)))
else Some(new File(toPath, applyTemplate(formatize(relNorm), fileParams)))
} catch {
case e: STException =>
// add the current relative path to the exception for debugging purposes
Expand Down
39 changes: 24 additions & 15 deletions plugin/src/main/scala/Giter8Plugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import giter8.Giter8PluginCompat._
import sbt._
import sbt.Path.relativeTo
import sbt.sbtgiter8.ScriptedCompat
import sbt.ScriptedPlugin.autoImport.scriptedBufferLog
import sbt.ScriptedPlugin.autoImport.scriptedLaunchOpts
import sbt.ScriptedPlugin.autoImport.scriptedDependencies
import sbt.ScriptedPlugin.autoImport.sbtTestDirectory

object Giter8Plugin extends sbt.AutoPlugin {
override val requires = sbt.plugins.JvmPlugin
Expand All @@ -47,11 +43,6 @@ object Giter8Plugin extends sbt.AutoPlugin {

import autoImport._

override lazy val globalSettings = Seq(
scriptedBufferLog := true,
scriptedLaunchOpts := Seq()
)

lazy val baseGiter8Settings: Seq[Def.Setting[?]] = Seq(
g8 := {
val base = (g8 / unmanagedSourceDirectories).value
Expand Down Expand Up @@ -109,12 +100,14 @@ object Giter8Plugin extends sbt.AutoPlugin {
}
)

lazy val giter8TestSettings: Seq[Def.Setting[?]] = ScriptedPlugin.projectSettings ++
Seq(
Test / g8Test := { ScriptedPlugin.autoImport.scripted.evaluated },
/** Wired by [[Giter8ScriptedPlugin]] when `ScriptedPlugin` is enabled (e.g. for `g8Test`). */
private[giter8] lazy val giter8TestSettings: Seq[Def.Setting[?]] = {
import sbt.ScriptedPlugin.autoImport.{scriptedBufferLog, scriptedDependencies, sbtTestDirectory}
sbt.ScriptedPlugin.projectSettings ++ Seq(
Test / g8Test := { sbt.ScriptedPlugin.autoImport.scripted.evaluated },
Test / g8Test / aggregate := false,
scriptedDependencies := Def.uncached {
val x = (Test / g8).value
val _ = (Test / g8).value
},
Test / g8 := {
val base = (Compile / g8 / unmanagedSourceDirectories).value
Expand Down Expand Up @@ -171,8 +164,24 @@ object Giter8Plugin extends sbt.AutoPlugin {
.find(_.isFile)
.getOrElse(defaultTestScript)
},
Test / g8 / scriptedBufferLog := true
Test / g8 / scriptedBufferLog := false
)
}

override lazy val projectSettings: Seq[Def.Setting[?]] = inConfig(Compile)(baseGiter8Settings)
}

/** Enables `g8Test` / scripted integration; requires [[Giter8Plugin]] and `ScriptedPlugin`. */
object Giter8ScriptedPlugin extends sbt.AutoPlugin {
override val requires = Giter8Plugin && sbt.ScriptedPlugin
override val trigger = allRequirements

import sbt.ScriptedPlugin.autoImport._

override lazy val globalSettings = Seq(
scriptedBufferLog := false,
scriptedLaunchOpts := Seq()
)

override lazy val projectSettings: Seq[Def.Setting[?]] = inConfig(Compile)(baseGiter8Settings) ++ giter8TestSettings
override lazy val projectSettings: Seq[Def.Setting[?]] = Giter8Plugin.giter8TestSettings
}
5 changes: 5 additions & 0 deletions plugin/src/sbt-test/giter8/root-layout/build.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
enablePlugins(ScriptedPlugin)

Compile / unmanagedSourceDirectories += baseDirectory.value

// ScriptedPlugin 1.x pulls scripted-sbt for this Scala binary version (2.12 is always published).
scalaVersion := "2.12.21"
2 changes: 2 additions & 0 deletions plugin/src/sbt-test/giter8/root-layout/project/giter8.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
*/

addSbtPlugin("org.foundweekends.giter8" % "sbt-giter8" % System.getProperty("plugin.version"))

libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
11 changes: 4 additions & 7 deletions plugin/src/sbt-test/giter8/simple/build.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
enablePlugins(ScriptedPlugin)

scalaVersion := "2.12.21"

TaskKey[Unit]("writeInvalidFile") := {
IO.write(file("src/main/g8/src/test/scala/invalid.scala"), "invalid file")
}

val javaVmArgs: List[String] = {
import scala.collection.JavaConverters._
java.lang.management.ManagementFactory.getRuntimeMXBean.getInputArguments.asScala.toList
}

scriptedLaunchOpts ++= javaVmArgs.filter(a => Seq("-Xmx", "-Xms", "-XX").exists(a.startsWith))
3 changes: 3 additions & 0 deletions plugin/src/sbt-test/giter8/simple/project/giter8.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
*/

addSbtPlugin("org.foundweekends.giter8" % "sbt-giter8" % System.getProperty("plugin.version"))

// sbt-giter8's Giter8Plugin requires ScriptedPlugin; add it to the meta-build like any sbt plugin test project.
libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
8 changes: 3 additions & 5 deletions plugin/src/sbt-test/giter8/simple/src/main/g8/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

name := "$name$"

scalaVersion := "2.11.12"

libraryDependencies += "net.databinder" %% "unfiltered" % "$unfiltered$"

libraryDependencies += "net.databinder.dispatch" %% "dispatch-core" % "$dispatch$"
// Scripted smoke-test projects must declare a Scala version.
// Pin to a version compatible with the CI JDK (17+).
scalaVersion := "2.13.14"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = New Project
unfiltered = maven(net.databinder, unfiltered_2.11)
dispatch = maven(net.databinder.dispatch, dispatch-core_2.11)
unfiltered = 0.8.4
dispatch = 0.11.3
organization = com.example
package = $organization$.$name;format="norm,word"$
1 change: 0 additions & 1 deletion plugin/src/sbt-test/giter8/simple/test
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
> show scriptedDependencies
> g8Test
> writeInvalidFile
-> g8Test
7 changes: 2 additions & 5 deletions plugin/src/sbt-test/giter8/without-name/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
val javaVmArgs: List[String] = {
import scala.collection.JavaConverters._
java.lang.management.ManagementFactory.getRuntimeMXBean.getInputArguments.asScala.toList
}
enablePlugins(ScriptedPlugin)

scriptedLaunchOpts ++= javaVmArgs.filter(a => Seq("-Xmx", "-Xms", "-XX").exists(a.startsWith))
scalaVersion := "2.12.21"
2 changes: 2 additions & 0 deletions plugin/src/sbt-test/giter8/without-name/project/giter8.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
addSbtPlugin("org.foundweekends.giter8" % "sbt-giter8" % System.getProperty("plugin.version"))

libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name := "Example SBT project"

scalaVersion := "2.11.12"
// Scripted smoke-test projects must declare a Scala version.
// Pin to a version compatible with the CI JDK (17+).
scalaVersion := "2.13.14"
15 changes: 8 additions & 7 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ object Dependencies {
"org.scalatest" %% "scalatest-funsuite" % "3.2.19" % Test,
"org.scalatest" %% "scalatest-shouldmatchers" % "3.2.19" % Test
)
val scalamock = "org.scalamock" %% "scalamock" % "7.5.5"
val verify = "com.eed3si9n.verify" %% "verify" % "1.0.0"
val sbtIo = "org.scala-sbt" %% "io" % "1.10.5"
val scala212 = "2.12.21"
val scala213 = "2.13.18"
val scala3 = "3.7.4"
val sbt1 = "1.3.13"
val scalamock = "org.scalamock" %% "scalamock" % "7.5.5"
val verify = "com.eed3si9n.verify" %% "verify" % "1.0.0"
val sbtIo = "org.scala-sbt" %% "io" % "1.10.5"
val scala212 = "2.12.21"
val scala213 = "2.13.18"
val scala3 = "3.7.4"
// Scripted tests fork this sbt version; 1.3.x breaks on modern JDKs (Security Manager, classfile parser).
val sbt1 = "1.10.7"
val scalaXml = "org.scala-lang.modules" %% "scala-xml" % "2.1.0"
def parserCombinator(scalaVersion: String) = "org.scala-lang.modules" %% "scala-parser-combinators" % {
CrossVersion.partialVersion(scalaVersion) match {
Expand Down