diff --git a/main/actions/src/main/scala/sbt/DotGraph.scala b/main/actions/src/main/scala/sbt/DotGraph.scala index 8f8545024..bbd7f2446 100644 --- a/main/actions/src/main/scala/sbt/DotGraph.scala +++ b/main/actions/src/main/scala/sbt/DotGraph.scala @@ -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) } diff --git a/util/io/src/main/scala/sbt/IO.scala b/util/io/src/main/scala/sbt/IO.scala index 718a05060..9534eea1d 100644 --- a/util/io/src/main/scala/sbt/IO.scala +++ b/util/io/src/main/scala/sbt/IO.scala @@ -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] = diff --git a/util/io/src/main/scala/sbt/Path.scala b/util/io/src/main/scala/sbt/Path.scala index 2d362e3de..10635e38f 100644 --- a/util/io/src/main/scala/sbt/Path.scala +++ b/util/io/src/main/scala/sbt/Path.scala @@ -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 }