Skip to content

Commit 7c569bc

Browse files
authored
Merge pull request #72 from jycr/feature/integration-test
Improved integration tests
2 parents d5f7ebd + 61e7603 commit 7c569bc

45 files changed

Lines changed: 3167 additions & 35 deletions

File tree

Some content is hidden

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

.github/workflows/build.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ jobs:
2424
with:
2525
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
2626

27-
- name: Set up JDK 11
27+
- name: Set up JDK 17
2828
uses: actions/setup-java@v3
2929
with:
3030
distribution: 'temurin'
31-
java-version: 11
31+
java-version: 17
3232

3333
- name: Cache Maven packages
3434
uses: actions/cache@v3
@@ -40,12 +40,6 @@ jobs:
4040
- name: Verify
4141
run: ./mvnw -e -B verify
4242

43-
- name: Set up JDK 17
44-
uses: actions/setup-java@v3
45-
with:
46-
distribution: 'temurin'
47-
java-version: 17
48-
4943
- name: Cache SonarQube packages
5044
uses: actions/cache@v3
5145
with:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- [#59](https://github.com/green-code-initiative/ecoCode-java/pull/59) Add builtin profile `ecoCode way` to aggregate all implemented ecoCode rules by this plugin
13+
- [#53](https://github.com/green-code-initiative/ecoCode-java/issues/53) Improve integration tests
1314

1415
### Changed
1516

README.md

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,28 @@ the [ecoCode repository](https://github.com/green-code-initiative/ecoCode#-sonar
2626
🚀 Getting Started
2727
------------------
2828

29-
You can give a try with a one command docker :
29+
You can give a try with a one command:
3030

3131
```sh
32-
docker run -ti --rm \
33-
-p 9000:9000 \
34-
--name sonarqube-ecocode-java ghcr.io/green-code-initiative/sonarqube-ecocode-java:latest
32+
./mvnw verify -Pkeep-running
3533
```
3634

37-
or (with logs and data locally stored) :
35+
... then you can use Java test project repository to test the environment : see [Java test project in `./src/it/test-projects/ecocode-java-plugin-test-project`](./src/it/test-projects/ecocode-java-plugin-test-project)
3836

39-
```sh
40-
docker run -ti --rm \
41-
-v sq_ecocode_logs:/opt/sonarqube/logs \
42-
-v sq_ecocode_data:/opt/sonarqube/data \
43-
-p 9000:9000 \
44-
--name sonarqube-ecocode-java ghcr.io/green-code-initiative/sonarqube-ecocode-java:latest
45-
```
37+
NB: To install other `ecocode` plugins, you can :
4638

47-
... and configure local SonarQube (security config and quality profile : see [configuration](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/INSTALL.md#configuration-sonarqube) for more details).
39+
- add JAVA System properties `Dtest-it.additional-plugins` with a comma separated list of plugin IDs (`groupId:artifactId:version`), or plugins JAR (`file://....`) to install.
4840

49-
To install other `ecocode` plugins, you can also :
41+
For example :
5042

51-
- download each plugin separatly and copy the plugin (jar file) to `$SONAR_INSTALL_DIR/extensions/plugins` and restart SonarQube.
43+
```sh
44+
./mvnw verify -Pkeep-running -Dtest-it.additional-plugins=org.sonarsource.javascript:sonar-plugin:10.1.0.21143
45+
```
5246
- install different ecocode plugins with Marketplace (inside admin panel of SonarQube)
5347

54-
Then you can use Java test project repository to test the environment : see README.md of [Java test project](https://github.com/green-code-initiative/ecoCode-java-test-project)
48+
You can also directly use a [all-in-one docker-compose](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/INSTALL.md#start-sonarqube-if-first-time)
5549

56-
Finally, you can directly use a [all-in-one docker-compose](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/INSTALL.md#start-sonarqube-if-first-time)
50+
... and configure local SonarQube (security config and quality profile : see [configuration](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/INSTALL.md#configuration-sonarqube) for more details).
5751

5852
🛒 Distribution
5953
------------------
@@ -63,9 +57,10 @@ Ready to use binaries are available [from GitHub](https://github.com/green-code-
6357
🧩 Compatibility
6458
-----------------
6559

66-
| Plugin version | SonarQube version | Java version |
67-
|----------------|---------------------|--------------|
68-
| 1.6.+ | 9.4.+ LTS to 10.6.0 | 11 / 17 |
60+
| Plugin version | SonarQube version | Java version |
61+
|----------------|---------------------|------------------------------------------------------------------------------------------------|
62+
| 1.6.+ | 9.4.+ LTS to 10.6.0 | 11 / 17 |
63+
| 2.0.+ | 9.9.+ LTS to 10.6.0 | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) |
6964

7065
> Compatibility table of versions lower than 1.4.+ are available from the
7166
> main [ecoCode repository](https://github.com/green-code-initiative/ecoCode#-plugins-version-compatibility).

pom.xml

Lines changed: 154 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>io.ecocode</groupId>
66
<artifactId>ecocode-java-plugin</artifactId>
77
<version>1.6.3-SNAPSHOT</version>
8-
8+
99
<packaging>sonar-plugin</packaging>
1010

1111
<name>ecoCode - Java language</name>
@@ -53,8 +53,13 @@
5353
<sonar.organization>green-code-initiative</sonar.organization>
5454
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
5555

56-
<sonarqube.version>9.4.0.54424</sonarqube.version>
57-
<sonarjava.version>7.19.0.31550</sonarjava.version>
56+
<!-- Version of SonarQube for integration tests -->
57+
<sonarqube.version>9.9.7.96285</sonarqube.version>
58+
<!-- Version of the SonarQube APIs used by `ecocode-java-plugin` -->
59+
<sonar.plugin.api.version>9.8.0.203</sonar.plugin.api.version>
60+
61+
<!-- Version of `sonar-java-plugin` that `ecocode-java-plugin` depends on -->
62+
<sonarjava.version>7.16.0.30901</sonarjava.version>
5863

5964
<sonar-analyzer-commons.version>2.5.0.1358</sonar-analyzer-commons.version>
6065

@@ -66,9 +71,22 @@
6671

6772
<google.re2j>1.7</google.re2j>
6873

69-
<!-- temporary version waiting for real automatic release in ecocode repository -->
74+
<!-- Version of ecoCode rules specifications implemented by this plugin -->
7075
<ecocode-rules-specifications.version>1.6.5</ecocode-rules-specifications.version>
7176

77+
<!-- URL of the Maven repository where sonarqube will be downloaded -->
78+
<test-it.orchestrator.artifactory.url>https://repo1.maven.org/maven2</test-it.orchestrator.artifactory.url>
79+
<!-- You can override this property to keep SonarQube instance running and to manually use it -->
80+
<test-it.sonarqube.keepRunning>false</test-it.sonarqube.keepRunning>
81+
82+
<!-- Version of `sonarqube` used by integration tests (you can override this value to perform matrix compatibility tests) -->
83+
<test-it.sonarqube.version>${sonarqube.version}</test-it.sonarqube.version>
84+
85+
<!-- Version of `sonar-java-plugin` used by integration tests (you can override this value to perform matrix compatibility tests) -->
86+
<test-it.sonarjava.version>${sonarjava.version}</test-it.sonarjava.version>
87+
88+
<!-- SonarQube server listening port. Leave this property blank to automatically choose an available port. -->
89+
<test-it.sonarqube.port />
7290
</properties>
7391

7492
<dependencies>
@@ -88,9 +106,9 @@
88106
</dependency>
89107

90108
<dependency>
91-
<groupId>org.sonarsource.sonarqube</groupId>
109+
<groupId>org.sonarsource.api.plugin</groupId>
92110
<artifactId>sonar-plugin-api</artifactId>
93-
<version>${sonarqube.version}</version>
111+
<version>${sonar.plugin.api.version}</version>
94112
<scope>provided</scope>
95113
</dependency>
96114

@@ -142,6 +160,44 @@
142160
<version>0.10.2</version>
143161
<scope>test</scope>
144162
</dependency>
163+
164+
<!-- Dependencies used by integration tests -->
165+
<dependency>
166+
<groupId>org.sonarsource.orchestrator</groupId>
167+
<artifactId>sonar-orchestrator-junit5</artifactId>
168+
<version>4.9.0.1920</version>
169+
<scope>test</scope>
170+
</dependency>
171+
<dependency>
172+
<groupId>org.sonarsource.java</groupId>
173+
<artifactId>test-classpath-reader</artifactId>
174+
<version>8.5.0.37199</version>
175+
<scope>test</scope>
176+
</dependency>
177+
<dependency>
178+
<groupId>org.sonarsource.sonarqube</groupId>
179+
<artifactId>sonar-ws</artifactId>
180+
<version>${sonarqube.version}</version>
181+
<scope>test</scope>
182+
</dependency>
183+
<dependency>
184+
<groupId>io.github.jycr</groupId>
185+
<artifactId>java-data-url-handler</artifactId>
186+
<version>0.0.1</version>
187+
<scope>test</scope>
188+
</dependency>
189+
<dependency>
190+
<groupId>org.slf4j</groupId>
191+
<artifactId>slf4j-api</artifactId>
192+
<version>2.0.13</version>
193+
<scope>test</scope>
194+
</dependency>
195+
<dependency>
196+
<groupId>ch.qos.logback</groupId>
197+
<artifactId>logback-classic</artifactId>
198+
<version>1.5.6</version>
199+
<scope>test</scope>
200+
</dependency>
145201
</dependencies>
146202

147203
<build>
@@ -333,8 +389,11 @@
333389
<licenseSet>
334390
<header>com/mycila/maven/plugin/license/templates/GPL-3.txt</header>
335391
<includes>
336-
<include>**/*.java</include>
392+
<include>${project.basedir}/src/**/*.java</include>
337393
</includes>
394+
<excludes>
395+
<exclude>${project.basedir}/src/it/test-projects/**</exclude>
396+
</excludes>
338397
</licenseSet>
339398
</licenseSets>
340399
</configuration>
@@ -348,6 +407,94 @@
348407
</execution>
349408
</executions>
350409
</plugin>
410+
<!-- activate integration tests -->
411+
<plugin>
412+
<!-- add integration test sources into test classpath -->
413+
<groupId>org.codehaus.mojo</groupId>
414+
<artifactId>build-helper-maven-plugin</artifactId>
415+
<version>3.6.0</version>
416+
<executions>
417+
<execution>
418+
<id>add-integration-test-sources</id>
419+
<phase>process-test-sources</phase>
420+
<goals>
421+
<goal>add-test-source</goal>
422+
</goals>
423+
<configuration>
424+
<sources>
425+
<source>${project.basedir}/src/it/java</source>
426+
</sources>
427+
</configuration>
428+
</execution>
429+
<execution>
430+
<id>add-integration-test-resources</id>
431+
<phase>generate-test-resources</phase>
432+
<goals>
433+
<goal>add-test-resource</goal>
434+
</goals>
435+
<configuration>
436+
<resources>
437+
<resource>
438+
<directory>${project.basedir}/src/it/resources</directory>
439+
</resource>
440+
<resource>
441+
<filtering>true</filtering>
442+
<directory>${project.basedir}/src/it/resources-filtered</directory>
443+
</resource>
444+
</resources>
445+
</configuration>
446+
</execution>
447+
</executions>
448+
</plugin>
449+
<plugin>
450+
<!-- Execute integration tests -->
451+
<groupId>org.apache.maven.plugins</groupId>
452+
<artifactId>maven-failsafe-plugin</artifactId>
453+
<version>3.2.5</version>
454+
<executions>
455+
<execution>
456+
<goals>
457+
<goal>integration-test</goal>
458+
<goal>verify</goal>
459+
</goals>
460+
<configuration>
461+
<systemPropertyVariables>
462+
<test-it.sonarqube.keepRunning>${test-it.sonarqube.keepRunning}</test-it.sonarqube.keepRunning>
463+
<test-it.orchestrator.artifactory.url>${test-it.orchestrator.artifactory.url}</test-it.orchestrator.artifactory.url>
464+
<test-it.sonarqube.version>${test-it.sonarqube.version}</test-it.sonarqube.version>
465+
<test-it.sonarqube.port>${test-it.sonarqube.port}</test-it.sonarqube.port>
466+
<!-- Comma separated list of plugins (`groupId|artifactId|version` or `file:///`) to install in SonarQube instance before lunching integration tests -->
467+
<test-it.plugins>
468+
${project.baseUri}/target/${project.artifactId}-${project.version}.jar,
469+
org.sonarsource.java:sonar-java-plugin:${test-it.sonarjava.version},
470+
</test-it.plugins>
471+
<!-- Comma separated JSON profile file URIs to load -->
472+
<test-it.additional-profile-uris>
473+
${project.baseUri}/src/main/resources/fr/greencodeinitiative/java/ecoCode_way_profile.json,
474+
</test-it.additional-profile-uris>
475+
<!-- Comma separated paths of "test projects" to analyze. Syntaxe: `sonar.projectKey|sonar.projectName|project.pomUri` -->
476+
<test-it.test-projects>
477+
io.ecocode:ecocode-java-plugin-test-project|ecoCode Java Sonar Plugin Test Project|${project.baseUri}/src/it/test-projects/ecocode-java-plugin-test-project/pom.xml,
478+
</test-it.test-projects>
479+
<!-- Comma separated list of profiles to associate to each "test project". Syntaxe: `language:profileName` -->
480+
<test-it.test-project-profile-by-language>
481+
java|ecoCode way,
482+
</test-it.test-project-profile-by-language>
483+
</systemPropertyVariables>
484+
</configuration>
485+
</execution>
486+
</executions>
487+
</plugin>
351488
</plugins>
352489
</build>
490+
491+
<profiles>
492+
<profile>
493+
<id>keep-running</id>
494+
<properties>
495+
<test-it.sonarqube.keepRunning>true</test-it.sonarqube.keepRunning>
496+
<test-it.sonarqube.port>9000</test-it.sonarqube.port>
497+
</properties>
498+
</profile>
499+
</profiles>
353500
</project>

0 commit comments

Comments
 (0)