Search in sources :

Example 31 with LocalFileSystem

use of com.intellij.openapi.vfs.LocalFileSystem in project android by JetBrains.

the class AndroidJniFolderNode method contains.

@Override
public boolean contains(@NotNull VirtualFile file) {
    Collection<File> sourceFolders = getModel().getSelectedVariant().getSourceFolders();
    LocalFileSystem fileSystem = LocalFileSystem.getInstance();
    for (File folder : sourceFolders) {
        VirtualFile virtualFile = fileSystem.findFileByIoFile(folder);
        if (virtualFile != null && isAncestor(virtualFile, file, false)) {
            return true;
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 32 with LocalFileSystem

use of com.intellij.openapi.vfs.LocalFileSystem in project android by JetBrains.

the class TemplateTest method ignored_testTemplateFormatting.

// This test is broken after the IntelliJ 2016.2.4 merge; investigate
// whether this is legitimate or whether it's due to changed formatting
// preferences in the platform
public void ignored_testTemplateFormatting() throws Exception {
    Template template = Template.createFromPath(new File(getTestDataPath(), FileUtil.join("templates", "TestTemplate")).getCanonicalFile());
    RenderingContext context = RenderingContext.Builder.newContext(template, myFixture.getProject()).withOutputRoot(new File(myFixture.getTempDirPath())).withModuleRoot(new File("dummy")).build();
    template.render(context);
    FileDocumentManager.getInstance().saveAllDocuments();
    LocalFileSystem fileSystem = LocalFileSystem.getInstance();
    VirtualFile desired = fileSystem.findFileByIoFile(new File(getTestDataPath(), FileUtil.join("templates", "TestTemplate", "MergedStringsFile.xml")));
    VirtualFile actual = fileSystem.findFileByIoFile(new File(myFixture.getTempDirPath(), FileUtil.join("values", "TestTargetResourceFile.xml")));
    desired.refresh(false, false);
    actual.refresh(false, false);
    PlatformTestUtil.assertFilesEqual(desired, actual);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RenderingContext(com.android.tools.idea.templates.recipe.RenderingContext) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File)

Example 33 with LocalFileSystem

use of com.intellij.openapi.vfs.LocalFileSystem in project android by JetBrains.

the class GradleEditorParserTest method purgeGradleConfig.

/**
   * Recursively removes all gradle config files from the given dir.
   *
   * @param rootDir  target root dir
   * @throws IOException  in case of unexpected I/O exception occurred during processing
   */
private void purgeGradleConfig(@NotNull VirtualFile rootDir) throws IOException {
    final List<VirtualFile> toRemove = Lists.newArrayList();
    VfsUtil.processFileRecursivelyWithoutIgnored(rootDir, new Processor<VirtualFile>() {

        @Override
        public boolean process(VirtualFile file) {
            if (file.getName().endsWith(SdkConstants.DOT_GRADLE)) {
                toRemove.add(file);
            }
            return true;
        }
    });
    if (toRemove.isEmpty()) {
        return;
    }
    LocalFileSystem fileSystem = LocalFileSystem.getInstance();
    for (VirtualFile file : toRemove) {
        fileSystem.deleteFile(this, file);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem)

Example 34 with LocalFileSystem

use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-plugins by JetBrains.

the class JstdDebuggingFileFinderProvider method addAllRemoteUrlMappings.

private void addAllRemoteUrlMappings(@NotNull Collection<FileInfo> filesInfo, @NotNull BiMap<String, VirtualFile> map) {
    LocalFileSystem fileSystem = LocalFileSystem.getInstance();
    for (FileInfo fileInfo : filesInfo) {
        String displayPath = fileInfo.getDisplayPath();
        File file = fileInfo.toFile();
        if (StringUtil.isNotEmpty(displayPath) && file.isFile()) {
            VirtualFile virtualFile = fileSystem.findFileByIoFile(file);
            if (virtualFile != null) {
                String url = "http://127.0.0.1:" + myServer.getSettings().getPort() + "/test/" + UriUtil.trimLeadingSlashes(displayPath);
                map.forcePut(url, virtualFile);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileInfo(com.google.jstestdriver.FileInfo) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Example 35 with LocalFileSystem

use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.

the class JarDirectoryWatcherImpl method updateWatchedRoots.

@Override
public void updateWatchedRoots() {
    final LocalFileSystem fs = LocalFileSystem.getInstance();
    if (!myJarDirectories.isEmpty()) {
        final Set<String> recursiveRoots = new HashSet<>();
        final Set<String> flatRoots = new HashSet<>();
        final VirtualFileManager fm = VirtualFileManager.getInstance();
        for (OrderRootType rootType : myJarDirectories.getRootTypes()) {
            for (String url : myJarDirectories.getDirectories(rootType)) {
                if (fm.getFileSystem(VirtualFileManager.extractProtocol(url)) instanceof LocalFileSystem) {
                    final boolean watchRecursively = myJarDirectories.isRecursive(rootType, url);
                    final String path = VirtualFileManager.extractPath(url);
                    (watchRecursively ? recursiveRoots : flatRoots).add(path);
                }
            }
        }
        myWatchRequests = fs.replaceWatchedRoots(myWatchRequests, recursiveRoots, flatRoots);
        if (myBusConnection == null) {
            myBusConnection = ApplicationManager.getApplication().getMessageBus().connect();
            myBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {

                @Override
                public void after(@NotNull final List<? extends VFileEvent> events) {
                    boolean changesDetected = false;
                    for (VFileEvent event : events) {
                        if (event instanceof VFileCopyEvent) {
                            final VFileCopyEvent copyEvent = (VFileCopyEvent) event;
                            final VirtualFile file = copyEvent.getFile();
                            if (isUnderJarDirectory(copyEvent.getNewParent() + "/" + copyEvent.getNewChildName()) || file != null && isUnderJarDirectory(file.getUrl())) {
                                changesDetected = true;
                                break;
                            }
                        } else if (event instanceof VFileMoveEvent) {
                            final VFileMoveEvent moveEvent = (VFileMoveEvent) event;
                            final VirtualFile file = moveEvent.getFile();
                            if (file != null && (isUnderJarDirectory(file.getUrl()) || isUnderJarDirectory(moveEvent.getOldParent().getUrl() + "/" + file.getName()))) {
                                changesDetected = true;
                                break;
                            }
                        } else if (event instanceof VFileDeleteEvent) {
                            final VFileDeleteEvent deleteEvent = (VFileDeleteEvent) event;
                            if (isUnderJarDirectory(deleteEvent.getFile().getUrl())) {
                                changesDetected = true;
                                break;
                            }
                        } else if (event instanceof VFileCreateEvent) {
                            final VFileCreateEvent createEvent = (VFileCreateEvent) event;
                            if (isUnderJarDirectory(createEvent.getParent().getUrl() + "/" + createEvent.getChildName())) {
                                changesDetected = true;
                                break;
                            }
                        }
                    }
                    if (changesDetected) {
                        fireRootSetChanged();
                    }
                }

                private boolean isUnderJarDirectory(String url) {
                    for (String rootUrl : myJarDirectories.getAllDirectories()) {
                        if (FileUtil.startsWith(url, rootUrl)) {
                            return true;
                        }
                    }
                    return false;
                }
            });
        }
    } else {
        cleanup();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) OrderRootType(com.intellij.openapi.roots.OrderRootType)

Aggregations

LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)58 VirtualFile (com.intellij.openapi.vfs.VirtualFile)52 File (java.io.File)27 Nullable (org.jetbrains.annotations.Nullable)9 NotNull (org.jetbrains.annotations.NotNull)8 IOException (java.io.IOException)6 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 Application (com.intellij.openapi.application.Application)3 Library (com.intellij.openapi.roots.libraries.Library)3 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)3 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)3 PsiFile (com.intellij.psi.PsiFile)3 Notification (com.intellij.notification.Notification)2 ModuleManager (com.intellij.openapi.module.ModuleManager)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)2