Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
}

Expand Down Expand Up @@ -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<Path> workDir = () -> Paths.get(System.getProperty("user.dir"));
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down