Skip to content

Commit 4db1427

Browse files
committed
Adds commits not pushed into 786-reusable-execution-context
1 parent 7e0ae27 commit 4db1427

File tree

45 files changed

+825
-80
lines changed

Some content is hidden

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

45 files changed

+825
-80
lines changed

applications/spring-boot-upgrade/pom.xml

+7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
<groupId>org.springframework.boot</groupId>
4848
<artifactId>spring-boot-starter-web</artifactId>
4949
</dependency>
50+
<dependency>
51+
<groupId>org.springframework.sbm</groupId>
52+
<artifactId>sbm-core</artifactId>
53+
<version>${project.version}</version>
54+
<classifier>tests</classifier>
55+
<scope>test</scope>
56+
</dependency>
5057
</dependencies>
5158

5259
<build>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.architecture;
17+
18+
import com.tngtech.archunit.core.importer.ImportOption;
19+
import com.tngtech.archunit.junit.AnalyzeClasses;
20+
import com.tngtech.archunit.junit.ArchTest;
21+
import com.tngtech.archunit.junit.ArchTests;
22+
23+
/**
24+
* @author Fabian Krüger
25+
*/
26+
@AnalyzeClasses(packages = {"org.springframework.sbm", "org.openrewrite"}, importOptions = {ImportOption.DoNotIncludeTests.class, ImportOption.DoNotIncludeJars.class})
27+
public class FindIllegalExecutionContextCreationsTest {
28+
@ArchTest
29+
static final ArchTests executionContextMustNotBeCreatedWithNew = ArchTests.in(
30+
ControlledInstantiationOfExecutionContextTest.class);
31+
}

ci/pipeline.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ jobs:
159159

160160
# Build every new PR
161161

162+
162163
- name: create-github-release
163164
serial: true
164165
plan:
@@ -194,10 +195,10 @@ jobs:
194195
- git-repo/applications/spring-boot-upgrade/target/spring-boot-upgrade.jar
195196
- git-repo/applications/spring-shell/target/spring-boot-migrator.jar
196197
groups:
198+
- name: "builds"
199+
jobs: ["build"]
197200
- name: "ci-images"
198201
jobs: ["build-ci-images"]
199-
- name: "pull-requests"
200-
jobs: ["build-pull-requests"]
201202
- name: "releases"
202203
jobs: ["create-github-release"]
203204

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

+14-11
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,17 @@
1515
*/
1616
package org.springframework.sbm.spring.migration.actions;
1717

18-
import org.springframework.sbm.engine.recipe.AbstractAction;
19-
import org.springframework.sbm.engine.context.ProjectContext;
20-
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
21-
import org.springframework.sbm.project.resource.filter.GenericTypeListFilter;
18+
import com.fasterxml.jackson.annotation.JsonIgnore;
2219
import lombok.extern.slf4j.Slf4j;
23-
import org.openrewrite.InMemoryExecutionContext;
24-
import org.openrewrite.Recipe;
25-
import org.openrewrite.Result;
26-
import org.openrewrite.SourceFile;
20+
import org.openrewrite.*;
2721
import org.openrewrite.properties.PropertiesParser;
2822
import org.openrewrite.xml.XmlParser;
2923
import org.openrewrite.yaml.YamlParser;
24+
import org.springframework.beans.factory.annotation.Autowired;
25+
import org.springframework.sbm.engine.context.ProjectContext;
26+
import org.springframework.sbm.engine.recipe.AbstractAction;
27+
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
28+
import org.springframework.sbm.project.resource.filter.GenericTypeListFilter;
3029

3130
import java.io.IOException;
3231
import java.nio.file.Files;
@@ -40,6 +39,10 @@ public class OpenRewriteRecipeAdapterAction extends AbstractAction {
4039

4140
private final Recipe recipe;
4241

42+
@JsonIgnore
43+
@Autowired
44+
private ExecutionContext executionContext;
45+
4346
public OpenRewriteRecipeAdapterAction(org.openrewrite.Recipe recipe) {
4447
this.recipe = recipe;
4548
}
@@ -70,7 +73,7 @@ public void apply(ProjectContext context) {
7073
.filter(Objects::nonNull)
7174
.filter(it -> it.getFileName().toString().endsWith(".yml") || it.endsWith(".yaml"))
7275
.collect(Collectors.toList()),
73-
null, new InMemoryExecutionContext()
76+
null, executionContext
7477
)
7578
);
7679

@@ -82,7 +85,7 @@ null, new InMemoryExecutionContext()
8285
.filter(it -> it.getFileName().toString().endsWith(".properties"))
8386
.collect(Collectors.toList()),
8487
null,
85-
new InMemoryExecutionContext()
88+
executionContext
8689
)
8790
);
8891

@@ -94,7 +97,7 @@ null, new InMemoryExecutionContext()
9497
.filter(it -> it.getFileName().toString().endsWith(".xml"))
9598
.collect(Collectors.toList()),
9699
null,
97-
new InMemoryExecutionContext())
100+
executionContext)
98101
);
99102

100103
List<Result> res = recipe.run(sourceFiles).getResults();

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

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

18-
import com.fasterxml.jackson.databind.ObjectMapper;
1918
import org.springframework.sbm.build.impl.MavenBuildFileRefactoringFactory;
2019
import org.springframework.sbm.build.impl.MavenSettingsInitializer;
2120
import org.springframework.sbm.build.impl.RewriteMavenParser;
@@ -28,10 +27,9 @@
2827
import org.springframework.sbm.project.resource.ProjectResourceSetHolder;
2928
import org.springframework.sbm.project.resource.SbmApplicationProperties;
3029
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;
34-
import org.springframework.sbm.search.recipe.actions.OpenRewriteJavaSearchAction;
30+
import org.springframework.sbm.scopes.ExecutionScope;
31+
import org.springframework.sbm.scopes.ScanScope;
32+
import org.springframework.sbm.scopes.ScopeConfiguration;
3533
import org.springframework.context.annotation.Bean;
3634
import org.springframework.context.annotation.Configuration;
3735
import org.springframework.context.annotation.Primary;

components/sbm-core/src/main/java/org/springframework/sbm/engine/commands/ApplicableRecipeListCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.springframework.sbm.engine.recipe.Recipes;
2323
import org.springframework.sbm.engine.recipe.RecipesBuilder;
2424
import org.springframework.sbm.project.parser.ProjectContextInitializer;
25-
import org.springframework.sbm.scopeplayground.ExecutionScope;
25+
import org.springframework.sbm.scopes.ExecutionScope;
2626
import org.springframework.stereotype.Component;
2727

2828
import java.util.List;

components/sbm-core/src/main/java/org/springframework/sbm/engine/commands/ApplyCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.springframework.sbm.engine.recipe.Action;
2929
import org.springframework.sbm.engine.recipe.Recipe;
3030
import org.springframework.sbm.engine.recipe.RecipesBuilder;
31-
import org.springframework.sbm.scopeplayground.ExecutionScope;
31+
import org.springframework.sbm.scopes.ExecutionScope;
3232
import org.springframework.stereotype.Component;
3333

3434
import java.util.List;

components/sbm-core/src/main/java/org/springframework/sbm/engine/commands/ScanCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.springframework.sbm.engine.precondition.PreconditionVerifier;
2727
import org.springframework.sbm.project.parser.PathScanner;
2828
import org.springframework.sbm.project.parser.ProjectContextInitializer;
29-
import org.springframework.sbm.scopeplayground.ScanScope;
29+
import org.springframework.sbm.scopes.ScanScope;
3030
import org.springframework.stereotype.Component;
3131

3232
import java.nio.file.Path;

components/sbm-core/src/main/java/org/springframework/sbm/engine/recipe/OpenRewriteRecipeAdapterAction.java

+6-17
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,15 @@
1818

1919
import com.fasterxml.jackson.annotation.JsonIgnore;
2020
import lombok.extern.slf4j.Slf4j;
21-
import org.openrewrite.*;
2221
import org.openrewrite.Recipe;
22+
import org.openrewrite.Result;
23+
import org.openrewrite.SourceFile;
2324
import org.springframework.beans.factory.annotation.Autowired;
24-
import org.springframework.sbm.common.filter.AbsolutePathResourceFinder;
2525
import org.springframework.sbm.engine.context.ProjectContext;
26-
import org.springframework.sbm.project.RewriteSourceFileWrapper;
27-
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
2826

29-
import java.nio.file.Path;
30-
import java.util.*;
27+
import java.util.List;
3128

3229
@Slf4j
33-
//@RequiredArgsConstructor
3430
public class OpenRewriteRecipeAdapterAction extends AbstractAction {
3531

3632
private final Recipe recipe;
@@ -39,30 +35,23 @@ public class OpenRewriteRecipeAdapterAction extends AbstractAction {
3935
@Autowired
4036
private RewriteMigrationResultMerger resultMerger;
4137

42-
// private final ModifiableProjectResourceFactory modifiableProjectResourceFactory = new ModifiableProjectResourceFactory();
43-
44-
4538
@Override
4639
public boolean isApplicable(ProjectContext context) {
4740
return true;
4841
// FIXME: use getApplicableTest and getSingleSourceApplicableTest to calculate
49-
/*
50-
Method getApplicableTest = ReflectionUtils.findMethod(Recipe.class, "getApplicableTest");
42+
/*Method getApplicableTest = ReflectionUtils.findMethod(Recipe.class, "getApplicableTest");
5143
ReflectionUtils.makeAccessible(getApplicableTest);
5244
try {
5345
TreeVisitor<?, ExecutionContext> visitor = (TreeVisitor<?, ExecutionContext>) getApplicableTest.invoke(recipe);
5446
if(visitor == null) {
5547
return true;
5648
} else {
57-
List<SourceFile> search = context.search(new OpenRewriteSourceFileFinder());
49+
List<SourceFile> search = context.search(new OpenRewriteSourceFilesFinder());
5850
return visitor.visit(search, new InMemoryExecutionContext());
5951
}
6052
} catch (IllegalAccessException e) {
6153
throw new RuntimeException(e);
62-
} catch (InvocationTargetException e) {
63-
throw new RuntimeException(e);
64-
}
65-
*/
54+
}*/
6655
}
6756

6857
public OpenRewriteRecipeAdapterAction(Recipe recipe) {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
import org.openrewrite.java.JavaParser;
2323
import org.openrewrite.java.marker.JavaSourceSet;
2424
import org.openrewrite.java.tree.J;
25+
import org.springframework.sbm.project.resource.SbmApplicationProperties;
26+
import org.springframework.sbm.scopes.annotations.ScanScope;
2527
import org.springframework.sbm.engine.annotations.StatefulComponent;
2628
import org.springframework.sbm.project.resource.SbmApplicationProperties;
27-
import org.springframework.sbm.scopeplayground.annotations.ScanScope;
2829
import org.springframework.stereotype.Component;
2930

3031
import java.net.URI;

components/sbm-core/src/main/java/org/springframework/sbm/project/parser/MavenProjectParser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import org.springframework.sbm.build.impl.MavenBuildFileUtil;
3939
import org.springframework.sbm.build.impl.RewriteMavenParser;
4040
import org.springframework.sbm.engine.events.*;
41-
import org.springframework.sbm.scopeplayground.ProjectMetadata;
41+
import org.springframework.sbm.scopes.ProjectMetadata;
4242
import org.springframework.stereotype.Component;
4343

4444
import java.io.IOException;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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.scopes;
17+
18+
import lombok.extern.slf4j.Slf4j;
19+
import org.springframework.beans.factory.ObjectFactory;
20+
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
21+
import org.springframework.beans.factory.config.Scope;
22+
import org.springframework.lang.Nullable;
23+
24+
import java.util.Map;
25+
import java.util.concurrent.ConcurrentHashMap;
26+
27+
/**
28+
* @author Fabian Krüger
29+
*/
30+
@Slf4j
31+
public class AbstractBaseScope implements Scope {
32+
private final Map<String, Object> scopedBeans = new ConcurrentHashMap<>();
33+
34+
public void clear(ConfigurableListableBeanFactory beanFactory) {
35+
scopedBeans.keySet().stream().forEach(beanName -> beanFactory.destroyScopedBean(beanName));
36+
}
37+
38+
public Object get(String name, ObjectFactory<?> objectFactory) {
39+
Object scopedObject = this.scopedBeans.get(name);
40+
if (scopedObject == null) {
41+
scopedObject = objectFactory.getObject();
42+
this.scopedBeans.put(name, scopedObject);
43+
}
44+
return scopedObject;
45+
}
46+
47+
@Nullable
48+
public Object remove(String name) {
49+
Map<String, Object> scope = this.scopedBeans;
50+
return scope.remove(name);
51+
}
52+
53+
public void registerDestructionCallback(String name, Runnable callback) {
54+
log.warn("%s does not support destruction callbacks.".formatted(this.getClass().getName()));
55+
}
56+
57+
@Nullable
58+
public Object resolveContextualObject(String key) {
59+
return null;
60+
}
61+
62+
public String getConversationId() {
63+
return null;
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
/*
3+
* Copyright 2021 - 2022 the original author or authors.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.springframework.sbm.scopes;
18+
19+
import org.springframework.stereotype.Component;
20+
21+
/**
22+
* Scope implementation for beans marked with {@link org.springframework.sbm.scopes.annotations.ExecutionScope}.
23+
*
24+
* @author Fabian Krüger
25+
*/
26+
@Component
27+
public class ExecutionScope extends AbstractBaseScope {
28+
29+
public final static String SCOPE_NAME = "executionScope";
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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.scopes;
17+
18+
import lombok.Getter;
19+
import lombok.Setter;
20+
import org.openrewrite.maven.MavenSettings;
21+
22+
@Getter
23+
@Setter
24+
public class ProjectMetadata {
25+
private String metadata;
26+
private MavenSettings mavenSettings;
27+
}

0 commit comments

Comments
 (0)