Search in sources :

Example 6 with VirtualFileFilter

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

the class ReformatCodeAction method registerFileMaskFilter.

public static void registerFileMaskFilter(@NotNull AbstractLayoutCodeProcessor processor, @Nullable String fileTypeMask) {
    if (fileTypeMask == null)
        return;
    final Condition<CharSequence> patternCondition = getFileTypeMaskPattern(fileTypeMask);
    processor.addFileFilter(new VirtualFileFilter() {

        @Override
        public boolean accept(@NotNull VirtualFile file) {
            return patternCondition.value(file.getNameSequence());
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileFilter(com.intellij.openapi.vfs.VirtualFileFilter)

Example 7 with VirtualFileFilter

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

the class CCStepicConnector method postAdditionalFiles.

private static void postAdditionalFiles(@NotNull final Project project, int id, ProgressIndicator indicator) {
    final VirtualFile baseDir = project.getBaseDir();
    final List<VirtualFile> files = VfsUtil.getChildren(baseDir, new VirtualFileFilter() {

        @Override
        public boolean accept(VirtualFile file) {
            final String name = file.getName();
            return !name.contains(EduNames.LESSON) && !name.equals(EduNames.COURSE_META_FILE) && !name.equals(EduNames.HINTS) && !"pyc".equals(file.getExtension()) && !file.isDirectory() && !name.equals(EduNames.TEST_HELPER) && !name.startsWith(".");
        }
    });
    if (!files.isEmpty()) {
        final int sectionId = postModule(id, 2, EduNames.PYCHARM_ADDITIONAL);
        final Lesson lesson = new Lesson();
        lesson.setName(EduNames.PYCHARM_ADDITIONAL);
        final Task task = new Task();
        task.setLesson(lesson);
        task.setName(EduNames.PYCHARM_ADDITIONAL);
        task.setIndex(1);
        task.setText(EduNames.PYCHARM_ADDITIONAL);
        for (VirtualFile file : files) {
            try {
                if (file != null) {
                    if (EduUtils.isImage(file.getName())) {
                        task.addTestsTexts(file.getName(), Base64.encodeBase64URLSafeString(FileUtil.loadBytes(file.getInputStream())));
                    } else {
                        task.addTestsTexts(file.getName(), FileUtil.loadTextAndClose(file.getInputStream()));
                    }
                }
            } catch (IOException e) {
                LOG.error("Can't find file " + file.getPath());
            }
        }
        lesson.addTask(task);
        lesson.setIndex(1);
        final int lessonId = postLesson(project, lesson, indicator);
        postUnit(lessonId, 1, sectionId);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileFilter(com.intellij.openapi.vfs.VirtualFileFilter) IOException(java.io.IOException)

Example 8 with VirtualFileFilter

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

the class PythonSdkConfigurator method configureProject.

public void configureProject(final Project project, @NotNull final VirtualFile baseDir, Ref<Module> moduleRef) {
    // it it a virtualenv?
    final List<VirtualFile> children = VfsUtil.getChildren(baseDir, new VirtualFileFilter() {

        @Override
        public boolean accept(VirtualFile file) {
            return !Project.DIRECTORY_STORE_FOLDER.equals(file.getName());
        }
    });
    if (children.isEmpty())
        return;
    final PythonSdkType sdkType = PythonSdkType.getInstance();
    //find virtualEnv in project directory
    final List<String> candidates = new ArrayList<>();
    if (project == null)
        return;
    final VirtualFile rootDir = project.getBaseDir();
    if (rootDir != null)
        candidates.addAll(VirtualEnvSdkFlavor.findInDirectory(rootDir));
    if (!candidates.isEmpty()) {
        String filePath = candidates.get(0);
        if (StringUtil.startsWithChar(filePath, '~')) {
            final String home = SystemProperties.getUserHome();
            filePath = home + filePath.substring(1);
        }
        final Sdk virtualEnvSdk = SdkConfigurationUtil.createAndAddSDK(filePath, sdkType);
        if (virtualEnvSdk != null) {
            SdkConfigurationUtil.setDirectoryProjectSdk(project, virtualEnvSdk);
            SdkAdditionalData additionalData = virtualEnvSdk.getSdkAdditionalData();
            if (additionalData == null) {
                additionalData = new PythonSdkAdditionalData(PythonSdkFlavor.getFlavor(virtualEnvSdk.getHomePath()));
                ((ProjectJdkImpl) virtualEnvSdk).setSdkAdditionalData(additionalData);
            }
            ((PythonSdkAdditionalData) additionalData).associateWithProject(project);
            return;
        }
        return;
    }
    final Sdk existingSdk = ProjectRootManager.getInstance(project).getProjectSdk();
    // SdkConfigurationUtil does the same
    if (existingSdk != null && existingSdk.getSdkType() == sdkType)
        return;
    final File executableFile = PythonSdkType.findExecutableFile(new File(project.getBasePath(), "bin"), "python");
    if (executableFile != null) {
        final File virtualEnvRoot = PythonSdkType.getVirtualEnvRoot(executableFile.getPath());
        if (virtualEnvRoot != null) {
            // yes, an unknown virtualenv; set it up as SDK
            final Sdk sdk = SdkConfigurationUtil.createAndAddSDK(executableFile.getPath(), sdkType);
            if (sdk != null) {
                SdkConfigurationUtil.setDirectoryProjectSdk(project, sdk);
                return;
            }
        }
    }
    // default
    SdkConfigurationUtil.configureDirectoryProjectSdk(project, new PreferredSdkComparator(), sdkType);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PreferredSdkComparator(com.jetbrains.python.sdk.PreferredSdkComparator) ArrayList(java.util.ArrayList) PythonSdkAdditionalData(com.jetbrains.python.sdk.PythonSdkAdditionalData) ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) VirtualFileFilter(com.intellij.openapi.vfs.VirtualFileFilter) PythonSdkType(com.jetbrains.python.sdk.PythonSdkType) Sdk(com.intellij.openapi.projectRoots.Sdk) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PythonSdkAdditionalData(com.jetbrains.python.sdk.PythonSdkAdditionalData) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData)

Example 9 with VirtualFileFilter

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

the class XmlIndex method createFilter.

protected static VirtualFileFilter createFilter(@NotNull final Module module) {
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
    return new VirtualFileFilter() {

        @Override
        public boolean accept(final VirtualFile file) {
            Module moduleForFile = fileIndex.getModuleForFile(file);
            if (moduleForFile != null) {
                // in module content
                return module.equals(moduleForFile);
            }
            if (fileIndex.isInLibraryClasses(file)) {
                List<OrderEntry> orderEntries = fileIndex.getOrderEntriesForFile(file);
                if (orderEntries.isEmpty()) {
                    return false;
                }
                for (OrderEntry orderEntry : orderEntries) {
                    Module ownerModule = orderEntry.getOwnerModule();
                    if (ownerModule.equals(module)) {
                        return true;
                    }
                }
            }
            final VirtualFile parent = file.getParent();
            assert parent != null;
            return parent.getName().equals("standardSchemas");
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileFilter(com.intellij.openapi.vfs.VirtualFileFilter) OrderEntry(com.intellij.openapi.roots.OrderEntry) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Module(com.intellij.openapi.module.Module)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 VirtualFileFilter (com.intellij.openapi.vfs.VirtualFileFilter)9 FileType (com.intellij.openapi.fileTypes.FileType)2 Module (com.intellij.openapi.module.Module)2 File (java.io.File)2 HashMultiset (com.google.common.collect.HashMultiset)1 Multiset (com.google.common.collect.Multiset)1 FindBundle (com.intellij.find.FindBundle)1 FindModel (com.intellij.find.FindModel)1 FindInProjectManager (com.intellij.find.findInProject.FindInProjectManager)1 TrigramIndex (com.intellij.find.ngrams.TrigramIndex)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ApplicationNamesInfo (com.intellij.openapi.application.ApplicationNamesInfo)1 ReadAction (com.intellij.openapi.application.ReadAction)1 Logger (com.intellij.openapi.diagnostic.Logger)1 FileTypeManager (com.intellij.openapi.fileTypes.FileTypeManager)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1