SHl-22 limit history size, remove dead code
This commit is contained in:
@@ -88,7 +88,7 @@
|
||||
<id>spring-maven-snapshot</id>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>always</updatePolicy>
|
||||
<!-- <updatePolicy>always</updatePolicy> -->
|
||||
</snapshots>
|
||||
<name>Springframework Maven SNAPSHOT Repository</name>
|
||||
<url>http://maven.springframework.org/snapshot</url>
|
||||
|
||||
@@ -17,7 +17,9 @@ public class HelloWorldCommands implements CommandMarker {
|
||||
|
||||
@CliCommand(value = "hw echo", help = "Print a hello world message")
|
||||
public void config(
|
||||
@CliOption(key = { "message" }, mandatory = true, help = "The hello world message") final String message) {
|
||||
System.out.println("Hello world " + message);
|
||||
@CliOption(key = { "message" }, mandatory = true, help = "The hello world message") final String message,
|
||||
@CliOption(key = { "name" }, mandatory = true, help = "The hello world name ") final String name,
|
||||
@CliOption(key = { "time" }, mandatory = false, help = "The hello world time ") final String time) {
|
||||
System.out.println("Hello world " + message + "," + name + ". time:" + time);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ public class SimpleParser implements Parser {
|
||||
}
|
||||
|
||||
protected void commandNotFound(final Logger logger, final String buffer) {
|
||||
logger.warning("Command '" + buffer + "' not found (for assistance press " + AbstractShell.completionKeys + " or type \"hint\" then hit ENTER)");
|
||||
logger.warning("Command '" + buffer + "' not found (for assistance press " + AbstractShell.completionKeys + ")");
|
||||
}
|
||||
|
||||
private Collection<MethodTarget> locateTargets(final String buffer, final boolean strictMatching, final boolean checkAvailabilityIndicators) {
|
||||
|
||||
@@ -45,7 +45,7 @@ public class Bootstrap {
|
||||
}
|
||||
ExitShellRequest exitShellRequest;
|
||||
try {
|
||||
bootstrap = new Bootstrap(options.applicationContextLocation);
|
||||
bootstrap = new Bootstrap(null);
|
||||
exitShellRequest = bootstrap.run(options.executeThenQuit);
|
||||
} catch (RuntimeException t) {
|
||||
throw t;
|
||||
@@ -57,12 +57,11 @@ public class Bootstrap {
|
||||
}
|
||||
|
||||
public Bootstrap(String applicationContextLocation) throws IOException {
|
||||
//setupLogging();
|
||||
Assert.hasText(applicationContextLocation, "Application context location required");
|
||||
createApplicationContext(applicationContextLocation);
|
||||
createApplicationContext();
|
||||
|
||||
shell = ctx.getBean("shell", JLineShellComponent.class);
|
||||
shell.setApplicationContext(ctx);
|
||||
shell.setHistorySize(options.historySize);
|
||||
if (options.executeThenQuit != null) {
|
||||
shell.setPrintBanner(false);
|
||||
}
|
||||
@@ -96,7 +95,7 @@ public class Bootstrap {
|
||||
|
||||
}
|
||||
|
||||
private void createApplicationContext(String applicationContextLocation) {
|
||||
private void createApplicationContext() {
|
||||
AnnotationConfigApplicationContext annctx = new AnnotationConfigApplicationContext();
|
||||
createAndRegisterBeanDefinition(annctx, org.springframework.roo.shell.converters.StringConverter.class);
|
||||
createAndRegisterBeanDefinition(annctx,
|
||||
|
||||
@@ -95,6 +95,7 @@ public abstract class JLineShell extends AbstractShell
|
||||
private String version;
|
||||
private String welcomeMessage;
|
||||
|
||||
private int historySize;
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
@@ -137,9 +138,14 @@ public abstract class JLineShell extends AbstractShell
|
||||
String logFileContents = FileCopyUtils.copyToString(new File(this.historyFileName));
|
||||
String[] logEntries = logFileContents.split(StringUtils.LINE_SEPARATOR);
|
||||
// LIFO
|
||||
int size = 0;
|
||||
for (String logEntry : logEntries) {
|
||||
if (!logEntry.startsWith("//")) {
|
||||
reader.getHistory().addToHistory(logEntry);
|
||||
size++;
|
||||
if(size > historySize){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
@@ -561,7 +567,7 @@ public abstract class JLineShell extends AbstractShell
|
||||
* get prompt text from provider. The provider has highest order
|
||||
* <link>org.springframework.core.Ordered.getOder</link> will win.
|
||||
*
|
||||
* @return
|
||||
* @return prompt text
|
||||
*/
|
||||
private String getPromptText(){
|
||||
return getHighestPriorityProvider(PromptProvider.class).getPromptText();
|
||||
@@ -591,11 +597,20 @@ public abstract class JLineShell extends AbstractShell
|
||||
return highestPriorityProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the version information
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public String version(String text){
|
||||
return this.version;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the welcome message at start.
|
||||
*
|
||||
* @return welcome message
|
||||
*/
|
||||
public String getWelcomeMessage(){
|
||||
return this.welcomeMessage;
|
||||
}
|
||||
@@ -607,5 +622,19 @@ public abstract class JLineShell extends AbstractShell
|
||||
public void setPrintBanner(boolean printBanner) {
|
||||
this.printBanner = printBanner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the historySize
|
||||
*/
|
||||
public int getHistorySize() {
|
||||
return historySize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param historySize the historySize to set
|
||||
*/
|
||||
public void setHistorySize(int historySize) {
|
||||
this.historySize = historySize;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,51 +18,61 @@ import org.apache.commons.io.FileUtils;
|
||||
* @author vnagaraja
|
||||
*/
|
||||
public class SimpleShellCommandLineOptions {
|
||||
String[] executeThenQuit = null;
|
||||
Map<String, String> extraSystemProperties = new HashMap<String, String>();
|
||||
int historySize = 3000;
|
||||
|
||||
public static final String DEFAULT_APP_CTX = "classpath*:/META-INF/spring/app-context.xml";
|
||||
String applicationContextLocation = DEFAULT_APP_CTX;
|
||||
String[] executeThenQuit = null;
|
||||
Map<String, String> extraSystemProperties = new HashMap<String, String>();
|
||||
public static SimpleShellCommandLineOptions parseCommandLine(String[] args) throws IOException {
|
||||
SimpleShellCommandLineOptions options = new SimpleShellCommandLineOptions();
|
||||
List<String> commands = new ArrayList<String>();
|
||||
int i = 0;
|
||||
while (i < args.length) {
|
||||
String arg = args[i++];
|
||||
if (arg.equals("--environment")) {
|
||||
String environment = args[i++];
|
||||
options.extraSystemProperties.put("napa.application.profile", environment);
|
||||
}
|
||||
else if (arg.equals("--cmdfile")) {
|
||||
File f = new File(args[i++]);
|
||||
commands.addAll(FileUtils.readLines(f));
|
||||
}
|
||||
else if (arg.equals("--histsize")) {
|
||||
options.historySize = Integer.parseInt(args[i++]);
|
||||
}
|
||||
else if (arg.equals("--help")) {
|
||||
printUsage();
|
||||
System.exit(0);
|
||||
}
|
||||
else {
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static SimpleShellCommandLineOptions parseCommandLine(String[] args) throws IOException {
|
||||
SimpleShellCommandLineOptions options = new SimpleShellCommandLineOptions();
|
||||
List<String> commands = new ArrayList<String>();
|
||||
int i = 0;
|
||||
while (i < args.length) {
|
||||
String arg = args[i++];
|
||||
if (arg.equals("-environment")) {
|
||||
String environment = args[i++];
|
||||
options.extraSystemProperties.put("napa.application.profile", environment);
|
||||
} else if (arg.equals("-ctx")) {
|
||||
options.applicationContextLocation = args[i++];
|
||||
} else if (arg.equals("-cmdfile")) {
|
||||
File f = new File(args[i++]);
|
||||
commands.addAll(FileUtils.readLines(f));
|
||||
} else {
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (; i < args.length; i++) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(" ");
|
||||
}
|
||||
sb.append(args[i]);
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (; i < args.length; i++) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(" ");
|
||||
}
|
||||
sb.append(args[i]);
|
||||
}
|
||||
if (sb.length() > 0) {
|
||||
String[] cmdLineCommands = sb.toString().split(";");
|
||||
for (String s : cmdLineCommands) {
|
||||
//add any command line commands after the commands loaded from the file
|
||||
commands.add(s.trim());
|
||||
}
|
||||
}
|
||||
|
||||
if(sb.length()>0) {
|
||||
String[] cmdLineCommands = sb.toString().split(";");
|
||||
for(String s : cmdLineCommands) {
|
||||
//add any command line commands after the commands loaded from the file
|
||||
commands.add(s.trim());
|
||||
}
|
||||
}
|
||||
if (commands.size() > 0)
|
||||
options.executeThenQuit = commands.toArray(new String[commands.size()]);
|
||||
|
||||
if(commands.size()>0)
|
||||
options.executeThenQuit = commands.toArray(new String[commands.size()]);
|
||||
|
||||
return options;
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
private static void printUsage(){
|
||||
System.out.println("Usage:");
|
||||
System.out.println("java -jar {jarname} --help --histsize {size} --cmdfile {file}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
|
||||
|
||||
<description>Example configuration to get you started.</description>
|
||||
|
||||
<context:component-scan base-package="org.springframework.shell" />
|
||||
|
||||
<bean class="org.springframework.roo.shell.converters.StringConverter"/>
|
||||
<bean class="org.springframework.roo.shell.converters.AvailableCommandsConverter"/>
|
||||
<bean class="org.springframework.roo.shell.converters.BigDecimalConverter"/>
|
||||
<bean class="org.springframework.roo.shell.converters.BigIntegerConverter"/>
|
||||
<bean class="org.springframework.roo.shell.converters.BooleanConverter"/>
|
||||
<bean class="org.springframework.roo.shell.converters.CharacterConverter"/>
|
||||
<bean class="org.springframework.roo.shell.converters.DateConverter"/>
|
||||
<bean class="org.springframework.roo.shell.converters.DoubleConverter"/>
|
||||
<bean class="org.springframework.roo.shell.converters.EnumConverter"/>
|
||||
<bean class="org.springframework.roo.shell.converters.FloatConverter"/>
|
||||
<bean class="org.springframework.roo.shell.converters.IntegerConverter"/>
|
||||
<bean class="org.springframework.roo.shell.converters.LocaleConverter"/>
|
||||
<bean class="org.springframework.roo.shell.converters.LongConverter"/>
|
||||
<bean class="org.springframework.roo.shell.converters.ShortConverter"/>
|
||||
<bean class="org.springframework.roo.shell.converters.StaticFieldConverterImpl"/>
|
||||
<bean class="org.springframework.roo.shell.converters.StringConverter"/>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user