[jps] Fix compilation JDK Path Kotlin extensions
This commit is contained in:
@@ -25,9 +25,8 @@ 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
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
|
||||
object CompilerRunnerUtil {
|
||||
private var ourClassLoaderRef = SoftReference<ClassLoader>(null)
|
||||
@@ -38,16 +37,16 @@ object CompilerRunnerUtil {
|
||||
if (javaHomePath == null || javaHomePath.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
val javaHome = Path(javaHomePath)
|
||||
val javaHome = Paths.get(javaHomePath)
|
||||
var toolsJar = javaHome.resolve("lib/tools.jar")
|
||||
if (toolsJar.exists()) {
|
||||
if (Files.exists(toolsJar)) {
|
||||
return toolsJar.toFile()
|
||||
}
|
||||
|
||||
// We might be inside jre.
|
||||
if (javaHome.name == "jre") {
|
||||
if (javaHome.fileName?.toString() == "jre") {
|
||||
toolsJar = javaHome.resolveSibling("lib/tools.jar")
|
||||
if (toolsJar.exists()) {
|
||||
if (Files.exists(toolsJar)) {
|
||||
return toolsJar.toFile()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,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.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.writeText
|
||||
|
||||
/**
|
||||
* Chunk of cyclically dependent [KotlinModuleBuildTarget]s
|
||||
@@ -171,8 +171,8 @@ class KotlinChunk internal constructor(val context: KotlinCompileContext, val ta
|
||||
|
||||
val serializedMetaInfo = representativeTarget.buildMetaInfoFactory.serializeToString(compilerArguments)
|
||||
|
||||
targets.forEach {
|
||||
buildMetaInfoFile(it.jpsModuleBuildTarget).writeText(serializedMetaInfo)
|
||||
targets.forEach { target ->
|
||||
Files.newOutputStream(buildMetaInfoFile(target.jpsModuleBuildTarget)).bufferedWriter().use { it.append(serializedMetaInfo) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +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.Files
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.*
|
||||
|
||||
/**
|
||||
* Manages files with actual version [loadActual] and provides expected version [expected].
|
||||
@@ -28,9 +28,9 @@ class CacheVersionManager(
|
||||
else CacheVersion(expectedOwnVersion, JvmBytecodeBinaryVersion.INSTANCE, JvmMetadataVersion.INSTANCE)
|
||||
|
||||
override fun loadActual(): CacheVersion? =
|
||||
if (versionFile.notExists()) null
|
||||
if (Files.notExists(versionFile)) null
|
||||
else try {
|
||||
CacheVersion(versionFile.readText().toInt())
|
||||
CacheVersion(Files.newInputStream(versionFile).bufferedReader().use { it.readText() }.toInt())
|
||||
} catch (e: NumberFormatException) {
|
||||
null
|
||||
} catch (e: IOException) {
|
||||
@@ -38,10 +38,10 @@ class CacheVersionManager(
|
||||
}
|
||||
|
||||
override fun writeVersion(values: CacheVersion?) {
|
||||
if (values == null) versionFile.deleteIfExists()
|
||||
if (values == null) Files.deleteIfExists(versionFile)
|
||||
else {
|
||||
versionFile.parent.createDirectories()
|
||||
versionFile.writeText(values.intValue.toString())
|
||||
Files.createDirectories(versionFile.parent)
|
||||
Files.newOutputStream(versionFile).bufferedWriter().use { it.append(values.intValue.toString()) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -7,8 +7,8 @@ package org.jetbrains.kotlin.jps.incremental
|
||||
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import java.io.IOException
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.*
|
||||
|
||||
/**
|
||||
* Attributes manager for global lookups cache that may contain lookups for several compilers (jvm, js).
|
||||
@@ -34,10 +34,10 @@ class CompositeLookupsCacheAttributesManager(
|
||||
override fun loadActual(): CompositeLookupsCacheAttributes? {
|
||||
val version = versionManager.loadActual() ?: return null
|
||||
|
||||
if (actualComponentsFile.notExists()) return null
|
||||
if (Files.notExists(actualComponentsFile)) return null
|
||||
|
||||
val components = try {
|
||||
actualComponentsFile.readLines().toSet()
|
||||
Files.readAllLines(actualComponentsFile).toSet()
|
||||
} catch (e: IOException) {
|
||||
return null
|
||||
}
|
||||
@@ -48,12 +48,12 @@ class CompositeLookupsCacheAttributesManager(
|
||||
override fun writeVersion(values: CompositeLookupsCacheAttributes?) {
|
||||
if (values == null) {
|
||||
versionManager.writeVersion(null)
|
||||
actualComponentsFile.deleteIfExists()
|
||||
Files.deleteIfExists(actualComponentsFile)
|
||||
} else {
|
||||
versionManager.writeVersion(CacheVersion(values.version))
|
||||
|
||||
actualComponentsFile.parent.createDirectories()
|
||||
actualComponentsFile.writeText(values.components.joinToString("\n"))
|
||||
Files.createDirectories(actualComponentsFile.parent)
|
||||
Files.newOutputStream(actualComponentsFile).bufferedWriter().use { it.append(values.components.joinToString("\n")) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,9 +39,7 @@ 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
|
||||
import java.nio.file.Files
|
||||
|
||||
private const val JS_BUILD_META_INFO_FILE_NAME = "js-build-meta-info.txt"
|
||||
|
||||
@@ -204,8 +202,8 @@ class KotlinJsModuleBuildTarget(kotlinContext: KotlinCompileContext, jpsModuleBu
|
||||
dependencyBuildTarget.sources.isNotEmpty()
|
||||
) {
|
||||
val metaFile = dependencyBuildTarget.outputMetaFile.toPath()
|
||||
if (metaFile.exists()) {
|
||||
result.add(metaFile.absolute().pathString)
|
||||
if (Files.exists(metaFile)) {
|
||||
result.add(metaFile.toAbsolutePath().toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,9 +47,6 @@ 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"
|
||||
|
||||
@@ -272,8 +269,9 @@ class KotlinJvmModuleBuildTarget(kotlinContext: KotlinCompileContext, jpsModuleB
|
||||
|
||||
private fun findClassPathRoots(): Collection<File> = allDependencies.classes().roots.filter { file ->
|
||||
val path = file.toPath()
|
||||
if (path.notExists()) {
|
||||
val extension = path.extension
|
||||
|
||||
if (Files.notExists(path)) {
|
||||
val extension = path.fileName?.toString()?.substringAfterLast('.', "") ?: ""
|
||||
|
||||
// Don't filter out files, we want to report warnings about absence through the common place
|
||||
if (extension != "class" && extension != "jar") {
|
||||
@@ -302,7 +300,7 @@ class KotlinJvmModuleBuildTarget(kotlinContext: KotlinCompileContext, jpsModuleB
|
||||
for (root in roots) {
|
||||
val file = root.rootFile
|
||||
val prefix = root.packagePrefix
|
||||
if (file.toPath().exists()) {
|
||||
if (Files.exists(file.toPath())) {
|
||||
result.add(JvmSourceRoot(file, prefix.ifEmpty { null }))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,8 +41,7 @@ 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
|
||||
import java.nio.file.Files
|
||||
|
||||
/**
|
||||
* Properties and actions for Kotlin test / production module build target.
|
||||
@@ -333,11 +332,11 @@ abstract class KotlinModuleBuildTarget<BuildMetaInfoType : BuildMetaInfo> intern
|
||||
|
||||
fun isVersionChanged(chunk: KotlinChunk, buildMetaInfo: BuildMetaInfo): Boolean {
|
||||
val file = chunk.buildMetaInfoFile(jpsModuleBuildTarget)
|
||||
if (file.notExists()) return false
|
||||
if (Files.notExists(file)) return false
|
||||
|
||||
val prevBuildMetaInfo =
|
||||
try {
|
||||
buildMetaInfoFactory.deserializeFromString(file.readText()) ?: return false
|
||||
buildMetaInfoFactory.deserializeFromString(Files.newInputStream(file).bufferedReader().use { it.readText() }) ?: return false
|
||||
} catch (e: Exception) {
|
||||
KotlinBuilder.LOG.error("Could not deserialize build meta info", e)
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user