Skip to content
Browse files

SHl-22 limit history size, remove dead code

  • Loading branch information...
1 parent 02ab62b commit 5dca1a102aef5884c203b81c8d803633f586f76f @leejianwei leejianwei committed
View
2 samples/helloworld/pom.xml
@@ -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>
View
6 ...c/main/java/org/springframework/shell/samples/helloworld/commands/HelloWorldCommands.java
@@ -17,7 +17,9 @@ public boolean isCommandAvailable() {
@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);
}
}
View
2 src/main/java/org/springframework/roo/shell/SimpleParser.java
@@ -270,7 +270,7 @@ String normalise(final String rawInput) {
}
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) {
View
9 src/main/java/org/springframework/shell/Bootstrap.java
@@ -45,7 +45,7 @@ public static void main(String[] args) throws IOException {
}
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 static void main(String[] args) throws IOException {
}
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 Bootstrap(String applicationContextLocation) throws IOException {
}
- private void createApplicationContext(String applicationContextLocation) {
+ private void createApplicationContext() {
AnnotationConfigApplicationContext annctx = new AnnotationConfigApplicationContext();
createAndRegisterBeanDefinition(annctx, org.springframework.roo.shell.converters.StringConverter.class);
createAndRegisterBeanDefinition(annctx,
View
31 src/main/java/org/springframework/shell/JLineShell.java
@@ -95,6 +95,7 @@
private String version;
private String welcomeMessage;
+ private int historySize;
public void run() {
try {
@@ -137,9 +138,14 @@ public void run() {
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 @@ private String getHistoryFileName() {
* 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 @@ private String getPromptText(){
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 String getWelcomeMessage(){
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;
+ }
}
View
94 src/main/java/org/springframework/shell/SimpleShellCommandLineOptions.java
@@ -18,51 +18,61 @@
* @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}");
+ }
}
View
30 src/main/resources/META-INF/spring/app-context.xml
@@ -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>

0 comments on commit 5dca1a1

Please sign in to comment.
Something went wrong with that request. Please try again.