diff --git a/samples/helloworld/build.gradle b/samples/helloworld/build.gradle index f96c117b..52b7e949 100644 --- a/samples/helloworld/build.gradle +++ b/samples/helloworld/build.gradle @@ -17,22 +17,6 @@ dependencies { testCompile "junit:junit:$junitVersion" } -task copyDependency(type: Copy) { - into "$buildDir/libs/dependency" - from configurations.runtime -} - -project.ext.springShellJar = configurations.runtime.find { file -> file.name.contains("spring-shell")} -//println("spring shell name is:" + project.ext.springShellJar.name) - -project.ext.manifestClasspath = "dependency/" + springShellJar.name + " " -project.ext.manifestClasspath = project.ext.manifestClasspath + configurations.runtime.collect{ File file -> "dependency/"+file.name}.join(' ') - -jar { - baseName "helloworld" - manifest { - attributes 'Main-Class' : 'org.springframework.shell.Bootstrap', "Class-Path" : project.ext.manifestClasspath - } -} +mainClassName = "org.springframework.shell.Bootstrap" defaultTasks 'clean', 'build', 'copyDependency' diff --git a/samples/helloworld/src/main/java/org/springframework/shell/samples/helloworld/commands/HelloWorldCommands.java b/samples/helloworld/src/main/java/org/springframework/shell/samples/helloworld/commands/HelloWorldCommands.java index 58afa10f..8f1babcd 100644 --- a/samples/helloworld/src/main/java/org/springframework/shell/samples/helloworld/commands/HelloWorldCommands.java +++ b/samples/helloworld/src/main/java/org/springframework/shell/samples/helloworld/commands/HelloWorldCommands.java @@ -1,6 +1,8 @@ package org.springframework.shell.samples.helloworld.commands; +import java.util.logging.Logger; + import org.springframework.shell.core.CommandMarker; import org.springframework.shell.core.annotation.CliAvailabilityIndicator; import org.springframework.shell.core.annotation.CliCommand; @@ -11,26 +13,27 @@ import org.springframework.stereotype.Component; public class HelloWorldCommands implements CommandMarker { + protected final Logger LOG = Logger.getLogger(getClass().getName()); + @CliAvailabilityIndicator({"hw echo"}) public boolean isCommandAvailable() { return true; } - @CliCommand(value = "hw echo", help = "Print a hello world message") + @CliCommand(value = "hw complex", help = "Print a complex hello world message") public void hello( @CliOption(key = { "message" }, mandatory = true, help = "The hello world message") final String message, - @CliOption(key = { "name1"}, mandatory = true, help = "The hello world name1 ") final String name1, - @CliOption(key = { "name2","name22" }, mandatory = true, help = "The hello world name2 ") final String name2, - @CliOption(key = { "time" }, mandatory = false, specifiedDefaultValue="now", help = "The hello world time ") final String time, - @CliOption(key = { "location" }, mandatory = false, help = "The hello world location ") final String location) { - System.out.println("Hello world " + message + ", name1: " + name1 + - ", name2:" + name2 + ". time:" + time + ".location: " + location); + @CliOption(key = { "name1"}, mandatory = true, help = "Say hello to the first name") final String name1, + @CliOption(key = { "name2" }, mandatory = true, help = "Say hello to a second name") final String name2, + @CliOption(key = { "time" }, mandatory = false, specifiedDefaultValue="now", help = "When you are saying hello") final String time, + @CliOption(key = { "location" }, mandatory = false, help = "Where you are saying hello") final String location) { + LOG.info("Hello " + name1 + " and " + name2 + ". Your special message is " + message + ". time=[" + time + "] location=[" + location + "]"); } - @CliCommand(value = "hw auto", help = "Print a hello world message") - public void autao( + @CliCommand(value = "hw enum", help = "Print a simple hello world message from an enumerated value") + public void eenum( @CliOption(key = { "message" }, mandatory = true, help = "The hello world message") final MessageType message){ - System.out.println("Hello world " + message); + LOG.info("Hello. You special enumerated message is " + message); } enum MessageType { diff --git a/samples/helloworld/src/main/java/org/springframework/shell/samples/helloworld/commands/MyBannerProvider.java b/samples/helloworld/src/main/java/org/springframework/shell/samples/helloworld/commands/MyBannerProvider.java index 744fd55c..8d0045c4 100644 --- a/samples/helloworld/src/main/java/org/springframework/shell/samples/helloworld/commands/MyBannerProvider.java +++ b/samples/helloworld/src/main/java/org/springframework/shell/samples/helloworld/commands/MyBannerProvider.java @@ -39,11 +39,9 @@ public class MyBannerProvider extends DefaultBannerProvider public String getBanner() { 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("* HelloWorld *" +StringUtils.LINE_SEPARATOR); + buf.append("* *"+ StringUtils.LINE_SEPARATOR); buf.append("=======================================" + StringUtils.LINE_SEPARATOR); buf.append("Verson:" + this.getVersion()); return buf.toString(); @@ -61,12 +59,12 @@ public class MyBannerProvider extends DefaultBannerProvider * @see org.springframework.shell.plugin.BannerProvider#getWelcomeMessage() */ public String getWelcomeMessage() { - return "Welcome to vHelper CLI"; + return "Welcome to HelloWorld CLI"; } @Override public String name() { - return "vHelper"; + return "helloworld"; } diff --git a/samples/helloworld/src/main/java/org/springframework/shell/samples/helloworld/commands/MyPromptProvider.java b/samples/helloworld/src/main/java/org/springframework/shell/samples/helloworld/commands/MyPromptProvider.java index 9a90f44c..469da31c 100644 --- a/samples/helloworld/src/main/java/org/springframework/shell/samples/helloworld/commands/MyPromptProvider.java +++ b/samples/helloworld/src/main/java/org/springframework/shell/samples/helloworld/commands/MyPromptProvider.java @@ -28,12 +28,11 @@ import org.springframework.stereotype.Component; @Order(Ordered.HIGHEST_PRECEDENCE) public class MyPromptProvider extends DefaultPromptProvider { - /* (non-Javadoc) - * @see org.springframework.shell.plugin.PromptProvider#getPromptText() - */ - public String getPromptText() { - return "vHelper>"; + @Override + public String getPrompt() { + return "hw-shell>"; } + @Override public String name() {