【问题标题】:Sonar-runner execution failure causing cast exceptionSonar-runner 执行失败导致转换异常
【发布时间】:2014-04-13 22:08:15
【问题描述】:

配置声纳工具(SonarQube、MySql 数据库和 Sonar-runner)后,我对 Android 项目进行了分析,没有任何问题。但是在安装了声纳的Android插件并重复分析后,这个失败了,得到下一个错误:

INFO  - Preview mode
Load batch settings
User cache: /home/user/.sonar/cache
INFO  - Install plugins
INFO  - Exclude plugins: devcockpit, jira, pdfreport, views, report, buildstability, scmactivity, buildbreaker
INFO  - Create JDBC datasource for jdbc:h2:/home/user/workspace/myAndroidProject/.sonar/.sonartmp/preview1394469024394-0
INFO  - Initializing Hibernate
INFO  - Load project settings
INFO  - Apply project exclusions
INFO  - -------------  Scan myAndroidProject
INFO  - Load module settings
INFO  - Language is forced to java
INFO  - Loading technical debt model...
INFO  - Loading technical debt model done: 424 ms
INFO  - Configure Maven plugins
INFO  - Base dir: /home/user/workspace/myAndroidProject
INFO  - Working dir: /home/user/workspace/myAndroidProject/.sonar
INFO  - Source dirs: /home/user/workspace/myAdnroidProject/src
INFO  - Source encoding: UTF-8, default locale: en_EN
INFO  - Index files
INFO  - Included sources: 
INFO  -   src/**
INFO  - 116 files indexed
WARN  - Accessing the filesystem before the Sensor phase is deprecated and will not be supported in the future. Please update your plugin.
INFO  - Index files
INFO  - Included sources: 
INFO  -   src/**
INFO  - 116 files indexed
WARN  - Accessing the filesystem before the Sensor phase is deprecated and will not be supported in the future. Please update your plugin.
INFO  - Index files
INFO  - Included sources: 
INFO  -   src/**
INFO  - 116 files indexed
INFO  - Quality profile for java: Sonar way
INFO  - Sensor JavaSourceImporter...
INFO  - Sensor JavaSourceImporter done: 49 ms
INFO  - Sensor JavaSquidSensor...
INFO  - Java AST scan...
INFO  - 116 source files to be analyzed
INFO  - 116/116 source files analyzed
INFO  - Java AST scan done: 6693 ms
WARN  - Java bytecode has not been made available to the analyzer. The Depth of Inheritance Tree (DIT) metric, Response for Class (RFC) metric, Number of Children (NOC) metric, Lack of Cohesion (LCOM4) metric, deperecated dependencies metrics, UnusedPrivateMethod rule, RedundantThrowsDeclarationCheck rule, S1160 rule, S1217 rule are disabled.
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 18.440s
Final Memory: 12M/357M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: org.sonar.api.resources.Directory cannot be cast to    org.sonar.api.resources.JavaPackage

我的 sonar-project.properties 文件是 enxt:

#Required metadata
sonar.projectKey=mKey
sonar.projectName=myAndroidProject
sonar.projectVersion=1.0

# Paths to source directories.
# Paths are relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Do not put the "sonar-project.properties" file in the same directory with the source code.
# (i.e. never set the "sonar.sources" property to ".")
sonar.sources=src

# The value of the property must be the key of the language.
sonar.language=java

# Encoding of the source code
sonar.sourceEncoding=UTF-8

# Analysis mode
sonar.analysis.mode=preview


#Enables the Lint profile to analyze the code using the Lint rules.
#sonar.profile=Android Lint

我正在使用下一个环境:

  • SonarQube 4.2 RC1
  • Sonar-runner 2.3
  • 数据库:MySQL
  • Ubuntu 12.04 LTS
  • Java 1.7

我尝试卸载 Android 插件,但问题仍然存在。我发现解决它的唯一方法是删除数据库和用户并重新创建它们。

【问题讨论】:

  • INFO - Create JDBC datasource for jdbc:h2:/home/user/... 这表明您仍在使用 H2 数据库。
  • #sonar.jdbc.url=jdbc:h2:tcp://localhost:9092/sonar #sonar.embeddedDatabase.dataDir= #sonar.embeddedDatabase.port=9092 我已经评论了这行。我认为@David RACODON - SonarSource 的响应是最准确的。

标签: java android mysql sonarqube sonar-runner


【解决方案1】:

【讨论】:

  • 谢谢!!三天可怕的研究这个,最后我找到了一些希望。那么还有另一种使用插件的可能性,也许是旧版本?
  • 以 4.1.2 为例,这是最新的稳定版本。见sonarqube.org/downloadsdocs.codehaus.org/display/SONAR/Plugin+version+matrix
  • 我已经更新了我的声纳版本,我还在 Sonar 中安装了 Android 插件来添加 Lint 配置文件。在 sonar.properties 文件中,我有 sonar.profile=Android Lint 行来运行 Lint 配置文件。但是在执行分析之后,我遇到了这个错误:Lint must be invoked with the System property com.android.tools.lint.bindir pointing to the ANDROID_SDK tools directory。我有 ANDROID_HOME 环境变量指向 sdk 目录,所以我不知道我还能做什么。
  • 我建议您等待 Android 插件的 1.0 版本。它将消除对 Android SDK 的依赖。见jira.codehaus.org/browse/SONARANDRO-14jira.codehaus.org/secure/…
【解决方案2】:

您需要将二进制文件(字节码 .class 文件)提供给声纳执行器。 将以下行添加到您的 sonar-project.properties

# Path to the class files
sonar.binaries=build\\classes\\main

如果上述行不起作用,请检查您的二进制文件实际路径并将其放在 sonar.binaries 属性中

【讨论】:

    猜你喜欢
    • 2015-06-15
    • 1970-01-01
    • 2013-10-14
    • 2013-08-09
    • 2014-09-12
    • 1970-01-01
    • 2013-05-20
    • 2016-12-12
    • 2011-12-25
    相关资源
    最近更新 更多