Skip to content

Commit 1439ff6

Browse files
SONARJAVA-5535 Add ruling test (#15)
Co-authored-by: Alban Auzeill <alban.auzeill@sonarsource.com>
1 parent 65c0131 commit 1439ff6

37 files changed

+1820
-0
lines changed

.cirrus.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ container_definition: &CONTAINER_DEFINITION
1717
region: eu-central-1
1818
namespace: default
1919

20+
orchestrator_cache_preparation_definition: &ORCHESTRATOR_CACHE_PREPARATION_DEFINITION
21+
set_orchestrator_home_script: |
22+
export TODAY=$(date '+%Y-%m-%d')
23+
echo "TODAY=${TODAY}" >> $CIRRUS_ENV
24+
echo "ORCHESTRATOR_HOME=${CIRRUS_WORKING_DIR}/orchestrator/${TODAY}" >> $CIRRUS_ENV
25+
mkdir_orchestrator_home_script: |
26+
echo "Create dir ${ORCHESTRATOR_HOME} if needed"
27+
mkdir -p ${ORCHESTRATOR_HOME}
28+
29+
orchestrator_cache_elements_definition: &ORCHESTRATOR_CACHE_ELEMENTS_DEFINITION
30+
folder: ${ORCHESTRATOR_HOME}
31+
fingerprint_script: echo ${TODAY}
32+
reupload_on_changes: "true"
33+
2034
only_sonarsource_qa: &ONLY_SONARSOURCE_QA
2135
only_if: ${CIRRUS_USER_COLLABORATOR} == 'true' && ${CIRRUS_TAG} == "" && (${CIRRUS_PR} != "" || ${CIRRUS_BRANCH} == "master" || ${CIRRUS_BRANCH} =~ "branch-.*" || ${CIRRUS_BRANCH} =~ "dogfood-on-.*")
2236

@@ -41,9 +55,41 @@ build_task:
4155
- regular_mvn_build_deploy_analyze
4256
cleanup_before_cache_script: cleanup_maven_repository
4357

58+
ruling_task:
59+
depends_on:
60+
- build
61+
<<: *ONLY_SONARSOURCE_QA
62+
eks_container:
63+
<<: *CONTAINER_DEFINITION
64+
image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j17-latest
65+
cpu: 14
66+
memory: 8G
67+
maven_cache:
68+
folder: ${CIRRUS_WORKING_DIR}/.m2/repository
69+
<<: *ORCHESTRATOR_CACHE_PREPARATION_DEFINITION
70+
orchestrator_LATEST_RELEASE_cache:
71+
<<: *ORCHESTRATOR_CACHE_ELEMENTS_DEFINITION
72+
submodules_script:
73+
- git submodule update --init --recursive
74+
env:
75+
MAVEN_OPTS: "-Xmx3g"
76+
matrix:
77+
- PROFILE: without-sonarqube-project
78+
- PROFILE: only-sonarqube-project
79+
ruling_script:
80+
- source cirrus-env QA
81+
- source set_maven_build_version $BUILD_NUMBER
82+
- cd its/ruling
83+
- mvn package --batch-mode "-Pit-ruling,$PROFILE" -Dsonar.runtimeVersion=LATEST_RELEASE -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dparallel=methods -DuseUnlimitedThreads=true
84+
cleanup_before_cache_script: cleanup_maven_repository
85+
on_failure:
86+
actual_artifacts:
87+
path: "${CIRRUS_WORKING_DIR}/its/ruling/target/actual/**/*"
88+
4489
promote_task:
4590
depends_on:
4691
- build
92+
- ruling
4793
<<: *ONLY_SONARSOURCE_QA
4894
eks_container:
4995
<<: *CONTAINER_DEFINITION

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "its/sources"]
2+
path = its/sources
3+
url = https://github.com/SonarSource/ruling_java.git
4+
branch = se-engine

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,50 @@ To build the plugin and run its unit tests, execute this command from the projec
3737

3838
mvn clean install
3939

40+
41+
#### Ruling Test
42+
43+
The "Ruling Test" is an integration test suite that launches the analysis of a large code base, saves the issues created by the plugin in
44+
report files, and then compares those results to the set of expected issues (stored as JSON files).
45+
46+
To run the test, first make sure the submodules are checked out:
47+
48+
git submodule update --init --recursive
49+
50+
Then, ensure that the `JAVA_HOME` environment variable is set for the ruling tests execution and that it points to your local JDK 17 installation.
51+
Failing to do so will produce inconsistencies with the expected results.
52+
53+
From the `its/ruling` folder, launch the ruling tests:
54+
55+
mvn clean install -Pit-ruling
56+
# Alternatively
57+
JAVA_HOME=/my/local/java17/jdk/ mvn clean install -Pit-ruling
58+
59+
This test gives you the opportunity to examine the issues created by each rule and make sure they are what you expect.
60+
Any implemented rule is highly likely to raise issues on the multiple projects we use as ruling code base.
61+
62+
* For a newly implemented rule, it means that a first build will most probably fail, caused by differences between expected results
63+
(without any values for the new rule) and the new results. You can inspect these new issues by searching for files named after your rule
64+
(`squid-SXXXX.json`) in the following folder:
65+
66+
/path/to/sonar-java-symbolic-execution/its/ruling/target/actual/...
67+
68+
* For existing rules which are modified, you may expect some differences between "actual" (from new analysis) and expected results.
69+
Review carefully the changes that are shown and update the expected resources accordingly.
70+
71+
All the `json` files contain a list of lines, indexed by file, explaining where the issues raised by a specific rule are located.
72+
If/When everything looks good to you, you can copy the file with the actual issues located at:
73+
74+
its/ruling/target/actual/
75+
76+
Into the directory with the expected issues:
77+
78+
its/ruling/src/test/resources/
79+
80+
For example using the command:
81+
82+
cp its/ruling/target/actual/* its/ruling/src/test/resources/
83+
4084
### License
4185

4286
Copyright 2012-2025 SonarSource.

its/pom.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>org.sonarsource.java</groupId>
9+
<artifactId>sonar-java-symbolic-execution</artifactId>
10+
<version>8.15.0-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>its</artifactId>
14+
<packaging>pom</packaging>
15+
<name>SonarQube Java :: Symbolic Execution :: ITs</name>
16+
17+
<modules>
18+
<module>ruling</module>
19+
</modules>
20+
21+
<properties>
22+
<skipTests>true</skipTests>
23+
<maven.deploy.skip>true</maven.deploy.skip>
24+
</properties>
25+
26+
</project>

its/ruling/pom.xml

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>org.sonarsource.java</groupId>
8+
<artifactId>its</artifactId>
9+
<version>8.15.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>it-java-ruling</artifactId>
13+
14+
<name>SonarQube Java :: Symbolic Execution :: ITs :: Ruling</name>
15+
<inceptionYear>2013</inceptionYear>
16+
17+
<properties>
18+
<surefire.argLine>-server</surefire.argLine>
19+
<maven.test.redirectTestOutputToFile>false</maven.test.redirectTestOutputToFile>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>org.slf4j</groupId>
25+
<artifactId>slf4j-api</artifactId>
26+
<scope>provided</scope>
27+
</dependency>
28+
<dependency>
29+
<groupId>com.google.code.gson</groupId>
30+
<artifactId>gson</artifactId>
31+
<scope>test</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.sonarsource.orchestrator</groupId>
35+
<artifactId>sonar-orchestrator-junit4</artifactId>
36+
<version>${orchestrator.version}</version>
37+
<scope>test</scope>
38+
<exclusions>
39+
<exclusion>
40+
<groupId>com.oracle</groupId>
41+
<artifactId>ojdbc6</artifactId>
42+
</exclusion>
43+
</exclusions>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.sonarsource.sonarqube</groupId>
47+
<artifactId>sonar-ws</artifactId>
48+
<version>${sonar.version}</version>
49+
<scope>test</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.sonarsource.analyzer-commons</groupId>
53+
<artifactId>sonar-performance-measure</artifactId>
54+
<scope>test</scope>
55+
</dependency>
56+
<dependency>
57+
<groupId>junit</groupId>
58+
<artifactId>junit</artifactId>
59+
<scope>test</scope>
60+
</dependency>
61+
<dependency>
62+
<groupId>org.assertj</groupId>
63+
<artifactId>assertj-core</artifactId>
64+
<scope>test</scope>
65+
</dependency>
66+
<dependency>
67+
<groupId>com.google.guava</groupId>
68+
<artifactId>guava</artifactId>
69+
<scope>test</scope>
70+
</dependency>
71+
<dependency>
72+
<groupId>com.google.code.findbugs</groupId>
73+
<artifactId>jsr305</artifactId>
74+
<scope>provided</scope>
75+
</dependency>
76+
<dependency>
77+
<groupId>org.apache.commons</groupId>
78+
<artifactId>commons-lang3</artifactId>
79+
<scope>test</scope>
80+
</dependency>
81+
<dependency>
82+
<groupId>org.sonarsource.java</groupId>
83+
<artifactId>test-classpath-reader</artifactId>
84+
<version>${sonar.java.version}</version>
85+
<scope>test</scope>
86+
</dependency>
87+
<!-- not a direct code dependency, but needed to download it and install it into SonarQube -->
88+
<dependency>
89+
<groupId>org.sonarsource.java</groupId>
90+
<artifactId>sonar-java-plugin</artifactId>
91+
<version>${sonar.java.version}</version>
92+
<scope>test</scope>
93+
</dependency>
94+
<dependency>
95+
<groupId>org.sonarsource.java</groupId>
96+
<artifactId>sonar-java-symbolic-execution-plugin</artifactId>
97+
<version>${project.version}</version>
98+
<scope>test</scope>
99+
</dependency>
100+
</dependencies>
101+
102+
<profiles>
103+
<profile>
104+
<id>it-ruling</id>
105+
<properties>
106+
<skipTests>false</skipTests>
107+
</properties>
108+
</profile>
109+
<profile>
110+
<id>without-sonarqube-project</id>
111+
<build>
112+
<plugins>
113+
<plugin>
114+
<groupId>org.apache.maven.plugins</groupId>
115+
<artifactId>maven-surefire-plugin</artifactId>
116+
<configuration>
117+
<test>!org.sonar.java.it.JavaRulingTest#sonarqube_server</test>
118+
</configuration>
119+
</plugin>
120+
</plugins>
121+
</build>
122+
</profile>
123+
<profile>
124+
<id>only-sonarqube-project</id>
125+
<build>
126+
<plugins>
127+
<plugin>
128+
<groupId>org.apache.maven.plugins</groupId>
129+
<artifactId>maven-surefire-plugin</artifactId>
130+
<configuration>
131+
<test>org.sonar.java.it.JavaRulingTest#sonarqube_server</test>
132+
</configuration>
133+
</plugin>
134+
</plugins>
135+
</build>
136+
</profile>
137+
</profiles>
138+
139+
</project>

0 commit comments

Comments
 (0)