mirror of https://github.com/sbt/sbt.git
remove duplicate relativize implementation from Path
This commit is contained in:
parent
0c95e44ad5
commit
9d1d18cd71
|
|
@ -62,7 +62,7 @@ object DotGraph
|
|||
|
||||
private def relativized(roots: Iterable[File], path: File): String =
|
||||
{
|
||||
val relativized = roots.flatMap(root => Path.relativize(root, path))
|
||||
val relativized = roots.flatMap(root => IO.relativize(root, path))
|
||||
val shortest = (Int.MaxValue /: relativized)(_ min _.length)
|
||||
relativized.find(_.length == shortest).getOrElse(path.getName)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -502,6 +502,10 @@ object IO
|
|||
}
|
||||
}
|
||||
|
||||
/** Returns the relative file for `file` relative to directory `base` or None if `base` is not a parent of `file`.
|
||||
* If `file` or `base` are not absolute, they are first resolved against the current working directory. */
|
||||
def relativizeFile(base: File, file: File): Option[File] = relativize(base, file).map { path => new File(path) }
|
||||
|
||||
/** Returns the path for `file` relative to directory `base` or None if `base` is not a parent of `file`.
|
||||
* If `file` or `base` are not absolute, they are first resolved against the current working directory. */
|
||||
def relativize(base: File, file: File): Option[String] =
|
||||
|
|
|
|||
|
|
@ -74,33 +74,8 @@ object Path extends PathExtra
|
|||
/** The separator character of the platform.*/
|
||||
val sep = java.io.File.separatorChar
|
||||
|
||||
def relativizeFile(baseFile: File, file: File): Option[File] = relativize(baseFile, file).map { path => new File(path) }
|
||||
private[sbt] def relativize(baseFile: File, file: File): Option[String] =
|
||||
{
|
||||
val pathString = file.getAbsolutePath
|
||||
baseFileString(baseFile) flatMap
|
||||
{
|
||||
baseString =>
|
||||
{
|
||||
if(pathString.startsWith(baseString))
|
||||
Some(pathString.substring(baseString.length))
|
||||
else
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
private def baseFileString(baseFile: File): Option[String] =
|
||||
if(baseFile.isDirectory)
|
||||
{
|
||||
val cp = baseFile.getAbsolutePath
|
||||
assert(cp.length > 0)
|
||||
if(cp.charAt(cp.length - 1) == File.separatorChar)
|
||||
Some(cp)
|
||||
else
|
||||
Some(cp + File.separatorChar)
|
||||
}
|
||||
else
|
||||
None
|
||||
@deprecated("Use IO.relativizeFile", "0.13.1")
|
||||
def relativizeFile(baseFile: File, file: File): Option[File] = IO.relativizeFile(baseFile, file)
|
||||
|
||||
def toURLs(files: Seq[File]): Array[URL] = files.map(_.toURI.toURL).toArray
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue