Skip to content

Commit

Permalink
Make sbm-recipes-boot-upgrade compile
Browse files Browse the repository at this point in the history
  • Loading branch information
fabapp2 committed Sep 24, 2023
1 parent 77cdea6 commit 479ff84
Show file tree
Hide file tree
Showing 21 changed files with 56 additions and 1,105 deletions.
5 changes: 3 additions & 2 deletions components/sbm-recipes-boot-upgrade/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

<dependencies>
Expand Down Expand Up @@ -73,6 +73,7 @@
<dependency>
<groupId>org.springframework.sbm</groupId>
<artifactId>recipe-test-support</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public String getDescription() {
}

@Override
protected TreeVisitor<?, ExecutionContext> getVisitor() {
public TreeVisitor<?, ExecutionContext> getVisitor() {

return new PropertiesVisitor<ExecutionContext>() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Sbu30_PreconditionCheckResult run(ProjectContext context) {
if(collect.isEmpty()) {
return new Sbu30_PreconditionCheckResult(PreconditionCheck.ResultState.PASSED, "No dependency to Google AppEngine's AppEngineDriver found.");
} else {
String message = "Dependencies containing 'com.google.appengine.api.rdbms.AppEngineDriver' were found in these modules: '" + collect.stream().map(m -> m.getBuildFile().getCoordinates()).collect(Collectors.joining("', '")) + "'";
String message = "Dependencies containing 'com.google.appengine.api.rdbms.AppEngineDriver' were found in these modules: '" + collect.stream().map(m -> m.getBuildFile().getGav()).collect(Collectors.joining("', '")) + "'";
return new Sbu30_PreconditionCheckResult(PreconditionCheck.ResultState.FAILED, message);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Section build(ProjectContext projectContext) {
Set<RedeclaredDependenciesFinder.RedeclaredDependency> matches = finder.findMatches(projectContext);
List<TodoList.Todo> todos = matches.stream()
.map(m -> TodoList.Todo.builder()
.text(String.format("Remove explicit declaration of version for artifact: %s, its already declared with version %s", m.getRedeclaredDependency().getCoordinates(), m.originalVersion()))
.text(String.format("Remove explicit declaration of version for artifact: %s, its already declared with version %s", m.getRedeclaredDependency().getGav(), m.originalVersion()))
.build()).toList();

return ChangeSection.RelevantChangeSection.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ public String getDisplayName() {
}

@Override
protected TreeVisitor<?, ExecutionContext> getVisitor() {
public String getDescription() {
return getDisplayName();
}

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new JavaIsoVisitor<>() {
@Override
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext executionContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Map<String, Object> getData(ProjectContext context, @Valid List<SpringBoo
.collect(Collectors.toSet());
data.put("contributors", authors);

String scannedCoordinate = context.getApplicationModules().getRootModule().getBuildFile().getCoordinates();
String scannedCoordinate = context.getApplicationModules().getRootModule().getBuildFile().getGav();
data.put("scannedCoordinate", scannedCoordinate);

data.put("scannedProjectRoot", context.getProjectRootDirectory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public boolean evaluate(ProjectContext context) {
}

GenericOpenRewriteRecipe<TreeVisitor<?, ExecutionContext>> recipe =
new GenericOpenRewriteRecipe<>(() -> new UsesType("org.springframework.boot.context.properties.ConstructorBinding"));
new GenericOpenRewriteRecipe<>(() -> new UsesType("org.springframework.boot.context.properties.ConstructorBinding", false));

List<RewriteSourceFileHolder<J.CompilationUnit>> rewriteSourceFileHolders =
context.getProjectJavaSources().find(recipe);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public String getDescription() {

@Override
public boolean evaluate(ProjectContext context) {

Optional<Dependency> d = context.getBuildFile().getDeclaredDependencies().stream()
.filter(x -> x.getCoordinates().contains("org.apache.johnzon:johnzon-core")).findFirst();
return d.isPresent();
return context.getApplicationModules().getRootModule().getBuildFile()
.getDeclaredDependencies()
.stream()
.anyMatch(x -> x.getGav().contains("org.apache.johnzon:johnzon-core"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public boolean evaluate(ProjectContext context) {
return false;
}

GenericOpenRewriteRecipe<UsesType<ExecutionContext>> usesTypeRecipe = new GenericOpenRewriteRecipe<>(() -> new UsesType<>(SPRING_REST_CONTROLLER_FQN));
GenericOpenRewriteRecipe<UsesType<ExecutionContext>> usesTypeRecipe = new GenericOpenRewriteRecipe<>(() -> new UsesType<>(SPRING_REST_CONTROLLER_FQN, false));

matches = context.getProjectJavaSources().find(usesTypeRecipe).stream()
.filter(m -> OpenRewriteJavaSource.class.isInstance(m))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.tngtech.archunit.lang.ArchRule;
import org.openrewrite.ExecutionContext;
import org.springframework.sbm.boot.autoconfigure.ScopeConfiguration;
import org.springframework.sbm.openrewrite.RewriteExecutionContext;
import org.springframework.sbm.parsers.RewriteExecutionContext;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.junit.jupiter.params.provider.Arguments;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.Result;
import org.openrewrite.SourceFile;
import org.openrewrite.internal.InMemoryLargeSourceSet;
import org.openrewrite.properties.PropertiesParser;
import org.openrewrite.properties.tree.Properties;
import org.openrewrite.test.RewriteTest;
Expand All @@ -42,10 +44,10 @@ public class ConfigRecipeTestHelper {

public static List<Result> runRecipeOnYaml(@Language("yml") String source, String recipeName) {
InMemoryExecutionContext ctx = new InMemoryExecutionContext(Throwable::printStackTrace);
List<Yaml.Documents> document = new YamlParser().parse(source);
List<SourceFile> document = new YamlParser().parse(source).toList();
return RewriteTest
.fromRuntimeClasspath(recipeName)
.run(document, ctx).getResults();
.run(new InMemoryLargeSourceSet(document), ctx).getChangeset().getAllResults();
}

// public static List<Result> runRecipeOnProperties(@Language("properties") String source, String recipeName) {
Expand Down
Loading

0 comments on commit 479ff84

Please sign in to comment.