Search in sources :

Example 11 with VirtualFileManager

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

the class ExternalAnnotationsSupport method attachJdkAnnotations.

// Based on similar code in JavaSdkImpl
public static void attachJdkAnnotations(@NotNull SdkModificator modificator) {
    String homePath = FileUtil.toSystemIndependentName(PathManager.getHomePath());
    VirtualFileManager fileManager = VirtualFileManager.getInstance();
    // release build?
    String releaseLocation = homePath + "/plugins/android/lib/androidAnnotations.jar";
    VirtualFile root = fileManager.findFileByUrl("jar://" + releaseLocation + "!/");
    for (String relativePath : DEVELOPMENT_ANNOTATIONS_PATHS) {
        if (root != null)
            break;
        String developmentLocation = homePath + relativePath;
        root = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(developmentLocation));
    }
    if (root == null) {
        // error message tailored for release build file layout
        LOG.error("jdk annotations not found in: " + releaseLocation);
        return;
    }
    OrderRootType annoType = AnnotationOrderRootType.getInstance();
    modificator.removeRoot(root, annoType);
    modificator.addRoot(root, annoType);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager)

Example 12 with VirtualFileManager

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

the class ImageRefreshFix method setStamps.

@NotNull
static String setStamps(@NotNull String html) {
    final VirtualFileManager virtualFileManager = VirtualFileManager.getInstance();
    final String pattern = "<img src=\"file:";
    StringBuilder sb = StringBuilderSpinAllocator.alloc();
    try {
        int processedOffset = 0;
        while (true) {
            final int nextI = html.indexOf(pattern, processedOffset);
            if (nextI == -1) {
                break;
            }
            final int nextJ = html.indexOf('"', nextI + pattern.length());
            if (nextJ == -1) {
                return html;
            }
            sb.append(html, processedOffset, nextI + pattern.length());
            final String url = html.substring(nextI + pattern.length(), nextJ);
            sb.append(processUrl(virtualFileManager, url));
            sb.append('"');
            processedOffset = nextJ + 1;
        }
        if (processedOffset < html.length()) {
            sb.append(html, processedOffset, html.length());
        }
        return sb.toString();
    } finally {
        StringBuilderSpinAllocator.dispose(sb);
    }
}
Also used : VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with VirtualFileManager

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

the class SimpleClasspathElementFactory method convertToFiles.

public static List<VirtualFile> convertToFiles(Collection<SimpleClasspathElement> cpeList) {
    VirtualFileManager fileManager = VirtualFileManager.getInstance();
    List<VirtualFile> files = new ArrayList<>();
    for (SimpleClasspathElement cpe : cpeList) {
        for (String fileUrl : cpe.getClassesRootUrls()) {
            VirtualFile file = fileManager.findFileByUrl(fileUrl);
            if (file != null) {
                files.add(file);
            }
        }
    }
    return files;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) ArrayList(java.util.ArrayList)

Example 14 with VirtualFileManager

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

the class LocalHistoryImpl method disposeComponent.

@Override
public void disposeComponent() {
    if (!isInitialized.getAndSet(false))
        return;
    long period = Registry.intValue("localHistory.daysToKeep") * 1000L * 60L * 60L * 24L;
    myConnection.disconnect();
    myConnection = null;
    VirtualFileManager fm = VirtualFileManager.getInstance();
    fm.removeVirtualFileManagerListener(myEventDispatcher);
    CommandProcessor.getInstance().removeCommandListener(myEventDispatcher);
    LocalHistoryLog.LOG.debug("Purging local history...");
    myChangeList.purgeObsolete(period);
    myChangeList.close();
    LocalHistoryLog.LOG.debug("Local history storage successfully closed.");
    ShutDownTracker.getInstance().unregisterShutdownTask(myShutdownTask);
}
Also used : VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager)

Example 15 with VirtualFileManager

use of com.intellij.openapi.vfs.VirtualFileManager 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

VirtualFileManager (com.intellij.openapi.vfs.VirtualFileManager)19 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 File (java.io.File)4 OrderRootType (com.intellij.openapi.roots.OrderRootType)3 Element (org.jdom.Element)3 NotNull (org.jetbrains.annotations.NotNull)3 Module (com.intellij.openapi.module.Module)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 JavadocOrderRootType (com.intellij.openapi.roots.JavadocOrderRootType)2 Nullable (org.jetbrains.annotations.Nullable)2 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)1 ResourceResolver (com.android.ide.common.resources.ResourceResolver)1 AttributesTableModel (com.android.tools.idea.editors.theme.attributes.AttributesTableModel)1 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)1 EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)1 AndroidModel (com.android.tools.idea.model.AndroidModel)1 IProperty (com.intellij.lang.properties.IProperty)1 ResourceBundle (com.intellij.lang.properties.ResourceBundle)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 XmlPropertiesFile (com.intellij.lang.properties.xml.XmlPropertiesFile)1