From c08edf471ea97b200a841f199e53b84cd0d4baca Mon Sep 17 00:00:00 2001 From: "Frank S. Thomas" Date: Thu, 6 Jun 2019 16:58:16 +0200 Subject: [PATCH] Refine replaceAllInGroupId ... to prevent PRs listed in https://github.com/fthomas/scala-steward/pull/545#issuecomment-499437250 This change drops the TLD from the groupId and only uses words that are longer than three characters. --- .../org/scalasteward/core/model/Update.scala | 15 +++++++++++---- .../org/scalasteward/core/model/UpdateTest.scala | 12 ++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/modules/core/src/main/scala/org/scalasteward/core/model/Update.scala b/modules/core/src/main/scala/org/scalasteward/core/model/Update.scala index e4e05f1832..5cc5d0f284 100644 --- a/modules/core/src/main/scala/org/scalasteward/core/model/Update.scala +++ b/modules/core/src/main/scala/org/scalasteward/core/model/Update.scala @@ -52,7 +52,10 @@ sealed trait Update extends Product with Serializable { replaceAllInImpl(false, artifactId.sliding(5).take(5).toList) def replaceAllInGroupId: String => Option[String] = - replaceAllInImpl(false, util.string.extractWords(groupId)) + replaceAllInImpl( + false, + groupId.split('.').toList.drop(1).flatMap(util.string.extractWords).filter(_.length > 3) + ) def replaceAllInImpl(includeGroupId: Boolean, terms: List[String]): String => Option[String] = { val ignoreChar = ".?" @@ -65,10 +68,14 @@ sealed trait Update extends Product with Serializable { } .filter(term => term.nonEmpty && term =!= ignoreChar) - val searchTerm = quotedSearchTerms.mkString_("(", "|", ")") - val groupIdPattern = if (includeGroupId) s"$groupId.*?" else "" + if (quotedSearchTerms.nonEmpty) { + val searchTerm = quotedSearchTerms.mkString_("(", "|", ")") + val groupIdPattern = if (includeGroupId) s"$groupId.*?" else "" - replaceVersion(s"(?i)(.*)($groupIdPattern$searchTerm.*?)${Regex.quote(currentVersion)}".r) + replaceVersion(s"(?i)(.*)($groupIdPattern$searchTerm.*?)${Regex.quote(currentVersion)}".r) + } else { _ => + None + } } private def replaceVersion(regex: Regex): String => Option[String] = diff --git a/modules/core/src/test/scala/org/scalasteward/core/model/UpdateTest.scala b/modules/core/src/test/scala/org/scalasteward/core/model/UpdateTest.scala index 297d865479..a70629d5d8 100644 --- a/modules/core/src/test/scala/org/scalasteward/core/model/UpdateTest.scala +++ b/modules/core/src/test/scala/org/scalasteward/core/model/UpdateTest.scala @@ -235,6 +235,18 @@ class UpdateTest extends FunSuite with Matchers { .replaceAllInGroupId(original) shouldBe Some(expected) } + test("replaceAllInGroupId: ignore TLD") { + val original = """ "com.propensive" %% "contextual" % "1.0.1" """ + Single("com.slamdata", "fs2-gzip", "1.0.1", Nel.of("1.1.1")) + .replaceAllInGroupId(original) shouldBe None + } + + test("replaceAllInGroupId: ignore short words") { + val original = "SBT_VERSION=1.2.7" + Single("org.scala-sbt", "scripted-plugin", "1.2.7", Nel.of("1.2.8")) + .replaceAllInGroupId(original) shouldBe None + } + test("Group.artifactId") { Group( "org.http4s",