# projects-sonar ## Getting Started It is imperative that these steps are completed in order, as many of the setup instructions rely on previous steps being completed. ### 1. Updating Required Properties for Elasticsearch Sonarqube will not start without Elasticsearch [Elasticsearch](https://www.elastic.co/), and Elasticsearch cannot start without the system property `vm.max_map_count` configured to a minimum of 262144. Instructions for how to do so on Windows and Unix-based OSs are available on the [Elasticsearch Docker reference guide](https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#_set_vm_max_map_count_to_at_least_262144). To set the `vm.max_map_count` property for the current session(This system setting will only last for the duration of the session), run the following command: ```bash sudo sysctl -w vm.max_map_count=262144 ``` ### 2. Update Your Hosts File Different operating systems, different file paths! Windows: C:\Windows\System32\drivers\etc\hosts Linux / MacOS: /etc/hosts Add the following: ```bash 127.0.0.1 sonar.eclipse.dev.docker ``` ### 3. Start the Application To start the SonarQube instance, run the following command: ```bash docker-compose up -d ``` ### 4. Open and Log In to Sonarqube In a browser, navigate to [localhost:9000](http://localhost:9000) to begin the initial setup. Once logged in for the first time, SonarQube will prompt for a password change. The default login and password fields are both `admin`. Note: it is advised that you select a secure password that will not be forgotten. ### 5. Generate Your Unique Application Token Complete the following steps to generate an application token: - Profile Icon(top right of page) > "My Account" > "Security" tab - Under "Generate Tokens", enter a token name in the text-box. Ex: ef-test - Copy the generated application token. Note: You will not be able to see this token again if you leave this page ### 6. Configuring Your Environment Before any Sonar reports can be generated, the following variables must be set in your local environment: `SONAR_HOST` and `SONAR_TOKEN`. To do this, add the following values to your local `bashrc` file: ```bash export SONAR_TOKEN="" export SONAR_HOST="http://localhost:9000" ``` ### 7. Setting Quality Gate and Profile To configure the Quality Gate: - "Quality Gates"(main menu) > Select "Sonar Way" gate - Click "Copy"(Top right) > Rename to "Ef Way" - Select "Set as Default" (Top right) - Edit the "Coverage" metric to 60% - Click "Add condition" > Check the "On Overall Code" option > Select "Comments (%)" > set to 10% To configure the Quality Profile: - "Quality Profiles"(main menu) - Scroll down to "Java" > Click the Settings icon next to "Sonar way" > Select Copy > Rename to "Ef Way" - Click the new "Ef Way" profile - Click the Settings icon(top right) > "Set as Default" - Click the Settings icon(top right) > "Activate more rules" - Click the "Clear All Filters"(top left) > Search for "type inference" > Select the "Local-Variable Type Inference should be used" rule - Click "Deactivate" for Ef Way profile ## Running the sonar-reports Script The eclipsefdn-webdev-toolkit provides a [simple script](https://gitlab.eclipse.org/eclipsefdn/it/webdev/eclipsefdn-webdev-toolkit/-/blob/master/generate-sonar-reports.sh) for generating Sonar reports for all java APIs. To ensure your local environment is adequately set up to generate meaningful reports, follow the steps listed under [Getting Started](#getting-started).