Skip to content

Commit

Permalink
Merge pull request #72 from jycr/feature/integration-test
Browse files Browse the repository at this point in the history
Improved integration tests
  • Loading branch information
dedece35 authored Nov 3, 2024
2 parents d5f7ebd + 61e7603 commit 7c569bc
Show file tree
Hide file tree
Showing 45 changed files with 3,167 additions and 35 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ jobs:
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 11
java-version: 17

- name: Cache Maven packages
uses: actions/cache@v3
Expand All @@ -40,12 +40,6 @@ jobs:
- name: Verify
run: ./mvnw -e -B verify

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17

- name: Cache SonarQube packages
uses: actions/cache@v3
with:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- [#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
- [#53](https://github.com/green-code-initiative/ecoCode-java/issues/53) Improve integration tests

### Changed

Expand Down
35 changes: 15 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,28 @@ the [ecoCode repository](https://github.com/green-code-initiative/ecoCode#-sonar
🚀 Getting Started
------------------

You can give a try with a one command docker :
You can give a try with a one command:

```sh
docker run -ti --rm \
-p 9000:9000 \
--name sonarqube-ecocode-java ghcr.io/green-code-initiative/sonarqube-ecocode-java:latest
./mvnw verify -Pkeep-running
```

or (with logs and data locally stored) :
... 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)

```sh
docker run -ti --rm \
-v sq_ecocode_logs:/opt/sonarqube/logs \
-v sq_ecocode_data:/opt/sonarqube/data \
-p 9000:9000 \
--name sonarqube-ecocode-java ghcr.io/green-code-initiative/sonarqube-ecocode-java:latest
```
NB: To install other `ecocode` plugins, you can :

... 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).
- 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.

To install other `ecocode` plugins, you can also :
For example :

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

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)
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)

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)
... 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).

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

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

> Compatibility table of versions lower than 1.4.+ are available from the
> main [ecoCode repository](https://github.com/green-code-initiative/ecoCode#-plugins-version-compatibility).
Expand Down
161 changes: 154 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>io.ecocode</groupId>
<artifactId>ecocode-java-plugin</artifactId>
<version>1.6.3-SNAPSHOT</version>

<packaging>sonar-plugin</packaging>

<name>ecoCode - Java language</name>
Expand Down Expand Up @@ -53,8 +53,13 @@
<sonar.organization>green-code-initiative</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>

<sonarqube.version>9.4.0.54424</sonarqube.version>
<sonarjava.version>7.19.0.31550</sonarjava.version>
<!-- Version of SonarQube for integration tests -->
<sonarqube.version>9.9.7.96285</sonarqube.version>
<!-- Version of the SonarQube APIs used by `ecocode-java-plugin` -->
<sonar.plugin.api.version>9.8.0.203</sonar.plugin.api.version>

<!-- Version of `sonar-java-plugin` that `ecocode-java-plugin` depends on -->
<sonarjava.version>7.16.0.30901</sonarjava.version>

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

Expand All @@ -66,9 +71,22 @@

<google.re2j>1.7</google.re2j>

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

<!-- URL of the Maven repository where sonarqube will be downloaded -->
<test-it.orchestrator.artifactory.url>https://repo1.maven.org/maven2</test-it.orchestrator.artifactory.url>
<!-- You can override this property to keep SonarQube instance running and to manually use it -->
<test-it.sonarqube.keepRunning>false</test-it.sonarqube.keepRunning>

<!-- Version of `sonarqube` used by integration tests (you can override this value to perform matrix compatibility tests) -->
<test-it.sonarqube.version>${sonarqube.version}</test-it.sonarqube.version>

<!-- Version of `sonar-java-plugin` used by integration tests (you can override this value to perform matrix compatibility tests) -->
<test-it.sonarjava.version>${sonarjava.version}</test-it.sonarjava.version>

<!-- SonarQube server listening port. Leave this property blank to automatically choose an available port. -->
<test-it.sonarqube.port />
</properties>

<dependencies>
Expand All @@ -88,9 +106,9 @@
</dependency>

<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<groupId>org.sonarsource.api.plugin</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${sonarqube.version}</version>
<version>${sonar.plugin.api.version}</version>
<scope>provided</scope>
</dependency>

Expand Down Expand Up @@ -142,6 +160,44 @@
<version>0.10.2</version>
<scope>test</scope>
</dependency>

<!-- Dependencies used by integration tests -->
<dependency>
<groupId>org.sonarsource.orchestrator</groupId>
<artifactId>sonar-orchestrator-junit5</artifactId>
<version>4.9.0.1920</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.java</groupId>
<artifactId>test-classpath-reader</artifactId>
<version>8.5.0.37199</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-ws</artifactId>
<version>${sonarqube.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.jycr</groupId>
<artifactId>java-data-url-handler</artifactId>
<version>0.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.6</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -333,8 +389,11 @@
<licenseSet>
<header>com/mycila/maven/plugin/license/templates/GPL-3.txt</header>
<includes>
<include>**/*.java</include>
<include>${project.basedir}/src/**/*.java</include>
</includes>
<excludes>
<exclude>${project.basedir}/src/it/test-projects/**</exclude>
</excludes>
</licenseSet>
</licenseSets>
</configuration>
Expand All @@ -348,6 +407,94 @@
</execution>
</executions>
</plugin>
<!-- activate integration tests -->
<plugin>
<!-- add integration test sources into test classpath -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<id>add-integration-test-sources</id>
<phase>process-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${project.basedir}/src/it/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-integration-test-resources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${project.basedir}/src/it/resources</directory>
</resource>
<resource>
<filtering>true</filtering>
<directory>${project.basedir}/src/it/resources-filtered</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- Execute integration tests -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.2.5</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<test-it.sonarqube.keepRunning>${test-it.sonarqube.keepRunning}</test-it.sonarqube.keepRunning>
<test-it.orchestrator.artifactory.url>${test-it.orchestrator.artifactory.url}</test-it.orchestrator.artifactory.url>
<test-it.sonarqube.version>${test-it.sonarqube.version}</test-it.sonarqube.version>
<test-it.sonarqube.port>${test-it.sonarqube.port}</test-it.sonarqube.port>
<!-- Comma separated list of plugins (`groupId|artifactId|version` or `file:///`) to install in SonarQube instance before lunching integration tests -->
<test-it.plugins>
${project.baseUri}/target/${project.artifactId}-${project.version}.jar,
org.sonarsource.java:sonar-java-plugin:${test-it.sonarjava.version},
</test-it.plugins>
<!-- Comma separated JSON profile file URIs to load -->
<test-it.additional-profile-uris>
${project.baseUri}/src/main/resources/fr/greencodeinitiative/java/ecoCode_way_profile.json,
</test-it.additional-profile-uris>
<!-- Comma separated paths of "test projects" to analyze. Syntaxe: `sonar.projectKey|sonar.projectName|project.pomUri` -->
<test-it.test-projects>
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,
</test-it.test-projects>
<!-- Comma separated list of profiles to associate to each "test project". Syntaxe: `language:profileName` -->
<test-it.test-project-profile-by-language>
java|ecoCode way,
</test-it.test-project-profile-by-language>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>keep-running</id>
<properties>
<test-it.sonarqube.keepRunning>true</test-it.sonarqube.keepRunning>
<test-it.sonarqube.port>9000</test-it.sonarqube.port>
</properties>
</profile>
</profiles>
</project>
Loading

0 comments on commit 7c569bc

Please sign in to comment.