Skip to content

Commit a2192b4

Browse files
shaundodd-diffblueKT-DiffbluemorganmazerThomasPerkins1123yuzhong1
committed
Add Diffblue SonarQube plugin 1.0.0
Co-authored-by: Kevin Tse <kevin.tse@diffblue.com> Co-authored-by: KT-Diffblue <kevin.tse@diffblue.com> Co-authored-by: morganmazer <morgan.mazer@diffblue.com> Co-authored-by: Shaun Dodd <shaun.dodd@diffblue.com> Co-authored-by: thomasperkins1123 <thomasperkins1123@gmail.com> Co-authored-by: yuzhong1 <yu.zhong@diffblue.com>
0 parents  commit a2192b4

File tree

47 files changed

+4750
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4750
-0
lines changed

.github/scripts/check-version.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
CURRENT_VERSION=$(awk -F'[<>]' '/<revision>/ {print $3; exit}' pom.xml)
5+
echo "Current version: '$CURRENT_VERSION'"
6+
echo "current_version=$CURRENT_VERSION" >> "$GITHUB_ENV"
7+
8+
if [[ "$CURRENT_VERSION" == *-SNAPSHOT ]]; then
9+
echo "::warning::Version '$CURRENT_VERSION' is a SNAPSHOT"
10+
echo "skip=true" >> "$GITHUB_ENV"
11+
echo "skip_reason=snapshot" >> "$GITHUB_ENV"
12+
elif PREVIOUS_VERSION=$(git describe --tags --abbrev=0 2>/dev/null); then
13+
echo "Previous version: '$PREVIOUS_VERSION'"
14+
if [[ "v$CURRENT_VERSION" == "$PREVIOUS_VERSION" ]]; then
15+
echo "::warning::Version number has not changed from $PREVIOUS_VERSION"
16+
echo "skip=true" >> "$GITHUB_ENV"
17+
echo "skip_reason=unchanged" >> "$GITHUB_ENV"
18+
else
19+
echo "skip=false" >> "$GITHUB_ENV"
20+
fi
21+
else
22+
echo "No previous tags found, first release"
23+
echo "skip=false" >> "$GITHUB_ENV"
24+
fi

.github/workflows/release.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Release to GitHub
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout this branch
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Set up JDK
18+
uses: actions/setup-java@v4
19+
with:
20+
distribution: 'adopt'
21+
java-version: '17'
22+
cache: 'maven'
23+
24+
- name: Check version number has been increased
25+
run: .github/scripts/check-version.sh
26+
27+
- name: Configure GPG Key
28+
if: ${{ env.skip == 'false' }}
29+
run: |
30+
echo -n "$GPG_KEY_BASE64" | base64 --decode | gpg --batch --passphrase ${GPG_PASSPHRASE} --import
31+
env:
32+
GPG_KEY_BASE64: ${{ secrets.GPG_KEY_BASE64 }}
33+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
34+
35+
- name: Build and sign artifact
36+
if: ${{ env.skip == 'false' }}
37+
run: |
38+
mvn install -B -P sign -Dgpg.passphrase="$GPG_PASSPHRASE"
39+
env:
40+
GPG_ID: ${{ secrets.GPG_ID }}
41+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
42+
43+
- name: Create Release on GitHub
44+
if: ${{ env.skip == 'false' }}
45+
env:
46+
GH_TOKEN: ${{ github.token }}
47+
run: |
48+
git tag "v${{ env.current_version }}"
49+
git push origin "v${{ env.current_version }}"
50+
gh release create "v${{ env.current_version }}" --repo="$GITHUB_REPOSITORY" --title="v${{ env.current_version }}" --generate-notes \
51+
sonar-plugin/target/diffblue-sonar-plugin-"${{ env.current_version }}".jar \
52+
sonar-plugin/target/diffblue-sonar-plugin-"${{ env.current_version }}".jar.asc
53+
54+
- name: Create mergeback PR
55+
if: ${{ env.skip == 'false' }}
56+
continue-on-error: true
57+
env:
58+
GH_TOKEN: ${{ github.token }}
59+
run: |
60+
gh pr create --head main --base develop \
61+
--title "Mergeback: v${{ env.current_version }} into develop" \
62+
--body "Automated mergeback of release v${{ env.current_version }} into develop."
63+
gh pr merge main --auto --merge

.github/workflows/test.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Build and Test
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
- develop
9+
10+
jobs:
11+
build-and-test:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v2
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Set up JDK
21+
uses: actions/setup-java@v4
22+
with:
23+
distribution: 'adopt'
24+
java-version: '17'
25+
cache: 'maven'
26+
27+
- name: Run Spotless Check
28+
run: mvn spotless:check
29+
30+
- name: Run Unit and Integration Tests
31+
run: mvn install
32+
33+
release-check:
34+
if: github.event_name == 'pull_request' && github.base_ref == 'main'
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v4
39+
with:
40+
fetch-depth: 0
41+
42+
- name: Set up JDK
43+
uses: actions/setup-java@v4
44+
with:
45+
distribution: 'adopt'
46+
java-version: '17'
47+
cache: 'maven'
48+
49+
- name: Check version number has been increased
50+
run: .github/scripts/check-version.sh
51+
52+
- name: Fail if version is not releasable
53+
if: ${{ env.skip == 'true' }}
54+
run: |
55+
echo "::error::Version check failed: ${{ env.skip_reason }}"
56+
exit 1
57+
58+
- name: Configure GPG Key
59+
run: |
60+
echo -n "$GPG_KEY_BASE64" | base64 --decode | gpg --batch --passphrase ${GPG_PASSPHRASE} --import
61+
env:
62+
GPG_KEY_BASE64: ${{ secrets.GPG_KEY_BASE64 }}
63+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
64+
65+
- name: Build and sign artifact
66+
run: mvn install -B -P sign -Dgpg.passphrase="$GPG_PASSPHRASE"
67+
env:
68+
GPG_ID: ${{ secrets.GPG_ID }}
69+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
70+
71+
- name: Upload artifact
72+
id: upload
73+
uses: actions/upload-artifact@v4
74+
with:
75+
name: diffblue-sonar-plugin-${{ env.current_version }}
76+
path: |
77+
sonar-plugin/target/diffblue-sonar-plugin-${{ env.current_version }}.jar
78+
sonar-plugin/target/diffblue-sonar-plugin-${{ env.current_version }}.jar.asc
79+
80+
- name: Comment artifact link on PR
81+
env:
82+
GH_TOKEN: ${{ github.token }}
83+
run: |
84+
ARTIFACT_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.upload.outputs.artifact-id }}"
85+
gh pr comment "${{ github.event.pull_request.number }}" --body "$(cat <<EOF
86+
**Build artifact for v${{ env.current_version }}**
87+
88+
[Download diffblue-sonar-plugin-${{ env.current_version }}]($ARTIFACT_URL)
89+
EOF
90+
)"

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# IntelliJ
2+
.idea/*
3+
4+
# Maven
5+
target/
6+
.flattened-pom.xml
7+
8+
# Diffblue
9+
.diffblue/
10+
!**/src/test/resources/**/.diffblue/
11+
!test-examples/.diffblue/

CONTRIBUTING.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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

Comments
 (0)