Skip to content

Commit ff73bdc

Browse files
committed
Remove dependency to Spring Boot from core module
The main blockers were: - ApplicationArguments, used in ShellRunner#canRun - ApplicationRunner, extended by ShellApplicationRunner This commit: - removes deprecated APIs (ShellRunner#canRun methods) - removes ShellApplicationRunner as it became empty after the removal of "extends ApplicationRunner". Its default implementation was also removed as it only iterates over ShellRunner instances and invokes them. This commit also adds the necessary dependencies that were brought transitively by Spring Boot: - spring-context - slf4j-api - jakarta.validation-api Resolves #200
1 parent 36710fc commit ff73bdc

File tree

18 files changed

+123
-347
lines changed

18 files changed

+123
-347
lines changed

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,17 @@
5454
<jline.version>3.30.6</jline.version>
5555
<antlr-st4.version>4.3.4</antlr-st4.version>
5656
<commons-io.version>2.20.0</commons-io.version>
57+
<slf4j.version>2.0.17</slf4j.version>
58+
<jakarta.validation-api.version>3.1.1</jakarta.validation-api.version>
5759

5860
<!-- test dependencies -->
5961
<jimfs.version>1.3.1</jimfs.version>
6062
<assertj.version>3.27.4</assertj.version>
6163
<junit-jupiter.version>6.0.0</junit-jupiter.version>
6264
<mockito.version>5.19.0</mockito.version>
6365
<awaitility.version>4.3.0</awaitility.version>
66+
<hibernate-validator.version>9.0.1.Final</hibernate-validator.version>
67+
<jakarta.el.version>4.0.2</jakarta.el.version>
6468

6569
<!-- documentation dependencies -->
6670
<antora-maven-plugin.version>1.0.0-alpha.5</antora-maven-plugin.version>

spring-shell-autoconfigure/src/main/java/org/springframework/shell/boot/ApplicationRunnerAutoConfiguration.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 the original author or authors.
2+
* Copyright 2021-present the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,29 +15,17 @@
1515
*/
1616
package org.springframework.shell.boot;
1717

18-
import java.util.List;
19-
2018
import org.springframework.boot.autoconfigure.AutoConfiguration;
21-
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2219
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2320
import org.springframework.boot.context.event.ApplicationReadyEvent;
2421
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2522
import org.springframework.context.ApplicationListener;
2623
import org.springframework.context.annotation.Bean;
27-
import org.springframework.shell.DefaultShellApplicationRunner;
28-
import org.springframework.shell.ShellApplicationRunner;
29-
import org.springframework.shell.ShellRunner;
3024

3125
@AutoConfiguration
3226
@EnableConfigurationProperties(SpringShellProperties.class)
3327
public class ApplicationRunnerAutoConfiguration {
3428

35-
@Bean
36-
@ConditionalOnMissingBean(ShellApplicationRunner.class)
37-
public DefaultShellApplicationRunner defaultShellApplicationRunner(List<ShellRunner> shellRunners) {
38-
return new DefaultShellApplicationRunner(shellRunners);
39-
}
40-
4129
@Bean
4230
@ConditionalOnProperty(prefix = "spring.shell.context", name = "close", havingValue = "true")
4331
public ApplicationReadyEventListener applicationReadyEventListener() {

spring-shell-autoconfigure/src/main/java/org/springframework/shell/boot/StandardCommandsAutoConfiguration.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2022 the original author or authors.
2+
* Copyright 2017-present the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,6 +46,7 @@
4646
* Creates beans for standard commands.
4747
*
4848
* @author Eric Bottard
49+
* @author Mahmoud Ben Hassine
4950
*/
5051
@AutoConfiguration
5152
@ConditionalOnClass({ Help.Command.class })
@@ -113,19 +114,8 @@ public Completion completion(SpringShellProperties properties) {
113114
public Version version(SpringShellProperties properties, ObjectProvider<BuildProperties> buildProperties,
114115
ObjectProvider<GitProperties> gitProperties, ObjectProvider<TemplateExecutor> templateExecutor) {
115116
Version version = new Version(templateExecutor.getIfAvailable());
116-
version.setBuildProperties(buildProperties.getIfAvailable());
117-
version.setGitProperties(gitProperties.getIfAvailable());
118117
VersionCommand versionProperties = properties.getCommand().getVersion();
119118
version.setTemplate(versionProperties.getTemplate());
120-
version.setShowBuildArtifact(versionProperties.isShowBuildArtifact());
121-
version.setShowBuildGroup(versionProperties.isShowBuildGroup());
122-
version.setShowBuildName(versionProperties.isShowBuildName());
123-
version.setShowBuildTime(versionProperties.isShowBuildTime());
124-
version.setShowBuildVersion(versionProperties.isShowBuildVersion());
125-
version.setShowGitBranch(versionProperties.isShowGitBranch());
126-
version.setShowGitCommitId(versionProperties.isShowGitCommitId());
127-
version.setShowGitShortCommitId(versionProperties.isShowGitShortCommitId());
128-
version.setShowGitCommitTime(versionProperties.isShowGitCommitTime());
129119
return version;
130120
}
131121
}

spring-shell-core/pom.xml

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,9 @@
4343
<version>${reactor.version}</version>
4444
</dependency>
4545
<dependency>
46-
<groupId>org.springframework.boot</groupId>
47-
<artifactId>spring-boot-starter</artifactId>
48-
<version>${spring-boot.version}</version>
49-
</dependency>
50-
<dependency>
51-
<groupId>org.springframework.boot</groupId>
52-
<artifactId>spring-boot-starter-validation</artifactId>
53-
<version>${spring-boot.version}</version>
46+
<groupId>org.springframework</groupId>
47+
<artifactId>spring-context</artifactId>
48+
<version>${spring-framework.version}</version>
5449
</dependency>
5550
<dependency>
5651
<groupId>org.springframework</groupId>
@@ -72,6 +67,16 @@
7267
<artifactId>commons-io</artifactId>
7368
<version>${commons-io.version}</version>
7469
</dependency>
70+
<dependency>
71+
<groupId>org.slf4j</groupId>
72+
<artifactId>slf4j-api</artifactId>
73+
<version>${slf4j.version}</version>
74+
</dependency>
75+
<dependency>
76+
<groupId>jakarta.validation</groupId>
77+
<artifactId>jakarta.validation-api</artifactId>
78+
<version>${jakarta.validation-api.version}</version>
79+
</dependency>
7580

7681
<!-- Test dependencies -->
7782
<dependency>
@@ -116,5 +121,23 @@
116121
<version>${awaitility.version}</version>
117122
<scope>test</scope>
118123
</dependency>
124+
<dependency>
125+
<groupId>org.hibernate.validator</groupId>
126+
<artifactId>hibernate-validator</artifactId>
127+
<version>${hibernate-validator.version}</version>
128+
<scope>test</scope>
129+
</dependency>
130+
<dependency>
131+
<groupId>org.glassfish</groupId>
132+
<artifactId>jakarta.el</artifactId>
133+
<version>${jakarta.el.version}</version>
134+
<scope>test</scope>
135+
</dependency>
136+
<dependency>
137+
<groupId>org.slf4j</groupId>
138+
<artifactId>slf4j-simple</artifactId>
139+
<version>${slf4j.version}</version>
140+
<scope>test</scope>
141+
</dependency>
119142
</dependencies>
120143
</project>

spring-shell-core/src/main/java/org/springframework/shell/DefaultShellApplicationRunner.java

Lines changed: 0 additions & 87 deletions
This file was deleted.

spring-shell-core/src/main/java/org/springframework/shell/ShellApplicationRunner.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

spring-shell-core/src/main/java/org/springframework/shell/ShellRunner.java

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2024 the original author or authors.
2+
* Copyright 2021-present the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,43 +15,14 @@
1515
*/
1616
package org.springframework.shell;
1717

18-
import org.springframework.boot.ApplicationArguments;
19-
2018
/**
2119
* Interface for shell runners.
2220
*
2321
* @author Janne Valkealahti
22+
* @author Mahmoud Ben Hassine
2423
*/
2524
public interface ShellRunner {
2625

27-
/**
28-
* Checks if a particular shell runner can execute.
29-
*
30-
* For {@link #canRun(ApplicationArguments)} and
31-
* {@link #run(ApplicationArguments)} prefer {@link #run(String[])}.
32-
*
33-
* @param args the application arguments
34-
* @return true if shell runner can execute
35-
*/
36-
@Deprecated(since = "3.3.0", forRemoval = true)
37-
default boolean canRun(ApplicationArguments args) {
38-
return false;
39-
}
40-
41-
/**
42-
* Execute application.
43-
*
44-
* For {@link #canRun(ApplicationArguments)} and
45-
* {@link #run(ApplicationArguments)} prefer {@link #run(String[])}.
46-
*
47-
* @param args the application argumets
48-
* @throws Exception in errors
49-
*/
50-
@Deprecated(since = "3.3.0", forRemoval = true)
51-
default void run(ApplicationArguments args) throws Exception {
52-
throw new UnsupportedOperationException("Should get implemented together with canRun");
53-
}
54-
5526
/**
5627
* Execute {@code ShellRunner} with given args. Return value indicates if run
5728
* operation happened and no further runners should be used.

spring-shell-core/src/main/java/org/springframework/shell/command/annotation/support/CommandScanRegistrar.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 the original author or authors.
2+
* Copyright 2023-present the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,10 +19,8 @@
1919
import java.util.LinkedHashSet;
2020
import java.util.Set;
2121

22-
import org.springframework.beans.factory.BeanFactory;
2322
import org.springframework.beans.factory.config.BeanDefinition;
2423
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
25-
import org.springframework.boot.context.TypeExcludeFilter;
2624
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
2725
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
2826
import org.springframework.core.annotation.AnnotationAttributes;
@@ -42,6 +40,7 @@
4240
* {@link ImportBeanDefinitionRegistrar} for {@link CommandScan @CommandScan}.
4341
*
4442
* @author Janne Valkealahti
43+
* @author Mahmoud Ben Hassine
4544
*/
4645
public class CommandScanRegistrar implements ImportBeanDefinitionRegistrar {
4746

@@ -91,9 +90,6 @@ private ClassPathScanningCandidateComponentProvider getScanner(BeanDefinitionReg
9190
scanner.setEnvironment(this.environment);
9291
scanner.setResourceLoader(this.resourceLoader);
9392
scanner.addIncludeFilter(new AnnotationTypeFilter(Command.class));
94-
TypeExcludeFilter typeExcludeFilter = new TypeExcludeFilter();
95-
typeExcludeFilter.setBeanFactory((BeanFactory) registry);
96-
scanner.addExcludeFilter(typeExcludeFilter);
9793
return scanner;
9894
}
9995

spring-shell-core/src/main/java/org/springframework/shell/result/ResultHandlerConfig.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2023 the original author or authors.
2+
* Copyright 2017-present the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,11 +18,9 @@
1818
import org.jline.terminal.Terminal;
1919

2020
import org.springframework.beans.factory.ObjectProvider;
21-
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2221
import org.springframework.context.annotation.Bean;
2322
import org.springframework.context.annotation.Configuration;
2423
import org.springframework.core.annotation.Order;
25-
import org.springframework.shell.TerminalSizeAware;
2624
import org.springframework.shell.command.CommandCatalog;
2725
import org.springframework.shell.command.CommandExceptionResolver;
2826
import org.springframework.shell.command.CommandParserExceptionResolver;
@@ -34,12 +32,12 @@
3432
*
3533
* @author Eric Bottard
3634
* @author Janne Valkealahti
35+
* @author Mahmoud Ben Hassine
3736
*/
3837
@Configuration(proxyBeanMethods = false)
3938
public class ResultHandlerConfig {
4039

4140
@Bean
42-
@ConditionalOnClass(TerminalSizeAware.class)
4341
public TerminalSizeAwareResultHandler terminalSizeAwareResultHandler(Terminal terminal) {
4442
return new TerminalSizeAwareResultHandler(terminal);
4543
}

0 commit comments

Comments
 (0)