Skip to content

Commit

Permalink
Use spring-rewrite-commons
Browse files Browse the repository at this point in the history
  • Loading branch information
fabapp2 committed Jan 10, 2024
1 parent aa3dab3 commit 0dd9548
Show file tree
Hide file tree
Showing 145 changed files with 336 additions and 320 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.engine.recipe.AbstractAction;
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
import org.springframework.rewrite.project.resource.RewriteSourceFileHolder;
import org.springframework.sbm.project.resource.filter.GenericTypeListFilter;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
*/
package org.springframework.sbm.test;

import org.springframework.sbm.boot.autoconfigure.ScopeConfiguration;
import org.springframework.rewrite.boot.autoconfigure.ScopeConfiguration;
import org.springframework.rewrite.parsers.maven.MavenSettingsInitializer;
import org.springframework.rewrite.project.RewriteSourceFileWrapper;
import org.springframework.sbm.build.impl.MavenBuildFileRefactoringFactory;
import org.springframework.sbm.parsers.maven.MavenSettingsInitializer;
import org.springframework.sbm.build.impl.RewriteMavenParser;
import org.springframework.sbm.engine.context.ProjectContextHolder;
import org.springframework.sbm.engine.context.RewriteJavaSearchActionDeserializer;
import org.springframework.sbm.engine.recipe.*;
import org.springframework.sbm.java.impl.RewriteJavaParser;
import org.springframework.sbm.java.util.BasePackageCalculator;
import org.springframework.sbm.project.RewriteSourceFileWrapper;
import org.springframework.sbm.project.resource.ProjectResourceSetHolder;
import org.springframework.sbm.project.resource.SbmApplicationProperties;
import org.springframework.sbm.project.resource.ResourceHelper;
import org.springframework.sbm.scopes.ExecutionScope;
import org.springframework.sbm.scopes.ScanScope;
import org.springframework.rewrite.scopes.ExecutionScope;
import org.springframework.rewrite.scopes.ScanScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.openrewrite.SourceFile;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.maven.MavenParser;
import org.springframework.sbm.parsers.maven.MavenSettingsInitializer;
import org.springframework.rewrite.parsers.maven.MavenSettingsInitializer;
import org.springframework.stereotype.Component;

import java.nio.file.Path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import org.openrewrite.Parser;
import org.openrewrite.SourceFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.rewrite.parsers.maven.RewriteMavenArtifactDownloader;
import org.springframework.sbm.build.impl.MavenBuildFileRefactoringFactory;
import org.springframework.sbm.build.impl.OpenRewriteMavenBuildFile;
import org.springframework.sbm.build.impl.RewriteMavenParser;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.engine.recipe.AbstractAction;
import org.springframework.sbm.parsers.maven.RewriteMavenArtifactDownloader;

import java.io.ByteArrayInputStream;
import java.io.StringWriter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
import org.openrewrite.xml.tree.Xml;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.core.annotation.Order;
import org.springframework.rewrite.parsers.maven.RewriteMavenArtifactDownloader;
import org.springframework.rewrite.project.resource.RewriteSourceFileHolder;
import org.springframework.sbm.build.impl.MavenBuildFileRefactoring;
import org.springframework.sbm.build.impl.MavenBuildFileRefactoringFactory;
import org.springframework.sbm.build.impl.OpenRewriteMavenBuildFile;
import org.springframework.sbm.parsers.maven.RewriteMavenArtifactDownloader;
import org.springframework.sbm.project.resource.ProjectResourceWrapper;
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
import org.springframework.stereotype.Component;

@Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.springframework.sbm.common.api.TextResource;

import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
import org.springframework.rewrite.project.resource.RewriteSourceFileHolder;
import org.openrewrite.text.PlainText;

import java.nio.file.Path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package org.springframework.sbm.common.migration.actions;

import lombok.Setter;
import org.springframework.sbm.project.resource.finder.PathPatternMatchingProjectResourceFinder;
import org.springframework.rewrite.project.resource.finder.PathPatternMatchingProjectResourceFinder;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.engine.recipe.AbstractAction;
import org.springframework.sbm.project.resource.ProjectResource;
import org.springframework.rewrite.project.resource.ProjectResource;

/**
* Delete files matching path pattern.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package org.springframework.sbm.common.migration.actions;

import org.springframework.rewrite.project.resource.ProjectResource;
import org.springframework.rewrite.project.resource.finder.PathPatternMatchingProjectResourceFinder;
import org.springframework.sbm.engine.recipe.AbstractAction;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.project.resource.ProjectResource;
import org.springframework.sbm.project.resource.finder.PathPatternMatchingProjectResourceFinder;
import lombok.Getter;
import lombok.Setter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package org.springframework.sbm.common.migration.conditions;

import lombok.*;
import org.springframework.sbm.utils.OsAgnosticPathMatcher;
import org.springframework.rewrite.utils.OsAgnosticPathMatcher;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.engine.recipe.Condition;
import org.springframework.util.PathMatcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
package org.springframework.sbm.engine.commands;

import org.springframework.rewrite.scopes.ExecutionScope;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.engine.recipe.ApplicableRecipesListHolder;
import org.springframework.sbm.engine.recipe.Recipe;
import org.springframework.sbm.engine.recipe.Recipes;
import org.springframework.sbm.engine.recipe.RecipesBuilder;
import org.springframework.sbm.scopes.ExecutionScope;
import org.springframework.stereotype.Component;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
package org.springframework.sbm.engine.commands;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.sbm.project.resource.finder.DeletedResourcePathStringFilter;
import org.springframework.sbm.project.resource.finder.ModifiedResourcePathStringFilter;
import org.springframework.rewrite.project.resource.finder.DeletedResourcePathStringFilter;
import org.springframework.rewrite.project.resource.finder.ModifiedResourcePathStringFilter;
import org.springframework.rewrite.scopes.ExecutionScope;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.engine.context.ProjectContextSerializer;
import org.springframework.sbm.engine.git.GitSupport;
import org.springframework.sbm.engine.git.ProjectSyncVerifier;
import org.springframework.sbm.engine.recipe.Action;
import org.springframework.sbm.engine.recipe.Recipe;
import org.springframework.sbm.engine.recipe.RecipesBuilder;
import org.springframework.sbm.scopes.ExecutionScope;
import org.springframework.stereotype.Component;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/
package org.springframework.sbm.engine.commands;

import org.springframework.rewrite.project.resource.finder.DeletedResourcePathStringFilter;
import org.springframework.rewrite.project.resource.finder.ModifiedResourcePathStringFilter;
import org.springframework.sbm.engine.git.GitSupport;
import org.springframework.sbm.engine.git.ProjectSyncVerifier;
import org.springframework.sbm.engine.recipe.Recipe;
import org.springframework.sbm.engine.recipe.RecipesBuilder;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.engine.context.ProjectContextSerializer;
import org.springframework.sbm.project.resource.finder.DeletedResourcePathStringFilter;
import org.springframework.sbm.project.resource.finder.ModifiedResourcePathStringFilter;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.springframework.sbm.engine.precondition.PreconditionVerifier;
import org.springframework.sbm.project.parser.PathScanner;
import org.springframework.sbm.project.parser.ProjectContextInitializer;
import org.springframework.sbm.scopes.ScanScope;
import org.springframework.stereotype.Component;

import java.nio.file.Path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
package org.springframework.sbm.engine.context;

import org.openrewrite.ExecutionContext;
import org.springframework.rewrite.project.resource.ProjectResourceSet;
import org.springframework.rewrite.project.resource.ProjectResourceSetFactory;
import org.springframework.rewrite.project.resource.RewriteMigrationResultMerger;
import org.springframework.rewrite.project.resource.RewriteSourceFileHolder;
import org.springframework.sbm.build.api.BuildFile;
import org.springframework.sbm.build.filter.BuildFileProjectResourceFinder;
import org.springframework.sbm.engine.recipe.MigrationResultProjectContextMerger;
import org.springframework.sbm.java.refactoring.JavaRefactoringFactory;
import org.springframework.sbm.java.impl.ClasspathRegistry;
import org.springframework.sbm.java.refactoring.JavaRefactoringFactory;
import org.springframework.sbm.java.util.BasePackageCalculator;
import org.springframework.sbm.parsers.JavaParserBuilder;
import org.springframework.sbm.project.resource.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package org.springframework.sbm.engine.context;

import org.springframework.sbm.project.resource.ProjectResourceSetSerializer;
import lombok.RequiredArgsConstructor;
import org.springframework.rewrite.project.resource.ProjectResourceSetSerializer;
import org.springframework.stereotype.Component;

@Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package org.springframework.sbm.engine.precondition;

import org.springframework.core.io.Resource;
import org.springframework.sbm.utils.OsAgnosticPathMatcher;
import org.springframework.sbm.utils.LinuxWindowsPathUnifier;
import org.springframework.rewrite.utils.LinuxWindowsPathUnifier;
import org.springframework.rewrite.utils.OsAgnosticPathMatcher;
import org.springframework.stereotype.Component;
import org.springframework.util.PathMatcher;

Expand All @@ -35,7 +35,7 @@ class JavaSourceDirExistsPreconditionCheck extends PreconditionCheck {
@Override
public PreconditionCheckResult verify(Path projectRoot, List<Resource> projectResources) {
if (projectResources.stream()
.noneMatch(r -> pathMatcher.match(PATTERN, pathUnifier.unifyPath(getPath(r).toAbsolutePath().toString())))) {
.noneMatch(r -> pathMatcher.match(PATTERN, LinuxWindowsPathUnifier.unifiedPathString(r)))) {
return new PreconditionCheckResult(ResultState.FAILED, "PreconditionCheck check could not find a '" + JAVA_SRC_DIR + "' dir. This dir is required.");
}
return new PreconditionCheckResult(ResultState.PASSED, "Found required source dir 'src/main/java'.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,11 @@

import lombok.RequiredArgsConstructor;
import org.openrewrite.Result;
import org.openrewrite.SourceFile;
import org.springframework.sbm.project.resource.RewriteMigrationResultMerger;
import org.springframework.sbm.project.resource.finder.AbsolutePathResourceFinder;
import org.springframework.rewrite.project.resource.RewriteMigrationResultMerger;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.project.RewriteSourceFileWrapper;
import org.springframework.sbm.project.resource.ProjectResourceSet;
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
import org.springframework.stereotype.Component;

import java.nio.file.Path;
import java.util.List;
import java.util.Optional;

@Component
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package org.springframework.sbm.engine.recipe;

import org.openrewrite.SourceFile;
import org.springframework.sbm.project.resource.ProjectResourceSet;
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
import org.springframework.sbm.project.resource.finder.ProjectResourceFinder;
import org.springframework.rewrite.project.resource.ProjectResourceSet;
import org.springframework.rewrite.project.resource.RewriteSourceFileHolder;
import org.springframework.rewrite.project.resource.finder.ProjectResourceFinder;

import java.util.List;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
package org.springframework.sbm.java;

import org.openrewrite.ExecutionContext;
import org.springframework.rewrite.project.resource.RewriteSourceFileHolder;
import org.springframework.sbm.java.impl.OpenRewriteJavaSource;
import org.springframework.sbm.java.refactoring.JavaRefactoring;
import org.springframework.sbm.java.refactoring.JavaRefactoringFactory;
import org.springframework.sbm.parsers.JavaParserBuilder;
import org.springframework.sbm.project.resource.ProjectResourceWrapper;
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
import lombok.RequiredArgsConstructor;
import org.openrewrite.SourceFile;
import org.openrewrite.java.tree.J;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package org.springframework.sbm.java.filter;

import org.springframework.rewrite.project.resource.ProjectResourceSet;
import org.springframework.rewrite.project.resource.finder.ProjectResourceFinder;
import org.springframework.sbm.java.api.JavaSourceAndType;
import org.springframework.sbm.java.impl.OpenRewriteJavaSource;
import org.springframework.sbm.java.impl.OpenRewriteType;
import org.springframework.sbm.project.resource.ProjectResourceSet;
import org.springframework.sbm.project.resource.finder.ProjectResourceFinder;

import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package org.springframework.sbm.java.filter;

import org.springframework.rewrite.project.resource.finder.GenericTypeListFinder;
import org.springframework.sbm.java.impl.OpenRewriteJavaSource;
import org.springframework.sbm.project.resource.finder.GenericTypeListFinder;

public class OpenRewriteJavaSourceListFinder extends GenericTypeListFinder<OpenRewriteJavaSource> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class JavaParserFactory {
@Deprecated
public static @NotNull JavaParser getCurrentJavaParser(ExecutionContext executionContext) {
Set<Path> dependencies = ClasspathRegistry.getInstance().getCurrentDependencies();
JavaParser javaParser = new RewriteJavaParser(new SbmApplicationProperties(), executionContext);
JavaParser javaParser = new RewriteJavaParser(new SpringRewriteProperties(), executionContext);
javaParser.setClasspath(new ArrayList<>(dependencies));
return javaParser;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import org.openrewrite.marker.Markers;
import org.openrewrite.marker.RecipesThatMadeChanges;
import org.openrewrite.marker.SearchResult;
import org.springframework.sbm.project.resource.ProjectResourceSet;
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
import org.springframework.sbm.support.openrewrite.GenericOpenRewriteRecipe;
import org.springframework.rewrite.project.resource.ProjectResourceSet;
import org.springframework.rewrite.project.resource.RewriteSourceFileHolder;
import org.springframework.rewrite.support.openrewrite.GenericOpenRewriteRecipe;

import java.util.Arrays;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import org.openrewrite.ExecutionContext;
import org.springframework.sbm.project.resource.ProjectResourceSetHolder;
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
import org.springframework.rewrite.project.resource.RewriteSourceFileHolder;
import lombok.RequiredArgsConstructor;
import org.openrewrite.java.tree.J;
import org.springframework.stereotype.Component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
*/
package org.springframework.sbm.java.refactoring;

import org.openrewrite.java.tree.JavaType;
import org.springframework.sbm.project.resource.ProjectResourceSet;
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
import org.springframework.sbm.support.openrewrite.GenericOpenRewriteRecipe;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Recipe;
import org.openrewrite.Result;
import org.openrewrite.java.JavaVisitor;
import org.openrewrite.java.tree.J;
import org.springframework.rewrite.project.resource.ProjectResourceSet;
import org.springframework.rewrite.project.resource.RewriteSourceFileHolder;
import org.springframework.rewrite.support.openrewrite.GenericOpenRewriteRecipe;

import java.util.Arrays;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import lombok.extern.slf4j.Slf4j;
import org.openrewrite.SourceFile;
import org.springframework.core.io.Resource;
import org.springframework.sbm.parsers.RewriteProjectParser;
import org.springframework.rewrite.parsers.RewriteProjectParser;
import org.springframework.stereotype.Component;

import java.nio.file.Path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

import lombok.RequiredArgsConstructor;
import org.springframework.core.io.Resource;
import org.springframework.sbm.utils.OsAgnosticPathMatcher;
import org.springframework.rewrite.utils.LinuxWindowsPathUnifier;
import org.springframework.rewrite.utils.OsAgnosticPathMatcher;
import org.springframework.sbm.project.resource.ResourceHelper;
import org.springframework.sbm.project.resource.SbmApplicationProperties;
import org.springframework.sbm.utils.LinuxWindowsPathUnifier;
import org.springframework.stereotype.Service;
import org.springframework.util.PathMatcher;

Expand All @@ -37,11 +37,10 @@ public class PathScanner {
private final SbmApplicationProperties sbmApplicationProperties;
private final ResourceHelper resourceHelper;
private final PathMatcher pathMatcher = new OsAgnosticPathMatcher();
private final LinuxWindowsPathUnifier pathUnifier = new LinuxWindowsPathUnifier();

public List<Resource> scan(Path projectRoot) {
Path absoluteRootPath = projectRoot.toAbsolutePath();
String pattern = new LinuxWindowsPathUnifier().unifyPath(absoluteRootPath.toString() + "/**");
String pattern = LinuxWindowsPathUnifier.unifiedPathString(absoluteRootPath) + "/**";
Resource[] resources = resourceHelper.loadResources("file:" + pattern);

return Arrays.asList(resources)
Expand All @@ -56,7 +55,7 @@ private boolean isRelevant(Path projectRoot, Path givenResource) {
}
return sbmApplicationProperties.getIgnoredPathsPatterns().stream()
.noneMatch(ir -> pathMatcher.match(ir,
pathUnifier.unifyPath(projectRoot.relativize(givenResource))));
LinuxWindowsPathUnifier.unifiedPathString(projectRoot.relativize(givenResource))));
}

private Path getPath(Resource r) {
Expand Down
Loading

0 comments on commit 0dd9548

Please sign in to comment.