@@ -12,7 +12,7 @@ import java.math.BigInteger
1212import java .security .MessageDigest
1313import java .util .jar .JarFile
1414
15- import cats .effect .{ Concurrent , ConcurrentEffect , Timer }
15+ import cats .effect ._
1616import cats .implicits ._
1717import coursier ._
1818import coursier .cache .{ArtifactError , FileCache }
@@ -22,12 +22,12 @@ import org.scalaexercises.evaluator.{Dependency => EvaluatorDependency}
2222
2323import scala .concurrent .duration ._
2424import scala .language .reflectiveCalls
25- import scala .reflect .internal .util .{AbstractFileClassLoader , BatchSourceFile , Position }
2625import scala .reflect .internal .util .ScalaClassLoader .URLClassLoader
26+ import scala .reflect .internal .util .{AbstractFileClassLoader , BatchSourceFile , Position }
2727import scala .tools .nsc .io .{AbstractFile , VirtualDirectory }
2828import scala .tools .nsc .reporters ._
2929import scala .tools .nsc .{Global , Settings }
30- import scala .util .{ Failure , Success , Try }
30+ import scala .util .Try
3131import scala .util .control .NonFatal
3232
3333class Evaluator [F [_]: Sync ](timeout : FiniteDuration = 20 .seconds)(
@@ -462,35 +462,35 @@ class ${className} extends (() => Any) with java.io.Serializable {
462462 val classPath = getClassPath(this .getClass.getClassLoader)
463463 val currentClassPath = classPath.head
464464
465+ def checkCurrentClassPath : List [String ] = currentClassPath match {
466+ case List (jarFile) if jarFile.endsWith(" .jar" ) =>
467+ val relativeRoot = new File (jarFile).getParentFile
468+ val jarResource : Resource [IO , JarFile ] =
469+ Resource .make(IO (new JarFile (jarFile)))(jar => IO (jar.close()))
470+
471+ val nestedClassPath : IO [String ] =
472+ jarResource
473+ .use(jar => IO (jar.getManifest.getMainAttributes.getValue(" Class-Path" )))
474+ .handleError { throwable : Throwable =>
475+ throw new CompilerException (List (List (throwable.getMessage)))
476+ }
477+
478+ nestedClassPath.map {
479+ case ncp if ncp eq null => Nil
480+ case ncp =>
481+ ncp
482+ .split(" " )
483+ .map { f =>
484+ new File (relativeRoot, f).getAbsolutePath
485+ }
486+ .toList
487+
488+ }.unsafeRunSync
489+ case _ => Nil
490+ }
491+
465492 // if there's just one thing in the classpath, and it's a jar, assume an executable jar.
466- currentClassPath ::: (if (currentClassPath.size == 1 && currentClassPath.head
467- .endsWith(" .jar" )) {
468- val jarFile = currentClassPath.head
469- val relativeRoot =
470- new File (jarFile).getParentFile
471- val nestedClassPath = Try {
472- val jar = new JarFile (jarFile)
473- val CP = jar.getManifest.getMainAttributes.getValue(" Class-Path" )
474- jar.close()
475- CP
476- } match {
477- case Success (classPath) => classPath
478- case Failure (throwable) =>
479- throw new CompilerException (List (List (throwable.getMessage)))
480- }
481- if (nestedClassPath eq null ) {
482- Nil
483- } else {
484- nestedClassPath
485- .split(" " )
486- .map { f =>
487- new File (relativeRoot, f).getAbsolutePath
488- }
489- .toList
490- }
491- } else {
492- Nil
493- }) ::: classPath.tail.flatten
493+ currentClassPath ::: checkCurrentClassPath ::: classPath.tail.flatten
494494 }
495495
496496 lazy val compilerOutputDir = target match {
0 commit comments