From f3d582009ec9680d1d925110f15d5e5ee73ddf1d Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Fri, 7 Feb 2025 05:21:01 +0100 Subject: [PATCH] Update samples to the latest Spring Shell and Boot versions --- gradle.properties | 6 ++-- .../main/java/demo/cdplayer/Application.java | 8 ++--- .../java/demo/cdplayer/CdPlayerCommands.java | 32 +++++++++---------- .../demo/cdplayer/StateMachineCommands.java | 13 ++++---- .../main/java/demo/persist/Application.java | 8 ++--- .../java/demo/persist/PersistCommands.java | 26 +++++++-------- .../demo/persist/StateMachineCommands.java | 13 ++++---- .../main/java/demo/showcase/Application.java | 8 ++--- .../demo/showcase/StateMachineCommands.java | 10 +++--- .../demo/AbstractStateMachineCommands.java | 20 ++++++------ .../java/demo/StateMachinePromptProvider.java | 17 ++++------ .../src/main/java/demo/tasks/Application.java | 8 ++--- .../java/demo/tasks/StateMachineCommands.java | 13 ++++---- .../main/java/demo/tasks/TasksCommands.java | 22 ++++++------- .../main/java/demo/turnstile/Application.java | 8 ++--- .../demo/turnstile/StateMachineCommands.java | 13 ++++---- .../main/java/demo/washer/Application.java | 8 ++--- .../demo/washer/StateMachineCommands.java | 13 ++++---- .../main/java/demo/zookeeper/Application.java | 8 ++--- .../demo/zookeeper/StateMachineCommands.java | 13 ++++---- 20 files changed, 124 insertions(+), 143 deletions(-) diff --git a/gradle.properties b/gradle.properties index 8de89586b..4b1bb41f4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,9 @@ -#Mon Jun 19 10:33:34 UTC 2023 version=4.0.1-SNAPSHOT -springBootVersion=3.4.2 +springBootVersion=3.5.0-SNAPSHOT +springShellVersion=3.4.1-SNAPSHOT + jakartaPersistenceVersion=3.1.0 kryoVersion=4.0.3 -springShellVersion=3.4.0 eclipseEmfXmiVersion=2.11.1 eclipseUml2CommonVersion=2.0.0-v20140602-0749 eclipseEmfCommonVersion=2.11.0 diff --git a/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/Application.java b/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/Application.java index ad3c76e85..3ea1f51da 100644 --- a/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/Application.java +++ b/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/Application.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2025 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. @@ -21,10 +21,10 @@ import java.lang.annotation.Target; import java.util.Map; +import org.springframework.boot.SpringApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.messaging.support.MessageBuilder; -import org.springframework.shell.Bootstrap; import org.springframework.statemachine.ExtendedState; import org.springframework.statemachine.StateContext; import org.springframework.statemachine.action.Action; @@ -308,8 +308,8 @@ public void execute(StateContext context) { } //end::snippetL[] - public static void main(String[] args) throws Exception { - Bootstrap.main(args); + public static void main(String[] args) { + SpringApplication.run(Application.class, args); } } diff --git a/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/CdPlayerCommands.java b/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/CdPlayerCommands.java index 624fabc99..8c5685e30 100644 --- a/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/CdPlayerCommands.java +++ b/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/CdPlayerCommands.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2025 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. @@ -19,13 +19,11 @@ import java.util.Date; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.shell.core.CommandMarker; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; -import org.springframework.stereotype.Component; +import org.springframework.shell.command.annotation.Command; +import org.springframework.shell.command.annotation.Option; -@Component -public class CdPlayerCommands implements CommandMarker { +@Command +public class CdPlayerCommands { @Autowired private CdPlayer cdPlayer; @@ -33,12 +31,12 @@ public class CdPlayerCommands implements CommandMarker { @Autowired private Library library; - @CliCommand(value = "cd lcd", help = "Prints CD player lcd info") + @Command(command = "cd lcd", description = "Prints CD player lcd info") public String lcd() { return cdPlayer.getLdcStatus(); } - @CliCommand(value = "cd library", help = "List user CD library") + @Command(command = "cd library", description = "List user CD library") public String library() { SimpleDateFormat format = new SimpleDateFormat("mm:ss"); StringBuilder buf = new StringBuilder(); @@ -53,8 +51,8 @@ public String library() { return buf.toString(); } - @CliCommand(value = "cd load", help = "Load CD into player") - public String load(@CliOption(key = {"", "index"}) int index) { + @Command(command = "cd load", description = "Load CD into player") + public String load(@Option(longNames = {"", "index"}) int index) { StringBuilder buf = new StringBuilder(); try { Cd cd = library.getCollection().get(index); @@ -66,32 +64,32 @@ public String load(@CliOption(key = {"", "index"}) int index) { return buf.toString(); } - @CliCommand(value = "cd play", help = "Press player play button") + @Command(command = "cd play", description = "Press player play button") public void play() { cdPlayer.play(); } - @CliCommand(value = "cd stop", help = "Press player stop button") + @Command(command = "cd stop", description = "Press player stop button") public void stop() { cdPlayer.stop(); } - @CliCommand(value = "cd pause", help = "Press player pause button") + @Command(command = "cd pause", description = "Press player pause button") public void pause() { cdPlayer.pause(); } - @CliCommand(value = "cd eject", help = "Press player eject button") + @Command(command = "cd eject", description = "Press player eject button") public void eject() { cdPlayer.eject(); } - @CliCommand(value = "cd forward", help = "Press player forward button") + @Command(command = "cd forward", description = "Press player forward button") public void forward() { cdPlayer.forward(); } - @CliCommand(value = "cd back", help = "Press player back button") + @Command(command = "cd back", description = "Press player back button") public void back() { cdPlayer.back(); } diff --git a/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/StateMachineCommands.java b/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/StateMachineCommands.java index 22293054d..2125ea516 100644 --- a/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/StateMachineCommands.java +++ b/spring-statemachine-samples/cdplayer/src/main/java/demo/cdplayer/StateMachineCommands.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2025 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. @@ -16,20 +16,19 @@ package demo.cdplayer; import org.springframework.messaging.support.MessageBuilder; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; -import org.springframework.stereotype.Component; +import org.springframework.shell.command.annotation.Command; +import org.springframework.shell.command.annotation.Option; import demo.AbstractStateMachineCommands; import demo.cdplayer.Application.Events; import demo.cdplayer.Application.States; import reactor.core.publisher.Mono; -@Component +@Command public class StateMachineCommands extends AbstractStateMachineCommands { - @CliCommand(value = "sm event", help = "Sends an event to a state machine") - public String event(@CliOption(key = { "", "event" }, mandatory = true, help = "The event") final Events event) { + @Command(command = "sm event", description = "Sends an event to a state machine") + public String event(@Option(longNames = { "", "event" }, required = true, description = "The event") final Events event) { getStateMachine() .sendEvent(Mono.just(MessageBuilder .withPayload(event).build())) diff --git a/spring-statemachine-samples/persist/src/main/java/demo/persist/Application.java b/spring-statemachine-samples/persist/src/main/java/demo/persist/Application.java index 783231f42..fb7aa00cc 100644 --- a/spring-statemachine-samples/persist/src/main/java/demo/persist/Application.java +++ b/spring-statemachine-samples/persist/src/main/java/demo/persist/Application.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2025 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. @@ -16,10 +16,10 @@ package demo.persist; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.shell.Bootstrap; import org.springframework.statemachine.StateMachine; import org.springframework.statemachine.config.EnableStateMachine; import org.springframework.statemachine.config.StateMachineConfigurerAdapter; @@ -105,8 +105,8 @@ public String toString() { } //end::snippetC[] - public static void main(String[] args) throws Exception { - Bootstrap.main(args); + public static void main(String[] args) { + SpringApplication.run(Application.class, args); } } diff --git a/spring-statemachine-samples/persist/src/main/java/demo/persist/PersistCommands.java b/spring-statemachine-samples/persist/src/main/java/demo/persist/PersistCommands.java index 02006e580..6f8eeac42 100644 --- a/spring-statemachine-samples/persist/src/main/java/demo/persist/PersistCommands.java +++ b/spring-statemachine-samples/persist/src/main/java/demo/persist/PersistCommands.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2025 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. @@ -16,34 +16,32 @@ package demo.persist; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.shell.core.CommandMarker; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; -import org.springframework.stereotype.Component; +import org.springframework.shell.command.annotation.Command; +import org.springframework.shell.command.annotation.Option; -@Component -public class PersistCommands implements CommandMarker { +@Command +public class PersistCommands { @Autowired private Persist persist; - @CliCommand(value = "persist db", help = "List entries from db") + @Command(command = "persist db", description = "List entries from db") public String listDbEntries() { return persist.listDbEntries(); } - @CliCommand(value = "persist process", help = "Process order") - public void process(@CliOption(key = {"", "id"}, help = "Order id") int order) { + @Command(command = "persist process", description = "Process order") + public void process(@Option(longNames = {"", "id"}, description = "Order id") int order) { persist.change(order, "PROCESS"); } - @CliCommand(value = "persist send", help = "Send order") - public void send(@CliOption(key = {"", "id"}, help = "Order id") int order) { + @Command(command = "persist send", description = "Send order") + public void send(@Option(longNames = {"", "id"}, description = "Order id") int order) { persist.change(order, "SEND"); } - @CliCommand(value = "persist deliver", help = "Deliver order") - public void deliver(@CliOption(key = {"", "id"}, help = "Order id") int order) { + @Command(command = "persist deliver", description = "Deliver order") + public void deliver(@Option(longNames = {"", "id"}, description = "Order id") int order) { persist.change(order, "DELIVER"); } diff --git a/spring-statemachine-samples/persist/src/main/java/demo/persist/StateMachineCommands.java b/spring-statemachine-samples/persist/src/main/java/demo/persist/StateMachineCommands.java index 04416bcd0..2991ba340 100644 --- a/spring-statemachine-samples/persist/src/main/java/demo/persist/StateMachineCommands.java +++ b/spring-statemachine-samples/persist/src/main/java/demo/persist/StateMachineCommands.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2025 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. @@ -16,18 +16,17 @@ package demo.persist; import org.springframework.messaging.support.MessageBuilder; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; -import org.springframework.stereotype.Component; +import org.springframework.shell.command.annotation.Command; +import org.springframework.shell.command.annotation.Option; import demo.AbstractStateMachineCommands; import reactor.core.publisher.Mono; -@Component +@Command public class StateMachineCommands extends AbstractStateMachineCommands { - @CliCommand(value = "sm event", help = "Sends an event to a state machine") - public String event(@CliOption(key = { "", "event" }, mandatory = true, help = "The event") final String event) { + @Command(command = "sm event", description = "Sends an event to a state machine") + public String event(@Option(longNames = { "", "event" }, required = true, description = "The event") final String event) { getStateMachine() .sendEvent(Mono.just(MessageBuilder .withPayload(event).build())) diff --git a/spring-statemachine-samples/showcase/src/main/java/demo/showcase/Application.java b/spring-statemachine-samples/showcase/src/main/java/demo/showcase/Application.java index e92b6c80d..0c4294be0 100644 --- a/spring-statemachine-samples/showcase/src/main/java/demo/showcase/Application.java +++ b/spring-statemachine-samples/showcase/src/main/java/demo/showcase/Application.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2025 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. @@ -19,9 +19,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.boot.SpringApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.shell.Bootstrap; import org.springframework.statemachine.StateContext; import org.springframework.statemachine.action.Action; import org.springframework.statemachine.config.EnableStateMachine; @@ -214,8 +214,8 @@ public boolean evaluate(StateContext context) { } // end::snippetE[] - public static void main(String[] args) throws Exception { - Bootstrap.main(args); + public static void main(String[] args) { + SpringApplication.run(Application.class, args); } } diff --git a/spring-statemachine-samples/showcase/src/main/java/demo/showcase/StateMachineCommands.java b/spring-statemachine-samples/showcase/src/main/java/demo/showcase/StateMachineCommands.java index 74121c0af..4d2faf8b8 100644 --- a/spring-statemachine-samples/showcase/src/main/java/demo/showcase/StateMachineCommands.java +++ b/spring-statemachine-samples/showcase/src/main/java/demo/showcase/StateMachineCommands.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2025 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. @@ -16,8 +16,8 @@ package demo.showcase; import org.springframework.messaging.support.MessageBuilder; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; +import org.springframework.shell.command.annotation.Command; +import org.springframework.shell.command.annotation.Option; import org.springframework.stereotype.Component; import demo.AbstractStateMachineCommands; @@ -28,8 +28,8 @@ @Component public class StateMachineCommands extends AbstractStateMachineCommands { - @CliCommand(value = "sm event", help = "Sends an event to a state machine") - public String event(@CliOption(key = { "", "event" }, mandatory = true, help = "The event") final Events event) { + @Command(command = "sm event", description = "Sends an event to a state machine") + public String event(@Option(longNames = { "", "event" }, required = true, description = "The event") final Events event) { getStateMachine() .sendEvent(Mono.just(MessageBuilder .withPayload(event).build())) diff --git a/spring-statemachine-samples/src/main/java/demo/AbstractStateMachineCommands.java b/spring-statemachine-samples/src/main/java/demo/AbstractStateMachineCommands.java index fb2dd674b..f2ea1580d 100644 --- a/spring-statemachine-samples/src/main/java/demo/AbstractStateMachineCommands.java +++ b/spring-statemachine-samples/src/main/java/demo/AbstractStateMachineCommands.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2025 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. @@ -21,15 +21,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.shell.core.CommandMarker; -import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.command.annotation.Command; import org.springframework.statemachine.StateMachine; import org.springframework.statemachine.state.State; -import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; -@Component -public class AbstractStateMachineCommands implements CommandMarker { +@Command +public class AbstractStateMachineCommands { @Autowired private StateMachine stateMachine; @@ -42,7 +40,7 @@ protected StateMachine getStateMachine() { @Qualifier("stateChartModel") private String stateChartModel; - @CliCommand(value = "sm state", help = "Prints current state") + @Command(command = "sm state", description = "Prints current state") public String state() { State state = stateMachine.getState(); if (state != null) { @@ -52,24 +50,24 @@ public String state() { } } - @CliCommand(value = "sm start", help = "Start a state machine") + @Command(command = "sm start", description = "Start a state machine") public String start() { stateMachine.startReactively().subscribe(); return "State machine started"; } - @CliCommand(value = "sm stop", help = "Stop a state machine") + @Command(command = "sm stop", description = "Stop a state machine") public String stop() { stateMachine.stopReactively().subscribe(); return "State machine stopped"; } - @CliCommand(value = "sm print", help = "Print state machine") + @Command(command = "sm print", description = "Print state machine") public String print() { return stateChartModel; } - @CliCommand(value = "sm variables", help = "Prints extended state variables") + @Command(command = "sm variables", description = "Prints extended state variables") public String variables() { StringBuilder buf = new StringBuilder(); Set> entrySet = stateMachine.getExtendedState().getVariables().entrySet(); diff --git a/spring-statemachine-samples/src/main/java/demo/StateMachinePromptProvider.java b/spring-statemachine-samples/src/main/java/demo/StateMachinePromptProvider.java index 9b58f3329..897e02990 100644 --- a/spring-statemachine-samples/src/main/java/demo/StateMachinePromptProvider.java +++ b/spring-statemachine-samples/src/main/java/demo/StateMachinePromptProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2025 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. @@ -15,24 +15,19 @@ */ package demo; +import org.jline.utils.AttributedString; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; -import org.springframework.shell.plugin.support.DefaultPromptProvider; +import org.springframework.shell.jline.PromptProvider; import org.springframework.stereotype.Component; @Component @Order(Ordered.HIGHEST_PRECEDENCE) -public class StateMachinePromptProvider extends DefaultPromptProvider { +public class StateMachinePromptProvider implements PromptProvider { @Override - public String getPrompt() { - return "sm>"; - } - - - @Override - public String getProviderName() { - return "State machine prompt provider"; + public AttributedString getPrompt() { + return AttributedString.fromAnsi("sm>"); } } diff --git a/spring-statemachine-samples/tasks/src/main/java/demo/tasks/Application.java b/spring-statemachine-samples/tasks/src/main/java/demo/tasks/Application.java index 049d99bc3..ea9dc3d6b 100644 --- a/spring-statemachine-samples/tasks/src/main/java/demo/tasks/Application.java +++ b/spring-statemachine-samples/tasks/src/main/java/demo/tasks/Application.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2025 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. @@ -21,10 +21,10 @@ import java.lang.annotation.Target; import java.util.Map; +import org.springframework.boot.SpringApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.messaging.support.MessageBuilder; -import org.springframework.shell.Bootstrap; import org.springframework.statemachine.StateContext; import org.springframework.statemachine.action.Action; import org.springframework.statemachine.annotation.OnTransition; @@ -232,8 +232,8 @@ public enum Events { } - public static void main(String[] args) throws Exception { - Bootstrap.main(args); + public static void main(String[] args) { + SpringApplication.run(Application.class, args); } } diff --git a/spring-statemachine-samples/tasks/src/main/java/demo/tasks/StateMachineCommands.java b/spring-statemachine-samples/tasks/src/main/java/demo/tasks/StateMachineCommands.java index 2333458cf..90fa20cbb 100644 --- a/spring-statemachine-samples/tasks/src/main/java/demo/tasks/StateMachineCommands.java +++ b/spring-statemachine-samples/tasks/src/main/java/demo/tasks/StateMachineCommands.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2025 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. @@ -16,20 +16,19 @@ package demo.tasks; import org.springframework.messaging.support.MessageBuilder; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; -import org.springframework.stereotype.Component; +import org.springframework.shell.command.annotation.Command; +import org.springframework.shell.command.annotation.Option; import demo.AbstractStateMachineCommands; import demo.tasks.Application.Events; import demo.tasks.Application.States; import reactor.core.publisher.Mono; -@Component +@Command public class StateMachineCommands extends AbstractStateMachineCommands { - @CliCommand(value = "sm event", help = "Sends an event to a state machine") - public String event(@CliOption(key = { "", "event" }, mandatory = true, help = "The event") final Events event) { + @Command(command = "sm event", description = "Sends an event to a state machine") + public String event(@Option(longNames = { "", "event" }, required = true, description = "The event") final Events event) { getStateMachine() .sendEvent(Mono.just(MessageBuilder .withPayload(event).build())) diff --git a/spring-statemachine-samples/tasks/src/main/java/demo/tasks/TasksCommands.java b/spring-statemachine-samples/tasks/src/main/java/demo/tasks/TasksCommands.java index e36bc4fe9..b23a46f0b 100644 --- a/spring-statemachine-samples/tasks/src/main/java/demo/tasks/TasksCommands.java +++ b/spring-statemachine-samples/tasks/src/main/java/demo/tasks/TasksCommands.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2025 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. @@ -16,34 +16,32 @@ package demo.tasks; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.shell.core.CommandMarker; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; -import org.springframework.stereotype.Component; +import org.springframework.shell.command.annotation.Command; +import org.springframework.shell.command.annotation.Option; -@Component -public class TasksCommands implements CommandMarker { +@Command +public class TasksCommands { @Autowired private Tasks tasks; - @CliCommand(value = "tasks run", help = "Run tasks") + @Command(command = "tasks run", description = "Run tasks") public void run() { tasks.run(); } - @CliCommand(value = "tasks list", help = "List tasks") + @Command(command = "tasks list", description = "List tasks") public String list() { return tasks.toString(); } - @CliCommand(value = "tasks fix", help = "Fix tasks") + @Command(command = "tasks fix", description = "Fix tasks") public void fix() { tasks.fix(); } - @CliCommand(value = "tasks fail", help = "Fail task") - public void fail(@CliOption(key = {"", "task"}, help = "Task id") String task) { + @Command(command = "tasks fail", description = "Fail task") + public void fail(@Option(longNames = {"", "task"}, description = "Task id") String task) { tasks.fail(task); } diff --git a/spring-statemachine-samples/turnstile/src/main/java/demo/turnstile/Application.java b/spring-statemachine-samples/turnstile/src/main/java/demo/turnstile/Application.java index 2584f704d..cfa2e4a67 100644 --- a/spring-statemachine-samples/turnstile/src/main/java/demo/turnstile/Application.java +++ b/spring-statemachine-samples/turnstile/src/main/java/demo/turnstile/Application.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2025 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. @@ -17,8 +17,8 @@ import java.util.EnumSet; +import org.springframework.boot.SpringApplication; import org.springframework.context.annotation.Configuration; -import org.springframework.shell.Bootstrap; import org.springframework.statemachine.config.EnableStateMachine; import org.springframework.statemachine.config.EnumStateMachineConfigurerAdapter; import org.springframework.statemachine.config.builders.StateMachineStateConfigurer; @@ -72,8 +72,8 @@ public enum Events { } //end::snippetC[] - public static void main(String[] args) throws Exception { - Bootstrap.main(args); + public static void main(String[] args) { + SpringApplication.run(Application.class, args); } } diff --git a/spring-statemachine-samples/turnstile/src/main/java/demo/turnstile/StateMachineCommands.java b/spring-statemachine-samples/turnstile/src/main/java/demo/turnstile/StateMachineCommands.java index 6779c3cd5..f02e1f50f 100644 --- a/spring-statemachine-samples/turnstile/src/main/java/demo/turnstile/StateMachineCommands.java +++ b/spring-statemachine-samples/turnstile/src/main/java/demo/turnstile/StateMachineCommands.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2025 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. @@ -16,20 +16,19 @@ package demo.turnstile; import org.springframework.messaging.support.MessageBuilder; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; -import org.springframework.stereotype.Component; +import org.springframework.shell.command.annotation.Command; +import org.springframework.shell.command.annotation.Option; import demo.AbstractStateMachineCommands; import demo.turnstile.Application.Events; import demo.turnstile.Application.States; import reactor.core.publisher.Mono; -@Component +@Command public class StateMachineCommands extends AbstractStateMachineCommands { - @CliCommand(value = "sm event", help = "Sends an event to a state machine") - public String event(@CliOption(key = { "", "event" }, mandatory = true, help = "The event") final Events event) { + @Command(command = "sm event", description = "Sends an event to a state machine") + public String event(@Option(longNames = { "", "event" }, required = true, description = "The event") final Events event) { getStateMachine() .sendEvent(Mono.just(MessageBuilder .withPayload(event).build())) diff --git a/spring-statemachine-samples/washer/src/main/java/demo/washer/Application.java b/spring-statemachine-samples/washer/src/main/java/demo/washer/Application.java index 7e886f13e..b71a78ca4 100644 --- a/spring-statemachine-samples/washer/src/main/java/demo/washer/Application.java +++ b/spring-statemachine-samples/washer/src/main/java/demo/washer/Application.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2025 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. @@ -15,8 +15,8 @@ */ package demo.washer; +import org.springframework.boot.SpringApplication; import org.springframework.context.annotation.Configuration; -import org.springframework.shell.Bootstrap; import org.springframework.statemachine.config.EnableStateMachine; import org.springframework.statemachine.config.EnumStateMachineConfigurerAdapter; import org.springframework.statemachine.config.builders.StateMachineStateConfigurer; @@ -94,8 +94,8 @@ public enum Events { } //end::snippetC[] - public static void main(String[] args) throws Exception { - Bootstrap.main(args); + public static void main(String[] args) { + SpringApplication.run(Application.class, args); } } diff --git a/spring-statemachine-samples/washer/src/main/java/demo/washer/StateMachineCommands.java b/spring-statemachine-samples/washer/src/main/java/demo/washer/StateMachineCommands.java index c0dc1d60f..4eb90960b 100644 --- a/spring-statemachine-samples/washer/src/main/java/demo/washer/StateMachineCommands.java +++ b/spring-statemachine-samples/washer/src/main/java/demo/washer/StateMachineCommands.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2025 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. @@ -16,20 +16,19 @@ package demo.washer; import org.springframework.messaging.support.MessageBuilder; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; -import org.springframework.stereotype.Component; +import org.springframework.shell.command.annotation.Command; +import org.springframework.shell.command.annotation.Option; import demo.AbstractStateMachineCommands; import demo.washer.Application.Events; import demo.washer.Application.States; import reactor.core.publisher.Mono; -@Component +@Command public class StateMachineCommands extends AbstractStateMachineCommands { - @CliCommand(value = "sm event", help = "Sends an event to a state machine") - public String event(@CliOption(key = { "", "event" }, mandatory = true, help = "The event") final Events event) { + @Command(command = "sm event", description = "Sends an event to a state machine") + public String event(@Option(longNames = { "", "event" }, required = true, description = "The event") final Events event) { getStateMachine() .sendEvent(Mono.just(MessageBuilder .withPayload(event).build())) diff --git a/spring-statemachine-samples/zookeeper/src/main/java/demo/zookeeper/Application.java b/spring-statemachine-samples/zookeeper/src/main/java/demo/zookeeper/Application.java index ff14382ee..09c3f096f 100644 --- a/spring-statemachine-samples/zookeeper/src/main/java/demo/zookeeper/Application.java +++ b/spring-statemachine-samples/zookeeper/src/main/java/demo/zookeeper/Application.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2025 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. @@ -18,9 +18,9 @@ import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.retry.ExponentialBackoffRetry; +import org.springframework.boot.SpringApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.shell.Bootstrap; import org.springframework.statemachine.config.EnableStateMachine; import org.springframework.statemachine.config.StateMachineConfigurerAdapter; import org.springframework.statemachine.config.builders.StateMachineConfigurationConfigurer; @@ -96,8 +96,8 @@ public enum Events { COIN, PUSH } - public static void main(String[] args) throws Exception { - Bootstrap.main(args); + public static void main(String[] args) { + SpringApplication.run(Application.class, args); } } diff --git a/spring-statemachine-samples/zookeeper/src/main/java/demo/zookeeper/StateMachineCommands.java b/spring-statemachine-samples/zookeeper/src/main/java/demo/zookeeper/StateMachineCommands.java index 2e2dce6ea..0583c6139 100644 --- a/spring-statemachine-samples/zookeeper/src/main/java/demo/zookeeper/StateMachineCommands.java +++ b/spring-statemachine-samples/zookeeper/src/main/java/demo/zookeeper/StateMachineCommands.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2025 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. @@ -16,18 +16,17 @@ package demo.zookeeper; import org.springframework.messaging.support.MessageBuilder; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; -import org.springframework.stereotype.Component; +import org.springframework.shell.command.annotation.Command; +import org.springframework.shell.command.annotation.Option; import demo.AbstractStateMachineCommands; import reactor.core.publisher.Mono; -@Component +@Command public class StateMachineCommands extends AbstractStateMachineCommands { - @CliCommand(value = "sm event", help = "Sends an event to a state machine") - public String event(@CliOption(key = { "", "event" }, mandatory = true, help = "The event") final String event) { + @Command(command = "sm event", description = "Sends an event to a state machine") + public String event(@Option(longNames = { "", "event" }, required = true, description = "The event") final String event) { getStateMachine() .sendEvent(Mono.just(MessageBuilder .withPayload(event).build()))