Search in sources :

Example 16 with VirtualFileManager

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

the class MvcModuleStructureUtil method cleanupDefaultLibrary.

public static void cleanupDefaultLibrary(Module module, Collection<Consumer<ModifiableRootModel>> actions, Collection<VirtualFile> appRoots, final String libName) {
    final Library library = findUserLibrary(module, libName);
    if (library == null) {
        return;
    }
    final VirtualFileManager virtualFileManager = VirtualFileManager.getInstance();
    final List<String> toRemoveUrls = new ArrayList<>();
    for (String url : library.getUrls(OrderRootType.CLASSES)) {
        VirtualFile virtualFile = virtualFileManager.findFileByUrl(url);
        if (virtualFile == null) {
            toRemoveUrls.add(url);
        } else {
            if (library.isJarDirectory(url)) {
                if (!virtualFile.getName().equals("lib") || !appRoots.contains(virtualFile.getParent())) {
                    toRemoveUrls.add(url);
                }
            }
        }
    }
    if (!toRemoveUrls.isEmpty()) {
        actions.add(model -> {
            final Library.ModifiableModel modifiableModel = modifyDefaultLibrary(model, libName);
            for (String url : toRemoveUrls) {
                modifiableModel.removeRoot(url, OrderRootType.CLASSES);
            }
            modifiableModel.commit();
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) Library(com.intellij.openapi.roots.libraries.Library)

Example 17 with VirtualFileManager

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

the class RepositoryAttachHandler method createRoots.

public static List<OrderRoot> createRoots(@NotNull Collection<MavenArtifact> artifacts, @Nullable String copyTo) {
    final List<OrderRoot> result = new ArrayList<>();
    final VirtualFileManager manager = VirtualFileManager.getInstance();
    for (MavenArtifact each : artifacts) {
        try {
            File repoFile = each.getFile();
            File toFile = repoFile;
            if (copyTo != null) {
                toFile = new File(copyTo, repoFile.getName());
                if (repoFile.exists()) {
                    FileUtil.copy(repoFile, toFile);
                }
            }
            // search for jar file first otherwise lib root won't be found!
            manager.refreshAndFindFileByUrl(VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(toFile.getPath())));
            final String url = VfsUtil.getUrlForLibraryRoot(toFile);
            final VirtualFile file = manager.refreshAndFindFileByUrl(url);
            if (file != null) {
                OrderRootType rootType;
                if (MavenExtraArtifactType.DOCS.getDefaultClassifier().equals(each.getClassifier())) {
                    rootType = JavadocOrderRootType.getInstance();
                } else if (MavenExtraArtifactType.SOURCES.getDefaultClassifier().equals(each.getClassifier())) {
                    rootType = OrderRootType.SOURCES;
                } else {
                    rootType = OrderRootType.CLASSES;
                }
                result.add(new OrderRoot(file, rootType));
            }
        } catch (IOException e) {
            MavenLog.LOG.warn(e);
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) OrderRootType(com.intellij.openapi.roots.OrderRootType) JavadocOrderRootType(com.intellij.openapi.roots.JavadocOrderRootType) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 18 with VirtualFileManager

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

the class DslActivationStatus method loadState.

@Override
public void loadState(State state) {
    synchronized (myStatus) {
        myStatus.clear();
        if (ContainerUtil.isEmpty(state.entries)) {
            return;
        }
        final VirtualFileManager fileManager = VirtualFileManager.getInstance();
        for (Entry entry : state.entries) {
            if (entry.url == null || entry.status == null)
                continue;
            final VirtualFile file = fileManager.findFileByUrl(entry.url);
            if (file != null) {
                myStatus.put(file, entry);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager)

Example 19 with VirtualFileManager

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

the class ResourceBundleEditor method installPropertiesChangeListeners.

private void installPropertiesChangeListeners() {
    final VirtualFileManager virtualFileManager = VirtualFileManager.getInstance();
    if (myVfsListener != null) {
        throw new AssertionError("Listeners can't be initialized twice");
    }
    myVfsListener = new ResourceBundleEditorFileListener(this);
    virtualFileManager.addVirtualFileListener(myVfsListener, this);
    PsiTreeChangeAdapter psiTreeChangeAdapter = new PsiTreeChangeAdapter() {

        @Override
        public void childAdded(@NotNull PsiTreeChangeEvent event) {
            final PsiFile file = event.getFile();
            if (file instanceof XmlFile) {
                final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file);
                if (propertiesFile != null) {
                    final ResourceBundle bundle = propertiesFile.getResourceBundle();
                    if (bundle.equals(myResourceBundle) && !myEditors.containsKey(propertiesFile.getVirtualFile())) {
                        recreateEditorsPanel();
                    }
                }
            }
        }

        @Override
        public void childRemoved(@NotNull PsiTreeChangeEvent event) {
            final PsiFile file = event.getFile();
            final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file);
            if (propertiesFile != null) {
                final ResourceBundle bundle = propertiesFile.getResourceBundle();
                if (bundle.equals(myResourceBundle) && myEditors.containsKey(propertiesFile.getVirtualFile())) {
                    final IProperty property = PropertiesImplUtil.getProperty(event.getParent());
                    if (property != null && Comparing.equal(property.getName(), getSelectedPropertyName())) {
                        updateEditorsFromProperties(false);
                    }
                }
            }
        }
    };
    PsiManager.getInstance(myProject).addPsiTreeChangeListener(psiTreeChangeAdapter, this);
}
Also used : VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) XmlFile(com.intellij.psi.xml.XmlFile) IProperty(com.intellij.lang.properties.IProperty) XmlPropertiesFile(com.intellij.lang.properties.xml.XmlPropertiesFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) ResourceBundle(com.intellij.lang.properties.ResourceBundle) NotNull(org.jetbrains.annotations.NotNull)

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