Skip to content

Commit

Permalink
Avoid calling parsers when there are no source files
Browse files Browse the repository at this point in the history
With empty lists of main or test, Java or Kotlin files avoid invoking
the parsers completely. That's more performant and avoids any bad side
effects during initialization of the parsers.

Fixes #658.
  • Loading branch information
Bananeweizen committed Nov 16, 2023
1 parent 18501f9 commit 6d4255f
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,13 @@ private Stream<SourceFile> processMainSources(
javaParserBuilder.classpath(dependencies).typeCache(typeCache);
kotlinParserBuilder.classpath(dependencies).typeCache(new JavaTypeCache());

Stream<? extends SourceFile> cus = Stream.of(javaParserBuilder)
.map(JavaParser.Builder::build)
.flatMap(parser -> parser.parse(mainJavaSources, baseDir, ctx));
Stream<? extends SourceFile> cus = mainJavaSources.isEmpty() ? Stream.empty()
: Stream.of(javaParserBuilder).map(JavaParser.Builder::build)
.flatMap(parser -> parser.parse(mainJavaSources, baseDir, ctx));

Stream<? extends SourceFile> kcus = Stream.of(kotlinParserBuilder)
.map(KotlinParser.Builder::build)
.flatMap(parser -> parser.parse(mainKotlinSources, baseDir, ctx));
Stream<? extends SourceFile> kcus = mainKotlinSources.isEmpty() ? Stream.empty()
: Stream.of(kotlinParserBuilder).map(KotlinParser.Builder::build)
.flatMap(parser -> parser.parse(mainKotlinSources, baseDir, ctx));

List<Marker> mainProjectProvenance = new ArrayList<>(projectProvenance);
mainProjectProvenance.add(sourceSet("main", dependencies, typeCache));
Expand Down Expand Up @@ -382,13 +382,13 @@ private Stream<SourceFile> processTestSources(

alreadyParsed.addAll(testKotlinSources);

Stream<? extends SourceFile> cus = Stream.of(javaParserBuilder)
.map(JavaParser.Builder::build)
.flatMap(parser -> parser.parse(testJavaSources, baseDir, ctx));
Stream<? extends SourceFile> cus = testJavaSources.isEmpty() ? Stream.empty()
: Stream.of(javaParserBuilder).map(JavaParser.Builder::build)
.flatMap(parser -> parser.parse(testJavaSources, baseDir, ctx));

Stream<? extends SourceFile> kcus = Stream.of(kotlinParserBuilder)
.map(KotlinParser.Builder::build)
.flatMap(parser -> parser.parse(testKotlinSources, baseDir, ctx));
Stream<? extends SourceFile> kcus = testKotlinSources.isEmpty() ? Stream.empty()
: Stream.of(kotlinParserBuilder).map(KotlinParser.Builder::build)
.flatMap(parser -> parser.parse(testKotlinSources, baseDir, ctx));

List<Marker> markers = new ArrayList<>(projectProvenance);
markers.add(sourceSet("test", testDependencies, typeCache));
Expand Down

0 comments on commit 6d4255f

Please sign in to comment.