mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
make temporary names more nice-looking, remove project files cached in VFS from the previous tests
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>testSimple_0.iml</file>
|
||||
<file>testSimple.iml</file>
|
||||
<problem_class>Unused library</problem_class>
|
||||
<description>Unused library 'JUnit'</description>
|
||||
</problem>
|
||||
|
||||
@@ -110,7 +110,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
|
||||
protected boolean myAssertionsInTestDetected;
|
||||
protected static final Logger LOG = Logger.getInstance("#com.intellij.testFramework.PlatformTestCase");
|
||||
public static Thread ourTestThread;
|
||||
private static TestCase ourTestCase = null;
|
||||
private static TestCase ourTestCase;
|
||||
public static final long DEFAULT_TEST_TIME = 300L;
|
||||
public static long ourTestTime = DEFAULT_TEST_TIME;
|
||||
private EditorListenerTracker myEditorListenerTracker;
|
||||
@@ -191,6 +191,9 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
File tempDir = new File(FileUtilRt.getTempDirectory());
|
||||
myFilesToDelete.add(tempDir);
|
||||
|
||||
if (ourTestCase != null) {
|
||||
String message = "Previous test " + ourTestCase + " hasn't called tearDown(). Probably overridden without super call.";
|
||||
ourTestCase = null;
|
||||
@@ -307,7 +310,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;
|
||||
}
|
||||
|
||||
@@ -139,7 +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
|
||||
myTempDir = FileUtil.toSystemDependentName(ORIGINAL_TEMP_DIR + "/" + TEMP_DIR_MARKER + testName + "_"+ RNG.nextInt(1000));
|
||||
myTempDir = new File(ORIGINAL_TEMP_DIR, TEMP_DIR_MARKER + testName).getPath();
|
||||
FileUtil.resetCanonicalTempPathCache(myTempDir);
|
||||
}
|
||||
ApplicationInfoImpl.setInPerformanceTest(isPerformanceTest());
|
||||
|
||||
@@ -315,7 +315,7 @@ public class FileUtilRt {
|
||||
}
|
||||
|
||||
private static class FilesToDeleteHolder {
|
||||
public static final Queue<String> ourFilesToDelete = createFilesToDelete();
|
||||
private static final Queue<String> ourFilesToDelete = createFilesToDelete();
|
||||
|
||||
private static Queue<String> createFilesToDelete() {
|
||||
final ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<String>();
|
||||
@@ -387,62 +387,47 @@ public class FileUtilRt {
|
||||
prefix = (prefix + "___").substring(0, 3);
|
||||
}
|
||||
if (suffix == null) {
|
||||
suffix = ".tmp";
|
||||
suffix = "";
|
||||
}
|
||||
// normalize and use only the file name from the prefix
|
||||
prefix = new File(prefix).getName();
|
||||
|
||||
int exceptionsCount = 0;
|
||||
int i = 0;
|
||||
while (true) {
|
||||
try {
|
||||
// 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);
|
||||
File f = calcName(dir, prefix, suffix, i);
|
||||
|
||||
boolean success = isDirectory ? f.mkdir() : f.createNewFile();
|
||||
if (!success) {
|
||||
throw new IOException("Unable to create temporary file " + f);
|
||||
}
|
||||
|
||||
return normalizeFile(f);
|
||||
}
|
||||
catch (IOException e) { // Win32 createFileExclusively access denied
|
||||
if (++exceptionsCount >= 100) {
|
||||
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 createTemp(@NotNull String prefix,
|
||||
@NotNull String suffix,
|
||||
@NotNull File directory,
|
||||
boolean isDirectory,
|
||||
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;
|
||||
private static File calcName(@NotNull File dir, @NotNull String prefix, @NotNull String suffix, int i) throws IOException {
|
||||
prefix += i == 0 ? "" : i;
|
||||
if (prefix.endsWith(".") && suffix.startsWith(".")) {
|
||||
prefix = prefix.substring(0, prefix.length() - 1);
|
||||
}
|
||||
|
||||
// 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++;
|
||||
String name = prefix + suffix;
|
||||
File f = new File(dir, name);
|
||||
if (!name.equals(f.getName())) {
|
||||
throw new IOException("Unable to create temporary file " + f + " for name " + name);
|
||||
}
|
||||
while (f.exists());
|
||||
|
||||
boolean success = isDirectory ? f.mkdir() : f.createNewFile();
|
||||
if (!success) {
|
||||
throw new IOException("Unable to create temporary file " + f);
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user