From a8d20f29bf13d9d329504b78509c526a998fa06d Mon Sep 17 00:00:00 2001 From: Janne Valkealahti Date: Sat, 18 Dec 2021 14:43:27 +0000 Subject: [PATCH] Remove legacy from sample - Preparation for further work as remove shell 1.x dep from sample. - Relates #333 --- spring-shell-samples/pom.xml | 17 +-- .../shell/samples/legacy/ArtifactType.java | 27 ----- .../shell/samples/legacy/LegacyCommands.java | 101 ------------------ .../shell/samples/noautoconf/NoAutoConf.java | 2 - 4 files changed, 1 insertion(+), 146 deletions(-) delete mode 100644 spring-shell-samples/src/main/java/org/springframework/shell/samples/legacy/ArtifactType.java delete mode 100644 spring-shell-samples/src/main/java/org/springframework/shell/samples/legacy/LegacyCommands.java diff --git a/spring-shell-samples/pom.xml b/spring-shell-samples/pom.xml index 8734aad8..3b01139a 100644 --- a/spring-shell-samples/pom.xml +++ b/spring-shell-samples/pom.xml @@ -11,7 +11,7 @@ spring-shell-parent 3.0.0-SNAPSHOT - + Examples of using Spring Shell 2 @@ -27,28 +27,13 @@ - - org.springframework.shell spring-shell-starter - - - - org.springframework.shell - spring-shell - 1.2.0.RELEASE - - - com.beust jcommander - 1.48 - - - diff --git a/spring-shell-samples/src/main/java/org/springframework/shell/samples/legacy/ArtifactType.java b/spring-shell-samples/src/main/java/org/springframework/shell/samples/legacy/ArtifactType.java deleted file mode 100644 index f0bfc0bc..00000000 --- a/spring-shell-samples/src/main/java/org/springframework/shell/samples/legacy/ArtifactType.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2015 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 - * - * https://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.samples.legacy; - -/** - * Enum used by some of the example Shell 1 commands. - * - * @author Eric Bottard - */ -public enum ArtifactType { - - source, processor, sink, task -} diff --git a/spring-shell-samples/src/main/java/org/springframework/shell/samples/legacy/LegacyCommands.java b/spring-shell-samples/src/main/java/org/springframework/shell/samples/legacy/LegacyCommands.java deleted file mode 100644 index fc1efa80..00000000 --- a/spring-shell-samples/src/main/java/org/springframework/shell/samples/legacy/LegacyCommands.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2015 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 - * - * https://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.samples.legacy; - -import java.io.File; -import java.lang.reflect.Method; - -import org.springframework.shell.core.CommandMarker; -import org.springframework.shell.core.annotation.CliAvailabilityIndicator; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; -import org.springframework.stereotype.Component; -import org.springframework.util.ReflectionUtils; - -import javax.validation.constraints.Min; - -/** - * A sample of legacy Shell 1 commands that can be run thanks to the legacy adapter. - * - * @author Eric Bottard - */ -@Component -public class LegacyCommands implements CommandMarker { - - public static final Method REGISTER_METHOD = ReflectionUtils.findMethod(LegacyCommands.class, "register", String.class, ArtifactType.class, String.class, boolean.class); - public static final Method SUM_METHOD = ReflectionUtils.findMethod(LegacyCommands.class, "sum", int.class, int.class); - - private boolean available = true; - - @CliAvailabilityIndicator("register module") - public boolean registerAvailable() { - return available; - } - - @CliCommand(value = "register module", help = "Register a new module") - public String register( - @CliOption(mandatory = true, - key = {"", "name"}, - help = "the name for the registered module") - String name, - @CliOption(mandatory = true, - key = {"type"}, - help = "the type for the registered module") - ArtifactType type, - @CliOption(mandatory = false, - key = {"coordinates", "coords"}, - help = "coordinates to the module archive") - String coordinates, - @CliOption(key = "force", - help = "force update if module already exists (only if not in use)", - specifiedDefaultValue = "true", - unspecifiedDefaultValue = "false") - boolean force) { - return String.format(("Successfully registered module '%s:%s'"), type, name); - } - - @CliCommand(value = "sum", help = "adds two numbers. Will also toggle the 'register module' command availability") - public int sum( - @CliOption(key = "v1", unspecifiedDefaultValue = "38") int a, - @CliOption(key = "v2", specifiedDefaultValue = "42") int b) { - available = !available; - return a + b; - } - - @CliCommand(value = "sum2", help = "adds two numbers") - public int sum2( - @CliOption(key = "v1", unspecifiedDefaultValue = "38") @Min(5) int a, - @CliOption(key = "v2", specifiedDefaultValue = "42", mandatory = true) int b, - @CliOption(key = "v3", mandatory = false) int c) { - return a + b + c; - } - - @CliCommand(value = "legacy-echo", help = "Echoes a message") - public String legacyEcho(@CliOption(key = "", mandatory = true) String message) { - return message; - } - - @CliCommand(value = "optional-echo", help = "Echoes an optional message") - public String optionalEcho(@CliOption(key = "", mandatory = false) String message) { - return message; - } - - @CliCommand(value = "legacy-file", help = "Uses a legacy converter for completion") - public String legacyFile(@CliOption(key = "file") File file, @CliOption(key = "flag") boolean flag) { - return file + " exists? : " + file.exists(); - } -} diff --git a/spring-shell-samples/src/main/java/org/springframework/shell/samples/noautoconf/NoAutoConf.java b/spring-shell-samples/src/main/java/org/springframework/shell/samples/noautoconf/NoAutoConf.java index c6d7ac10..9128d471 100644 --- a/spring-shell-samples/src/main/java/org/springframework/shell/samples/noautoconf/NoAutoConf.java +++ b/spring-shell-samples/src/main/java/org/springframework/shell/samples/noautoconf/NoAutoConf.java @@ -24,7 +24,6 @@ import org.springframework.shell.SpringShellAutoConfiguration; import org.springframework.shell.jcommander.JCommanderParameterResolverAutoConfiguration; import org.springframework.shell.jline.JLineShellAutoConfiguration; import org.springframework.shell.samples.jcommander.JCommanderCommands; -import org.springframework.shell.samples.legacy.LegacyCommands; import org.springframework.shell.samples.standard.Commands; import org.springframework.shell.samples.standard.DynamicCommands; import org.springframework.shell.samples.standard.TableCommands; @@ -51,7 +50,6 @@ import org.springframework.shell.standard.commands.StandardCommandsAutoConfigura //PropertyPlaceholderAutoConfiguration.class, // Sample Commands JCommanderCommands.class, - LegacyCommands.class, Commands.class, FileValueProvider.class, DynamicCommands.class,