mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Load IdeaWin32 in tests; cleanup
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,8 +19,7 @@ package com.intellij.openapi.vfs.impl.win32;
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public class IdeaWin32 {
|
||||
public native FileInfo getInfo(String path);
|
||||
|
||||
public native FileInfo getInfo(String path);
|
||||
|
||||
public native FileInfo[] listChildren(String path);
|
||||
public native FileInfo[] listChildren(String path);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,9 +26,8 @@ import java.util.Map;
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public class Win32Kernel {
|
||||
|
||||
public static final int FILE_ATTRIBUTE_READONLY = 0x0001;
|
||||
public static final int FILE_ATTRIBUTE_DIRECTORY = 0x0010;
|
||||
public static final int FILE_ATTRIBUTE_READONLY = 0x0001;
|
||||
|
||||
private final IdeaWin32 myKernel = new IdeaWin32();
|
||||
|
||||
@@ -39,7 +38,6 @@ public class Win32Kernel {
|
||||
}
|
||||
|
||||
public String[] list(String absolutePath) {
|
||||
|
||||
FileInfo[] fileInfos = myKernel.listChildren(absolutePath.replace('/', '\\') + "\\*.*");
|
||||
if (fileInfos == null) {
|
||||
return ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
@@ -62,7 +60,7 @@ public class Win32Kernel {
|
||||
}
|
||||
|
||||
public void exists(String path) throws FileNotFoundException {
|
||||
getInfo(path);
|
||||
getInfo(path);
|
||||
}
|
||||
|
||||
public boolean isDirectory(String path) throws FileNotFoundException {
|
||||
@@ -88,7 +86,6 @@ public class Win32Kernel {
|
||||
private FileInfo getInfo(String path) throws FileNotFoundException {
|
||||
FileInfo info = myCache.get(path);
|
||||
if (info == null) {
|
||||
|
||||
info = myKernel.getInfo(path.replace('/', '\\'));
|
||||
if (info == null) {
|
||||
throw new FileNotFoundException(path);
|
||||
|
||||
+26
-12
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,7 +15,9 @@
|
||||
*/
|
||||
package com.intellij.openapi.vfs.impl.win32;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.impl.local.LocalFileSystemBase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -29,18 +31,31 @@ import java.util.Set;
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public class Win32LocalFileSystem extends LocalFileSystemBase {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vfs.impl.win32.Win32LocalFileSystem");
|
||||
|
||||
private static boolean ourIsAvailable;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("IdeaWin32");
|
||||
ourIsAvailable = true;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
ourIsAvailable = false;
|
||||
if (SystemInfo.isWindows) {
|
||||
try {
|
||||
System.load(PathManager.getHomePath() + "/community/bin/win/IdeaWin32.dll");
|
||||
ourIsAvailable = true;
|
||||
}
|
||||
catch (Throwable t0) {
|
||||
try {
|
||||
System.load(PathManager.getHomePath() + "/bin/win/IdeaWin32.dll");
|
||||
ourIsAvailable = true;
|
||||
}
|
||||
catch (Throwable t1) {
|
||||
try {
|
||||
System.loadLibrary("IdeaWin32");
|
||||
ourIsAvailable = true;
|
||||
}
|
||||
catch (Throwable t2) {
|
||||
ourIsAvailable = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +71,7 @@ public class Win32LocalFileSystem extends LocalFileSystemBase {
|
||||
};
|
||||
|
||||
public static Win32LocalFileSystem getWin32Instance() {
|
||||
if (!isAvailable()) throw new RuntimeException("dll is not loaded");
|
||||
if (!isAvailable()) throw new RuntimeException("DLL is not loaded");
|
||||
Win32LocalFileSystem fileSystem = THREAD_LOCAL.get();
|
||||
fileSystem.myKernel.clearCache();
|
||||
return fileSystem;
|
||||
@@ -65,8 +80,7 @@ public class Win32LocalFileSystem extends LocalFileSystemBase {
|
||||
private final Win32Kernel myKernel = new Win32Kernel();
|
||||
public static boolean checkMe = false;
|
||||
|
||||
private Win32LocalFileSystem() {
|
||||
}
|
||||
private Win32LocalFileSystem() { }
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -157,7 +171,7 @@ public class Win32LocalFileSystem extends LocalFileSystemBase {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public WatchRequest addRootToWatch(@NotNull String rootPath, boolean toWatchRecursively) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
+36
-10
@@ -28,22 +28,36 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SymLinkHandlingTest extends LightPlatformTestCase {
|
||||
private LocalFileSystem myFileSystem;
|
||||
|
||||
@SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors")
|
||||
public SymLinkHandlingTest() {
|
||||
PlatformTestCase.initPlatformLangPrefix();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFileSystem = LocalFileSystem.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
myFileSystem = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testBadLinksAreIgnored() throws Exception {
|
||||
if (!SystemInfo.areSymLinksSupported) return;
|
||||
|
||||
final File missingFile = new File(FileUtil.getTempDirectory(), "missing_file");
|
||||
assertTrue(missingFile.getAbsolutePath(), !missingFile.exists() || missingFile.delete());
|
||||
final File missingLinkFile = createTempLink(missingFile.getAbsolutePath(), "missing_link");
|
||||
final VirtualFile missingLinkVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(missingLinkFile);
|
||||
final VirtualFile missingLinkVFile = refreshAndFind(missingLinkFile);
|
||||
assertNull(missingLinkVFile);
|
||||
|
||||
final File selfLinkFile = createTempLink("self_link", "self_link");
|
||||
final VirtualFile selfLinkVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(selfLinkFile);
|
||||
final VirtualFile selfLinkVFile = refreshAndFind(selfLinkFile);
|
||||
assertNull(selfLinkVFile);
|
||||
}
|
||||
|
||||
@@ -52,27 +66,27 @@ public class SymLinkHandlingTest extends LightPlatformTestCase {
|
||||
|
||||
final File targetFile = FileUtil.createTempFile("target", "");
|
||||
final File linkFile = createTempLink(targetFile.getAbsolutePath(), "link");
|
||||
final VirtualFile linkVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(linkFile);
|
||||
final VirtualFile linkVFile = refreshAndFind(linkFile);
|
||||
assertTrue("link=" + linkFile + ", vLink=" + linkVFile, linkVFile != null && !linkVFile.isDirectory() && linkVFile.isSymLink());
|
||||
|
||||
assertTrue(targetFile.getAbsolutePath(), targetFile.setWritable(true, false) && targetFile.canWrite());
|
||||
linkVFile.refresh(false, false);
|
||||
refresh();
|
||||
assertTrue(linkVFile.getPath(), linkVFile.isWritable());
|
||||
assertTrue(targetFile.getAbsolutePath(), targetFile.setWritable(false, false) && !targetFile.canWrite());
|
||||
linkVFile.refresh(false, false);
|
||||
refresh();
|
||||
assertFalse(linkVFile.getPath(), linkVFile.isWritable());
|
||||
|
||||
final File targetDir = FileUtil.createTempDirectory("targetDir", "");
|
||||
final File linkDir = createTempLink(targetDir.getAbsolutePath(), "linkDir");
|
||||
final VirtualFile linkVDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(linkDir);
|
||||
final VirtualFile linkVDir = refreshAndFind(linkDir);
|
||||
assertTrue("link=" + linkDir + ", vLink=" + linkVDir, linkVDir != null && linkVDir.isDirectory() && linkVDir.isSymLink());
|
||||
|
||||
if (!SystemInfo.isWindows) {
|
||||
assertTrue(targetDir.getAbsolutePath(), targetDir.setWritable(true, false) && targetDir.canWrite());
|
||||
linkVDir.refresh(false, true);
|
||||
refresh();
|
||||
assertTrue(linkVDir.getPath(), linkVDir.isWritable());
|
||||
assertTrue(targetDir.getAbsolutePath(), targetDir.setWritable(false, false) && !targetDir.canWrite());
|
||||
linkVDir.refresh(false, true);
|
||||
refresh();
|
||||
assertFalse(linkVDir.getPath(), linkVDir.isWritable());
|
||||
}
|
||||
else {
|
||||
@@ -85,7 +99,7 @@ public class SymLinkHandlingTest extends LightPlatformTestCase {
|
||||
|
||||
final File targetFile = FileUtil.createTempFile("target", "");
|
||||
final File linkFile = createTempLink(targetFile.getAbsolutePath(), "link");
|
||||
final VirtualFile linkVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(linkFile);
|
||||
final VirtualFile linkVFile = refreshAndFind(linkFile);
|
||||
assertTrue("link=" + linkFile + ", vLink=" + linkVFile, linkVFile != null && !linkVFile.isDirectory() && linkVFile.isSymLink());
|
||||
|
||||
AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(getClass());
|
||||
@@ -103,7 +117,7 @@ public class SymLinkHandlingTest extends LightPlatformTestCase {
|
||||
final File childFile = new File(targetDir, "child.txt");
|
||||
assertTrue(childFile.getAbsolutePath(), childFile.exists() || childFile.createNewFile());
|
||||
final File linkDir = createTempLink(targetDir.getAbsolutePath(), "linkDir");
|
||||
final VirtualFile linkVDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(linkDir);
|
||||
final VirtualFile linkVDir = refreshAndFind(linkDir);
|
||||
assertTrue("link=" + linkDir + ", vLink=" + linkVDir,
|
||||
linkVDir != null && linkVDir.isDirectory() && linkVDir.isSymLink() && linkVDir.getChildren().length == 1);
|
||||
|
||||
@@ -143,4 +157,16 @@ public class SymLinkHandlingTest extends LightPlatformTestCase {
|
||||
assertEquals("target=" + target + ", link=" + linkFile, targetFile.exists(), linkFile.exists());
|
||||
return linkFile;
|
||||
}
|
||||
|
||||
private VirtualFile refreshAndFind(final File ioFile) {
|
||||
refresh();
|
||||
return myFileSystem.findFileByPath(ioFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
final String tempPath = FileUtil.getTempDirectory();
|
||||
final VirtualFile tempDir = myFileSystem.findFileByPath(tempPath);
|
||||
assertNotNull(tempPath, tempDir);
|
||||
tempDir.refresh(false, true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user