Skip to content

Commit fb38b19

Browse files
respencer-nclclaude
andcommitted
Fix scripted tests and pass AKKA_REPO_TOKEN to test JVMs
- Make Git and DynamicVersioning helpers detect git repos before enabling native git. This allows scripted tests to run in non-git directories (temp dirs) while still supporting git worktrees in real development environments. - Pass AKKA_REPO_TOKEN to scripted test JVMs via scriptedLaunchOpts system property, and check both sys.props and sys.env in Akka helper. - Update scripted test build.sbt files to use modern PascalCase With.* syntax (BuildInfo, Scala3, Riddl) instead of deprecated lowercase versions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 501d70e commit fb38b19

8 files changed

Lines changed: 66 additions & 12 deletions

File tree

build.sbt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ lazy val `sbt-ossuminc` = project
3131
scalaVersion := "2.12.19",
3232
// Scripted == sbt plugin tests
3333
scriptedLaunchOpts := {
34-
scriptedLaunchOpts.value ++ Seq("-Xmx1024M", "-Dplugin.version=" + version.value)
34+
scriptedLaunchOpts.value ++
35+
Seq("-Xmx1024M", "-Dplugin.version=" + version.value) ++
36+
sys.env.get("AKKA_REPO_TOKEN").map(t => s"-Dakka.repo.token=$t").toSeq
3537
},
3638
libraryDependencies ++= Seq(
3739
"org.apache.commons" % "commons-lang3" % "3.20.0",

src/main/scala/com/ossuminc/sbt/helpers/Akka.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ object Akka extends AutoPluginHelper {
2323

2424
/** Akka repository URL with embedded token. Akka uses tokenized URLs for authentication - the
2525
* token is part of the URL path. See https://doc.akka.io/libraries/akka-dependencies/current/
26+
*
27+
* The token is read from (in order of precedence):
28+
* 1. `akka.repo.token` system property (used by scripted tests)
29+
* 2. `AKKA_REPO_TOKEN` environment variable (normal usage)
2630
*/
2731
private def akkaRepoUrl: String = {
28-
sys.env.get("AKKA_REPO_TOKEN") match {
32+
sys.props.get("akka.repo.token").orElse(sys.env.get("AKKA_REPO_TOKEN")) match {
2933
case Some(token) => s"https://repo.akka.io/$token/secure"
3034
case None =>
3135
System.err.println(

src/main/scala/com/ossuminc/sbt/helpers/DynamicVersioning.scala

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,23 @@ import sbt.*
55
import sbtdynver.DynVerPlugin
66
import sbtdynver.DynVerPlugin.autoImport.{dynverSeparator, dynverVTagPrefix}
77

8+
import java.io.File
9+
810
object DynamicVersioning extends AutoPluginHelper {
911

12+
/** Check if we're in a git repository by looking for .git directory or file */
13+
private def isGitRepo: Boolean = {
14+
def checkDir(dir: File): Boolean = {
15+
if (dir == null) false
16+
else {
17+
val gitDir = new File(dir, ".git")
18+
if (gitDir.exists()) true
19+
else checkDir(dir.getParentFile)
20+
}
21+
}
22+
checkDir(new File(System.getProperty("user.dir")))
23+
}
24+
1025
/** The configuration function to call for this plugin helper
1126
*
1227
* @param project
@@ -15,8 +30,8 @@ object DynamicVersioning extends AutoPluginHelper {
1530
* @return
1631
* The same project passed as an argument, post configuration
1732
*/
18-
def apply(project: Project): Project =
19-
project
33+
def apply(project: Project): Project = {
34+
val baseProject = project
2035
.enablePlugins(DynVerPlugin)
2136
.settings(
2237
// NEVER SET THIS:
@@ -27,12 +42,22 @@ object DynamicVersioning extends AutoPluginHelper {
2742
ThisBuild / dynverVTagPrefix := false,
2843

2944
// use the minus character to separate version fields
30-
ThisBuild / dynverSeparator := "-",
45+
ThisBuild / dynverSeparator := "-"
46+
)
3147

48+
// Only use native git if we're actually in a git repository.
49+
// This allows scripted tests to run in non-git directories while
50+
// still supporting git worktrees in actual development environments.
51+
if (isGitRepo) {
52+
baseProject.settings(
3253
// Use native git instead of JGit to support git worktrees.
3354
// JGit doesn't properly handle worktrees (sees .git file as bare repo).
3455
// Native git fully supports worktrees and is required for parallel
3556
// development with multiple Claude workers in separate worktrees.
3657
useReadableConsoleGit
3758
)
59+
} else {
60+
baseProject
61+
}
62+
}
3863
}

src/main/scala/com/ossuminc/sbt/helpers/Git.scala

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,40 @@ import com.github.sbt.git.GitPlugin
44
import com.github.sbt.git.SbtGit.useReadableConsoleGit
55
import sbt._
66

7+
import java.io.File
8+
79
object Git extends AutoPluginHelper {
810

11+
/** Check if we're in a git repository by looking for .git directory or file */
12+
private def isGitRepo: Boolean = {
13+
def checkDir(dir: File): Boolean = {
14+
if (dir == null) false
15+
else {
16+
val gitDir = new File(dir, ".git")
17+
if (gitDir.exists()) true
18+
else checkDir(dir.getParentFile)
19+
}
20+
}
21+
checkDir(new File(System.getProperty("user.dir")))
22+
}
23+
924
def apply(project: Project): Project = {
10-
project
11-
.enablePlugins(GitPlugin)
12-
.settings(
25+
val baseSettings = project.enablePlugins(GitPlugin)
26+
27+
// Only use native git if we're actually in a git repository.
28+
// This allows scripted tests to run in non-git directories while
29+
// still supporting git worktrees in actual development environments.
30+
if (isGitRepo) {
31+
baseSettings.settings(
1332
// Use native git instead of JGit to support git worktrees.
1433
// JGit doesn't properly handle worktrees (sees .git file as bare repo).
1534
// Native git fully supports worktrees and is required for parallel
1635
// development with multiple Claude workers in separate worktrees.
1736
useReadableConsoleGit
1837
)
38+
} else {
39+
// Fall back to JGit for non-git directories (e.g., scripted tests)
40+
baseSettings
41+
}
1942
}
2043
}

src/sbt-test/sbt-ossuminc/basic/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import java.nio.file.{Files,Path}
66
enablePlugins(OssumIncPlugin)
77

88
lazy val root = Root("basic-test", startYr=2015)
9-
.configure(With.basic, With.build_info)
9+
.configure(With.basic, With.BuildInfo)
1010
.settings(
1111
maxErrors := 50,
1212
TaskKey[Unit]("check") := {

src/sbt-test/sbt-ossuminc/everything/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ lazy val root = Root(
1515
)
1616
)
1717
.configure(With.typical)
18-
.configure(With.riddl)
18+
.configure(With.Riddl)
1919
.settings(
2020
name := "program-test",
2121
maxErrors := 50,

src/sbt-test/sbt-ossuminc/native/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ lazy val root = Root("hello", startYr = 2024)
2121
)
2222

2323
lazy val hello = Program("hello", "hello", Some("test.hello"))
24-
.configure(With.basic, With.build_info, With.scala3, With.Native(buildTarget = "application"))
24+
.configure(With.basic, With.BuildInfo, With.Scala3, With.Native(buildTarget = "application"))
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
enablePlugins(OssumIncPlugin)
22

33
lazy val root = Root("basic-test", startYr = 2015)
4-
.configure(With.basic, With.build_info)
4+
.configure(With.basic, With.BuildInfo)
55
.settings(
66
maxErrors := 50
77
)

0 commit comments

Comments
 (0)