Search in sources :

Example 21 with LocalFileSystem

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

the class GradleInstallationManager method getClassRoots.

/**
   * Allows to ask for the classpath roots of the classes that are additionally provided by the gradle integration (e.g. gradle class
   * files, bundled groovy-all jar etc).
   *
   * @param project target project to use for gradle home retrieval
   * @return classpath roots of the classes that are additionally provided by the gradle integration (if any);
   * <code>null</code> otherwise
   */
@Nullable
public List<VirtualFile> getClassRoots(@Nullable Project project) {
    List<File> files = getClassRoots(project, null);
    if (files == null)
        return null;
    final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
    final JarFileSystem jarFileSystem = JarFileSystem.getInstance();
    return ContainerUtil.mapNotNull(files, file -> {
        final VirtualFile virtualFile = localFileSystem.refreshAndFindFileByIoFile(file);
        return virtualFile != null ? jarFileSystem.getJarRootForLocalFile(virtualFile) : null;
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 22 with LocalFileSystem

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

the class GradleModuleBuilder method setupRootModel.

@Override
public void setupRootModel(final ModifiableRootModel modifiableRootModel) throws ConfigurationException {
    String contentEntryPath = getContentEntryPath();
    if (StringUtil.isEmpty(contentEntryPath)) {
        return;
    }
    File contentRootDir = new File(contentEntryPath);
    FileUtilRt.createDirectory(contentRootDir);
    LocalFileSystem fileSystem = LocalFileSystem.getInstance();
    VirtualFile modelContentRootDir = fileSystem.refreshAndFindFileByIoFile(contentRootDir);
    if (modelContentRootDir == null) {
        return;
    }
    modifiableRootModel.addContentEntry(modelContentRootDir);
    // todo this should be moved to generic ModuleBuilder
    if (myJdk != null) {
        modifiableRootModel.setSdk(myJdk);
    } else {
        modifiableRootModel.inheritSdk();
    }
    final Project project = modifiableRootModel.getProject();
    if (myParentProject != null) {
        rootProjectPath = myParentProject.getLinkedExternalProjectPath();
    } else {
        rootProjectPath = FileUtil.toCanonicalPath(myWizardContext.isCreatingNewProject() ? project.getBasePath() : modelContentRootDir.getPath());
    }
    assert rootProjectPath != null;
    final VirtualFile gradleBuildFile = setupGradleBuildFile(modelContentRootDir);
    setupGradleSettingsFile(rootProjectPath, modelContentRootDir, modifiableRootModel.getProject().getName(), myProjectId == null ? modifiableRootModel.getModule().getName() : myProjectId.getArtifactId(), myWizardContext.isCreatingNewProject() || myParentProject == null);
    if (gradleBuildFile != null) {
        modifiableRootModel.getModule().putUserData(BUILD_SCRIPT_DATA, new BuildScriptDataBuilder(gradleBuildFile));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) BuildScriptDataBuilder(org.jetbrains.plugins.gradle.frameworkSupport.BuildScriptDataBuilder) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File)

Example 23 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)

Example 24 with LocalFileSystem

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

the class ShowImageDuplicatesAction method collectAndShowDuplicates.

private static void collectAndShowDuplicates(final Project project) {
    final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    if (indicator != null && !indicator.isCanceled()) {
        indicator.setText("Collecting project images...");
        indicator.setIndeterminate(false);
        final List<VirtualFile> images = new ArrayList<>();
        for (String ext : IMAGE_EXTENSIONS) {
            images.addAll(FilenameIndex.getAllFilesByExt(project, ext));
        }
        final Map<Long, Set<VirtualFile>> duplicates = new HashMap<>();
        final Map<Long, VirtualFile> all = new HashMap<>();
        for (int i = 0; i < images.size(); i++) {
            indicator.setFraction((double) (i + 1) / (double) images.size());
            final VirtualFile file = images.get(i);
            if (!(file.getFileSystem() instanceof LocalFileSystem))
                continue;
            final long length = file.getLength();
            if (all.containsKey(length)) {
                if (!duplicates.containsKey(length)) {
                    final HashSet<VirtualFile> files = new HashSet<>();
                    files.add(all.get(length));
                    duplicates.put(length, files);
                }
                duplicates.get(length).add(file);
            } else {
                all.put(length, file);
            }
            indicator.checkCanceled();
        }
        showResults(project, images, duplicates, all);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem)

Example 25 with LocalFileSystem

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

the class DirectoryIndexRestoreTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    LocalFileSystem fs = LocalFileSystem.getInstance();
    File temp = createTempDirectory();
    myTempVFile = fs.findFileByIoFile(temp);
    assertNotNull(myTempVFile);
    File root = new File(temp, "top/d1/d2/root");
    assertTrue(root.mkdirs());
    VirtualFile rootVFile = fs.findFileByIoFile(root);
    assertNotNull(rootVFile);
    VirtualFile moduleDir = createChildDirectory(rootVFile, "module");
    VirtualFile srcDir = createChildDirectory(moduleDir, "src");
    VirtualFile testDir = createChildDirectory(srcDir, "pkg");
    ModuleRootModificationUtil.setModuleSdk(myModule, null);
    PsiTestUtil.addContentRoot(myModule, moduleDir);
    PsiTestUtil.addSourceRoot(myModule, srcDir);
    myTestDirPath = testDir.getPath();
    myFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
    // to not interfere with previous test firing vfs events
    VirtualFileManager.getInstance().syncRefresh();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

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