diff --git a/idea-plugin/README.md b/idea-plugin/README.md
index dea906a983c6479388bef68031afd74e3543cb32..9833e6e6751e5159ec6c0fcbdafc071cd2ae0582 100644
--- a/idea-plugin/README.md
+++ b/idea-plugin/README.md
@@ -7,16 +7,16 @@
## Build
```
cd p3c-idea
-gradle clean buildPlugin
+../gradlew clean buildPlugin
```
## Run plugin
```
cd p3c-idea
-gradle runIde
+../gradlew runIde
# run specific IDEA
-gradle runIde -Pidea_version=14.1.7
+../gradlew runIde -Pidea_version=14.1.7
```
## Use p3c-common as your plugin dependency
diff --git a/idea-plugin/gradle.properties b/idea-plugin/gradle.properties
index 9c338100ab759e84eeaea811cd50346aca4f46bc..637c314fab37295bd656d19e6661a972d428d86b 100644
--- a/idea-plugin/gradle.properties
+++ b/idea-plugin/gradle.properties
@@ -1,8 +1,7 @@
-kotlin_version=1.3.50
-#idea_version=171.3780.15
-idea_version=145.258.11
+kotlin_version=1.3.72
+idea_version=2018.3
plugin_name=Alibaba Java Coding Guidelines
gradle_jetbrains_version=0.4.5
systemProp.file.encoding=UTF-8
-plugin_version=2.0.2
+plugin_version=2.1.0
diff --git a/idea-plugin/gradle/wrapper/gradle-wrapper.jar b/idea-plugin/gradle/wrapper/gradle-wrapper.jar
index 51288f9c2f05faf8d42e1a751a387ca7923882c3..87b738cbd051603d91cc39de6cb000dd98fe6b02 100644
Binary files a/idea-plugin/gradle/wrapper/gradle-wrapper.jar and b/idea-plugin/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/idea-plugin/gradle/wrapper/gradle-wrapper.properties b/idea-plugin/gradle/wrapper/gradle-wrapper.properties
index 29bf84a4b5a47b879ed8e20cd7e49efe1748e3ba..bb8b2fc26b2e572c79d7212a4f6f11057c6787f7 100644
--- a/idea-plugin/gradle/wrapper/gradle-wrapper.properties
+++ b/idea-plugin/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,5 @@
-#Wed Nov 30 15:31:46 CST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-bin.zip
diff --git a/idea-plugin/gradlew b/idea-plugin/gradlew
index 4453ccea33d960069d9137ee65f6b21fc65e7e92..af6708ff229fda75da4f7cc4da4747217bac4d53 100755
--- a/idea-plugin/gradlew
+++ b/idea-plugin/gradlew
@@ -28,16 +28,16 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-DEFAULT_JVM_OPTS=""
+DEFAULT_JVM_OPTS='"-Xmx64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
-warn ( ) {
+warn () {
echo "$*"
}
-die ( ) {
+die () {
echo
echo "$*"
echo
@@ -155,7 +155,7 @@ if $cygwin ; then
fi
# Escape application args
-save ( ) {
+save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
diff --git a/idea-plugin/gradlew.bat b/idea-plugin/gradlew.bat
index f9553162f122c71b34635112e717c3e733b5b212..6d57edc706c93465988754383a2d7ff353d4e79f 100644
--- a/idea-plugin/gradlew.bat
+++ b/idea-plugin/gradlew.bat
@@ -14,7 +14,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS=
+set DEFAULT_JVM_OPTS="-Xmx64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
diff --git a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/action/PmdGlobalInspectionContextImpl.kt b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/action/PmdGlobalInspectionContextImpl.kt
index 7207622a9888d6878df9a77c220a40e0f8ae78bd..f7c277872854957f80b4ab316f57adf10bc6c2d4 100644
--- a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/action/PmdGlobalInspectionContextImpl.kt
+++ b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/action/PmdGlobalInspectionContextImpl.kt
@@ -6,6 +6,7 @@ import com.alibaba.p3c.idea.inspection.AliLocalInspectionToolProvider
import com.alibaba.p3c.idea.inspection.PmdRuleInspectionIdentify
import com.alibaba.p3c.idea.pmd.AliPmdProcessor
import com.intellij.analysis.AnalysisScope
+import com.intellij.codeInsight.daemon.ProblemHighlightFilter
import com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator
import com.intellij.codeInspection.ex.GlobalInspectionContextImpl
import com.intellij.codeInspection.ui.InspectionResultsView
@@ -14,21 +15,32 @@ import com.intellij.concurrency.JobLauncherImpl
import com.intellij.concurrency.SensitiveProgressWrapper
import com.intellij.diagnostic.ThreadDumper
import com.intellij.openapi.application.ApplicationManager
+import com.intellij.openapi.application.ReadAction
import com.intellij.openapi.application.ex.ApplicationManagerEx
import com.intellij.openapi.diagnostic.Logger
+import com.intellij.openapi.editor.Document
import com.intellij.openapi.progress.ProcessCanceledException
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.ProgressIndicatorProvider
import com.intellij.openapi.progress.ProgressManager
+import com.intellij.openapi.progress.Task.Backgroundable
+import com.intellij.openapi.progress.impl.CoreProgressManager
import com.intellij.openapi.progress.util.ProgressIndicatorUtils
import com.intellij.openapi.project.DumbService
import com.intellij.openapi.project.Project
-import com.intellij.openapi.project.ProjectUtilCore
+import com.intellij.openapi.project.displayUrlRelativeToProject
+import com.intellij.openapi.project.isProjectOrWorkspaceFile
+import com.intellij.openapi.roots.FileIndex
+import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.util.EmptyRunnable
import com.intellij.openapi.util.NotNullLazyValue
import com.intellij.openapi.vfs.VirtualFile
+import com.intellij.psi.PsiBinaryFile
+import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiFile
+import com.intellij.psi.PsiManager
+import com.intellij.psi.SingleRootFileViewProvider
import com.intellij.psi.search.LocalSearchScope
import com.intellij.psi.search.SearchScope
import com.intellij.psi.util.PsiUtilCore
@@ -123,20 +135,7 @@ class PmdGlobalInspectionContextImpl(
val localScopeFiles: MutableSet? = if (searchScope is LocalSearchScope) THashSet() else null
val filesToInspect: BlockingQueue = ArrayBlockingQueue(1000)
val iteratingIndicator: ProgressIndicator = SensitiveProgressWrapper(progressIndicator)
- val startIterateScopeInBackground = ReflectionUtil.getDeclaredMethod(
- javaClass.superclass,
- "startIterateScopeInBackground",
- AnalysisScope::class.java,
- Collection::class.java,
- headlessEnvironment.javaClass,
- BlockingQueue::class.java,
- ProgressIndicator::class.java
- )
- requireNotNull(startIterateScopeInBackground) {
- "method GlobalInspectionContextImpl.startIterateScopeInBackground not found in this IDEA version"
- }
- val future: Future<*> = startIterateScopeInBackground.invoke(
- this,
+ val future: Future<*> = startIterateScopeInBackground(
scope,
localScopeFiles,
headlessEnvironment,
@@ -219,12 +218,91 @@ class PmdGlobalInspectionContextImpl(
ProgressManager.checkCanceled()
}
+ private fun startIterateScopeInBackground(
+ scope: AnalysisScope,
+ localScopeFiles: MutableCollection?,
+ headlessEnvironment: Boolean,
+ outFilesToInspect: BlockingQueue,
+ progressIndicator: ProgressIndicator
+ ): Future<*>? {
+ val task: Backgroundable = object : Backgroundable(project, "Scanning Files to Inspect") {
+ override fun run(indicator: ProgressIndicator) {
+ try {
+ val fileIndex: FileIndex = ProjectRootManager.getInstance(project).fileIndex
+ scope.accept { file: VirtualFile? ->
+ ProgressManager.checkCanceled()
+ if (isProjectOrWorkspaceFile(file!!) || !fileIndex.isInContent(file)) return@accept true
+ val psiFile =
+ ReadAction.compute {
+ if (project.isDisposed) throw ProcessCanceledException()
+ val psi = PsiManager.getInstance(project).findFile(file)
+ val document =
+ psi?.let { shouldProcess(it, headlessEnvironment, localScopeFiles) }
+ if (document != null) {
+ return@compute psi
+ }
+ null
+ }
+ // do not inspect binary files
+ if (psiFile != null) {
+ try {
+ check(!ApplicationManager.getApplication().isReadAccessAllowed) { "Must not have read action" }
+ outFilesToInspect.put(psiFile)
+ } catch (e: InterruptedException) {
+ logger.error(e)
+ }
+ }
+ ProgressManager.checkCanceled()
+ true
+ }
+ } catch (e: ProcessCanceledException) {
+ // ignore, but put tombstone
+ } finally {
+ try {
+ outFilesToInspect.put(PsiUtilCore.NULL_PSI_FILE)
+ } catch (e: InterruptedException) {
+ logger.error(e)
+ }
+ }
+ }
+ }
+ return (ProgressManager.getInstance() as CoreProgressManager).runProcessWithProgressAsynchronously(
+ task,
+ progressIndicator,
+ null
+ )
+ }
+
+ private fun shouldProcess(
+ file: PsiFile,
+ headlessEnvironment: Boolean,
+ localScopeFiles: MutableCollection?
+ ): Document? {
+ val virtualFile = file.virtualFile ?: return null
+ if (isBinary(file)) return null //do not inspect binary files
+ if (isViewClosed && !headlessEnvironment) {
+ throw ProcessCanceledException()
+ }
+ if (logger.isDebugEnabled) {
+ logger.debug("Running local inspections on " + virtualFile.path)
+ }
+ if (SingleRootFileViewProvider.isTooLargeForIntelligence(virtualFile)) return null
+ if (localScopeFiles != null && !localScopeFiles.add(virtualFile)) return null
+ return if (!ProblemHighlightFilter.shouldProcessFileInBatch(file)) null else PsiDocumentManager.getInstance(
+ project
+ ).getDocument(file)
+ }
+
+ private fun isBinary(file: PsiFile): Boolean {
+ return file is PsiBinaryFile || file.fileType.isBinary
+ }
+
private fun doPmdProcess(
file: PsiFile,
aliProjectComponent: AliProjectComponent,
virtualFile: VirtualFile
) {
- val url: String = ProjectUtilCore.displayUrlRelativeToProject(
+ val url: String = displayUrlRelativeToProject(
virtualFile,
virtualFile.presentableUrl,
project,
diff --git a/idea-plugin/p3c-idea/src/main/resources/META-INF/plugin.xml b/idea-plugin/p3c-idea/src/main/resources/META-INF/plugin.xml
index 932d886c628424724fbef558e6f17597e894078b..0a19bf9f4af5a24e21cdca0060efa079ad495a26 100755
--- a/idea-plugin/p3c-idea/src/main/resources/META-INF/plugin.xml
+++ b/idea-plugin/p3c-idea/src/main/resources/META-INF/plugin.xml
@@ -6,6 +6,15 @@
+ 2.1.0
+ Fix idea 2020.2 Ultimate compatibility issue
+ Minimum supported idea version up to 2018.3
+ Kotlin upgrade to 1.3.72
+ Disable real time inspect if file lines more than 3000 lines
+ Fix https://github.com/alibaba/p3c/issues/722
+ Fix https://github.com/alibaba/p3c/issues/620
+
+
2.0.2
- Fix idea 2020.1 Ultimate compatibility issue
@@ -75,7 +84,7 @@
alibaba
2.0.0
-
+
com.intellij.velocity
com.intellij.modules.java
com.intellij.modules.platform