2015-05-20 23 views
1

新規則,我使用SonarQube 5.1,以收集所有的Java林特誤差爲的Android應用程序聲納:創建針對Android林特

幾乎每一個重要的問題是通過聲納使用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> 

...和XPath來尋找minSdkVersion元素是:

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

我不知道我現在必須做的。此外,SonarQube 5.1 web界面已經改變,我看不到如何將XPath字符串添加到新規則。

任何幫助將非常感激!

+0

順便說一句,到SonarQube文檔的舊鏈接目前已被打破,如下所示:http://docs.codehaus.org/display/SONAR/Extending++oding+Rules。 SonarSource有人可以修復它? – frapen

+1

是的,這是一個正在進行的過程,由於CodeHaus的關閉 - 新的URL是http://docs.sonarqube.org/display/DEV/Extending+Coding+Rules – Mithfindel

回答

1

我意外地發現瞭如何做到這一點。步驟:

  1. 身份登錄管理員或其他用戶有足夠的權限。
  2. Look for XPath rule爲語言,在這種情況下爲XML。
  3. 創建按鈕靠近「自定義規則」文本並填寫表格。

不要忘記在您的個人資料中激活此自定義規則。

PS:恕我直言,底層的問題是文檔沒有更新,並且絕大多數的URL目前都被破壞,由於CodeHaus termination。直到舊的斷開的鏈接將被糾正,如果執行自動重定向,那將會很好。

+0

我在哪裏需要以管理員身份登錄?在聲納儀表板上? – Shruti

+0

喲需要在右上角「搜索圖標」旁邊「登錄」。默認情況下,登錄名是「admin」| 「管理員」。 – frapen

+0

如何合併在手動規則庫中創建的這個新規則在android-sonar-master中? – Shruti