code cleanup
remove non-Javadoc eliminate useless constants interface add some javadocs
This commit is contained in:
@@ -28,7 +28,7 @@ public class VersionUtils {
|
||||
* or <code>null</code> if it cannot be determined.
|
||||
* @see java.lang.Package#getImplementationVersion()
|
||||
*/
|
||||
public static String getVersion() {
|
||||
public static String versionInfo() {
|
||||
Package pkg = SpringVersion.class.getPackage();
|
||||
return (pkg != null ? pkg.getImplementationVersion() : "Unknown Version");
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.shell;
|
||||
|
||||
/**
|
||||
* @author Jarred Li
|
||||
*
|
||||
*/
|
||||
public interface Constant {
|
||||
|
||||
String HISTORY_FILE_NAME = "spring-shell.log";
|
||||
|
||||
String COMMAND_LINE_PROMPT = "spring>";
|
||||
|
||||
String PRODUCT_NAME = "Spring Shell";
|
||||
|
||||
String WELCOME_MESSAGE = "Welcome to " + PRODUCT_NAME + ". For assistance press or type \"hint\" then hit ENTER.";
|
||||
}
|
||||
@@ -146,7 +146,7 @@ public class JLineShellComponent extends JLineShell implements Lifecycle {
|
||||
* @return prompt text
|
||||
*/
|
||||
protected String getPromptText() {
|
||||
String providerPromptText = getHighestPriorityProvider(PromptProvider.class).getPromptText();
|
||||
String providerPromptText = getHighestPriorityProvider(PromptProvider.class).getPrompt();
|
||||
if (providerPromptText != null) {
|
||||
return providerPromptText;
|
||||
} else {
|
||||
|
||||
@@ -31,11 +31,7 @@ public class HelpCommands implements CommandMarker, ApplicationContextAware {
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
|
||||
*/
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.ctx = applicationContext;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,19 +17,34 @@ package org.springframework.shell.plugin;
|
||||
|
||||
|
||||
/**
|
||||
* Banner provider. Plugin should implements this interface to replace the version banner.
|
||||
* Banner provider. Plugin should implement this interface to replace the version banner.
|
||||
* <code>getOrder</code> indicate the priority, higher values can be interpreted as lower priority
|
||||
*
|
||||
* @author Jarred Li
|
||||
* @since 1.0
|
||||
*
|
||||
*/
|
||||
public interface BannerProvider extends PluginProvider{
|
||||
public interface BannerProvider extends PluginProvider {
|
||||
|
||||
/**
|
||||
* Returns the banner.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getBanner();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the associated version.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getVersion();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the welcome message.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getWelcomeMessage();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -17,14 +17,15 @@ package org.springframework.shell.plugin;
|
||||
|
||||
|
||||
/**
|
||||
* History file name provider. Plugin should implements this interface to customize history file.
|
||||
* History file name provider.
|
||||
* Plugin should implement this interface to customize history file.
|
||||
* <code>getOrder</code> indicate the priority, higher values can be interpreted as lower priority
|
||||
*
|
||||
* @author Jarred Li
|
||||
* @since 1.0
|
||||
*
|
||||
*/
|
||||
public interface HistoryFileNameProvider extends PluginProvider{
|
||||
public interface HistoryFileNameProvider extends PluginProvider {
|
||||
|
||||
/**
|
||||
* get history file name
|
||||
@@ -32,5 +33,5 @@ public interface HistoryFileNameProvider extends PluginProvider{
|
||||
* @return history file name
|
||||
*/
|
||||
String getHistoryFileName();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -16,11 +16,16 @@
|
||||
package org.springframework.shell.plugin;
|
||||
|
||||
/**
|
||||
* Generic plugin provider.
|
||||
*
|
||||
* @author Jarred Li
|
||||
*
|
||||
*/
|
||||
public interface PluginProvider {
|
||||
|
||||
/**
|
||||
* Returns the name of the plugin.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String name();
|
||||
|
||||
}
|
||||
|
||||
@@ -17,14 +17,19 @@ package org.springframework.shell.plugin;
|
||||
|
||||
|
||||
/**
|
||||
* Shell prompt provider. Plugin should implements this interface to customize prompt.
|
||||
* Shell prompt provider.
|
||||
* Plugins should implement this interface to customize prompt.
|
||||
* <code>getOrder</code> indicate the priority, higher values can be interpreted as lower priority
|
||||
*
|
||||
* @author Jarred Li
|
||||
*
|
||||
*/
|
||||
public interface PromptProvider extends PluginProvider{
|
||||
public interface PromptProvider extends PluginProvider {
|
||||
|
||||
String getPromptText();
|
||||
|
||||
/**
|
||||
* Returns the prompt text.
|
||||
*
|
||||
* @return prompt
|
||||
*/
|
||||
String getPrompt();
|
||||
}
|
||||
|
||||
@@ -15,16 +15,15 @@
|
||||
*/
|
||||
package org.springframework.shell.plugin.support;
|
||||
|
||||
import static org.springframework.roo.support.util.StringUtils.LINE_SEPARATOR;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
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;
|
||||
|
||||
import static org.springframework.roo.support.util.StringUtils.*;
|
||||
|
||||
/**
|
||||
* Default Banner provider.
|
||||
*
|
||||
@@ -35,16 +34,10 @@ import org.springframework.stereotype.Component;
|
||||
@Order(Ordered.LOWEST_PRECEDENCE)
|
||||
public class DefaultBannerProvider implements BannerProvider, CommandMarker {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.core.Ordered#getOrder()
|
||||
*/
|
||||
public int getOrder() {
|
||||
return Ordered.LOWEST_PRECEDENCE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.shell.plugin.BannerProvider#getBanner()
|
||||
*/
|
||||
//@CliCommand(value = { "shell-version" }, help = "Displays shell version")
|
||||
public String getBanner() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@@ -61,26 +54,16 @@ public class DefaultBannerProvider implements BannerProvider, CommandMarker {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.shell.plugin.BannerProvider#getVersion()
|
||||
*/
|
||||
|
||||
public String getVersion() {
|
||||
return VersionUtils.versionInfo();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.shell.plugin.BannerProvider#getWelcomeMessage()
|
||||
*/
|
||||
public String getWelcomeMessage() {
|
||||
return Constant.WELCOME_MESSAGE;
|
||||
return "Welcome to " + name() + ". For assistance press or type \"hint\" then hit ENTER.";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.shell.plugin.PluginProvider#name()
|
||||
*/
|
||||
@Override
|
||||
public String name() {
|
||||
return Constant.PRODUCT_NAME;
|
||||
return "Spring Shell";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@ package org.springframework.shell.plugin.support;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.shell.Constant;
|
||||
import org.springframework.shell.plugin.HistoryFileNameProvider;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -29,28 +28,17 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component
|
||||
@Order(Ordered.LOWEST_PRECEDENCE)
|
||||
public class DefaultHistoryFileNameProvider implements HistoryFileNameProvider{
|
||||
public class DefaultHistoryFileNameProvider implements HistoryFileNameProvider {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.core.Ordered#getOrder()
|
||||
*/
|
||||
public int getOrder() {
|
||||
return Ordered.LOWEST_PRECEDENCE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.shell.plugin.HistoryFileProvider#getHistoryFileName()
|
||||
*/
|
||||
public String getHistoryFileName() {
|
||||
return Constant.HISTORY_FILE_NAME;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.shell.plugin.PluginProvider#name()
|
||||
*/
|
||||
@Override
|
||||
public String name() {
|
||||
return "default banner provider";
|
||||
return "spring-shell.log";
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return "default history provider";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ package org.springframework.shell.plugin.support;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.shell.Constant;
|
||||
import org.springframework.shell.plugin.PromptProvider;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -29,28 +28,17 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component
|
||||
@Order(Ordered.LOWEST_PRECEDENCE)
|
||||
public class DefaultPromptProvider implements PromptProvider{
|
||||
public class DefaultPromptProvider implements PromptProvider {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.core.Ordered#getOrder()
|
||||
*/
|
||||
public int getOrder() {
|
||||
return Ordered.LOWEST_PRECEDENCE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.shell.plugin.PromptProvider#getPromptText()
|
||||
*/
|
||||
public String getPromptText() {
|
||||
return Constant.COMMAND_LINE_PROMPT;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.shell.plugin.PluginProvider#name()
|
||||
*/
|
||||
@Override
|
||||
public String name() {
|
||||
return "default banner provider";
|
||||
public String getPrompt() {
|
||||
return "spring-shell>";
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return "default prompt provider";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,11 @@
|
||||
*/
|
||||
package org.springframework.shell.plugin.support;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.shell.Constant;
|
||||
import org.springframework.shell.plugin.HistoryFileNameProvider;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Jarred Li
|
||||
*
|
||||
@@ -36,7 +34,7 @@ public class DefaultHistoryFileProviderTest {
|
||||
@Test
|
||||
public void testGetHistoryFileName() {
|
||||
assertNotNull(historyFile.getHistoryFileName());
|
||||
assertEquals(Constant.HISTORY_FILE_NAME, historyFile.getHistoryFileName());
|
||||
assertEquals("spring-shell.log", historyFile.getHistoryFileName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,14 +15,13 @@
|
||||
*/
|
||||
package org.springframework.shell.plugin.support;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.shell.Constant;
|
||||
import org.springframework.shell.plugin.PromptProvider;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Jarred Li
|
||||
*
|
||||
@@ -49,11 +48,10 @@ public class DefaultPromptProviderTest {
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.shell.plugin.support.DefaultPromptProvider#getPromptText()}.
|
||||
* Test method for {@link org.springframework.shell.plugin.support.DefaultPromptProvider#getPrompt()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetPromptText() {
|
||||
assertEquals(Constant.COMMAND_LINE_PROMPT, prompt.getPromptText());
|
||||
assertEquals("spring-shell>", prompt.getPrompt());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user