plugins customizing is intialized once at start
This commit is contained in:
@@ -78,8 +78,6 @@ public class Bootstrap {
|
|||||||
//System.out.println("Registering converter " + converter);
|
//System.out.println("Registering converter " + converter);
|
||||||
shell.getSimpleParser().add(converter);
|
shell.getSimpleParser().add(converter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
shell.start();
|
shell.start();
|
||||||
|
|
||||||
//TODO use listener and latch..
|
//TODO use listener and latch..
|
||||||
@@ -125,6 +123,7 @@ public class Bootstrap {
|
|||||||
annctx.refresh();
|
annctx.refresh();
|
||||||
|
|
||||||
ctx = initPluginApplicationContext(annctx);
|
ctx = initPluginApplicationContext(annctx);
|
||||||
|
|
||||||
ctx.refresh();
|
ctx.refresh();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,10 @@ public abstract class JLineShell extends AbstractShell
|
|||||||
|
|
||||||
private ApplicationContext applicatonContext;
|
private ApplicationContext applicatonContext;
|
||||||
private boolean printBanner = true;
|
private boolean printBanner = true;
|
||||||
|
private String historyFileName;
|
||||||
|
private String promptText;
|
||||||
|
private String version;
|
||||||
|
private String welcomeMessage;
|
||||||
|
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -122,7 +126,7 @@ public abstract class JLineShell extends AbstractShell
|
|||||||
|
|
||||||
// Try to build previous command history from the project's log
|
// Try to build previous command history from the project's log
|
||||||
try {
|
try {
|
||||||
String logFileContents = FileCopyUtils.copyToString(new File(getHistoryFileName()));
|
String logFileContents = FileCopyUtils.copyToString(new File(this.historyFileName));
|
||||||
String[] logEntries = logFileContents.split(StringUtils.LINE_SEPARATOR);
|
String[] logEntries = logFileContents.split(StringUtils.LINE_SEPARATOR);
|
||||||
// LIFO
|
// LIFO
|
||||||
for (String logEntry : logEntries) {
|
for (String logEntry : logEntries) {
|
||||||
@@ -174,7 +178,7 @@ public abstract class JLineShell extends AbstractShell
|
|||||||
|
|
||||||
public void printBannerAndWelcome(){
|
public void printBannerAndWelcome(){
|
||||||
if(printBanner){
|
if(printBanner){
|
||||||
logger.info(version(null));
|
logger.info(this.version);
|
||||||
logger.info(getWelcomeMessage());
|
logger.info(getWelcomeMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -202,7 +206,7 @@ public abstract class JLineShell extends AbstractShell
|
|||||||
if (reader.getTerminal().isANSISupported()) {
|
if (reader.getTerminal().isANSISupported()) {
|
||||||
ANSIBuffer ansi = JLineLogHandler.getANSIBuffer();
|
ANSIBuffer ansi = JLineLogHandler.getANSIBuffer();
|
||||||
if (path == null || "".equals(path)) {
|
if (path == null || "".equals(path)) {
|
||||||
shellPrompt = ansi.yellow(getPromptText()).toString();
|
shellPrompt = ansi.yellow(this.promptText).toString();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (overrideStyle) {
|
if (overrideStyle) {
|
||||||
@@ -211,7 +215,7 @@ public abstract class JLineShell extends AbstractShell
|
|||||||
else {
|
else {
|
||||||
ansi.cyan(path);
|
ansi.cyan(path);
|
||||||
}
|
}
|
||||||
shellPrompt = ansi.yellow(" " + getPromptText()).toString();
|
shellPrompt = ansi.yellow(" " + this.promptText).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -456,7 +460,7 @@ public abstract class JLineShell extends AbstractShell
|
|||||||
|
|
||||||
private void openFileLogIfPossible() {
|
private void openFileLogIfPossible() {
|
||||||
try {
|
try {
|
||||||
fileLog = new FileWriter(getHistoryFileName(), true);
|
fileLog = new FileWriter(this.historyFileName, true);
|
||||||
// First write, so let's record the date and time of the first user command
|
// First write, so let's record the date and time of the first user command
|
||||||
fileLog.write("// Spring Roo " + versionInfo() + " log opened at " + df.format(new Date()) + "\n");
|
fileLog.write("// Spring Roo " + versionInfo() + " log opened at " + df.format(new Date()) + "\n");
|
||||||
fileLog.flush();
|
fileLog.flush();
|
||||||
@@ -528,6 +532,12 @@ public abstract class JLineShell extends AbstractShell
|
|||||||
this.applicatonContext = applicationContext;
|
this.applicatonContext = applicationContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void costomizePlugin(){
|
||||||
|
this.historyFileName = getHistoryFileName();
|
||||||
|
this.promptText = getPromptText();
|
||||||
|
this.version = getBannerText()[0];
|
||||||
|
this.welcomeMessage = getBannerText()[1];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get history file name from provider. The provider has highest order
|
* get history file name from provider. The provider has highest order
|
||||||
@@ -538,9 +548,9 @@ public abstract class JLineShell extends AbstractShell
|
|||||||
private String getHistoryFileName() {
|
private String getHistoryFileName() {
|
||||||
String historyFileName = null;
|
String historyFileName = null;
|
||||||
Map<String, HistoryFileNameProvider> historyFileProviders = getBeansInFactory(HistoryFileNameProvider.class);
|
Map<String, HistoryFileNameProvider> historyFileProviders = getBeansInFactory(HistoryFileNameProvider.class);
|
||||||
int order = Integer.MIN_VALUE;
|
int order = Integer.MAX_VALUE;
|
||||||
for(HistoryFileNameProvider p : historyFileProviders.values()){
|
for(HistoryFileNameProvider p : historyFileProviders.values()){
|
||||||
if(p.getOrder() > order){
|
if(p.getOrder() < order){
|
||||||
order = p.getOrder();
|
order = p.getOrder();
|
||||||
historyFileName = p.getHistoryFileName();
|
historyFileName = p.getHistoryFileName();
|
||||||
}
|
}
|
||||||
@@ -557,9 +567,9 @@ public abstract class JLineShell extends AbstractShell
|
|||||||
private String getPromptText(){
|
private String getPromptText(){
|
||||||
String promptText = null;
|
String promptText = null;
|
||||||
Map<String, PromptProvider> promptProviders = getBeansInFactory(PromptProvider.class);
|
Map<String, PromptProvider> promptProviders = getBeansInFactory(PromptProvider.class);
|
||||||
int order = Integer.MIN_VALUE;
|
int order = Integer.MAX_VALUE;
|
||||||
for(PromptProvider p : promptProviders.values()){
|
for(PromptProvider p : promptProviders.values()){
|
||||||
if(p.getOrder() > order){
|
if(p.getOrder() < order){
|
||||||
order = p.getOrder();
|
order = p.getOrder();
|
||||||
promptText = p.getPromptText();
|
promptText = p.getPromptText();
|
||||||
}
|
}
|
||||||
@@ -576,9 +586,9 @@ public abstract class JLineShell extends AbstractShell
|
|||||||
private String[] getBannerText(){
|
private String[] getBannerText(){
|
||||||
String[] bannerText = new String[2];
|
String[] bannerText = new String[2];
|
||||||
Map<String, BannerProvider> bannerProviders = getBeansInFactory(BannerProvider.class);
|
Map<String, BannerProvider> bannerProviders = getBeansInFactory(BannerProvider.class);
|
||||||
int order = Integer.MIN_VALUE;
|
int order = Integer.MAX_VALUE;
|
||||||
for(BannerProvider p : bannerProviders.values()){
|
for(BannerProvider p : bannerProviders.values()){
|
||||||
if(p.getOrder() > order){
|
if(p.getOrder() < order){
|
||||||
order = p.getOrder();
|
order = p.getOrder();
|
||||||
bannerText[0] = p.getBanner();
|
bannerText[0] = p.getBanner();
|
||||||
bannerText[1] = p.getWelcomMessage();
|
bannerText[1] = p.getWelcomMessage();
|
||||||
@@ -594,12 +604,13 @@ public abstract class JLineShell extends AbstractShell
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String version(String text){
|
public String version(String text){
|
||||||
return getBannerText()[0];
|
return this.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWelcomeMessage(){
|
public String getWelcomeMessage(){
|
||||||
return getBannerText()[1];
|
return this.welcomeMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ public class JLineShellComponent extends JLineShell implements Lifecycle {
|
|||||||
|
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
|
//customizePlug must run before start thread to take plugin's configuration into effect
|
||||||
|
super.costomizePlugin();
|
||||||
shellThread = new Thread(this, "Spring Shell");
|
shellThread = new Thread(this, "Spring Shell");
|
||||||
shellThread.start();
|
shellThread.start();
|
||||||
running = true;
|
running = true;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import org.springframework.core.Ordered;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Banner provider. Plugin should implements this interface to replace the version banner.
|
* Banner provider. Plugin should implements this interface to replace the version banner.
|
||||||
* <code>getOrder</code> should be > 1 to override default.
|
* <code>getOrder</code> indicate the priority, higher values can be interpreted as lower priority
|
||||||
*
|
*
|
||||||
* @author Jarred Li
|
* @author Jarred Li
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import org.springframework.core.Ordered;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* History file name provider. Plugin should implements this interface to customize history file.
|
* History file name provider. Plugin should implements this interface to customize history file.
|
||||||
* <code>getOrder</code> should be > 1 to override default.
|
* <code>getOrder</code> indicate the priority, higher values can be interpreted as lower priority
|
||||||
*
|
*
|
||||||
* @author Jarred Li
|
* @author Jarred Li
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ import org.springframework.core.Ordered;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Shell prompt provider. Plugin should implements this interface to customize prompt.
|
* Shell prompt provider. Plugin should implements this interface to customize prompt.
|
||||||
*
|
* <code>getOrder</code> indicate the priority, higher values can be interpreted as lower priority
|
||||||
* <code>getOrder</code> should be > 1 to override default.
|
|
||||||
*
|
*
|
||||||
* @author Jarred Li
|
* @author Jarred Li
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ package org.springframework.shell.plugin.support;
|
|||||||
|
|
||||||
import static org.springframework.roo.support.util.StringUtils.LINE_SEPARATOR;
|
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.shell.CommandMarker;
|
||||||
import org.springframework.roo.support.util.VersionUtils;
|
import org.springframework.roo.support.util.VersionUtils;
|
||||||
import org.springframework.shell.Constant;
|
import org.springframework.shell.Constant;
|
||||||
@@ -37,7 +36,7 @@ public class DefaultBannerProvider implements BannerProvider, CommandMarker {
|
|||||||
* @see org.springframework.core.Ordered#getOrder()
|
* @see org.springframework.core.Ordered#getOrder()
|
||||||
*/
|
*/
|
||||||
public int getOrder() {
|
public int getOrder() {
|
||||||
return 0;
|
return Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class DefaultHistoryFileNameProvider implements HistoryFileNameProvider{
|
|||||||
* @see org.springframework.core.Ordered#getOrder()
|
* @see org.springframework.core.Ordered#getOrder()
|
||||||
*/
|
*/
|
||||||
public int getOrder() {
|
public int getOrder() {
|
||||||
return 0;
|
return Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class DefaultPromptProvider implements PromptProvider{
|
|||||||
* @see org.springframework.core.Ordered#getOrder()
|
* @see org.springframework.core.Ordered#getOrder()
|
||||||
*/
|
*/
|
||||||
public int getOrder() {
|
public int getOrder() {
|
||||||
return 0;
|
return Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|||||||
Reference in New Issue
Block a user