From d444088b208476fae750ebcbf3088c951cabf249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20C=2E=20Silva?= <12188364+andrecsilva@users.noreply.github.com> Date: Fri, 4 Oct 2024 09:41:08 -0300 Subject: [PATCH] Codetf output for pom files now consider target lines instead of source (#454) \close #work --- .../maven/DefaultArtifactInjectionPositionFinder.java | 6 +++--- .../java/io/codemodder/plugins/maven/MavenProviderTest.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/codemodder-plugin-maven/src/main/java/io/codemodder/plugins/maven/DefaultArtifactInjectionPositionFinder.java b/plugins/codemodder-plugin-maven/src/main/java/io/codemodder/plugins/maven/DefaultArtifactInjectionPositionFinder.java index 4bd2a8496..63998eaf3 100644 --- a/plugins/codemodder-plugin-maven/src/main/java/io/codemodder/plugins/maven/DefaultArtifactInjectionPositionFinder.java +++ b/plugins/codemodder-plugin-maven/src/main/java/io/codemodder/plugins/maven/DefaultArtifactInjectionPositionFinder.java @@ -18,17 +18,17 @@ public int find(final List> deltas, final String artifactI if (hasArtifactId && hasVersion) { // if it has the artifact and version, it could be the section, which // is 2nd preference - backupPosition = 1 + delta.getSource().getPosition(); + backupPosition = 1 + delta.getTarget().getPosition(); } else if (hasArtifactId) { // if it has the artifact but not the version, it could be the section, which // is preferred - return 1 + delta.getSource().getPosition(); + return 1 + delta.getTarget().getPosition(); } } if (backupPosition != null) { return backupPosition; } // the fallback is to just use the first change to the file - return 1 + deltas.get(0).getSource().getPosition(); + return 1 + deltas.get(0).getTarget().getPosition(); } } diff --git a/plugins/codemodder-plugin-maven/src/test/java/io/codemodder/plugins/maven/MavenProviderTest.java b/plugins/codemodder-plugin-maven/src/test/java/io/codemodder/plugins/maven/MavenProviderTest.java index 1925c7636..3fe5b7e3b 100644 --- a/plugins/codemodder-plugin-maven/src/test/java/io/codemodder/plugins/maven/MavenProviderTest.java +++ b/plugins/codemodder-plugin-maven/src/test/java/io/codemodder/plugins/maven/MavenProviderTest.java @@ -172,11 +172,11 @@ private static Stream expectedChangeDescriptionLocations() { Arguments.of(simplePom, 7), // injects all new text in one delta Arguments.of( simplePomWithExistingSections, - 16), // already has both sections, record at dependencies section + 17), // already has both sections, record at dependencies section Arguments.of( webgoatPomThatJustNeedsUpgrades, 151), // just updating the version number here in the properties - Arguments.of(webgoatPom, 413) // add to the end of the dependencies section + Arguments.of(webgoatPom, 419) // add to the end of the dependencies section ); }