Skip to content

Commit

Permalink
Allow editing of params at any time
Browse files Browse the repository at this point in the history
Currently it is only possible to edit command line parameters in dev
mode after the application has exited. This means that if you have long
running applications (or accidently hang your app) you can't restart
with different parameters.
  • Loading branch information
stuartwdouglas committed May 22, 2023
1 parent d73267b commit a830a0c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
import java.util.logging.Level;
import java.util.stream.Collectors;

import org.jboss.logging.Logger;
import org.jboss.logmanager.LogManager;

import io.quarkus.deployment.dev.RuntimeUpdatesProcessor;
import io.quarkus.deployment.dev.testing.MessageFormat;
import io.quarkus.deployment.dev.testing.TestSupport;
import io.quarkus.deployment.util.CommandLineUtil;
import io.quarkus.dev.console.QuarkusConsole;
import io.quarkus.dev.spi.DevModeType;

Expand Down Expand Up @@ -97,6 +100,25 @@ void installBuiltins(DevModeType devModeType) {
commands.add(new ConsoleCommand('s', "Force restart", null, () -> {
forceRestart();
}));
commands.add(new ConsoleCommand('e', "Edits the command line parameters and restarts",
"to edit command line args (currently '" + MessageFormat.GREEN
+ String.join(" ", RuntimeUpdatesProcessor.INSTANCE.getCommandLineArgs()) + MessageFormat.RESET
+ "')",
100, new ConsoleCommand.HelpState(() -> BLUE,
() -> String.join(" ", RuntimeUpdatesProcessor.INSTANCE.getCommandLineArgs())),
new Consumer<String>() {
@Override
public void accept(String args) {
try {
RuntimeUpdatesProcessor.INSTANCE.setCommandLineArgs(
CommandLineUtil.translateCommandline(args));
} catch (Exception e) {
Logger.getLogger(ConsoleStateManager.class).errorf(e, "Failed to parse command line %s", args);
return;
}
RuntimeUpdatesProcessor.INSTANCE.doScan(true, true);
}
}));

commands.add(new ConsoleCommand('i', "Toggle instrumentation based reload",
new ConsoleCommand.HelpState(() -> RuntimeUpdatesProcessor.INSTANCE.instrumentationEnabled()), () -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.quarkus.deployment.dev;

import static io.quarkus.deployment.dev.testing.MessageFormat.BLUE;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
Expand Down Expand Up @@ -42,10 +40,8 @@
import io.quarkus.deployment.builditem.ApplicationClassPredicateBuildItem;
import io.quarkus.deployment.console.ConsoleCommand;
import io.quarkus.deployment.console.ConsoleStateManager;
import io.quarkus.deployment.dev.testing.MessageFormat;
import io.quarkus.deployment.dev.testing.TestSupport;
import io.quarkus.deployment.steps.ClassTransformingBuildStep;
import io.quarkus.deployment.util.CommandLineUtil;
import io.quarkus.dev.appstate.ApplicationStartException;
import io.quarkus.dev.console.DevConsoleManager;
import io.quarkus.dev.spi.DeploymentFailedStartHandler;
Expand Down Expand Up @@ -110,27 +106,7 @@ public void accept(Integer integer) {
() -> {
consoleContext.reset();
RuntimeUpdatesProcessor.INSTANCE.doScan(true, true);
}),
new ConsoleCommand('e', "Edits the command line parameters and restarts",
"to edit command line args (currently '" + MessageFormat.GREEN
+ String.join(" ", context.getArgs()) + MessageFormat.RESET + "')",
100, new ConsoleCommand.HelpState(() -> BLUE,
() -> String.join(" ", context.getArgs())),
new Consumer<String>() {
@Override
public void accept(String args) {
try {
context.setArgs(
CommandLineUtil.translateCommandline(args));
} catch (Exception e) {
log.error("Failed to parse command line", e);
return;
}
consoleContext.reset();
RuntimeUpdatesProcessor.INSTANCE.doScan(true, true);
}
}));

}));
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1252,4 +1252,16 @@ boolean isWatchedFileRestartNeeded(String changedFile) {
}
}

public String[] getCommandLineArgs() {
String[] contextArgs = context.getArgs();
if (contextArgs == null) {
return new String[0];
}
return contextArgs;
}

public RuntimeUpdatesProcessor setCommandLineArgs(String[] commandLineArgs) {
this.context.setArgs(commandLineArgs);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ public void close() throws Throwable {
context.setTest(true);
context.setAbortOnFailedStart(!allowFailedStart);
context.getBuildSystemProperties().put("quarkus.banner.enabled", "false");
context.getBuildSystemProperties().put("quarkus.console.disable-input", "true"); //surefire communicates via stdin, we don't want the test to be reading input
context.getBuildSystemProperties().putAll(buildSystemProperties);
devModeMain = new DevModeMain(context);
devModeMain.start();
Expand Down

0 comments on commit a830a0c

Please sign in to comment.