diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java index 55c6d919805..9fc5de0b3ab 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java @@ -426,6 +426,13 @@ public class KotlinTestUtils { return normalizeFile(FileUtil.createTempDirectory(name, "", false)); } + @NotNull + public static File tmpDirForReusableLibrary(String name) throws IOException { + File answer = normalizeFile(FileUtil.createTempDirectory(new File(System.getProperty("java.io.tmpdir")), name, "")); + deleteOnShutdown(answer); + return answer; + } + private static File normalizeFile(File file) throws IOException { // Get canonical file to be sure that it's the same as inside the compiler, // for example, on Windows, if a canonical path contains any space from FileUtil.createTempDirectory we will get @@ -433,6 +440,18 @@ public class KotlinTestUtils { return file.getCanonicalFile(); } + private static void deleteOnShutdown(File file) { + if (filesToDelete.isEmpty()) { + ShutDownTracker.getInstance().registerShutdownTask(() -> { + for (File victim : filesToDelete) { + FileUtil.delete(victim); + } + }); + } + + filesToDelete.add(file); + } + @NotNull public static KtFile createFile(@NotNull @NonNls String name, @NotNull String text, @NotNull Project project) { String shortName = name.substring(name.lastIndexOf('/') + 1); diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as32 b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as32 index 65f18ee3714..6abfe316996 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as32 +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as32 @@ -410,9 +410,7 @@ public class KotlinTestUtils { @NotNull public static File tmpDirForTest(@NotNull String testClassName, @NotNull String testName) throws IOException { - File answer = normalizeFile(FileUtil.createTempDirectory(testClassName, testName)); - deleteOnShutdown(answer); - return answer; + return normalizeFile(FileUtil.createTempDirectory(testClassName, testName, false)); } @NotNull @@ -422,7 +420,11 @@ public class KotlinTestUtils { @NotNull public static File tmpDir(String name) throws IOException { - // We should use this form. otherwise directory will be deleted on each test. + return normalizeFile(FileUtil.createTempDirectory(name, "", false)); + } + + @NotNull + public static File tmpDirForReusableLibrary(String name) throws IOException { File answer = normalizeFile(FileUtil.createTempDirectory(new File(System.getProperty("java.io.tmpdir")), name, "")); deleteOnShutdown(answer); return answer; diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/MockLibraryUtil.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/test/MockLibraryUtil.kt index eb7f18f5678..2d64751e741 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/MockLibraryUtil.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/MockLibraryUtil.kt @@ -52,8 +52,8 @@ object MockLibraryUtil { useJava9: Boolean = false ): File { return compileLibraryToJar( - sourcesPath, KotlinTestUtils.tmpDir("testLibrary-" + jarName), jarName, addSources,allowKotlinSources, extraOptions, extraClasspath - , useJava9)} + sourcesPath, KotlinTestUtils.tmpDirForReusableLibrary("testLibrary-" + jarName), jarName, addSources, allowKotlinSources, extraOptions, extraClasspath + , useJava9)} @JvmStatic @JvmOverloads @@ -127,7 +127,7 @@ object MockLibraryUtil { @JvmStatic fun compileJsLibraryToJar(sourcesPath: String, jarName: String, addSources: Boolean, extraOptions: List = emptyList()): File { - val contentDir = KotlinTestUtils.tmpDir("testLibrary-" + jarName) + val contentDir = KotlinTestUtils.tmpDirForReusableLibrary("testLibrary-" + jarName) val outDir = File(contentDir, "out") val outputFile = File(outDir, jarName + ".js") diff --git a/idea/tests/org/jetbrains/kotlin/idea/script/AbstractScriptConfigurationTest.kt b/idea/tests/org/jetbrains/kotlin/idea/script/AbstractScriptConfigurationTest.kt index 608b3d7275f..52e0456575a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/script/AbstractScriptConfigurationTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/script/AbstractScriptConfigurationTest.kt @@ -181,7 +181,7 @@ abstract class AbstractScriptConfigurationTest : KotlinCompletionTestCase() { } if (configureConflictingModule in environment) { - val sharedLib = LocalFileSystem.getInstance().findFileByIoFile(environment["lib-classes"] as File)!! + val sharedLib = VfsUtil.findFileByIoFile(environment["lib-classes"] as File, true)!! if (module == null) { myModule = createTestModuleByName("mainModule") }