Changes in Gradle integration tests are needed because:
- in new-mpp-android, kotlin-stdlib-jdk8 is used, and JVM IR generates
JDK 8-specific bytecode (invokedynamic). D8 needs to be configured to
desugar it with source/target versions set to 1.8, otherwise it
reports an error.
- in AndroidExtensionsManyVariants and AndroidIcepickProject, D8 fails
with assertions enabled if AGP < 4.0.0 is used because of
https://issuetracker.google.com/issues/148661132. The tests which use
old AGP versions are probably not relevant anymore anyway.
Changes in kotlin-stdlib-runtime-merged.txt are caused by a slightly
different generation scheme of collection subclasses in JVM IR, and are
harmless.
(Previous attempt was at 15e978dbd311c2ba78ec32b394c21acde9811ccb.)
There seems to be no point in configuring the compiler argument per
project. This argument will be deleted soon anyway, when we remove
support for JDK 1.6 & 1.7.
Also remove `disableDeprecatedJvmTargetWarning`. It didn't have any
effect in all modules where it was applied because these modules
reassign `freeCompilerArgs` anyway, with
`-Xsuppress-deprecated-jvm-target-warning` in it.
These compiler arguments enable features which are enabled by default in
the current Kotlin anyway.
The only exception is in :compiler:cli which uses an old language
version.
Some multiplatform tests are compiled in single-platform projects:
- in kotlin-stdlib-jdk7
- in kotlin-stdlib-jdk8
- in kotlin-stdlib-js-ir. The latter is technically MPP but with a
single platform, so its common sources are not considered as common.
Pass information about common sources to test compilation tasks in order
to use OptionalExpectation annotations there.
Co-authored-by: Svyatoslav Scherbina <svyatoslav.scherbina@jetbrains.com>
- Adjust implementations to avoid excessive vararg copies
- Remove options from forEachLine, it doesn't make much sense and
isn't consistent with the other read* functions.
- Revise inlineness of functions in PathReadWrite
- Compact implementations of those that are remained inline.
- Clarify docs of functions for reading the entire file
#KT-19192
Delegate most checks to the platform Files.copy.
This changes the exception type thrown in one case,
so document when it happens. Also 'copyTo' no longer
creates target parent directory if it doesn't exist.
#KT-19192
This PR adds most extensions on `java.io.File` in `kotlin.io` to `java.nio.Path`. This includes extensions from `FileReadWrite.kt`, `Utils.kt`, and `FileTreeWalk.kt`.
I attempted to keep the implementations, documentation, and tests as similar as possible to the existing implementations.
I am happy to add, remove, or move to separate PRs any of the functions of this PR.
### `File` extensions that were not added to `Path`
##### `createTempDir`, `createTempFile`
These functions have no `File` parameters, so can't be overloaded. Equivalents exist as `Files.createTempFile()` and `Files.createTempDirectory()`.
##### `startsWith`, `endsWith`, `normalize`, `resolve`, `resolveSibling`
These exist as member functions on `Path`
##### `relativeTo`, `relativeToOrNull`, `relativeToOrSelf`, `toRelativeString`, `toRelativeStringOrNull`
This functionality exists as the `Path.relativize` member function, which is equivalent to `relativeTo`, but with the receiver and parameter flipped. `foo.relativeTo(bar)` is equivalent to `bar.relativize(foo)`. We could potentially add a `relativizeOrNull` extension to make that pattern simpler.
##### `isRooted`
`Path` has a `root` method, so `isRooted` is equivalent to `root != null`
### New extensions
All of the simple boolean attribute checks from `java.nio.Files` were added as extensions on `Path`. These extensions are used commonly enough that it seems worth supporting them. This functionality for `File` is implemented as member methods.
The following `Path` extensions were added:
- `exists`
- `isDirectory`
- `isExecutable`
- `isFile`
- `isHidden`
- `isReadable`
- `isSameFile`
- `isSymbolicLink`
- `isWritable`
Some of these extensions take options that are forwarded to their `Files` method, so all of the extensions were implemented as functions rather than properties for consistency.
Additionally, `Path.listFiles` was added to match the `File.listFiles` method. One motivation for its addition was that it's used several times in the implementation of other file extensions. The way to list directory contents with `java.nio` is via `Files.newDirectoryStream()`, which returns an iterable object that must be closed to avoid leaking resources. It's difficult to use correctly with functions like `map` and `filter`, so this extension was added as a simpler, less error-prone alternative.
### Other changes
I added overloads of several of the read-write that take `OpenOptions` to expose the greater control that `java.nio` introduces. For example, you can use `printWriter(APPEND)` to create a `PrintWriter` that doesn't delete the contents of an existing file.
All the new extensions throw exceptions (such as `NoSuchFileException`) from `java.nio` rather than the copies from `kotlin.io`. The `kotlin.io` copies take `File` objects as parameters, and so aren't compatible with `Path`s.
### Address review comments
- Move varargs parameters to the last position
- Remove PathTreeWalk
#KT-19192
The next step for JVM IR adoption in our project is going to be enabling
`kotlin.build.useIR`, but keeping `kotlin.build.useIRForLibraries`
disabled until we fix all remaining ABI incompatibility issues for
library code.
- include kotlin.time package
Suppress module-info warnings:
- terminal digits in module name
- open/export for another not yet built dependee module
#KT-21266
There is one failing test namely `ValByMapExtensionsTest.doTest`, which
is quite questionable because its checks the use of out projection and
Exact annotation (see KT-18789)