From 04fb864cc4bfc3951565a3990f13df15ee562a8e Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 22 Sep 2015 14:23:18 +0300 Subject: [PATCH] Reverted --- .../unusedLibrary/simple/expected.xml | 2 +- .../testFramework/PlatformTestCase.java | 19 +------- .../testFramework/UsefulTestCase.java | 3 +- .../com/intellij/testFramework/FixtureRule.kt | 2 +- .../intellij/openapi/util/io/FileUtilRt.java | 47 ++++++++++++------- 5 files changed, 33 insertions(+), 40 deletions(-) diff --git a/java/java-tests/testData/inspection/unusedLibrary/simple/expected.xml b/java/java-tests/testData/inspection/unusedLibrary/simple/expected.xml index 9cd23b0df42b..8184735d55cf 100644 --- a/java/java-tests/testData/inspection/unusedLibrary/simple/expected.xml +++ b/java/java-tests/testData/inspection/unusedLibrary/simple/expected.xml @@ -1,7 +1,7 @@ - testSimple.iml + testSimple_0.iml Unused library Unused library 'JUnit' diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java index 86738af62f47..9ddb3b4c53a7 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java @@ -54,7 +54,6 @@ import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.impl.local.LocalFileSystemImpl; -import com.intellij.openapi.vfs.newvfs.NewVirtualFile; import com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl; import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS; import com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl; @@ -192,7 +191,6 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro @Override protected void setUp() throws Exception { super.setUp(); - myFilesToDelete.add(new File(FileUtilRt.getTempDirectory())); if (ourTestCase != null) { String message = "Previous test " + ourTestCase + " hasn't called tearDown(). Probably overridden without super call."; ourTestCase = null; @@ -264,22 +262,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro @NotNull public static Project createProject(@NotNull String path, String creationPlace) { - return createProject(path, creationPlace, false); - } - - @NotNull - public static Project createProject(@NotNull String path, String creationPlace, boolean clearVfs) { String fileName = PathUtilRt.getFileName(path); - if (clearVfs) { - VirtualFile projectBase = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(fileName.endsWith( - ProjectFileType.DOT_DEFAULT_EXTENSION) ? PathUtilRt.getParentPath(path) : path)); - if (projectBase != null) { - // must be leftovers from the previous test run - for (VirtualFile file : ((NewVirtualFile)projectBase).iterInDbChildren()) { - delete(file); - } - } - } try { String projectName = FileUtilRt.getNameWithoutExtension(fileName); @@ -324,7 +307,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro } protected File getIprFile() throws IOException { - File tempFile = FileUtil.createTempFile(getName(), ProjectFileType.DOT_DEFAULT_EXTENSION); + File tempFile = FileUtil.createTempFile(getName() + "_", ProjectFileType.DOT_DEFAULT_EXTENSION); myFilesToDelete.add(tempFile); return tempFile; } diff --git a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java index 2496c7deb3d2..fcc8bee14fb6 100644 --- a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java @@ -139,8 +139,7 @@ public abstract class UsefulTestCase extends TestCase { String testName = FileUtil.sanitizeFileName(getTestName(true)); if (StringUtil.isEmptyOrSpaces(testName)) testName = ""; testName = new File(testName).getName(); // in case the test name contains file separators - File tempDirectory = FileUtil.createTempDirectory(new File(ORIGINAL_TEMP_DIR), TEMP_DIR_MARKER + testName, ""); - myTempDir = tempDirectory.getPath(); + myTempDir = FileUtil.toSystemDependentName(ORIGINAL_TEMP_DIR + "/" + TEMP_DIR_MARKER + testName + "_"+ RNG.nextInt(1000)); FileUtil.resetCanonicalTempPathCache(myTempDir); } ApplicationInfoImpl.setInPerformanceTest(isPerformanceTest()); diff --git a/platform/testFramework/testSrc/com/intellij/testFramework/FixtureRule.kt b/platform/testFramework/testSrc/com/intellij/testFramework/FixtureRule.kt index 87de6b1d6434..bb8ddc710b74 100644 --- a/platform/testFramework/testSrc/com/intellij/testFramework/FixtureRule.kt +++ b/platform/testFramework/testSrc/com/intellij/testFramework/FixtureRule.kt @@ -72,7 +72,7 @@ public class ProjectRule() : ExternalResource() { val buffer = ByteArrayOutputStream() java.lang.Throwable(projectPath).printStackTrace(PrintStream(buffer)) - val project = PlatformTestCase.createProject(projectPath, "Light project: $buffer", false) as ProjectEx + val project = PlatformTestCase.createProject(projectPath, "Light project: $buffer") as ProjectEx Disposer.register(ApplicationManager.getApplication(), Disposable { try { disposeProject() diff --git a/platform/util-rt/src/com/intellij/openapi/util/io/FileUtilRt.java b/platform/util-rt/src/com/intellij/openapi/util/io/FileUtilRt.java index fe7fdf648c90..8a48ba176218 100644 --- a/platform/util-rt/src/com/intellij/openapi/util/io/FileUtilRt.java +++ b/platform/util-rt/src/com/intellij/openapi/util/io/FileUtilRt.java @@ -385,14 +385,12 @@ public class FileUtilRt { if (suffix == null) { suffix = ".tmp"; } - // normalize and use only the file name from the prefix - prefix = new File(prefix).getName(); int exceptionsCount = 0; - int i = 0; while (true) { try { - final File temp = callCreate(dir, prefix, suffix, isDirectory, i); + // If there was an IOException, there's no reason to do sequential search - fallback to random + final File temp = createTemp(prefix, suffix, dir, isDirectory, exceptionsCount > 0); return normalizeFile(temp); } catch (IOException e) { // Win32 createFileExclusively access denied @@ -400,28 +398,41 @@ public class FileUtilRt { throw e; } } - i++; // for some reason the file1 can't be created (previous file1 was deleted but got locked by anti-virus?). try file2. - if (i > 2) { - i = 2 + (int)(System.nanoTime() % 998); // generate random suffix if too many failures - } } } @NotNull - private static File callCreate(@NotNull File directory, - @NotNull String prefix, + private static File createTemp(@NotNull String prefix, @NotNull String suffix, + @NotNull File directory, boolean isDirectory, - int i) throws IOException { - prefix += i == 0 ? "" : i; - if (prefix.endsWith(".") && suffix.startsWith(".")) { - prefix = prefix.substring(0, prefix.length() - 1); + boolean randomName) throws IOException { + // Fallback to the original File.createTempFile + if (randomName) { + @SuppressWarnings("SSBasedInspection") + File res = File.createTempFile(prefix, suffix, directory); + if (isDirectory) { + if (!res.delete() || !res.mkdir()) { + throw new IOException("Cannot create directory: " + res); + } + } + return res; } - String name = prefix + suffix; - File f = new File(directory, name); - if (!name.equals(f.getName())) { - throw new IOException("Unable to create temporary file " + f + " for name " + name); + + // normalize and use only the file name from the prefix + prefix = new File(prefix).getName(); + + File f; + int i = 0; + do { + String name = prefix + i + suffix; + f = new File(directory, name); + if (!name.equals(f.getName())) { + throw new IOException("Unable to create temporary file " + f + " for name " + name); + } + i++; } + while (f.exists()); boolean success = isDirectory ? f.mkdir() : f.createNewFile(); if (!success) {