Skip to content

Commit f3a2876

Browse files
committed
jooby:run fail on app.js fix #406
1 parent 4fed884 commit f3a2876

4 files changed

Lines changed: 974 additions & 964 deletions

File tree

jooby-hotreload/src/main/java/org/jooby/hotreload/AppModule.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@
3030
import java.nio.file.Path;
3131
import java.nio.file.PathMatcher;
3232
import java.nio.file.WatchEvent.Kind;
33-
import java.time.LocalTime;
34-
import java.time.format.DateTimeFormatter;
3533
import java.util.ArrayList;
3634
import java.util.List;
3735
import java.util.Map.Entry;
3836
import java.util.Properties;
3937
import java.util.concurrent.ExecutorService;
4038
import java.util.concurrent.Executors;
4139
import java.util.concurrent.atomic.AtomicReference;
40+
import java.util.function.Supplier;
4241

4342
import org.jboss.modules.Module;
4443
import 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();

jooby-hotreload/src/main/java/org/jooby/hotreload/AppModuleLoader.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,12 @@ private static Map<ModuleIdentifier, ModuleSpec> newModule(final String name,
107107
}
108108
}
109109
}
110-
Set<String> jdkPaths = sysPaths();
111-
builder.addDependency(DependencySpec.createSystemDependencySpec(jdkPaths));
110+
Set<String> sysPaths = sysPaths();
111+
112+
AppModule.trace("system packages:");
113+
sysPaths.forEach(p -> AppModule.trace(" %s", p));
114+
115+
builder.addDependency(DependencySpec.createSystemDependencySpec(sysPaths));
112116
builder.addDependency(DependencySpec.createLocalDependencySpec());
113117

114118
if (mainClass != null) {

0 commit comments

Comments
 (0)