声纳:创建针对Android林特新规则(Sonar: Create new rule for And

2019-10-23 04:30发布

我为了收集所有的Java皮棉错误for Android应用程序使用SonarQube 5.1。

几乎每一个重要的问题是通过声纳使用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元素)。

我已阅读有关声纳创建新规则的文件 ,但我仍然感到困惑。 我已经下载了对XML SSLR并执行它找到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>

...和XPath来寻找minSdkVersion元素是:

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

我不知道我现在必须做的。 此外,SonarQube 5.1 Web界面已经改变了,我不明白如何将XPath字符串添加新的规则。

任何帮助将非常感激!

Answer 1:

无意中我发现如何做到这一点。 脚步:

  1. 管理员身份登录或其他用户有足够的权限。
  2. 寻找的XPath规则的语言,XML在这种情况下。
  3. 创建不久的“自定义规则”文本按钮并填写表格。

不要忘了激活您的个人资料这个自定义规则。

PS:恕我直言,根本的问题是,文件没有被更新,而绝大多数的网址正在打破,由于Codehaus的终止 。 直到老断开的链接会被纠正,这将是巨大的,如果进行自动重定向。



文章来源: Sonar: Create new rule for Android Lint