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 Mar 20, 2023
1 parent d870b54 commit 664f048
Show file tree
Hide file tree
Showing 3 changed files with 31 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 @@ -1237,4 +1237,12 @@ public void merge(TimestampSet other) {
}
}

public String[] getCommandLineArgs() {
return context.getArgs();
}

public RuntimeUpdatesProcessor setCommandLineArgs(String[] commandLineArgs) {
this.context.setArgs(commandLineArgs);
return this;
}
}

0 comments on commit 664f048

Please sign in to comment.