Merge pull request #8443 from xuwei-k/deprecated-scala-App

This commit is contained in:
eugene yokota 2026-01-09 08:15:11 -05:00 committed by GitHub
commit 7320b7176a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
42 changed files with 270 additions and 181 deletions

View File

@ -1,5 +1,7 @@
package foo
object Hello extends App {
println("hello")
object Hello {
def main(args: Array[String]): Unit = {
println("hello")
}
}

View File

@ -1,3 +1,5 @@
object Hello extends App {
println("hello" + args.toList.toString)
object Hello {
def main(args: Array[String]): Unit = {
println("hello" + args.toList.toString)
}
}

View File

@ -1,10 +1,13 @@
object Main extends App {
object Main {
class Foo
new Thread {
override def run(): Unit = {
Thread.sleep(500)
try new Foo
catch { case t: Throwable => sys.exit(1) }
}
}.start()
}
def main(args: Array[String]): Unit = {
new Thread {
override def run(): Unit = {
Thread.sleep(500)
try new Foo
catch { case t: Throwable => sys.exit(1) }
}
}.start()
}
}

View File

@ -1,6 +1,8 @@
package foo
object Foo extends App {
println("yay")
object Foo {
def main(args: Array[String]): Unit = {
println("yay")
}
}

View File

@ -1,6 +1,8 @@
import java.io.File
import java.nio.file.Files
object Main extends App {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
object Main {
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
}
}

View File

@ -3,7 +3,7 @@ import java.nio.file.Files
import scala.util.Try
object Main extends App {
object Main {
def classFound(clsName: String) = Try(
Thread.currentThread()
@ -12,7 +12,10 @@ object Main extends App {
).toOption.nonEmpty
val name = "org.jclouds.openstack.nova.functions.ParseServerFromJsonResponseTest"
val classifierTest = classFound(name)
assert(classifierTest, s"Couldn't find $name")
def main(args: Array[String]): Unit = {
val classifierTest = classFound(name)
assert(classifierTest, s"Couldn't find $name")
}
}

View File

@ -3,7 +3,7 @@ import java.nio.file.Files
import scala.util.Try
object Main extends App {
object Main {
def classFound(clsName: String) = Try(
Thread.currentThread()
@ -11,22 +11,24 @@ object Main extends App {
.loadClass(clsName)
).toOption.nonEmpty
val shapelessFound = classFound("shapeless.HList")
val argonautFound = classFound("argonaut.Json")
val argonautShapelessFound = classFound("argonaut.derive.MkEncodeJson")
def main(args: Array[String]): Unit = {
val shapelessFound = classFound("shapeless.HList")
val argonautFound = classFound("argonaut.Json")
val argonautShapelessFound = classFound("argonaut.derive.MkEncodeJson")
assert(
argonautShapelessFound,
"Expected to find class from argonaut-shapeless"
)
assert(
!shapelessFound,
"Expected not to find classes from shapeless"
)
assert(
!argonautFound,
"Expected not to find classes from argonaut"
)
assert(
argonautShapelessFound,
"Expected to find class from argonaut-shapeless"
)
assert(
!shapelessFound,
"Expected not to find classes from shapeless"
)
assert(
!argonautFound,
"Expected not to find classes from argonaut"
)
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
}
}

View File

@ -3,6 +3,8 @@ import java.nio.file.Files
import org.apache.zookeeper.ZooKeeper
object Main extends App {
Files.write(new File("output").toPath, classOf[ZooKeeper].getSimpleName.getBytes("UTF-8"))
object Main {
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, classOf[ZooKeeper].getSimpleName.getBytes("UTF-8"))
}
}

View File

@ -3,11 +3,13 @@ import java.nio.file.Files
import argonaut._, Argonaut._, ArgonautShapeless._
object Main extends App {
object Main {
case class CC(i: Int, s: String)
val msg = CC(2, A.msg).asJson.spaces2
def main(args: Array[String]): Unit = {
val msg = CC(2, A.msg).asJson.spaces2
Files.write(new File("output").toPath, msg.getBytes("UTF-8"))
Files.write(new File("output").toPath, msg.getBytes("UTF-8"))
}
}

View File

@ -1,19 +1,21 @@
import java.io.File
import java.nio.file.Files
object Main extends App {
val p = new java.util.Properties
p.load(
Thread.currentThread()
.getContextClassLoader
.getResource("common-version-info.properties")
.openStream()
)
object Main {
def main(args: Array[String]): Unit = {
val p = new java.util.Properties
p.load(
Thread.currentThread()
.getContextClassLoader
.getResource("common-version-info.properties")
.openStream()
)
val hadoopVersion = p.getProperty("version")
Console.err.println(s"Found hadoop version $hadoopVersion")
val hadoopVersion = p.getProperty("version")
Console.err.println(s"Found hadoop version $hadoopVersion")
assert(hadoopVersion == "2.6.0")
assert(hadoopVersion == "2.6.0")
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
}
}

View File

@ -9,8 +9,10 @@ package scala.collection.immutable {
}
object A extends App {
println(scala.util.Properties.versionString)
object A {
def main(args: Array[String]): Unit = {
println(scala.util.Properties.versionString)
}
}
object AMacro {

View File

@ -1,7 +1,9 @@
import java.nio.file.{Paths, Files}
import java.nio.charset.StandardCharsets
object B extends App {
println(AMacro.m(33)) // fails
Files.write(Paths.get(s"s${scala.util.Properties.versionNumberString}.txt"), "nix".getBytes)
object B {
def main(args: Array[String]): Unit = {
println(AMacro.m(33)) // fails
Files.write(Paths.get(s"s${scala.util.Properties.versionNumberString}.txt"), "nix".getBytes)
}
}

View File

@ -1,7 +1,9 @@
import java.nio.file.{Paths, Files}
import java.nio.charset.StandardCharsets
object C extends App {
assert(scala.collection.immutable.Exp.v == null)
Files.write(Paths.get(s"s${scala.util.Properties.versionNumberString}.txt"), "nix".getBytes)
object C {
def main(args: Array[String]): Unit = {
assert(scala.collection.immutable.Exp.v == null)
Files.write(Paths.get(s"s${scala.util.Properties.versionNumberString}.txt"), "nix".getBytes)
}
}

View File

@ -1,7 +1,9 @@
import scala.language.reflectiveCalls
object A extends App {
println(scala.util.Properties.versionString)
object A {
def main(args: Array[String]): Unit = {
println(scala.util.Properties.versionString)
}
}
object AMacro {

View File

@ -1,7 +1,9 @@
import java.nio.file.{Paths, Files}
import java.nio.charset.StandardCharsets
object B extends App {
println(AMacro.m(33))
Files.write(Paths.get(s"s${scala.util.Properties.versionNumberString}.txt"), "nix".getBytes)
object B {
def main(args: Array[String]): Unit = {
println(AMacro.m(33))
Files.write(Paths.get(s"s${scala.util.Properties.versionNumberString}.txt"), "nix".getBytes)
}
}

View File

@ -1,11 +1,13 @@
import java.io.File
import java.nio.file.Files
object Main extends App {
object Main {
// Not using directly the NetLogo 5.x lib, which seems to depend on Scala 2.9
// Can't find a way to check that NetLogo.jar is in the classpath
// These don't work, even with fork := true:
// assert(Thread.currentThread.getContextClassLoader.getResource("org/nlogo/nvm/Task.class") != null)
// Thread.currentThread.getContextClassLoader.getResource("org/nlogo/nvm/Task.class")
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
}
}

View File

@ -3,14 +3,16 @@ package pkg
import java.nio.file.{ Paths, Files }
import java.nio.charset.Charset
object A extends App {
val out = Paths.get("out.txt")
val content = sys.props("java.version")
val w = Files.newBufferedWriter(out, Charset.forName("UTF-8"))
try {
w.write(content)
w.flush()
} finally {
w.close
object A {
def main(args: Array[String]): Unit = {
val out = Paths.get("out.txt")
val content = sys.props("java.version")
val w = Files.newBufferedWriter(out, Charset.forName("UTF-8"))
try {
w.write(content)
w.flush()
} finally {
w.close
}
}
}

View File

@ -3,7 +3,7 @@ import java.nio.file.Files
import scala.util.Try
object Main extends App {
object Main {
def classFound(clsName: String) = Try(
Thread.currentThread()
@ -12,7 +12,10 @@ object Main extends App {
).toOption.nonEmpty
val name = "org.jclouds.openstack.nova.functions.ParseServerFromJsonResponseTest"
val classifierTest = classFound(name)
assert(classifierTest, s"Couldn't find $name")
def main(args: Array[String]): Unit = {
val classifierTest = classFound(name)
assert(classifierTest, s"Couldn't find $name")
}
}

View File

@ -1,6 +1,8 @@
import ch.qos.logback.classic.BasicConfigurator
import ch.qos.logback.classic.LoggerContext
object GcMetricsApp extends App {
BasicConfigurator.configure(new LoggerContext())
object GcMetricsApp {
def main(args: Array[String]): Unit = {
BasicConfigurator.configure(new LoggerContext())
}
}

View File

@ -1 +1,3 @@
object Main extends App
object Main {
def main(args: Array[String]): Unit = ()
}

View File

@ -1 +1,3 @@
object Main extends App
object Main {
def main(args: Array[String]): Unit = ()
}

View File

@ -1 +1,3 @@
object Main extends App
object Main {
def main(args: Array[String]): Unit = ()
}

View File

@ -1 +1,3 @@
object Main extends App
object Main {
def main(args: Array[String]): Unit = ()
}

View File

@ -1,11 +1,13 @@
import java.io.File
import java.nio.file.Files
object Main extends App {
object Main {
// Not using directly the NetLogo 5.x lib, which seems to depend on Scala 2.9
// Can't find a way to check that NetLogo.jar is in the classpath
// These don't work, even with fork := true:
// assert(Thread.currentThread.getContextClassLoader.getResource("org/nlogo/nvm/Task.class") != null)
// Thread.currentThread.getContextClassLoader.getResource("org/nlogo/nvm/Task.class")
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
}
}

View File

@ -3,11 +3,14 @@ import java.nio.file.Files
import shapeless._
object Main extends App {
object Main {
case class CC(s: String)
val cc = CC("OK")
val l = Generic[CC].to(cc)
val msg = l.head
Files.write(new File("output").toPath, msg.getBytes("UTF-8"))
def main(args: Array[String]): Unit = {
val cc = CC("OK")
val l = Generic[CC].to(cc)
val msg = l.head
Files.write(new File("output").toPath, msg.getBytes("UTF-8"))
}
}

View File

@ -3,11 +3,14 @@ import java.nio.file.Files
import shapeless._
object Main extends App {
object Main {
case class CC(s: String)
val cc = CC("OK")
val l = Generic[CC].to(cc)
val msg = l.head
Files.write(new File("output").toPath, msg.getBytes("UTF-8"))
def main(args: Array[String]): Unit = {
val cc = CC("OK")
val l = Generic[CC].to(cc)
val msg = l.head
Files.write(new File("output").toPath, msg.getBytes("UTF-8"))
}
}

View File

@ -1,9 +1,11 @@
import java.io.File
import java.nio.file.Files
object Main extends App {
object Main {
// TODO Use some jvm-repr stuff as a test
Files.write(new File("output").toPath, A.default.msg.getBytes("UTF-8"))
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, A.default.msg.getBytes("UTF-8"))
}
}

View File

@ -8,6 +8,8 @@ import java.nio.file.Files
* @author A
* @param may not be `'''null'''`!!!
*/
object Main extends App {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
object Main {
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
}
}

View File

@ -1,9 +1,11 @@
import java.io.File
import java.nio.file.Files
object Main extends App {
object Main {
// TODO Use some jvm-repr stuff
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
}
}

View File

@ -1,6 +1,8 @@
import java.io.File
import java.nio.file.Files
object Main extends App {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
object Main {
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
}
}

View File

@ -1,6 +1,8 @@
import java.io.File
import java.nio.file.Files
object Main extends App {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
object Main {
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
}
}

View File

@ -3,64 +3,66 @@ import java.nio.file.Files
import scala.collection.JavaConverters._
object Main extends App {
object Main {
val cp = new collection.mutable.ArrayBuffer[File]
def main(args: Array[String]): Unit = {
val cp = new collection.mutable.ArrayBuffer[File]
def buildCp(loader: ClassLoader): Unit =
if (loader != null) {
loader match {
case u: java.net.URLClassLoader =>
cp ++= u.getURLs
.map(_.toURI)
.map(new File(_))
case _ =>
def buildCp(loader: ClassLoader): Unit =
if (loader != null) {
loader match {
case u: java.net.URLClassLoader =>
cp ++= u.getURLs
.map(_.toURI)
.map(new File(_))
case _ =>
}
buildCp(loader.getParent)
}
buildCp(loader.getParent)
buildCp(Thread.currentThread().getContextClassLoader)
System.err.println("Classpath:")
for (f <- cp)
System.err.println(s" $f")
System.err.println()
val sbtBase = new File(sys.props.getOrElse(
"sbt.global.base",
sys.props("user.home") + "/.sbt"
))
val prefixes = Seq(new File(sbtBase, "boot").getAbsolutePath) ++
Seq("coursier.sbt-launcher.dirs.scala-jars", "coursier.sbt-launcher.dirs.base", "user.dir")
.flatMap(sys.props.get(_))
.map(new File(_).getAbsolutePath)
val home = new File(sys.props("user.home")).getAbsolutePath
def notFromCoursierCache(name: String): Unit = {
val jars = cp.filter(_.getName.startsWith(name)).distinct
assert(jars.nonEmpty, s"Found no JARs for $name")
for (jar <- jars)
assert(
!jar.getAbsolutePath.startsWith(home) ||
!jar.getAbsolutePath.toLowerCase(java.util.Locale.ROOT).contains("coursier") ||
prefixes.exists(jar.getAbsolutePath.startsWith),
s"JAR for $name ($jar) under $home and not under any of ${prefixes.mkString(", ")}"
)
}
buildCp(Thread.currentThread().getContextClassLoader)
val props = Thread.currentThread()
.getContextClassLoader
.getResources("library.properties")
.asScala
.toVector
.map(_.toString)
.sorted
.distinct // TODO should not need distinct
System.err.println("Classpath:")
for (f <- cp)
System.err.println(s" $f")
System.err.println()
notFromCoursierCache("scala-library")
assert(props.lengthCompare(1) == 0, s"Found several library.properties files in classpath: $props")
val sbtBase = new File(sys.props.getOrElse(
"sbt.global.base",
sys.props("user.home") + "/.sbt"
))
val prefixes = Seq(new File(sbtBase, "boot").getAbsolutePath) ++
Seq("coursier.sbt-launcher.dirs.scala-jars", "coursier.sbt-launcher.dirs.base", "user.dir")
.flatMap(sys.props.get(_))
.map(new File(_).getAbsolutePath)
val home = new File(sys.props("user.home")).getAbsolutePath
def notFromCoursierCache(name: String): Unit = {
val jars = cp.filter(_.getName.startsWith(name)).distinct
assert(jars.nonEmpty, s"Found no JARs for $name")
for (jar <- jars)
assert(
!jar.getAbsolutePath.startsWith(home) ||
!jar.getAbsolutePath.toLowerCase(java.util.Locale.ROOT).contains("coursier") ||
prefixes.exists(jar.getAbsolutePath.startsWith),
s"JAR for $name ($jar) under $home and not under any of ${prefixes.mkString(", ")}"
)
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
}
val props = Thread.currentThread()
.getContextClassLoader
.getResources("library.properties")
.asScala
.toVector
.map(_.toString)
.sorted
.distinct // TODO should not need distinct
notFromCoursierCache("scala-library")
assert(props.lengthCompare(1) == 0, s"Found several library.properties files in classpath: $props")
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
}

View File

@ -1,6 +1,8 @@
import java.io.File
import java.nio.file.Files
object Main extends App {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
}
object Main {
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
}
}

View File

@ -1,6 +1,8 @@
import java.io.File
import java.nio.file.Files
object Main extends App {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
object Main {
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
}
}

View File

@ -3,6 +3,8 @@ import java.nio.file.Files
import org.apache.zookeeper.ZooKeeper
object Main extends App {
Files.write(new File("output").toPath, classOf[ZooKeeper].getSimpleName.getBytes("UTF-8"))
object Main {
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, classOf[ZooKeeper].getSimpleName.getBytes("UTF-8"))
}
}

View File

@ -1,5 +1,7 @@
package example
object Hello extends App {
println("Hello!")
object Hello {
def main(args: Array[String]): Unit = {
println("Hello!")
}
}

View File

@ -1,5 +1,7 @@
package com.config
object Main extends App {
object Main {
def main(args: Array[String]): Unit = {
println(s"Version: ${MyClass.configValue()}")
}
}

View File

@ -1,5 +1,7 @@
package a
object Main extends App {
val core = Core
object Main {
def main(args: Array[String]): Unit = {
val core = Core
}
}

View File

@ -1,3 +1,5 @@
object Main extends App {
println(com.example.Lib.getMessage)
object Main {
def main(args: Array[String]): Unit = {
println(com.example.Lib.getMessage)
}
}

View File

@ -1,3 +1,5 @@
object Main extends App {
println(com.example.Lib.getMessage)
object Main {
def main(args: Array[String]): Unit = {
println(com.example.Lib.getMessage)
}
}

View File

@ -1,3 +1,5 @@
object B extends App {
println(A.`=`)
object B {
def main(args: Array[String]): Unit = {
println(A.`=`)
}
}

View File

@ -1,6 +1,8 @@
@hello
case class Test(x: Int)
object Main extends App {
Test(3).hello
}
object Main {
def main(args: Array[String]): Unit = {
Test(3).hello
}
}