Skip to content

Commit 0a61b22

Browse files
authored
Bumped openrewrite to 7.22.0 (#174)
- Ignore flaky tests - Add todo and fixme - Merge Boot 3 upgrade branch - fix copyrights - Rewritten MavenProjectParser - Add new resource parser
1 parent 3e5a90f commit 0a61b22

File tree

189 files changed

+5331
-2292
lines changed

Some content is hidden

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

189 files changed

+5331
-2292
lines changed

.github/workflows/mvn-build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ jobs:
1717
java-version: '11'
1818
distribution: 'adopt'
1919
- name: Build with Maven
20-
run: mvn --update-snapshots -DskipITs verify
20+
run: mvn --update-snapshots -DtrimStackTrace=false -Dsurefire.useFile=false -DskipITs verify

components/openrewrite-spring-recipes/src/main/java/org/springframework/sbm/OrRecipesConfig.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
*/
1616
package org.springframework.sbm;
1717

18-
import org.springframework.sbm.build.migration.conditions.AnyDependencyExistMatchingRegex;
18+
import org.openrewrite.maven.AddPluginDependency;
19+
import org.springframework.context.annotation.Bean;
20+
import org.springframework.context.annotation.Configuration;
1921
import org.springframework.sbm.build.impl.OpenRewriteMavenBuildFile;
22+
import org.springframework.sbm.build.migration.conditions.AnyDependencyExistMatchingRegex;
2023
import org.springframework.sbm.build.migration.recipe.RemoveMavenPlugin;
2124
import org.springframework.sbm.engine.recipe.Action;
2225
import org.springframework.sbm.engine.recipe.Condition;
2326
import org.springframework.sbm.engine.recipe.Recipe;
2427
import org.springframework.sbm.spring.migration.actions.OpenRewriteRecipeAdapterAction;
25-
import org.springframework.sbm.support.openrewrite.maven.AddPluginDependency;
26-
import org.springframework.context.annotation.Bean;
27-
import org.springframework.context.annotation.Configuration;
2828

2929
import java.lang.reflect.InvocationTargetException;
3030
import java.util.List;

components/openrewrite-spring-recipes/src/test/java/org/springframework/sbm/OpenRewriteRecipeTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ void retrieveOpenRewriteRecipeFromClasspath() {
6868
@Test
6969
void getClasspathJars() {
7070
String[] property = System.getProperty("java.class.path").split(System.getProperty("path.separator"));
71-
Arrays.stream(property).forEach(System.out::println);
71+
// Arrays.stream(property).forEach(System.out::println);
72+
assertThat(property).isNotEmpty();
7273
}
7374

7475
@Test

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

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.fasterxml.jackson.databind.ObjectMapper;
1919
import org.springframework.sbm.engine.context.RewriteJavaSearchActionDeserializer;
2020
import org.springframework.sbm.engine.recipe.*;
21+
import org.springframework.sbm.java.impl.RewriteJavaParser;
2122
import org.springframework.sbm.java.util.BasePackageCalculator;
2223
import org.springframework.sbm.project.resource.SbmApplicationProperties;
2324
import org.springframework.sbm.project.resource.ResourceHelper;
@@ -54,6 +55,7 @@ private RecipeTestSupport() {
5455
RecipesBuilder.class,
5556
ResourceHelper.class,
5657
RecipeParser.class,
58+
RewriteJavaParser.class,
5759
CustomValidator.class,
5860
ValidatorConfiguration.class,
5961
YamlObjectMapperConfiguration.class,

components/sbm-core/pom.xml

+12-5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
<groupId>org.openrewrite</groupId>
6262
<artifactId>rewrite-yaml</artifactId>
6363
</dependency>
64+
<dependency>
65+
<groupId>org.openrewrite</groupId>
66+
<artifactId>rewrite-json</artifactId>
67+
</dependency>
6468
<dependency>
6569
<groupId>org.openrewrite</groupId>
6670
<artifactId>rewrite-properties</artifactId>
@@ -69,6 +73,14 @@
6973
<groupId>org.openrewrite</groupId>
7074
<artifactId>rewrite-java-11</artifactId>
7175
</dependency>
76+
<dependency>
77+
<groupId>org.openrewrite</groupId>
78+
<artifactId>rewrite-protobuf</artifactId>
79+
</dependency>
80+
<dependency>
81+
<groupId>org.openrewrite</groupId>
82+
<artifactId>rewrite-hcl</artifactId>
83+
</dependency>
7284
<!-- TODO: bind to profile, currently not in use -->
7385
<!-- <dependency>-->
7486
<!-- <groupId>org.mapdb</groupId>-->
@@ -139,11 +151,6 @@
139151
<classifier>tests</classifier>
140152
<scope>test</scope>
141153
</dependency>
142-
<dependency>
143-
<groupId>org.junit.jupiter</groupId>
144-
<artifactId>junit-jupiter</artifactId>
145-
<scope>test</scope>
146-
</dependency>
147154
</dependencies>
148155
<build>
149156
<plugins>

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

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

18+
import org.openrewrite.java.JavaParser;
19+
import org.openrewrite.maven.tree.MavenResolutionResult;
1820
import org.springframework.sbm.build.impl.JavaSourceSetImpl;
21+
import org.springframework.sbm.build.impl.MavenBuildFileUtil;
1922
import org.springframework.sbm.build.impl.OpenRewriteMavenBuildFile;
2023
import org.springframework.sbm.java.api.JavaSource;
2124
import org.springframework.sbm.java.api.JavaSourceLocation;
@@ -27,7 +30,6 @@
2730
import lombok.Getter;
2831
import lombok.RequiredArgsConstructor;
2932
import org.openrewrite.SourceFile;
30-
import org.openrewrite.maven.tree.Modules;
3133

3234
import java.nio.file.Path;
3335
import java.util.ArrayList;
@@ -49,6 +51,7 @@ public class ApplicationModule {
4951
private final ProjectResourceSet projectResourceSet;
5052
private final JavaRefactoringFactory javaRefactoringFactory;
5153
private final BasePackageCalculator basePackageCalculator;
54+
private final JavaParser javaParser;
5255

5356
public JavaSourceLocation getBaseJavaSourceLocation() {
5457
return getMainJavaSourceSet().getJavaSourceLocation();
@@ -60,7 +63,8 @@ public JavaSourceLocation getBaseTestJavaSourceLocation() {
6063

6164
public JavaSourceSet getTestJavaSourceSet() {
6265
Path testJavaPath = Path.of("src/test/java");
63-
return new JavaSourceSetImpl(projectResourceSet, projectRootDir, modulePath, testJavaPath, javaRefactoringFactory, basePackageCalculator);
66+
// FIXME: #7 JavaParser
67+
return new JavaSourceSetImpl(projectResourceSet, projectRootDir, modulePath, testJavaPath, javaRefactoringFactory, basePackageCalculator, javaParser);
6468
}
6569

6670
public List<? extends JavaSource> getMainJavaSources() {
@@ -76,7 +80,7 @@ public List<? extends JavaSource> getTestJavaSources() {
7680
public JavaSourceSet getMainJavaSourceSet() {
7781
Path mainJavaPath = Path.of("src/main/java");
7882
// return new JavaSourceSetImpl(projectResourceSet, projectRootDir.resolve(modulePath).resolve(mainJavaPath), javaRefactoringFactory);
79-
return new JavaSourceSetImpl(projectResourceSet, projectRootDir, modulePath, mainJavaPath, javaRefactoringFactory, basePackageCalculator);
83+
return new JavaSourceSetImpl(projectResourceSet, projectRootDir, modulePath, mainJavaPath, javaRefactoringFactory, basePackageCalculator, javaParser);
8084
}
8185

8286
private List<JavaSource> cast(List<RewriteSourceFileHolder<? extends SourceFile>> filter) {
@@ -109,19 +113,20 @@ public ResourceSet getMainResourceSet() {
109113
}
110114

111115
public List<ApplicationModule> getModules() {
112-
Optional<Modules> modulesMarker = ((OpenRewriteMavenBuildFile) buildFile).getPom().getMarkers().findFirst(Modules.class);
113-
if (modulesMarker.isPresent()) {
114-
return modulesMarker.get()
115-
.getModules()
116+
Optional<MavenResolutionResult> mavenResolution = MavenBuildFileUtil.findMavenResolution(((OpenRewriteMavenBuildFile) buildFile).getSourceFile());
117+
List<MavenResolutionResult> modulesMarker = mavenResolution.get().getModules();
118+
if ( ! modulesMarker.isEmpty()) {
119+
return modulesMarker
116120
.stream()
117121
.map(m -> new ApplicationModule(
118-
m.getName(),
122+
m.getPom().getGav().toString(),
119123
this.buildFile,
120124
projectRootDir,
121125
modulePath,
122126
projectResourceSet,
123127
javaRefactoringFactory,
124-
basePackageCalculator
128+
basePackageCalculator,
129+
javaParser
125130
))
126131
.collect(Collectors.toList());
127132
} else {

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

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

18-
import org.springframework.sbm.build.impl.OpenRewriteMavenBuildFile;
1918
import org.jetbrains.annotations.NotNull;
20-
import org.openrewrite.maven.tree.Modules;
19+
import org.openrewrite.maven.tree.MavenResolutionResult;
20+
import org.springframework.sbm.build.impl.MavenBuildFileUtil;
21+
import org.springframework.sbm.build.impl.OpenRewriteMavenBuildFile;
2122

2223
import java.nio.file.Path;
2324
import java.util.ArrayList;
@@ -60,43 +61,43 @@ public ApplicationModule getModule(String name) {
6061
}
6162

6263
public List<ApplicationModule> getModules(ApplicationModule module) {
63-
Optional<Modules> modulesMarker = ((OpenRewriteMavenBuildFile) module.getBuildFile()).getPom().getMarkers().findFirst(Modules.class);
64-
if (modulesMarker.isPresent()) {
65-
return getModulesForMarkers(modulesMarker.get());
64+
MavenResolutionResult mavenResolutionResult = MavenBuildFileUtil.findMavenResolution(((OpenRewriteMavenBuildFile) module.getBuildFile()).getSourceFile()).get();
65+
List<MavenResolutionResult> modulesMarker = mavenResolutionResult.getModules();
66+
if (!modulesMarker.isEmpty()) {
67+
return filterModulesContainingMavens(modulesMarker);
6668
} else {
6769
return new ArrayList<>();
6870
}
6971
}
7072

7173
@NotNull
72-
private List<ApplicationModule> getModulesForMarkers(Modules modulesMarker) {
73-
List<String> collect = modulesMarker.getModules().stream()
74-
.map(m -> m.getGroupId() + ":" + m.getArtifactId())
74+
private List<ApplicationModule> filterModulesContainingMavens(List<MavenResolutionResult> modulesMarker) {
75+
List<String> collect = modulesMarker.stream()
76+
.map(m -> m.getPom().getGroupId() + ":" + m.getPom().getArtifactId())
7577
.collect(Collectors.toList());
7678

77-
List<ApplicationModule> modules = this.modules.stream()
79+
return modules.stream()
7880
.filter(module -> {
7981
String groupAndArtifactId = module.getBuildFile().getGroupId() + ":" + module.getBuildFile().getArtifactId();
8082
return collect.contains(groupAndArtifactId);
8183
})
8284
.collect(Collectors.toList());
83-
return modules;
8485
}
8586

8687
public List<ApplicationModule> getTopmostApplicationModules() {
8788
List<ApplicationModule> topmostModules = new ArrayList<>();
8889
modules.forEach(module -> {
8990
// is jar
90-
if ("jar".equals(module.getBuildFile().getPackaging())) {
91+
if ("jar".equals(module.getBuildFile().getPackaging())) { // FIXME: other types could be topmost too, e.g. 'war'
9192
// no other pom depends on this pom in its dependency section
9293
if (noOtherPomDependsOn(module.getBuildFile())) {
9394
// has no parent or parent has packaging pom
94-
ParentDeclaration parentPomDeclaration = module.getBuildFile().getParentPomDeclaration();
95-
if (parentPomDeclaration == null) {
95+
Optional<ParentDeclaration> parentPomDeclaration = module.getBuildFile().getParentPomDeclaration();
96+
if (parentPomDeclaration.isEmpty()) {
9697
topmostModules.add(module);
97-
} else if (isDeclaredInProject(parentPomDeclaration) && isPackagingOfPom(parentPomDeclaration)) {
98+
} else if (isDeclaredInProject(parentPomDeclaration.get()) && isPackagingOfPom(parentPomDeclaration.get())) {
9899
topmostModules.add(module);
99-
} else if (!isDeclaredInProject(parentPomDeclaration)) {
100+
} else if (!isDeclaredInProject(parentPomDeclaration.get())) {
100101
topmostModules.add(module);
101102
}
102103
}

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

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

18-
import org.springframework.sbm.project.resource.ProjectResource;
19-
import org.openrewrite.maven.tree.Pom;
2018
import org.openrewrite.maven.tree.Scope;
19+
import org.springframework.sbm.project.resource.ProjectResource;
2120

2221
import java.nio.file.Path;
2322
import java.util.List;
@@ -26,9 +25,14 @@
2625

2726
public interface BuildFile extends ProjectResource {
2827

29-
List<Dependency> getDeclaredDependencies();
28+
List<Dependency> getDeclaredDependencies(Scope... scopes);
3029

31-
Set<Pom.Dependency> getEffectiveDependencies(Scope scope);
30+
/**
31+
* Returns any available dependency (declared or transitive) with given scope.
32+
*/
33+
Set<Dependency> getEffectiveDependencies(Scope scope);
34+
35+
Set<Dependency> getEffectiveDependencies();
3236

3337
/**
3438
* Check if any declared dependency matches any of the given regex.
@@ -46,8 +50,16 @@ public interface BuildFile extends ProjectResource {
4650

4751
boolean hasExactDeclaredDependency(Dependency dependency);
4852

53+
/**
54+
* Add a dependency to the build file and reparse Java sources.
55+
*
56+
* Always prefer {@link #addDependencies(List)} instead of looping this method.
57+
*/
4958
void addDependency(Dependency dependency);
5059

60+
/**
61+
* Add a list of dependencies to the build file and reparse Java sources.
62+
*/
5163
void addDependencies(List<Dependency> dependencies);
5264

5365
void removeDependencies(List<Dependency> dependencies);
@@ -89,6 +101,9 @@ public interface BuildFile extends ProjectResource {
89101

90102
String print();
91103

104+
/**
105+
* Get the packaging type for this BuildFile.
106+
*/
92107
String getPackaging();
93108

94109
void setPackaging(String packaging);
@@ -113,7 +128,7 @@ public interface BuildFile extends ProjectResource {
113128

114129
void upgradeParentVersion(String version);
115130

116-
ParentDeclaration getParentPomDeclaration();
131+
Optional<ParentDeclaration> getParentPomDeclaration();
117132

118133
Optional<String> getName();
119134

@@ -125,4 +140,7 @@ public interface BuildFile extends ProjectResource {
125140
*/
126141
void excludeDependencies(List<Dependency> excludedDependencies);
127142

143+
void addRepository(RepositoryDefinition repository);
144+
145+
List<RepositoryDefinition> getRepositories();
128146
}

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.springframework.sbm.build.api.JavaSourceSet;
1919
import org.springframework.sbm.java.api.JavaSource;
2020
import org.springframework.sbm.java.api.JavaSourceLocation;
21-
import org.springframework.sbm.java.impl.JavaParserFactory;
2221
import org.springframework.sbm.java.impl.OpenRewriteJavaSource;
2322
import org.springframework.sbm.java.refactoring.JavaRefactoringFactory;
2423
import org.springframework.sbm.java.util.BasePackageCalculator;
@@ -43,10 +42,12 @@ public class JavaSourceSetImpl implements JavaSourceSet {
4342
private final Path sourceSetRoot;
4443
private final JavaRefactoringFactory javaRefactoringFactory;
4544
private final BasePackageCalculator basePackageCalculator;
45+
private final JavaParser javaParser;
4646

47-
public JavaSourceSetImpl(ProjectResourceSet projectResourceSet, Path projectRootDir, Path modulePath, Path mainJavaPath, JavaRefactoringFactory javaRefactoringFactory, BasePackageCalculator basePackageCalculator) {
47+
public JavaSourceSetImpl(ProjectResourceSet projectResourceSet, Path projectRootDir, Path modulePath, Path mainJavaPath, JavaRefactoringFactory javaRefactoringFactory, BasePackageCalculator basePackageCalculator, JavaParser javaParser) {
4848
this.projectResourceSet = projectResourceSet;
4949
this.basePackageCalculator = basePackageCalculator;
50+
this.javaParser = javaParser;
5051
this.sourceSetRoot = projectRootDir.resolve(modulePath).resolve(mainJavaPath);
5152
this.filter = (r) -> {
5253
return r.getAbsolutePath().getParent().normalize().toString().startsWith(sourceSetRoot.toString());
@@ -60,7 +61,7 @@ public JavaSourceSetImpl(ProjectResourceSet projectResourceSet, Path projectRoot
6061
@Override
6162
@Deprecated(forRemoval = true)
6263
public JavaSource addJavaSource(Path projectRoot, Path sourceFolder, String sourceCode, String packageName) {
63-
JavaParser javaParser = JavaParserFactory.getCurrentJavaParser();
64+
// FIXME: #7 JavaParser
6465
javaParser.reset();
6566
List<J.CompilationUnit> compilationUnits = javaParser.parse(sourceCode);
6667
J.CompilationUnit parsedCompilationUnit = compilationUnits.get(0);
@@ -70,7 +71,7 @@ public JavaSource addJavaSource(Path projectRoot, Path sourceFolder, String sour
7071
throw new RuntimeException("The Java class you tried to add already lives here: '" + sourceFilePath + "'.");
7172
} else {
7273
J.CompilationUnit compilationUnit = parsedCompilationUnit.withSourcePath(sourceFilePath);
73-
OpenRewriteJavaSource addedSource = new OpenRewriteJavaSource(projectRoot, compilationUnit, javaRefactoringFactory.createRefactoring(compilationUnit));
74+
OpenRewriteJavaSource addedSource = new OpenRewriteJavaSource(projectRoot, compilationUnit, javaRefactoringFactory.createRefactoring(compilationUnit), javaParser);
7475
addedSource.markChanged();
7576
projectResourceSet.add(addedSource);
7677
return addedSource;
@@ -79,7 +80,7 @@ public JavaSource addJavaSource(Path projectRoot, Path sourceFolder, String sour
7980

8081
@Override
8182
public List<JavaSource> addJavaSource(Path projectRoot, Path sourceFolder, String... sourceCodes) {
82-
JavaParser javaParser = JavaParserFactory.getCurrentJavaParser();
83+
// FIXME: #7 JavaParser
8384
javaParser.reset();
8485

8586
List<J.CompilationUnit> compilationUnits = javaParser.parse(sourceCodes);
@@ -91,7 +92,7 @@ public List<JavaSource> addJavaSource(Path projectRoot, Path sourceFolder, Strin
9192
Path sourceFilePath = sourceFolder.resolve(sourceFileName);
9293
if(!Files.exists(sourceFilePath)) {
9394
J.CompilationUnit compilationUnit = cu.withSourcePath(sourceFilePath);
94-
OpenRewriteJavaSource addedSource = new OpenRewriteJavaSource(projectRoot, compilationUnit, javaRefactoringFactory.createRefactoring(compilationUnit));
95+
OpenRewriteJavaSource addedSource = new OpenRewriteJavaSource(projectRoot, compilationUnit, javaRefactoringFactory.createRefactoring(compilationUnit), javaParser);
9596
addedSource.markChanged();
9697
projectResourceSet.add(addedSource);
9798
addedSources.add(addedSource);

0 commit comments

Comments
 (0)