Skip to content

Commit 2bfd06b

Browse files
committed
fix some bugs on jooby:run rewrite #337
1 parent 8c1fd91 commit 2bfd06b

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

jooby-maven-plugin/src/main/java/org/jooby/JoobyMojo.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,6 @@ public void run() {
122122
@Override
123123
public void execute() throws MojoExecutionException, MojoFailureException {
124124

125-
boolean js = new File("app.js").exists();
126-
if (js) {
127-
mainClass = "org.jooby.Jooby";
128-
}
129-
130125
Set<File> appcp = new LinkedHashSet<File>();
131126

132127
// public / config, etc..

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,17 @@ public void unload(final Module module) {
6363
* Build a flat jboss module, with some minor exceptions (like j2v8).
6464
*
6565
* @param name module name.
66-
* @param mainClass
6766
* @param cp
6867
* @return
6968
* @throws Exception
7069
*/
71-
public static AppModuleLoader build(final String name, final String mainClass, final File... cp)
72-
throws Exception {
73-
Map<ModuleIdentifier, ModuleSpec> modules = newModule(name, mainClass, 0, "", cp);
70+
public static AppModuleLoader build(final String name, final File... cp) throws Exception {
71+
Map<ModuleIdentifier, ModuleSpec> modules = newModule(name, 0, "", cp);
7472
return new AppModuleLoader(modules);
7573
}
7674

7775
private static Map<ModuleIdentifier, ModuleSpec> newModule(final String name,
78-
final String mainClass, final int level, final String prefix, final File... cp)
79-
throws Exception {
76+
final int level, final String prefix, final File... cp) throws Exception {
8077
Map<ModuleIdentifier, ModuleSpec> modules = new HashMap<>();
8178

8279
String mId = name.replace(".jar", "");
@@ -87,7 +84,7 @@ private static Map<ModuleIdentifier, ModuleSpec> newModule(final String name,
8784
for (File file : cp) {
8885
String fname = "└── " + file.getAbsolutePath();
8986
if (file.getName().startsWith("j2v8") && !name.equals(file.getName())) {
90-
ModuleSpec dependency = newModule(file.getName(), null, level + 2, "└── ", file)
87+
ModuleSpec dependency = newModule(file.getName(), level + 2, "└── ", file)
9188
.values()
9289
.iterator()
9390
.next();
@@ -115,10 +112,6 @@ private static Map<ModuleIdentifier, ModuleSpec> newModule(final String name,
115112
builder.addDependency(DependencySpec.createSystemDependencySpec(sysPaths));
116113
builder.addDependency(DependencySpec.createLocalDependencySpec());
117114

118-
if (mainClass != null) {
119-
builder.setMainClass(mainClass);
120-
}
121-
122115
ModuleSpec module = builder.create();
123116
modules.put(module.getModuleIdentifier(), builder.create());
124117
return modules;

jooby-run/src/main/java/org/jooby/run/Main.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@
2929
import java.nio.file.FileSystems;
3030
import java.nio.file.Path;
3131
import java.nio.file.PathMatcher;
32+
import java.nio.file.Paths;
3233
import java.nio.file.WatchEvent.Kind;
3334
import java.util.ArrayList;
35+
import java.util.Arrays;
3436
import java.util.List;
3537
import java.util.Map.Entry;
38+
import java.util.Optional;
3639
import java.util.Properties;
3740
import java.util.concurrent.ExecutorService;
3841
import java.util.concurrent.Executors;
@@ -70,7 +73,7 @@ public class Main {
7073
public Main(final String mId, final String mainClass, final File... cp)
7174
throws Exception {
7275
this.mainClass = mainClass;
73-
loader = AppModuleLoader.build(mId, mainClass, cp);
76+
loader = AppModuleLoader.build(mId, cp);
7477
this.mId = ModuleIdentifier.create(mId);
7578
this.executor = Executors.newSingleThreadExecutor(task -> new Thread(task, "HotSwap"));
7679
this.scanner = new Watcher(this::onChange, new Path[]{basedir.toPath() });
@@ -160,19 +163,18 @@ private void startApp() {
160163

161164
Thread.currentThread().setContextClassLoader(mcloader);
162165

163-
Class<?> joobyClass = mcloader.loadClass("org.jooby.Jooby");
164-
if (mainClass.equals(joobyClass.getName())) {
166+
if (mainClass.endsWith(".js")) {
165167
// js version
166168
Object js = mcloader.loadClass("org.jooby.internal.js.JsJooby")
167169
.newInstance();
168170
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();
170172
} else {
171-
this.app = joobyClass
173+
this.app = mcloader.loadClass(mainClass)
172174
.getDeclaredConstructors()[0].newInstance();
173175
}
174176
debug("starting: %s", mainClass);
175-
Method joobyRun = joobyClass.getMethod("start");
177+
Method joobyRun = app.getClass().getMethod("start");
176178
joobyRun.invoke(this.app);
177179
} catch (Throwable ex) {
178180
Throwable cause = ex;
@@ -357,6 +359,18 @@ public void classDefineFailed(final Throwable throwable, final String className,
357359
}
358360
});
359361
}
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);
360374
}
361375

362376
public static void info(final String message, final Object... args) {

0 commit comments

Comments
 (0)