Skip to content

Commit

Permalink
Update scrooge support to be compatible with Scala 3 (#1350)
Browse files Browse the repository at this point in the history
  • Loading branch information
liucijus authored Feb 10, 2022
1 parent 3b9c834 commit d8b0336
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Compiler(val config: ScroogeConfig) {
var fileMapWriter: scala.Option[FileWriter] = None


def run() {
def run(): Unit = {
// if --gen-file-map is specified, prepare the map file.
fileMapWriter = config.fileMapPath.map { path =>
val file = new File(path)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.bazel.rules_scala.scrooge_support

import com.twitter.scrooge.frontend.{ FileContents, Importer }
import com.twitter.scrooge.frontend.{FileContents, Importer}

import java.io.File
import java.util.zip.{ZipFile, ZipEntry}
import java.util.zip.{ZipEntry, ZipFile}
import scala.io.Source

object FocusedZipImporter {
Expand Down Expand Up @@ -31,10 +31,13 @@ case class FocusedZipImporter(focus: Option[File], zips: List[File], zipFiles: L
case "." :: tail => loop(leftPart, tail)
case child :: tail => loop(new File(leftPart, child), tail)
}

val parts = n.split("/", -1).toList
val newPath = loop(f, parts).getPath.replaceAllLiterally(File.separator, "/")
if (parts(0) == File.pathSeparatorChar) newPath.substring(1)
else newPath
val newPath = loop(f, parts).getPath.replace(File.separator, "/")
if (parts.head == File.separator)
newPath.substring(1)
else
newPath
}

private def resolve(filename: String): Option[(ZipEntry, ZipFile, FocusedZipImporter)] = {
Expand All @@ -51,6 +54,7 @@ case class FocusedZipImporter(focus: Option[File], zips: List[File], zipFiles: L
}

private val maxLastMod = zips.map(_.lastModified).reduceOption(_ max _)

// uses the lastModified time of the zip/jar file
def lastModified(filename: String): Option[Long] =
resolve(filename).flatMap(_ => maxLastMod)
Expand Down

0 comments on commit d8b0336

Please sign in to comment.