Skip to content

Commit

Permalink
Merge pull request #545 from fthomas/topic/use-words-from-groupId
Browse files Browse the repository at this point in the history
Add heuristic that uses words from the groupId
  • Loading branch information
fthomas authored Jun 5, 2019
2 parents e521900 + 0ba5c4a commit 2802788
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ sealed trait Update extends Product with Serializable {
newerVersions.head

def replaceAllInStrict: String => Option[String] =
replaceAllInImpl(true, identity)
replaceAllInImpl(true, searchTerms.toList)

def replaceAllIn: String => Option[String] =
replaceAllInImpl(false, identity)
replaceAllInImpl(false, searchTerms.toList)

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

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

def replaceAllInImpl(
includeGroupId: Boolean,
modifySearchTerms: Nel[String] => Nel[String]
): String => Option[String] = {
def replaceAllInGroupId: String => Option[String] =
replaceAllInImpl(false, util.string.extractWords(groupId))

def replaceAllInImpl(includeGroupId: Boolean, terms: List[String]): String => Option[String] = {
val ignoreChar = ".?"
val quotedSearchTerms = modifySearchTerms(searchTerms)
val quotedSearchTerms = terms
.map { term =>
Regex
.quoteReplacement(Update.removeCommonSuffix(term))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ object EditAlg {
applyHeuristic("strict", update.replaceAllInStrict),
applyHeuristic("original", update.replaceAllIn),
applyHeuristic("relaxed", update.replaceAllInRelaxed),
applyHeuristic("sliding", update.replaceAllInSliding)
applyHeuristic("sliding", update.replaceAllInSliding),
applyHeuristic("groupId", update.replaceAllInGroupId)
)
bindUntilTrue(heuristics).void
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ object string {

/** Extracts words from a string.
*
* Words are separated by '-', '_', or a change from lower to upper case
* and are at least three characters long.
* Words are separated by '-', '_', '.', or a change from lower to
* upper case and are at least three characters long.
*/
def extractWords(s: String): List[String] = {
val minLength = 3
val splitBySeparators: String => List[String] = _.split(Array('-', '_')).toList
splitBySeparators(s)
val splitBySeparators = s.split(Array('-', '_', '.')).toList
splitBySeparators
.flatMap(splitBetweenLowerAndUpperChars)
.filter(_.length >= minLength)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ class UpdateTest extends FunSuite with Matchers {
.replaceAllInSliding(original) shouldBe None
}

test("replaceAllInGroupId: word from groupId") {
val original = """val acolyteVersion = "1.0.49" """
val expected = """val acolyteVersion = "1.0.51" """
Single("org.eu.acolyte", "jdbc-driver", "1.0.49", Nel.of("1.0.51"))
.replaceAllInGroupId(original) shouldBe Some(expected)
}

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

0 comments on commit 2802788

Please sign in to comment.