Skip to content

Commit

Permalink
Reuse ExecutionContext for ResourceParser (#683)
Browse files Browse the repository at this point in the history
Fixes #622
  • Loading branch information
timtebeek authored Dec 11, 2023
1 parent d1b68cd commit 24ddb24
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public Stream<SourceFile> listSourceFiles(MavenProject mavenProject, @Nullable X
// todo, add styles from autoDetect
KotlinParser.Builder kotlinParserBuilder = KotlinParser.builder();
ResourceParser rp = new ResourceParser(baseDir, logger, exclusions, plainTextMasks, sizeThresholdMb, pathsToOtherMavenProjects(mavenProject),
javaParserBuilder.clone(), kotlinParserBuilder.clone());
javaParserBuilder.clone(), kotlinParserBuilder.clone(), ctx);

sourceFiles = Stream.concat(sourceFiles, processMainSources(mavenProject, javaParserBuilder.clone(), kotlinParserBuilder.clone(), rp, projectProvenance, alreadyParsed, ctx));
sourceFiles = Stream.concat(sourceFiles, processTestSources(mavenProject, javaParserBuilder.clone(), kotlinParserBuilder.clone(), rp, projectProvenance, alreadyParsed, ctx));
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/org/openrewrite/maven/ResourceParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import org.apache.maven.plugin.logging.Log;
import org.openrewrite.ExecutionContext;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.SourceFile;
import org.openrewrite.groovy.GroovyParser;
import org.openrewrite.hcl.HclParser;
Expand All @@ -38,7 +37,6 @@
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -59,8 +57,10 @@ public class ResourceParser {

private final KotlinParser.Builder kotlinParserBuilder;

private final ExecutionContext ctx;

public ResourceParser(Path baseDir, Log logger, Collection<String> exclusions, Collection<String> plainTextMasks, int sizeThresholdMb, Collection<Path> excludedDirectories,
JavaParser.Builder<? extends JavaParser, ?> javaParserBuilder, KotlinParser.Builder kotlinParserBuilder) {
JavaParser.Builder<? extends JavaParser, ?> javaParserBuilder, KotlinParser.Builder kotlinParserBuilder, ExecutionContext ctx) {
this.baseDir = baseDir;
this.logger = logger;
this.javaParserBuilder = javaParserBuilder;
Expand All @@ -69,6 +69,7 @@ public ResourceParser(Path baseDir, Log logger, Collection<String> exclusions, C
this.sizeThresholdMb = sizeThresholdMb;
this.excludedDirectories = excludedDirectories;
this.plainTextMasks = pathMatchers(baseDir, plainTextMasks);
this.ctx = ctx;
}

private Collection<PathMatcher> pathMatchers(Path basePath, Collection<String> pathExpressions) {
Expand All @@ -82,8 +83,6 @@ public Stream<SourceFile> parse(Path searchDir, Collection<Path> alreadyParsed)
if (!searchDir.toFile().exists()) {
return sourceFiles;
}
Consumer<Throwable> errorConsumer = t -> logger.debug("Error parsing", t);
InMemoryExecutionContext ctx = new InMemoryExecutionContext(errorConsumer);

try {
sourceFiles = Stream.concat(sourceFiles, parseSourceFiles(searchDir, alreadyParsed, ctx));
Expand Down

0 comments on commit 24ddb24

Please sign in to comment.