Updated Branches: refs/heads/master 66f843e6c -> b9adfbf0c
STRATOS-414 - [CLI] A Tenant can see the command history of super admin and other tenants Now users have separate history files Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/e5c87ce5 Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/e5c87ce5 Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/e5c87ce5 Branch: refs/heads/master Commit: e5c87ce54d3de89c552a7631d7587aee733cd135 Parents: 033086a Author: Manula Thantriwatte <[email protected]> Authored: Tue Feb 11 14:15:15 2014 +0530 Committer: Manula Thantriwatte <[email protected]> Committed: Tue Feb 11 14:15:15 2014 +0530 ---------------------------------------------------------------------- .../java/org/apache/stratos/cli/CliTool.java | 2 +- .../stratos/cli/CommandLineApplication.java | 32 +++++++++++++++----- .../apache/stratos/cli/StratosApplication.java | 17 ++++++++--- .../stratos/cli/commands/ExitCommand.java | 12 -------- 4 files changed, 39 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e5c87ce5/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CliTool.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CliTool.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CliTool.java index d0dd7de..ac21579 100644 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CliTool.java +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CliTool.java @@ -52,7 +52,7 @@ public class CliTool { if (logger.isInfoEnabled()) { logger.info("Stratos CLI Started..."); } - StratosApplication application = new StratosApplication(); + StratosApplication application = new StratosApplication(arguments); application.start(arguments); } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e5c87ce5/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CommandLineApplication.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CommandLineApplication.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CommandLineApplication.java index c0c2dce..a3284ac 100644 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CommandLineApplication.java +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CommandLineApplication.java @@ -33,14 +33,18 @@ public abstract class CommandLineApplication<T extends CommandContext> { private static final Logger logger = LoggerFactory.getLogger(CommandLineApplication.class); - protected final ConsoleReader reader; + protected ConsoleReader reader; protected FileHistory history; + protected String userName; - public CommandLineApplication() { - reader = createConsoleReader(); - } + public CommandLineApplication(String[] args) { + if (args != null && args.length > 1) { + userName = args[1]; + } + reader = createConsoleReader(); + } - /** + /** * Creates new jline ConsoleReader. * * @return a jline ConsoleReader instance @@ -50,7 +54,7 @@ public abstract class CommandLineApplication<T extends CommandContext> { try { consoleReader = new ConsoleReader(); consoleReader.setPrompt(getPrompt()); - history = new FileHistory(getHistoryFile()); + history = new FileHistory(getHistoryFile(userName)); consoleReader.setHistory(history); } catch (IOException e) { throw new IllegalStateException("Cannot create jline console reader", e); @@ -58,6 +62,20 @@ public abstract class CommandLineApplication<T extends CommandContext> { return consoleReader; } + protected ConsoleReader createConsoleReaderWhithoutArgs(String enteredUserName) { + ConsoleReader consoleReader = null; + history = null; + try { + consoleReader = new ConsoleReader(); + consoleReader.setPrompt(getPrompt()); + history = new FileHistory(getHistoryFile(enteredUserName)); + consoleReader.setHistory(history); + } catch (IOException e) { + throw new IllegalStateException("Cannot create jline console reader", e); + } + return consoleReader; + } + public ConsoleReader getConsoleReader() { return reader; } @@ -69,7 +87,7 @@ public abstract class CommandLineApplication<T extends CommandContext> { * * @return File for storing history */ - protected abstract File getHistoryFile(); + protected abstract File getHistoryFile(String userName); public final void start(String[] args) { Thread shutdownHookThread = new Thread("CLI Shutdown Hook") { http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e5c87ce5/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/StratosApplication.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/StratosApplication.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/StratosApplication.java index f0e2cf4..68730c3 100644 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/StratosApplication.java +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/StratosApplication.java @@ -50,14 +50,14 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon private final Options options; - public StratosApplication() { + public StratosApplication(String[] args) { + super(args); commands = new TreeMap<String, Command<StratosCommandContext>>(); context = new StratosCommandContext(this); options = constructOptions(); createCommands(); - createAutocomplete(); } /** @@ -171,9 +171,9 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon } @Override - protected File getHistoryFile() { + protected File getHistoryFile(String userName) { File stratosFile = new File(System.getProperty("user.home"), STRATOS_DIR); - File historyFile = new File(stratosFile, STRATOS_HISTORY_DIR); + File historyFile = new File(stratosFile, STRATOS_HISTORY_DIR + "_" + userName); return historyFile; } @@ -343,6 +343,15 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon String stratosURL = null; stratosURL = context.getString(CliConstants.STRATOS_URL_ENV_PROPERTY); + // This is to create the history file. + // This section execute only when user didn't enter the username as command line arguments + if (userName == null) { + reader = null; + reader = createConsoleReaderWhithoutArgs(usernameInput); + } + + createAutocomplete(); + try { success = RestCommandLineService.getInstance().login(stratosURL, usernameInput, passwordInput, validateLogin); //success = CommandLineService.getInstance().login(stratosURL, usernameInput, passwordInput, validateLogin); http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e5c87ce5/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ExitCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ExitCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ExitCommand.java index 412b125..4a3a801 100644 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ExitCommand.java +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ExitCommand.java @@ -60,18 +60,6 @@ public class ExitCommand implements Command<StratosCommandContext> { logger.debug("Executing {} command...", getName()); } if (args == null || args.length == 0) { - // Delete the command history file on exit - File stratosFile = new File(System.getProperty("user.home"), STRATOS_DIR); - File historyFile = new File(stratosFile, STRATOS_HISTORY_DIR); - - historyFile.deleteOnExit(); - - if(historyFile.delete()){ - logger.debug(historyFile.getName() + " is deleted!"); - }else{ - logger.debug("Delete operation is failed."); - } - return CliConstants.SUCCESSFUL_CODE; } else { context.getStratosApplication().printUsage(getName());
