3030import java .nio .file .Path ;
3131import java .nio .file .PathMatcher ;
3232import java .nio .file .WatchEvent .Kind ;
33- import java .time .LocalTime ;
34- import java .time .format .DateTimeFormatter ;
3533import java .util .ArrayList ;
3634import java .util .List ;
3735import java .util .Map .Entry ;
3836import java .util .Properties ;
3937import java .util .concurrent .ExecutorService ;
4038import java .util .concurrent .Executors ;
4139import java .util .concurrent .atomic .AtomicReference ;
40+ import java .util .function .Supplier ;
4241
4342import org .jboss .modules .Module ;
4443import org .jboss .modules .ModuleClassLoader ;
@@ -147,6 +146,7 @@ public void run() {
147146 this .startApp ();
148147 }
149148
149+ @ SuppressWarnings ("rawtypes" )
150150 private void startApp () {
151151 if (app != null ) {
152152 stopApp (app );
@@ -160,18 +160,20 @@ private void startApp() {
160160
161161 Thread .currentThread ().setContextClassLoader (mcloader );
162162
163- if (mainClass .equals ("org.jooby.Jooby" )) {
163+ Class <?> joobyClass = mcloader .loadClass ("org.jooby.Jooby" );
164+ if (mainClass .equals (joobyClass .getName ())) {
164165 // js version
165166 Object js = mcloader .loadClass ("org.jooby.internal.js.JsJooby" )
166167 .newInstance ();
167168 Method runjs = js .getClass ().getDeclaredMethod ("run" , File .class );
168- this .app = runjs .invoke (js , new File ("app.js" ));
169+ this .app = (( Supplier ) runjs .invoke (js , new File ("app.js" ))). get ( );
169170 } else {
170- this .app = mcloader . loadClass ( mainClass )
171+ this .app = joobyClass
171172 .getDeclaredConstructors ()[0 ].newInstance ();
172173 }
173174 debug ("starting: %s" , mainClass );
174- app .getClass ().getMethod ("start" ).invoke (app );
175+ Method joobyRun = joobyClass .getMethod ("start" );
176+ joobyRun .invoke (this .app );
175177 } catch (Throwable ex ) {
176178 Throwable cause = ex ;
177179 if (ex instanceof InvocationTargetException ) {
@@ -272,6 +274,7 @@ private static void logLevel() {
272274 TRACE = "trace" .equalsIgnoreCase (System .getProperty ("logLevel" , "" ));
273275
274276 if (TRACE ) {
277+ DEBUG = true ;
275278 Module .setModuleLogger (new ModuleLogger () {
276279
277280 @ Override
@@ -357,26 +360,26 @@ public void classDefineFailed(final Throwable throwable, final String className,
357360 }
358361
359362 public static void info (final String message , final Object ... args ) {
360- System .out .println (format (message , args ));
363+ System .out .println (format ("info" , message , args ));
361364 }
362365
363366 public static void error (final String message , final Object ... args ) {
364- System .err .println (format (message , args ));
367+ System .err .println (format ("error" , message , args ));
365368 }
366369
367370 public static void debug (final String message , final Object ... args ) {
368371 if (DEBUG ) {
369- System .out .println (format (message , args ));
372+ System .out .println (format ("debug" , message , args ));
370373 }
371374 }
372375
373376 public static void trace (final String message , final Object ... args ) {
374377 if (TRACE ) {
375- System .out .println (format (message , args ));
378+ System .out .println (format ("trace" , message , args ));
376379 }
377380 }
378381
379- private static String format (final String message , final Object ... args ) {
382+ private static String format (final String level , final String message , final Object ... args ) {
380383 Object [] values = args ;
381384 Throwable x = null ;
382385 if (args .length > 0 ) {
@@ -388,10 +391,12 @@ private static String format(final String message, final Object... args) {
388391 }
389392 String msg = String .format (message , values );
390393 StringBuilder buff = new StringBuilder ();
391- buff .append ("[HotSwap|" )
392- .append (Thread .currentThread ().getName ()).append ("|" )
393- .append (LocalTime .now ().format (DateTimeFormatter .ofPattern ("hh:mm:ss" )))
394- .append ("]: " ).append (msg );
394+ buff .append (">>> jooby:run[" )
395+ .append (level )
396+ .append ("|" )
397+ .append (Thread .currentThread ().getName ())
398+ .append ("]: " )
399+ .append (msg );
395400 if (x != null ) {
396401 buff .append ("\n " );
397402 StringWriter writer = new StringWriter ();
0 commit comments