From cdbbf1d96dfb2f0180d1f5b130593ac62533b4ef Mon Sep 17 00:00:00 2001 From: Janne Valkealahti Date: Sun, 10 Mar 2024 13:48:54 +0000 Subject: [PATCH] Only NonInteractiveShellRunner is active on default - Disable InteractiveShellRunner and ScriptShellRunner on default - Enable those in commands and e2e sample apps - Document changes - Fixes #1017 --- .../boot/ShellRunnerAutoConfiguration.java | 6 ++--- .../ShellRunnerAutoConfigurationTests.java | 13 ++++++----- .../modules/ROOT/pages/execution.adoc | 22 ++++++++++++++++--- .../src/main/resources/application.yml | 2 ++ .../src/main/resources/application.yml | 2 ++ 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/spring-shell-autoconfigure/src/main/java/org/springframework/shell/boot/ShellRunnerAutoConfiguration.java b/spring-shell-autoconfigure/src/main/java/org/springframework/shell/boot/ShellRunnerAutoConfiguration.java index 041b9391..491cc317 100644 --- a/spring-shell-autoconfigure/src/main/java/org/springframework/shell/boot/ShellRunnerAutoConfiguration.java +++ b/spring-shell-autoconfigure/src/main/java/org/springframework/shell/boot/ShellRunnerAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2023 the original author or authors. + * Copyright 2021-2024 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. @@ -59,7 +59,7 @@ public class ShellRunnerAutoConfiguration { public static class NonePrimaryCommandConfiguration { @Bean - @ConditionalOnProperty(prefix = "spring.shell.interactive", value = "enabled", havingValue = "true", matchIfMissing = true) + @ConditionalOnProperty(prefix = "spring.shell.interactive", value = "enabled", havingValue = "true", matchIfMissing = false) public InteractiveShellRunner interactiveApplicationRunner(LineReader lineReader, PromptProvider promptProvider, Shell shell, ShellContext shellContext) { return new InteractiveShellRunner(lineReader, promptProvider, shell, shellContext); @@ -75,7 +75,7 @@ public class ShellRunnerAutoConfiguration { } @Bean - @ConditionalOnProperty(prefix = "spring.shell.script", value = "enabled", havingValue = "true", matchIfMissing = true) + @ConditionalOnProperty(prefix = "spring.shell.script", value = "enabled", havingValue = "true", matchIfMissing = false) public ScriptShellRunner scriptApplicationRunner(Parser parser, Shell shell) { return new ScriptShellRunner(parser, shell); } diff --git a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/ShellRunnerAutoConfigurationTests.java b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/ShellRunnerAutoConfigurationTests.java index 119f68c1..cb0c2f90 100644 --- a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/ShellRunnerAutoConfigurationTests.java +++ b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/ShellRunnerAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 the original author or authors. + * Copyright 2022-2024 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. @@ -53,9 +53,10 @@ class ShellRunnerAutoConfigurationTests { @Nested class Interactive { + @Test - void enabledByDefault() { - contextRunner.run(context -> assertThat(context).hasSingleBean(InteractiveShellRunner.class)); + void disabledByDefault() { + contextRunner.run(context -> assertThat(context).doesNotHaveBean(InteractiveShellRunner.class)); } @Test @@ -67,6 +68,7 @@ class ShellRunnerAutoConfigurationTests { @Nested class NonInteractive { + @Test void enabledByDefault() { contextRunner.run(context -> assertThat(context).hasSingleBean(NonInteractiveShellRunner.class)); @@ -101,9 +103,10 @@ class ShellRunnerAutoConfigurationTests { @Nested class Script { + @Test - void enabledByDefault() { - contextRunner.run(context -> assertThat(context).hasSingleBean(ScriptShellRunner.class)); + void disabledByDefault() { + contextRunner.run(context -> assertThat(context).doesNotHaveBean(ScriptShellRunner.class)); } @Test diff --git a/spring-shell-docs/modules/ROOT/pages/execution.adoc b/spring-shell-docs/modules/ROOT/pages/execution.adoc index 75c90293..a5bebb98 100644 --- a/spring-shell-docs/modules/ROOT/pages/execution.adoc +++ b/spring-shell-docs/modules/ROOT/pages/execution.adoc @@ -31,6 +31,22 @@ and its default implementation makes a choice which `ShellRunner` is used. There only one `ShellApplicationRunner` but it can be redefined if needed for some reason. Three `ShellRunner` implementation exists, named `InteractiveShellRunner`, -`NonInteractiveShellRunner` and `ScriptShellRunner`. These are enabled on default but -can be disable if needed using properties `spring.shell.interactive.enabled`, -`spring.shell.noninteractive.enabled` and `spring.shell.script.enabled` respecively. +`NonInteractiveShellRunner` and `ScriptShellRunner`. Only `NonInteractiveShellRunner` +is enabled by default. Enabled state can be modified using properties +`spring.shell.interactive.enabled`, `spring.shell.noninteractive.enabled` and +`spring.shell.script.enabled` respecively. + +For example enabling interactive and script runners use properties: + +[source, yaml] +---- +spring: + shell: + interactive: + enabled: true + script: + enabled: true +---- + +NOTE: Versions up to `3.2.x` had all runners enabled by default, starting from `3.3.x` + only `NonInteractiveShellRunner` is enabled by default. diff --git a/spring-shell-samples/spring-shell-sample-commands/src/main/resources/application.yml b/spring-shell-samples/spring-shell-sample-commands/src/main/resources/application.yml index 25542e94..37ebaf0b 100644 --- a/spring-shell-samples/spring-shell-sample-commands/src/main/resources/application.yml +++ b/spring-shell-samples/spring-shell-sample-commands/src/main/resources/application.yml @@ -2,6 +2,8 @@ spring: main: banner-mode: off shell: + interactive: + enabled: true ## pick global default option naming # option: # naming: diff --git a/spring-shell-samples/spring-shell-sample-e2e/src/main/resources/application.yml b/spring-shell-samples/spring-shell-sample-e2e/src/main/resources/application.yml index 25542e94..37ebaf0b 100644 --- a/spring-shell-samples/spring-shell-sample-e2e/src/main/resources/application.yml +++ b/spring-shell-samples/spring-shell-sample-e2e/src/main/resources/application.yml @@ -2,6 +2,8 @@ spring: main: banner-mode: off shell: + interactive: + enabled: true ## pick global default option naming # option: # naming: