Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Import Can';t在Eclipse中导入PMD规则集_Import_Eclipse Plugin_Sonarqube_Rules_Pmd - Fatal编程技术网

Import Can';t在Eclipse中导入PMD规则集

Import Can';t在Eclipse中导入PMD规则集,import,eclipse-plugin,sonarqube,rules,pmd,Import,Eclipse Plugin,Sonarqube,Rules,Pmd,我希望在IDE(Eclipse)中使用与Sonar概要文件相同的规则集 我从Sonar Permalinks获得了PMD XML规则集,并希望将其导入到我的PMD Eclipse插件中,但当我尝试这样做时,“OK”按钮被取消激活 有人能帮我吗?你为什么不使用?您不必担心规则集的同步。问题可能是Sonar正在导出v4.x格式的规则集,而Eclipse插件希望它们是v5.x格式 尝试从以下位置更改规则: <rule ref="rulesets/basic.xml/UnusedNullChec

我希望在IDE(Eclipse)中使用与Sonar概要文件相同的规则集

我从Sonar Permalinks获得了PMD XML规则集,并希望将其导入到我的PMD Eclipse插件中,但当我尝试这样做时,“OK”按钮被取消激活


有人能帮我吗?

你为什么不使用?您不必担心规则集的同步。

问题可能是Sonar正在导出v4.x格式的规则集,而Eclipse插件希望它们是v5.x格式

尝试从以下位置更改规则:

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

3.


3.

请注意ref属性。一个简单的查找并替换所有内容对您来说很好。

伊万·尼科洛夫的答案是正确的。您的问题是规则集格式的不同版本。在我的例子中,我试图将PMD插件版本3.2.6导出的规则集导入插件版本4.0.0。以下是我的发现:

  • 伊万·尼科洛夫(Ivan Nikolov)提到的路径改变对于所有规则都是必要的。要小心,因为并非所有规则都属于java(我还看到了XML规则,…)。我对PMD没有那么深入,所以我不知道在哪个版本中引入了其他技术的规则
  • 导出PMD插件4.0.0的默认规则集以与旧的自定义规则集文件进行比较非常有用。通过这种方式,您可以修复在下一点可以发现的问题
  • 在您的行为被抛出的过程中,出现了无法可视化的异常。此异常可以在末尾的工作区日志文件(/.metadata/.log)中看到。这可以给你一个线索,还有什么需要改变。使用上一点了解如何解决问题。在我的例子中,一条规则的路径从 到
在这些更改之后,我能够将手动迁移的自定义规则集文件导入PMD插件4.0.0

希望这有帮助


顺便说一句:我发现PMD插件的4.0.0版本有很多问题,所以我将其降级到3.2.6,Ivan Nikolov的建议对我有所帮助,但我也不得不改变一条规则:

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

5.


5.
这是我的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.
3.
3.
3.
3.
3.
3.
3.
3.
3.
3.
3.
3.
3.
4.
2.
3.
3.
3.
3.
4.
4.
3.
2.
4.
2.
3.
3.
5.
3.
3.
2.
2.
3.
3.
2.
3.
4.
4.
3.
3.
3.
3.
3.
3.
3.
3.
3.
3.
3.
4.
3.
3.
3.
3.
3.
2.
3.
3.
3.
3.
3.
3.
3.
3.
4.
3.
3.
4.
3.

除了其他人所说的,您可能还必须找到以下内容:

net.sourceforge.pmd.rules.XPathRule
并将其替换为:

net.sourceforge.pmd.lang.rule.XPathRule

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

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


但是使用Sonar Eclipse,运行Complett测试需要很长时间。这里我想使用3个单独的插件(PMD、CheckStyle、Findbugs),因为我可以在特定的包上运行它。。(谢谢你的帮助)好吧,好吧。。。很抱歉,我无法在这方面为您提供更多帮助,因为PMD Eclipse不在我的范围之内。作为一个信息:我们正在努力改进Sonar Eclipse,以便能够运行增量分析:)这将是一个非常好的功能!非常感谢你的帮助!在他的IDE(Eclipse)中直接显示声纳“警告”也很有趣。因为在Sonar Web服务器上看到问题,然后在他的IDE中搜索相关的代码行,这真的很无聊…:-)恩,你不是在说这个吗:?我也有声纳日食的问题。分析花费的时间太长,因为它们是针对整个项目执行的。拥有自动和增量分析将是非常棒的。你知道它是否已经实施了吗?有没有关于什么时候可以使用的预测?只是用SonarQube 3.7和EclipseKepler进行了尝试,但没有成功。这个答案有什么更新吗?另外,你可能还需要使用下面的Dove和KrishPrabakar答案。此外,以下内容也发生了更改-规则UnusedPrivateField、UnusedLocalVariable、UnusedPrivateMethod、UnusedFormalParameter、UnusedModifier从convertive.xml移动到unusedcode.xml。规则design.xml/UseSingleton更改为design.xml/UseUtilityClass
net.sourceforge.pmd.lang.rule.XPathRule
<rule name="DontUseDate" language="java" class="net.sourceforge.pmd.lang.rule.XPathRule" ...></rule>