Skip to content
This repository was archived by the owner on Nov 22, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ A sample project is available on GitHub, can be [browsed](https://github.com/Son
- copy the jar (in the new generated target folder) in <path_to_your_sonar_install>/extensions/plugins folder,
- restart sonar

## Upgrade Android Lint
1. Change `lint.version` in `pom.xml`
2. Ensure `lint-rules-gen` compiles, `cd lint-rules-gen` `mvn clean compile`
3. Run `lint-rules-gen` - `mvn clean compile exec:java`
4. Copy the generated XML to the correct location (from the root directory)
`cp lint-rules-gen/out/org/sonar/plugins/android/lint/android_lint_sonar_way.xml sonar-android-plugin/src/main/resources/org/sonar/plugins/android/lint/android_lint_sonar_way.xml`
`cp lint-rules-gen/out/org/sonar/plugins/android/lint/rules.xml sonar-android-plugin/src/main/resources/org/sonar/plugins/android/lint/rules.xml`
5. go to `its/plugin/projects/SonarAndroidSample` and run `gradlew lint`
6. Run the tests from the base directory `mvn clean install`, fix as necessary.
7. Add missing rules to: `sonar-android-plugin/src/main/resources/org/sonar/plugins/android/lint
/java-model.xml`

## Running an analyse:
1. On a Maven project
- mvn sonar:sonar -Dsonar.profile="Android Lint" in your project
Expand Down
Empty file modified cix.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion its/plugin/projects/SonarAndroidSample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
checkAllWarnings true
absolutePaths false
lintConfig file("lint.xml")
xmlOutput file("lint-report-build.xml")
xmlOutput file("lint-results.xml")
}
}

Expand Down
116 changes: 116 additions & 0 deletions its/plugin/projects/SonarAndroidSample/app/lint-results.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<issues format="4" by="lint 25.1.7">

<issue
id="SuspiciousImport"
severity="Warning"
message="Don&apos;t include `android.R` here; use a fully qualified name for each usage instead"
category="Correctness"
priority="9"
summary="&apos;`import android.R`&apos; statement"
explanation="Importing `android.R` is usually not intentional; it sometimes happens when you use an IDE and ask it to automatically add imports at a time when your project&apos;s R class it not present.

Once the import is there you might get a lot of &quot;confusing&quot; error messages because of course the fields available on `android.R` are not the ones you&apos;d expect from just looking at your own `R` class."
errorLine1="import android.R;"
errorLine2="~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/org/sonarsource/app/TestViolations.java"
line="3"
column="1"/>
</issue>

<issue
id="GradleDeprecated"
severity="Warning"
message="&apos;android&apos; is deprecated; use &apos;com.android.application&apos; instead"
category="Correctness"
priority="6"
summary="Deprecated Gradle Construct"
explanation="This detector looks for deprecated Gradle constructs which currently work but will likely stop working in a future update."
errorLine1="apply plugin: &apos;android&apos;"
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~"
quickfix="studio">
<location
file="build.gradle"
line="1"
column="1"/>
</issue>

<issue
id="NewApi"
severity="Error"
message="Call requires API level 9 (current min is 7): `android.os.StrictMode#enableDefaults`"
category="Correctness"
priority="6"
summary="Calling new methods on older versions"
explanation="This check scans through all the Android API calls in the application and warns about any calls that are not available on *all* versions targeted by this application (according to its minimum SDK attribute in the manifest).

If you really want to use this API and don&apos;t need to support older devices just set the `minSdkVersion` in your `build.gradle` or `AndroidManifest.xml` files.
If your code is *deliberately* accessing newer APIs, and you have ensured (e.g. with conditional execution) that this code will only ever be called on a supported platform, then you can annotate your class or method with the `@TargetApi` annotation specifying the local minimum SDK to apply, such as `@TargetApi(11)`, such that this check considers 11 rather than your manifest file&apos;s minimum SDK as the required API level.

If you are deliberately setting `android:` attributes in style definitions, make sure you place this in a `values-vNN` folder in order to avoid running into runtime conflicts on certain devices where manufacturers have added custom attributes whose ids conflict with the new ones on later platforms.

Similarly, you can use tools:targetApi=&quot;11&quot; in an XML file to indicate that the element will only be inflated in an adequate context."
errorLine1=" StrictMode.enableDefaults();"
errorLine2=" ~~~~~~~~~~~~~~"
quickfix="studio,adt">
<location
file="src/main/java/org/sonarsource/app/TestViolations.java"
line="10"
column="20"/>
</issue>

<issue
id="OldTargetApi"
severity="Warning"
message="Not targeting the latest versions of Android; compatibility modes apply. Consider testing and updating this version. Consult the android.os.Build.VERSION_CODES javadoc for details."
category="Correctness"
priority="6"
summary="Target SDK attribute is not targeting latest version"
explanation="When your application runs on a version of Android that is more recent than your `targetSdkVersion` specifies that it has been tested with, various compatibility modes kick in. This ensures that your application continues to work, but it may look out of place. For example, if the `targetSdkVersion` is less than 14, your app may get an option button in the UI.

To fix this issue, set the `targetSdkVersion` to the highest available value. Then test your app to make sure everything works correctly. You may want to consult the compatibility notes to see what changes apply to each version you are adding support for: http://developer.android.com/reference/android/os/Build.VERSION_CODES.html"
url="http://developer.android.com/reference/android/os/Build.VERSION_CODES.html"
urls="http://developer.android.com/reference/android/os/Build.VERSION_CODES.html"
errorLine1=" targetSdkVersion 19"
errorLine2=" ~~~~~~~~~~~~~~~~~~~"
quickfix="studio">
<location
file="build.gradle"
line="9"
column="9"/>
</issue>

<issue
id="GradleDynamicVersion"
severity="Warning"
message="Avoid using + in version numbers; can lead to unpredictable and unrepeatable builds (com.android.support:appcompat-v7:19.1.+)"
category="Correctness"
priority="4"
summary="Gradle Dynamic Version"
explanation="Using `+` in dependencies lets you automatically pick up the latest available version rather than a specific, named version. However, this is not recommended; your builds are not repeatable; you may have tested with a slightly different version than what the build server used. (Using a dynamic version as the major version number is more problematic than using it in the minor version position.)"
errorLine1=" compile &apos;com.android.support:appcompat-v7:19.1.+&apos;"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
quickfix="studio">
<location
file="build.gradle"
line="29"
column="5"/>
</issue>

<issue
id="IconMissingDensityFolder"
severity="Warning"
message="Missing density variation folders in `src/main/res`: drawable-xxxhdpi"
category="Usability:Icons"
priority="3"
summary="Missing density folder"
explanation="Icons will look best if a custom version is provided for each of the major screen density classes (low, medium, high, extra-high, extra-extra-high). This lint check identifies folders which are missing, such as `drawable-hdpi`.
Low density is not really used much anymore, so this check ignores the ldpi density. To force lint to include it, set the environment variable `ANDROID_LINT_INCLUDE_LDPI=true`. For more information on current density usage, see http://developer.android.com/resources/dashboard/screens.html"
url="http://developer.android.com/guide/practices/screens_support.html"
urls="http://developer.android.com/guide/practices/screens_support.html">
<location
file="src/main/res"/>
</issue>

</issues>
Loading