不能在Eclipse中导入PMD规则集吗

时间:2021-08-16 10:33:56

I would like to use the same Ruleset in my IDE (Eclipse) that my Sonar profile.

我想在我的IDE (Eclipse)中使用与我的声纳配置文件相同的规则集。

I got the PMD XML ruleset from the Sonar Permalinks and would like to import it into my PMD Eclipse Plugin but when i try to do it, the "OK" button is desactivated ...

我从Sonar Permalinks中获得PMD XML规则集,并希望将其导入到PMD Eclipse插件中,但当我尝试这么做时,“OK”按钮被禁用……

不能在Eclipse中导入PMD规则集吗

Can someone help me ?

有人能帮我吗?

6 个解决方案

#1


13  

The problem could be that Sonar is exporting your ruleset for v4.x format and your Eclipse plugin expects them in v5.x format.

问题可能是,声纳正在向v4输出您的规则集。x格式和Eclipse插件都希望在v5中实现。x格式。

Try changing your rules from:

试着改变你的规则:

<rule ref="rulesets/basic.xml/UnusedNullCheckInEquals">
    <priority>3</priority>
</rule>

to

<rule ref="rulesets/java/basic.xml/UnusedNullCheckInEquals">
    <priority>3</priority>
</rule>

Please note the ref attribute. A simple find and replace all will work out fine for you.

请注意ref属性。一个简单的发现和替换将会对你很好。

#2


3  

The advice from Ivan Nikolov helped me, but I had to also change one rule from:

伊凡·尼科洛夫(Ivan Nikolov)的建议帮助了我,但我也不得不改变一条规则:

<rule ref="rulesets/java/controversial.xml/UnusedModifier">
  <priority>5</priority>
</rule>

to

<rule ref="rulesets/java/unusedcode.xml/UnusedModifier">
  <priority>5</priority>
</rule>

Here is my PMD configuration file from sonar which is working for me with PMD-plugin 4.0.2.:

这是我的PMD配置文件,来自sonar,这是我的PMD插件4.0.2。

<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         name="pmd-eclipse"
         xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
  <rule ref="rulesets/java/basic.xml/UnusedNullCheckInEquals">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strings.xml/StringInstantiation">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/ConstructorCallsOverridableMethod">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strictexception.xml/AvoidCatchingNPE">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strictexception.xml/AvoidRethrowingException">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/migrating.xml/ReplaceEnumerationWithIterator">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/optimizations.xml/AvoidArrayLoops">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/unusedcode.xml/UnusedFormalParameter">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/basic.xml/ClassCastExceptionWithToArray">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strictexception.xml/AvoidThrowingNullPointerException">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/unusedcode.xml/UnusedPrivateField">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/CompareObjectsWithEquals">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strings.xml/UseIndexOfChar">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/basic.xml/BigIntegerInstantiation">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/FinalFieldCouldBeStatic">
    <priority>4</priority>
  </rule>
  <rule ref="rulesets/java/naming.xml/SuspiciousEqualsMethodName">
    <priority>2</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/InstantiationToGetClass">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/naming.xml/SuspiciousHashcodeMethodName">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/coupling.xml/LooseCoupling">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/unusedcode.xml/UnusedLocalVariable">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strings.xml/UnnecessaryCaseChange">
    <priority>4</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/SingularField">
    <priority>4</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/CloseResource">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strictexception.xml/AvoidCatchingThrowable">
    <priority>2</priority>
  </rule>
  <rule ref="rulesets/java/basic.xml/CollapsibleIfStatements">
    <priority>4</priority>
  </rule>
  <rule ref="rulesets/java/basic.xml/UselessOperationOnImmutable">
    <priority>2</priority>
  </rule>
  <rule ref="rulesets/java/clone.xml/CloneMethodMustImplementCloneable">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/basic.xml/UselessOverridingMethod">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/unusedcode.xml/UnusedModifier">
    <priority>5</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/PreserveStackTrace">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/optimizations.xml/UseArraysAsList">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/EqualsNull">
    <priority>2</priority>
  </rule>
  <rule ref="rulesets/java/basic.xml/BrokenNullCheck">
    <priority>2</priority>
  </rule>
  <rule ref="rulesets/java/logging-jakarta-commons.xml/UseCorrectExceptionLogging">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strings.xml/InefficientStringBuffering">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/sunsecure.xml/ArrayIsStoredDirectly">
    <priority>2</priority>
  </rule>
  <rule ref="rulesets/java/finalizers.xml/FinalizeOverloaded">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/controversial.xml/DontImportSun">
    <priority>4</priority>
  </rule>
  <rule ref="rulesets/java/imports.xml/DontImportJavaLang">
    <priority>4</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/MissingStaticMethodInNonInstantiatableClass">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strings.xml/StringBufferInstantiationWithChar">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/optimizations.xml/UseArrayListInsteadOfVector">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strings.xml/StringToString">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/SimplifyConditional">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/migrating.xml/ReplaceVectorWithList">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/codesize.xml/NcssMethodCount">
    <priority>3</priority>
    <properties>
      <property name="minimum" value="50" />
    </properties>
  </rule>
  <rule ref="rulesets/java/logging-java.xml/AvoidPrintStackTrace">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/naming.xml/MethodWithSameNameAsEnclosingClass">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/naming.xml/SuspiciousConstantFieldName">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/codesize.xml/NcssTypeCount">
    <priority>3</priority>
    <properties>
      <property name="minimum" value="800" />
    </properties>
  </rule>
  <rule ref="rulesets/java/design.xml/AvoidInstanceofChecksInCatchClause">
    <priority>4</priority>
  </rule>
  <rule ref="rulesets/java/migrating.xml/IntegerInstantiation">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/migrating.xml/AvoidAssertAsIdentifier">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/UnnecessaryLocalBeforeReturn">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/finalizers.xml/AvoidCallingFinalize">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/basic.xml/BooleanInstantiation">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/basic.xml/UnconditionalIfStatement">
    <priority>2</priority>
  </rule>
  <rule ref="rulesets/java/clone.xml/CloneThrowsCloneNotSupportedException">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/migrating.xml/ReplaceHashtableWithMap">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/basic.xml/AvoidDecimalLiteralsInBigDecimalConstructor">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strictexception.xml/SignatureDeclareThrowsException">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/finalizers.xml/EmptyFinalizer">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/IdempotentOperations">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strictexception.xml/ExceptionAsFlowControl">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/finalizers.xml/FinalizeDoesNotCallSuperFinalize">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strings.xml/UseStringBufferLength">
    <priority>4</priority>
  </rule>
  <rule ref="rulesets/java/migrating.xml/AvoidEnumAsIdentifier">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/logging-java.xml/SystemPrintln">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strings.xml/UselessStringValueOf">
    <priority>4</priority>
  </rule>
  <rule ref="rulesets/java/strings.xml/AvoidDuplicateLiterals">
    <priority>3</priority>
  </rule>
</ruleset>

#3


1  

I had to add the language to my XPath rule(s) as well, e.g:

我还必须将该语言添加到XPath规则中,例如:

<rule name="DontUseDate" language="java" class="net.sourceforge.pmd.lang.rule.XPathRule" ...></rule>

#4


0  

In addition to what others said, you may also have to find this:

除了别人说的,你还得找到这个:

net.sourceforge.pmd.rules.XPathRule

and replace it by this:

把它替换为:

net.sourceforge.pmd.lang.rule.XPathRule

#5


0  

Ivan Nikolov's answer is correct. Your problem are different versions of ruleset format . In my case I was trying to import ruleset exported from PMD plugin version 3.2.6 into plugin version 4.0.0. Here are my findings:

Ivan Nikolov的回答是正确的。您的问题是规则集格式的不同版本。在我的例子中,我试图将从PMD插件版本3.2.6导出的规则集导入到插件版本4.0.0中。以下是我的发现:

  • Path change that Ivan Nikolov mentioned is needed for all the rules. Be careful because not all the rules belong to java (I saw also rules for XML,...). I am not that deep into PMD, so I don't know in which version were rules for other technologies introduced.
  • Ivan Nikolov提到的路径改变是所有规则都需要的。要小心,因为不是所有的规则都属于java(我也看到了XML的规则,…)。我对PMD不是很深入,所以我不知道在哪个版本中引入了其他技术的规则。
  • It is useful to export default ruleset of PMD plugin 4.0.0 for comparison with old custom ruleset file. This way you can fix problems that can be spotted at next point.
  • 将PMD插件4.0.0的默认规则集导出,以便与旧的自定义规则集文件进行比较。通过这种方式,您可以修复可以在下一时刻发现的问题。
  • During your behavior was thrown exception that wasn't visualized. This exception can be seen in your workspace log file (/.metadata/.log) at the end. This can give you a clue what else needs to be changed. Use the previous point to find out how to fix problems. In my case it was changed path of one rule from to
  • 在您的行为被抛出异常时,并没有被可视化。在您的工作空间日志文件(/.metadata/.log)中可以看到这个异常。这可以给你一个需要改变的线索。使用前面的点找出解决问题的方法。在我的例子中,它改变了一条规则的路径。

After these changes I was able to import manually migrated custom ruleset file into PMD plugin 4.0.0.

在这些更改之后,我可以将手动迁移的自定义规则集文件导入PMD插件4.0.0。

Hope this helps.

希望这个有帮助。

BTW: I find 4.0.0 version of PMD plugin very buggy so I downgraded back to 3.2.6

顺便说一句:我发现4.0.0版本的PMD插件有很多问题,所以我把它降级为3.2.6版本

#6


-1  

Why don't you use Sonar Eclipse ? You wouldn't need to worry about synchronization of rule sets.

为什么不使用声呐Eclipse ?您不需要担心规则集的同步。

#1


13  

The problem could be that Sonar is exporting your ruleset for v4.x format and your Eclipse plugin expects them in v5.x format.

问题可能是,声纳正在向v4输出您的规则集。x格式和Eclipse插件都希望在v5中实现。x格式。

Try changing your rules from:

试着改变你的规则:

<rule ref="rulesets/basic.xml/UnusedNullCheckInEquals">
    <priority>3</priority>
</rule>

to

<rule ref="rulesets/java/basic.xml/UnusedNullCheckInEquals">
    <priority>3</priority>
</rule>

Please note the ref attribute. A simple find and replace all will work out fine for you.

请注意ref属性。一个简单的发现和替换将会对你很好。

#2


3  

The advice from Ivan Nikolov helped me, but I had to also change one rule from:

伊凡·尼科洛夫(Ivan Nikolov)的建议帮助了我,但我也不得不改变一条规则:

<rule ref="rulesets/java/controversial.xml/UnusedModifier">
  <priority>5</priority>
</rule>

to

<rule ref="rulesets/java/unusedcode.xml/UnusedModifier">
  <priority>5</priority>
</rule>

Here is my PMD configuration file from sonar which is working for me with PMD-plugin 4.0.2.:

这是我的PMD配置文件,来自sonar,这是我的PMD插件4.0.2。

<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         name="pmd-eclipse"
         xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
  <rule ref="rulesets/java/basic.xml/UnusedNullCheckInEquals">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strings.xml/StringInstantiation">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/ConstructorCallsOverridableMethod">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strictexception.xml/AvoidCatchingNPE">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strictexception.xml/AvoidRethrowingException">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/migrating.xml/ReplaceEnumerationWithIterator">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/optimizations.xml/AvoidArrayLoops">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/unusedcode.xml/UnusedFormalParameter">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/basic.xml/ClassCastExceptionWithToArray">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strictexception.xml/AvoidThrowingNullPointerException">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/unusedcode.xml/UnusedPrivateField">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/CompareObjectsWithEquals">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strings.xml/UseIndexOfChar">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/basic.xml/BigIntegerInstantiation">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/FinalFieldCouldBeStatic">
    <priority>4</priority>
  </rule>
  <rule ref="rulesets/java/naming.xml/SuspiciousEqualsMethodName">
    <priority>2</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/InstantiationToGetClass">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/naming.xml/SuspiciousHashcodeMethodName">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/coupling.xml/LooseCoupling">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/unusedcode.xml/UnusedLocalVariable">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strings.xml/UnnecessaryCaseChange">
    <priority>4</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/SingularField">
    <priority>4</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/CloseResource">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strictexception.xml/AvoidCatchingThrowable">
    <priority>2</priority>
  </rule>
  <rule ref="rulesets/java/basic.xml/CollapsibleIfStatements">
    <priority>4</priority>
  </rule>
  <rule ref="rulesets/java/basic.xml/UselessOperationOnImmutable">
    <priority>2</priority>
  </rule>
  <rule ref="rulesets/java/clone.xml/CloneMethodMustImplementCloneable">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/basic.xml/UselessOverridingMethod">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/unusedcode.xml/UnusedModifier">
    <priority>5</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/PreserveStackTrace">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/optimizations.xml/UseArraysAsList">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/EqualsNull">
    <priority>2</priority>
  </rule>
  <rule ref="rulesets/java/basic.xml/BrokenNullCheck">
    <priority>2</priority>
  </rule>
  <rule ref="rulesets/java/logging-jakarta-commons.xml/UseCorrectExceptionLogging">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strings.xml/InefficientStringBuffering">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/sunsecure.xml/ArrayIsStoredDirectly">
    <priority>2</priority>
  </rule>
  <rule ref="rulesets/java/finalizers.xml/FinalizeOverloaded">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/controversial.xml/DontImportSun">
    <priority>4</priority>
  </rule>
  <rule ref="rulesets/java/imports.xml/DontImportJavaLang">
    <priority>4</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/MissingStaticMethodInNonInstantiatableClass">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strings.xml/StringBufferInstantiationWithChar">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/optimizations.xml/UseArrayListInsteadOfVector">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strings.xml/StringToString">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/SimplifyConditional">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/migrating.xml/ReplaceVectorWithList">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/codesize.xml/NcssMethodCount">
    <priority>3</priority>
    <properties>
      <property name="minimum" value="50" />
    </properties>
  </rule>
  <rule ref="rulesets/java/logging-java.xml/AvoidPrintStackTrace">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/naming.xml/MethodWithSameNameAsEnclosingClass">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/naming.xml/SuspiciousConstantFieldName">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/codesize.xml/NcssTypeCount">
    <priority>3</priority>
    <properties>
      <property name="minimum" value="800" />
    </properties>
  </rule>
  <rule ref="rulesets/java/design.xml/AvoidInstanceofChecksInCatchClause">
    <priority>4</priority>
  </rule>
  <rule ref="rulesets/java/migrating.xml/IntegerInstantiation">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/migrating.xml/AvoidAssertAsIdentifier">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/UnnecessaryLocalBeforeReturn">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/finalizers.xml/AvoidCallingFinalize">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/basic.xml/BooleanInstantiation">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/basic.xml/UnconditionalIfStatement">
    <priority>2</priority>
  </rule>
  <rule ref="rulesets/java/clone.xml/CloneThrowsCloneNotSupportedException">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/migrating.xml/ReplaceHashtableWithMap">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/basic.xml/AvoidDecimalLiteralsInBigDecimalConstructor">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strictexception.xml/SignatureDeclareThrowsException">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/finalizers.xml/EmptyFinalizer">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/design.xml/IdempotentOperations">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strictexception.xml/ExceptionAsFlowControl">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/finalizers.xml/FinalizeDoesNotCallSuperFinalize">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strings.xml/UseStringBufferLength">
    <priority>4</priority>
  </rule>
  <rule ref="rulesets/java/migrating.xml/AvoidEnumAsIdentifier">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/logging-java.xml/SystemPrintln">
    <priority>3</priority>
  </rule>
  <rule ref="rulesets/java/strings.xml/UselessStringValueOf">
    <priority>4</priority>
  </rule>
  <rule ref="rulesets/java/strings.xml/AvoidDuplicateLiterals">
    <priority>3</priority>
  </rule>
</ruleset>

#3


1  

I had to add the language to my XPath rule(s) as well, e.g:

我还必须将该语言添加到XPath规则中,例如:

<rule name="DontUseDate" language="java" class="net.sourceforge.pmd.lang.rule.XPathRule" ...></rule>

#4


0  

In addition to what others said, you may also have to find this:

除了别人说的,你还得找到这个:

net.sourceforge.pmd.rules.XPathRule

and replace it by this:

把它替换为:

net.sourceforge.pmd.lang.rule.XPathRule

#5


0  

Ivan Nikolov's answer is correct. Your problem are different versions of ruleset format . In my case I was trying to import ruleset exported from PMD plugin version 3.2.6 into plugin version 4.0.0. Here are my findings:

Ivan Nikolov的回答是正确的。您的问题是规则集格式的不同版本。在我的例子中,我试图将从PMD插件版本3.2.6导出的规则集导入到插件版本4.0.0中。以下是我的发现:

  • Path change that Ivan Nikolov mentioned is needed for all the rules. Be careful because not all the rules belong to java (I saw also rules for XML,...). I am not that deep into PMD, so I don't know in which version were rules for other technologies introduced.
  • Ivan Nikolov提到的路径改变是所有规则都需要的。要小心,因为不是所有的规则都属于java(我也看到了XML的规则,…)。我对PMD不是很深入,所以我不知道在哪个版本中引入了其他技术的规则。
  • It is useful to export default ruleset of PMD plugin 4.0.0 for comparison with old custom ruleset file. This way you can fix problems that can be spotted at next point.
  • 将PMD插件4.0.0的默认规则集导出,以便与旧的自定义规则集文件进行比较。通过这种方式,您可以修复可以在下一时刻发现的问题。
  • During your behavior was thrown exception that wasn't visualized. This exception can be seen in your workspace log file (/.metadata/.log) at the end. This can give you a clue what else needs to be changed. Use the previous point to find out how to fix problems. In my case it was changed path of one rule from to
  • 在您的行为被抛出异常时,并没有被可视化。在您的工作空间日志文件(/.metadata/.log)中可以看到这个异常。这可以给你一个需要改变的线索。使用前面的点找出解决问题的方法。在我的例子中,它改变了一条规则的路径。

After these changes I was able to import manually migrated custom ruleset file into PMD plugin 4.0.0.

在这些更改之后,我可以将手动迁移的自定义规则集文件导入PMD插件4.0.0。

Hope this helps.

希望这个有帮助。

BTW: I find 4.0.0 version of PMD plugin very buggy so I downgraded back to 3.2.6

顺便说一句:我发现4.0.0版本的PMD插件有很多问题,所以我把它降级为3.2.6版本

#6


-1  

Why don't you use Sonar Eclipse ? You wouldn't need to worry about synchronization of rule sets.

为什么不使用声呐Eclipse ?您不需要担心规则集的同步。