use of com.intellij.openapi.vfs.LocalFileSystem in project google-cloud-intellij by GoogleCloudPlatform.
the class EndpointTestBase method addEndpointSdkToProject.
/**
* Adds the App Engine - Endpoint SDK to the test project's library
*/
private void addEndpointSdkToProject() {
LocalFileSystem fs = LocalFileSystem.getInstance();
final VirtualFile libDir = fs.findFileByPath(getTestDataPath());
if (libDir != null) {
final VirtualFile pluginsDir = libDir.findChild("lib");
if (pluginsDir != null) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
final LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(LibraryTablesRegistrar.APPLICATION_LEVEL, myModule.getProject());
assert table != null;
final LibraryTable.ModifiableModel tableModel = table.getModifiableModel();
final Library library = tableModel.createLibrary("endpoints-lib");
final Library.ModifiableModel libraryModel = library.getModifiableModel();
libraryModel.addJarDirectory(pluginsDir, true);
libraryModel.commit();
tableModel.commit();
ModifiableRootModel rootModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
Library jar = table.getLibraries()[0];
// Endpoint is the only jar added
rootModel.addLibraryEntry(jar);
rootModel.commit();
}
});
}
}
}
use of com.intellij.openapi.vfs.LocalFileSystem in project yii2support by nvlad.
the class YiiApplicationUtils method getYiiRootVirtualFile.
@Nullable
public static VirtualFile getYiiRootVirtualFile(Project project) {
if (yiiRootPaths.containsKey(project)) {
return yiiRootPaths.get(project);
}
String path = Yii2SupportSettings.getInstance(project).yiiRootPath;
VirtualFile yiiRootPath;
if (path == null) {
yiiRootPath = project.getBaseDir();
} else {
LocalFileSystem fileSystem = LocalFileSystem.getInstance();
yiiRootPath = fileSystem.refreshAndFindFileByPath(path);
if (yiiRootPath == null) {
yiiRootPath = project.getBaseDir();
path = path.replace('\\', '/');
if (path.startsWith("./")) {
path = path.substring(2);
}
if (path.startsWith("/")) {
path = path.substring(1);
}
List<String> pathEntries = StringUtil.split(path, "/");
for (String pathEntry : pathEntries) {
yiiRootPath = yiiRootPath.findChild(pathEntry);
if (yiiRootPath == null) {
break;
}
}
}
}
yiiRootPaths.put(project, yiiRootPath);
return yiiRootPath;
}
use of com.intellij.openapi.vfs.LocalFileSystem in project moe-ide-integration by multi-os-engine.
the class MOESdkType method setupSdkRoots.
private void setupSdkRoots(Sdk sdk, Sdk jdk) {
SdkModificator sdkModificator = sdk.getSdkModificator();
sdkModificator.removeAllRoots();
LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
sdkModificator.setVersionString(jdk.getVersionString());
sdkModificator.setHomePath(sdkRootPath);
sdkModificator.commitChanges();
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij by bazelbuild.
the class VfsUtils method resolveVirtualFile.
/**
* Attempts to resolve the given file path to a {@link VirtualFile}. If called on the event
* thread, will refresh if not already cached.
*/
@Nullable
public static VirtualFile resolveVirtualFile(File file) {
LocalFileSystem fileSystem = VirtualFileSystemProvider.getInstance().getSystem();
VirtualFile vf = fileSystem.findFileByPathIfCached(file.getPath());
if (vf != null) {
return vf;
}
vf = fileSystem.findFileByIoFile(file);
if (vf != null && vf.isValid()) {
return vf;
}
boolean shouldRefresh = ApplicationManager.getApplication().isDispatchThread();
return shouldRefresh ? fileSystem.refreshAndFindFileByIoFile(file) : null;
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij by bazelbuild.
the class BlazeGoGotoDeclarationHandler method resolveElement.
@Nullable
private static PsiElement[] resolveElement(@Nullable PsiElement element) {
if (element == null) {
return null;
}
PsiFile targetPsiFile = element.getContainingFile();
if (!(targetPsiFile instanceof GoFile)) {
return null;
}
LocalFileSystem lfs = VirtualFileSystemProvider.getInstance().getSystem();
FileOperationProvider provider = FileOperationProvider.getInstance();
VirtualFile targetVirtualFile = targetPsiFile.getVirtualFile();
File targetFile = VfsUtil.virtualToIoFile(targetVirtualFile);
if (!provider.isSymbolicLink(targetFile)) {
return null;
}
VirtualFile resolved;
try {
// Resolve only one layer of symlink.
File resolvedFile = provider.readSymbolicLink(targetFile);
resolved = lfs.findFileByIoFile(resolvedFile);
} catch (IOException e) {
logger.error(e);
return null;
}
if (resolved == null) {
return null;
}
PsiFile resolvedFile = PsiManager.getInstance(element.getProject()).findFile(resolved);
if (!(resolvedFile instanceof GoFile)) {
return null;
}
PsiElement foundElement = resolvedFile.findElementAt(element.getTextOffset());
return new PsiElement[] { PsiTreeUtil.getParentOfType(foundElement, element.getClass()) };
}
Aggregations