Articles → SONARQUBE → Run Sonar Scanner

Run Sonar Scanner






Android Project




package com.example.demo_application;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Log.v("METHOD", "onCreate called");
  }

  @Override
  protected void onStart() {
    super.onStart();
    Log.v("METHOD", "onStart called");
  }

  @Override
  protected void onResume() {
    super.onResume();
    Log.v("METHOD", "onResume called");
  }

  @Override
  protected void onPause() {
    super.onPause();
    Log.v("METHOD", "onPause called");
  }

  @Override
  protected void onStop() {
    super.onStop();
    Log.v("METHOD", "onStop called");
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    Log.v("METHOD", "onDestroy called");
  }

  @Override
  protected void onRestart() {
    super.onRestart();
    Log.v("METHOD", "onRestart called");
  }

}



Sonar Scanner Properties File




sonar.host.url=http://localhost:9000
sonar.sourceEncoding=UTF-8
sonar.projectKey=android-sample-1
sonar.projectName=Sonar_demo_project_1
sonar.projectVersion=1.0
sonar.scm.disabled=True
sonar.sources=src/main/java
sonar.language=android
sonar.java.binaries=build/outputs/apk/debug




  1. First line specifies the URL of the sonarqube server.
  2. Second line specifies the encoding used in the source code.
  3. Third parameter is the project key, which is the unique id given to the project.
  4. Fourth parameter is the project name.
  5. Fifth parameter is the version of code.
  6. Sixth parameter is the path of source code.
  7. Seventh parameter is the language in which your code is written.

Run Sonar Scanner




  1. Open powershell.
  2. Go the path of sonar-project.properties file using cd command.
  3. Run the following command.
  4. sonar-scanner.bat




Picture showing the execution of sonar-scanner.bat command
Click to Enlarge


Check The Result




  1. Go to http://localhost:9000
  2. Login to the server using ‘admin’ as user name and ‘admin’ as password.
  3. On the home page, you can see the project scanned
  4. Picture showing the home page of sonarqube admin
    Click to Enlarge

  5. Click on the project name (‘Sonar_demo_project_1’ in this case)
  6. In the detail screen, you can see the results of scan in more categorized way
  7. Picture showing the detailed screen of the selected project in sonarqube admin
    Click to Enlarge

  8. Click on the any category (like we can click on ‘Code Smells’ in this case).
  9. You can see the list of issues
  10. Picture showing the code smells in the selected project
    Click to Enlarge

  11. You can click on the issue to get more details
  12. Picture showing the detailed code smells in the selected project
    Click to Enlarge



Posted By  -  Karan Gupta
 
Posted On  -  Monday, September 30, 2019

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250