Skip to content

Commit

Permalink
Adjust upper modules to changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fabapp2 committed Oct 9, 2023
1 parent e519722 commit 0fea63f
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
*/
package org.springframework.sbm.build.api;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.openrewrite.ExecutionContext;
import org.openrewrite.SourceFile;
import org.openrewrite.maven.tree.MavenResolutionResult;
import org.springframework.sbm.build.impl.JavaSourceSetImpl;
import org.springframework.sbm.build.impl.MavenBuildFileUtil;
import org.springframework.sbm.build.impl.OpenRewriteMavenBuildFile;
import org.springframework.sbm.common.util.Verify;
import org.springframework.sbm.engine.recipe.MigrationResultProjectContextMerger;
import org.springframework.sbm.java.api.JavaSource;
import org.springframework.sbm.java.api.JavaSourceLocation;
import org.springframework.sbm.java.refactoring.JavaRefactoringFactory;
Expand All @@ -32,9 +34,6 @@
import org.springframework.sbm.project.resource.RewriteMigrationResultMerger;
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
import org.springframework.sbm.project.resource.finder.ProjectResourceFinder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.openrewrite.SourceFile;

import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -67,10 +66,6 @@ public JavaSourceLocation getBaseJavaSourceLocation() {
return getMainJavaSourceSet().getJavaSourceLocation();
}

public JavaSourceLocation getBaseTestJavaSourceLocation() {
return getTestJavaSourceSet().getJavaSourceLocation();
}

public JavaSourceSet getTestJavaSourceSet() {
Path testJavaPath = Path.of("src/test/java");
// FIXME: #7 JavaParser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void commentFindings(List<? extends JavaSource> javaSources, String comme
OpenRewriteJavaSource affectedJavaSource = javaSources.stream()
.filter(js -> js.getClass().isAssignableFrom(OpenRewriteJavaSource.class))
.map(OpenRewriteJavaSource.class::cast)
.filter(js -> result.getBefore().getId().equals(js.getResource().getId()))
.filter(js -> result.getBefore().getId().equals(js.getResource().getSourceFile().getId()))
.findFirst()
.get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public List<MethodCall> findMethodCalls(String methodPattern) {
FindMethods findMethods = new FindMethods(methodPattern,true);
MethodMatcher methodMatcher = new MethodMatcher(methodPattern);
find(findMethods).stream()
.map(m -> list().stream().filter(js -> js.getResource().getId().equals(m.getId())).findFirst().get())
.map(m -> list().stream().filter(js -> js.getResource().getSourceFile().getId().equals(m.getSourceFile().getId())).findFirst().get())
.map(m -> new MethodCall(m, methodMatcher))
.forEach(matches::add);
return matches;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected List<RewriteSourceFileHolder<J.CompilationUnit>> findInternal(List<Rew
.filter(r -> J.CompilationUnit.class.isAssignableFrom(r.getClass()))
.map(J.CompilationUnit.class::cast)
.map(cu -> resourceWrappers.stream()
.filter(fh -> fh.getId().equals(cu.getId()))
.filter(fh -> fh.getSourceFile().getId().equals(cu.getId()))
.map(pr -> {
J.CompilationUnit cuRemovedMarkers = removeMarkers(cu, SearchResult.class, RecipesThatMadeChanges.class);
pr.replaceWith(cuRemovedMarkers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.openrewrite.ExecutionContext;
import org.openrewrite.SourceFile;
import org.openrewrite.java.JavaParser;
import org.openrewrite.maven.utilities.MavenArtifactDownloader;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.core.io.Resource;
import org.springframework.sbm.build.impl.RewriteMavenParser;
import org.springframework.sbm.parsers.RewriteProjectParser;
import org.springframework.sbm.scopes.ProjectMetadata;
import org.springframework.stereotype.Component;

import java.nio.file.Path;
Expand All @@ -44,19 +38,10 @@
@Deprecated(forRemoval = true)
public class MavenProjectParser {

private final ResourceParser resourceParser;
private final RewriteMavenParser mavenParser;
private final MavenArtifactDownloader artifactDownloader;
private final ApplicationEventPublisher eventPublisher;
private final JavaProvenanceMarkerFactory javaProvenanceMarkerFactory;
private final JavaParser javaParser;
private final MavenConfigHandler mavenConfigHandler;
private final ProjectMetadata projectMetadata;
private final ExecutionContext executionContext;
private final RewriteProjectParser parser;

public List<SourceFile> parse(Path projectDirectory, List<Resource> resources) {
return parser.parse(projectDirectory, resources, executionContext).sourceFiles();
return parser.parse(projectDirectory, resources).sourceFiles();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class ProjectContextInitializer {
private final RewriteProjectParser mavenProjectParser;
private final GitSupport gitSupport;
private final RewriteSourceFileWrapper rewriteSourceFileWrapper;
private final ExecutionContext executionContext;
private final ProjectContextHolder projectContextHolder;
private final ProjectResourceSetFactory projectResourceSetFactory;

Expand All @@ -52,7 +51,7 @@ public ProjectContext initProjectContext(Path projectDir, List<Resource> resourc
// TODO: remove git initialization, handled by precondition check
initializeGitRepoIfNoneExists(absoluteProjectDir);

List<SourceFile> parsedResources = mavenProjectParser.parse(absoluteProjectDir, resources, executionContext).sourceFiles();
List<SourceFile> parsedResources = mavenProjectParser.parse(absoluteProjectDir, resources).sourceFiles();
List<RewriteSourceFileHolder<? extends SourceFile>> rewriteSourceFileHolders = rewriteSourceFileWrapper.wrapRewriteSourceFiles(absoluteProjectDir, parsedResources);

ProjectResourceSet projectResourceSet = projectResourceSetFactory.createFromSourceFileHolders(rewriteSourceFileHolders);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void run(String... args) throws Exception {
List<Resource> resources = scanner.scan(baseDir);

// parse
RewriteProjectParsingResult parsingResult = parser.parse(baseDir, resources, executionContext);
RewriteProjectParsingResult parsingResult = parser.parse(baseDir);
List<SourceFile> sourceFiles = parsingResult.sourceFiles();
ProjectResourceSet projectResourceSet = projectResourceSetFactory.create(baseDir, sourceFiles);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ProjectResourceSet {
private final ExecutionContext executionContext;
private final RewriteMigrationResultMerger migrationResultMerger;

ProjectResourceSet(List<RewriteSourceFileHolder<? extends SourceFile>> projectResources, ExecutionContext executionContext, RewriteMigrationResultMerger migrationResultMerger) {
public ProjectResourceSet(List<RewriteSourceFileHolder<? extends SourceFile>> projectResources, ExecutionContext executionContext, RewriteMigrationResultMerger migrationResultMerger) {
this.executionContext = executionContext;
this.migrationResultMerger = migrationResultMerger;
this.projectResources.addAll(projectResources);
Expand Down

0 comments on commit 0fea63f

Please sign in to comment.