Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make rewrite-maven-plugin search for Kotlin source files in src/*/java if src/*/kotlin does not exist #937

Merged
merged 12 commits into from
Jan 28, 2025
Merged
Prev Previous commit
Next Next commit
#936 in case of missing src/*/kotlin fall back to scanning for Kotlin…
… sources in src/*/java instead
reisners committed Jan 25, 2025
commit 9e5e0db8b950d8933a0d33fd911cc902d1fd7696
10 changes: 5 additions & 5 deletions src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java
Original file line number Diff line number Diff line change
@@ -242,7 +242,7 @@ private SourceFile logParseErrors(SourceFile source) {
source.getMarkers().findFirst(ParseExceptionResult.class).ifPresent(e -> {
if (firstWarningLogged.compareAndSet(false, true)) {
logger.warn("There were problems parsing some source files" +
(mavenSession.getRequest().isShowErrors() ? "" : ", run with --errors to see full stack traces"));
(mavenSession.getRequest().isShowErrors() ? "" : ", run with --errors to see full stack traces"));
}
logger.warn("There were problems parsing " + source.getSourcePath());
if (mavenSession.getRequest().isShowErrors()) {
@@ -397,7 +397,7 @@ private Stream<SourceFile> processMainSources(

// scan Kotlin files
String kotlinSourceDir = getKotlinDirectory(mavenProject.getBuild().getSourceDirectory());
List<Path> mainKotlinSources = (kotlinSourceDir != null) ? listKotlinSources(mavenProject.getBasedir().toPath().resolve(kotlinSourceDir)) : Collections.emptyList();
List<Path> mainKotlinSources = listKotlinSources(mavenProject.getBasedir().toPath().resolve(kotlinSourceDir != null ? kotlinSourceDir : mavenProject.getBuild().getSourceDirectory()));
MBoegers marked this conversation as resolved.
Show resolved Hide resolved
alreadyParsed.addAll(mainKotlinSources);

logInfo(mavenProject, "Parsing source files");
@@ -466,7 +466,7 @@ private Stream<SourceFile> processTestSources(

// scan Kotlin files
String kotlinSourceDir = getKotlinDirectory(mavenProject.getBuild().getTestSourceDirectory());
List<Path> testKotlinSources = (kotlinSourceDir != null) ? listKotlinSources(mavenProject.getBasedir().toPath().resolve(kotlinSourceDir)) : Collections.emptyList();
List<Path> testKotlinSources = listKotlinSources(mavenProject.getBasedir().toPath().resolve(kotlinSourceDir != null ? kotlinSourceDir : mavenProject.getBuild().getTestSourceDirectory()));
MBoegers marked this conversation as resolved.
Show resolved Hide resolved
alreadyParsed.addAll(testKotlinSources);

Stream<SourceFile> parsedJava = Stream.empty();
@@ -489,7 +489,7 @@ private Stream<SourceFile> processTestSources(
int sourcesParsedBefore = alreadyParsed.size();
Stream<SourceFile> parsedResourceFiles = resourceParser.parse(mavenProject.getBasedir().toPath().resolve("src/test/resources"), alreadyParsed);
logDebug(mavenProject, "Scanned " + (alreadyParsed.size() - sourcesParsedBefore) + " resource files in test scope.");
return Stream.concat(Stream.concat(parsedJava, parsedKotlin), parsedResourceFiles)
return Stream.concat(Stream.concat(parsedJava, kotlinParserBuilder.build().parse(testKotlinSources, baseDir, ctx)), parsedResourceFiles)
MBoegers marked this conversation as resolved.
Show resolved Hide resolved
.map(addProvenance(baseDir, markers, null));
}

@@ -582,7 +582,7 @@ public Map<MavenProject, Xml.Document> parseMaven(List<MavenProject> mavenProjec
throw new MojoFailureException(
mavenProject,
"Failed to parse or resolve the Maven POM file or one of its dependencies; " +
"We can not reliably continue without this information.",
"We can not reliably continue without this information.",
parseExceptionResult.get().getMessage());
}
projectMap.put(mavenProject, (Xml.Document) document);