Search in sources :

Example 6 with LocalFileSystem

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

the class MavenProject method getExistingModuleFiles.

@NotNull
public List<VirtualFile> getExistingModuleFiles() {
    LocalFileSystem fs = LocalFileSystem.getInstance();
    List<VirtualFile> result = new ArrayList<>();
    Set<String> pathsInStack = getModulePaths();
    for (String each : pathsInStack) {
        VirtualFile f = fs.findFileByPath(each);
        if (f != null)
            result.add(f);
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with LocalFileSystem

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

the class SvnExternalCommitNoticedTest method testExternalCommitInExternals.

@Test
public void testExternalCommitInExternals() throws Exception {
    prepareExternal();
    final File sourceDir = new File(myWorkingCopyDir.getPath(), "source");
    final File externalDir = new File(myWorkingCopyDir.getPath(), "source/external");
    final File file = new File(externalDir, "t11.txt");
    final VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
    final File mainFile = new File(myWorkingCopyDir.getPath(), "source/s1.txt");
    final VirtualFile vfMain = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(mainFile);
    renameFileInCommand(vf, "tt11.txt");
    renameFileInCommand(vfMain, "ss11.txt");
    myVcsDirtyScopeManager.markEverythingDirty();
    clManager.ensureUpToDate(false);
    Assert.assertEquals(2, clManager.getChangesIn(myWorkingCopyDir).size());
    TimeoutUtil.sleep(100);
    runInAndVerifyIgnoreOutput("ci", "-m", "test", sourceDir.getPath());
    runInAndVerifyIgnoreOutput("ci", "-m", "test", externalDir.getPath());
    myWorkingCopyDir.refresh(false, true);
    final LocalFileSystem lfs = LocalFileSystem.getInstance();
    imitateEvent(lfs.refreshAndFindFileByIoFile(sourceDir));
    imitateEvent(lfs.refreshAndFindFileByIoFile(externalDir));
    // no dirty scope externally provided! just VFS refresh
    clManager.ensureUpToDate(false);
    Assert.assertEquals(0, clManager.getChangesIn(myWorkingCopyDir).size());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Test(org.junit.Test)

Example 8 with LocalFileSystem

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

the class AntTasksProvider method getAntObjects.

private static Map<String, Class> getAntObjects(final GroovyFile groovyFile) {
    final Project project = groovyFile.getProject();
    final Module module = ModuleUtilCore.findModuleForPsiElement(groovyFile);
    Set<VirtualFile> jars = new HashSet<>();
    if (module != null) {
        ContainerUtil.addAll(jars, OrderEnumerator.orderEntries(module).getAllLibrariesAndSdkClassesRoots());
    }
    if (groovyFile.isScript() && GroovyScriptUtil.getScriptType(groovyFile) instanceof GantScriptType) {
        jars.addAll(GantScriptType.additionalScopeFiles(groovyFile));
    }
    final ArrayList<URL> urls = new ArrayList<>();
    for (VirtualFile jar : jars) {
        VirtualFile localFile = PathUtil.getLocalFile(jar);
        if (localFile.getFileSystem() instanceof LocalFileSystem) {
            urls.add(VfsUtilCore.convertToURL(localFile.getUrl()));
        }
    }
    AntClassLoader loader;
    synchronized (ourLock) {
        final Map<List<URL>, AntClassLoader> map = CachedValuesManager.getManager(project).getParameterizedCachedValue(project, KEY, PROVIDER, false, project);
        loader = map.get(urls);
        if (loader == null) {
            map.put(urls, loader = new AntClassLoader(urls));
        }
    }
    return loader.getAntObjects();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) URL(java.net.URL) Project(com.intellij.openapi.project.Project) ReflectedProject(com.intellij.lang.ant.ReflectedProject) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Module(com.intellij.openapi.module.Module)

Example 9 with LocalFileSystem

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

the class CompilerUtil method refreshOutputRoots.

/**
   * A lightweight procedure which ensures that given roots exist in the VFS.
   * No actual refresh is performed.
   */
public static void refreshOutputRoots(@NotNull Collection<String> outputRoots) {
    LocalFileSystem fs = LocalFileSystem.getInstance();
    Collection<VirtualFile> toRefresh = ContainerUtil.newHashSet();
    for (String outputRoot : outputRoots) {
        FileAttributes attributes = FileSystemUtil.getAttributes(FileUtil.toSystemDependentName(outputRoot));
        VirtualFile vFile = fs.findFileByPath(outputRoot);
        if (attributes != null && vFile == null) {
            VirtualFile parent = fs.refreshAndFindFileByPath(PathUtil.getParentPath(outputRoot));
            if (parent != null && toRefresh.add(parent)) {
                parent.getChildren();
            }
        } else if (attributes == null && vFile != null || attributes != null && attributes.isDirectory() != vFile.isDirectory()) {
            toRefresh.add(vFile);
        }
    }
    if (!toRefresh.isEmpty()) {
        RefreshQueue.getInstance().refresh(false, false, null, toRefresh);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) FileAttributes(com.intellij.openapi.util.io.FileAttributes)

Example 10 with LocalFileSystem

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

the class ExternalSystemNodeAction method getExternalConfig.

@Nullable
protected VirtualFile getExternalConfig(@NotNull ExternalConfigPathAware data, ProjectSystemId externalSystemId) {
    String path = data.getLinkedExternalProjectPath();
    LocalFileSystem fileSystem = LocalFileSystem.getInstance();
    VirtualFile externalSystemConfigPath = fileSystem.refreshAndFindFileByPath(path);
    if (externalSystemConfigPath == null) {
        return null;
    }
    VirtualFile toOpen = externalSystemConfigPath;
    for (ExternalSystemConfigLocator locator : ExternalSystemConfigLocator.EP_NAME.getExtensions()) {
        if (externalSystemId.equals(locator.getTargetExternalSystemId())) {
            toOpen = locator.adjust(toOpen);
            if (toOpen == null) {
                return null;
            }
            break;
        }
    }
    return toOpen.isDirectory() ? null : toOpen;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) ExternalSystemConfigLocator(com.intellij.openapi.externalSystem.service.settings.ExternalSystemConfigLocator) Nullable(org.jetbrains.annotations.Nullable)

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