diff --git a/src/main/java/com/leinardi/pycharm/pylint/PylintConfigurable.java b/src/main/java/com/leinardi/pycharm/pylint/PylintConfigurable.java index 7251c0a..6a25aaf 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/PylintConfigurable.java +++ b/src/main/java/com/leinardi/pycharm/pylint/PylintConfigurable.java @@ -31,29 +31,17 @@ public class PylintConfigurable implements Configurable { private static final Logger LOG = Logger.getInstance(PylintConfigurable.class); - private final Project project; - private final PylintConfigPanel configPanel; private final PylintConfigService pylintConfigService; - // private final PylintProjectService pylintProjectService; - // private final PluginConfigurationManager pluginConfigurationManager; - public PylintConfigurable(@NotNull final Project project/*, - @NotNull final PylintProjectService pylintProjectService, - @NotNull final PluginConfigurationManager pluginConfigurationManager*/) { - this(project, new PylintConfigPanel(project/*, pylintProjectService*/)/*, - pylintProjectService, pluginConfigurationManager*/); + public PylintConfigurable(@NotNull final Project project) { + this(project, new PylintConfigPanel(project)); } PylintConfigurable(@NotNull final Project project, - @NotNull final PylintConfigPanel configPanel/*, - @NotNull final PylintProjectService pylintProjectService, - @NotNull final PluginConfigurationManager pluginConfigurationManager*/) { - this.project = project; + @NotNull final PylintConfigPanel configPanel) { this.configPanel = configPanel; pylintConfigService = PylintConfigService.getInstance(project); - // this.pylintProjectService = pylintProjectService; - // this.pluginConfigurationManager = pluginConfigurationManager; } @Override @@ -74,12 +62,6 @@ public JComponent createComponent() { @Override public boolean isModified() { - // final PluginConfiguration oldConfig = pluginConfigurationManager.getCurrent(); - // final PluginConfiguration newConfig = PluginConfigurationBuilder - // .from(configPanel.getPluginConfiguration()) - // .withScanBeforeCheckin(oldConfig.isScanBeforeCheckin()) - // .build(); - // boolean result = !configPanel.getPathToPylint().equals(pylintConfigService.getPathToPylint()); if (LOG.isDebugEnabled()) { LOG.debug("Has config changed? " + result); @@ -89,37 +71,9 @@ public boolean isModified() { @Override public void apply() { - // final PluginConfiguration newConfig = PluginConfigurationBuilder.from(configPanel - // .getPluginConfiguration()) - // .withScanBeforeCheckin(pluginConfigurationManager.getCurrent().isScanBeforeCheckin()) - // .build(); - // pluginConfigurationManager.setCurrent(newConfig, true); - // - // activateCurrentPylintVersion(newConfig.getPylintVersion(), newConfig.getThirdPartyClasspath()); - // if (!newConfig.isCopyLibs()) { - // new TempDirProvider().deleteCopiedLibrariesDir(project); - // } pylintConfigService.setPathToPylint(configPanel.getPathToPylint()); } - // private void activateCurrentPylintVersion(final String pylintVersion, - // final List thirdPartyClasspath) { - // // Invalidate cache *before* activating the new Pylint version - // getCheckerFactoryCache().invalidate(); - // - // pylintProjectService.activatePylintVersion(pylintVersion, thirdPartyClasspath); - // } - // - // private CheckerFactoryCache getCheckerFactoryCache() { - // return ServiceManager.getService(project, CheckerFactoryCache.class); - // } - // - // public void reset() { - // final PluginConfiguration pluginConfig = pluginConfigurationManager.getCurrent(); - // configPanel.showPluginConfiguration(pluginConfig); - // - // activateCurrentPylintVersion(pluginConfig.getPylintVersion(), pluginConfig.getThirdPartyClasspath()); - // } @Override public void disposeUIResources() { // do nothing diff --git a/src/main/java/com/leinardi/pycharm/pylint/PylintInspection.java b/src/main/java/com/leinardi/pycharm/pylint/PylintInspection.java index 7c1a95d..78710db 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/PylintInspection.java +++ b/src/main/java/com/leinardi/pycharm/pylint/PylintInspection.java @@ -20,8 +20,6 @@ import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleUtil; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiFile; @@ -72,16 +70,10 @@ public JComponent createOptionsPanel() { public ProblemDescriptor[] checkFile(@NotNull final PsiFile psiFile, @NotNull final InspectionManager manager, final boolean isOnTheFly) { - // final Module module = moduleOf(psiFile); - return asProblemDescriptors(asyncResultOf(() -> inspectFile(psiFile, /*module, */manager), NO_PROBLEMS_FOUND), + return asProblemDescriptors(asyncResultOf(() -> inspectFile(psiFile, manager), NO_PROBLEMS_FOUND), manager); } - @Nullable - private Module moduleOf(@NotNull final PsiFile psiFile) { - return ModuleUtil.findModuleForPsiElement(psiFile); - } - @Nullable public List inspectFile(@NotNull final PsiFile psiFile, // @Nullable final Module module, @@ -90,15 +82,9 @@ public List inspectFile(@NotNull final PsiFile psiFile, final PylintPlugin plugin = plugin(manager.getProject()); - // ConfigurationLocation configurationLocation = null; final List scannableFiles = new ArrayList<>(); try { - // configurationLocation = plugin.getConfigurationLocation(module, null); - // if (configurationLocation == null || configurationLocation.isBlacklisted()) { - // return NO_PROBLEMS_FOUND; - // } - - scannableFiles.addAll(ScannableFile.createAndValidate(singletonList(psiFile), plugin/*, module*/)); + scannableFiles.addAll(ScannableFile.createAndValidate(singletonList(psiFile), plugin)); ScanFiles scanFiles = new ScanFiles(plugin, Collections.singletonList(psiFile.getVirtualFile())); Map> map = scanFiles.call(); if (map.isEmpty()) { @@ -115,7 +101,7 @@ public List inspectFile(@NotNull final PsiFile psiFile, return NO_PROBLEMS_FOUND; } catch (Throwable e) { - handlePluginException(e, psiFile, /*plugin, configurationLocation,*/ manager.getProject()); + handlePluginException(e, psiFile, manager.getProject()); return NO_PROBLEMS_FOUND; } finally { @@ -123,43 +109,18 @@ public List inspectFile(@NotNull final PsiFile psiFile, } } - // private List dropIgnoredProblems(final List problems) { - // return problems.stream() - // .filter(problem -> problem.severityLevel() != SeverityLevel.Ignore) - // .collect(toList()); - // } - private void handlePluginException(final Throwable e, final @NotNull PsiFile psiFile, - // final PylintPlugin plugin, - // final ConfigurationLocation - // configurationLocation, final @NotNull Project project) { - // if (e.getCause() != null && e.getCause() instanceof FileNotFoundException) { - // disableActiveConfiguration(plugin, project); - // } else if (e.getCause() != null && e.getCause() instanceof IOException) { showWarning(project, message("pylint.file-io-failed")); - // blacklist(configurationLocation); } else { LOG.warn("Pylint threw an exception when scanning: " + psiFile.getName(), e); showException(project, e); - // blacklist(configurationLocation); } } - // private void disableActiveConfiguration(final PylintPlugin plugin, final Project project) { - // plugin.configurationManager().disableActiveConfiguration(); - // showWarning(project, message("pylint.configuration-disabled.file-not-found")); - // } - - // private void blacklist(final ConfigurationLocation configurationLocation) { - // if (configurationLocation != null) { - // configurationLocation.blacklist(); - // } - // } - @NotNull private ProblemDescriptor[] asProblemDescriptors(final List results, final InspectionManager manager) { return ofNullable(results) @@ -168,9 +129,4 @@ private ProblemDescriptor[] asProblemDescriptors(final List results, fi .toArray(ProblemDescriptor[]::new)) .orElseGet(() -> ProblemDescriptor.EMPTY_ARRAY); } - - // private CheckerFactory checkerFactory(final Project project) { - // return ServiceManager.getService(project, CheckerFactory.class); - // } - } diff --git a/src/main/java/com/leinardi/pycharm/pylint/PylintPlugin.java b/src/main/java/com/leinardi/pycharm/pylint/PylintPlugin.java index bde1583..55703bf 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/PylintPlugin.java +++ b/src/main/java/com/leinardi/pycharm/pylint/PylintPlugin.java @@ -16,11 +16,8 @@ package com.leinardi.pycharm.pylint; -import com.intellij.ide.plugins.IdeaPluginDescriptor; -import com.intellij.ide.plugins.PluginManager; import com.intellij.openapi.components.ProjectComponent; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; @@ -53,23 +50,18 @@ public final class PylintPlugin implements ProjectComponent { */ public static final String ID_PLUGIN = "Pylint-PyCharm"; -// public static final String ID_MODULE_PLUGIN = "Pylint-PyCharm-Module"; - private static final Logger LOG = com.intellij.openapi.diagnostic.Logger.getInstance(PylintPlugin.class); private final Set> checksInProgress = new HashSet<>(); private final Project project; - // private final PluginConfigurationManager configurationManager; /** * Construct a plug-in instance for the given project. * * @param project the current project. */ - public PylintPlugin(@NotNull final Project project - /*, @NotNull final PluginConfigurationManager configurationManager*/) { + public PylintPlugin(@NotNull final Project project) { this.project = project; - // this.configurationManager = configurationManager; LOG.info("Pylint Plugin loaded with project base dir: \"" + getProjectPath() + "\""); @@ -89,15 +81,6 @@ private File getProjectPath() { return new File(baseDir.getPath()); } - // /** - // * Get the plugin configuration. - // * - // * @return the plug-in configuration. - // */ - // public PluginConfigurationManager configurationManager() { - // return configurationManager; - // } - /** * Is a scan in progress? *

@@ -114,41 +97,13 @@ public boolean isScanInProgress() { @Override public void projectOpened() { LOG.debug("Project opened."); - // notifyUserIfPluginUpdated(); - } - - // private void notifyUserIfPluginUpdated() { - // if (!Objects.equals(currentPluginVersion(), lastActivePluginVersion())) { - // Notifications.showInfo(project, message("plugin.update", currentPluginVersion())); - // configurationManager.setCurrent(PluginConfigurationBuilder.from(configurationManager.getCurrent()) - // .withLastActivePluginVersion(currentPluginVersion()) - // .build(), false); - // } - // } - - // private String lastActivePluginVersion() { - // return configurationManager.getCurrent().getLastActivePluginVersion(); - // } - - public static String currentPluginVersion() { - final IdeaPluginDescriptor plugin = PluginManager.getPlugin(PluginId.getId(ID_PLUGIN)); - if (plugin != null) { - return plugin.getVersion(); - } - return "unknown"; } @Override public void projectClosed() { LOG.debug("Project closed; invalidating checkers."); - - // invalidateCheckerCache(); } - // private void invalidateCheckerCache() { - // ServiceManager.getService(project, CheckerFactoryCache.class).invalidate(); - // } - @Override @NotNull public String getComponentName() { @@ -194,8 +149,7 @@ public void checkComplete(final Future task) { } @SuppressWarnings("FutureReturnValueIgnored") - public void asyncScanFiles(final List files/*, final ConfigurationLocation - overrideConfigLocation*/) { + public void asyncScanFiles(final List files) { LOG.info("Scanning current file(s)."); if (files == null || files.isEmpty()) { @@ -203,7 +157,7 @@ public void asyncScanFiles(final List files/*, final ConfigurationL return; } - final ScanFiles checkFiles = new ScanFiles(this, files/*, overrideConfigLocation*/); + final ScanFiles checkFiles = new ScanFiles(this, files); checkFiles.addListener(new UiFeedbackScannerListener(this)); runAsyncCheck(checkFiles); } @@ -214,7 +168,7 @@ public Map> scanFiles(@NotNull final List fi } try { - return whenFinished(runAsyncCheck(new ScanFiles(this, files/*, null*/))).get(); + return whenFinished(runAsyncCheck(new ScanFiles(this, files))).get(); } catch (final Throwable e) { LOG.warn("ERROR scanning files", e); return Collections.emptyMap(); @@ -228,27 +182,6 @@ private Future>> runAsyncCheck(final ScanFiles checke return checkFilesFuture; } - // public ConfigurationLocation getConfigurationLocation(@Nullable final Module module, @Nullable final - // ConfigurationLocation override) { - // if (override != null) { - // return override; - // } - // - // if (module != null) { - // final PylintModuleConfiguration moduleConfiguration = ModuleServiceManager.getService(module, - // PylintModuleConfiguration.class); - // if (moduleConfiguration == null) { - // throw new IllegalStateException("Couldn't get pylint module configuration"); - // } - // - // if (moduleConfiguration.isExcluded()) { - // return null; - // } - // return moduleConfiguration.getActiveConfiguration(); - // } - // return configurationManager().getCurrent().getActiveLocation(); - // } - private class ScanCompletionTracker implements ScannerListener { private final Future>> future; diff --git a/src/main/java/com/leinardi/pycharm/pylint/actions/BaseAction.java b/src/main/java/com/leinardi/pycharm/pylint/actions/BaseAction.java index 3d22d14..d81e467 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/actions/BaseAction.java +++ b/src/main/java/com/leinardi/pycharm/pylint/actions/BaseAction.java @@ -94,20 +94,11 @@ protected void setProgressText(final ToolWindow toolWindow, final String progres } } - // protected ConfigurationLocation getSelectedOverride(final ToolWindow toolWindow) { - // final Content content = toolWindow.getContentManager().getContent(0); - // // the content instance will be a JLabel while the component initialises - // if (content != null && content.getComponent() instanceof PylintToolWindowPanel) { - // return ((PylintToolWindowPanel) content.getComponent()).getSelectedOverride(); - // } - // return null; - // } - protected Optional project(@NotNull final AnActionEvent event) { return ofNullable(PROJECT.getData(event.getDataContext())); } - protected boolean containsAtLeastOneFile(@NotNull final VirtualFile... files) { + boolean containsAtLeastOneFile(@NotNull final VirtualFile... files) { boolean result = false; for (VirtualFile file : files) { if ((file.isDirectory() && containsAtLeastOneFile(file.getChildren())) || (!file.isDirectory() && file diff --git a/src/main/java/com/leinardi/pycharm/pylint/actions/ScanCurrentChangeList.java b/src/main/java/com/leinardi/pycharm/pylint/actions/ScanCurrentChangeList.java index 16d51a2..9961f2b 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/actions/ScanCurrentChangeList.java +++ b/src/main/java/com/leinardi/pycharm/pylint/actions/ScanCurrentChangeList.java @@ -25,10 +25,7 @@ import com.intellij.openapi.vcs.changes.ChangeListManager; import com.intellij.openapi.vcs.changes.LocalChangeList; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.wm.ToolWindow; -import com.intellij.openapi.wm.ToolWindowManager; import com.leinardi.pycharm.pylint.PylintPlugin; -import com.leinardi.pycharm.pylint.toolwindow.PylintToolWindowPanel; import com.leinardi.pycharm.pylint.util.VfUtil; import java.util.ArrayList; @@ -46,21 +43,17 @@ public class ScanCurrentChangeList extends BaseAction { @Override public final void actionPerformed(final AnActionEvent event) { - Project project = null; + Project project; try { project = PlatformDataKeys.PROJECT.getData(event.getDataContext()); if (project == null) { return; } - final ToolWindow toolWindow = ToolWindowManager.getInstance(project) - .getToolWindow(PylintToolWindowPanel.ID_TOOLWINDOW); - final ChangeListManager changeListManager = ChangeListManager.getInstance(project); project.getComponent(PylintPlugin.class) .asyncScanFiles(VfUtil.filterOnlyPythonProjectFiles(project, - filesFor(changeListManager.getDefaultChangeList())) - /*, getSelectedOverride(toolWindow)*/); + filesFor(changeListManager.getDefaultChangeList()))); } catch (Throwable e) { LOG.warn("Modified files scan failed", e); } @@ -85,7 +78,7 @@ private List filesFor(final LocalChangeList changeList) { public void update(final AnActionEvent event) { super.update(event); - Project project = null; + Project project; try { project = PlatformDataKeys.PROJECT.getData(event.getDataContext()); if (project == null) { // check if we're loading... @@ -100,7 +93,7 @@ public void update(final AnActionEvent event) { final Presentation presentation = event.getPresentation(); final LocalChangeList changeList = ChangeListManager.getInstance(project).getDefaultChangeList(); - if (changeList == null || changeList.getChanges() == null || changeList.getChanges().size() == 0) { + if (changeList.getChanges() == null || changeList.getChanges().size() == 0) { presentation.setEnabled(false); } else { presentation.setEnabled(!pylintPlugin.isScanInProgress()); diff --git a/src/main/java/com/leinardi/pycharm/pylint/actions/ScanCurrentFile.java b/src/main/java/com/leinardi/pycharm/pylint/actions/ScanCurrentFile.java index c5b95a0..f28ce39 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/actions/ScanCurrentFile.java +++ b/src/main/java/com/leinardi/pycharm/pylint/actions/ScanCurrentFile.java @@ -30,7 +30,7 @@ import com.leinardi.pycharm.pylint.toolwindow.PylintToolWindowPanel; import com.leinardi.pycharm.pylint.util.FileTypes; -import java.util.Arrays; +import java.util.Collections; /** * Action to execute a Pylint scan on the current editor file. @@ -50,7 +50,6 @@ public void actionPerformed(final AnActionEvent event) { if (pylintPlugin == null) { throw new IllegalStateException("Couldn't get pylint plugin"); } - // final ScanScope scope = pylintPlugin.configurationManager().getCurrent().getScanScope(); final ToolWindow toolWindow = ToolWindowManager.getInstance( project).getToolWindow(PylintToolWindowPanel.ID_TOOLWINDOW); @@ -58,10 +57,10 @@ public void actionPerformed(final AnActionEvent event) { try { setProgressText(toolWindow, "plugin.status.in-progress.current"); - final VirtualFile selectedFile = getSelectedFile(project/*, scope*/); + final VirtualFile selectedFile = getSelectedFile(project); if (selectedFile != null) { project.getComponent(PylintPlugin.class).asyncScanFiles( - Arrays.asList(selectedFile)/*, getSelectedOverride(toolWindow)*/); + Collections.singletonList(selectedFile)); } } catch (Throwable e) { @@ -74,7 +73,7 @@ public void actionPerformed(final AnActionEvent event) { } } - private VirtualFile getSelectedFile(final Project project /*, final ScanScope scope*/) { + private VirtualFile getSelectedFile(final Project project) { VirtualFile selectedFile = null; @@ -116,9 +115,7 @@ public void update(final AnActionEvent event) { if (pylintPlugin == null) { throw new IllegalStateException("Couldn't get pylint plugin"); } - // final ScanScope scope = pylintPlugin.configurationManager().getCurrent().getScanScope(); - // - final VirtualFile selectedFile = getSelectedFile(project/*, scope*/); + final VirtualFile selectedFile = getSelectedFile(project); // disable if no file is selected or scan in progress final Presentation presentation = event.getPresentation(); diff --git a/src/main/java/com/leinardi/pycharm/pylint/actions/ScanEverythingAction.java b/src/main/java/com/leinardi/pycharm/pylint/actions/ScanEverythingAction.java index f8d62a5..588e50a 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/actions/ScanEverythingAction.java +++ b/src/main/java/com/leinardi/pycharm/pylint/actions/ScanEverythingAction.java @@ -30,23 +30,20 @@ class ScanEverythingAction implements Runnable { private final Project project; private final Module module; - // private final ConfigurationLocation selectedOverride; - ScanEverythingAction(@NotNull final Project project/*, final ConfigurationLocation selectedOverride*/) { + ScanEverythingAction(@NotNull final Project project) { this.project = project; this.module = null; - // this.selectedOverride = selectedOverride; } - ScanEverythingAction(@NotNull final Module module/*, final ConfigurationLocation selectedOverride*/) { + ScanEverythingAction(@NotNull final Module module) { this.project = module.getProject(); this.module = module; - // this.selectedOverride = selectedOverride; } @Override public void run() { - List filesToScan = null; + List filesToScan; if (module != null) { // all non-excluded files of a module final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); @@ -57,6 +54,6 @@ public void run() { } filesToScan = VfUtil.filterOnlyPythonProjectFiles(project, filesToScan); - project.getComponent(PylintPlugin.class).asyncScanFiles(filesToScan/*, selectedOverride*/); + project.getComponent(PylintPlugin.class).asyncScanFiles(filesToScan); } } diff --git a/src/main/java/com/leinardi/pycharm/pylint/actions/ScanModifiedFiles.java b/src/main/java/com/leinardi/pycharm/pylint/actions/ScanModifiedFiles.java index 86a7ada..f51491b 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/actions/ScanModifiedFiles.java +++ b/src/main/java/com/leinardi/pycharm/pylint/actions/ScanModifiedFiles.java @@ -46,13 +46,10 @@ public final void actionPerformed(final AnActionEvent event) { return; } - // final ToolWindow toolWindow = ToolWindowManager.getInstance(project) - // .getToolWindow(PylintToolWindowPanel.ID_TOOLWINDOW); - final ChangeListManager changeListManager = ChangeListManager.getInstance(project); project.getComponent(PylintPlugin.class).asyncScanFiles( VfUtil.filterOnlyPythonProjectFiles(project, changeListManager.getAffectedFiles()) - /*, getSelectedOverride(toolWindow)*/); + ); } catch (Throwable e) { LOG.warn("Modified files scan failed", e); } @@ -62,7 +59,7 @@ public final void actionPerformed(final AnActionEvent event) { public void update(final AnActionEvent event) { super.update(event); - Project project = null; + Project project; try { project = PlatformDataKeys.PROJECT.getData(event.getDataContext()); if (project == null) { // check if we're loading... diff --git a/src/main/java/com/leinardi/pycharm/pylint/actions/ScanModule.java b/src/main/java/com/leinardi/pycharm/pylint/actions/ScanModule.java index 9239e24..823870e 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/actions/ScanModule.java +++ b/src/main/java/com/leinardi/pycharm/pylint/actions/ScanModule.java @@ -69,22 +69,8 @@ public final void actionPerformed(final AnActionEvent event) { List moduleFiles = VfUtil.filterOnlyPythonProjectFiles( project, VfUtil.flattenFiles(new VirtualFile[]{selectedFiles[0].getParent()})); - Runnable scanAction = null; - // if (scope == ScanScope.Everything) { - scanAction = new ScanSourceRootsAction(project, moduleFiles.toArray(new VirtualFile[0])/*, - getSelectedOverride(toolWindow)*/); - // } else { - // final VirtualFile[] moduleSourceRoots = - // ModuleRootManager.getInstance(module).getSourceRoots(scope - // .includeTestClasses()); - // if (moduleSourceRoots.length > 0) { - // scanAction = new ScanSourceRootsAction(project, moduleSourceRoots, - // getSelectedOverride(toolWindow)); - // } - // } - // if (scanAction != null) { + Runnable scanAction = new ScanSourceRootsAction(project, moduleFiles.toArray(new VirtualFile[0])); ApplicationManager.getApplication().runReadAction(scanAction); - // } } catch (Throwable e) { PylintPlugin.processErrorAndLog("Current Module scan", e); } @@ -125,15 +111,10 @@ public final void update(final AnActionEvent event) { if (pylintPlugin == null) { throw new IllegalStateException("Couldn't get pylint plugin"); } - // final ScanScope scope = pylintPlugin.configurationManager().getCurrent().getScanScope(); - VirtualFile[] moduleFiles = null; + VirtualFile[] moduleFiles; final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); - // if (scope == ScanScope.Everything) { moduleFiles = moduleRootManager.getContentRoots(); - // } else { - // moduleFiles = moduleRootManager.getSourceRoots(scope.includeTestClasses()); - // } // disable if no files are selected or scan in progress if (containsAtLeastOneFile(moduleFiles)) { diff --git a/src/main/java/com/leinardi/pycharm/pylint/actions/ScanProject.java b/src/main/java/com/leinardi/pycharm/pylint/actions/ScanProject.java index 0f77f40..fdfa4fc 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/actions/ScanProject.java +++ b/src/main/java/com/leinardi/pycharm/pylint/actions/ScanProject.java @@ -44,7 +44,6 @@ public void actionPerformed(final AnActionEvent event) { if (pylintPlugin == null) { throw new IllegalStateException("Couldn't get pylint plugin"); } - // final ScanScope scope = pylintPlugin.configurationManager().getCurrent().getScanScope(); final ToolWindow toolWindow = ToolWindowManager.getInstance( project).getToolWindow(PylintToolWindowPanel.ID_TOOLWINDOW); @@ -53,7 +52,7 @@ public void actionPerformed(final AnActionEvent event) { setProgressText(toolWindow, "plugin.status.in-progress.project"); Runnable scanAction = null; // if (scope == ScanScope.Everything) { - scanAction = new ScanEverythingAction(project/*, getSelectedOverride(toolWindow)*/); + scanAction = new ScanEverythingAction(project); // } else { // final ProjectRootManager projectRootManager = ProjectRootManager // .getInstance(project); diff --git a/src/main/java/com/leinardi/pycharm/pylint/actions/ScanSourceRootsAction.java b/src/main/java/com/leinardi/pycharm/pylint/actions/ScanSourceRootsAction.java index 1c45ebd..e573710 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/actions/ScanSourceRootsAction.java +++ b/src/main/java/com/leinardi/pycharm/pylint/actions/ScanSourceRootsAction.java @@ -25,21 +25,18 @@ class ScanSourceRootsAction implements Runnable { private final Project project; private final VirtualFile[] sourceRoots; - // private final ConfigurationLocation selectedOverride; ScanSourceRootsAction(@NotNull final Project project, - @NotNull final VirtualFile[] sourceRoots/*, - final ConfigurationLocation selectedOverride*/) { + @NotNull final VirtualFile[] sourceRoots) { this.project = project; this.sourceRoots = sourceRoots; - // this.selectedOverride = selectedOverride; } @Override public void run() { project.getComponent(PylintPlugin.class) .asyncScanFiles(VfUtil.filterOnlyPythonProjectFiles(project, - VfUtil.flattenFiles(sourceRoots)/*, selectedOverride*/)); + VfUtil.flattenFiles(sourceRoots))); } } diff --git a/src/main/java/com/leinardi/pycharm/pylint/checker/CreateScannableFileAction.java b/src/main/java/com/leinardi/pycharm/pylint/checker/CreateScannableFileAction.java index c5a4835..fb21ec9 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/checker/CreateScannableFileAction.java +++ b/src/main/java/com/leinardi/pycharm/pylint/checker/CreateScannableFileAction.java @@ -32,7 +32,6 @@ class CreateScannableFileAction implements Runnable { private IOException failure; private final PsiFile psiFile; - // private final Module module; /** * The created temporary file. @@ -44,10 +43,8 @@ class CreateScannableFileAction implements Runnable { * * @param psiFile the file to read. */ - CreateScannableFileAction(@NotNull final PsiFile psiFile/*, - @Nullable final Module module*/) { + CreateScannableFileAction(@NotNull final PsiFile psiFile) { this.psiFile = psiFile; - // this.module = module; } /** @@ -71,7 +68,7 @@ public ScannableFile getFile() { @Override public void run() { try { - file = new ScannableFile(psiFile/*, module*/); + file = new ScannableFile(psiFile); } catch (IOException e) { failure = e; diff --git a/src/main/java/com/leinardi/pycharm/pylint/checker/Problem.java b/src/main/java/com/leinardi/pycharm/pylint/checker/Problem.java index 16ee530..ad3f679 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/checker/Problem.java +++ b/src/main/java/com/leinardi/pycharm/pylint/checker/Problem.java @@ -98,9 +98,6 @@ public boolean isSuppressErrors() { } private ProblemHighlightType problemHighlightType() { -// if (!suppressErrors) { - // return ProblemHighlightType.ERROR; - // } return ProblemHighlightType.GENERIC_ERROR_OR_WARNING; } diff --git a/src/main/java/com/leinardi/pycharm/pylint/checker/PsiFileValidator.java b/src/main/java/com/leinardi/pycharm/pylint/checker/PsiFileValidator.java index 639aaa8..acc4529 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/checker/PsiFileValidator.java +++ b/src/main/java/com/leinardi/pycharm/pylint/checker/PsiFileValidator.java @@ -36,9 +36,6 @@ public static boolean isScannable(@Nullable final PsiFile psiFile, final Project && hasDocument(psiFile) && isInSource(psiFile, projectFileIndex) && isValidFileType(psiFile); - // && isScannableIfTest(psiFile, pluginConfig) - // && modulesMatch(psiFile, module) - // && !isGenerated(psiFile); } private static boolean hasDocument(final PsiFile psiFile) { @@ -49,41 +46,8 @@ private static boolean isValidFileType(final PsiFile psiFile) { return FileTypes.isPython(psiFile.getFileType()); } - // private static boolean isScannableIfTest(final PsiFile psiFile) { - // return !isTestClass(psiFile); - // } - - // private static boolean isGenerated(final PsiFile psiFile) { - // return PythonProjectRootsUtil.isInGeneratedCode(psiFile.getVirtualFile(), psiFile.getProject()); - // } - private static boolean isInSource(final PsiFile psiFile, final ProjectFileIndex projectFileIndex) { return !projectFileIndex.isExcluded(psiFile.getVirtualFile()); } - // private static boolean isTestClass(final PsiElement element) { - // final VirtualFile elementFile = element.getContainingFile().getVirtualFile(); - // if (elementFile == null) { - // return false; - // } - // - // final Module module = ModuleUtil.findModuleForPsiElement(element); - // if (module == null) { - // return false; - // } - // - // final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); - // return moduleRootManager != null - // && moduleRootManager.getFileIndex().isInTestSourceContent(elementFile); - // } - - // private static boolean modulesMatch(final PsiFile psiFile, - // final Optional module) { - // if (!module.isPresent()) { - // return true; - // } - // final Module elementModule = ModuleUtil.findModuleForPsiElement(psiFile); - // return elementModule != null && elementModule.equals(module.get()); - // } - } diff --git a/src/main/java/com/leinardi/pycharm/pylint/checker/ScanFiles.java b/src/main/java/com/leinardi/pycharm/pylint/checker/ScanFiles.java index ac4f098..34a5765 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/checker/ScanFiles.java +++ b/src/main/java/com/leinardi/pycharm/pylint/checker/ScanFiles.java @@ -32,7 +32,6 @@ import com.leinardi.pycharm.pylint.util.Notifications; import org.jetbrains.annotations.NotNull; -import java.io.File; import java.io.InterruptedIOException; import java.util.ArrayList; import java.util.HashMap; @@ -49,19 +48,14 @@ public class ScanFiles implements Callable>> { private static final Logger LOG = Logger.getInstance(ScanFiles.class); private final List files; - // private final Map> moduleToFiles; private final Set listeners = new HashSet<>(); private final PylintPlugin plugin; - private final int tabWidth = 4; public ScanFiles(@NotNull final PylintPlugin pylintPlugin, - @NotNull final List virtualFiles/*, - @Nullable final ConfigurationLocation overrideConfigLocation*/) { + @NotNull final List virtualFiles) { this.plugin = pylintPlugin; - // this.overrideConfigLocation = overrideConfigLocation; files = findAllFilesFor(virtualFiles); - // moduleToFiles = mapsModulesToFiles(); } private List findAllFilesFor(@NotNull final List virtualFiles) { @@ -73,26 +67,14 @@ private List findAllFilesFor(@NotNull final List virtualFi return childFiles; } - // private Map> mapsModulesToFiles() { - // final Map> modulesToFiles = new HashMap<>(); - // for (final PsiFile file : files) { - // final Module module = ModuleUtil.findModuleForPsiElement(file); - // Set filesForModule = modulesToFiles.computeIfAbsent(module, key -> new HashSet<>()); - // filesForModule.add(file); - // } - // return modulesToFiles; - // } - @Override public final Map> call() { try { fireCheckStarting(files); - // final Pair>> scanResult = - // processFilesForModuleInfoAndScan(); return scanCompletedSuccessfully(checkFiles(new HashSet<>(files))); } catch (final InterruptedIOException e) { LOG.debug("Scan cancelled by PyCharm", e); - return scanCompletedSuccessfully(/*resultOf(PRESENT),*/ emptyMap()); + return scanCompletedSuccessfully(emptyMap()); } catch (final PylintPluginException e) { LOG.warn("An error occurred while scanning a file.", e); return scanFailedWithError(e); @@ -110,13 +92,6 @@ private Map mapFilesToElements(final List filesT return filePathsToElements; } - private String withTrailingSeparator(final String path) { - if (path != null && !path.endsWith(File.separator)) { - return path + File.separator; - } - return path; - } - private Map> checkFiles(final Set filesToScan) throws InterruptedIOException { final List scannableFiles = new ArrayList<>(); try { @@ -132,21 +107,19 @@ private Map> scan(final List filesToScan) Map fileNamesToPsiFiles = mapFilesToElements(filesToScan); List errors = PylintRunner.scan(plugin.getProject(), fileNamesToPsiFiles.keySet()); String baseDir = plugin.getProject().getBasePath(); + int tabWidth = 4; final ProcessResultsThread findThread = new ProcessResultsThread(false, tabWidth, baseDir, errors, fileNamesToPsiFiles); final Application application = ApplicationManager.getApplication(); - // if (application != null) { // can be null in unit tests // TODO Make sure that this does not block ... it seems that we are not starting a new thread. - // Sometimes, the editor is non-responsive because Checkstyle is still processing results. - // Problem: OpScan currently expects the ready-made list of problems synchronously. + // Sometimes, the editor is non-responsive because Pylint is still processing results. if (application.isDispatchThread()) { findThread.run(); } else { application.runReadAction(findThread); } return findThread.getProblems(); - // } } private Map> scanFailedWithError(final PylintPluginException e) { @@ -156,10 +129,8 @@ private Map> scanFailedWithError(final PylintPluginExcept return emptyMap(); } - private Map> scanCompletedSuccessfully(/*final ConfigurationLocationResult - configurationLocationResult,*/ - final Map> filesToProblems) { - fireScanCompletedSuccessfully(/*configurationLocationResult, */filesToProblems); + private Map> scanCompletedSuccessfully(final Map> filesToProblems) { + fireScanCompletedSuccessfully(filesToProblems); return filesToProblems; } @@ -171,9 +142,9 @@ private void fireCheckStarting(final List filesToScan) { listeners.forEach(listener -> listener.scanStarting(filesToScan)); } - private void fireScanCompletedSuccessfully(/*final ConfigurationLocationResult configLocationResult,*/ + private void fireScanCompletedSuccessfully( final Map> fileResults) { - listeners.forEach(listener -> listener.scanCompletedSuccessfully(/*configLocationResult, */fileResults)); + listeners.forEach(listener -> listener.scanCompletedSuccessfully(fileResults)); } private void fireScanFailedWithError(final PylintPluginException error) { @@ -194,79 +165,6 @@ private List buildFilesList(final PsiManager psiManager, final VirtualF return allChildFiles; } - // private Pair>> processFilesForModuleInfoAndScan() { - // final Map> fileResults = new HashMap<>(); - // - // for (final Module module : moduleToFiles.keySet()) { - // if (module == null) { - // continue; - // } - // - // final ConfigurationLocationResult locationResult = configurationLocation(overrideConfigLocation, - // module); - // if (locationResult.status != PRESENT) { - // return pair(locationResult, emptyMap()); - // } - // - // final Set filesForModule = moduleToFiles.get(module); - // if (filesForModule.isEmpty()) { - // continue; - // } - // - // fileResults.putAll(filesWithProblems(filesForModule, - // checkFiles(module, filesForModule, locationResult.location))); - // fireFilesScanned(filesForModule.size()); - // } - // - // return pair(resultOf(PRESENT), fileResults); - // } - - // @NotNull - // private Map> filesWithProblems(final Set filesForModule, - // final Map> moduleFileResults) { - // final Map> moduleResults = new HashMap<>(); - // for (final PsiFile psiFile : filesForModule) { - // final List resultsForFile = moduleFileResults.get(psiFile); - // if (resultsForFile != null && !resultsForFile.isEmpty()) { - // moduleResults.put(psiFile, new ArrayList<>(resultsForFile)); - // } - // } - // return moduleResults; - // } - - // @NotNull - // private ConfigurationLocationResult configurationLocation(final ConfigurationLocation override, - // final Module module) { - // final ConfigurationLocation location = plugin.getConfigurationLocation(module, override); - // if (location == null) { - // return resultOf(NOT_PRESENT); - // } - // if (location.isBlacklisted()) { - // return resultOf(location, BLACKLISTED); - // } - // return resultOf(location, PRESENT); - // } - // - // private Map> checkFiles(final Module module, - // final Set filesToScan, - // final ConfigurationLocation configurationLocation) { - // final List scannableFiles = new ArrayList<>(); - // try { - // scannableFiles.addAll(ScannableFile.createAndValidate(filesToScan, plugin, module)); - // - // return checkerFactory(module.getProject()).checker(module, configurationLocation) - // .map(checker -> checker.scan(scannableFiles, - // plugin.configurationManager().getCurrent().isSuppressErrors())) - // .orElseThrow(() -> new PylintPluginException("Could not create checker")); - // } finally { - // scannableFiles.forEach(ScannableFile::deleteIfRequired); - // } - // } - - // private CheckerFactory checkerFactory(final Project project) { - // return ServiceManager.getService(project, CheckerFactory.class); - // } - private static class FindChildFiles extends VirtualFileVisitor { private final VirtualFile virtualFile; diff --git a/src/main/java/com/leinardi/pycharm/pylint/checker/ScannableFile.java b/src/main/java/com/leinardi/pycharm/pylint/checker/ScannableFile.java index 16afa59..3cd306f 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/checker/ScannableFile.java +++ b/src/main/java/com/leinardi/pycharm/pylint/checker/ScannableFile.java @@ -74,12 +74,12 @@ public class ScannableFile { * @param psiFile the psiFile to create the file from. * @throws IOException if file creation is required and fails. */ - public ScannableFile(@NotNull final PsiFile psiFile/*, @Nullable final Module module*/) throws IOException { + public ScannableFile(@NotNull final PsiFile psiFile) throws IOException { this.psiFile = psiFile; if (!existsOnFilesystem(psiFile) || documentIsModifiedAndUnsaved(psiFile)) { baseTempDir = prepareBaseTmpDirFor(psiFile); - realFile = createTemporaryFileFor(psiFile, /*module,*/ baseTempDir); + realFile = createTemporaryFileFor(psiFile, baseTempDir); } else { baseTempDir = null; realFile = new File(pathOf(psiFile)); @@ -94,7 +94,7 @@ public static List createAndValidate(@NotNull final Collection PsiFileValidator.isScannable(psiFile, plugin.getProject())) - .map(psiFile -> ScannableFile.create(psiFile/*, module*/)) + .map(psiFile -> ScannableFile.create(psiFile)) .filter(Objects::nonNull).collect(Collectors.toList()); } finally { readAccessToken.finish(); @@ -102,9 +102,9 @@ public static List createAndValidate(@NotNull final Collection> scanResults); void scanFailedWithError(PylintPluginException error); diff --git a/src/main/java/com/leinardi/pycharm/pylint/checker/UiFeedbackScannerListener.java b/src/main/java/com/leinardi/pycharm/pylint/checker/UiFeedbackScannerListener.java index 0cb4de5..12b0386 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/checker/UiFeedbackScannerListener.java +++ b/src/main/java/com/leinardi/pycharm/pylint/checker/UiFeedbackScannerListener.java @@ -54,22 +54,12 @@ public void filesScanned(final int count) { } @Override - public void scanCompletedSuccessfully(/*final ConfigurationLocationResult configurationLocationResult,*/ + public void scanCompletedSuccessfully( final Map> scanResults) { SwingUtilities.invokeLater(() -> { final PylintToolWindowPanel toolWindowPanel = toolWindowPanel(); if (toolWindowPanel != null) { - // switch (configurationLocationResult.status) { - // case NOT_PRESENT: - // toolWindowPanel.displayWarningResult("plugin.results.no-rules-file"); - // break; - // case BLACKLISTED: - // toolWindowPanel.displayWarningResult("plugin.results.rules-blacklist", - // configurationLocationResult.location.blacklistedForSeconds()); - // break; - // default: toolWindowPanel.displayResults(scanResults); - // } } }); } diff --git a/src/main/java/com/leinardi/pycharm/pylint/plapi/PylintRunner.java b/src/main/java/com/leinardi/pycharm/pylint/plapi/PylintRunner.java index 045e134..131afce 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/plapi/PylintRunner.java +++ b/src/main/java/com/leinardi/pycharm/pylint/plapi/PylintRunner.java @@ -85,16 +85,10 @@ public static List scan(Project project, Set filesToScan) throws generalCommandLine.addParameter(file); } - // GeneralCommandLine generalCommandLine = new GeneralCommandLine("cat"); - // generalCommandLine.setCharset(Charset.forName("UTF-8")); - // generalCommandLine.addParameter("pl.txt"); - generalCommandLine.setWorkDirectory(project.getBasePath()); - //generalCommandLine.getCommandLineString(); final Process process; try { process = generalCommandLine.createProcess(); - // process.waitFor(); Moshi moshi = new Moshi.Builder().build(); Type type = Types.newParameterizedType(List.class, Issue.class); JsonAdapter> adapter = moshi.adapter(type); diff --git a/src/main/java/com/leinardi/pycharm/pylint/toolwindow/PylintToolWindowPanel.java b/src/main/java/com/leinardi/pycharm/pylint/toolwindow/PylintToolWindowPanel.java index 4e2b4d5..5ee663c 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/toolwindow/PylintToolWindowPanel.java +++ b/src/main/java/com/leinardi/pycharm/pylint/toolwindow/PylintToolWindowPanel.java @@ -34,6 +34,7 @@ import com.intellij.ui.components.JBScrollPane; import com.intellij.ui.content.Content; import com.intellij.ui.treeStructure.Tree; +import com.intellij.util.ui.JBUI; import com.leinardi.pycharm.pylint.PylintBundle; import com.leinardi.pycharm.pylint.PylintPlugin; import com.leinardi.pycharm.pylint.checker.Problem; @@ -49,7 +50,6 @@ import javax.swing.JTree; import javax.swing.ToolTipManager; import javax.swing.UIManager; -import javax.swing.border.EmptyBorder; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; @@ -136,8 +136,6 @@ public PylintToolWindowPanel(final ToolWindow toolWindow, final Project project) throw new IllegalStateException("Couldn't get pylint plugin"); } - // pylintPlugin.configurationManager().addConfigurationListener(this); - final ActionGroup mainActionGroup = (ActionGroup) ActionManager.getInstance().getAction(MAIN_ACTION_GROUP); final ActionToolbar mainToolbar = ActionManager.getInstance().createActionToolbar( @@ -152,7 +150,7 @@ public PylintToolWindowPanel(final ToolWindow toolWindow, final Project project) toolBarBox.add(mainToolbar.getComponent()); toolBarBox.add(treeToolbar.getComponent()); - setBorder(new EmptyBorder(1, 1, 1, 1)); + setBorder(JBUI.Borders.empty(1)); add(toolBarBox, BorderLayout.WEST); add(createToolPanel(), BorderLayout.CENTER); @@ -161,14 +159,6 @@ public PylintToolWindowPanel(final ToolWindow toolWindow, final Project project) mainToolbar.getComponent().setVisible(true); } - // public ConfigurationLocation getSelectedOverride() { - // final Object selectedItem = configurationOverrideModel.getSelectedItem(); - // if (DEFAULT_OVERRIDE.equals(selectedItem)) { - // return null; - // } - // return (ConfigurationLocation) selectedItem; - // } - private JPanel createToolPanel() { treeModel = new ResultTreeModel(); diff --git a/src/main/java/com/leinardi/pycharm/pylint/toolwindow/ResultTreeModel.java b/src/main/java/com/leinardi/pycharm/pylint/toolwindow/ResultTreeModel.java index 1023d96..02a20af 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/toolwindow/ResultTreeModel.java +++ b/src/main/java/com/leinardi/pycharm/pylint/toolwindow/ResultTreeModel.java @@ -115,7 +115,7 @@ private void filter(final boolean sendEvents, final SeverityLevel... levels) { final ResultTreeNode result = (ResultTreeNode) problemNode.getUserObject(); final boolean currentVisible = problemNode.isVisible(); - final boolean desiredVisible = levels != null && contains(levels, result.getSeverity()); + final boolean desiredVisible = contains(levels, result.getSeverity()); if (currentVisible != desiredVisible) { problemNode.setVisible(desiredVisible); @@ -155,15 +155,6 @@ private boolean contains(final Object[] array, final Object objectToFind) { return false; } - // /** - // * Set the displayed model. - // * - // * @param results the model. - // */ - // public void setModel(final Map> results) { - // setModel(results, SeverityLevel.ERROR, SeverityLevel.WARNING, SeverityLevel.INFO); - // } - /** * Set the displayed model. * diff --git a/src/main/java/com/leinardi/pycharm/pylint/toolwindow/ResultTreeRenderer.java b/src/main/java/com/leinardi/pycharm/pylint/toolwindow/ResultTreeRenderer.java index 02076f9..8bb3668 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/toolwindow/ResultTreeRenderer.java +++ b/src/main/java/com/leinardi/pycharm/pylint/toolwindow/ResultTreeRenderer.java @@ -72,7 +72,7 @@ public Component getTreeCellRendererComponent(final JTree tree, final DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; if (node != null) { final Object userObject = node.getUserObject(); - if (userObject != null && userObject instanceof ResultTreeNode) { + if (userObject instanceof ResultTreeNode) { final ResultTreeNode treeNode = (ResultTreeNode) userObject; diff --git a/src/main/java/com/leinardi/pycharm/pylint/ui/PylintConfigPanel.java b/src/main/java/com/leinardi/pycharm/pylint/ui/PylintConfigPanel.java index 2e945db..417db0a 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/ui/PylintConfigPanel.java +++ b/src/main/java/com/leinardi/pycharm/pylint/ui/PylintConfigPanel.java @@ -40,7 +40,6 @@ import static org.apache.commons.lang.StringUtils.isBlank; public class PylintConfigPanel { - private final PylintConfigService pylintConfigService; private JTextField pathToPylintTextField; private JPanel rootPanel; private JButton browseButton; @@ -49,7 +48,7 @@ public class PylintConfigPanel { public PylintConfigPanel(Project project) { this.project = project; - pylintConfigService = PylintConfigService.getInstance(project); + PylintConfigService pylintConfigService = PylintConfigService.getInstance(project); browseButton.setAction(new BrowseAction()); testButton.setAction(new TestAction()); pathToPylintTextField.setText(pylintConfigService.getPathToPylint()); diff --git a/src/main/java/com/leinardi/pycharm/pylint/util/TempDirProvider.java b/src/main/java/com/leinardi/pycharm/pylint/util/TempDirProvider.java index 7386cee..cccbde0 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/util/TempDirProvider.java +++ b/src/main/java/com/leinardi/pycharm/pylint/util/TempDirProvider.java @@ -34,16 +34,10 @@ * Locate and/or create temporary directories for use by this plugin. */ public class TempDirProvider { - // private static final Logger LOG = Logger.getInstance(TempDirProvider.class); - // - // private static final String README_TEMPLATE = "copylibs-readme.template.txt"; - // - // public static final String README_FILE = "readme.txt"; - public String forPersistedPsiFile(final PsiFile tempPsiFile) { String systemTempDir = System.getProperty("java.io.tmpdir"); if (OS.isWindows() && driveLetterOf(systemTempDir) != driveLetterOf(pathOf(tempPsiFile))) { - // Pylint on Windows requires the files to be on the same drive + // Some tool on Windows requires the files to be on the same drive final File projectTempDir = temporaryDirectoryLocationFor(tempPsiFile.getProject()); if (projectTempDir.exists() || projectTempDir.mkdirs()) { projectTempDir.deleteOnExit(); @@ -87,80 +81,4 @@ private Optional virtualFileOf(final PsiFile file) { return Optional.ofNullable(file.getVirtualFile()); } - // /** - // * Locate the directory for storing libraries from the project directory in order to prevent their getting - // locked - // * by our classloaders. The directory will be created if it does not exist. It should persist after PyCharm - // is closed, - // * because copying the libraries is potentially time-consuming (so, no deleteOnExit()!). - // * - // * @param pProject the current project - // * @return the existing directory, or an empty Optional if such could not be made available - // */ - // public Optional forCopiedLibraries(@NotNull final Project pProject) { - // Optional result = Optional.empty(); - // try { - // final File tempDir = determineCopiedLibrariesDir(pProject); - // if (tempDir.mkdir()) { - // putReadmeFile(pProject, tempDir); - // } - // if (tempDir.isDirectory()) { - // result = Optional.of(tempDir); - // } - // } catch (IOException | URISyntaxException | RuntimeException e) { - // LOG.warn("Unable to create suitable temporary directory. Library unlock unavailable.", e); - // } - // return result; - // } - // - // @NotNull - // private File determineCopiedLibrariesDir(@NotNull final Project pProject) { - // File result = getIdeaFolder(pProject).map(pVirtualFile -> new File(pVirtualFile.getPath(), - // "pylintidea-libs")).orElseGet(() -> new File(System.getProperty("java.io.tmpdir"), "csi-" + - // projectUnique(pProject) + "-libs")); - // return result; - // } - // - // @NotNull - // private String projectUnique(@NotNull final Project pProject) { - // return pProject.getLocationHash().replaceAll(" ", "_"); - // } - // - // private void putReadmeFile(@NotNull final Project pProject, @NotNull final File pTempDir) - // throws URISyntaxException, IOException { - // final Path tempDir = Paths.get(pTempDir.toURI()); - // final Path readme = tempDir.resolve(README_FILE); - // if (!Files.isRegularFile(readme)) { - // String s = readTemplate(); - // if (s != null) { - // s = MessageFormat.format(s, pProject.getName(), PylintPlugin.ID_PLUGIN); - // s = s.replaceAll("[\r\n]+", System.lineSeparator()); - // Files.write(readme, s.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE); - // } - // } - // } - // - // @Nullable - // private String readTemplate() throws IOException { - // String result = null; - // InputStream is = null; - // try { - // is = getClass().getResourceAsStream(README_TEMPLATE); - // result = IOUtils.toString(is, StandardCharsets.UTF_8); - // } finally { - // IOUtils.closeQuietly(is); - // } - // return result; - // } - // - // public void deleteCopiedLibrariesDir(@NotNull final Project pProject) { - // try { - // final File dir = determineCopiedLibrariesDir(pProject); - // if (dir.isDirectory()) { - // FileUtils.deleteQuietly(dir); - // } - // } catch (RuntimeException e) { - // // ignore - // } - // } }