diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalLazyCachesTest.kt b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalLazyCachesTest.kt index a59f33190b3..ce787d228d5 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalLazyCachesTest.kt +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalLazyCachesTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2021 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -111,7 +111,7 @@ abstract class AbstractIncrementalLazyCachesTest : AbstractIncrementalJpsTest() dumpCachesForTarget( printer, paths, target.jpsModuleBuildTarget, target.localCacheVersionManager.versionFileForTesting, - metaBuildInfo, + metaBuildInfo.toFile(), subdirectory = KOTLIN_CACHE_DIRECTORY_NAME ) } diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/incremental/CompositeLookupsCacheAttributesManagerTest.kt b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/incremental/CompositeLookupsCacheAttributesManagerTest.kt index bc162aba34d..02bd634cab8 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/incremental/CompositeLookupsCacheAttributesManagerTest.kt +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/incremental/CompositeLookupsCacheAttributesManagerTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -8,11 +8,11 @@ package org.jetbrains.kotlin.jps.incremental import org.jetbrains.kotlin.jps.incremental.CacheStatus import org.jetbrains.kotlin.jps.incremental.loadDiff import org.junit.Test -import java.io.File +import kotlin.io.path.Path import kotlin.test.assertEquals class CompositeLookupsCacheAttributesManagerTest { - val manager = CompositeLookupsCacheAttributesManager(File("not-used"), setOf()) + val manager = CompositeLookupsCacheAttributesManager(Path("not-used"), setOf()) @Test fun testNothingToJava() { diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/CompilerRunnerUtil.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/CompilerRunnerUtil.kt index 282fded48c8..669f1a5a4c3 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/CompilerRunnerUtil.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/CompilerRunnerUtil.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2021 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,9 @@ import org.jetbrains.kotlin.utils.KotlinPathsFromBaseDirectory import java.io.File import java.io.PrintStream import java.lang.ref.SoftReference +import kotlin.io.path.Path +import kotlin.io.path.exists +import kotlin.io.path.name object CompilerRunnerUtil { private var ourClassLoaderRef = SoftReference(null) @@ -35,17 +38,17 @@ object CompilerRunnerUtil { if (javaHomePath == null || javaHomePath.isEmpty()) { return null } - val javaHome = File(javaHomePath) - var toolsJar = File(javaHome, "lib/tools.jar") + val javaHome = Path(javaHomePath) + var toolsJar = javaHome.resolve("lib/tools.jar") if (toolsJar.exists()) { - return toolsJar.canonicalFile + return toolsJar.toFile() } // We might be inside jre. if (javaHome.name == "jre") { - toolsJar = File(javaHome.parent, "lib/tools.jar") + toolsJar = javaHome.parent.resolve("lib/tools.jar") if (toolsJar.exists()) { - return toolsJar.canonicalFile + return toolsJar.toFile() } } diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinChunk.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinChunk.kt index 24b5982e1f9..3f4079b0ab8 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinChunk.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinChunk.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -15,7 +15,8 @@ import org.jetbrains.kotlin.jps.incremental.getKotlinCache import org.jetbrains.kotlin.jps.model.kotlinCompilerArguments import org.jetbrains.kotlin.jps.targets.KotlinModuleBuildTarget import org.jetbrains.kotlin.utils.keysToMapExceptNulls -import java.io.File +import java.nio.file.Path +import kotlin.io.path.writeText /** * Chunk of cyclically dependent [KotlinModuleBuildTarget]s @@ -82,11 +83,10 @@ class KotlinChunk internal constructor(val context: KotlinCompileContext, val ta return false } - fun buildMetaInfoFile(target: ModuleBuildTarget): File = - File( - context.dataPaths.getTargetDataRoot(target), - representativeTarget.buildMetaInfoFileName - ) + fun buildMetaInfoFile(target: ModuleBuildTarget): Path = context.dataPaths + .getTargetDataRoot(target) + .toPath() + .resolve(representativeTarget.buildMetaInfoFileName) fun saveVersions() { context.ensureLookupsCacheAttributesSaved() diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinCompileContext.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinCompileContext.kt index 2d039bb8a33..51c501944ba 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinCompileContext.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinCompileContext.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -12,8 +12,7 @@ import org.jetbrains.jps.incremental.GlobalContextKey import org.jetbrains.jps.incremental.fs.CompilationRound import org.jetbrains.jps.incremental.messages.BuildMessage import org.jetbrains.jps.incremental.messages.CompilerMessage -import org.jetbrains.kotlin.config.CompilerRunnerConstants -import org.jetbrains.kotlin.config.CompilerRunnerConstants.* +import org.jetbrains.kotlin.config.CompilerRunnerConstants.KOTLIN_COMPILER_NAME import org.jetbrains.kotlin.incremental.LookupSymbol import org.jetbrains.kotlin.incremental.storage.FileToPathConverter import org.jetbrains.kotlin.jps.incremental.* @@ -109,7 +108,7 @@ class KotlinCompileContext(val jpsContext: CompileContext) { } val lookupsCacheRootPath = dataPaths.getTargetDataRoot(KotlinDataContainerTarget) - return CompositeLookupsCacheAttributesManager(lookupsCacheRootPath, expectedLookupsCacheComponents) + return CompositeLookupsCacheAttributesManager(lookupsCacheRootPath.toPath(), expectedLookupsCacheComponents) } private fun loadLookupsCacheStateDiff(): CacheAttributesDiff { diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/CacheVersionManager.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/CacheVersionManager.kt index d86215f6b2d..106a83bbda9 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/CacheVersionManager.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/CacheVersionManager.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -10,6 +10,8 @@ import org.jetbrains.kotlin.load.kotlin.JvmBytecodeBinaryVersion import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion import java.io.File import java.io.IOException +import java.nio.file.Path +import kotlin.io.path.* /** * Manages files with actual version [loadActual] and provides expected version [expected]. @@ -18,7 +20,7 @@ import java.io.IOException * Based on that status system may perform required actions (i.e. rebuild something, clearing caches, etc...). */ class CacheVersionManager( - private val versionFile: File, + private val versionFile: Path, expectedOwnVersion: Int? ) : CacheAttributesManager { override val expected: CacheVersion? = @@ -26,7 +28,7 @@ class CacheVersionManager( else CacheVersion(expectedOwnVersion, JvmBytecodeBinaryVersion.INSTANCE, JvmMetadataVersion.INSTANCE) override fun loadActual(): CacheVersion? = - if (!versionFile.exists()) null + if (versionFile.notExists()) null else try { CacheVersion(versionFile.readText().toInt()) } catch (e: NumberFormatException) { @@ -36,16 +38,16 @@ class CacheVersionManager( } override fun writeVersion(values: CacheVersion?) { - if (values == null) versionFile.delete() + if (values == null) versionFile.deleteIfExists() else { - versionFile.parentFile.mkdirs() + versionFile.parent.createDirectories() versionFile.writeText(values.intValue.toString()) } } @get:TestOnly val versionFileForTesting: File - get() = versionFile + get() = versionFile.toFile() } fun CacheVersion(own: Int, bytecode: JvmBytecodeBinaryVersion, metadata: JvmMetadataVersion): CacheVersion { diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/CompositeLookupsCacheAttributes.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/CompositeLookupsCacheAttributes.kt index 04115c7bc39..065dfd7dce7 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/CompositeLookupsCacheAttributes.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/CompositeLookupsCacheAttributes.kt @@ -1,13 +1,14 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.jps.incremental import org.jetbrains.annotations.TestOnly -import java.io.File import java.io.IOException +import java.nio.file.Path +import kotlin.io.path.* /** * Attributes manager for global lookups cache that may contain lookups for several compilers (jvm, js). @@ -16,7 +17,7 @@ import java.io.IOException * TODO(1.2.80): got rid of shared lookup cache, replace with individual lookup cache for each compiler */ class CompositeLookupsCacheAttributesManager( - rootPath: File, + rootPath: Path, expectedComponents: Set ) : CacheAttributesManager { private val versionManager = lookupsCacheVersionManager( @@ -24,7 +25,7 @@ class CompositeLookupsCacheAttributesManager( expectedComponents.isNotEmpty() ) - private val actualComponentsFile = File(rootPath, "components.txt") + private val actualComponentsFile = rootPath.resolve("components.txt") override val expected: CompositeLookupsCacheAttributes? = if (expectedComponents.isEmpty()) null @@ -33,7 +34,7 @@ class CompositeLookupsCacheAttributesManager( override fun loadActual(): CompositeLookupsCacheAttributes? { val version = versionManager.loadActual() ?: return null - if (!actualComponentsFile.exists()) return null + if (actualComponentsFile.notExists()) return null val components = try { actualComponentsFile.readLines().toSet() @@ -47,11 +48,11 @@ class CompositeLookupsCacheAttributesManager( override fun writeVersion(values: CompositeLookupsCacheAttributes?) { if (values == null) { versionManager.writeVersion(null) - actualComponentsFile.delete() + actualComponentsFile.deleteIfExists() } else { versionManager.writeVersion(CacheVersion(values.version)) - actualComponentsFile.parentFile.mkdirs() + actualComponentsFile.parent.createDirectories() actualComponentsFile.writeText(values.components.joinToString("\n")) } } diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/local.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/local.kt index 6f51a4e29b3..fcf1bd3b012 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/local.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/local.kt @@ -1,17 +1,16 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.jps.incremental -import java.io.File +import java.nio.file.Path -private val NORMAL_VERSION = 14 -private val NORMAL_VERSION_FILE_NAME = "format-version.txt" +private const val NORMAL_VERSION = 14 +private const val NORMAL_VERSION_FILE_NAME = "format-version.txt" -fun localCacheVersionManager(dataRoot: File, isCachesEnabled: Boolean) = - CacheVersionManager( - File(dataRoot, NORMAL_VERSION_FILE_NAME), - if (isCachesEnabled) NORMAL_VERSION else null - ) \ No newline at end of file +fun localCacheVersionManager(dataRoot: Path, isCachesEnabled: Boolean) = CacheVersionManager( + dataRoot.resolve(NORMAL_VERSION_FILE_NAME), + if (isCachesEnabled) NORMAL_VERSION else null +) \ No newline at end of file diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/lookups.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/lookups.kt index b670b9d8cd5..3d688e51c4a 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/lookups.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/lookups.kt @@ -1,17 +1,16 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.jps.incremental -import java.io.File +import java.nio.file.Path -private val DATA_CONTAINER_VERSION_FILE_NAME = "data-container-format-version.txt" -private val DATA_CONTAINER_VERSION = 5 +private const val DATA_CONTAINER_VERSION_FILE_NAME = "data-container-format-version.txt" +private const val DATA_CONTAINER_VERSION = 5 -fun lookupsCacheVersionManager(dataRoot: File, isEnabled: Boolean) = - CacheVersionManager( - File(dataRoot, DATA_CONTAINER_VERSION_FILE_NAME), - if (isEnabled) DATA_CONTAINER_VERSION else null - ) \ No newline at end of file +fun lookupsCacheVersionManager(dataRoot: Path, isEnabled: Boolean) = CacheVersionManager( + dataRoot.resolve(DATA_CONTAINER_VERSION_FILE_NAME), + if (isEnabled) DATA_CONTAINER_VERSION else null +) \ No newline at end of file diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinJsModuleBuildTarget.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinJsModuleBuildTarget.kt index 6c94a735e4b..8b2e5eb4dc3 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinJsModuleBuildTarget.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinJsModuleBuildTarget.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -39,6 +39,9 @@ import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils.JS_EXT import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils.META_JS_SUFFIX import java.io.File import java.net.URI +import kotlin.io.path.absolute +import kotlin.io.path.exists +import kotlin.io.path.pathString private const val JS_BUILD_META_INFO_FILE_NAME = "js-build-meta-info.txt" @@ -200,9 +203,9 @@ class KotlinJsModuleBuildTarget(kotlinContext: KotlinCompileContext, jpsModuleBu dependencyBuildTarget is KotlinJsModuleBuildTarget && dependencyBuildTarget.sources.isNotEmpty() ) { - val metaFile = dependencyBuildTarget.outputMetaFile + val metaFile = dependencyBuildTarget.outputMetaFile.toPath() if (metaFile.exists()) { - result.add(metaFile.absolutePath) + result.add(metaFile.absolute().pathString) } } } diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinJvmModuleBuildTarget.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinJvmModuleBuildTarget.kt index e1284cd30b9..aaef345e343 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinJvmModuleBuildTarget.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinJvmModuleBuildTarget.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.jps.targets @@ -47,6 +47,9 @@ import java.io.IOException import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths +import kotlin.io.path.exists +import kotlin.io.path.extension +import kotlin.io.path.notExists private const val JVM_BUILD_META_INFO_FILE_NAME = "jvm-build-meta-info.txt" @@ -267,19 +270,18 @@ class KotlinJvmModuleBuildTarget(kotlinContext: KotlinCompileContext, jpsModuleB }.toFile() } - private fun findClassPathRoots(): Collection { - return allDependencies.classes().roots.filter { file -> - if (!file.exists()) { - val extension = file.extension + private fun findClassPathRoots(): Collection = allDependencies.classes().roots.filter { file -> + val path = file.toPath() + if (path.notExists()) { + val extension = path.extension - // Don't filter out files, we want to report warnings about absence through the common place - if (extension != "class" && extension != "jar") { - return@filter false - } + // Don't filter out files, we want to report warnings about absence through the common place + if (extension != "class" && extension != "jar") { + return@filter false } - - true } + + true } private fun findModularJdkRoot(): File? { @@ -296,12 +298,12 @@ class KotlinJvmModuleBuildTarget(kotlinContext: KotlinCompileContext, jpsModuleB private fun findSourceRoots(context: CompileContext): List { val roots = context.projectDescriptor.buildRootIndex.getTargetRoots(jpsModuleBuildTarget, context) - val result = ContainerUtil.newArrayList() + val result = mutableListOf() for (root in roots) { val file = root.rootFile val prefix = root.packagePrefix - if (file.exists()) { - result.add(JvmSourceRoot(file, if (prefix.isEmpty()) null else prefix)) + if (file.toPath().exists()) { + result.add(JvmSourceRoot(file, prefix.ifEmpty { null })) } } return result diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinModuleBuildTarget.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinModuleBuildTarget.kt index b12c39078c0..2dda2e615f4 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinModuleBuildTarget.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinModuleBuildTarget.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -40,6 +40,8 @@ import org.jetbrains.kotlin.progress.CompilationCanceledException import org.jetbrains.kotlin.progress.CompilationCanceledStatus import org.jetbrains.kotlin.utils.addIfNotNull import java.io.File +import kotlin.io.path.notExists +import kotlin.io.path.readText /** * Properties and actions for Kotlin test / production module build target. @@ -69,7 +71,7 @@ abstract class KotlinModuleBuildTarget intern @Suppress("LeakingThis") val localCacheVersionManager = localCacheVersionManager( - kotlinContext.dataPaths.getTargetDataRoot(jpsModuleBuildTarget), + kotlinContext.dataPaths.getTargetDataRoot(jpsModuleBuildTarget).toPath(), isIncrementalCompilationEnabled ) @@ -330,7 +332,7 @@ abstract class KotlinModuleBuildTarget intern fun isVersionChanged(chunk: KotlinChunk, buildMetaInfo: BuildMetaInfo): Boolean { val file = chunk.buildMetaInfoFile(jpsModuleBuildTarget) - if (!file.exists()) return false + if (file.notExists()) return false val prevBuildMetaInfo = try {