Skip to content

Commit 5c38942

Browse files
authored
Merge pull request #182 from gslowikowski/scala212-simplified-proposal
Scala 2.12.0-RC1 support.
2 parents cff95bd + 6d849ee commit 5c38942

File tree

6 files changed

+83
-39
lines changed

6 files changed

+83
-39
lines changed

.travis.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ language: scala
33
script:
44
- sbt ++$TRAVIS_SCALA_VERSION test
55

6-
jdk:
7-
- oraclejdk7
8-
9-
scala:
10-
- 2.10.6
11-
- 2.11.8
6+
matrix:
7+
include:
8+
- jdk: oraclejdk7
9+
scala: 2.10.6
10+
- jdk: oraclejdk7
11+
scala: 2.11.8
12+
- jdk: oraclejdk8
13+
scala: 2.12.0-RC1
1214

1315
before_cache:
1416
- find "$HOME/.sbt/" -name '*.lock' -print0 | xargs -0 rm

build.sbt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ val ScalatestVersion = "3.0.0"
1313
val appSettings = Seq(
1414
organization := Org,
1515
scalaVersion := "2.11.8",
16-
crossScalaVersions := Seq("2.10.6", "2.11.8"),
16+
crossScalaVersions := Seq("2.10.6", "2.11.8", "2.12.0-RC1"),
1717
fork in Test := false,
1818
publishMavenStyle := true,
1919
publishArtifact in Test := false,
@@ -90,13 +90,15 @@ lazy val plugin = Project("scalac-scoverage-plugin", file("scalac-scoverage-plug
9090
"org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided",
9191
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided",
9292
"org.joda" % "joda-convert" % "1.6" % "test",
93-
"joda-time" % "joda-time" % "2.3" % "test",
94-
"com.typesafe.scala-logging" %% "scala-logging-slf4j" % "2.1.2" % "test"
93+
"joda-time" % "joda-time" % "2.3" % "test"
9594
)).settings(libraryDependencies ++= {
9695
CrossVersion.partialVersion(scalaVersion.value) match {
97-
case Some((2, scalaMajor)) if scalaMajor == 11 =>
98-
Seq("org.scala-lang.modules" %% "scala-xml" % "1.0.4")
99-
case _ =>
100-
Nil
96+
case Some((2, scalaMajor)) if scalaMajor > 10 => Seq(
97+
"org.scala-lang.modules" %% "scala-xml" % "1.0.5",
98+
"com.typesafe.scala-logging" %% "scala-logging" % "3.5.0" % "test"
99+
)
100+
case _ => Seq(
101+
"com.typesafe.scala-logging" %% "scala-logging-slf4j" % "2.1.2" % "test"
102+
)
101103
}
102104
})

scalac-scoverage-plugin/src/test/scala/scoverage/PluginASTSupportTest.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ class PluginASTSupportTest
88
extends FunSuite
99
with MockitoSugar
1010
with OneInstancePerTest
11-
with BeforeAndAfterEachTestData {
11+
with BeforeAndAfterEachTestData
12+
with ScalaLoggingSupport {
1213

1314
override protected def afterEach(testData: TestData): Unit = {
1415
val compiler = ScoverageCompiler.default
@@ -62,7 +63,7 @@ class PluginASTSupportTest
6263
assert(!compiler.reporter.hasErrors)
6364
}
6465

65-
// https://github.com/scoverage/scalac-scoverage-plugin/issues/32
66+
// https://github.com/scoverage/scalac-scoverage-plugin/issues/32
6667
test("exhaustive warnings should not be generated for @unchecked") {
6768
val compiler = ScoverageCompiler.default
6869
compiler.compileCodeSnippet( """object PartialMatchObject {
@@ -79,10 +80,8 @@ class PluginASTSupportTest
7980
// https://github.com/skinny-framework/skinny-framework/issues/97
8081
test("macro range positions should not break plugin") {
8182
val compiler = ScoverageCompiler.default
82-
compiler.addToClassPath("org.slf4j", "slf4j-api", "1.7.7")
83-
compiler.addToClassPath("com.typesafe.scala-logging", "scala-logging-api_" + ScoverageCompiler.ShortScalaVersion, "2.1.2")
84-
compiler.addToClassPath("com.typesafe.scala-logging", "scala-logging-slf4j_" + ScoverageCompiler.ShortScalaVersion, "2.1.2")
85-
compiler.compileCodeSnippet( """import com.typesafe.scalalogging.slf4j.StrictLogging
83+
scalaLoggingDeps.foreach(compiler.addToClassPath(_))
84+
compiler.compileCodeSnippet( s"""import ${scalaLoggingPackageName}.StrictLogging
8685
|
8786
|object MacroTest extends StrictLogging {
8887
| println("Hello")

scalac-scoverage-plugin/src/test/scala/scoverage/PluginCoverageTest.scala

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ class PluginCoverageTest
88
extends FunSuite
99
with MockitoSugar
1010
with OneInstancePerTest
11-
with BeforeAndAfterEachTestData {
11+
with BeforeAndAfterEachTestData
12+
with ScalaLoggingSupport {
1213

1314
test("scoverage should instrument default arguments with methods") {
1415
val compiler = ScoverageCompiler.default
@@ -287,16 +288,8 @@ class PluginCoverageTest
287288

288289
test("plugin should not instrument expanded macro code github.com/skinny-framework/skinny-framework/issues/97") {
289290
val compiler = ScoverageCompiler.default
290-
compiler.addToClassPath("org.slf4j", "slf4j-api", "1.7.7")
291-
compiler
292-
.addToClassPath("com.typesafe.scala-logging",
293-
"scala-logging-api_" + ScoverageCompiler.ShortScalaVersion,
294-
"2.1.2")
295-
compiler
296-
.addToClassPath("com.typesafe.scala-logging",
297-
"scala-logging-slf4j_" + ScoverageCompiler.ShortScalaVersion,
298-
"2.1.2")
299-
compiler.compileCodeSnippet( """import com.typesafe.scalalogging.slf4j.StrictLogging
291+
scalaLoggingDeps.foreach(compiler.addToClassPath(_))
292+
compiler.compileCodeSnippet( s"""import ${scalaLoggingPackageName}.StrictLogging
300293
|class MacroTest extends StrictLogging {
301294
| logger.info("will break")
302295
|} """.stripMargin)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package scoverage
2+
3+
import java.io.{File, FileNotFoundException}
4+
import java.net.URL
5+
6+
import scala.collection.mutable.ListBuffer
7+
import scala.tools.nsc.{Settings, Global}
8+
import scala.tools.nsc.plugins.PluginComponent
9+
import scala.tools.nsc.transform.{Transform, TypingTransformers}
10+
11+
trait ScalaLoggingSupport {
12+
13+
val scalaLoggingPackageName: String = if (ScoverageCompiler.ShortScalaVersion == "2.10") {
14+
"com.typesafe.scalalogging.slf4j"
15+
}
16+
else {
17+
"com.typesafe.scalalogging"
18+
}
19+
20+
lazy val scalaLoggingDeps: Seq[File] = {
21+
if (ScoverageCompiler.ShortScalaVersion == "2.10") {
22+
Seq(
23+
findIvyJar("org.slf4j", "slf4j-api", "1.7.7"),
24+
findCrossedIvyJar("com.typesafe.scala-logging", "scala-logging-api", "2.1.2"),
25+
findCrossedIvyJar("com.typesafe.scala-logging", "scala-logging-slf4j", "2.1.2")
26+
)
27+
}
28+
else {
29+
Seq(
30+
findIvyJar("org.slf4j", "slf4j-api", "1.7.21"),
31+
findCrossedIvyJar("com.typesafe.scala-logging", "scala-logging", "3.5.0", "bundle")
32+
)
33+
}
34+
}
35+
36+
private def findCrossedIvyJar(groupId: String, artifactId: String, version: String, packaging: String = "jar"): File =
37+
findIvyJar(groupId, artifactId + "_" + ScoverageCompiler.ShortScalaVersion, version, packaging)
38+
39+
private def findIvyJar(groupId: String, artifactId: String, version: String, packaging: String = "jar"): File = {
40+
val userHome = System.getProperty("user.home")
41+
val jarPath = s"$userHome/.ivy2/cache/$groupId/$artifactId/${packaging}s/${artifactId}-${version}.jar"
42+
val file = new File(jarPath)
43+
if (!file.exists)
44+
throw new FileNotFoundException(s"Could not locate [$jarPath].")
45+
file
46+
}
47+
48+
}

scalac-scoverage-plugin/src/test/scala/scoverage/ScoverageCompiler.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import scala.tools.nsc.transform.{Transform, TypingTransformers}
1212
object ScoverageCompiler {
1313

1414
val ScalaVersion = scala.util.Properties.versionNumberString
15-
val ShortScalaVersion = ScalaVersion.dropRight(2)
15+
val ShortScalaVersion = (ScalaVersion split "[.]").toList match {
16+
case init :+ last if last forall (_.isDigit) => init mkString "."
17+
case _ => ScalaVersion
18+
}
1619

1720
def classPath = getScalaJars.map(_.getAbsolutePath) :+ sbtCompileDir.getAbsolutePath :+ runtimeClasses.getAbsolutePath
1821

@@ -55,10 +58,9 @@ object ScoverageCompiler {
5558

5659
private def findScalaJar(artifactId: String): File = findIvyJar("org.scala-lang", artifactId, ScalaVersion)
5760

58-
private def findIvyJar(groupId: String, artifactId: String, version: String): File = {
61+
private def findIvyJar(groupId: String, artifactId: String, version: String, packaging: String = "jar"): File = {
5962
val userHome = System.getProperty("user.home")
60-
val sbtHome = userHome + "/.ivy2"
61-
val jarPath = sbtHome + "/cache/" + groupId + "/" + artifactId + "/jars/" + artifactId + "-" + version + ".jar"
63+
val jarPath = s"$userHome/.ivy2/cache/$groupId/$artifactId/${packaging}s/${artifactId}-${version}.jar"
6264
val file = new File(jarPath)
6365
if (!file.exists)
6466
throw new FileNotFoundException(s"Could not locate [$jarPath].")
@@ -69,10 +71,8 @@ object ScoverageCompiler {
6971
class ScoverageCompiler(settings: scala.tools.nsc.Settings, reporter: scala.tools.nsc.reporters.Reporter)
7072
extends scala.tools.nsc.Global(settings, reporter) {
7173

72-
def addToClassPath(groupId: String, artifactId: String, version: String): Unit = {
73-
settings.classpath.value = settings.classpath.value + File.pathSeparator + ScoverageCompiler
74-
.findIvyJar(groupId, artifactId, version)
75-
.getAbsolutePath
74+
def addToClassPath(file: File): Unit = {
75+
settings.classpath.value = settings.classpath.value + File.pathSeparator + file.getAbsolutePath
7676
}
7777

7878
val instrumentationComponent = new ScoverageInstrumentationComponent(this, None, None)
@@ -130,7 +130,7 @@ class ScoverageCompiler(settings: scala.tools.nsc.Settings, reporter: scala.tool
130130
val sources = new ListBuffer[String]
131131

132132
override val phaseName = "scoverage-teststore"
133-
override val runsAfter = List("dce")
133+
override val runsAfter = List("jvm")
134134
override val runsBefore = List("terminal")
135135

136136
override protected def newTransformer(unit: global.CompilationUnit): global.Transformer = new Transformer(unit)

0 commit comments

Comments
 (0)