@@ -23,12 +23,14 @@ import org.intellij.lang.annotations.Language
2323import org.jetbrains.kotlin.com.intellij.lang.ASTNode
2424
2525import java.io.File
26+ import java.nio.file.NoSuchFileException
2627import java.nio.file.Path
2728import java.util.concurrent.atomic.AtomicInteger
2829import java.util.function.Consumer
2930import kotlin.io.path.absolute
3031import kotlin.io.path.deleteIfExists
3132import kotlin.io.path.isDirectory
33+ import kotlin.io.path.isSameFileAs
3234
3335internal const val TEST_FILE_NAME = " TestFileName.kt"
3436
@@ -216,6 +218,33 @@ internal fun Path.deleteIfExistsSilently() {
216218 }
217219}
218220
221+ /* *
222+ * @receiver the 1st operand.
223+ * @param other the 2nd operand.
224+ * @return `true` if, and only if, the two paths locate the same `JAVA_HOME`.
225+ */
226+ internal fun Path.isSameJavaHomeAs (other : Path ): Boolean =
227+ isDirectory() &&
228+ (isSameFileAsSafe(other) ||
229+ resolve(" jre" ).isSameFileAsSafe(other) ||
230+ other.resolve(" jre" ).isSameFileAsSafe(this ))
231+
232+ /* *
233+ * The same as [Path.isSameFileAs], but doesn't throw any [NoSuchFileException]
234+ * if either of the operands doesn't exist.
235+ *
236+ * @receiver the 1st operand.
237+ * @param other the 2nd operand.
238+ * @return `true` if, and only if, the two paths locate the same file.
239+ * @see Path.isSameFileAs
240+ */
241+ internal fun Path.isSameFileAsSafe (other : Path ): Boolean =
242+ try {
243+ isSameFileAs(other)
244+ } catch (_: NoSuchFileException ) {
245+ false
246+ }
247+
219248/* *
220249 * Prepends the `PATH` of this process builder with [pathEntry].
221250 *
0 commit comments