mirror of https://github.com/sbt/sbt.git
Path normalization for Windows + scalafmt
- CacheUrlConversion: normalize paths for comparison (forward slashes) and strip leading slash on Windows file URIs so cache matching works. - Apply scalafmt to touched files.
This commit is contained in:
parent
afae6daea2
commit
ef6968e20c
|
|
@ -382,7 +382,8 @@ class CoursierDependencyResolution(
|
|||
.groupBy(_._1)
|
||||
.view
|
||||
.mapValues(_.map { case (_, pub, art, _) =>
|
||||
val originalUrl = lmcoursier.internal.CacheUrlConversion.cacheFileToOriginalUrl(art.url, cache)
|
||||
val originalUrl =
|
||||
lmcoursier.internal.CacheUrlConversion.cacheFileToOriginalUrl(art.url, cache)
|
||||
(originalUrl, pub.classifier.value, pub.ext.value)
|
||||
})
|
||||
.toMap
|
||||
|
|
|
|||
|
|
@ -15,13 +15,30 @@ object CacheUrlConversion {
|
|||
final val FileUrlPrefix = "file:"
|
||||
final val UnconvertiblePrefix = "${CSR_CACHE}"
|
||||
|
||||
private def normalizePathForComparison(path: String): String =
|
||||
path.replace('\\', '/')
|
||||
|
||||
private def normalizedFilePath(fileUrl: String): String = {
|
||||
val afterPrefix = fileUrl.stripPrefix(FileUrlPrefix).replaceFirst("^/+", "/")
|
||||
val withForwardSlash = normalizePathForComparison(afterPrefix)
|
||||
if (
|
||||
withForwardSlash.length >= 3 && withForwardSlash
|
||||
.charAt(0) == '/' && withForwardSlash.charAt(2) == ':'
|
||||
)
|
||||
withForwardSlash.substring(1)
|
||||
else
|
||||
withForwardSlash
|
||||
}
|
||||
|
||||
def cacheFileToOriginalUrl(fileUrl: String, cacheDir: File): String = {
|
||||
if (!fileUrl.startsWith(FileUrlPrefix)) return fileUrl
|
||||
val filePath = fileUrl.stripPrefix(FileUrlPrefix).replaceFirst("^/+", "/")
|
||||
val filePath = normalizedFilePath(fileUrl)
|
||||
val cachePaths = Seq(
|
||||
cacheDir.getAbsolutePath,
|
||||
cacheDir.getCanonicalPath
|
||||
).distinct.map(p => if (p.endsWith("/")) p else p + "/")
|
||||
).distinct.map(p =>
|
||||
normalizePathForComparison(if (p.endsWith("/") || p.endsWith("\\")) p else p + "/")
|
||||
)
|
||||
|
||||
def extractHttpUrl(relativePath: String): Option[String] = {
|
||||
val protocolSepIndex = relativePath.indexOf('/')
|
||||
|
|
|
|||
|
|
@ -44,7 +44,11 @@ object DependencyLockManager:
|
|||
isValid
|
||||
}
|
||||
|
||||
private def artifactUrlForLock(rawUrl: String, cacheDir: Option[File], moduleDesc: String): String =
|
||||
private def artifactUrlForLock(
|
||||
rawUrl: String,
|
||||
cacheDir: Option[File],
|
||||
moduleDesc: String
|
||||
): String =
|
||||
if !rawUrl.startsWith(CacheUrlConversion.FileUrlPrefix) then rawUrl
|
||||
else
|
||||
cacheDir match
|
||||
|
|
|
|||
Loading…
Reference in New Issue