Skip to content

Commit 1f0282a

Browse files
authored
Merge pull request #2931 from scala-steward-org/topic/maven-deps-with-scala-bin-suffix
Support Maven dependencies with a property for the Scala binary suffix
2 parents bcebebe + ef550af commit 1f0282a

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

modules/core/src/main/scala/org/scalasteward/core/edit/update/ModulePositionScanner.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ object ModulePositionScanner {
7272
mavenDependencyRegex(dependency).findAllIn(fileData.content).matchData.map { m =>
7373
val groupId = Substring.Position.fromMatch(fileData.path, m, dependency.groupId.value)
7474
val artifactId = Substring.Position.fromMatch(fileData.path, m, dependency.artifactId.name)
75-
val version = Substring.Position.fromMatch(fileData.path, m, m.group(1))
75+
val version = Substring.Position.fromMatch(fileData.path, m, m.group(2))
7676
ModulePosition(groupId, artifactId, version)
7777
}
7878

7979
private def mavenDependencyRegex(dependency: Dependency): Regex = {
8080
val g = Regex.quote(dependency.groupId.value)
8181
val a = Regex.quote(dependency.artifactId.name)
82-
raw"""<groupId>$g</groupId>\s*<artifactId>$a</artifactId>\s*<version>(.*)</version>""".r
82+
raw"""<groupId>$g</groupId>\s*<artifactId>$a(|_[^<]+)</artifactId>\s*<version>(.*)</version>""".r
8383
}
8484
}

modules/core/src/main/scala/org/scalasteward/core/edit/update/Selector.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ object Selector {
7575
case _ => true
7676
}
7777
.filter { p =>
78+
val artifactIdNames = Set(p.artifactId, p.artifactId.takeWhile(_ =!= '_'))
7879
dependencies.exists { d =>
79-
d.groupId.value === p.groupId && d.artifactId.names.contains_(p.artifactId)
80+
d.groupId.value === p.groupId && d.artifactId.names.exists(artifactIdNames)
8081
}
8182
}
8283

modules/core/src/test/scala/org/scalasteward/core/edit/RewriteTest.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,18 @@ class RewriteTest extends FunSuite {
419419
runApplyUpdate(update, original, expected)
420420
}
421421

422+
test("artifactId and version change of Maven dependency with binary suffix") {
423+
val update = ("org.foo".g % ("log4cats", "log4cats_2.13").a % "1.1.1" %> "1.2.0").single
424+
.copy(newerArtifactId = Some("log4dogs"))
425+
val original = Map("pom.xml" -> s"""<groupId>org.foo</groupId>
426+
|<artifactId>log4cats_$${scala.binary.version}</artifactId>
427+
|<version>1.1.1</version>""".stripMargin)
428+
val expected = Map("pom.xml" -> s"""<groupId>org.foo</groupId>
429+
|<artifactId>log4dogs_$${scala.binary.version}</artifactId>
430+
|<version>1.2.0</version>""".stripMargin)
431+
runApplyUpdate(update, original, expected)
432+
}
433+
422434
// https://github.com/scala-steward-org/scala-steward/pull/566
423435
test("prevent exception: named capturing group is missing trailing '}'") {
424436
val update =

0 commit comments

Comments
 (0)