-
Notifications
You must be signed in to change notification settings - Fork 287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🎨 catch information of Error-Prone #780
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a15d5d5
:art: catch information of Error-Prone
b72c1ae
Merge branch 'Tencent:main' into main
didebughu 737a547
:art: 添加Error-Prone使用文档
f7356dc
:art: 修改Error-Prone使用手册
d0c7faf
:art: 添加Error Prone使用步骤
854fd1d
:art: 更新Error Prone规则
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# Error Prone 使用手册 | ||
|
||
## Error Prone 介绍 | ||
|
||
> Error Prone是google开源的Java编译时检测工具,将常见的Java错误捕获为编译时错误,增强对java代码的类型分析,从而让开发人员及时发现问题 | ||
|
||
## TCA使用指引 | ||
由于Error Prone同为编译时检测工具,已添加规则至JavaWarning工具以增强类型检测。建议采用客户端本地分析模式以满足编译条件,参考[编译配置](../../../guide/分析方案/代码检查编译配置.md),Error Prone客户端配置和编译命令可参考文档下文。 | ||
|
||
|
||
## Error Prone 配置 | ||
|
||
### 通过Bazel构建 | ||
|
||
- Bazel在构建java项目时,默认打开了Error Prone,所以在本地配置Bazel环境,编写Bazel构建文件,`bazel build :project`构建项目即可。 | ||
- 详情请参考[Bazel官方文档](https://bazel.build/?hl=zh-cn) | ||
|
||
### Maven 配置 Error Prone | ||
|
||
编辑pom.xml文件将设置添加到maven-compiler-plugin,例如: | ||
```xml | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
<configuration> | ||
<source>8</source> | ||
<target>8</target> | ||
<encoding>UTF-8</encoding> | ||
<compilerArgs> | ||
<arg>-XDcompilePolicy=simple</arg> | ||
<arg>-Xplugin:ErrorProne</arg> | ||
</compilerArgs> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>com.google.errorprone</groupId> | ||
<artifactId>error_prone_core</artifactId> | ||
<version>${error-prone.version}</version> | ||
</path> | ||
<!-- Other annotation processors go here. | ||
|
||
If 'annotationProcessorPaths' is set, processors will no longer be | ||
discovered on the regular -classpath; see also 'Using Error Prone | ||
together with other annotation processors' below. --> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
``` | ||
对于`JDK 16`或更高的版本,需要将以下内容`--add-exports`和`--add-opens`标志添加到`.mvn/jvm.config`文件中: | ||
```html | ||
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED | ||
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED | ||
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED | ||
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED | ||
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED | ||
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED | ||
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED | ||
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED | ||
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED | ||
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED | ||
``` | ||
|
||
###命令行 | ||
Error Prone 支持`com.sun.source.util.Plugin`API,并且可以通过将 Error Prone 添加到`-processorpath`并设置`-Xplugin`标志来与`JDK 9`及更高版本一起使用: | ||
```shell | ||
wget https://repo1.maven.org/maven2/com/google/errorprone/error_prone_core/${EP_VERSION?}/error_prone_core-${EP_VERSION?}-with-dependencies.jar | ||
wget https://repo1.maven.org/maven2/org/checkerframework/dataflow-errorprone/3.15.0/dataflow-errorprone-3.15.0.jar | ||
javac \ | ||
-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ | ||
-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \ | ||
-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED \ | ||
-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED \ | ||
-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \ | ||
-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED \ | ||
-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \ | ||
-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \ | ||
-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \ | ||
-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED \ | ||
-XDcompilePolicy=simple \ | ||
-processorpath error_prone_core-${EP_VERSION?}-with-dependencies.jar:dataflow-errorprone-3.15.0.jar \ | ||
'-Xplugin:ErrorProne -XepDisableAllChecks -Xep:CollectionIncompatibleType:ERROR' \ | ||
Example.java | ||
``` | ||
- 对于`JDK 16`以及更高的版本`--add-exports`和`--add-opens`参数是必须的 | ||
- 对于`JDK 8`,请参考[旧版本安装说明](https://github.com/google/error-prone/blob/f8e33bc460be82ab22256a7ef8b979d7a2cacaba/docs/installation.md) | ||
|
||
### 其他配置和注意事项 | ||
- Error Prone还支持通过Gradle和Ant配置,详情参考[Error Prone官方配置文档](https://errorprone.info/docs/installation) | ||
- 不同JDK版本参数有所不同,详情参考[旧版本安装说明](https://github.com/google/error-prone/blob/f8e33bc460be82ab22256a7ef8b979d7a2cacaba/docs/installation.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# Error Prone 使用手册 | ||
|
||
## Error Prone 介绍 | ||
|
||
> Error Prone是google开源的Java编译时检测工具,将常见的Java错误捕获为编译时错误,增强对java代码的类型分析,从而让开发人员及时发现问题 | ||
|
||
## TCA使用指引 | ||
由于Error Prone同为编译时检测工具,已添加规则至JavaWarning工具以增强类型检测。建议采用客户端本地分析模式以满足编译条件,参考[编译配置](../../../guide/分析方案/代码检查编译配置.md),Error Prone客户端配置和编译命令可参考文档下文。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 跟上面的一样。 |
||
|
||
|
||
## Error Prone 配置 | ||
|
||
### 通过Bazel构建 | ||
|
||
- Bazel在构建java项目时,默认打开了Error Prone,所以在本地配置Bazel环境,编写Bazel构建文件,`bazel build :project`构建项目即可。 | ||
- 详情请参考[Bazel官方文档](https://bazel.build/?hl=zh-cn) | ||
|
||
### Maven 配置 Error Prone | ||
|
||
编辑pom.xml文件将设置添加到maven-compiler-plugin,例如: | ||
```xml | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
<configuration> | ||
<source>8</source> | ||
<target>8</target> | ||
<encoding>UTF-8</encoding> | ||
<compilerArgs> | ||
<arg>-XDcompilePolicy=simple</arg> | ||
<arg>-Xplugin:ErrorProne</arg> | ||
</compilerArgs> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>com.google.errorprone</groupId> | ||
<artifactId>error_prone_core</artifactId> | ||
<version>${error-prone.version}</version> | ||
</path> | ||
<!-- Other annotation processors go here. | ||
|
||
If 'annotationProcessorPaths' is set, processors will no longer be | ||
discovered on the regular -classpath; see also 'Using Error Prone | ||
together with other annotation processors' below. --> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
``` | ||
对于`JDK 16`或更高的版本,需要将以下内容`--add-exports`和`--add-opens`标志添加到`.mvn/jvm.config`文件中: | ||
```html | ||
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED | ||
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED | ||
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED | ||
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED | ||
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED | ||
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED | ||
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED | ||
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED | ||
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED | ||
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED | ||
``` | ||
|
||
###命令行 | ||
Error Prone 支持`com.sun.source.util.Plugin`API,并且可以通过将 Error Prone 添加到`-processorpath`并设置`-Xplugin`标志来与`JDK 9`及更高版本一起使用: | ||
```shell | ||
wget https://repo1.maven.org/maven2/com/google/errorprone/error_prone_core/${EP_VERSION?}/error_prone_core-${EP_VERSION?}-with-dependencies.jar | ||
wget https://repo1.maven.org/maven2/org/checkerframework/dataflow-errorprone/3.15.0/dataflow-errorprone-3.15.0.jar | ||
javac \ | ||
-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ | ||
-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \ | ||
-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED \ | ||
-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED \ | ||
-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \ | ||
-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED \ | ||
-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \ | ||
-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \ | ||
-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \ | ||
-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED \ | ||
-XDcompilePolicy=simple \ | ||
-processorpath error_prone_core-${EP_VERSION?}-with-dependencies.jar:dataflow-errorprone-3.15.0.jar \ | ||
'-Xplugin:ErrorProne -XepDisableAllChecks -Xep:CollectionIncompatibleType:ERROR' \ | ||
Example.java | ||
``` | ||
- 对于`JDK 16`以及更高的版本`--add-exports`和`--add-opens`参数是必须的 | ||
- 对于`JDK 8`,请参考[旧版本安装说明](https://github.com/google/error-prone/blob/f8e33bc460be82ab22256a7ef8b979d7a2cacaba/docs/installation.md) | ||
|
||
### 其他配置和注意事项 | ||
- Error Prone还支持通过Gradle和Ant配置,详情参考[Error Prone官方配置文档](https://errorprone.info/docs/installation) | ||
- 不同JDK版本参数有所不同,详情参考[旧版本安装说明](https://github.com/google/error-prone/blob/f8e33bc460be82ab22256a7ef8b979d7a2cacaba/docs/installation.md) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里需要详细写下: