提交 ae5348ec 编写于 作者: C caikang.ck

Fix idea 2020.2 Ultimate compatibility issue

Minimum supported idea version up to 2018.3
Kotlin upgrade to 1.3.72
上级 5fb5777a
......@@ -7,16 +7,16 @@
## <font color="green">Build</font>
```
cd p3c-idea
gradle clean buildPlugin
../gradlew clean buildPlugin
```
## <font color="green">Run plugin</font>
```
cd p3c-idea
gradle runIde
../gradlew runIde
# run specific IDEA
gradle runIde -Pidea_version=14.1.7
../gradlew runIde -Pidea_version=14.1.7
```
## <font color="green">Use p3c-common as your plugin dependency</font>
......
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
#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
......@@ -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 " "
}
......
......@@ -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
......
......@@ -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<VirtualFile>? = if (searchScope is LocalSearchScope) THashSet() else null
val filesToInspect: BlockingQueue<PsiFile> = 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<VirtualFile>?,
headlessEnvironment: Boolean,
outFilesToInspect: BlockingQueue<in PsiFile>,
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<PsiFile?, RuntimeException> {
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<VirtualFile>?
): 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,
......
......@@ -6,6 +6,15 @@
<change-notes>
<![CDATA[
<ul>
2.1.0
<li>Fix idea 2020.2 Ultimate compatibility issue</li>
<li>Minimum supported idea version up to 2018.3</li>
<li>Kotlin upgrade to 1.3.72</li>
<li>Disable real time inspect if file lines more than 3000 lines</li>
<li>Fix https://github.com/alibaba/p3c/issues/722</li>
<li>Fix https://github.com/alibaba/p3c/issues/620</li>
</ul>
<ul>
2.0.2
<li>Fix idea 2020.1 Ultimate compatibility issue</li>
</ul>
......@@ -75,7 +84,7 @@
</change-notes>
<vendor>alibaba</vendor>
<version>2.0.0</version>
<idea-version since-build="145.0"/>
<idea-version since-build="183.4284"/>
<depends optional="true">com.intellij.velocity</depends>
<depends optional="true" config-file="p3c.xml">com.intellij.modules.java</depends>
<depends>com.intellij.modules.platform</depends>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册