Skip to content

Commit

Permalink
Update samples to the latest Spring Shell and Boot versions
Browse files Browse the repository at this point in the history
  • Loading branch information
fmbenhassine committed Feb 7, 2025
1 parent 45350cb commit f3d5820
Show file tree
Hide file tree
Showing 20 changed files with 124 additions and 143 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -308,8 +308,8 @@ public void execute(StateContext<States, Events> 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);
}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -19,26 +19,24 @@
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;

@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();
Expand All @@ -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);
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<States, Events> {

@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()))
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<String, String> {

@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()))
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -214,8 +214,8 @@ public boolean evaluate(StateContext<States, Events> 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);
}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -28,8 +28,8 @@
@Component
public class StateMachineCommands extends AbstractStateMachineCommands<States, Events> {

@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()))
Expand Down
Loading

0 comments on commit f3d5820

Please sign in to comment.