diff --git a/src/main/java/org/springframework/shell/Bootstrap.java b/src/main/java/org/springframework/shell/Bootstrap.java index 2bdd6e54..388973d1 100644 --- a/src/main/java/org/springframework/shell/Bootstrap.java +++ b/src/main/java/org/springframework/shell/Bootstrap.java @@ -86,7 +86,7 @@ public class Bootstrap { configureApplicationContext(ctx); //built-in commands and converters ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx); - scanner.scan("org.springframework.shell.commands", "org.springframework.shell.converters", "org.springframework.shell.plugin.support"); + scanner.scan("org.springframework.shell.commands", "org.springframework.shell.converters", "org.springframework.shell.plugin.support"); //user contributed commands XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) ctx); reader.loadBeanDefinitions(contextPath); diff --git a/src/main/java/org/springframework/shell/commands/ConsoleCommands.java b/src/main/java/org/springframework/shell/commands/ConsoleCommands.java new file mode 100644 index 00000000..1effa045 --- /dev/null +++ b/src/main/java/org/springframework/shell/commands/ConsoleCommands.java @@ -0,0 +1,39 @@ +/* + * 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.commands; + +import jline.ANSIBuffer; + +import org.springframework.shell.core.CommandMarker; +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.stereotype.Component; + +/** + * Commands related to the manipulation of the jline console + * + * @author Mark Pollack + * + */ +@Component +public class ConsoleCommands implements CommandMarker { + + @CliCommand(value = {"cls", "clear"}, help = "Clears the console") + public void clear() { + System.out.print(ANSIBuffer.ANSICodes.clrscr()); + System.out.print(ANSIBuffer.ANSICodes.gotoxy(0, 0)); + } + +} diff --git a/src/main/java/org/springframework/shell/commands/DateCommands.java b/src/main/java/org/springframework/shell/commands/DateCommands.java new file mode 100644 index 00000000..10d76849 --- /dev/null +++ b/src/main/java/org/springframework/shell/commands/DateCommands.java @@ -0,0 +1,39 @@ +/* + * 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.commands; + +import java.text.DateFormat; +import java.util.Date; +import java.util.Locale; + +import org.springframework.shell.core.CommandMarker; +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.stereotype.Component; + +/** + * Commands related to the dates + * + */ +@Component +public class DateCommands implements CommandMarker { + + @CliCommand(value = { "date" }, help = "Displays the local date and time") + public String date() { + return DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL,Locale.US) + .format(new Date()); + } + +} diff --git a/src/main/java/org/springframework/shell/commands/EssentialCommands.java b/src/main/java/org/springframework/shell/commands/ExitCommands.java similarity index 90% rename from src/main/java/org/springframework/shell/commands/EssentialCommands.java rename to src/main/java/org/springframework/shell/commands/ExitCommands.java index 6012411a..d0c6dd69 100644 --- a/src/main/java/org/springframework/shell/commands/EssentialCommands.java +++ b/src/main/java/org/springframework/shell/commands/ExitCommands.java @@ -20,8 +20,12 @@ import org.springframework.shell.core.ExitShellRequest; import org.springframework.shell.core.annotation.CliCommand; import org.springframework.stereotype.Component; +/** + * Commands related to exiting the shell + * + */ @Component -public class EssentialCommands implements CommandMarker { +public class ExitCommands implements CommandMarker { @CliCommand(value={"exit", "quit"}, help="Exits the shell") public ExitShellRequest quit() { diff --git a/src/main/java/org/springframework/shell/commands/InlineCommentCommands.java b/src/main/java/org/springframework/shell/commands/InlineCommentCommands.java new file mode 100644 index 00000000..2d4d5f12 --- /dev/null +++ b/src/main/java/org/springframework/shell/commands/InlineCommentCommands.java @@ -0,0 +1,28 @@ +/* + * 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.commands; + +import org.springframework.shell.core.CommandMarker; +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.stereotype.Component; + +@Component +public class InlineCommentCommands implements CommandMarker { + + @CliCommand(value = { "//", ";" }, help = "Inline comment markers (start of line only)") + public void inlineComment() {} + +} diff --git a/src/main/java/org/springframework/shell/commands/OsCommands.java b/src/main/java/org/springframework/shell/commands/OsCommands.java index 01217c49..2a402ece 100644 --- a/src/main/java/org/springframework/shell/commands/OsCommands.java +++ b/src/main/java/org/springframework/shell/commands/OsCommands.java @@ -25,8 +25,7 @@ import org.springframework.shell.support.logging.HandlerUtils; import org.springframework.stereotype.Component; /** - * Command type to allow execution of native OS commands from the Spring Roo - * shell. + * Command type to allow execution of native OS commands from the Spring Shell. * * @author Stefan Schmidt * @since 1.2.0 diff --git a/src/main/java/org/springframework/shell/commands/SystemPropertyCommands.java b/src/main/java/org/springframework/shell/commands/SystemPropertyCommands.java new file mode 100644 index 00000000..3279ba3a --- /dev/null +++ b/src/main/java/org/springframework/shell/commands/SystemPropertyCommands.java @@ -0,0 +1,46 @@ +/* + * 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.commands; + +import static org.springframework.shell.support.util.OsUtils.LINE_SEPARATOR; + +import java.util.Map.Entry; +import java.util.Set; +import java.util.TreeSet; + +import org.springframework.shell.core.CommandMarker; +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; + +/** + * Commands related to system properties + * + */ +@Component +public class SystemPropertyCommands implements CommandMarker { + + @CliCommand(value = { "system properties" }, help = "Shows the shell's properties") + public String props() { + final Set data = new TreeSet(); // For repeatability + for (final Entry entry : System.getProperties().entrySet()) { + data.add(entry.getKey() + " = " + entry.getValue()); + } + + return StringUtils.collectionToDelimitedString(data, LINE_SEPARATOR) + LINE_SEPARATOR; + } + +} diff --git a/src/main/java/org/springframework/shell/core/AbstractShell.java b/src/main/java/org/springframework/shell/core/AbstractShell.java index b15670e8..e1eb7005 100644 --- a/src/main/java/org/springframework/shell/core/AbstractShell.java +++ b/src/main/java/org/springframework/shell/core/AbstractShell.java @@ -313,8 +313,7 @@ public abstract class AbstractShell extends AbstractShellStatusPublisher impleme return exitShellRequest; } - @CliCommand(value = { "//", ";" }, help = "Inline comment markers (start of line only)") - public void inlineComment() {} + @CliCommand(value = { "/*" }, help = "Start of block comment") public void blockCommentBegin() { @@ -328,22 +327,6 @@ public abstract class AbstractShell extends AbstractShellStatusPublisher impleme inBlockComment = false; } - @CliCommand(value = { "system properties" }, help = "Shows the shell's properties") - public String props() { - final Set data = new TreeSet(); // For repeatability - for (final Entry entry : System.getProperties().entrySet()) { - data.add(entry.getKey() + " = " + entry.getValue()); - } - - return StringUtils.collectionToDelimitedString(data, LINE_SEPARATOR) + LINE_SEPARATOR; - } - - @CliCommand(value = { "date" }, help = "Displays the local date and time") - public String date() { - return DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL,Locale.US) - .format(new Date()); - } - //@CliCommand(value = { "flash test" }, help = "Tests message flashing") public void flashCustom() throws Exception { flash(Level.FINE, "Hello world", "a"); @@ -369,45 +352,6 @@ public abstract class AbstractShell extends AbstractShellStatusPublisher impleme flash(Level.FINE, "", "b"); } - //@CliCommand(value = { "version" }, help = "Displays shell version") - public String version(@CliOption(key = "", help = "Special version flags") final String extra) { - StringBuilder sb = new StringBuilder(); - - if ("jaime".equals(extra)) { - sb.append(" /\\ /l").append(LINE_SEPARATOR); - sb.append(" ((.Y(!").append(LINE_SEPARATOR); - sb.append(" \\ |/").append(LINE_SEPARATOR); - sb.append(" / 6~6,").append(LINE_SEPARATOR); - sb.append(" \\ _ +-.").append(LINE_SEPARATOR); - sb.append(" \\`-=--^-' \\").append(LINE_SEPARATOR); - sb.append(" \\ \\ |\\--------------------------+").append(LINE_SEPARATOR); - sb.append(" _/ \\ | Thanks for loading Roo! |").append(LINE_SEPARATOR); - sb.append(" ( . Y +---------------------------+").append(LINE_SEPARATOR); - sb.append(" /\"\\ `---^--v---.").append(LINE_SEPARATOR); - sb.append(" / _ `---\"T~~\\/~\\/").append(LINE_SEPARATOR); - sb.append(" / \" ~\\. !").append(LINE_SEPARATOR); - sb.append(" _ Y Y.~~~ /'").append(LINE_SEPARATOR); - sb.append(" Y^| | | Roo 7").append(LINE_SEPARATOR); - sb.append(" | l | / . /'").append(LINE_SEPARATOR); - sb.append(" | `L | Y .^/ ~T").append(LINE_SEPARATOR); - sb.append(" | l ! | |/ | | ____ ____ ____").append(LINE_SEPARATOR); - sb.append(" | .`\\/' | Y | ! / __ \\/ __ \\/ __ \\").append(LINE_SEPARATOR); - sb.append(" l \"~ j l j L______ / /_/ / / / / / / /").append(LINE_SEPARATOR); - sb.append(" \\,____{ __\"\" ~ __ ,\\_,\\_ / _, _/ /_/ / /_/ /").append(LINE_SEPARATOR); - sb.append(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~ /_/ |_|\\____/\\____/").append(" ").append(versionInfo()).append(LINE_SEPARATOR); - return sb.toString(); - } - - sb.append(" ____ ____ ____ ").append(LINE_SEPARATOR); - sb.append(" / __ \\/ __ \\/ __ \\ ").append(LINE_SEPARATOR); - sb.append(" / /_/ / / / / / / / ").append(LINE_SEPARATOR); - sb.append(" / _, _/ /_/ / /_/ / ").append(LINE_SEPARATOR); - sb.append("/_/ |_|\\____/\\____/ ").append(" ").append(versionInfo()).append(LINE_SEPARATOR); - sb.append(LINE_SEPARATOR); - - return sb.toString(); - } - public String versionInfo(){ return VersionUtils.versionInfo(); }