|
| 1 | +# Contributing to Diffblue SonarQube Plugin |
| 2 | + |
| 3 | +This guide will help you set up your development environment and walk through the testing workflow for making changes to the plugin. |
| 4 | + |
| 5 | +## Development Prerequisites |
| 6 | + |
| 7 | +- Java Development Kit (JDK 17 or higher) |
| 8 | +- Maven 3.6+ |
| 9 | +- A local instance of SonarQube Community Edition |
| 10 | +- Diffblue Cover CLI (for generating test coverage data - optional) |
| 11 | +- A Java project with Diffblue tests present for testing |
| 12 | + |
| 13 | +## Initial Setup |
| 14 | + |
| 15 | +### 1. Set Up SonarQube Locally |
| 16 | + |
| 17 | +Download and set up a local instance of **SonarQube Community Edition** from the [official SonarQube downloads page](https://www.sonarqube.org/downloads/). |
| 18 | + |
| 19 | +### 2. Prepare a Test Project |
| 20 | + |
| 21 | +Pick a Java project to use for testing the plugin. For convenience, you can clone the [SonarQube Example Repository](https://github.com/diffblue/SonarQube-Example-Repo), which includes pre-generated Diffblue tests and metadata. |
| 22 | + |
| 23 | +### 3. Configure SonarQube |
| 24 | + |
| 25 | +1. Create a new project in your local SonarQube instance. |
| 26 | +2. Configure the **Analysis Method** to "Locally". |
| 27 | +3. Generate a SonarQube authentication token through the UI. |
| 28 | +4. Store this token somewhere secure for later use. |
| 29 | + |
| 30 | +## Development Workflow |
| 31 | + |
| 32 | +### Building the Plugin |
| 33 | + |
| 34 | +Build the SonarQube plugin JAR file from the project root: |
| 35 | + |
| 36 | +```bash |
| 37 | +mvn clean package |
| 38 | +``` |
| 39 | + |
| 40 | +This produces the plugin JAR at `sonar-plugin/target/diffblue-sonar-plugin-X.X.X-SNAPSHOT.jar`. |
| 41 | + |
| 42 | +### Installing Your Build |
| 43 | + |
| 44 | +1. Copy the produced JAR to the `extensions/plugins/` directory of your SonarQube installation, replacing any previous versions: |
| 45 | + |
| 46 | + ```bash |
| 47 | + cp sonar-plugin/target/diffblue-sonar-plugin-X.X.X-SNAPSHOT.jar ~/sonarqube-25.11.0.114957/extensions/plugins/ |
| 48 | + ``` |
| 49 | + |
| 50 | +2. Restart SonarQube to load the new version of the plugin: |
| 51 | + |
| 52 | + ```bash |
| 53 | + # Navigate to your SonarQube installation directory |
| 54 | + ./bin/[your-platform]/sonar.sh restart |
| 55 | + ``` |
| 56 | + |
| 57 | +### Running an Analysis |
| 58 | + |
| 59 | +Run the SonarQube analysis on your test project using the Maven command provided by SonarQube: |
| 60 | + |
| 61 | +```bash |
| 62 | +mvn clean verify sonar:sonar \ |
| 63 | + -Dsonar.projectKey=Your-Project-Key \ |
| 64 | + -Dsonar.projectName='Your Project Name' \ |
| 65 | + -Dsonar.host.url=http://localhost:9000 \ |
| 66 | + -Dsonar.token=YOUR_TOKEN_HERE |
| 67 | +``` |
| 68 | + |
| 69 | +Replace `Your-Project-Key`, `Your Project Name`, and `YOUR_TOKEN_HERE` with the appropriate values for your test project. |
| 70 | + |
| 71 | +### Viewing Results |
| 72 | + |
| 73 | +1. Open the SonarQube UI at `http://localhost:9000`. |
| 74 | +2. Navigate to your project. |
| 75 | +3. View the latest measures, including the Diffblue coverage metrics. |
| 76 | + |
| 77 | +## Testing Changes |
| 78 | + |
| 79 | +When making changes to the plugin, follow this iteration cycle: |
| 80 | + |
| 81 | +1. Make your code changes. |
| 82 | +2. Build the plugin: `mvn clean package` |
| 83 | +3. Copy the new JAR to SonarQube's plugins directory. |
| 84 | +4. Restart SonarQube. |
| 85 | +5. Run the analysis on your test project. |
| 86 | +6. Verify the changes in the SonarQube UI. |
| 87 | +7. Repeat as needed. |
| 88 | + |
| 89 | +## Debugging and Logs |
| 90 | + |
| 91 | +### Analysis-Time Logs |
| 92 | + |
| 93 | +When running the analysis locally, log messages from **DiffblueCoverageSensor** will appear in the console where you execute the `mvn sonar:sonar` command. These logs show information about: |
| 94 | +- Detection of Diffblue coverage files |
| 95 | +- Processing of coverage data |
| 96 | +- Any errors or warnings during sensor execution |
| 97 | + |
| 98 | +### Server-Side Logs |
| 99 | + |
| 100 | +Log lines from the **DiffblueMeasureComputer** and **PercentageMeasureComputer** can be found in SonarQube's server log, as this component runs server-side after the analysis completes. |
| 101 | + |
| 102 | +To view server logs: |
| 103 | +- Navigate to your SonarQube installation directory |
| 104 | +- Check `logs/sonar.log` or `logs/web.log` |
| 105 | + |
| 106 | +## Code Style and Standards |
| 107 | + |
| 108 | +- Follow standard Java coding conventions |
| 109 | +- Write clear, descriptive commit messages |
| 110 | +- Include unit tests for new functionality |
| 111 | +- Run the code formatter before submitting changes: `mvn spotless:apply` |
| 112 | +- Ensure all tests pass before submitting changes: `mvn clean test` |
| 113 | + |
| 114 | +## Questions or Issues? |
| 115 | + |
| 116 | +If you encounter problems or have questions: |
| 117 | +- Check existing [GitHub Issues](https://github.com/diffblue/diffblue-sonar-plugin/issues) |
| 118 | +- Open a new issue with detailed information about your problem |
| 119 | +- Include relevant logs and SonarQube/plugin versions |
| 120 | +- Contact Diffblue with [support@Diffblue.com](support@Diffblue.com) |
| 121 | + |
| 122 | +Thank you for contributing to the Diffblue SonarQube Plugin! |
0 commit comments