Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Scala to 2.13.12 #278

Merged
merged 9 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions polyglot-scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<name>Polyglot :: Scala</name>

<properties>
<scala.version>2.12.18</scala.version>
<scala.bin.version>2.12</scala.bin.version>
<scala.version>2.13.12</scala.version>
<scala.bin.version>2.13</scala.bin.version>
</properties>

<contributors>
Expand All @@ -45,19 +45,19 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-core_${scala.bin.version}</artifactId>
<version>6.43.0</version>
<version>22.3.0</version>
</dependency>

<dependency>
<groupId>org.scala-lang.modules</groupId>
<artifactId>scala-xml_${scala.bin.version}</artifactId>
<version>1.0.6</version>
<version>2.2.0</version>
</dependency>

<dependency>
<groupId>com.googlecode.kiama</groupId>
<groupId>org.bitbucket.inkytonik.kiama</groupId>
<artifactId>kiama_${scala.bin.version}</artifactId>
<version>1.8.0</version>
<version>2.5.1</version>
</dependency>

<dependency>
Expand All @@ -81,7 +81,7 @@
<dependency>
<groupId>org.specs2</groupId>
<artifactId>specs2-junit_${scala.bin.version}</artifactId>
<version>3.9.5</version>
<version>4.20.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Model(
name = "Test for Java + Scala compilation",
description = "Test for Java + Scala compilation",
dependencies = Seq(
"org.scala-lang" % "scala-library" % "2.12.18"
"org.scala-lang" % "scala-library" % "2.13.12"
),
build = Build(
pluginManagement = PluginManagement(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ class ScalaModelReader @Inject() (executeManager: ExecuteManager) extends ModelR
}

private def registerExecutors(m: Model, options: util.Map[String, _], tasks: immutable.Seq[Task]): Unit = {
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
executeManager.register(m, tasks.map(new ScalaTask(_).asInstanceOf[ExecuteTask]).asJava)
executeManager.install(m, options)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package org.sonatype.maven.polyglot.scala
import java.io.Writer
import java.util
import org.sonatype.maven.polyglot.io.ModelWriterSupport
import org.kiama.output.PrettyPrinter
import org.bitbucket.inkytonik.kiama.output.PrettyPrinter
import org.apache.maven.model.{ Activation => MavenActivation, ActivationFile => MavenActivationFile, ActivationOS => MavenActivationOS, ActivationProperty => MavenActivationProperty, Build => MavenBuild, BuildBase => MavenBuildBase, CiManagement => MavenCiManagement, Contributor => MavenContributor, DependencyManagement => MavenDependencyManagement, Dependency => MavenDependency, DeploymentRepository => MavenDeploymentRepository, Developer => MavenDeveloper, DistributionManagement => MavenDistributionManagement, PluginExecution => MavenExecution, Extension => MavenExtension, IssueManagement => MavenIssueManagement, License => MavenLicense, MailingList => MavenMailingList, Model => MavenModel, Notifier => MavenNotifier, Organization => MavenOrganization, Parent => MavenParent, Plugin => MavenPlugin, PluginManagement => MavenPluginManagement, Prerequisites => MavenPrerequisites, Profile => MavenProfile, Relocation => MavenRelocation, RepositoryPolicy => MavenRepositoryPolicy, Repository => MavenRepository, Resource => MavenResource, Scm => MavenScm, Site => MavenSite, Reporting => MavenReporting, ReportPlugin => MavenReportPlugin, ReportSet => MavenReportSet }
import org.sonatype.maven.polyglot.scala.model._
import scala.collection.immutable
Expand Down Expand Up @@ -42,7 +42,7 @@ object ScalaPrettyPrinter extends PrettyPrinter {
}

def mapStrings(m: Map[String, String]): Doc = {
"Map" <> lparen <> nest(lsep(m.map(me => dquotes(me._1) <+> "->" <+> dquotes(me._2)).to[immutable.Seq], comma)) <@> rparen
"Map" <> lparen <> nest(lsep(m.map(me => dquotes(me._1) <+> "->" <+> dquotes(me._2)).toSeq, comma)) <@> rparen
}

def seqString(s: immutable.Seq[String]): Doc = "Seq" <> lparen <> nest(lsep(s.map(dquotes(_)), comma)) <@> rparen
Expand Down Expand Up @@ -324,11 +324,11 @@ class ScalaModelWriter extends ModelWriterSupport {

val d = "import" <+> "org.sonatype.maven.polyglot.scala.model._" <@>
"import" <+> "scala.collection.immutable.Seq" <@>
empty <@>
emptyDoc <@>
mm.asScala.asDoc <@>
empty
emptyDoc
val pp = ScalaPrettyPrinter.pretty(d)
writer.append(pp)
writer.append(pp.layout)
writer.flush()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package org.sonatype.maven.polyglot.scala.eval

import com.twitter.conversions.string._
import com.twitter.conversions.StringOps._
import com.twitter.io.StreamIO

import java.io._
Expand All @@ -28,19 +28,25 @@ import java.util.concurrent.atomic.AtomicInteger
import java.util.jar.JarFile
import scala.collection.mutable
import scala.io.Source
import scala.reflect.internal.util.{AbstractFileClassLoader, BatchSourceFile, Position}
import scala.reflect.internal.util.{AbstractFileClassLoader, BatchSourceFile, CodeAction, Position}
import scala.reflect.io.{AbstractFile, VirtualDirectory}
import scala.tools.nsc.reporters.{FilteringReporter, Reporter}
import scala.tools.nsc.{Global, Settings}
import scala.util.Using
import scala.util.matching.Regex

object Eval {
private val jvmId = java.lang.Math.abs(new Random().nextInt())
val classCleaner: Regex = "\\W".r
private val classCleaner: Regex = "\\W".r

class CompilerException(val messages: List[List[String]]) extends Exception(
"Compiler exception " + messages.map(_.mkString("\n")).mkString("\n"))

trait MessageCollector {
val messages: mutable.Seq[List[String]]
val counts: Map[_root_.scala.reflect.internal.Reporter.Severity, AtomicInteger]
}

}

/**
Expand Down Expand Up @@ -121,7 +127,7 @@ class Eval(target: Option[File]) {
/**
* write the current checksum to a file
*/
def writeChecksum(checksum: String, file: File) {
def writeChecksum(checksum: String, file: File): Unit = {
val writer = new FileWriter(file)
writer.write("%s".format(checksum))
writer.close()
Expand All @@ -141,12 +147,12 @@ class Eval(target: Option[File]) {
def apply[T](files: File*): T = {
if (target.isDefined) {
val targetDir = target.get
val unprocessedSource = files.map { scala.io.Source.fromFile(_).mkString }.mkString("\n")
val unprocessedSource = files.map { f => Using.resource(Source.fromFile(f))(_.mkString) }.mkString("\n")
val processed = sourceForString(unprocessedSource)
val sourceChecksum = uniqueId(processed, None)
val checksumFile = new File(targetDir, "checksum")
val lastChecksum = if (checksumFile.exists) {
Source.fromFile(checksumFile).getLines().take(1).toList.head
Using.resource(Source.fromFile(checksumFile))(_.getLines().take(1).toList.head)
} else {
-1
}
Expand All @@ -164,9 +170,9 @@ class Eval(target: Option[File]) {
val cleanBaseName = fileToClassName(files(0))
val className = "Evaluator__%s_%s".format(
cleanBaseName, sourceChecksum)
applyProcessed(className, processed, false)
applyProcessed(className, processed, resetState = false)
} else {
apply(files.map { scala.io.Source.fromFile(_).mkString }.mkString("\n"), true)
apply(files.map {f => Using.resource(Source.fromFile(f))(_.mkString) }.mkString("\n"), true)
}
}

Expand Down Expand Up @@ -202,7 +208,7 @@ class Eval(target: Option[File]) {
* delegates to toSource(code: String)
*/
def toSource(file: File): String = {
toSource(scala.io.Source.fromFile(file).mkString)
toSource(Using.resource(Source.fromFile(file))(_.mkString))
}

/**
Expand All @@ -215,23 +221,23 @@ class Eval(target: Option[File]) {
/**
* Compile an entire source file into the virtual classloader.
*/
def compile(code: String) {
def compile(code: String): Unit = {
compiler(sourceForString(code))
}

/**
* Like `Eval()`, but doesn't reset the virtual classloader before evaluating. So if you've
* loaded classes with `compile`, they can be referenced/imported in code run by `inPlace`.
*/
def inPlace[T](code: String) = {
apply[T](code, false)
def inPlace[T](code: String): T = {
apply[T](code, resetState = false)
}

/**
* Check if code is Eval-able.
* @throws CompilerException if not Eval-able.
*/
def check(code: String) {
def check(code: String): Unit = {
val id = uniqueId(sourceForString(code))
val className = "Evaluator__" + id
val wrappedCode = wrapCodeInClass(className, code)
Expand All @@ -243,16 +249,16 @@ class Eval(target: Option[File]) {
* Check if files are Eval-able.
* @throws CompilerException if not Eval-able.
*/
def check(files: File*) {
val code = files.map { scala.io.Source.fromFile(_).mkString }.mkString("\n")
def check(files: File*): Unit = {
val code = files.map { f => Using.resource(Source.fromFile(f))(_.mkString) }.mkString("\n")
check(code)
}

/**
* Check if stream is Eval-able.
* @throws CompilerException if not Eval-able.
*/
def check(stream: InputStream) {
def check(stream: InputStream): Unit = {
check(scala.io.Source.fromInputStream(stream).mkString)
}

Expand All @@ -268,7 +274,7 @@ class Eval(target: Option[File]) {
val digest = MessageDigest.getInstance("SHA-1").digest(code.getBytes())
val sha = new BigInteger(1, digest).toString(16)
idOpt match {
case Some(id) => sha + "_" + jvmId
case Some(_) => sha + "_" + jvmId
case _ => sha
}
}
Expand Down Expand Up @@ -348,8 +354,8 @@ class Eval(target: Option[File]) {
val currentClassPath = classPath.head

// if there's just one thing in the classpath, and it's a jar, assume an executable jar.
currentClassPath ::: (if (currentClassPath.size == 1 && currentClassPath(0).endsWith(".jar")) {
val jarFile = currentClassPath(0)
currentClassPath ::: (if (currentClassPath.size == 1 && currentClassPath.head.endsWith(".jar")) {
val jarFile = currentClassPath.head
val relativeRoot = new File(jarFile).getParentFile()
val nestedClassPath = new JarFile(jarFile).getManifest.getMainAttributes.getValue("Class-Path")
if (nestedClassPath eq null) {
Expand Down Expand Up @@ -414,7 +420,7 @@ class Eval(target: Option[File]) {
apply(code, maximumRecursionDepth)

def apply(code: String, maxDepth: Int): String = {
val lines = code.lines map { line: String =>
val lines = code.linesIterator map { line: String =>
val tokens = line.trim.split(' ')
if (tokens.length == 2 && tokens(0).equals("#include")) {
val path = tokens(1)
Expand All @@ -440,7 +446,7 @@ class Eval(target: Option[File]) {
}
}

lazy val compilerOutputDir = target match {
lazy val compilerOutputDir: AbstractFile = target match {
case Some(dir) => AbstractFile.getDirectory(dir)
case None => new VirtualDirectory("(memory)", None)
}
Expand All @@ -463,11 +469,6 @@ class Eval(target: Option[File]) {
val cache = new mutable.HashMap[String, Class[_]]()
val target = compilerOutputDir

trait MessageCollector {
val messages: Seq[List[String]]
val counts: Map[_root_.scala.reflect.internal.Reporter.Severity, AtomicInteger]
}

val reporter = messageHandler getOrElse new FilteringReporter with MessageCollector {
val settings = StringCompiler.this.settings
val messages = new mutable.ListBuffer[List[String]]
Expand All @@ -480,7 +481,7 @@ class Eval(target: Option[File]) {

override def hasErrors: Boolean = super.hasErrors || (counts(ERROR).get() > 0)

override def doReport(pos: Position, msg: String, severity: Severity): Unit = {
override def doReport(pos: Position, msg: String, severity: Severity, actions: List[CodeAction]): Unit = {
counts(severity).intValue()
val severityName = severity match {
case ERROR => "error: "
Expand All @@ -504,8 +505,8 @@ class Eval(target: Option[File]) {
})
}

override def reset {
super.reset
override def reset(): Unit = {
super.reset()
messages.clear()
counts.foreach(p => p._2.set(0))
}
Expand All @@ -519,7 +520,7 @@ class Eval(target: Option[File]) {
*/
private var classLoader = new AbstractFileClassLoader(target, this.getClass.getClassLoader)

def reset() {
def reset(): Unit = {
targetDir match {
case None => {
target.asInstanceOf[VirtualDirectory].clear()
Expand All @@ -544,14 +545,14 @@ class Eval(target: Option[File]) {
}

object Debug {
val enabled =
val enabled: Boolean =
System.getProperty("eval.debug") != null

def printWithLineNumbers(code: String) {
def printWithLineNumbers(code: String): Unit = {
printf("Code follows (%d bytes)\n", code.length)

var numLines = 0
code.lines foreach { line: String =>
code.linesIterator foreach { line: String =>
numLines += 1
println(numLines.toString.padTo(5, ' ') + "| " + line)
}
Expand All @@ -575,7 +576,7 @@ class Eval(target: Option[File]) {
/**
* Compile scala code. It can be found using the above class loader.
*/
def apply(code: String) {
def apply(code: String): Unit = {
if (Debug.enabled)
Debug.printWithLineNumbers(code)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class PrettiedBuild(b: Build) {


import org.sonatype.maven.polyglot.scala.MavenConverters._
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
import org.apache.maven.model.{Build => MavenBuild}

class ConvertibleMavenBuild(mb: MavenBuild) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class PrettiedBuildBase(b: BuildBase) {


import org.sonatype.maven.polyglot.scala.MavenConverters._
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
import org.apache.maven.model.{BuildBase => MavenBuildBase}

class ConvertibleMavenBuildBase(mb: MavenBuildBase) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PrettiedCiManagement(c: CiManagement) {


import org.sonatype.maven.polyglot.scala.MavenConverters._
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
import org.apache.maven.model.{CiManagement => MavenCiManagement}

class ConvertibleMavenCiManagement(mcm: MavenCiManagement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ object Config extends Dynamic {
def sanitizeElementName(k: String): String = {
val r = elementStartCharMapping.foldLeft(k)((k, m) => m._1.replaceAllIn(k, found => m._2))
if (r.length() > 1) {
r(0) + elementCharMapping.foldLeft(r.substring(1))((k, m) => m._1.replaceAllIn(k, found => m._2))
r.substring(0, 1) + elementCharMapping.foldLeft(r.substring(1))((k, m) => m._1.replaceAllIn(k, found => m._2))
} else r
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class PrettiedContributor(c: Contributor) {
}


import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
import org.apache.maven.model.{Contributor => MavenContributor}

class ConvertibleMavenContributor(mc: MavenContributor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ class PrettiedDependency(d: Dependency) {
`object`("Dependency", args.toList)
} else {
val gav = d.gav.asDoc
val version = if (d.gav.version.isEmpty) space <> percent <+> dquote <> dquote else empty
gav <> version <> d.scope.map(empty <+> percent <+> dquotes(_)).getOrElse(empty)
val version = if (d.gav.version.isEmpty) space <> percent <+> dquote <> dquote else emptyDoc
gav <> version <> d.scope.map(emptyDoc <+> percent <+> dquotes(_)).getOrElse(emptyDoc)
}
}
}


import org.sonatype.maven.polyglot.scala.MavenConverters._
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
import org.apache.maven.model.{Dependency => MavenDependency, Exclusion => MavenExclusion}

class ConvertibleMavenDependency(md: MavenDependency) {
Expand Down
Loading