From 20de904d0ada8079499931172149ceafe2da7e83 Mon Sep 17 00:00:00 2001
From: Jamie Shiell
Date: Mon, 12 Dec 2022 09:30:29 +0000
Subject: [PATCH] Use newer ReadAction API
---
CHANGELOG.md | 1 +
build.gradle | 2 +-
.../service/CheckStyleAuditListener.java | 3 ++-
.../idea/checkstyle/actions/ScanAllFilesTask.java | 3 ++-
.../idea/checkstyle/actions/ScanModule.java | 7 ++++---
.../idea/checkstyle/actions/ScanProject.java | 7 ++++---
.../checker/CreateScannableFileAction.java | 3 ++-
.../idea/checkstyle/checker/ScanFiles.java | 14 ++++++--------
.../idea/checkstyle/checker/ScannableFile.java | 10 +++++-----
.../checkstyle/csapi/ProcessResultsThread.java | 3 ++-
.../idea/checkstyle/model/NamedScopeHelper.java | 1 -
src/main/resources/META-INF/plugin.xml | 3 ++-
12 files changed, 31 insertions(+), 26 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7f0e9443..f51fd0d6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
# CheckStyle-IDEA Changelog
+* **5.74.1** Fixed: Ensure scope is checked as read action (#595).
* **5.74.0** New: Added Checkstyle 10.5.0 - thanks to @kennysoft (#596).
* **5.73.0** New: Added Checkstyle 10.4.
* **5.72.0** Now built against IDEA 2021.3.3 (was 2021.1.3).
diff --git a/build.gradle b/build.gradle
index 6be5fdd8..355daaff 100644
--- a/build.gradle
+++ b/build.gradle
@@ -16,7 +16,7 @@ repositories {
// Project Metadata
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-version = '5.74.0'
+version = '5.74.1'
intellij {
version = 'IC-2021.3.3'
diff --git a/src/csaccess/java/org/infernus/idea/checkstyle/service/CheckStyleAuditListener.java b/src/csaccess/java/org/infernus/idea/checkstyle/service/CheckStyleAuditListener.java
index 441c53c8..a547585d 100644
--- a/src/csaccess/java/org/infernus/idea/checkstyle/service/CheckStyleAuditListener.java
+++ b/src/csaccess/java/org/infernus/idea/checkstyle/service/CheckStyleAuditListener.java
@@ -2,6 +2,7 @@
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.PsiFile;
import com.puppycrawl.tools.checkstyle.api.AuditEvent;
@@ -57,7 +58,7 @@ public void auditFinished(final AuditEvent auditEvent) {
final Application application = ApplicationManager.getApplication();
if (application != null) { // can be null in unit tests
- application.runReadAction(findThread);
+ ReadAction.run(findThread);
problems = findThread.getProblems();
}
}
diff --git a/src/main/java/org/infernus/idea/checkstyle/actions/ScanAllFilesTask.java b/src/main/java/org/infernus/idea/checkstyle/actions/ScanAllFilesTask.java
index c2b505b3..a0ccfc03 100644
--- a/src/main/java/org/infernus/idea/checkstyle/actions/ScanAllFilesTask.java
+++ b/src/main/java/org/infernus/idea/checkstyle/actions/ScanAllFilesTask.java
@@ -4,6 +4,7 @@
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileVisitor;
+import com.intellij.util.ThrowableRunnable;
import org.infernus.idea.checkstyle.StaticScanner;
import org.infernus.idea.checkstyle.model.ConfigurationLocation;
import org.jetbrains.annotations.NotNull;
@@ -12,7 +13,7 @@
import java.util.List;
-abstract class ScanAllFilesTask implements Runnable {
+abstract class ScanAllFilesTask implements ThrowableRunnable {
private final Project project;
private final ConfigurationLocation selectedOverride;
diff --git a/src/main/java/org/infernus/idea/checkstyle/actions/ScanModule.java b/src/main/java/org/infernus/idea/checkstyle/actions/ScanModule.java
index ebf8d887..a77f174e 100644
--- a/src/main/java/org/infernus/idea/checkstyle/actions/ScanModule.java
+++ b/src/main/java/org/infernus/idea/checkstyle/actions/ScanModule.java
@@ -2,7 +2,7 @@
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.Presentation;
-import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.module.Module;
@@ -11,6 +11,7 @@
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindow;
+import com.intellij.util.ThrowableRunnable;
import org.infernus.idea.checkstyle.model.ScanScope;
import org.jetbrains.annotations.NotNull;
@@ -50,7 +51,7 @@ public final void actionPerformed(final @NotNull AnActionEvent event) {
try {
setProgressText(toolWindow, "plugin.status.in-progress.module");
- Runnable scanAction = null;
+ ThrowableRunnable scanAction = null;
if (scope == ScanScope.Everything) {
scanAction = new ScanAllFilesInModuleTask(module, getSelectedOverride(toolWindow));
} else {
@@ -62,7 +63,7 @@ public final void actionPerformed(final @NotNull AnActionEvent event) {
}
}
if (scanAction != null) {
- ApplicationManager.getApplication().runReadAction(scanAction);
+ ReadAction.run(scanAction);
}
} catch (Throwable e) {
LOG.warn("Current Module scan failed", e);
diff --git a/src/main/java/org/infernus/idea/checkstyle/actions/ScanProject.java b/src/main/java/org/infernus/idea/checkstyle/actions/ScanProject.java
index f0d0913c..75de2307 100644
--- a/src/main/java/org/infernus/idea/checkstyle/actions/ScanProject.java
+++ b/src/main/java/org/infernus/idea/checkstyle/actions/ScanProject.java
@@ -2,12 +2,13 @@
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.Presentation;
-import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindow;
+import com.intellij.util.ThrowableRunnable;
import org.infernus.idea.checkstyle.model.ScanScope;
import org.jetbrains.annotations.NotNull;
@@ -39,7 +40,7 @@ public void actionPerformed(final @NotNull AnActionEvent event) {
private void executeScan(final Project project, final ScanScope scope, final ToolWindow toolWindow) {
try {
setProgressText(toolWindow, "plugin.status.in-progress.project");
- Runnable scanAction = null;
+ ThrowableRunnable scanAction = null;
if (scope == ScanScope.Everything) {
scanAction = new ScanAllFilesInProjectTask(project, getSelectedOverride(toolWindow));
} else {
@@ -50,7 +51,7 @@ private void executeScan(final Project project, final ScanScope scope, final Too
}
}
if (scanAction != null) {
- ApplicationManager.getApplication().runReadAction(scanAction);
+ ReadAction.run(scanAction);
}
} catch (Throwable e) {
LOG.warn("Project scan failed", e);
diff --git a/src/main/java/org/infernus/idea/checkstyle/checker/CreateScannableFileAction.java b/src/main/java/org/infernus/idea/checkstyle/checker/CreateScannableFileAction.java
index 5ae5a50c..e323ed85 100644
--- a/src/main/java/org/infernus/idea/checkstyle/checker/CreateScannableFileAction.java
+++ b/src/main/java/org/infernus/idea/checkstyle/checker/CreateScannableFileAction.java
@@ -2,6 +2,7 @@
import com.intellij.openapi.module.Module;
import com.intellij.psi.PsiFile;
+import com.intellij.util.ThrowableRunnable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -10,7 +11,7 @@
/**
* Action to read the file to a temporary file.
*/
-class CreateScannableFileAction implements Runnable {
+class CreateScannableFileAction implements ThrowableRunnable {
/**
* Any failure that occurred on the thread.
diff --git a/src/main/java/org/infernus/idea/checkstyle/checker/ScanFiles.java b/src/main/java/org/infernus/idea/checkstyle/checker/ScanFiles.java
index 98042f57..7a713a67 100644
--- a/src/main/java/org/infernus/idea/checkstyle/checker/ScanFiles.java
+++ b/src/main/java/org/infernus/idea/checkstyle/checker/ScanFiles.java
@@ -1,6 +1,6 @@
package org.infernus.idea.checkstyle.checker;
-import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
@@ -63,15 +63,15 @@ private List findAllFilesFor(@NotNull final List virtualFi
}
private Map> mapsModulesToFiles() {
- final Map> modulesToFiles = new HashMap<>();
- ApplicationManager.getApplication().runReadAction(() -> {
+ return ReadAction.compute(() -> {
+ 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;
});
- return modulesToFiles;
}
@Override
@@ -132,13 +132,11 @@ private void fireFilesScanned(final int count) {
}
private List buildFilesList(final PsiManager psiManager, final VirtualFile virtualFile) {
- final List allChildFiles = new ArrayList<>();
- ApplicationManager.getApplication().runReadAction(() -> {
+ return ReadAction.compute(() -> {
final FindChildFiles visitor = new FindChildFiles(virtualFile, psiManager);
VfsUtilCore.visitChildrenRecursively(virtualFile, visitor);
- allChildFiles.addAll(visitor.locatedFiles);
+ return visitor.locatedFiles;
});
- return allChildFiles;
}
private Pair>> processFilesForModuleInfoAndScan() {
diff --git a/src/main/java/org/infernus/idea/checkstyle/checker/ScannableFile.java b/src/main/java/org/infernus/idea/checkstyle/checker/ScannableFile.java
index be276e67..2b3cccaf 100644
--- a/src/main/java/org/infernus/idea/checkstyle/checker/ScannableFile.java
+++ b/src/main/java/org/infernus/idea/checkstyle/checker/ScannableFile.java
@@ -1,14 +1,14 @@
package org.infernus.idea.checkstyle.checker;
import com.intellij.application.options.CodeStyle;
-import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectUtil;
import com.intellij.openapi.roots.ModuleRootManager;
-import com.intellij.openapi.util.Computable;
+import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
@@ -75,7 +75,7 @@ public static List createAndValidate(@NotNull final Collection> action = () -> psiFiles.stream()
+ ThrowableComputable, RuntimeException> action = () -> psiFiles.stream()
.filter(currentFile -> PsiFileValidator.isScannable(
currentFile,
ofNullable(module),
@@ -84,7 +84,7 @@ public static List createAndValidate(@NotNull final Collection ScannableFile.create(currentFile, module))
.filter(Objects::nonNull)
.collect(Collectors.toCollection(CopyOnWriteArrayList::new));
- return ApplicationManager.getApplication().runReadAction(action);
+ return ReadAction.compute(action);
}
private static PluginConfigurationManager configurationManager(final Project project) {
@@ -95,7 +95,7 @@ private static PluginConfigurationManager configurationManager(final Project pro
private static ScannableFile create(@NotNull final PsiFile psiFile, @Nullable final Module module) {
try {
final CreateScannableFileAction fileAction = new CreateScannableFileAction(psiFile, module);
- ApplicationManager.getApplication().runReadAction(fileAction);
+ ReadAction.run(fileAction);
if (fileAction.getFailure() != null) {
throw fileAction.getFailure();
diff --git a/src/main/java/org/infernus/idea/checkstyle/csapi/ProcessResultsThread.java b/src/main/java/org/infernus/idea/checkstyle/csapi/ProcessResultsThread.java
index 5b519780..d76bdb1e 100644
--- a/src/main/java/org/infernus/idea/checkstyle/csapi/ProcessResultsThread.java
+++ b/src/main/java/org/infernus/idea/checkstyle/csapi/ProcessResultsThread.java
@@ -4,6 +4,7 @@
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiInvalidElementAccessException;
+import com.intellij.util.ThrowableRunnable;
import org.infernus.idea.checkstyle.checker.Problem;
import org.infernus.idea.checkstyle.checks.Check;
import org.jetbrains.annotations.NotNull;
@@ -14,7 +15,7 @@
import java.util.*;
-public class ProcessResultsThread implements Runnable {
+public class ProcessResultsThread implements ThrowableRunnable {
private static final Logger LOG = Logger.getInstance(ProcessResultsThread.class);
diff --git a/src/main/java/org/infernus/idea/checkstyle/model/NamedScopeHelper.java b/src/main/java/org/infernus/idea/checkstyle/model/NamedScopeHelper.java
index 564df099..dbd18060 100644
--- a/src/main/java/org/infernus/idea/checkstyle/model/NamedScopeHelper.java
+++ b/src/main/java/org/infernus/idea/checkstyle/model/NamedScopeHelper.java
@@ -10,7 +10,6 @@
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Stream;
public final class NamedScopeHelper {
diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml
index 81d6b424..1c1490cf 100644
--- a/src/main/resources/META-INF/plugin.xml
+++ b/src/main/resources/META-INF/plugin.xml
@@ -15,7 +15,7 @@
]]>
- 5.73.0
+ 5.74.1
Jamie Shiell
@@ -24,6 +24,7 @@
+ 5.74.1: Fixed: Ensure scope is checked as read action (#595).
5.74.0: New: Added Checkstyle 10.5.0 - thanks to @kennysoft (#596).
5.73.0: New: Added Checkstyle 10.4.
5.72.0: Now built against IDEA 2021.3.3 (was 2021.1.3).