Drop deprecations: io and threading functions.

This commit is contained in:
Ilya Gorbunov
2016-01-19 20:25:01 +03:00
parent 25c4453dc5
commit b39b29dfea
8 changed files with 43 additions and 166 deletions
@@ -41,12 +41,7 @@ public fun thread(start: Boolean = true, isDaemon: Boolean = false, contextClass
return thread return thread
} }
@Deprecated("Use thread function with the 'isDaemon' parameter") /**
public fun thread(start: Boolean = true, contextClassLoader: ClassLoader? = null, name: String? = null, priority: Int = -1, daemon: Boolean, block: () -> Unit): Thread =
thread(start = start, isDaemon = daemon, contextClassLoader = contextClassLoader, name = name, priority = priority, block = block)
/**
* Gets the value in the current thread's copy of this * Gets the value in the current thread's copy of this
* thread-local variable or replaces the value with the result of calling * thread-local variable or replaces the value with the result of calling
* [default] function in case if that value was `null`. * [default] function in case if that value was `null`.
+3 -5
View File
@@ -8,16 +8,14 @@ package kotlin.io
*/ */
public val DEFAULT_BUFFER_SIZE: Int = 64 * 1024 public val DEFAULT_BUFFER_SIZE: Int = 64 * 1024
@Deprecated("Use DEFAULT_BUFFER_SIZE constant instead.", ReplaceWith("kotlin.io.DEFAULT_BUFFER_SIZE")) @Deprecated("Use DEFAULT_BUFFER_SIZE constant instead.", ReplaceWith("kotlin.io.DEFAULT_BUFFER_SIZE"), level = DeprecationLevel.ERROR)
public val defaultBufferSize: Int = DEFAULT_BUFFER_SIZE public val defaultBufferSize: Int = DEFAULT_BUFFER_SIZE
/** /**
* Returns the default block size for forEachBlock(). * Returns the default block size for forEachBlock().
*/ */
@Deprecated("This constant will become private soon, use its value instead.", ReplaceWith("4096")) internal val defaultBlockSize: Int = 4096
public val defaultBlockSize: Int = 4096
/** /**
* Returns the minimum block size for forEachBlock(). * Returns the minimum block size for forEachBlock().
*/ */
@Deprecated("This constant will become private soon, use its value instead.", ReplaceWith("512")) internal val minimumBlockSize: Int = 512
public val minimumBlockSize: Int = 512
@@ -6,9 +6,6 @@ import java.io.*
import java.nio.charset.Charset import java.nio.charset.Charset
import java.util.NoSuchElementException import java.util.NoSuchElementException
@Deprecated("It's not recommended to iterate through input stream of bytes unless it's buffered. Use buffered() extension on stream to make it buffered.", ReplaceWith("this.buffered().iterator()"))
public operator fun InputStream.iterator(): ByteIterator = buffered().iterator()
/** Returns an [Iterator] of bytes read from this input stream. */ /** Returns an [Iterator] of bytes read from this input stream. */
public operator fun BufferedInputStream.iterator(): ByteIterator = public operator fun BufferedInputStream.iterator(): ByteIterator =
object : ByteIterator() { object : ByteIterator() {
+5 -99
View File
@@ -45,68 +45,12 @@ public fun createTempFile(prefix: String = "tmp", suffix: String? = null, direct
return File.createTempFile(prefix, suffix, directory) return File.createTempFile(prefix, suffix, directory)
} }
/**
* Returns this if this file is a directory, or the parent if it is a file inside a directory.
*/
@Deprecated("This property has unclear semantics and will be removed soon.")
public val File.directory: File
get() = if (isDirectory) this else parentFile!!
/**
* Returns parent of this abstract path name, or `null` if it has no parent.
*/
@Deprecated("Use 'parentFile' property instead.", ReplaceWith("parentFile"), DeprecationLevel.ERROR)
public val File.parent: File?
get() = parentFile
/** /**
* Returns the extension of this file (not including the dot), or an empty string if it doesn't have one. * Returns the extension of this file (not including the dot), or an empty string if it doesn't have one.
*/ */
public val File.extension: String public val File.extension: String
get() = name.substringAfterLast('.', "") get() = name.substringAfterLast('.', "")
/**
* Replaces all separators in the string used to separate directories with system ones and returns the resulting string.
*
* @return the pathname with system separators.
*/
@Deprecated("Use File.path instead", ReplaceWith("File(this).path", "java.io.File"))
public fun String.separatorsToSystem(): String {
val otherSep = if (File.separator == "/") "\\" else "/"
return replace(otherSep, File.separator)
}
/**
* Replaces all path separators in the string with system ones and returns the resulting string.
*
* @return the pathname with system separators.
*/
@Deprecated("This function is deprecated")
public fun String.pathSeparatorsToSystem(): String {
val otherSep = if (File.pathSeparator == ":") ";" else ":"
return replace(otherSep, File.pathSeparator)
}
/**
* Replaces path and directories separators with corresponding system ones and returns the resulting string.
*
* @return the pathname with system separators.
*/
@Deprecated("This function is deprecated")
public fun String.allSeparatorsToSystem(): String {
return separatorsToSystem().pathSeparatorsToSystem()
}
/**
* Returns a pathname of this file with all path separators replaced with File.pathSeparator.
*
* @return the pathname with system separators.
*/
@Deprecated("File has already system separators.")
public fun File.separatorsToSystem(): String {
return toString().separatorsToSystem()
}
/** /**
* Returns [path] of this File using the invariant separator '/' to * Returns [path] of this File using the invariant separator '/' to
* separate the names in the name sequence. * separate the names in the name sequence.
@@ -120,20 +64,6 @@ public val File.invariantSeparatorsPath: String
public val File.nameWithoutExtension: String public val File.nameWithoutExtension: String
get() = name.substringBeforeLast(".") get() = name.substringBeforeLast(".")
/**
* Calculates the relative path for this file from [base] file.
* Note that the [base] file is treated as a directory.
* If this file matches the [base] file, then an empty string will be returned.
*
* @return relative path from [base] to this.
*
* @throws IllegalArgumentException if this and base paths have different roots.
*/
@Deprecated("This function will change return type to File soon. Use toRelativeString instead.", ReplaceWith("toRelativeString(base)"))
public fun File.relativeTo(base: File): String
= toRelativeString(base)
/** /**
* Calculates the relative path for this file from [base] file. * Calculates the relative path for this file from [base] file.
* Note that the [base] file is treated as a directory. * Note that the [base] file is treated as a directory.
@@ -155,8 +85,10 @@ public fun File.toRelativeString(base: File): String
* *
* @throws IllegalArgumentException if this and base paths have different roots. * @throws IllegalArgumentException if this and base paths have different roots.
*/ */
@Deprecated("This function will be renamed to relativeTo soon.") public fun File.relativeTo(base: File): File = File(this.toRelativeString(base))
public fun File.relativeToFile(base: File): File = File(this.relativeTo(base))
@Deprecated("Use relativeTo instead.", ReplaceWith("this.relativeTo(base)"), level = DeprecationLevel.WARNING)
public fun File.relativeToFile(base: File): File = File(this.toRelativeString(base))
/** /**
@@ -225,25 +157,6 @@ private fun File.toRelativeStringOrNull(base: File): String? {
return res.toString() return res.toString()
} }
/**
* Calculates the relative path for this file from [descendant] file.
* Note that the [descendant] file is treated as a directory.
* If this file matches the [descendant] directory or does not belong to it,
* then an empty string will be returned.
*/
@Deprecated("Use relativeTo() function instead")
public fun File.relativePath(descendant: File): String {
val prefix = directory.canonicalPath
val answer = descendant.canonicalPath
return if (answer.startsWith(prefix)) {
val prefixSize = prefix.length
if (answer.length > prefixSize) {
answer.substring(prefixSize + 1)
} else ""
} else {
answer
}
}
/** /**
* Copies this file to the given output [dst], returning the number of bytes copied. * Copies this file to the given output [dst], returning the number of bytes copied.
@@ -338,7 +251,7 @@ public fun File.copyRecursively(dst: File,
OnErrorAction.TERMINATE) OnErrorAction.TERMINATE)
return false return false
} else { } else {
val relPath = src.relativeTo(this) val relPath = src.toRelativeString(this)
val dstFile = File(dst, relPath) val dstFile = File(dst, relPath)
if (dstFile.exists() && !(src.isDirectory && dstFile.isDirectory)) { if (dstFile.exists() && !(src.isDirectory && dstFile.isDirectory)) {
if (onError(dstFile, FileAlreadyExistsException(file = src, if (onError(dstFile, FileAlreadyExistsException(file = src,
@@ -369,13 +282,6 @@ public fun File.copyRecursively(dst: File,
*/ */
public fun File.deleteRecursively(): Boolean = walkBottomUp().fold(true, { res, it -> (it.delete() || !it.exists()) && res }) public fun File.deleteRecursively(): Boolean = walkBottomUp().fold(true, { res, it -> (it.delete() || !it.exists()) && res })
/**
* Returns an array of files and directories in the directory that match the specified [filter]
* or `null` if this file does not denote a directory.
*/
@Deprecated("Provided for binary compatiblity", level = DeprecationLevel.HIDDEN)
public fun File.listFiles(filter: (file: File) -> Boolean): Array<File>? = listFiles(FileFilter(filter))
/** /**
* Determines whether this file belongs to the same root as [other] * Determines whether this file belongs to the same root as [other]
* and starts with all components of [other] in the same order. * and starts with all components of [other] in the same order.
+2 -2
View File
@@ -188,14 +188,14 @@ class FileTreeWalkTest {
private fun compareWalkResults(expected: Set<String>, basedir: File, filter: (File) -> Boolean) { private fun compareWalkResults(expected: Set<String>, basedir: File, filter: (File) -> Boolean) {
val namesTopDown = HashSet<String>() val namesTopDown = HashSet<String>()
for (file in basedir.walkTopDown().treeFilter { filter(it) }) { for (file in basedir.walkTopDown().treeFilter { filter(it) }) {
val name = file.relativeTo(basedir) val name = file.toRelativeString(basedir)
assertFalse(namesTopDown.contains(name), "$name is visited twice") assertFalse(namesTopDown.contains(name), "$name is visited twice")
namesTopDown.add(name) namesTopDown.add(name)
} }
assertEquals(expected, namesTopDown, "Top-down walk results differ") assertEquals(expected, namesTopDown, "Top-down walk results differ")
val namesBottomUp = HashSet<String>() val namesBottomUp = HashSet<String>()
for (file in basedir.walkBottomUp().treeFilter { filter(it) }) { for (file in basedir.walkBottomUp().treeFilter { filter(it) }) {
val name = file.relativeTo(basedir) val name = file.toRelativeString(basedir)
assertFalse(namesBottomUp.contains(name), "$name is visited twice") assertFalse(namesBottomUp.contains(name), "$name is visited twice")
namesBottomUp.add(name) namesBottomUp.add(name)
} }
+29 -48
View File
@@ -74,43 +74,43 @@ class FilesTest {
val file1 = File("/foo/bar/baz") val file1 = File("/foo/bar/baz")
val file2 = File("/foo/baa/ghoo") val file2 = File("/foo/baa/ghoo")
assertEquals("../../bar/baz", file1.relativeToFile(file2).invariantSeparatorsPath) assertEquals("../../bar/baz", file1.relativeTo(file2).invariantSeparatorsPath)
val file3 = File("/foo/bar") val file3 = File("/foo/bar")
assertEquals("baz", file1.relativeTo(file3)) assertEquals("baz", file1.toRelativeString(file3))
assertEquals("..", file3.relativeTo(file1)) assertEquals("..", file3.toRelativeString(file1))
val file4 = File("/foo/bar/") val file4 = File("/foo/bar/")
assertEquals("baz", file1.relativeTo(file4)) assertEquals("baz", file1.toRelativeString(file4))
assertEquals("..", file4.relativeTo(file1)) assertEquals("..", file4.toRelativeString(file1))
assertEquals("", file3.relativeTo(file4)) assertEquals("", file3.toRelativeString(file4))
assertEquals("", file4.relativeTo(file3)) assertEquals("", file4.toRelativeString(file3))
val file5 = File("/foo/baran") val file5 = File("/foo/baran")
assertEquals("../bar", file3.relativeToFile(file5).invariantSeparatorsPath) assertEquals("../bar", file3.relativeTo(file5).invariantSeparatorsPath)
assertEquals("../baran", file5.relativeToFile(file3).invariantSeparatorsPath) assertEquals("../baran", file5.relativeTo(file3).invariantSeparatorsPath)
assertEquals("../bar", file4.relativeToFile(file5).invariantSeparatorsPath) assertEquals("../bar", file4.relativeTo(file5).invariantSeparatorsPath)
assertEquals("../baran", file5.relativeToFile(file4).invariantSeparatorsPath) assertEquals("../baran", file5.relativeTo(file4).invariantSeparatorsPath)
if (isBackslashSeparator) { if (isBackslashSeparator) {
val file6 = File("C:\\Users\\Me") val file6 = File("C:\\Users\\Me")
val file7 = File("C:\\Users\\Me\\Documents") val file7 = File("C:\\Users\\Me\\Documents")
assertEquals("..", file6.relativeTo(file7)) assertEquals("..", file6.toRelativeString(file7))
assertEquals("Documents", file7.relativeTo(file6)) assertEquals("Documents", file7.toRelativeString(file6))
val file8 = File("""\\my.host\home/user/documents/vip""") val file8 = File("""\\my.host\home/user/documents/vip""")
val file9 = File("""\\my.host\home/other/images/nice""") val file9 = File("""\\my.host\home/other/images/nice""")
assertEquals("../../../user/documents/vip", file8.relativeToFile(file9).invariantSeparatorsPath) assertEquals("../../../user/documents/vip", file8.relativeTo(file9).invariantSeparatorsPath)
assertEquals("../../../other/images/nice", file9.relativeToFile(file8).invariantSeparatorsPath) assertEquals("../../../other/images/nice", file9.relativeTo(file8).invariantSeparatorsPath)
} }
if (isCaseInsensitiveFileSystem) { if (isCaseInsensitiveFileSystem) {
assertEquals("bar", File("C:/bar").relativeTo(File("c:/"))) assertEquals("bar", File("C:/bar").toRelativeString(File("c:/")))
} }
} }
@@ -118,31 +118,32 @@ class FilesTest {
val nested = File("foo/bar") val nested = File("foo/bar")
val base = File("foo") val base = File("foo")
assertEquals("bar", nested.relativeTo(base)) assertEquals("bar", nested.toRelativeString(base))
assertEquals("..", base.relativeTo(nested)) assertEquals("..", base.toRelativeString(nested))
val empty = File("") val empty = File("")
val current = File(".") val current = File(".")
val parent = File("..") val parent = File("..")
val outOfRoot = File("../bar") val outOfRoot = File("../bar")
assertEquals(File("../bar"), File(outOfRoot.relativeTo(empty))) assertEquals(File("../bar"), outOfRoot.relativeTo(empty))
assertEquals(File("../../bar"), File(outOfRoot.relativeTo(base))) assertEquals(File("../../bar"), outOfRoot.relativeTo(base))
assertEquals("bar", outOfRoot.relativeTo(parent)) assertEquals("bar", outOfRoot.toRelativeString(parent))
assertEquals("..", parent.relativeTo(outOfRoot)) assertEquals("..", parent.toRelativeString(outOfRoot))
val root = File("/root") val root = File("/root")
val files = listOf(nested, base, empty, outOfRoot, current, parent) val files = listOf(nested, base, empty, outOfRoot, current, parent)
val bases = listOf(nested, base, empty, current) val bases = listOf(nested, base, empty, current)
for (file in files) for (file in files)
assertEquals("", file.relativeTo(file), "file should have empty path relative to itself: $file") assertEquals("", file.toRelativeString(file), "file should have empty path relative to itself: $file")
for (file in files) { for (file in files) {
for (base in bases) { for (base in bases) {
val rootedFile = root.resolve(file) val rootedFile = root.resolve(file)
val rootedBase = root.resolve(base) val rootedBase = root.resolve(base)
assertEquals(file.relativeTo(base), rootedFile.relativeTo(rootedBase), "nested: $file, base: $base") assertEquals(file.relativeTo(base), rootedFile.relativeTo(rootedBase), "nested: $file, base: $base")
assertEquals(file.toRelativeString(base), rootedFile.toRelativeString(rootedBase), "strings, nested: $file, base: $base")
} }
} }
} }
@@ -175,10 +176,10 @@ class FilesTest {
} }
@test fun relativeTo() { @test fun relativeTo() {
assertEquals("kotlin", File("src/kotlin").relativeTo(File("src"))) assertEquals("kotlin", File("src/kotlin").toRelativeString(File("src")))
assertEquals("", File("dir").relativeTo(File("dir"))) assertEquals("", File("dir").toRelativeString(File("dir")))
assertEquals("..", File("dir").relativeTo(File("dir/subdir"))) assertEquals("..", File("dir").toRelativeString(File("dir/subdir")))
assertEquals(File("../../test"), File("test").relativeToFile(File("dir/dir"))) assertEquals(File("../../test"), File("test").relativeTo(File("dir/dir")))
} }
private fun checkFilePathComponents(f: File, root: File, elements: List<String>) { private fun checkFilePathComponents(f: File, root: File, elements: List<String>) {
@@ -348,26 +349,6 @@ class FilesTest {
assertEquals("log", File("/my.dir/log").nameWithoutExtension) assertEquals("log", File("/my.dir/log").nameWithoutExtension)
} }
@test fun separatorsToSystem() {
var path = "/aaa/bbb/ccc"
assertEquals(path.replace("/", File.separator), File(path).separatorsToSystem())
path = "C:\\Program Files\\My Awesome Program"
assertEquals(path.replace("\\", File.separator), File(path).separatorsToSystem())
path = "/Libraries\\Java:/Libraries/Python:/Libraries/Ruby"
assertEquals(path.replace(":", File.pathSeparator), path.pathSeparatorsToSystem())
path = "/Libraries\\Java;/Libraries/Python;/Libraries/Ruby"
assertEquals(path.replace(";", File.pathSeparator), path.pathSeparatorsToSystem())
path = "/Libraries\\Java;/Libraries/Python:\\Libraries/Ruby"
assertEquals(path.replace("/", File.separator).replace("\\", File.separator)
.replace(":", File.pathSeparator).replace(";", File.pathSeparator), path.allSeparatorsToSystem())
assertEquals("test", "test".allSeparatorsToSystem())
}
@test fun testCopyTo() { @test fun testCopyTo() {
val srcFile = createTempFile() val srcFile = createTempFile()
val dstFile = createTempFile() val dstFile = createTempFile()
@@ -472,7 +453,7 @@ class FilesTest {
dst.delete() dst.delete()
fun check() { fun check() {
for (file in src.walkTopDown()) { for (file in src.walkTopDown()) {
val dstFile = File(dst, file.relativeTo(src)) val dstFile = dst.resolve(file.relativeTo(src))
assertTrue(dstFile.exists()) assertTrue(dstFile.exists())
if (dstFile.isFile) { if (dstFile.isFile) {
assertEquals(file.readText(), dstFile.readText()) assertEquals(file.readText(), dstFile.readText())
@@ -268,7 +268,7 @@ public open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArgumen
get() = kotlinOptions.outputFile get() = kotlinOptions.outputFile
public val sourceMapDestinationDir: File public val sourceMapDestinationDir: File
get() = File(outputFile).directory get() = File(outputFile).let { if (it.isDirectory) it else it.parentFile!! }
public val sourceMap: Boolean public val sourceMap: Boolean
get() = kotlinOptions.sourceMap get() = kotlinOptions.sourceMap
@@ -298,7 +298,7 @@ public open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArgumen
throw GradleException("$name.kotlinOptions.outputFile should be specified.") throw GradleException("$name.kotlinOptions.outputFile should be specified.")
} }
val outputDir = File(args.outputFile).directory val outputDir = File(args.outputFile).let { if (it.isDirectory) it else it.parentFile!! }
if (!outputDir.exists()) { if (!outputDir.exists()) {
if (!outputDir.mkdirs()) { if (!outputDir.mkdirs()) {
throw GradleException("Failed to create output directory ${outputDir} or one of its ancestors") throw GradleException("Failed to create output directory ${outputDir} or one of its ancestors")
@@ -199,7 +199,7 @@ class Kotlin2JsSourceSetProcessor(
val defaultKotlinDestinationDir = File(project.buildDir, "kotlin2js/${sourceSetName}") val defaultKotlinDestinationDir = File(project.buildDir, "kotlin2js/${sourceSetName}")
private fun kotlinTaskDestinationDir(): File? = kotlinTask.property("kotlinDestinationDir") as File? private fun kotlinTaskDestinationDir(): File? = kotlinTask.property("kotlinDestinationDir") as File?
private fun kotlinJsDestinationDir(): File? = (kotlinTask.property("outputFile") as String).let { File(it).directory } private fun kotlinJsDestinationDir(): File? = (kotlinTask.property("outputFile") as String).let { File(it) }.let { if (it.isDirectory) it else it.parentFile }
private fun kotlinSourcePathsForSourceMap() = sourceSet.getAllSource() private fun kotlinSourcePathsForSourceMap() = sourceSet.getAllSource()
.map { it.path } .map { it.path }