From 73dacf1447f19528e6ee3dca4fae31ba8b982942 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Mon, 4 Dec 2023 18:59:19 +0100 Subject: [PATCH 1/2] Always parse Maven wrapper files Fixes #1005 --- .sdkmanrc | 3 +++ .../openrewrite/maven/MavenMojoProjectParser.java | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .sdkmanrc diff --git a/.sdkmanrc b/.sdkmanrc new file mode 100644 index 00000000..bc36ae5d --- /dev/null +++ b/.sdkmanrc @@ -0,0 +1,3 @@ +# Enable auto-env through the sdkman_auto_env config +# Add key=value pairs of SDKs to use below +java=21-tem diff --git a/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java b/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java index 4c0b9ae9..46f92eaa 100644 --- a/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java +++ b/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java @@ -206,6 +206,17 @@ public Stream listSourceFiles(MavenProject mavenProject, @Nullable X .map(addProvenance(baseDir, projectProvenance, null)); logDebug(mavenProject, "Parsed " + (alreadyParsed.size() - sourcesParsedBefore) + " additional files found within the project."); sourceFiles = Stream.concat(sourceFiles, parsedResourceFiles); + } else { + // Only parse Maven wrapper files, such that UpdateMavenWrapper can use the version information. + int sourcesParsedBefore = alreadyParsed.size(); + Stream parsedResourceFiles = Stream.concat( + rp.parse(mavenProject.getBasedir().toPath().resolve(".mvn/wrapper"), alreadyParsed), + Stream.concat( + rp.parse(mavenProject.getBasedir().toPath().resolve("mvnw"), alreadyParsed), + rp.parse(mavenProject.getBasedir().toPath().resolve("mvnw.bat"), alreadyParsed))) + .map(addProvenance(baseDir, projectProvenance, null)); + logDebug(mavenProject, "Parsed " + (alreadyParsed.size() - sourcesParsedBefore) + " Maven wrapper files found within the project."); + sourceFiles = Stream.concat(sourceFiles, parsedResourceFiles); } // log parse errors here at the end, so that we don't log parse errors for files that were excluded @@ -216,7 +227,7 @@ private SourceFile logParseErrors(SourceFile source) { if (source instanceof ParseError) { 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()); } From 74778511ffa54b3f3d15b7b13a404080f46d3bc1 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Mon, 4 Dec 2023 22:28:46 +0100 Subject: [PATCH 2/2] Update src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java --- src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java b/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java index 46f92eaa..24888253 100644 --- a/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java +++ b/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java @@ -213,7 +213,7 @@ public Stream listSourceFiles(MavenProject mavenProject, @Nullable X rp.parse(mavenProject.getBasedir().toPath().resolve(".mvn/wrapper"), alreadyParsed), Stream.concat( rp.parse(mavenProject.getBasedir().toPath().resolve("mvnw"), alreadyParsed), - rp.parse(mavenProject.getBasedir().toPath().resolve("mvnw.bat"), alreadyParsed))) + rp.parse(mavenProject.getBasedir().toPath().resolve("mvnw.cmd"), alreadyParsed))) .map(addProvenance(baseDir, projectProvenance, null)); logDebug(mavenProject, "Parsed " + (alreadyParsed.size() - sourcesParsedBefore) + " Maven wrapper files found within the project."); sourceFiles = Stream.concat(sourceFiles, parsedResourceFiles);