diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Shell.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Shell.java index b98fce02fb9..4c3346a14de 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Shell.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Shell.java @@ -17,13 +17,8 @@ package org.apache.activemq.artemis.cli; -import java.io.BufferedReader; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.PrintStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -36,7 +31,6 @@ import org.apache.activemq.artemis.cli.commands.ActionContext; import org.apache.activemq.artemis.cli.commands.Connect; import org.apache.activemq.artemis.cli.commands.messages.ConnectionAbstract; -import org.apache.activemq.artemis.cli.commands.util.input.SystemInputReader; import org.jline.console.SystemRegistry; import org.jline.console.impl.SystemRegistryImpl; import org.jline.reader.EndOfFileException; @@ -48,7 +42,6 @@ import org.jline.reader.impl.DefaultParser; import org.jline.terminal.Terminal; import org.jline.terminal.TerminalBuilder; -import org.jspecify.annotations.Nullable; import picocli.CommandLine; import picocli.CommandLine.Command; import picocli.shell.jline3.PicocliCommands; @@ -68,8 +61,6 @@ public class Shell implements Runnable { @CommandLine.Option(names = "--history", description = "File where shell history is being stored.") protected File historyFile; - private static final String DEFAULT_HISTORY_FILE = "history-file"; - public Shell(CommandLine commandLine) { } @@ -117,8 +108,14 @@ public static void runShell(boolean printBanner, File historyFile) { boolean isInstance = artemisInstance != null; - if (isInstance && historyFile == null) { - historyFile = inquiryDefaultHistory(historyFile, artemisInstance); + if (historyFile == null) { + String historyFilePath = System.getProperty("artemis.shell.history"); + if (historyFilePath == null) { + historyFilePath = System.getenv("ARTEMIS_SHELL_HISTORY"); + } + if (historyFilePath != null) { + historyFile = new File(historyFilePath); + } } Supplier workDir = () -> Paths.get(System.getProperty("user.dir")); @@ -234,46 +231,6 @@ private static void loadHistory(File historyFile, LineReader reader) { } } - private static @Nullable File inquiryDefaultHistory(File historyFile, String artemisInstance) { - final String NO_HISTORY = "NO_HISTORY"; - SystemInputReader inputReader = new SystemInputReader(); - File defaultHistoryFile = new File(artemisInstance + "/etc/" + DEFAULT_HISTORY_FILE); - try { - if (!defaultHistoryFile.exists()) { - defaultHistoryFile.createNewFile(); - } - - if (defaultHistoryFile.exists()) { - if (defaultHistoryFile.length() == 0) { - String input = inputReader.inputLoop(null, "Allow shell history? (Y/N)", s -> s != null && (s.toUpperCase().equals("Y") || s.toUpperCase().equals("N"))).toUpperCase(); - if (input.equals("N")) { - historyFile = null; - try (PrintStream fileOutputStream = new PrintStream(new FileOutputStream(defaultHistoryFile))) { - fileOutputStream.println(NO_HISTORY); - } - } else { - defaultHistoryFile.createNewFile(); - } - } - - if (historyFile == null) { - try (BufferedReader fileReader = new BufferedReader(new InputStreamReader(new FileInputStream(defaultHistoryFile)))) { - String line = fileReader.readLine(); - if (line != null && line.equals(NO_HISTORY)) { - // the user selected no history in the past - historyFile = null; - } else { - historyFile = defaultHistoryFile; - } - } - } - } - } catch (IOException e) { - // no history on this case then - } - return historyFile; - } - private static void printBanner() { System.out.print(org.apache.activemq.artemis.cli.Terminal.INFO_COLOR_UNICODE); try { diff --git a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis index b792eb88695..693b1756972 100755 --- a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis +++ b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis @@ -119,6 +119,11 @@ if [ -f "$ARTEMIS_OOME_DUMP" ] ; then mv $ARTEMIS_OOME_DUMP $ARTEMIS_OOME_DUMP.bkp fi +# Set shell history argument if ARTEMIS_SHELL_HISTORY is defined +if [ -n "$ARTEMIS_SHELL_HISTORY" ]; then + SHELL_HISTORY_ARG="-Dartemis.shell.history=${ARTEMIS_SHELL_HISTORY}" +fi + exec "$JAVACMD" \ $LOGGING_ARGS \ $JAVA_ARGS \ @@ -132,6 +137,7 @@ exec "$JAVACMD" \ -Djava.io.tmpdir="$ARTEMIS_INSTANCE/tmp" \ -Ddata.dir="$ARTEMIS_DATA_DIR" \ -Dartemis.instance.etc="$ARTEMIS_INSTANCE_ETC" \ + $SHELL_HISTORY_ARG \ $DEBUG_ARGS \ $JAVA_ARGS_APPEND \ org.apache.activemq.artemis.boot.Artemis "$@" diff --git a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/artemis-utility.profile b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/artemis-utility.profile index a724cd6c496..6c445b9750e 100644 --- a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/artemis-utility.profile +++ b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/artemis-utility.profile @@ -19,6 +19,8 @@ ARTEMIS_HOME='${artemis.home}' ARTEMIS_INSTANCE='@artemis.instance@' ARTEMIS_DATA_DIR='${artemis.instance.data}' +ARTEMIS_SHELL_HISTORY=~/.artemis_history + if [ -z "$LOGGING_ARGS" ]; then LOGGING_ARGS="-Dlog4j2.configurationFile=log4j2-utility.properties" fi