用于python自定义规则的SonarQube ClassNotFoundException

时间:2016-11-24 15:28:15

标签: python sonarqube classnotfoundexception

我已经配置了我的SonarQube服务器和我的python项目,以便进行各种分析......(很正常......)

我想添加一条规则,以确保我在所有python脚本文件的开头放置了许可证/版权文本。使用sslr-python-toolkit-1.5应用程序,我成功创建了规则XPath,并且还在SonarQube服务器上创建并激活了规则。

但是,当我发起声纳分析时,我有一个堆栈跟踪:

ERROR: Error during SonarQube Scanner execution
org.sonar.api.utils.SonarException: Unable to initialize the XPath engine, perhaps because of an invalid query: //FILE_INPUT/STATEMENT[0][@tokenValue[not(contains(.,"''' Copyright .... '''"))]]
        at org.sonar.squidbridge.checks.AbstractXPathCheck.init(AbstractXPathCheck.java:47)
        at org.sonar.squidbridge.AstScanner.scanFiles(AstScanner.java:82)
        at org.sonar.plugins.python.PythonSquidSensor.execute(PythonSquidSensor.java:106)
        at org.sonar.batch.sensor.SensorWrapper.analyse(SensorWrapper.java:57)
        at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:58)
        at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:50)
        at org.sonar.batch.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:83)
        at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:192)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
        at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:241)
        at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:236)
        at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:234)
        at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:226)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
        at org.sonar.batch.task.ScanTask.execute(ScanTask.java:47)
        at org.sonar.batch.task.TaskContainer.doAfterStart(TaskContainer.java:86)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
        at org.sonar.batch.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:106)
        at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:119)
        at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:62)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
        at com.sun.proxy.$Proxy0.execute(Unknown Source)
        at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)
        at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
        at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:110)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:74)
        at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.RuntimeException: org.jaxen.JaxenException: org.jaxen.saxpath.base.XPathReader
        at com.google.common.base.Throwables.propagate(Throwables.java:156)
        at com.sonar.sslr.xpath.api.AstNodeXPathQuery.<init>(AstNodeXPathQuery.java:39)
        at com.sonar.sslr.xpath.api.AstNodeXPathQuery.create(AstNodeXPathQuery.java:103)
        at org.sonar.squidbridge.checks.AbstractXPathCheck.init(AbstractXPathCheck.java:45)
        ... 33 more
Caused by: org.jaxen.JaxenException: org.jaxen.saxpath.base.XPathReader
        at org.jaxen.BaseXPath.<init>(BaseXPath.java:125)
        at org.jaxen.BaseXPath.<init>(BaseXPath.java:142)
        at com.sonar.sslr.xpath.api.AstNodeXPathQuery.<init>(AstNodeXPathQuery.java:37)
        ... 35 more
Caused by: org.jaxen.saxpath.SAXPathException: org.jaxen.saxpath.base.XPathReader
        at org.jaxen.saxpath.helpers.XPathReaderFactory.createReader(XPathReaderFactory.java:152)
        at org.jaxen.saxpath.helpers.XPathReaderFactory.createReader(XPathReaderFactory.java:110)
        at org.jaxen.BaseXPath.<init>(BaseXPath.java:113)
        ... 37 more
Caused by: java.lang.ClassNotFoundException: org.jaxen.saxpath.base.XPathReader
        at org.sonar.classloader.ParentFirstStrategy.loadClass(ParentFirstStrategy.java:39)
        at org.sonar.classloader.ClassRealm.loadClass(ClassRealm.java:87)
        at org.sonar.classloader.ClassRealm.loadClass(ClassRealm.java:76)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at org.jaxen.saxpath.helpers.XPathReaderFactory.createReader(XPathReaderFactory.java:137)
        ... 39 more
  1. 我尝试使用命令行启动声纳扫描仪

    / usr / bin / java -cp sslr-python-toolkit-1.5.jar:sonar-scanner-cli-2.8.jar -Dscanner.home = / opt / sonar-scanner -project.home = / home / dev / workspaces / pepyt org.sonarsource.scanner.cli.Main

  2. 但结果相同......

    1. 我已将两个罐子解压缩到一个目录中而没有任何变化......
    2. 经过一番搜索后,我发现了一些关于SONAR_SCANNER_OPTS环境变量的声纳-java-libraries的帖子...如果使用了环境变量(在声纳运行日志中看到)并没有解决问题。 ..
    3. 我把sslr-python-toolkit-1.5.jar库放在我的声纳主目录的lib目录中没有成功
    4. 我没想到了......

      如何将sslr python库添加到我的sonar-scanner类路径中,以便使用我的自定义规则分析代码?

      Cormandyr

1 个答案:

答案 0 :(得分:0)

这是SonarQube Python插件中的bug。它将在下一个版本中修复。感谢您的反馈!