@@ -11,6 +11,7 @@ import scala.tools.nsc.plugins.PluginComponent
11
11
import scala .tools .nsc .transform .Transform
12
12
import scala .tools .nsc .transform .TypingTransformers
13
13
14
+ import buildinfo .BuildInfo
14
15
import scoverage .reporter .IOUtils
15
16
16
17
private [scoverage] object ScoverageCompiler {
@@ -24,9 +25,22 @@ private[scoverage] object ScoverageCompiler {
24
25
def classPath : Seq [String ] =
25
26
getScalaJars.map(
26
27
_.getAbsolutePath
27
- ) :+ sbtCompileDir.getAbsolutePath :+ runtimeClasses.getAbsolutePath
28
+ ) :+ sbtCompileDir.getAbsolutePath :+ runtimeClasses( " jvm " ) .getAbsolutePath
28
29
29
- def settings : Settings = {
30
+ def jsClassPath : Seq [String ] =
31
+ getScalaJsJars.map(
32
+ _.getAbsolutePath
33
+ ) :+ sbtCompileDir.getAbsolutePath :+ runtimeClasses(" js" ).getAbsolutePath
34
+
35
+ def settings : Settings = settings(classPath)
36
+
37
+ def jsSettings : Settings = {
38
+ val s = settings(jsClassPath)
39
+ s.plugin.value = List (getScalaJsCompilerJar.getAbsolutePath)
40
+ s
41
+ }
42
+
43
+ def settings (classPath : Seq [String ]): Settings = {
30
44
val s = new scala.tools.nsc.Settings
31
45
s.Xprint .value = List (" all" , " _" )
32
46
s.deprecation.value = true
@@ -46,6 +60,11 @@ private[scoverage] object ScoverageCompiler {
46
60
new ScoverageCompiler (settings, reporter)
47
61
}
48
62
63
+ def defaultJS : ScoverageCompiler = {
64
+ val reporter = new scala.tools.nsc.reporters.ConsoleReporter (jsSettings)
65
+ new ScoverageCompiler (jsSettings, reporter)
66
+ }
67
+
49
68
def locationCompiler : LocationCompiler = {
50
69
val reporter = new scala.tools.nsc.reporters.ConsoleReporter (settings)
51
70
new LocationCompiler (settings, reporter)
@@ -56,6 +75,19 @@ private[scoverage] object ScoverageCompiler {
56
75
scalaJars.map(findScalaJar)
57
76
}
58
77
78
+ private def getScalaJsJars : List [File ] =
79
+ findJar(
80
+ " org.scala-js" ,
81
+ s " scalajs-library_ $ShortScalaVersion" ,
82
+ BuildInfo .scalaJSVersion
83
+ ) :: getScalaJars
84
+
85
+ private def getScalaJsCompilerJar : File = findJar(
86
+ " org.scala-js" ,
87
+ s " scalajs-compiler_ $ScalaVersion" ,
88
+ BuildInfo .scalaJSVersion
89
+ )
90
+
59
91
private def sbtCompileDir : File = {
60
92
val dir = new File (
61
93
s " ./plugin/target/scala- $ScalaVersion/classes "
@@ -67,20 +99,28 @@ private[scoverage] object ScoverageCompiler {
67
99
dir
68
100
}
69
101
70
- private def runtimeClasses : File = new File (
71
- s " ./runtime/jvm /target/scala- $ScalaVersion/classes "
102
+ private def runtimeClasses ( platform : String ) : File = new File (
103
+ s " ./runtime/ $platform /target/scala- $ScalaVersion/classes "
72
104
)
73
105
74
106
private def findScalaJar (artifactId : String ): File =
75
- findIvyJar(" org.scala-lang" , artifactId, ScalaVersion )
76
- .orElse(findCoursierJar(artifactId, ScalaVersion ))
107
+ findJar(" org.scala-lang" , artifactId, ScalaVersion )
108
+
109
+ private def findJar (
110
+ groupId : String ,
111
+ artifactId : String ,
112
+ version : String
113
+ ): File =
114
+ findIvyJar(groupId, artifactId, version)
115
+ .orElse(findCoursierJar(groupId, artifactId, version))
77
116
.getOrElse {
78
117
throw new FileNotFoundException (
79
- s " Could not locate $artifactId/ $ScalaVersion "
118
+ s " Could not locate $groupId : $ artifactId: $version "
80
119
)
81
120
}
82
121
83
122
private def findCoursierJar (
123
+ groupId : String ,
84
124
artifactId : String ,
85
125
version : String
86
126
): Option [File ] = {
@@ -89,9 +129,10 @@ private[scoverage] object ScoverageCompiler {
89
129
" .cache/coursier" , // Linux
90
130
" Library/Caches/Coursier" , // MacOSX
91
131
" AppData/Local/Coursier/cache" // Windows
92
- ).map(loc =>
93
- s " $userHome/ $loc/v1/https/repo1.maven.org/maven2/org/scala-lang/ $artifactId/ $version/ $artifactId- $version.jar "
94
- )
132
+ ).map { loc =>
133
+ val gid = groupId.replace('.' , '/' )
134
+ s " $userHome/ $loc/v1/https/repo1.maven.org/maven2/ $gid/ $artifactId/ $version/ $artifactId- $version.jar "
135
+ }
95
136
jarPaths.map(new File (_)).find(_.exists())
96
137
}
97
138
0 commit comments