refactor code per Mark comments, remove some system commands per Jun comments.

This commit is contained in:
Jarred Li
2012-04-13 12:11:20 +08:00
parent 270c6d1e17
commit 34e4c23e1f
11 changed files with 21 additions and 28 deletions

View File

@@ -16,7 +16,7 @@
package org.springframework.shell.samples.helloworld.commands;
import org.springframework.shell.plugin.HistoryFileProvider;
import org.springframework.shell.plugin.HistoryFileNameProvider;
import org.springframework.stereotype.Component;
/**
@@ -25,7 +25,7 @@ import org.springframework.stereotype.Component;
*
*/
@Component
public class MyHistoryFileProvider implements HistoryFileProvider {
public class MyHistoryFileNameProvider implements HistoryFileNameProvider {
public int getOrder() {
return 1;

View File

@@ -332,7 +332,7 @@ public abstract class AbstractShell extends AbstractShellStatusPublisher impleme
return DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(new Date());
}
@CliCommand(value = { "flash test" }, help = "Tests message flashing")
//@CliCommand(value = { "flash test" }, help = "Tests message flashing")
public void flashCustom() throws Exception {
flash(Level.FINE, "Hello world", "a");
Thread.sleep(150);
@@ -357,7 +357,7 @@ public abstract class AbstractShell extends AbstractShellStatusPublisher impleme
flash(Level.FINE, "", "b");
}
@CliCommand(value = { "version" }, help = "Displays shell version")
//@CliCommand(value = { "version" }, help = "Displays shell version")
public String version(@CliOption(key = "", help = "Special version flags") final String extra) {
StringBuilder sb = new StringBuilder();

View File

@@ -148,7 +148,7 @@ public class Bootstrap {
* @return new ApplicationContext in the plugin with core spring shell's context as parent
*/
private ConfigurableApplicationContext initPluginApplicationContext(AnnotationConfigApplicationContext annctx) {
ClassPathXmlApplicationContext subContext = new ClassPathXmlApplicationContext("spring-shell-beans.xml");
ClassPathXmlApplicationContext subContext = new ClassPathXmlApplicationContext("classpath*:/META-INF/spring/spring-shell-plugin.xml");
subContext.setParent(annctx);
return subContext;
}
@@ -189,7 +189,6 @@ public class Bootstrap {
exitShellRequest = ExitShellRequest.NORMAL_EXIT;
}
} else {
//shell.promptLoop();
exitShellRequest = shell.getExitShellRequest();
if (exitShellRequest == null) {
// shouldn't really happen, but we'll fallback to this anyway

View File

@@ -10,7 +10,6 @@ import java.io.PrintStream;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
@@ -42,7 +41,7 @@ import org.springframework.roo.support.util.IOUtils;
import org.springframework.roo.support.util.OsUtils;
import org.springframework.roo.support.util.StringUtils;
import org.springframework.shell.plugin.BannerProvider;
import org.springframework.shell.plugin.HistoryFileProvider;
import org.springframework.shell.plugin.HistoryFileNameProvider;
import org.springframework.shell.plugin.PromptProvider;
@@ -59,7 +58,8 @@ import org.springframework.shell.plugin.PromptProvider;
* @author Jarred Li
* @since 1.0
*/
public abstract class JLineShell extends AbstractShell implements CommandMarker, Shell, Runnable {
public abstract class JLineShell extends AbstractShell
implements CommandMarker, Shell, Runnable {
// Constants
private static final String ANSI_CONSOLE_CLASSNAME = "org.fusesource.jansi.AnsiConsole";
@@ -528,6 +528,7 @@ public abstract class JLineShell extends AbstractShell implements CommandMarker,
this.applicatonContext = applicationContext;
}
/**
* get history file name from provider. The provider has highest order
* <link>org.springframework.core.Ordered.getOder</link> will win.
@@ -536,15 +537,14 @@ public abstract class JLineShell extends AbstractShell implements CommandMarker,
*/
private String getHistoryFileName() {
String historyFileName = null;
Map<String, HistoryFileProvider> historyFileProviders = getBeansInFactory(HistoryFileProvider.class);
Map<String, HistoryFileNameProvider> historyFileProviders = getBeansInFactory(HistoryFileNameProvider.class);
int order = Integer.MIN_VALUE;
for(HistoryFileProvider p : historyFileProviders.values()){
for(HistoryFileNameProvider p : historyFileProviders.values()){
if(p.getOrder() > order){
order = p.getOrder();
historyFileName = p.getHistoryFileName();
}
}
historyFileName = (historyFileName == null)?Constant.HISTORY_FILE_NAME:historyFileName;
return historyFileName;
}
@@ -564,7 +564,6 @@ public abstract class JLineShell extends AbstractShell implements CommandMarker,
promptText = p.getPromptText();
}
}
promptText = (promptText == null)?Constant.COMMAND_LINE_PROMPT:promptText;
return promptText;
}
@@ -585,8 +584,6 @@ public abstract class JLineShell extends AbstractShell implements CommandMarker,
bannerText[1] = p.getWelcomMessage();
}
}
bannerText[0] = (bannerText[0] == null)?Constant.COMMAND_LINE_PROMPT:bannerText[0];
bannerText[1] = (bannerText[1] == null)?Constant.WELCOME_MESSAGE:bannerText[1];
return bannerText;
}

View File

@@ -1,13 +1,9 @@
package org.springframework.shell;
import static org.springframework.roo.support.util.StringUtils.LINE_SEPARATOR;
import java.net.URL;
import java.util.Collection;
import org.springframework.context.Lifecycle;
import org.springframework.roo.shell.CliCommand;
import org.springframework.roo.shell.CliOption;
import org.springframework.roo.shell.ExecutionStrategy;
import org.springframework.roo.shell.Parser;
import org.springframework.roo.shell.SimpleParser;

View File

@@ -12,7 +12,8 @@ public class HintCommands implements CommandMarker {
// Fields
@Autowired private HintOperations hintOperations;
@CliCommand(value = "hint", help = "Provides step-by-step hints and context-sensitive guidance")
//TODO: figure out how to provide hint
//@CliCommand(value = "hint", help = "Provides step-by-step hints and context-sensitive guidance")
public String hint(
@CliOption(key = { "topic", "" }, mandatory = false, unspecifiedDefaultValue = "", optionContext = "disable-string-converter,topics", help = "The topic for which advice should be provided") final String topic) {

View File

@@ -25,7 +25,7 @@ import org.springframework.core.Ordered;
* @since 1.0
*
*/
public interface HistoryFileProvider extends Ordered{
public interface HistoryFileNameProvider extends Ordered{
/**
* get history file name

View File

@@ -43,7 +43,7 @@ public class DefaultBannerProvider implements BannerProvider, CommandMarker {
/* (non-Javadoc)
* @see org.springframework.shell.plugin.BannerProvider#getBanner()
*/
@CliCommand(value = { "shell-version" }, help = "Displays shell version")
//@CliCommand(value = { "shell-version" }, help = "Displays shell version")
public String getBanner() {
StringBuilder sb = new StringBuilder();
sb.append(" _____ _ ").append(LINE_SEPARATOR);

View File

@@ -16,7 +16,7 @@
package org.springframework.shell.plugin.support;
import org.springframework.shell.Constant;
import org.springframework.shell.plugin.HistoryFileProvider;
import org.springframework.shell.plugin.HistoryFileNameProvider;
import org.springframework.stereotype.Component;
/**
@@ -26,7 +26,7 @@ import org.springframework.stereotype.Component;
*
*/
@Component
public class DefaultHistoryFileProvider implements HistoryFileProvider{
public class DefaultHistoryFileNameProvider implements HistoryFileNameProvider{
/* (non-Javadoc)
* @see org.springframework.core.Ordered#getOrder()

View File

@@ -20,7 +20,7 @@ import static org.junit.Assert.*;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.shell.Constant;
import org.springframework.shell.plugin.HistoryFileProvider;
import org.springframework.shell.plugin.HistoryFileNameProvider;
/**
* @author Jarred Li
@@ -28,10 +28,10 @@ import org.springframework.shell.plugin.HistoryFileProvider;
*/
public class DefaultHistoryFileProviderTest {
private HistoryFileProvider historyFile = new DefaultHistoryFileProvider();
private HistoryFileNameProvider historyFile = new DefaultHistoryFileNameProvider();
/**
* Test method for {@link org.springframework.shell.plugin.support.DefaultHistoryFileProvider#getOrder()}.
* Test method for {@link org.springframework.shell.plugin.support.DefaultHistoryFileNameProvider#getOrder()}.
*/
@Test
public void testGetOrder() {
@@ -39,7 +39,7 @@ public class DefaultHistoryFileProviderTest {
}
/**
* Test method for {@link org.springframework.shell.plugin.support.DefaultHistoryFileProvider#getHistoryFileName()}.
* Test method for {@link org.springframework.shell.plugin.support.DefaultHistoryFileNameProvider#getHistoryFileName()}.
*/
@Test
public void testGetHistoryFileName() {