@@ -4,20 +4,20 @@ import java.io.{File, FileNotFoundException}
44import java .net .URL
55
66import scala .collection .mutable .ListBuffer
7- import scala .tools .nsc .{Settings , Global }
7+ import scala .tools .nsc .{Global , Settings }
88import scala .tools .nsc .plugins .PluginComponent
99import scala .tools .nsc .transform .{Transform , TypingTransformers }
1010
11- /** @author Stephen Samuel */
1211object ScoverageCompiler {
1312
14- val ScalaVersion = scala.util.Properties .versionNumberString
15- val ShortScalaVersion = (ScalaVersion split " [.]" ).toList match {
13+ val ScalaVersion : String = scala.util.Properties .versionNumberString
14+ val ShortScalaVersion : String = (ScalaVersion split " [.]" ).toList match {
1615 case init :+ last if last forall (_.isDigit) => init mkString " ."
17- case _ => ScalaVersion
16+ case _ => ScalaVersion
1817 }
1918
20- def classPath = getScalaJars.map(_.getAbsolutePath) :+ sbtCompileDir.getAbsolutePath :+ runtimeClasses.getAbsolutePath
19+ def classPath : Seq [String ] =
20+ getScalaJars.map(_.getAbsolutePath) :+ sbtCompileDir.getAbsolutePath :+ runtimeClasses.getAbsolutePath
2121
2222 def settings : Settings = {
2323 val s = new scala.tools.nsc.Settings
@@ -57,15 +57,25 @@ object ScoverageCompiler {
5757
5858 private def runtimeClasses : File = new File (s " ./scalac-scoverage-runtime/jvm/target/scala- $ShortScalaVersion/classes " )
5959
60- private def findScalaJar (artifactId : String ): File = findIvyJar(" org.scala-lang" , artifactId, ScalaVersion )
60+ private def findScalaJar (artifactId : String ): File =
61+ findIvyJar(" org.scala-lang" , artifactId, ScalaVersion )
62+ .orElse(findCoursierJar(artifactId, ScalaVersion ))
63+ .getOrElse {
64+ throw new FileNotFoundException (s " Could not locate $artifactId/ $ScalaVersion" )
65+ }
66+
67+ private def findCoursierJar (artifactId : String , version : String ): Option [File ] = {
68+ val userHome = System .getProperty(" user.home" )
69+ val jarPath = s " $userHome/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/ $artifactId/ $version/ $artifactId- $version.jar "
70+ val file = new File (jarPath)
71+ if (file.exists()) Some (file) else None
72+ }
6173
62- private def findIvyJar (groupId : String , artifactId : String , version : String , packaging : String = " jar" ): File = {
74+ private def findIvyJar (groupId : String , artifactId : String , version : String , packaging : String = " jar" ): Option [ File ] = {
6375 val userHome = System .getProperty(" user.home" )
6476 val jarPath = s " $userHome/.ivy2/cache/ $groupId/ $artifactId/ ${packaging}s/ $artifactId- $version.jar "
6577 val file = new File (jarPath)
66- if (! file.exists)
67- throw new FileNotFoundException (s " Could not locate [ $jarPath]. " )
68- file
78+ if (file.exists()) Some (file) else None
6979 }
7080}
7181
0 commit comments