scala.meta.internal.metac.Main.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of metac_2.13.12 Show documentation
Show all versions of metac_2.13.12 Show documentation
Scalac 2.x launcher that generates SemanticDB on compile
The newest version!
package scala.meta.internal.metac
import scala.meta.cli._
import scala.meta.internal.semanticdb.scalac._
import scala.meta.metac._
import java.io._
import java.net._
import java.nio.channels._
import java.nio.file._
import scala.tools.nsc.{Main => ScalacMain}
class Main(settings: Settings, reporter: Reporter) {
def process(): Boolean = {
val manifestDir = Files.createTempDirectory("semanticdb-scalac_")
val resourceUrl = classOf[SemanticdbPlugin].getResource("/scalac-plugin.xml")
val resourceChannel = Channels.newChannel(resourceUrl.openStream())
val manifestStream = new FileOutputStream(manifestDir.resolve("scalac-plugin.xml").toFile)
manifestStream.getChannel.transferFrom(resourceChannel, 0, Long.MaxValue)
manifestStream.close()
val pluginClasspath = classOf[SemanticdbPlugin].getClassLoader match {
case null => manifestDir.toString
case cl: URLClassLoader => cl.getURLs.map(_.getFile).mkString(File.pathSeparator)
case cl => sys.error(s"unsupported classloader: $cl")
}
val enablePluginArgs = List("-Xplugin:" + pluginClasspath, "-Xplugin-require:semanticdb")
val enableRangeposArgs = List("-Yrangepos")
val stopAfterPluginArgs = List("-Ystop-after:semanticdb-typer")
val args = settings.scalacArgs ++ enablePluginArgs ++ enableRangeposArgs ++ stopAfterPluginArgs
scala.Console.withOut(reporter.out) {
scala.Console.withErr(reporter.err)(ScalacMain.process(args.toArray))
}
!ScalacMain.reporter.hasErrors
}
}