SHL-17 customize welcome message
This commit is contained in:
@@ -17,6 +17,7 @@ package org.springframework.shell.samples.helloworld.commands;
|
||||
|
||||
import org.springframework.roo.shell.CliCommand;
|
||||
import org.springframework.roo.shell.CommandMarker;
|
||||
import org.springframework.roo.support.util.StringUtils;
|
||||
import org.springframework.shell.plugin.BannerProvider;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -37,9 +38,19 @@ public class MyBannerProvider implements BannerProvider, CommandMarker {
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.shell.plugin.BannerProvider#getBanner()
|
||||
*/
|
||||
@CliCommand(value = { "version" }, help = "Displays shell version")
|
||||
@CliCommand(value = { "version" }, help = "Displays current CLI version")
|
||||
public String getBanner() {
|
||||
return "vHelper. Version: " + this.getVersion();
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("=======================================" + StringUtils.LINE_SEPARATOR);
|
||||
buf.append("* *"+ StringUtils.LINE_SEPARATOR);
|
||||
buf.append("* *"+ StringUtils.LINE_SEPARATOR);
|
||||
buf.append("* vHelper *" +StringUtils.LINE_SEPARATOR);
|
||||
buf.append("* *"+ StringUtils.LINE_SEPARATOR);
|
||||
buf.append("* *"+ StringUtils.LINE_SEPARATOR);
|
||||
buf.append("=======================================" + StringUtils.LINE_SEPARATOR);
|
||||
buf.append("Verson:" + this.getVersion());
|
||||
return buf.toString();
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -49,4 +60,11 @@ public class MyBannerProvider implements BannerProvider, CommandMarker {
|
||||
return "1.0.1";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.shell.plugin.BannerProvider#getWelcomMessage()
|
||||
*/
|
||||
public String getWelcomMessage() {
|
||||
return "Welcome to vHelper CLI";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,10 +35,11 @@ public class Bootstrap {
|
||||
private Thread shellThread;
|
||||
private ConfigurableApplicationContext ctx;
|
||||
private static StopWatch sw = new StopWatch("Spring Sehll");
|
||||
private static SimpleShellCommandLineOptions options;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
sw.start();
|
||||
SimpleShellCommandLineOptions options = SimpleShellCommandLineOptions.parseCommandLine(args);
|
||||
options = SimpleShellCommandLineOptions.parseCommandLine(args);
|
||||
|
||||
for (Map.Entry<String, String> entry : options.extraSystemProperties.entrySet()) {
|
||||
System.setProperty(entry.getKey(), entry.getValue());
|
||||
@@ -68,6 +69,9 @@ public class Bootstrap {
|
||||
//shell = new JLineShellComponent();
|
||||
shell = ctx.getBean("shell", JLineShellComponent.class);
|
||||
shell.setApplicationContext(ctx);
|
||||
if(options.executeThenQuit != null){
|
||||
shell.setPrintBanner(false);
|
||||
}
|
||||
|
||||
Map<String, CommandMarker> commands = BeanFactoryUtils.beansOfTypeIncludingAncestors(ctx,CommandMarker.class);
|
||||
|
||||
@@ -191,14 +195,15 @@ public class Bootstrap {
|
||||
// shouldn't really happen, but we'll fallback to this anyway
|
||||
exitShellRequest = ExitShellRequest.NORMAL_EXIT;
|
||||
}
|
||||
|
||||
try {
|
||||
shellThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
shellThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
ctx.close();
|
||||
sw.stop();
|
||||
if (shell.isDevelopmentMode()) {
|
||||
|
||||
@@ -25,4 +25,6 @@ public interface Constant {
|
||||
|
||||
String COMMAND_LINE_PROMPT = "spring>";
|
||||
|
||||
String WELCOME_MESSAGE = "Welcome to Spring Shell. For assistance press or type \"hint\" then hit ENTER.";
|
||||
|
||||
}
|
||||
|
||||
@@ -81,6 +81,8 @@ public abstract class JLineShell extends AbstractShell implements CommandMarker,
|
||||
private boolean shutdownHookFired = false; // ROO-1599
|
||||
|
||||
private ApplicationContext applicatonContext;
|
||||
private boolean printBanner = true;
|
||||
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
@@ -132,15 +134,8 @@ public abstract class JLineShell extends AbstractShell implements CommandMarker,
|
||||
}
|
||||
|
||||
flashMessageRenderer();
|
||||
|
||||
logger.info(version(null));
|
||||
|
||||
flash(Level.FINE, "Spring Roo " + versionInfo(), Shell.WINDOW_TITLE_SLOT);
|
||||
|
||||
|
||||
//TODO make this configurable
|
||||
logger.info("Welcome to Spring Shell. For assistance press " + completionKeys
|
||||
+ " or type \"hint\" then hit ENTER.");
|
||||
flash(Level.FINE, "Spring Shell " + versionInfo(), Shell.WINDOW_TITLE_SLOT);
|
||||
printBannerAndWelcome();
|
||||
|
||||
String startupNotifications = getStartupNotifications();
|
||||
if (StringUtils.hasText(startupNotifications)) {
|
||||
@@ -176,6 +171,13 @@ public abstract class JLineShell extends AbstractShell implements CommandMarker,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void printBannerAndWelcome(){
|
||||
if(printBanner){
|
||||
logger.info(version(null));
|
||||
logger.info(getWelcomeMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public String getStartupNotifications() {
|
||||
return null;
|
||||
@@ -526,6 +528,12 @@ 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.
|
||||
*
|
||||
* @return history file name
|
||||
*/
|
||||
private String getHistoryFileName() {
|
||||
String historyFileName = null;
|
||||
Map<String, HistoryFileProvider> historyFileProviders = getBeansInFactory(HistoryFileProvider.class);
|
||||
@@ -540,6 +548,12 @@ public abstract class JLineShell extends AbstractShell implements CommandMarker,
|
||||
return historyFileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* get prompt text from provider. The provider has highest order
|
||||
* <link>org.springframework.core.Ordered.getOder</link> will win.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String getPromptText(){
|
||||
String promptText = null;
|
||||
Map<String, PromptProvider> promptProviders = getBeansInFactory(PromptProvider.class);
|
||||
@@ -554,17 +568,25 @@ public abstract class JLineShell extends AbstractShell implements CommandMarker,
|
||||
return promptText;
|
||||
}
|
||||
|
||||
private String getBannerText(){
|
||||
String bannerText = null;
|
||||
/**
|
||||
* Get Banner and Welcome Message from provider. The provider has highest order
|
||||
* <link>org.springframework.core.Ordered.getOder</link> will win.
|
||||
* @return BannerText[0]: Banner
|
||||
* BannerText[1]: Welcome Message.
|
||||
*/
|
||||
private String[] getBannerText(){
|
||||
String[] bannerText = new String[2];
|
||||
Map<String, BannerProvider> bannerProviders = getBeansInFactory(BannerProvider.class);
|
||||
int order = Integer.MIN_VALUE;
|
||||
for(BannerProvider p : bannerProviders.values()){
|
||||
if(p.getOrder() > order){
|
||||
order = p.getOrder();
|
||||
bannerText = p.getBanner();
|
||||
bannerText[0] = p.getBanner();
|
||||
bannerText[1] = p.getWelcomMessage();
|
||||
}
|
||||
}
|
||||
bannerText = (bannerText == null)?Constant.COMMAND_LINE_PROMPT:bannerText;
|
||||
bannerText[0] = (bannerText[0] == null)?Constant.COMMAND_LINE_PROMPT:bannerText[0];
|
||||
bannerText[1] = (bannerText[1] == null)?Constant.WELCOME_MESSAGE:bannerText[1];
|
||||
return bannerText;
|
||||
}
|
||||
|
||||
@@ -576,7 +598,19 @@ public abstract class JLineShell extends AbstractShell implements CommandMarker,
|
||||
}
|
||||
|
||||
public String version(String text){
|
||||
return getBannerText();
|
||||
return getBannerText()[0];
|
||||
}
|
||||
|
||||
public String getWelcomeMessage(){
|
||||
return getBannerText()[1];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param printBanner the printBanner to set
|
||||
*/
|
||||
public void setPrintBanner(boolean printBanner) {
|
||||
this.printBanner = printBanner;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.core.Ordered;
|
||||
* <code>getOrder</code> should be > 1 to override default.
|
||||
*
|
||||
* @author Jarred Li
|
||||
* @since 1.01
|
||||
* @since 1.0
|
||||
*
|
||||
*/
|
||||
public interface BannerProvider extends Ordered {
|
||||
@@ -31,4 +31,6 @@ public interface BannerProvider extends Ordered {
|
||||
|
||||
String getVersion();
|
||||
|
||||
String getWelcomMessage();
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.springframework.roo.support.util.StringUtils.LINE_SEPARATOR;
|
||||
import org.springframework.roo.shell.CliCommand;
|
||||
import org.springframework.roo.shell.CommandMarker;
|
||||
import org.springframework.roo.support.util.VersionUtils;
|
||||
import org.springframework.shell.Constant;
|
||||
import org.springframework.shell.plugin.BannerProvider;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -30,7 +31,7 @@ import org.springframework.stereotype.Component;
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class DefaultBannerProvider implements BannerProvider, CommandMarker{
|
||||
public class DefaultBannerProvider implements BannerProvider, CommandMarker {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.core.Ordered#getOrder()
|
||||
@@ -65,4 +66,11 @@ public class DefaultBannerProvider implements BannerProvider, CommandMarker{
|
||||
return VersionUtils.versionInfo();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.shell.plugin.BannerProvider#getWelcomMessage()
|
||||
*/
|
||||
public String getWelcomMessage() {
|
||||
return Constant.WELCOME_MESSAGE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user