1

我在使用 Checkstyle Suppression 文件配置的 Sonar Eclipse Plugin 和 Sonar Local Analysis 时遇到问题。

我在用:

  • 声纳 3.5.1
  • Maven 3.0.4
  • 日食朱诺 SR2
  • 最新版本的 Sonar Eclipse 插件 (3.1.1)

在 SonarQube UI 中,我在 Settings -> System -> General Settings -> Checkstyle -> Filters 中设置:

<module name="SuppressionCommentFilter" />
<module name="SuppressionFilter">
    <property name="file" value="${main.dir}/config/checkstyle-suppressions.xml" />
</module>

在我的 Maven pom.xml 我有:

<properties>
    <sonar.exclusions>**/gener/*.java</sonar.exclusions>
    <main.dir>${basedir}/..</main.dir>
</properties>

当我运行本地分析属性时,正确使用了sonar.exclusions ,但是对于 Checkstyle,我得到了异常:

org.xml.sax.SAXException: Property ${main.dir} has not been set

当我从 Jenkins 运行“远程”分析时,main.dir被正确使用。

那么,为什么不将main.dir也用于本地分析呢?或者问题出在哪里?

在文档中是:

可以在各个地方设置配置本地分析的参数。这是参数的层次结构:

  • SonarQube Web UI 中定义的参数

  • pom.xml 文件中设置的参数(仅适用于 Maven 项目,安装了 m2e 连接器)将覆盖 UI 中定义的参数

  • Eclipse 中定义的参数将覆盖 pom 文件中定义的参数(转到 Window > Preferences > Sonar > Local analysis properties)
  • 在 Eclipse 中在项目级别定义的参数将覆盖在 Eclipse 级别定义的参数(右键单击项目并转到 Properties > Sonar > Local analysis properties)

非常感谢您的任何回复。

完成 StackTrace:

Exception in thread "main" org.sonar.runner.impl.RunnerException: Unable to execute Sonar
    at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:79)
    at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:63)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:57)
    at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
    at org.sonar.runner.impl.BatchLauncherMain.execute(BatchLauncherMain.java:41)
    at org.sonar.runner.impl.BatchLauncherMain.main(BatchLauncherMain.java:59)
Caused by: org.sonar.api.utils.SonarException: Can not execute Checkstyle
    at org.sonar.plugins.checkstyle.CheckstyleExecutor.execute(CheckstyleExecutor.java:89)
    at org.sonar.plugins.checkstyle.CheckstyleSensor.analyse(CheckstyleSensor.java:44)
    at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:70)
    at org.sonar.batch.phases.Phases.execute(Phases.java:101)
    at org.sonar.batch.scan.ScanContainer.doStart(ScanContainer.java:147)
    at org.sonar.batch.bootstrap.Container.start(Container.java:72)
    at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:65)
    at org.sonar.batch.scan.ScanTask.scanRecursively(ScanTask.java:56)
    at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:49)
    at org.sonar.batch.bootstrap.TaskContainer.doStart(TaskContainer.java:188)
    at org.sonar.batch.bootstrap.Container.start(Container.java:72)
    at org.sonar.batch.bootstrap.TaskBootstrapContainer.executeTask(TaskBootstrapContainer.java:73)
    at org.sonar.batch.bootstrap.TaskBootstrapContainer.doStart(TaskBootstrapContainer.java:62)
    at org.sonar.batch.bootstrap.Container.start(Container.java:72)
    at org.sonar.batch.bootstrap.BootstrapContainer.doStart(BootstrapContainer.java:104)
    at org.sonar.batch.bootstrap.Container.start(Container.java:72)
    at org.sonar.batch.bootstrapper.Batch.startBatch(Batch.java:88)
    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:72)
    at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:45)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:75)
    ... 6 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: unable to read
C:\Development\Java\workspace\eclipse\Juno\SR2\x86\CSA\TRUNK\.metadata\.plugins
\org.eclipse.core.resources\.projects\mfgw-module-ffp-fbp-upgrade-core-ejb
\org.sonar.ide.eclipse.core\checkstyle.xml - unable to parse configuration stream - 
Property ${main.dir} has not been set
    at com.puppycrawl.tools.checkstyle.ConfigurationLoader.loadConfiguration(ConfigurationLoader.java:346)
    at com.puppycrawl.tools.checkstyle.ConfigurationLoader.loadConfiguration(ConfigurationLoader.java:286)
    at org.sonar.plugins.checkstyle.CheckstyleConfiguration.toCheckstyleConfiguration(CheckstyleConfiguration.java:113)
    at org.sonar.plugins.checkstyle.CheckstyleConfiguration.getCheckstyleConfiguration(CheckstyleConfiguration.java:107)
    at org.sonar.plugins.checkstyle.CheckstyleExecutor.execute(CheckstyleExecutor.java:83)
    ... 29 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: unable to parse 
configuration stream - Property ${main.dir} has not been set
    at com.puppycrawl.tools.checkstyle.ConfigurationLoader.loadConfiguration(ConfigurationLoader.java:410)
    at com.puppycrawl.tools.checkstyle.ConfigurationLoader.loadConfiguration(ConfigurationLoader.java:338)
    ... 33 more
 Caused by: org.xml.sax.SAXException: Property ${main.dir} has not been set
    at com.puppycrawl.tools.checkstyle.ConfigurationLoader$InternalLoader.startElement(ConfigurationLoader.java:158)
    at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
    at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
    at org.apache.xerces.impl.dtd.XMLDTDValidator.emptyElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at com.puppycrawl.tools.checkstyle.api.AbstractLoader.parseInputSource(AbstractLoader.java:98)
    at com.puppycrawl.tools.checkstyle.ConfigurationLoader.parseInputSource(ConfigurationLoader.java:273)
    at com.puppycrawl.tools.checkstyle.ConfigurationLoader.loadConfiguration(ConfigurationLoader.java:397)
    ... 34 more
4

0 回答 0