Java代码静态检查技术探究Java代码静态检查技术探究(二)使用案例-PMD

举报
Jet Ding 发表于 2021/07/22 17:48:29 2021/07/22
【摘要】 运行全部规则PS D:\tool\openapi\out\java> pmd -d . -f text -R rulesets/java/quickstart.xmlMay 01, 2020 1:44:58 PM net.sourceforge.pmd.PMD encourageToUseIncrementalAnalysisWARNING: This analysis could be f...

运行全部规则

PS D:\tool\openapi\out\java> pmd -d . -f text -R rulesets/java/quickstart.xml

May 01, 2020 1:44:58 PM net.sourceforge.pmd.PMD encourageToUseIncrementalAnalysis

WARNING: This analysis could be faster, please consider using Incremental Analysis: https://pmd.github.io/pmd-6.23.0/pmd_userdocs_incremental_analysis.html

D:\tool\openapi\out\java\src\main\java\org\openapitools\client\ApiCallback.java:16:     Avoid unused imports such as 'java.io.IOException'

D:\tool\openapi\out\java\src\main\java\org\openapitools\client\ApiClient.java:16:       Avoid unused imports such as 'okhttp3'

D:\tool\openapi\out\java\src\main\java\org\openapitools\client\ApiClient.java:27:       Avoid unused imports such as 'org.apache.oltu.oauth2.common.message.types.GrantType'

D:\tool\openapi\out\java\src\main\java\org\openapitools\client\ApiClient.java:44:       Avoid unused imports such as 'java.security.cert.X509Certificate'

D:\tool\openapi\out\java\src\main\java\org\openapitools\client\ApiClient.java:54:       Avoid unused imports such as 'org.openapitools.client.auth.HttpBearerAuth'

D:\tool\openapi\out\java\src\main\java\org\openapitools\client\ApiClient.java:71:       Avoid unused private fields such as 'datetimeFormat'.

D:\tool\openapi\out\java\src\main\java\org\openapitools\client\ApiClient.java:72:       Avoid unused private fields such as 'lenientDatetimeFormat'.

D:\tool\openapi\out\java\src\main\java\org\openapitools\client\ApiClient.java:73:       Avoid unused private fields such as 'dateLength'.

运行指定规则

PS D:\tool\openapi\out\java> pmd -d . -f text -R rulesets/java/quickstart.xml/ImportFromSamePackage

May 01, 2020 1:53:09 PM net.sourceforge.pmd.PMD encourageToUseIncrementalAnalysis

WARNING: This analysis could be faster, please consider using Incremental Analysis: https://pmd.github.io/pmd-6.23.0/pmd_userdocs_incremental_analysis.html

D:\tool\openapi\out\java\src\main\java\org\openapitools\client\model\Pet.java:28:       No need to import a type that lives in the same package

D:\tool\openapi\out\java\src\main\java\org\openapitools\client\model\Pet.java:29:       No need to import a type that lives in the same package

D:\tool\openapi\out\java\src\test\java\org\openapitools\client\model\PetTest.java:26:   No need to import a type that lives in the same package

D:\tool\openapi\out\java\src\test\java\org\openapitools\client\model\PetTest.java:27:   No need to import a type that lives in the same package

 

XML格式输出

PS D:\tool\openapi\out\java> pmd -d . -f xml -R rulesets/java/quickstart.xml/ImportFromSamePackage

May 01, 2020 1:53:50 PM net.sourceforge.pmd.PMD encourageToUseIncrementalAnalysis

WARNING: This analysis could be faster, please consider using Incremental Analysis: https://pmd.github.io/pmd-6.23.0/pmd_userdocs_incremental_analysis.html

<?xml version="1.0" encoding="UTF-8"?>

<pmd xmlns="http://pmd.sourceforge.net/report/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/report/2.0.0 http://pmd.sourceforge.net/report_2_0_0.xsd" version="6.23.0" timestamp="2020-05-01T13:53:50.934">

    <file name="D:\tool\openapi\out\java\src\main\java\org\openapitools\client\model\Pet.java">

        <violation beginline="28" endline="28" begincolumn="1" endcolumn="46" rule="ImportFromSamePackage" ruleset="Error Prone" package="org.openapitools.client.model" class="Pet" externalInfoUrl="https://pmd.github.io/pmd-6.23.0/pmd_rules_java_errorprone.html#importfromsamepackage" priority="3">

            No need to import a type that lives in the same package

        </violation>

        <violation beginline="29" endline="29" begincolumn="1" endcolumn="41" rule="ImportFromSamePackage" ruleset="Error Prone" package="org.openapitools.client.model" class="Pet" externalInfoUrl="https://pmd.github.io/pmd-6.23.0/pmd_rules_java_errorprone.html#importfromsamepackage" priority="3">

            No need to import a type that lives in the same package

        </violation>

    </file>

    <file name="D:\tool\openapi\out\java\src\test\java\org\openapitools\client\model\PetTest.java">

        <violation beginline="26" endline="26" begincolumn="1" endcolumn="46" rule="ImportFromSamePackage" ruleset="Error Prone" package="org.openapitools.client.model" class="PetTest" externalInfoUrl="https://pmd.github.io/pmd-6.23.0/pmd_rules_java_errorprone.html#importfromsamepackage" priority="3">

            No need to import a type that lives in the same package

        </violation>

        <violation beginline="27" endline="27" begincolumn="1" endcolumn="41" rule="ImportFromSamePackage" ruleset="Error Prone" package="org.openapitools.client.model" class="PetTest" externalInfoUrl="https://pmd.github.io/pmd-6.23.0/pmd_rules_java_errorprone.html#importfromsamepackage" priority="3">

            No need to import a type that lives in the same package

        </violation>

    </file>

</pmd>

 
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。