Skip to content

Commit

Permalink
Migrate to Scala 3
Browse files Browse the repository at this point in the history
  • Loading branch information
jjudd committed Jul 26, 2024
1 parent ae2658f commit 11f068b
Show file tree
Hide file tree
Showing 14 changed files with 1,177 additions and 154 deletions.
5 changes: 2 additions & 3 deletions play-routes-compiler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ scala_library(
tags = ["maven_coordinates=com.lucidchart:" + artifact_id + ":{pom_version}"],
visibility = ["//visibility:public"],
deps = [
"@play_routes_compiler_cli_maven//:com_github_scopt_scopt_2_13",
"@play_routes_compiler_cli_maven//:org_playframework_play_routes_compiler_2_13",
"@play_routes_compiler_cli_maven//:org_scala_lang_scala_reflect",
"@play_routes_compiler_cli_maven//:com_github_scopt_scopt_3",
"@play_routes_compiler_cli_maven//:org_playframework_play_routes_compiler_3",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import play.routes.compiler._
import play.routes.compiler.RoutesCompiler.RoutesCompilerTask
import scala.jdk.CollectionConverters._
import scala.io.Source
import scala.reflect.runtime.universe
import scala.Console._

object CommandLinePlayRoutesCompiler {
Expand Down Expand Up @@ -38,21 +37,16 @@ object CommandLinePlayRoutesCompiler {

opt[String]('g', "routesGenerator").valueName("<generator>").maxOccurs(1).action { (value, config) =>
config.copy(routesGenerator = {
val runtimeMirror = universe.runtimeMirror(getClass.getClassLoader)
val module = try {
runtimeMirror.staticModule(value)
} catch {
case e: Exception => {
throw new Exception("Could not find routes generator class.", e)
}
}

try {
val obj = runtimeMirror.reflectModule(module)
obj.instance.asInstanceOf[RoutesGenerator]
val name = if value.endsWith("$") then value else value + "$"
val clazz = java.lang.Class.forName(name, true, getClass.getClassLoader)
clazz.getField("MODULE$").get(null).asInstanceOf[RoutesGenerator]
} catch {
case e: Exception => {
throw new Exception(s"Could not cast ${value} as a RoutesGenerator", e)
throw new Exception(
s"Could not instantiate a routes generator from the given class: ${value}",
e,
)
}
}
})
Expand All @@ -79,12 +73,11 @@ object CommandLinePlayRoutesCompiler {
Files.write(Paths.get(path), sansHeader.asJava)
}

def main(args: Array[String]): Unit = {
val config = parser.parse(args, Config()).getOrElse {
return System.exit(1)
}

val didAllSucceed = config.sources.forall { file =>
/**
* Do Play Routes compilation and return true if things succeeded, otherwise return false.
*/
def doCompile(config: Config): Boolean = {
config.sources.forall { file =>
RoutesCompiler.compile(
RoutesCompilerTask(
file,
Expand All @@ -107,8 +100,14 @@ object CommandLinePlayRoutesCompiler {
false
}
}
}

def main(args: Array[String]): Unit = {
val isSuccess = parser.parse(args, Config())
.map(doCompile)
.getOrElse(false)

if (didAllSucceed) {
if (isSuccess) {
System.exit(0)
} else {
System.exit(1)
Expand Down
Loading

0 comments on commit 11f068b

Please sign in to comment.