Skip to content

Commit 62aec63

Browse files
authored
Revert "Reusable Execution Context (#792)"
This reverts commit 0090e2e.
1 parent 0090e2e commit 62aec63

File tree

139 files changed

+2498
-4117
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+2498
-4117
lines changed

applications/spring-shell/pom.xml

-7
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,6 @@
124124
<artifactId>sbm-recipes-boot-upgrade</artifactId>
125125
<version>0.13.1-SNAPSHOT</version>
126126
</dependency>
127-
<dependency>
128-
<groupId>org.springframework.sbm</groupId>
129-
<artifactId>sbm-core</artifactId>
130-
<version>${project.version}</version>
131-
<classifier>tests</classifier>
132-
<scope>test</scope>
133-
</dependency>
134127
</dependencies>
135128

136129
<build>

applications/spring-shell/src/test/java/org/springframework/sbm/architecture/FindIllegalExecutionContextCreationsTest.java

-31
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import static org.assertj.core.api.Assertions.assertThat;
2121

22-
class ApplyRecipeCommandHeaderRendererTest {
22+
class ScanCommandHeaderRendererTest {
2323

2424
@Test
2525
void renderHeader() {

components/openrewrite-spring-recipes/src/main/java/org/springframework/sbm/spring/migration/actions/InitDataSourceAfterJpaInitAction.java

+2-8
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
*/
1616
package org.springframework.sbm.spring.migration.actions;
1717

18-
import com.fasterxml.jackson.annotation.JsonIgnore;
19-
import org.openrewrite.ExecutionContext;
20-
import org.springframework.beans.factory.annotation.Autowired;
2118
import org.springframework.sbm.engine.recipe.AbstractAction;
2219
import org.springframework.sbm.engine.recipe.UserInteractions;
2320
import org.springframework.sbm.common.migration.conditions.FileExist;
@@ -31,11 +28,8 @@
3128
public class InitDataSourceAfterJpaInitAction extends AbstractAction {
3229

3330
public static final String QUESTION = "Would you rather run the SQL init scripts after JPA initialization?";
34-
private final UserInteractions ui;
3531

36-
@Autowired
37-
@JsonIgnore
38-
private ExecutionContext executionContext;
32+
private final UserInteractions ui;
3933

4034
public InitDataSourceAfterJpaInitAction(UserInteractions ui) {
4135
this.ui = ui;
@@ -50,7 +44,7 @@ public void apply(ProjectContext context) {
5044
SpringBootApplicationProperties applicationProperties;
5145
if (filteredResources.isEmpty()) {
5246
Path path = context.getBuildFile().getResourceFolders().get(0).resolve("application.properties");
53-
applicationProperties = SpringBootApplicationProperties.newApplicationProperties(context.getProjectRootDirectory(), path, executionContext);
47+
applicationProperties = SpringBootApplicationProperties.newApplicationProperties(context.getProjectRootDirectory(), path);
5448
context.getProjectResources().add(applicationProperties);
5549
} else {
5650
applicationProperties = filteredResources.get(0);

components/recipe-test-support/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
<dependency>
6363
<groupId>org.springframework.sbm</groupId>
6464
<artifactId>sbm-core</artifactId>
65-
<version>${project.version}</version>
65+
<version>0.13.1-SNAPSHOT</version>
6666
<type>test-jar</type>
6767
<scope>compile</scope>
6868
</dependency>

components/recipe-test-support/src/main/java/org/springframework/sbm/test/RecipeTestSupport.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
import org.springframework.sbm.project.resource.ProjectResourceSetHolder;
2929
import org.springframework.sbm.project.resource.SbmApplicationProperties;
3030
import org.springframework.sbm.project.resource.ResourceHelper;
31-
import org.springframework.sbm.scopeplayground.ExecutionScope;
32-
import org.springframework.sbm.scopeplayground.ScanScope;
33-
import org.springframework.sbm.scopeplayground.ScopeConfiguration;
3431
import org.springframework.sbm.search.recipe.actions.OpenRewriteJavaSearchAction;
3532
import org.springframework.context.annotation.Bean;
3633
import org.springframework.context.annotation.Configuration;
@@ -80,10 +77,7 @@ private RecipeTestSupport() {
8077
RewriteMavenParser.class,
8178
MavenSettingsInitializer.class,
8279
MavenBuildFileRefactoringFactory.class,
83-
ProjectResourceSetHolder.class,
84-
ScopeConfiguration.class,
85-
ExecutionScope.class,
86-
ScanScope.class
80+
ProjectResourceSetHolder.class
8781
};
8882

8983

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2021 - 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.sbm.test;
17+
18+
import org.springframework.boot.context.annotation.Configurations;
19+
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
20+
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
21+
import org.springframework.boot.test.context.runner.ContextConsumer;
22+
import org.springframework.context.annotation.ComponentScan;
23+
import org.springframework.context.annotation.Configuration;
24+
25+
public class SpringBeanProvider {
26+
27+
@Configuration
28+
@ComponentScan("org.springframework.sbm")
29+
public static class ComponentScanConfiguration { }
30+
31+
public static void run(ContextConsumer<AssertableApplicationContext> testcode, Class<?>... springBeans) {
32+
ApplicationContextRunner contextRunner = new ApplicationContextRunner();
33+
for (Class<?> springBean : springBeans) {
34+
if(springBean.isAssignableFrom(Configurations.class)) {
35+
Configurations c = Configurations.class.cast(springBean);
36+
contextRunner.withConfiguration(c);
37+
} else {
38+
contextRunner = contextRunner.withBean(springBean);
39+
}
40+
}
41+
contextRunner.run(testcode);
42+
}
43+
}

components/sbm-core/pom.xml

+1-14
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@
3838
<artifactId>spring-boot-starter-freemarker</artifactId>
3939
</dependency>
4040

41-
<dependency>
42-
<groupId>com.tngtech.archunit</groupId>
43-
<artifactId>archunit-junit5</artifactId>
44-
<version>1.0.1</version>
45-
<scope>test</scope>
46-
</dependency>
47-
4841
<dependency>
4942
<groupId>org.springframework.boot</groupId>
5043
<artifactId>spring-boot-starter-test</artifactId>
@@ -182,13 +175,7 @@
182175
</goals>
183176
</execution>
184177
</executions>
185-
<configuration>
186-
<excludes>
187-
<!-- Would be picked up by component scan in other modules -->
188-
<exclude>**/org/springframework/sbm/archfitfun/**</exclude>
189-
</excludes>
190-
</configuration>
191178
</plugin>
192179
</plugins>
193180
</build>
194-
</project>
181+
</project>
+2-10
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,10 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.sbm.scopeplayground;
17-
18-
import org.springframework.stereotype.Component;
16+
package org.springframework.sbm.build;
1917

2018
/**
21-
* Scope implementation for beans marked with {@link org.springframework.sbm.scopeplayground.annotations.ScanScope}.
22-
*
2319
* @author Fabian Krüger
2420
*/
25-
@Component
26-
public class ScanScope extends AbstractBaseScope {
27-
28-
public final static String SCOPE_NAME = "scanScope";
29-
21+
public class Foo {
3022
}

components/sbm-core/src/main/java/org/springframework/sbm/build/api/Module.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.sbm.build.api;
1717

18-
import org.openrewrite.ExecutionContext;
1918
import org.openrewrite.java.JavaParser;
2019
import org.openrewrite.maven.tree.MavenResolutionResult;
2120
import org.springframework.sbm.build.impl.JavaSourceSetImpl;
@@ -56,7 +55,6 @@ public class Module {
5655
private final JavaRefactoringFactory javaRefactoringFactory;
5756
private final BasePackageCalculator basePackageCalculator;
5857
private final JavaParser javaParser;
59-
private final ExecutionContext executionContext;
6058

6159
public JavaSourceLocation getBaseJavaSourceLocation() {
6260
return getMainJavaSourceSet().getJavaSourceLocation();
@@ -69,8 +67,7 @@ public JavaSourceLocation getBaseTestJavaSourceLocation() {
6967
public JavaSourceSet getTestJavaSourceSet() {
7068
Path testJavaPath = Path.of("src/test/java");
7169
// FIXME: #7 JavaParser
72-
return new JavaSourceSetImpl(projectResourceSet, projectRootDir, modulePath, testJavaPath, javaRefactoringFactory, basePackageCalculator, javaParser,
73-
executionContext);
70+
return new JavaSourceSetImpl(projectResourceSet, projectRootDir, modulePath, testJavaPath, javaRefactoringFactory, basePackageCalculator, javaParser);
7471
}
7572

7673
public List<? extends JavaSource> getMainJavaSources() {
@@ -86,8 +83,7 @@ public List<? extends JavaSource> getTestJavaSources() {
8683
public JavaSourceSet getMainJavaSourceSet() {
8784
Path mainJavaPath = Path.of("src/main/java");
8885
// return new JavaSourceSetImpl(projectResourceSet, projectRootDir.resolve(modulePath).resolve(mainJavaPath), javaRefactoringFactory);
89-
return new JavaSourceSetImpl(projectResourceSet, projectRootDir, modulePath, mainJavaPath, javaRefactoringFactory, basePackageCalculator, javaParser,
90-
executionContext);
86+
return new JavaSourceSetImpl(projectResourceSet, projectRootDir, modulePath, mainJavaPath, javaRefactoringFactory, basePackageCalculator, javaParser);
9187
}
9288

9389
private List<JavaSource> cast(List<RewriteSourceFileHolder<? extends SourceFile>> filter) {
@@ -116,12 +112,12 @@ public Path getProjectRootDirectory() {
116112

117113
public ResourceSet getMainResourceSet() {
118114
Path mainResourceSet = buildFile.getMainResourceFolder();
119-
return new ResourceSet(projectResourceSet, projectRootDir, modulePath, mainResourceSet, executionContext);
115+
return new ResourceSet(projectResourceSet, projectRootDir, modulePath, mainResourceSet);
120116
}
121117

122118
public ResourceSet getTestResourceSet() {
123119
Path testResourceSet = buildFile.getTestResourceFolder();
124-
return new ResourceSet(projectResourceSet, projectRootDir, modulePath, testResourceSet, executionContext);
120+
return new ResourceSet(projectResourceSet, projectRootDir, modulePath, testResourceSet);
125121
}
126122

127123
public List<Module> getModules() {
@@ -131,7 +127,7 @@ public List<Module> getModules() {
131127
return modulesMarker
132128
.stream()
133129
.map(m -> new Module(m.getPom().getGav().toString(), this.buildFile, projectRootDir, modulePath,
134-
projectResourceSet, javaRefactoringFactory, basePackageCalculator, javaParser, executionContext))
130+
projectResourceSet, javaRefactoringFactory, basePackageCalculator, javaParser))
135131
.collect(Collectors.toList());
136132
} else {
137133
return new ArrayList<>();

components/sbm-core/src/main/java/org/springframework/sbm/build/api/ResourceSet.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.sbm.build.api;
1717

18-
import org.openrewrite.ExecutionContext;
1918
import org.springframework.sbm.project.resource.ProjectResourceSet;
2019
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
2120
import org.springframework.sbm.project.resource.StringProjectResource;
@@ -31,11 +30,10 @@ public class ResourceSet {
3130
private final Path projectRoot;
3231
private final Path modulePath;
3332
private final Path resourceSetPath;
34-
private final ExecutionContext executionContext;
3533

3634
public void addStringResource(String filePath, String content) {
3735
Path absFilePath = getAbsolutePath().resolve(filePath);
38-
StringProjectResource resource = new StringProjectResource(projectRoot, absFilePath, content, executionContext);
36+
StringProjectResource resource = new StringProjectResource(projectRoot, absFilePath, content);
3937
resource.markAsChanged();
4038
projectResourceSet.add(resource);
4139
}

components/sbm-core/src/main/java/org/springframework/sbm/build/api/SpringManagedDependencies.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
*/
1616
package org.springframework.sbm.build.api;
1717

18-
import org.openrewrite.ExecutionContext;
1918
import org.openrewrite.maven.MavenDownloadingException;
2019
import org.openrewrite.maven.internal.MavenPomDownloader;
2120
import org.openrewrite.maven.tree.GroupArtifactVersion;
2221
import org.openrewrite.maven.tree.MavenRepository;
22+
import org.springframework.sbm.openrewrite.RewriteExecutionContext;
2323

2424
import java.util.Collections;
2525
import java.util.HashMap;
@@ -39,17 +39,17 @@ public class SpringManagedDependencies {
3939
private List<org.openrewrite.maven.tree.Dependency> dependencies;
4040
private static Map<GroupArtifactVersion, SpringManagedDependencies> INSTANCES = new HashMap<>();
4141

42-
public static SpringManagedDependencies by(String groupId, String artifact, String version, ExecutionContext executionContext){
42+
public static SpringManagedDependencies by(String groupId, String artifact, String version){
4343
final GroupArtifactVersion groupArtifactVersion =
4444
new GroupArtifactVersion(groupId, artifact, version);
4545

46-
INSTANCES.computeIfAbsent(groupArtifactVersion, gav -> new SpringManagedDependencies(gav, executionContext));
46+
INSTANCES.computeIfAbsent(groupArtifactVersion, SpringManagedDependencies::new);
4747
return INSTANCES.get(groupArtifactVersion);
4848
}
4949

50-
private SpringManagedDependencies(GroupArtifactVersion groupArtifactVersion, ExecutionContext executionContext){
50+
private SpringManagedDependencies(GroupArtifactVersion groupArtifactVersion){
5151
try {
52-
dependencies = new MavenPomDownloader(Collections.emptyMap(), executionContext)
52+
dependencies = new MavenPomDownloader(Collections.emptyMap(), new RewriteExecutionContext())
5353
.download(groupArtifactVersion, null, null, SPRING_REPOSITORIES)
5454
.getDependencies();
5555
} catch (MavenDownloadingException e) {

components/sbm-core/src/main/java/org/springframework/sbm/build/impl/JavaSourceSetImpl.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.sbm.build.impl;
1717

18-
import org.openrewrite.ExecutionContext;
1918
import org.springframework.sbm.build.api.JavaSourceSet;
2019
import org.springframework.sbm.java.api.JavaSource;
2120
import org.springframework.sbm.java.api.JavaSourceLocation;
@@ -45,13 +44,11 @@ public class JavaSourceSetImpl implements JavaSourceSet {
4544
private final JavaRefactoringFactory javaRefactoringFactory;
4645
private final BasePackageCalculator basePackageCalculator;
4746
private final JavaParser javaParser;
48-
private ExecutionContext executionContext;
4947

50-
public JavaSourceSetImpl(ProjectResourceSet projectResourceSet, Path projectRootDir, Path modulePath, Path mainJavaPath, JavaRefactoringFactory javaRefactoringFactory, BasePackageCalculator basePackageCalculator, JavaParser javaParser, ExecutionContext executionContext) {
48+
public JavaSourceSetImpl(ProjectResourceSet projectResourceSet, Path projectRootDir, Path modulePath, Path mainJavaPath, JavaRefactoringFactory javaRefactoringFactory, BasePackageCalculator basePackageCalculator, JavaParser javaParser) {
5149
this.projectResourceSet = projectResourceSet;
5250
this.basePackageCalculator = basePackageCalculator;
5351
this.javaParser = javaParser;
54-
this.executionContext = executionContext;
5552
this.sourceSetRoot = projectRootDir.resolve(modulePath).resolve(mainJavaPath);
5653
this.filter = (r) -> {
5754
return r.getAbsolutePath().getParent().normalize().toString().startsWith(sourceSetRoot.toString());
@@ -76,7 +73,7 @@ public JavaSource addJavaSource(Path projectRoot, Path sourceFolder, String sour
7673
throw new RuntimeException("The Java class you tried to add already lives here: '" + sourceFilePath + "'.");
7774
} else {
7875
J.CompilationUnit compilationUnit = parsedCompilationUnit.withSourcePath(sourceFilePath);
79-
OpenRewriteJavaSource addedSource = new OpenRewriteJavaSource(projectRoot, compilationUnit, javaRefactoringFactory.createRefactoring(compilationUnit), javaParser, executionContext);
76+
OpenRewriteJavaSource addedSource = new OpenRewriteJavaSource(projectRoot, compilationUnit, javaRefactoringFactory.createRefactoring(compilationUnit), javaParser);
8077
addedSource.markChanged();
8178
projectResourceSet.add(addedSource);
8279
return addedSource;
@@ -97,7 +94,7 @@ public List<JavaSource> addJavaSource(Path projectRoot, Path sourceFolder, Strin
9794
Path sourceFilePath = sourceFolder.resolve(sourceFileName);
9895
if(!Files.exists(sourceFilePath)) {
9996
J.CompilationUnit compilationUnit = cu.withSourcePath(sourceFilePath);
100-
OpenRewriteJavaSource addedSource = new OpenRewriteJavaSource(projectRoot, compilationUnit, javaRefactoringFactory.createRefactoring(compilationUnit), javaParser, executionContext);
97+
OpenRewriteJavaSource addedSource = new OpenRewriteJavaSource(projectRoot, compilationUnit, javaRefactoringFactory.createRefactoring(compilationUnit), javaParser);
10198
addedSource.markChanged();
10299
projectResourceSet.add(addedSource);
103100
addedSources.add(addedSource);

0 commit comments

Comments
 (0)