Skip to content

Commit

Permalink
Merge pull request #547 from fthomas/topic/refine-replaceAllInGroupId
Browse files Browse the repository at this point in the history
Refine replaceAllInGroupId
  • Loading branch information
fthomas authored Jun 6, 2019
2 parents 9145e1f + c08edf4 commit 2d92354
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ".?"
Expand All @@ -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] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 2d92354

Please sign in to comment.