From 547e934134e98fb9a595b79a6f5d6e7bd6d862d7 Mon Sep 17 00:00:00 2001 From: Adriano Machado <60320+ammachado@users.noreply.github.com> Date: Sun, 27 Oct 2024 11:29:09 -0400 Subject: [PATCH] Fix download snapshot warnings --- .gitignore | 1 + .../maven/MavenMojoProjectParser.java | 20 ++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index d4acdc53..b6d51cdb 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ pom.xml.versionsBackup .classpath .project .settings +.vscode/ diff --git a/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java b/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java index 72742f09..d60eb750 100644 --- a/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java +++ b/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java @@ -47,6 +47,7 @@ import org.openrewrite.marker.ci.BuildEnvironment; import org.openrewrite.maven.cache.InMemoryMavenPomCache; import org.openrewrite.maven.cache.MavenPomCache; +import org.openrewrite.maven.internal.RawPom; import org.openrewrite.maven.internal.RawRepositories; import org.openrewrite.maven.tree.Pom; import org.openrewrite.maven.tree.ProfileActivation; @@ -57,6 +58,7 @@ import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.nio.charset.Charset; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; @@ -615,7 +617,10 @@ public Map parseMaven(List mavenProjec * @param paths A list of paths to poms that have been collected so far. */ private void collectPoms(MavenProject project, Set paths, MavenExecutionContextView ctx) { - paths.add(pomPath(project)); + if (!paths.add(pomPath(project))) { + return; + } + ResolvedGroupArtifactVersion gav = createResolvedGAV(project, ctx); ctx.getPomCache().putPom(gav, createPom(gav, project)); @@ -822,11 +827,12 @@ private static ResolvedGroupArtifactVersion createResolvedGAV(MavenProject proje ); } - private static Pom createPom(ResolvedGroupArtifactVersion gav, MavenProject project) { - Pom.PomBuilder builder = Pom.builder() - .gav(gav) - ; - // TODO: complete mapping - return builder.build(); + private static @Nullable Pom createPom(ResolvedGroupArtifactVersion gav, MavenProject project) { + try (InputStream is = Files.newInputStream(project.getFile().toPath())) { + RawPom rawPom = RawPom.parse(is, null); + return rawPom.toPom(project.getBasedir().toPath(), null); + } catch (IOException e) { + return null; + } } }