Skip to content

Commit a624421

Browse files
committed
sbt 2
1 parent 5f8179b commit a624421

File tree

9 files changed

+113
-20
lines changed

9 files changed

+113
-20
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- uses: sbt/setup-sbt@v1
3131
- name: Build and test
3232
shell: bash
33-
run: sbt -v clean scalafmtCheckAll headerCheck test scripted
33+
run: sbt -v clean "+ scalafmtCheckAll" "+ headerCheckAll" "+ test" scripted
3434
- name: Build site
3535
if: ${{ matrix.java-version == 11 }}
3636
shell: bash

build.sbt

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,22 @@ lazy val jacocoPlugin = (project in file("."))
2626
scalacOptions ++= Seq(
2727
"-unchecked",
2828
"-deprecation",
29-
"-feature",
30-
"-Xfuture",
31-
"-Ywarn-adapted-args",
32-
"-Ywarn-dead-code"
29+
"-feature"
3330
)
3431

32+
scalacOptions ++= {
33+
scalaBinaryVersion.value match {
34+
case "2.12" =>
35+
Seq(
36+
"-Xfuture",
37+
"-Ywarn-adapted-args",
38+
"-Ywarn-dead-code"
39+
)
40+
case _ =>
41+
Nil
42+
}
43+
}
44+
3545
buildInfoPackage := "com.github.sbt.jacoco.build"
3646
buildInfoKeys := Seq[BuildInfoKey](
3747
Test / resourceDirectory,
@@ -85,3 +95,13 @@ ThisBuild / pomIncludeRepository := { _ =>
8595
ThisBuild / publishTo := (if (isSnapshot.value) None else localStaging.value)
8696
ThisBuild / publishMavenStyle := true
8797
ThisBuild / dynverSonatypeSnapshots := true
98+
99+
crossScalaVersions += "3.7.4"
100+
pluginCrossBuild / sbtVersion := {
101+
scalaBinaryVersion.value match {
102+
case "2.12" =>
103+
sbtVersion.value
104+
case _ =>
105+
"2.0.0-RC6"
106+
}
107+
}

src/main/scala/com/github/sbt/jacoco/JacocoItPlugin.scala renamed to src/main/scala-2/com/github/sbt/jacoco/JacocoItPlugin.scala

File renamed without changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* This file is part of sbt-jacoco.
3+
*
4+
* Copyright (c) Joachim Hofer & contributors
5+
* All rights reserved.
6+
*
7+
* This program and the accompanying materials
8+
* are made available under the terms of the Eclipse Public License v1.0
9+
* which accompanies this distribution, and is available at
10+
* http://www.eclipse.org/legal/epl-v10.html
11+
*/
12+
13+
package com.github.sbt.jacoco
14+
15+
import sbt.Def
16+
import sbt.Keys.Classpath
17+
18+
private[jacoco] object JacocoPluginCompat {
19+
def testFull = sbt.Keys.test
20+
21+
def convertClasspath(x: Classpath): Classpath =
22+
x
23+
24+
def fromClasspath(x: Classpath): Classpath =
25+
x
26+
27+
implicit class DefOps(private val self: Def.type) extends AnyVal {
28+
def uncached[A](a: A): A = a
29+
}
30+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* This file is part of sbt-jacoco.
3+
*
4+
* Copyright (c) Joachim Hofer & contributors
5+
* All rights reserved.
6+
*
7+
* This program and the accompanying materials
8+
* are made available under the terms of the Eclipse Public License v1.0
9+
* which accompanies this distribution, and is available at
10+
* http://www.eclipse.org/legal/epl-v10.html
11+
*/
12+
13+
package com.github.sbt.jacoco
14+
15+
import sbt.Keys.*
16+
import java.io.File
17+
import sbt.internal.util.Attributed
18+
19+
private[jacoco] object JacocoPluginCompat {
20+
def testFull = sbt.Keys.testFull
21+
22+
inline def convertClasspath(x: Seq[Attributed[File]]): Classpath = {
23+
val converter = fileConverter.value
24+
x.map(_.map(f => converter.toVirtualFile(f.toPath)))
25+
}
26+
27+
inline def fromClasspath(x: Classpath): Seq[Attributed[File]] = {
28+
val converter = fileConverter.value
29+
x.map(_.map(f => converter.toPath(f).toFile))
30+
}
31+
}

src/main/scala/com/github/sbt/jacoco/BaseJacocoPlugin.scala

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ package com.github.sbt.jacoco
1414

1515
import java.io.File
1616

17+
import com.github.sbt.jacoco.JacocoPluginCompat.*
1718
import com.github.sbt.jacoco.build.BuildInfo
1819
import com.github.sbt.jacoco.data.{ExecutionDataUtils, InstrumentationUtils, ProjectData}
1920
import com.github.sbt.jacoco.report.ReportUtils
@@ -78,7 +79,7 @@ private[jacoco] abstract class BaseJacocoPlugin extends AutoPlugin with JacocoKe
7879
ExecutionDataUtils
7980
.saveRuntimeData(projectData(thisProject.value), jacocoDataFile.value, fork.value, streams.value)
8081
)
81-
.dependsOn(test)
82+
.dependsOn(JacocoPluginCompat.testFull)
8283
.value,
8384
jacocoReport := ReportUtils.generateReport(
8485
jacocoReportDirectory.value,
@@ -99,19 +100,23 @@ private[jacoco] abstract class BaseJacocoPlugin extends AutoPlugin with JacocoKe
99100
streams.value
100101
),
101102
clean := jacocoDirectory.map(dir => if (dir.exists) IO delete dir.listFiles).value,
102-
fullClasspath := InstrumentationUtils.instrumentClasses(
103-
(Compile / products).value,
104-
filterClassesToInstrument(
105-
(Compile / products).value,
106-
(srcConfig / jacocoInstrumentationIncludes).value,
107-
(srcConfig / jacocoInstrumentationExcludes).value
108-
),
109-
(srcConfig / fullClasspath).value,
110-
jacocoInstrumentedDirectory.value,
111-
update.value,
112-
fork.value,
113-
projectData(thisProject.value),
114-
streams.value
103+
fullClasspath := Def.uncached(
104+
JacocoPluginCompat.convertClasspath(
105+
InstrumentationUtils.instrumentClasses(
106+
(Compile / products).value,
107+
filterClassesToInstrument(
108+
(Compile / products).value,
109+
(srcConfig / jacocoInstrumentationIncludes).value,
110+
(srcConfig / jacocoInstrumentationExcludes).value
111+
),
112+
JacocoPluginCompat.fromClasspath((srcConfig / fullClasspath).value),
113+
jacocoInstrumentedDirectory.value,
114+
update.value,
115+
fork.value,
116+
projectData(thisProject.value),
117+
streams.value
118+
)
119+
)
115120
),
116121
definedTests := (srcConfig / definedTests).value,
117122
definedTestNames := (srcConfig / definedTestNames).value

src/main/scala/com/github/sbt/jacoco/JacocoKeys.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,21 @@ import sbt.*
1919
object JacocoKeys extends JacocoKeys
2020

2121
trait JacocoKeys {
22+
@transient
2223
val jacoco: TaskKey[Unit] = taskKey[Unit]("Executes the tests and creates a JaCoCo coverage report.")
2324

25+
@transient
2426
val jacocoCheck: TaskKey[Unit] = taskKey[Unit]("Executes the tests and saves the execution data in 'jacoco.exec'.")
27+
@transient
2528
val jacocoReport: TaskKey[Unit] =
2629
taskKey[Unit]("Generates a JaCoCo report. You can use the 'jacoco report' command alternatively.")
2730

31+
@transient
2832
val jacocoAggregate: TaskKey[Unit] = taskKey[Unit](
2933
"Executes the tests and creates a JaCoCo coverage report as well as an aggregated report which merges all sub-projects."
3034
)
3135

36+
@transient
3237
val jacocoAggregateReport: TaskKey[Unit] = taskKey[Unit]("Generates an aggregated JaCoCo report.")
3338

3439
val jacocoDirectory: SettingKey[File] =

src/main/scala/com/github/sbt/jacoco/coveralls/JacocoCoverallsPlugin.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ object JacocoCoverallsPlugin extends BaseJacocoPlugin {
2626
override protected def srcConfig = Test
2727

2828
object autoImport {
29+
@transient
2930
val jacocoCoveralls: TaskKey[Unit] = taskKey("Generate and upload JaCoCo reports to Coveralls")
31+
@transient
3032
val jacocoCoverallsGenerateReport: TaskKey[Unit] = taskKey("Generate Coveralls report JSON")
3133

3234
val jacocoCoverallsServiceName: SettingKey[String] = settingKey("CI service name")

src/main/scala/com/github/sbt/jacoco/data/InstrumentationUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ object InstrumentationUtils {
2525
def instrumentClasses(
2626
products: Seq[File],
2727
classFiles: Seq[File],
28-
classpath: Classpath,
28+
classpath: Seq[Attributed[File]],
2929
destDirectory: File,
3030
updateReport: UpdateReport,
3131
forked: Boolean,

0 commit comments

Comments
 (0)