Java Code Examples for com.wix.utils.FileUtils

The following examples show how to use com.wix.utils.FileUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: jscs-plugin   Source File: JscsFinder.java    License: MIT License 6 votes vote down vote up
/**
 * find possible jscs rc files
 * @param projectRoot
 * @return
 */
public static List<String> searchForJscsRCFiles(final File projectRoot) {
    FilenameFilter filter = new FilenameFilter() {
        @Override
        public boolean accept(File file, String name) {
            return name.equals(JSCSRC);
        }
    };
    // return Arrays.asList(files);
    List<String> files = FileUtils.recursiveVisitor(projectRoot, filter);
    return ContainerUtil.map(files, new Function<String, String>() {
        public String fun(String curFile) {
            return FileUtils.makeRelative(projectRoot, new File(curFile));
        }
    });
}
 
Example 2
Source Project: eslint-plugin   Source File: ESLintFinder.java    License: MIT License 6 votes vote down vote up
/**
 * find possible eslint rc files
 *
 * @param projectRoot project root
 * @return list
 */
public static List<String> searchForESLintRCFiles(final File projectRoot) {
    FilenameFilter filter = new FilenameFilter() {
        @Override
        public boolean accept(File file, String name) {
            return name.equals(ESLINTRC) || name.startsWith(ESLINTRC + '.');
        }
    };
    // return Arrays.asList(files);
    List<String> files = FileUtils.recursiveVisitor(projectRoot, filter);
    return ContainerUtil.map(files, new Function<String, String>() {
        public String fun(String curFile) {
            return FileUtils.makeRelative(projectRoot, new File(curFile));
        }
    });
}
 
Example 3
Source Project: sass-lint-plugin   Source File: SassLintSettingsPage.java    License: MIT License 5 votes vote down vote up
private void configLintBinField() {
    configWithDefaults(sasslintBinField);
    SwingHelper.addHistoryOnExpansion(sasslintBinField.getChildComponent(), new NotNullProducer<List<String>>() {
        @NotNull
        public List<String> produce() {
            List<File> newFiles = SassLintFinder.searchForSassLintExe(getProjectPath());
            return FileUtils.toAbsolutePath(newFiles);
        }
    });
    SwingHelper.installFileCompletionAndBrowseDialog(project, sasslintBinField, "Select Sass Lint Exe", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor());
}
 
Example 4
Source Project: sass-lint-plugin   Source File: SassLintSettingsPage.java    License: MIT License 5 votes vote down vote up
private void configNodeField() {
    TextFieldWithHistory textFieldWithHistory = configWithDefaults(nodeInterpreterField);
    SwingHelper.addHistoryOnExpansion(textFieldWithHistory, new NotNullProducer<List<String>>() {
        @NotNull
        public List<String> produce() {
            List<File> newFiles = NodeDetectionUtil.listAllPossibleNodeInterpreters();
            return FileUtils.toAbsolutePath(newFiles);
        }
    });
    SwingHelper.installFileCompletionAndBrowseDialog(project, nodeInterpreterField, "Select Node Interpreter", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor());
}
 
Example 5
Source Project: sass-lint-plugin   Source File: SassLintFinder.java    License: MIT License 5 votes vote down vote up
/**
 * find possible sasslint rc files
 * @param projectRoot
 * @return
 */
public static List<String> searchForConfigFiles(final File projectRoot) {
    FilenameFilter filter = new FilenameFilter() {
        @Override
        public boolean accept(File file, String name) {
            return name.equals(SassLintConfigFileUtil.SASS_LINT_CONFIG);
        }
    };
    List<String> files = FileUtils.recursiveVisitor(projectRoot, filter);
    return ContainerUtil.map(files, new Function<String, String>() {
        public String fun(String curFile) {
            return FileUtils.makeRelative(projectRoot, new File(curFile));
        }
    });
}
 
Example 6
Source Project: react-templates-plugin   Source File: RTSettingsPage.java    License: MIT License 5 votes vote down vote up
private void configRTBinField() {
    configWithDefaults(rtBinField);
    SwingHelper.addHistoryOnExpansion(rtBinField.getChildComponent(), new NotNullProducer<List<String>>() {
        @NotNull
        public List<String> produce() {
            List<File> newFiles = RTFinder.searchForRTBin(getProjectPath());
            return FileUtils.toAbsolutePath(newFiles);
        }
    });
    SwingHelper.installFileCompletionAndBrowseDialog(project, rtBinField, "Select React-Templates Cli", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor());
}
 
Example 7
Source Project: react-templates-plugin   Source File: RTSettingsPage.java    License: MIT License 5 votes vote down vote up
private void configNodeField() {
    TextFieldWithHistory textFieldWithHistory = configWithDefaults(nodeInterpreterField);
    SwingHelper.addHistoryOnExpansion(textFieldWithHistory, new NotNullProducer<List<String>>() {
        @NotNull
        public List<String> produce() {
            List<File> newFiles = NodeDetectionUtil.listAllPossibleNodeInterpreters();
            return FileUtils.toAbsolutePath(newFiles);
        }
    });
    SwingHelper.installFileCompletionAndBrowseDialog(project, nodeInterpreterField, "Select Node Interpreter", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor());
}
 
Example 8
Source Project: jscs-plugin   Source File: JscsSettingsPage.java    License: MIT License 5 votes vote down vote up
private void configBinField() {
    configWithDefaults(jscsBinField);
    SwingHelper.addHistoryOnExpansion(jscsBinField.getChildComponent(), new NotNullProducer<List<String>>() {
        @NotNull
        public List<String> produce() {
            List<File> newFiles = JscsFinder.searchForJscsBin(getProjectPath());
            return FileUtils.toAbsolutePath(newFiles);
        }
    });
    SwingHelper.installFileCompletionAndBrowseDialog(project, jscsBinField, "Select jscs.js cli", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor());
}
 
Example 9
Source Project: jscs-plugin   Source File: JscsSettingsPage.java    License: MIT License 5 votes vote down vote up
private void configNodeField() {
    TextFieldWithHistory textFieldWithHistory = configWithDefaults(nodeInterpreterField);
    SwingHelper.addHistoryOnExpansion(textFieldWithHistory, new NotNullProducer<List<String>>() {
        @NotNull
        public List<String> produce() {
            List<File> newFiles = NodeDetectionUtil.listAllPossibleNodeInterpreters();
            return FileUtils.toAbsolutePath(newFiles);
        }
    });
    SwingHelper.installFileCompletionAndBrowseDialog(project, nodeInterpreterField, "Select Node interpreter", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor());
}
 
Example 10
Source Project: jscs-plugin   Source File: JscsFinder.java    License: MIT License 5 votes vote down vote up
public static List<String> tryFindRulesAsString(final File projectRoot) {
        List<File> files = tryFindRules(projectRoot);
        return ContainerUtil.map(files, new Function<File, String>() {
            public String fun(File file) {
//                return FileUtils.makeRelative(projectRoot, file);
                return FileUtil.isAncestor(projectRoot, file, true) ? FileUtils.makeRelative(projectRoot, file) : file.toString();
            }
        });
    }
 
Example 11
Source Project: react-templates-plugin   Source File: RTSettingsPage.java    License: MIT License 5 votes vote down vote up
private void configRTBinField() {
    configWithDefaults(rtBinField);
    SwingHelper.addHistoryOnExpansion(rtBinField.getChildComponent(), new NotNullProducer<List<String>>() {
        @NotNull
        public List<String> produce() {
            List<File> newFiles = RTFinder.searchForRTBin(getProjectPath());
            return FileUtils.toAbsolutePath(newFiles);
        }
    });
    SwingHelper.installFileCompletionAndBrowseDialog(project, rtBinField, "Select React-Templates Cli", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor());
}
 
Example 12
Source Project: react-templates-plugin   Source File: RTSettingsPage.java    License: MIT License 5 votes vote down vote up
private void configNodeField() {
    TextFieldWithHistory textFieldWithHistory = configWithDefaults(nodeInterpreterField);
    SwingHelper.addHistoryOnExpansion(textFieldWithHistory, new NotNullProducer<List<String>>() {
        @NotNull
        public List<String> produce() {
            List<File> newFiles = NodeDetectionUtil.listAllPossibleNodeInterpreters();
            return FileUtils.toAbsolutePath(newFiles);
        }
    });
    SwingHelper.installFileCompletionAndBrowseDialog(project, nodeInterpreterField, "Select Node Interpreter", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor());
}
 
Example 13
Source Project: eslint-plugin   Source File: ESLintFinder.java    License: MIT License 5 votes vote down vote up
public static List<String> tryFindRulesAsString(final File projectRoot) {
        List<File> files = tryFindRules(projectRoot);
        return ContainerUtil.map(files, new Function<File, String>() {
            public String fun(File file) {
//                return FileUtils.makeRelative(projectRoot, file);
                if (projectRoot != null && FileUtil.isAncestor(projectRoot, file, true)) {
                    return FileUtils.makeRelative(projectRoot, file);
                }
                return file.toString();
            }
        });
    }
 
Example 14
Source Project: eslint-plugin   Source File: ESLintSettingsPage.java    License: MIT License 5 votes vote down vote up
private void configESLintBinField() {
    configWithDefaults(eslintBinField2);
    SwingHelper.addHistoryOnExpansion(eslintBinField2.getChildComponent(), new NotNullProducer<List<String>>() {
        @NotNull
        public List<String> produce() {
            List<File> newFiles = ESLintFinder.searchForESLintBin(getProjectPath());
            return FileUtils.toAbsolutePath(newFiles);
        }
    });
    SwingHelper.installFileCompletionAndBrowseDialog(project, eslintBinField2, "Select ESLint.js Cli", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor());
}
 
Example 15
Source Project: eslint-plugin   Source File: ESLintSettingsPage.java    License: MIT License 5 votes vote down vote up
private void configNodeField() {
    TextFieldWithHistory textFieldWithHistory = configWithDefaults(nodeInterpreterField);
    SwingHelper.addHistoryOnExpansion(textFieldWithHistory, new NotNullProducer<List<String>>() {
        @NotNull
        public List<String> produce() {
            List<File> newFiles = NodeDetectionUtil.listAllPossibleNodeInterpreters();
            return FileUtils.toAbsolutePath(newFiles);
        }
    });
    SwingHelper.installFileCompletionAndBrowseDialog(project, nodeInterpreterField, "Select Node Interpreter", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor());
}
 
Example 16
Source Project: sass-lint-plugin   Source File: SassLintExternalAnnotator.java    License: MIT License 4 votes vote down vote up
@Nullable
@Override
public ExternalLintAnnotationResult<LintResult> doAnnotate(ExternalLintAnnotationInput collectedInfo) {
    ActualFile2 actualCodeFile = null;
    try {
        PsiFile file = collectedInfo.psiFile;
        if (!SassLintConfigFileUtil.isSassFile(file)) return null;
        SassLintProjectComponent component = file.getProject().getComponent(SassLintProjectComponent.class);
        if (!component.isSettingsValid() || !component.isEnabled()) {
            return null;
        }

        SassLintConfigFileListener.start(collectedInfo.project);
        String relativeFile;
        actualCodeFile = ActualFile2.getOrCreateActualFile(SASS_LINT_TEMP_FILE, file, collectedInfo.fileContent);
        if (actualCodeFile == null || actualCodeFile.getActualFile() == null) {
            return null;
        }
        relativeFile = FileUtils.makeRelative(new File(file.getProject().getBasePath()), actualCodeFile.getActualFile());
        if (relativeFile == null) {
            LOG.error("Error running Sass Lint inspection: relative file path is null");
            return null;
        }
        LintResult result = SassLintRunner.lint(file.getProject().getBasePath(), relativeFile, component.nodeInterpreter, component.lintExecutable, component.configFile, component.customRulesPath, component.extensions);

        actualCodeFile.deleteTemp();
        if (StringUtils.isNotEmpty(result.errorOutput)) {
            component.showInfoNotification(result.errorOutput, NotificationType.WARNING);
            return null;
        }
        Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
        if (document == null) {
            component.showInfoNotification("Error running Sass Lint inspection: Could not get document for file " + file.getName(), NotificationType.WARNING);
            LOG.error("Could not get document for file " + file.getName());
            return null;
        }
        return new ExternalLintAnnotationResult<LintResult>(collectedInfo, result);
    } catch (Exception e) {
        LOG.error("Error running Sass Lint inspection: ", e);
        showNotification("Error running Sass Lint inspection: " + e.getMessage(), NotificationType.ERROR);
    } finally {
        if (actualCodeFile != null) {
            actualCodeFile.deleteTemp();
        }
    }
    return null;
}
 
Example 17
Source Project: react-templates-plugin   Source File: RTExternalAnnotator.java    License: MIT License 4 votes vote down vote up
@Nullable
    @Override
    public ExternalLintAnnotationResult<Result> doAnnotate(ExternalLintAnnotationInput collectedInfo) {
        ActualFile actualCodeFile = null;
        try {
            PsiFile file = collectedInfo.psiFile;
            if (!RTFileUtil.isRTFile(file)) return null;
            Project project = file.getProject();
            RTProjectComponent component = project.getComponent(RTProjectComponent.class);
            if (component == null || !component.isValidAndEnabled()) {
                return null;
            }

            String relativeFile;
            actualCodeFile = ActualFile.getOrCreateActualFile(RT_TEMP_FILE_KEY, file.getVirtualFile(), collectedInfo.fileContent);
            if (actualCodeFile == null || actualCodeFile.getActualFile() == null) {
                return null;
            }
            relativeFile = FileUtils.makeRelative(new File(project.getBasePath()), actualCodeFile.getActualFile());
            RTSettings settings = RTSettings.buildSettings(component.settings, project.getBasePath(), relativeFile);
            Result result = RTRunner.INSTANCE.compile(settings);

            if (StringUtils.isNotEmpty(result.getErrorOutput())) {
                component.showInfoNotification(result.getErrorOutput(), NotificationType.WARNING);
                return null;
            }
            Document document = PsiDocumentManager.getInstance(project).getDocument(file);
            if (document == null) {
                component.showInfoNotification("Error running RT inspection: Could not get document for file " + file.getName(), NotificationType.WARNING);
                LOG.error("Could not get document for file " + file.getName());
                return null;
            }
            return new ExternalLintAnnotationResult<Result>(collectedInfo, result);
        } catch (Exception e) {
            LOG.error("Error running RT inspection: ", e);
            showNotification("Error running RT inspection: " + e.getMessage(), NotificationType.ERROR);
//            return new ExternalLintAnnotationResult<Result>(collectedInfo, result); file level annotation
        } finally {
            if (actualCodeFile != null) {
                actualCodeFile.deleteTemp();
            }
        }
        return null;
    }
 
Example 18
Source Project: react-templates-plugin   Source File: RTExternalAnnotator.java    License: MIT License 4 votes vote down vote up
@Nullable
    @Override
    public ExternalLintAnnotationResult<Result> doAnnotate(ExternalLintAnnotationInput collectedInfo) {
        ActualFile actualCodeFile = null;
        try {
            PsiFile file = collectedInfo.psiFile;
            if (!RTFileUtil.isRTFile(file)) return null;
            Project project = file.getProject();
            RTProjectComponent component = project.getComponent(RTProjectComponent.class);
            if (component == null || !component.isValidAndEnabled()) {
                return null;
            }

            String relativeFile;
            actualCodeFile = ActualFile.getOrCreateActualFile(RT_TEMP_FILE_KEY, file.getVirtualFile(), collectedInfo.fileContent);
            if (actualCodeFile == null || actualCodeFile.getActualFile() == null) {
                return null;
            }
            relativeFile = FileUtils.makeRelative(new File(project.getBasePath()), actualCodeFile.getActualFile());
            RTSettings settings = RTSettings.buildSettings(component.settings, project.getBasePath(), relativeFile);
            Result result = RTRunner.INSTANCE.compile(settings);

            if (StringUtils.isNotEmpty(result.getErrorOutput())) {
                component.showInfoNotification(result.getErrorOutput(), NotificationType.WARNING);
                return null;
            }
            Document document = PsiDocumentManager.getInstance(project).getDocument(file);
            if (document == null) {
                component.showInfoNotification("Error running RT inspection: Could not get document for file " + file.getName(), NotificationType.WARNING);
                LOG.error("Could not get document for file " + file.getName());
                return null;
            }
            return new ExternalLintAnnotationResult<Result>(collectedInfo, result);
        } catch (Exception e) {
            LOG.error("Error running RT inspection: ", e);
            showNotification("Error running RT inspection: " + e.getMessage(), NotificationType.ERROR);
//            return new ExternalLintAnnotationResult<Result>(collectedInfo, result); file level annotation
        } finally {
            if (actualCodeFile != null) {
                actualCodeFile.deleteTemp();
            }
        }
        return null;
    }
 
Example 19
Source Project: eslint-plugin   Source File: ESLintExternalAnnotator.java    License: MIT License 4 votes vote down vote up
@Nullable
    @Override
    public ExternalLintAnnotationResult<Result> doAnnotate(ExternalLintAnnotationInput collectedInfo) {
        try {
            LOG.info("Running ESLint inspection");
            PsiFile file = collectedInfo.psiFile;
            Project project = file.getProject();
            ESLintProjectComponent component = project.getComponent(ESLintProjectComponent.class);
            if (!component.isSettingsValid() || !component.isEnabled() || !isJavaScriptFile(file, component.ext)) {
                return null;
            }
            ESLintConfigFileListener.start(collectedInfo.project);
            String relativeFile;
            ActualFile actualCodeFile = ActualFile.getOrCreateActualFile(ESLINT_TEMP_FILE_KEY, file.getVirtualFile(), collectedInfo.fileContent);
            if (actualCodeFile == null || actualCodeFile.getFile() == null) {
                return null;
            }
            relativeFile = FileUtils.makeRelative(new File(project.getBasePath()), actualCodeFile.getActualFile());
            Result result = ESLintRunner.lint(project.getBasePath(), relativeFile, component);

            if (component.settings.autoFix) {
//            Document document = PsiDocumentManager.getInstance(project).getDocument(file);
//            document.
//            Document document = PsiDocumentManager.getInstance(project).getDocument(file);
                // read lock
//            ApplicationManager.getApplication().runWriteAction()
//            ApplicationManager.getApplication().runWriteAction()
                ApplicationManager.getApplication().invokeLater(new Runnable() {
                    public void run() {
                        file.getVirtualFile().refresh(false, false);
                    }
                }, ModalityState.NON_MODAL);

//            WriteAction.run(() -> file.getVirtualFile().refresh(false, false));
//            UIUtil.invokeLaterIfNeeded(new Runnable() {
//                public void run() {
//                    file.getVirtualFile().refresh(false, false);
//                }
//            });
            }

            actualCodeFile.deleteTemp();
            if (StringUtils.isNotEmpty(result.errorOutput)) {
                component.showInfoNotification(result.errorOutput, NotificationType.WARNING);
                return null;
            }
            Document document = PsiDocumentManager.getInstance(project).getDocument(file);
            if (document == null) {
                component.showInfoNotification("Error running ESLint inspection: Could not get document for file " + file.getName(), NotificationType.WARNING);
                LOG.error("Could not get document for file " + file.getName());
                return null;
            }
            return new ExternalLintAnnotationResult<>(collectedInfo, result);
        } catch (Exception e) {
            LOG.error("Error running ESLint inspection: ", e);
            ESLintProjectComponent.showNotification("Error running ESLint inspection: " + e.getMessage(), NotificationType.ERROR);
        }
        return null;
    }
 
Example 20
Source Project: eslint-plugin   Source File: RuleCache.java    License: MIT License 4 votes vote down vote up
public static void initializeFromPath(Project project, ESLintProjectComponent component) {
//        ESLintProjectComponent component = project.getComponent(ESLintProjectComponent.class);
        String absRulesPath = FileUtils.resolvePath(project, component.customRulesPath);
        initializeFromPaths(component.rulesPath, absRulesPath);
    }