Search in sources :

Example 66 with LocalFileSystem

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();
                }
            });
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Library(com.intellij.openapi.roots.libraries.Library)

Example 67 with LocalFileSystem

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Nullable(org.jetbrains.annotations.Nullable)

Example 68 with LocalFileSystem

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();
}
Also used : LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator)

Example 69 with LocalFileSystem

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Nullable(javax.annotation.Nullable)

Example 70 with LocalFileSystem

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()) };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GoFile(com.goide.psi.GoFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) PsiFile(com.intellij.psi.PsiFile) IOException(java.io.IOException) GoFile(com.goide.psi.GoFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) PsiElement(com.intellij.psi.PsiElement) Nullable(javax.annotation.Nullable)

Aggregations

LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)70 VirtualFile (com.intellij.openapi.vfs.VirtualFile)62 File (java.io.File)32 Nullable (org.jetbrains.annotations.Nullable)10 NotNull (org.jetbrains.annotations.NotNull)8 IOException (java.io.IOException)7 Project (com.intellij.openapi.project.Project)5 Change (com.intellij.openapi.vcs.changes.Change)5 Test (org.junit.Test)5 Module (com.intellij.openapi.module.Module)4 Library (com.intellij.openapi.roots.libraries.Library)4 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)4 PsiFile (com.intellij.psi.PsiFile)4 Application (com.intellij.openapi.application.Application)3 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)3 Notification (com.intellij.notification.Notification)2 ModuleManager (com.intellij.openapi.module.ModuleManager)2 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)2