Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new replaceAllInSliding strategy #527

Merged
merged 1 commit into from
May 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,21 @@ sealed trait Update extends Product with Serializable {
newerVersions.head

def replaceAllInStrict(target: String): Option[String] =
replaceAllInImpl(target, true, false)
replaceAllInImpl(target, true, identity)

def replaceAllIn(target: String): Option[String] =
replaceAllInImpl(target, false, false)
replaceAllInImpl(target, false, identity)

def replaceAllInRelaxed(target: String): Option[String] =
replaceAllInImpl(target, false, true)
replaceAllInImpl(target, false, terms => terms ++ util.string.extractWords(artifactId))

def replaceAllInSliding(target: String): Option[String] =
replaceAllInImpl(target, false, terms => terms ++ artifactId.sliding(5).take(5).toList)

def replaceAllInImpl(
target: String,
includeGroupId: Boolean,
splitArtifactId: Boolean
modifySearchTerms: Nel[String] => Nel[String]
): Option[String] = {
def replaceVersion(regex: Regex): Option[String] =
util.string.replaceSomeInOpt(
Expand All @@ -65,10 +68,7 @@ sealed trait Update extends Product with Serializable {
Some(group1 + m.group(2) + nextVersion)
}
)

val artifactIdParts = if (splitArtifactId) util.string.extractWords(artifactId) else Nil
val quotedSearchTerms = searchTerms
.concat(artifactIdParts)
val quotedSearchTerms = modifySearchTerms(searchTerms)
.map { term =>
Regex
.quoteReplacement(Update.removeCommonSuffix(term))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ object EditAlg {
log("replaceAllIn") >>
fileAlg.editSourceFiles(repoDir, update.replaceAllIn),
log("replaceAllInRelaxed") >>
fileAlg.editSourceFiles(repoDir, update.replaceAllInRelaxed)
fileAlg.editSourceFiles(repoDir, update.replaceAllInRelaxed),
log("replaceAllInSliding") >>
fileAlg.editSourceFiles(repoDir, update.replaceAllInSliding)
)

bindUntilTrue(strategies).void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,17 @@ class UpdateTest extends FunSuite with Matchers {
.replaceAllInRelaxed(original) shouldBe Some(expected)
}

test("replaceAllInSliding: mongo from mongodb") {
val original = """val mongoVersion = "3.7.0" """
val expected = """val mongoVersion = "3.7.1" """
Group(
"org.mongodb",
Nel.of("mongodb-driver", "mongodb-driver-async", "mongodb-driver-core"),
"3.7.0",
Nel.of("3.7.1")
).replaceAllInSliding(original) shouldBe Some(expected)
}

test("Group.artifactId") {
Group(
"org.http4s",
Expand Down