Skip to content

Commit

Permalink
Add support for Scala 2.13 to core
Browse files Browse the repository at this point in the history
  • Loading branch information
mdedetrich committed Nov 3, 2023
1 parent 5212ff2 commit 4b6dd78
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
16 changes: 14 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
val buildName = "jardiff"

val scala212Version = "2.12.18"
val scala213Version = "2.13.12"

inThisBuild(Seq[Setting[_]](
organization := "com.lightbend",
scalaVersion := "2.13.12",
Expand Down Expand Up @@ -51,7 +54,9 @@ lazy val root = (
publish / skip := true,
publishArtifact := false,
publish := {},
publishLocal := {}
publishLocal := {},
// See https://github.com/sbt/sbt/issues/4262#issuecomment-405607763
crossScalaVersions := Seq.empty
)
)

Expand All @@ -69,7 +74,9 @@ lazy val core = project.
"ch.qos.logback" % "logback-classic" % "1.3.11",
"org.scalatest" %% "scalatest" % "3.2.17" % Test,
),
name := buildName + "-core"
name := buildName + "-core",
crossScalaVersions := Seq(scala212Version, scala213Version),
scalaVersion := scala212Version
)

lazy val cli = project.
Expand All @@ -83,6 +90,11 @@ lazy val cli = project.
case x if x.endsWith("module-info.class") => MergeStrategy.discard
case x => (assembly / assemblyMergeStrategy).value(x)
},
// Having Scala 2.13 here in crossScalaVersions is redundant but due to how
// sbt-github-actions generates the sbt test command (i.e. sbt '++ 2.13.12' test),
// sbt's update task cannot handle projects with different crossScalaVersions well
crossScalaVersions := Seq(scala212Version, scala213Version),
scalaVersion := scala212Version,
// cli is not meant to be published
publish / skip := true,
publishArtifact := false,
Expand Down
3 changes: 2 additions & 1 deletion cli/src/main/scala/scala/tools/jardiff/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

package scala.tools.jardiff

import JDKCollectionConvertersCompat.Converters._

import java.io.{ByteArrayOutputStream, File, PrintWriter}
import java.nio.file._

import org.apache.commons.cli
import org.apache.commons.cli.{CommandLine, DefaultParser, HelpFormatter, Options}
import org.eclipse.jgit.util.io.NullOutputStream

import scala.jdk.CollectionConverters._
import scala.util.Try
import scala.util.control.NonFatal

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

package scala.tools.jardiff

import JDKCollectionConvertersCompat.Converters._

import java.io.PrintWriter
import java.nio.file.{Files, Path}

import scala.jdk.CollectionConverters._
import org.objectweb.asm.{ClassReader, Opcodes}
import org.objectweb.asm.tree.{ClassNode, FieldNode, InnerClassNode, MethodNode}
import org.objectweb.asm.util.TraceClassVisitor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package scala.tools.jardiff

import scala.annotation.nowarn

/** Magic to get cross-compiling access to `scala.jdk.CollectionConverters`
* with a fallback on `scala.collection.JavaConverters`, without deprecation
* warning in any Scala version.
*
* @see https://github.com/scala/scala-collection-compat/issues/208
*/
@nowarn("msg=Unused import")
private[jardiff] object JDKCollectionConvertersCompat {
object Scope1 {
object jdk {
type CollectionConverters = Int
}
}
import Scope1._

object Scope2 {
import scala.collection.{JavaConverters => CollectionConverters}

object Inner {
import scala._
import jdk.CollectionConverters
val Converters = CollectionConverters
}
}

val Converters = Scope2.Inner.Converters
}
3 changes: 2 additions & 1 deletion core/src/main/scala/scala/tools/jardiff/JarDiff.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package scala.tools.jardiff

import JDKCollectionConvertersCompat.Converters._

import java.io.{File, OutputStream}
import java.nio.file._
import java.nio.file.attribute.BasicFileAttributes
Expand All @@ -14,7 +16,6 @@ import org.eclipse.jgit.lib.RepositoryCache
import org.eclipse.jgit.revwalk.RevCommit

import scala.tools.jardiff.JGitUtil._
import scala.jdk.CollectionConverters._

final class JarDiff(files: List[List[Path]], config: JarDiff.Config, renderers: String => List[FileRenderer]) {
private val targetBase = config.gitRepo.getOrElse(Files.createTempDirectory("jardiff-"))
Expand Down

0 comments on commit 4b6dd78

Please sign in to comment.