aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2016-09-28 20:32:07 -0400
committerChristopher Vogt <oss.nsp@cvogt.org>2016-09-28 20:32:07 -0400
commit8bd15f12236a6ce3d65952dbcbfc1d25e7a73e32 (patch)
treea8e7cf7b65fce32fb95714a4a49b928db817ef01
parent1694dd3bc3cd407c3784080d38778030385ae758 (diff)
downloadcbt-8bd15f12236a6ce3d65952dbcbfc1d25e7a73e32.tar.gz
cbt-8bd15f12236a6ce3d65952dbcbfc1d25e7a73e32.tar.bz2
cbt-8bd15f12236a6ce3d65952dbcbfc1d25e7a73e32.zip
Use correct main method for Dottydoc - the java interface
and work around the fact that the main method is not static (huh?)
-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
)
}
}