mirror of https://github.com/sbt/sbt.git
[2.x] refactor: Reduce return statements (#8925)
This commit is contained in:
parent
b24ecddbd6
commit
0608a660da
|
|
@ -18,7 +18,6 @@ object EditDistance {
|
||||||
* Translated from the java version at http://www.merriampark.com/ld.htm which is declared to be
|
* Translated from the java version at http://www.merriampark.com/ld.htm which is declared to be
|
||||||
* public domain.
|
* public domain.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings(Array("scalafix:DisableSyntax"))
|
|
||||||
def levenshtein(
|
def levenshtein(
|
||||||
s: String,
|
s: String,
|
||||||
t: String,
|
t: String,
|
||||||
|
|
@ -33,29 +32,33 @@ object EditDistance {
|
||||||
val _ = transposeCost
|
val _ = transposeCost
|
||||||
val n = s.length
|
val n = s.length
|
||||||
val m = t.length
|
val m = t.length
|
||||||
if (n == 0) return m
|
if (n == 0) {
|
||||||
if (m == 0) return n
|
m
|
||||||
|
} else if (m == 0) {
|
||||||
|
n
|
||||||
|
} else {
|
||||||
|
val d = Array.ofDim[Int](n + 1, m + 1)
|
||||||
|
0 to n foreach (x => d(x)(0) = x)
|
||||||
|
0 to m foreach (x => d(0)(x) = x)
|
||||||
|
|
||||||
val d = Array.ofDim[Int](n + 1, m + 1)
|
for (i <- 1 to n; s_i = s(i - 1); j <- 1 to m) {
|
||||||
0 to n foreach (x => d(x)(0) = x)
|
val t_j = t(j - 1)
|
||||||
0 to m foreach (x => d(0)(x) = x)
|
val cost =
|
||||||
|
if (s_i == t_j) matchCost else if (lower(s_i) == lower(t_j)) caseCost else subCost
|
||||||
|
|
||||||
for (i <- 1 to n; s_i = s(i - 1); j <- 1 to m) {
|
val c1 = d(i - 1)(j) + deleteCost
|
||||||
val t_j = t(j - 1)
|
val c2 = d(i)(j - 1) + insertCost
|
||||||
val cost = if (s_i == t_j) matchCost else if (lower(s_i) == lower(t_j)) caseCost else subCost
|
val c3 = d(i - 1)(j - 1) + cost
|
||||||
|
|
||||||
val c1 = d(i - 1)(j) + deleteCost
|
d(i)(j) = c1 min c2 min c3
|
||||||
val c2 = d(i)(j - 1) + insertCost
|
|
||||||
val c3 = d(i - 1)(j - 1) + cost
|
|
||||||
|
|
||||||
d(i)(j) = c1 min c2 min c3
|
if (transpositions) {
|
||||||
|
if (i > 1 && j > 1 && s(i - 1) == t(j - 2) && s(i - 2) == t(j - 1))
|
||||||
if (transpositions) {
|
d(i)(j) = d(i)(j) min (d(i - 2)(j - 2) + cost)
|
||||||
if (i > 1 && j > 1 && s(i - 1) == t(j - 2) && s(i - 2) == t(j - 1))
|
}
|
||||||
d(i)(j) = d(i)(j) min (d(i - 2)(j - 2) + cost)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
d(n)(m)
|
d(n)(m)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,34 +30,36 @@ object CacheUrlConversion {
|
||||||
withForwardSlash
|
withForwardSlash
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings(Array("scalafix:DisableSyntax"))
|
|
||||||
def cacheFileToOriginalUrl(fileUrl: String, cacheDir: File): String = {
|
def cacheFileToOriginalUrl(fileUrl: String, cacheDir: File): String = {
|
||||||
if (!fileUrl.startsWith(FileUrlPrefix)) return fileUrl
|
if (!fileUrl.startsWith(FileUrlPrefix)) {
|
||||||
val filePath = normalizedFilePath(fileUrl)
|
fileUrl
|
||||||
val cachePaths = Seq(
|
} else {
|
||||||
cacheDir.getAbsolutePath,
|
val filePath = normalizedFilePath(fileUrl)
|
||||||
cacheDir.getCanonicalPath
|
val cachePaths = Seq(
|
||||||
).distinct.map(p =>
|
cacheDir.getAbsolutePath,
|
||||||
normalizePathForComparison(if (p.endsWith("/") || p.endsWith("\\")) p else p + "/")
|
cacheDir.getCanonicalPath
|
||||||
)
|
).distinct.map(p =>
|
||||||
|
normalizePathForComparison(if (p.endsWith("/") || p.endsWith("\\")) p else p + "/")
|
||||||
|
)
|
||||||
|
|
||||||
def extractHttpUrl(relativePath: String): Option[String] = {
|
def extractHttpUrl(relativePath: String): Option[String] = {
|
||||||
val protocolSepIndex = relativePath.indexOf('/')
|
val protocolSepIndex = relativePath.indexOf('/')
|
||||||
if (protocolSepIndex > 0) {
|
if (protocolSepIndex > 0) {
|
||||||
val protocol = relativePath.substring(0, protocolSepIndex)
|
val protocol = relativePath.substring(0, protocolSepIndex)
|
||||||
val rest = relativePath.substring(protocolSepIndex + 1)
|
val rest = relativePath.substring(protocolSepIndex + 1)
|
||||||
Some(s"$protocol://$rest")
|
Some(s"$protocol://$rest")
|
||||||
} else None
|
} else None
|
||||||
}
|
|
||||||
|
|
||||||
cachePaths
|
|
||||||
.collectFirst {
|
|
||||||
case cachePath if filePath.startsWith(cachePath) =>
|
|
||||||
val relativePath = filePath.stripPrefix(cachePath)
|
|
||||||
extractHttpUrl(relativePath)
|
|
||||||
}
|
}
|
||||||
.flatten
|
|
||||||
.getOrElse(s"$UnconvertiblePrefix$filePath")
|
cachePaths
|
||||||
|
.collectFirst {
|
||||||
|
case cachePath if filePath.startsWith(cachePath) =>
|
||||||
|
val relativePath = filePath.stripPrefix(cachePath)
|
||||||
|
extractHttpUrl(relativePath)
|
||||||
|
}
|
||||||
|
.flatten
|
||||||
|
.getOrElse(s"$UnconvertiblePrefix$filePath")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def isPortableUrl(url: String): Boolean =
|
def isPortableUrl(url: String): Boolean =
|
||||||
|
|
|
||||||
|
|
@ -240,18 +240,19 @@ private[sbt] object PomGenerator:
|
||||||
(scope, optional)
|
(scope, optional)
|
||||||
|
|
||||||
/** Convert Ivy-style dynamic versions to Maven range format. */
|
/** Convert Ivy-style dynamic versions to Maven range format. */
|
||||||
@SuppressWarnings(Array("scalafix:DisableSyntax"))
|
|
||||||
private def convertVersion(version: String): String =
|
private def convertVersion(version: String): String =
|
||||||
if version == null then null
|
if version == null then null
|
||||||
else if version.endsWith("+") then
|
else if version.endsWith("+") then
|
||||||
val base = version.stripSuffix("+").stripSuffix(".")
|
val base = version.stripSuffix("+").stripSuffix(".")
|
||||||
val parts = base.split('.')
|
val parts = base.split('.')
|
||||||
if parts.nonEmpty then
|
if parts.nonEmpty then
|
||||||
val last =
|
parts.last.toIntOption.map(_ + 1) match {
|
||||||
try parts.last.toInt + 1
|
case Some(last) =>
|
||||||
catch case _: NumberFormatException => return version
|
val upper = (parts.init :+ last.toString).mkString(".")
|
||||||
val upper = (parts.init :+ last.toString).mkString(".")
|
s"[$base,$upper)"
|
||||||
s"[$base,$upper)"
|
case None =>
|
||||||
|
version
|
||||||
|
}
|
||||||
else version
|
else version
|
||||||
else if version == "latest.integration" || version == "latest.release" then ""
|
else if version == "latest.integration" || version == "latest.release" then ""
|
||||||
else version
|
else version
|
||||||
|
|
|
||||||
|
|
@ -70,21 +70,21 @@ object Runner:
|
||||||
if opts.jvmClient then s = s :+ "--client"
|
if opts.jvmClient then s = s :+ "--client"
|
||||||
s
|
s
|
||||||
|
|
||||||
@SuppressWarnings(Array("scalafix:DisableSyntax"))
|
|
||||||
def runNativeClient(sbtBinDir: File, scriptPath: String, opts: LauncherOptions): Int =
|
def runNativeClient(sbtBinDir: File, scriptPath: String, opts: LauncherOptions): Int =
|
||||||
val sbtn = new File(sbtBinDir, "sbtn-x86_64-pc-win32.exe")
|
val sbtn = new File(sbtBinDir, "sbtn-x86_64-pc-win32.exe")
|
||||||
if !sbtn.isFile then
|
if !sbtn.isFile then
|
||||||
System.err.println("[error] sbtn-x86_64-pc-win32.exe not found in " + sbtBinDir)
|
System.err.println("[error] sbtn-x86_64-pc-win32.exe not found in " + sbtBinDir)
|
||||||
return 1
|
1
|
||||||
val args = Seq("--sbt-script=" + scriptPath.replace(" ", "%20")) ++
|
else
|
||||||
(if opts.verbose then Seq("-v") else Nil) ++
|
val args = Seq("--sbt-script=" + scriptPath.replace(" ", "%20")) ++
|
||||||
opts.residual
|
(if opts.verbose then Seq("-v") else Nil) ++
|
||||||
val cmd = sbtn.getAbsolutePath +: args
|
opts.residual
|
||||||
if opts.verbose then
|
val cmd = sbtn.getAbsolutePath +: args
|
||||||
System.err.println("# running native client")
|
if opts.verbose then
|
||||||
cmd.foreach(a => System.err.println(a))
|
System.err.println("# running native client")
|
||||||
val proc = Process(cmd, None, "SBT_SCRIPT" -> scriptPath)
|
cmd.foreach(a => System.err.println(a))
|
||||||
proc.!
|
val proc = Process(cmd, None, "SBT_SCRIPT" -> scriptPath)
|
||||||
|
proc.!
|
||||||
|
|
||||||
def runJvm(
|
def runJvm(
|
||||||
javaCmd: String,
|
javaCmd: String,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue