aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--stage1/Stage1Lib.scala16
-rw-r--r--stage2/plugins/Dotty.scala5
2 files changed, 14 insertions, 7 deletions
diff --git a/stage1/Stage1Lib.scala b/stage1/Stage1Lib.scala
index bbb6f7b..c427b77 100644
--- a/stage1/Stage1Lib.scala
+++ b/stage1/Stage1Lib.scala
@@ -101,13 +101,19 @@ class Stage1Lib( val logger: Logger ) extends BaseLib{
} else ExitCode.Success
}
- def runMain(cls: String, args: Seq[String], classLoader: ClassLoader ): ExitCode = {
+ def runMain( cls: String, args: Seq[String], classLoader: ClassLoader, fakeInstance: Boolean = false ): ExitCode = {
+ import java.lang.reflect.Modifier
logger.lib(s"Running $cls.main($args) with classLoader: " ++ classLoader.toString)
trapExitCode{
- classLoader
- .loadClass(cls)
- .getMethod( "main", classOf[Array[String]] )
- .invoke( null, args.toArray.asInstanceOf[AnyRef] )
+ val c = classLoader.loadClass(cls)
+ val m = c.getMethod( "main", classOf[Array[String]] )
+ val instance =
+ if(!fakeInstance) null else c.newInstance
+ assert(
+ fakeInstance || (m.getModifiers & java.lang.reflect.Modifier.STATIC) > 0,
+ "Cannot run non-static method " ++ cls+".main"
+ )
+ m.invoke( instance, args.toArray.asInstanceOf[AnyRef] )
ExitCode.Success
}
}
diff --git a/stage2/plugins/Dotty.scala b/stage2/plugins/Dotty.scala
index c6acbcd..5700e4d 100644
--- a/stage2/plugins/Dotty.scala
+++ b/stage2/plugins/Dotty.scala
@@ -83,9 +83,10 @@ class DottyLib(
logger.lib("creating docs for source files "+args.mkString(", "))
redirectOutToErr{
runMain(
- "dotty.tools.dottydoc.DottyDoc",
+ "dotty.tools.dottydoc.api.java.Dottydoc",
args,
- dottyDependency.classLoader(classLoaderCache)
+ dottyDependency.classLoader(classLoaderCache),
+ fakeInstance = true // this is a hack as Dottydoc's main method is not static
)
}
}