Skip to content

Commit 5f8ec25

Browse files
committed
Cross build to sbt 2.0.0-RC4
1 parent da54830 commit 5f8ec25

File tree

10 files changed

+136
-26
lines changed

10 files changed

+136
-26
lines changed

.github/workflows/scala.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ on:
99
jobs:
1010
build:
1111

12-
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
include:
16+
- os: ubuntu-latest
17+
jobtype: 1
18+
- os: ubuntu-latest
19+
jobtype: 2
20+
runs-on: ${{ matrix.os }}
1321

1422
steps:
1523
- uses: actions/checkout@v5
@@ -21,5 +29,11 @@ jobs:
2129
cache: sbt
2230
- name: Install sbt
2331
uses: sbt/setup-sbt@v1
24-
- name: Run tests
25-
run: sbt "^ scripted"
32+
- name: Build and test
33+
if: ${{ matrix.jobtype == 1 }}
34+
shell: bash
35+
run: sbt -v '++ 2.12.x' scripted
36+
- name: Scala 3
37+
if: ${{ matrix.jobtype == 2 }}
38+
shell: bash
39+
run: sbt -v '++ 3.x' scripted

build.sbt

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
* Copyright © 2016-2017 Lightbend, Inc. <http://www.lightbend.com>
33
*/
44

5-
// sbt cross build
6-
crossSbtVersions := Seq("1.11.4")
7-
85
// dependencies
96
val packagerVersion = "1.11.3"
107
val packager19xVersion = "1.9.16"
118

9+
val scala212 = "2.12.20"
10+
val scala3 = "3.7.2"
11+
1212
addSbtPlugin(
1313
"com.github.sbt" % "sbt-native-packager" % packagerVersion % "provided"
1414
)
@@ -42,6 +42,13 @@ lazy val `sbt-javaagent` = (project.in(file(".")))
4242
.settings(
4343
name := "sbt-javaagent",
4444
organization := "com.github.sbt",
45+
crossScalaVersions := Seq(scala212, scala3),
46+
scalacOptions ++= {
47+
scalaBinaryVersion.value match {
48+
case "2.12" => Seq("-Xsource:3")
49+
case _ => Nil
50+
}
51+
},
4552
scriptedBufferLog := false,
4653
scriptedLaunchOpts ++= Seq(
4754
"-Dproject.version=" + version.value,
@@ -51,6 +58,18 @@ lazy val `sbt-javaagent` = (project.in(file(".")))
5158
scriptedDependencies := {
5259
(maxwell / publishLocal).value
5360
publishLocal.value
61+
},
62+
(pluginCrossBuild / sbtVersion) := {
63+
scalaBinaryVersion.value match {
64+
case "2.12" => "1.11.6"
65+
case _ => "2.0.0-RC4"
66+
}
67+
},
68+
scriptedSbt := {
69+
scalaBinaryVersion.value match {
70+
case "2.12" => "1.11.6"
71+
case _ => (pluginCrossBuild / sbtVersion).value
72+
}
5473
}
5574
)
5675

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.lightbend.sbt.javaagent
2+
3+
import sbt.*
4+
import scala.language.implicitConversions
5+
6+
case class AgentScope(compile: Boolean = false, test: Boolean = false, run: Boolean = false, dist: Boolean = true)
7+
8+
case class AgentModule(name: String, module: ModuleID, scope: AgentScope, arguments: String)
9+
10+
case class ResolvedAgent(agent: AgentModule, artifact: File)
11+
12+
object AgentModule {
13+
implicit def moduleToAgentModule(module: ModuleID): AgentModule = JavaAgent(module)
14+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.lightbend.sbt.javaagent
2+
3+
import sbt.*
4+
import java.nio.file.{ Path => NioPath }
5+
import xsbti.FileConverter
6+
7+
private[javaagent] object PluginCompat {
8+
type FileRef = java.io.File
9+
type Out = java.io.File
10+
11+
def toNioPath(a: Attributed[File])(implicit conv: FileConverter): NioPath =
12+
a.data.toPath()
13+
def toFile(a: Attributed[File])(implicit conv: FileConverter): File =
14+
a.data
15+
def toNioPaths(cp: Seq[Attributed[File]])(implicit conv: FileConverter): Vector[NioPath] =
16+
cp.map(_.data.toPath()).toVector
17+
def toFiles(cp: Seq[Attributed[File]])(implicit conv: FileConverter): Vector[File] =
18+
cp.map(_.data).toVector
19+
def toFileRef(a: File)(implicit conv: FileConverter): File = a
20+
21+
// This adds `Def.uncached(...)`
22+
implicit class DefOp(singleton: Def.type) {
23+
def uncached[A1](a: A1): A1 = a
24+
}
25+
}

src/main/scala-3/AgentModule.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.lightbend.sbt.javaagent
2+
3+
import sbt.*
4+
import scala.language.implicitConversions
5+
6+
case class AgentScope(compile: Boolean = false, test: Boolean = false, run: Boolean = false, dist: Boolean = true)
7+
8+
case class AgentModule(name: String, module: ModuleID, scope: AgentScope, arguments: String)
9+
10+
case class ResolvedAgent(agent: AgentModule, artifact: File)
11+
12+
object AgentModule {
13+
given Conversion[ModuleID, AgentModule] with
14+
def apply(module: ModuleID): AgentModule = JavaAgent(module)
15+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.lightbend.sbt.javaagent
2+
3+
import java.nio.file.{ Path => NioPath }
4+
import sbt.*
5+
import xsbti.{ FileConverter, HashedVirtualFileRef, VirtualFile }
6+
7+
private[javaagent] object PluginCompat:
8+
type FileRef = HashedVirtualFileRef
9+
type Out = VirtualFile
10+
11+
def toNioPath(a: Attributed[HashedVirtualFileRef])(using conv: FileConverter): NioPath =
12+
conv.toPath(a.data)
13+
inline def toFile(a: Attributed[HashedVirtualFileRef])(using conv: FileConverter): File =
14+
toNioPath(a).toFile()
15+
def toNioPaths(cp: Seq[Attributed[HashedVirtualFileRef]])(using conv: FileConverter): Vector[NioPath] =
16+
cp.map(toNioPath).toVector
17+
inline def toFiles(cp: Seq[Attributed[HashedVirtualFileRef]])(using conv: FileConverter): Vector[File] =
18+
toNioPaths(cp).map(_.toFile())
19+
def toFileRef(a: File)(using conv: FileConverter): HashedVirtualFileRef =
20+
conv.toVirtualFile(a.toPath())
21+
end PluginCompat

src/main/scala/com/lightbend/sbt/javaagent/JavaAgent.scala

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
package com.lightbend.sbt.javaagent
66

7-
import sbt._
8-
import sbt.Keys._
7+
import sbt.*
8+
import sbt.Keys.*
9+
import xsbti.FileConverter
10+
import PluginCompat.{ *, given }
911

1012
/**
1113
* Plugin for adding Java agents to projects in a general way.
@@ -17,22 +19,13 @@ object JavaAgent extends JavaAgent {
1719

1820
object JavaAgentKeys {
1921
val javaAgents = settingKey[Seq[AgentModule]]("Java agent modules enabled for this project.")
22+
23+
@transient
2024
val resolvedJavaAgents = taskKey[Seq[ResolvedAgent]]("Java agent modules with resolved artifacts.")
2125
}
2226

2327
val AgentConfig = config("javaagent").hide
2428

25-
case class AgentScope(compile: Boolean = false, test: Boolean = false, run: Boolean = false, dist: Boolean = true)
26-
27-
case class AgentModule(name: String, module: ModuleID, scope: AgentScope, arguments: String)
28-
29-
case class ResolvedAgent(agent: AgentModule, artifact: File)
30-
31-
object AgentModule {
32-
import scala.language.implicitConversions
33-
implicit def moduleToAgentModule(module: ModuleID): AgentModule = JavaAgent(module)
34-
}
35-
3629
/**
3730
* Create an agent module from a module dependency.
3831
* Scope is also derived from the given module configuration.
@@ -69,7 +62,11 @@ class JavaAgent extends AutoPlugin {
6962
Test/fork := enableFork(Test/fork, _.scope.test).value,
7063
run/javaOptions ++= agentOptions(_.agent.scope.run).value,
7164
Test/javaOptions ++= agentOptions(_.agent.scope.test).value,
72-
Test/fullClasspath := filterAgents((Test/fullClasspath).value, resolvedJavaAgents.value)
65+
Test/fullClasspath := Def.uncached {
66+
val conv = fileConverter.value
67+
implicit val conv0: xsbti.FileConverter = conv
68+
filterAgents((Test/fullClasspath).value, resolvedJavaAgents.value)
69+
}
7370
)
7471

7572
private def resolveAgents = Def.task[Seq[ResolvedAgent]] {
@@ -102,8 +99,9 @@ class JavaAgent extends AutoPlugin {
10299
}
103100
}
104101

105-
def filterAgents(classpath: Classpath, resolvedAgents: Seq[ResolvedAgent]): Classpath = {
102+
def filterAgents(classpath: Classpath, resolvedAgents: Seq[ResolvedAgent])(implicit conv: FileConverter): Classpath = {
106103
val agents = resolvedAgents.map(resolved => resolved.artifact.absolutePath)
107-
classpath.filter(aFile => !agents.contains(aFile.data.getAbsolutePath))
104+
classpath
105+
.filter(entry => !agents.contains(PluginCompat.toFile(entry).getAbsolutePath))
108106
}
109107
}

src/main/scala/com/lightbend/sbt/javaagent/JavaAgentPackaging.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
package com.lightbend.sbt.javaagent
66

7-
import sbt._
8-
import sbt.Keys._
7+
import sbt.*
8+
import sbt.Keys.*
99
import com.typesafe.sbt.packager.universal.UniversalPlugin.autoImport.Universal
1010
import java.io.File
1111

@@ -24,7 +24,11 @@ object JavaAgentPackaging extends AutoPlugin {
2424
override def projectSettings = {
2525
import com.typesafe.sbt.packager.{ Keys => PackagerKeys }
2626
Seq(
27-
Universal / mappings ++= agentMappings.value.map(m => m._1 -> m._2),
27+
Universal / mappings ++= {
28+
val conv = fileConverter.value
29+
implicit val conv0: xsbti.FileConverter = conv
30+
agentMappings.value.map(m => PluginCompat.toFileRef(m._1) -> m._2)
31+
},
2832
PackagerKeys.bashScriptExtraDefines ++= agentBashScriptOptions.value,
2933
PackagerKeys.batScriptExtraDefines ++= agentBatScriptOptions.value
3034
)

src/sbt-test/agent/compile/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ lazy val agentCompile =
33

44
javaAgents += "sbt.javaagent.test" % "maxwell" % sys.props(
55
"project.version"
6-
) % "compile"
6+
) % Compile
File renamed without changes.

0 commit comments

Comments
 (0)