Skip to content

Commit be2dc1c

Browse files
committed
add execution mode to maven plugin
1 parent aee1abf commit be2dc1c

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

jooby/src/main/java/io/jooby/Jooby.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -682,16 +682,6 @@ public static void runApp(@Nonnull String[] args, @Nonnull ExecutionMode executi
682682
server.join();
683683
}
684684

685-
/**
686-
* Setup default environment, logging (logback or log4j2) and run application.
687-
*
688-
* @param applicationType Application type.
689-
* @return Application.
690-
*/
691-
public static Jooby createApp(@Nonnull Class<? extends Jooby> applicationType) {
692-
return createApp(new String[0], ExecutionMode.DEFAULT, reflectionProvider(applicationType));
693-
}
694-
695685
/**
696686
* Setup default environment, logging (logback or log4j2) and run application.
697687
*

modules/jooby-maven-plugin/src/main/java/io/jooby/RunMojo.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public class RunMojo extends AbstractMojo {
6464
@Parameter(defaultValue = "${application.class}")
6565
private String mainClass;
6666

67+
@Parameter(defaultValue = "${application.mode}")
68+
private String executionMode;
69+
6770
@Parameter(defaultValue = "conf,properties,class")
6871
private List<String> restartExtensions;
6972

@@ -90,9 +93,13 @@ public class RunMojo extends AbstractMojo {
9093
.map(it -> it.getProperties().getProperty(APP_CLASS))
9194
.orElseThrow(() -> new MojoExecutionException("Application class not found"));
9295
}
96+
if (executionMode == null) {
97+
executionMode = "DEFAULT";
98+
}
9399
getLog().debug("Found `" + APP_CLASS + "`: " + mainClass);
94100

95-
HotSwap hotSwap = new HotSwap(session.getCurrentProject().getArtifactId(), mainClass);
101+
HotSwap hotSwap = new HotSwap(session.getCurrentProject().getArtifactId(), mainClass,
102+
executionMode);
96103

97104
Runtime.getRuntime().addShutdownHook(new Thread(hotSwap::shutdown));
98105

modules/jooby-run/src/main/java/io/jooby/run/HotSwap.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,18 @@ private static class AppModule {
8484
private final ExtModuleLoader loader;
8585
private final String projectName;
8686
private final String mainClass;
87+
private final String executionMode;
8788
private Module module;
8889
private Server server;
8990
private ClassLoader contextClassLoader;
9091

9192
public AppModule(Logger logger, ExtModuleLoader loader, String projectName, String mainClass,
92-
ClassLoader contextClassLoader) {
93+
String executionMode, ClassLoader contextClassLoader) {
9394
this.logger = logger;
9495
this.loader = loader;
9596
this.projectName = projectName;
9697
this.mainClass = mainClass;
98+
this.executionMode = executionMode;
9799
this.contextClassLoader = contextClassLoader;
98100
}
99101

@@ -105,10 +107,13 @@ public void start() {
105107
Thread.currentThread().setContextClassLoader(classLoader);
106108

107109
Class joobyClass = classLoader.loadClass("io.jooby.Jooby");
108-
Method createApp = joobyClass.getDeclaredMethod("createApp", Class.class);
110+
Class executionModeClass = classLoader.loadClass("io.jooby.ExecutionMode");
111+
Method createApp = joobyClass
112+
.getDeclaredMethod("createApp", String[].class, executionModeClass, Class.class);
109113

110114
Class appClass = classLoader.loadClass(mainClass);
111-
App app = new App(createApp.invoke(null, appClass));
115+
Enum executionModeValue = Enum.valueOf(executionModeClass, executionMode.toUpperCase());
116+
App app = new App(createApp.invoke(null, new String[0], executionModeValue, appClass));
112117
server = app.start();
113118
} catch (Exception x) {
114119
logger.error("Unable to start: {}", mainClass, x);
@@ -158,6 +163,8 @@ private void closeServer() {
158163

159164
private final String mainClass;
160165

166+
private final String executionMode;
167+
161168
private final Set<Path> resources = new LinkedHashSet<>();
162169

163170
private final Set<Path> dependencies = new LinkedHashSet<>();
@@ -168,9 +175,10 @@ private void closeServer() {
168175

169176
private AppModule module;
170177

171-
public HotSwap(String projectName, String mainClass) {
178+
public HotSwap(String projectName, String mainClass, String executionMode) {
172179
this.projectName = projectName;
173180
this.mainClass = mainClass;
181+
this.executionMode = executionMode;
174182
}
175183

176184
public void addResource(Path path) {
@@ -197,7 +205,7 @@ public void start() throws Exception {
197205
ModuleFinder[] finders = finders(false);
198206

199207
ExtModuleLoader loader = new ExtModuleLoader(finders);
200-
module = new AppModule(logger, loader, projectName, mainClass,
208+
module = new AppModule(logger, loader, projectName, mainClass, executionMode,
201209
Thread.currentThread().getContextClassLoader());
202210
module.start();
203211
watcher.watch();

0 commit comments

Comments
 (0)