From 54702460d1bb9e17c8cfeba287b69d9862938931 Mon Sep 17 00:00:00 2001 From: Janne Valkealahti Date: Fri, 24 Dec 2021 13:25:07 +0000 Subject: [PATCH] Make sample to work with spring-native - While project uses jdk8, you can do native build with jdk11 `./mvnw clean package -Pnative` - You can then run these spring-shell-samples/target/spring-shell-samples java -jar spring-shell-samples/target/spring-shell-samples-3.0.0-SNAPSHOT-exec.jar - Remove logback.xml in favour of spring config to workaround for https://github.com/spring-projects-experimental/spring-native/issues/625 - For now remove jcommander command sample to get support for it #340 - Relates #323 --- spring-shell-samples/pom.xml | 88 ++++++++++++++++++- ...ExampleApplicationRunnerConfiguration.java | 4 +- .../shell/samples/jcommander/Args.java | 55 ------------ .../jcommander/JCommanderCommands.java | 37 -------- .../shell/samples/noautoconf/NoAutoConf.java | 63 ------------- .../src/main/resources/application.yml | 6 +- .../src/main/resources/logback.xml | 5 -- 7 files changed, 90 insertions(+), 168 deletions(-) delete mode 100644 spring-shell-samples/src/main/java/org/springframework/shell/samples/jcommander/Args.java delete mode 100644 spring-shell-samples/src/main/java/org/springframework/shell/samples/jcommander/JCommanderCommands.java delete mode 100644 spring-shell-samples/src/main/java/org/springframework/shell/samples/noautoconf/NoAutoConf.java delete mode 100644 spring-shell-samples/src/main/resources/logback.xml diff --git a/spring-shell-samples/pom.xml b/spring-shell-samples/pom.xml index 3b01139a..5ee588e5 100644 --- a/spring-shell-samples/pom.xml +++ b/spring-shell-samples/pom.xml @@ -19,14 +19,15 @@ org.springframework.boot spring-boot-maven-plugin - - org.springframework.shell.samples.SpringShellSample - + + org.springframework.boot + spring-boot-starter + org.springframework.shell spring-shell-starter @@ -36,4 +37,85 @@ jcommander + + + + native + + + 0.11.1 + + + + org.springframework.experimental + spring-native + ${spring-native.version} + + + + org.junit.platform + junit-platform-launcher + test + + + + + + org.springframework.experimental + spring-aot-maven-plugin + ${spring-native.version} + + + generate + + generate + + + + + + org.graalvm.buildtools + native-maven-plugin + 0.9.9 + true + + + build-native + + build + + package + + + test-native + + test + + test + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + exec + + + + + + + spring-releases + Spring Releasess + https://repo.spring.io/release + + + + + diff --git a/spring-shell-samples/src/main/java/org/springframework/shell/samples/ExampleApplicationRunnerConfiguration.java b/spring-shell-samples/src/main/java/org/springframework/shell/samples/ExampleApplicationRunnerConfiguration.java index 0a047f71..661456b8 100644 --- a/spring-shell-samples/src/main/java/org/springframework/shell/samples/ExampleApplicationRunnerConfiguration.java +++ b/spring-shell-samples/src/main/java/org/springframework/shell/samples/ExampleApplicationRunnerConfiguration.java @@ -6,7 +6,7 @@ * 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. @@ -34,7 +34,7 @@ import org.springframework.shell.Shell; import org.springframework.shell.jline.InteractiveShellApplicationRunner; import org.springframework.util.StringUtils; -@Configuration +@Configuration(proxyBeanMethods = false) public class ExampleApplicationRunnerConfiguration { @Autowired diff --git a/spring-shell-samples/src/main/java/org/springframework/shell/samples/jcommander/Args.java b/spring-shell-samples/src/main/java/org/springframework/shell/samples/jcommander/Args.java deleted file mode 100644 index 4338a8a4..00000000 --- a/spring-shell-samples/src/main/java/org/springframework/shell/samples/jcommander/Args.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2017 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.jcommander; - -import java.util.ArrayList; -import java.util.List; - -import com.beust.jcommander.Parameter; - -import javax.validation.constraints.Min; - -/** - * An example straight from the JCommander documentation. - * - * @author Eric Bottard - * @author Cédric Beust - */ -public class Args { - @Parameter - private List parameters = new ArrayList<>(); - - @Min(3) - @Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity") - private Integer verbose = 1; - - @Parameter(names = "-groups", description = "Comma-separated list of group names to be run") - private String groups; - - @Parameter(names = "-debug", description = "Debug mode") - private boolean debug = false; - - @Override - public String toString() { - return "Args{" + - "parameters=" + parameters + - ", verbose=" + verbose + - ", groups='" + groups + '\'' + - ", debug=" + debug + - '}'; - } -} diff --git a/spring-shell-samples/src/main/java/org/springframework/shell/samples/jcommander/JCommanderCommands.java b/spring-shell-samples/src/main/java/org/springframework/shell/samples/jcommander/JCommanderCommands.java deleted file mode 100644 index ee5b59c1..00000000 --- a/spring-shell-samples/src/main/java/org/springframework/shell/samples/jcommander/JCommanderCommands.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2017 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.jcommander; - -import org.springframework.shell.standard.ShellComponent; -import org.springframework.shell.standard.ShellMethod; -import org.springframework.shell.standard.ShellOption; - -import javax.validation.Valid; - -/** - * A class with JCommander commands. - * - * @author Eric Bottard - */ -@ShellComponent -public class JCommanderCommands { - - @ShellMethod("Bind parameters to JCommander POJO.") - public String jcommander(@ShellOption(optOut = true) @Valid Args args) { - return "You said " + args; - } -} 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 deleted file mode 100644 index 94aac506..00000000 --- a/spring-shell-samples/src/main/java/org/springframework/shell/samples/noautoconf/NoAutoConf.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2017-2021 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.noautoconf; - -import org.springframework.boot.SpringApplication; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.shell.boot.JCommanderParameterResolverAutoConfiguration; -import org.springframework.shell.boot.JLineShellAutoConfiguration; -import org.springframework.shell.boot.SpringShellAutoConfiguration; -import org.springframework.shell.boot.StandardAPIAutoConfiguration; -import org.springframework.shell.boot.StandardCommandsAutoConfiguration; -import org.springframework.shell.samples.jcommander.JCommanderCommands; -import org.springframework.shell.samples.standard.Commands; -import org.springframework.shell.samples.standard.DynamicCommands; -import org.springframework.shell.samples.standard.TableCommands; -import org.springframework.shell.standard.FileValueProvider; - -/** - * This class shows how to use the full extent of Spring Shell without relying on Boot auto configuration. - * - * @author Eric Bottard - */ -@Configuration -@Import({ - // Core runtime - SpringShellAutoConfiguration.class, - JLineShellAutoConfiguration.class, - // Various Resolvers - JCommanderParameterResolverAutoConfiguration.class, - StandardAPIAutoConfiguration.class, - // Built-In Commands - StandardCommandsAutoConfiguration.class, - // Allows ${} support - //PropertyPlaceholderAutoConfiguration.class, - // Sample Commands - JCommanderCommands.class, - Commands.class, - FileValueProvider.class, - DynamicCommands.class, - TableCommands.class, - }) -public class NoAutoConf { - - public static void main(String[] args) { - SpringApplication.run(NoAutoConf.class, args); - } - -} diff --git a/spring-shell-samples/src/main/resources/application.yml b/spring-shell-samples/src/main/resources/application.yml index 60b6d1a6..ca84aebe 100644 --- a/spring-shell-samples/src/main/resources/application.yml +++ b/spring-shell-samples/src/main/resources/application.yml @@ -1,3 +1,3 @@ -spring: - main: - allow-circular-references: false \ No newline at end of file +logging: + level: + root: error diff --git a/spring-shell-samples/src/main/resources/logback.xml b/spring-shell-samples/src/main/resources/logback.xml deleted file mode 100644 index 9a8bf719..00000000 --- a/spring-shell-samples/src/main/resources/logback.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - -