|
29 | 29 | import java.nio.file.FileSystems; |
30 | 30 | import java.nio.file.Path; |
31 | 31 | import java.nio.file.PathMatcher; |
| 32 | +import java.nio.file.Paths; |
32 | 33 | import java.nio.file.WatchEvent.Kind; |
33 | 34 | import java.util.ArrayList; |
| 35 | +import java.util.Arrays; |
34 | 36 | import java.util.List; |
35 | 37 | import java.util.Map.Entry; |
| 38 | +import java.util.Optional; |
36 | 39 | import java.util.Properties; |
37 | 40 | import java.util.concurrent.ExecutorService; |
38 | 41 | import java.util.concurrent.Executors; |
@@ -70,7 +73,7 @@ public class Main { |
70 | 73 | public Main(final String mId, final String mainClass, final File... cp) |
71 | 74 | throws Exception { |
72 | 75 | this.mainClass = mainClass; |
73 | | - loader = AppModuleLoader.build(mId, mainClass, cp); |
| 76 | + loader = AppModuleLoader.build(mId, cp); |
74 | 77 | this.mId = ModuleIdentifier.create(mId); |
75 | 78 | this.executor = Executors.newSingleThreadExecutor(task -> new Thread(task, "HotSwap")); |
76 | 79 | this.scanner = new Watcher(this::onChange, new Path[]{basedir.toPath() }); |
@@ -160,19 +163,18 @@ private void startApp() { |
160 | 163 |
|
161 | 164 | Thread.currentThread().setContextClassLoader(mcloader); |
162 | 165 |
|
163 | | - Class<?> joobyClass = mcloader.loadClass("org.jooby.Jooby"); |
164 | | - if (mainClass.equals(joobyClass.getName())) { |
| 166 | + if (mainClass.endsWith(".js")) { |
165 | 167 | // js version |
166 | 168 | Object js = mcloader.loadClass("org.jooby.internal.js.JsJooby") |
167 | 169 | .newInstance(); |
168 | 170 | Method runjs = js.getClass().getDeclaredMethod("run", File.class); |
169 | | - this.app = ((Supplier) runjs.invoke(js, new File("app.js"))).get(); |
| 171 | + this.app = ((Supplier) runjs.invoke(js, new File(mainClass))).get(); |
170 | 172 | } else { |
171 | | - this.app = joobyClass |
| 173 | + this.app = mcloader.loadClass(mainClass) |
172 | 174 | .getDeclaredConstructors()[0].newInstance(); |
173 | 175 | } |
174 | 176 | debug("starting: %s", mainClass); |
175 | | - Method joobyRun = joobyClass.getMethod("start"); |
| 177 | + Method joobyRun = app.getClass().getMethod("start"); |
176 | 178 | joobyRun.invoke(this.app); |
177 | 179 | } catch (Throwable ex) { |
178 | 180 | Throwable cause = ex; |
@@ -357,6 +359,18 @@ public void classDefineFailed(final Throwable throwable, final String className, |
357 | 359 | } |
358 | 360 | }); |
359 | 361 | } |
| 362 | + |
| 363 | + // set logback |
| 364 | + String logback = Optional.ofNullable(System.getProperty("logback.configurationFile")) |
| 365 | + .orElseGet(() -> Arrays |
| 366 | + .asList(Paths.get("conf", "logback-test.xml"), Paths.get("conf", "logback.xml")) |
| 367 | + .stream() |
| 368 | + .filter(p -> p.toFile().exists()) |
| 369 | + .map(Path::toString) |
| 370 | + .findFirst() |
| 371 | + .orElse(Paths.get("conf", "logback.xml").toString())); |
| 372 | + debug("logback: %s", logback); |
| 373 | + System.setProperty("logback.configurationFile", logback); |
360 | 374 | } |
361 | 375 |
|
362 | 376 | public static void info(final String message, final Object... args) { |
|
0 commit comments