【问题标题】:Sonar: Create new rule for Android Lint声纳:为 Android Lint 创建新规则
【发布时间】:2015-08-01 11:13:10
【问题描述】:

我正在使用 SonarQube 5.1 来收集 Android 应用的所有 JavaLint 错误。

Sonar 使用 Lint 插件已经发现了几乎所有重要问题,但我发现至少有一个问题不包括在内:

<issue
    id="GradleOverrides"
    severity="Warning"
    message="This `minSdkVersion` value (`14`) is not used; it is always overridden by the value specified in the Gradle build script (`15`)"
    category="Correctness"
    priority="4"
    summary="Value overridden by Gradle build script"
    explanation="The value of (for example) `minSdkVersion` is only used if it is not specified in the `build.gradle` build scripts. When specified in the Gradle build scripts, the manifest value is ignored and can be misleading, so should be removed to avoid ambiguity."
    errorLine1="    &lt;uses-sdk android:minSdkVersion=&quot;14&quot; />"
    errorLine2="              ~~~~~~~~~~~~~~~~~~~~~~~~~~">
    <location
        file="C:\Code\Android\TestApp\app\src\main\AndroidManifest.xml"
        line="5"
        column="15"/>
</issue>

此问题与AndroidManifest.xml(设置Android minSdkVersion 属性的传统方式)和build.gradle(设置minSdkVersion 元素的当前方式)有关。

我已经阅读了documentation about creating new rules in Sonar,但我是 仍然很困惑。我已经下载了SSLR for XML 并执行它来查找XPath 字符串。

我的 XML 文件是:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.juanacaja.testapp" >

    <uses-sdk android:minSdkVersion="14" />

    <application
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

...寻找minSdkVersion 元素的XPath 是:

//manifest/uses-sdk/@android:minSdkVersion

我不确定我现在必须做什么。此外,SonarQube 5.1 Web 界面已更改,我看不到如何将 XPath 字符串添加到新规则中。

任何帮助将不胜感激!

【问题讨论】:

标签: java android xpath sonarqube lint


【解决方案1】:

我偶然发现了如何做到这一点。步骤:

  1. 管理员或其他具有足够权限的用户身份登录。
  2. Look for XPath rule 表示语言,在这种情况下为 XML。
  3. 按“自定义规则”文本附近的创建按钮并填写表单。

不要忘记在您的个人资料中激活此自定义规则。

PS:恕我直言,根本问题是文档未更新,并且绝大多数 URL 目前已损坏,原因是 CodeHaus termination。在旧的断开链接被纠正之前,如果执行自动重定向会很棒。

【讨论】:

  • 我需要在哪里以管理员身份登录?在声纳仪表板上??
  • 您需要在右上角的“搜索图标”旁边“登录”。默认情况下,登录为“admin” | “管理员”。
  • 如何合并在 android-sonar-master 手动规则库下创建的新规则?
  • 尝试按照上面的步骤解释你遇到的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-06-03
  • 1970-01-01
  • 1970-01-01
  • 2015-07-07
  • 1970-01-01
  • 2019-11-20
  • 2013-04-30
相关资源
最近更新 更多