Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade some versions + sonar version from 9.3 to 9.8 #15

Merged
merged 15 commits into from
Dec 25, 2022
Merged
1 change: 1 addition & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Howto build the SonarQube ecoCode plugins

- Java >= 11.0.17
- Mvn 3
- SonarQube 9.4 or higher
dedece35 marked this conversation as resolved.
Show resolved Hide resolved

### Build the code

Expand Down
14 changes: 7 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.3"
services:
sonar:
image: sonarqube:9.3-community
image: sonarqube:9.7-community
dedece35 marked this conversation as resolved.
Show resolved Hide resolved
container_name: sonar_standard
ports:
- "9000:9000"
Expand All @@ -24,12 +24,12 @@ services:
- type: bind
source: ./python-plugin/target/ecocode-python-plugin-0.1.0-SNAPSHOT.jar
target: /opt/sonarqube/extensions/plugins/ecocode-python-plugin-0.1.0-SNAPSHOT.jar
# - type: bind
# source: ./ecolinter-plugin/target/ecocode-ecolinter-plugin-0.1.0-SNAPSHOT.jar
# target: /opt/sonarqube/extensions/plugins/ecocode-ecolinter-plugin-0.1.0-SNAPSHOT.jar
# - type: bind
# source: ./xml-plugin/target/ecocode-xml-plugin-0.1.0-SNAPSHOT.jar
# target: /opt/sonarqube/extensions/plugins/ecocode-xml-plugin-0.1.0-SNAPSHOT.jar
# - type: bind
dedece35 marked this conversation as resolved.
Show resolved Hide resolved
# source: ./ecolinter-plugin/target/ecocode-ecolinter-plugin-0.1.0-SNAPSHOT.jar
# target: /opt/sonarqube/extensions/plugins/ecocode-ecolinter-plugin-0.1.0-SNAPSHOT.jar
# - type: bind
# source: ./xml-plugin/target/ecocode-xml-plugin-0.1.0-SNAPSHOT.jar
# target: /opt/sonarqube/extensions/plugins/ecocode-xml-plugin-0.1.0-SNAPSHOT.jar
- "extensions:/opt/sonarqube/extensions"
- "logs:/opt/sonarqube/logs"
- "data:/opt/sonarqube/data"
Expand Down
45 changes: 33 additions & 12 deletions java-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
<artifactId>sonar-plugin-api</artifactId>
</dependency>

<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api-impl</artifactId>
</dependency>

<dependency>
<groupId>org.sonarsource.analyzer-commons</groupId>
<artifactId>sonar-analyzer-commons</artifactId>
Expand Down Expand Up @@ -68,7 +73,7 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand All @@ -83,9 +88,25 @@
<pluginClass>fr.cnumr.java.MyJavaRulesPlugin</pluginClass>
<sonarLintSupported>true</sonarLintSupported>
<sonarQubeMinVersion>${sonarqube.version}</sonarQubeMinVersion>
<requirePlugins>java:${sonarjava.version}</requirePlugins>
<!-- TODO : commented because plugin not loaded in SONAR if required version of java plugin is not installed -->
<!-- TODO : check how to resolve it (how to force this version in SonarQube installation) -->
<!-- <requirePlugins>java:${sonarjava.version}</requirePlugins> -->
<basePlugin>java</basePlugin>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down Expand Up @@ -116,15 +137,15 @@
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
</artifactItem>
</artifactItems>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
</artifactItem>
</artifactItems>
<outputDirectory>../lib</outputDirectory>
</configuration>
</execution>
Expand All @@ -133,7 +154,7 @@
<id>copy</id>
<phase>test-compile</phase>
<goals>
<goal>copy</goal>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@
import java.util.Collections;
import java.util.Objects;
import java.util.Set;

import org.sonar.api.SonarEdition;
import org.sonar.api.SonarQubeSide;
import org.sonar.api.SonarRuntime;
import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.api.utils.Version;
import org.sonarsource.analyzer.commons.RuleMetadataLoader;

/**
Expand All @@ -46,7 +52,9 @@ public class MyJavaRulesDefinition implements RulesDefinition {
public void define(Context context) {
NewRepository repository = context.createRepository(REPOSITORY_KEY, LANGUAGE).setName(NAME);

RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_BASE_PATH);
SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(9, 7), SonarQubeSide.SCANNER, SonarEdition.DEVELOPER);

RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_BASE_PATH,sonarRuntime);

ruleMetadataLoader.addRulesByAnnotatedClass(repository, new ArrayList<>(RulesList.getChecks()));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package fr.cnumr.java.checks;

import org.junit.jupiter.api.Test;
import org.sonar.java.checks.verifier.JavaCheckVerifier;
import org.sonar.java.checks.verifier.CheckVerifier;

public class AvoidConcatenateStringsInLoopTest {

@Test
public void checkNonCompliantTests() {
JavaCheckVerifier.newVerifier()
CheckVerifier.newVerifier()
.onFile("src/test/files/AvoidConcatenateStringsInLoop.java")
.withCheck(new AvoidConcatenateStringsInLoop())
.verifyIssues();
}

@Test
public void checkCompliantTests() {
JavaCheckVerifier.newVerifier()
CheckVerifier.newVerifier()
.onFile("src/test/files/GoodWayConcatenateStringsLoop.java")
.withCheck(new AvoidConcatenateStringsInLoop())
.verifyNoIssues();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package fr.cnumr.java.checks;

import org.junit.jupiter.api.Test;
import org.sonar.java.checks.verifier.JavaCheckVerifier;
import org.sonar.java.checks.verifier.CheckVerifier;

class AvoidFullSQLRequestCheckTest {

@Test
void test() {
JavaCheckVerifier.newVerifier()
CheckVerifier.newVerifier()
.onFile("src/test/files/AvoidFullSQLRequestCheck.java")
.withCheck(new AvoidFullSQLRequest())
.verifyIssues();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package fr.cnumr.java.checks;

import org.junit.jupiter.api.Test;
import org.sonar.java.checks.verifier.JavaCheckVerifier;
import org.sonar.java.checks.verifier.CheckVerifier;

class AvoidGettingSizeCollectionInLoopTest {
@Test
void test() {
JavaCheckVerifier.newVerifier()
CheckVerifier.newVerifier()
.onFile("src/test/files/AvoidGettingSizeCollectionInLoopBad.java")
.withCheck(new AvoidGettingSizeCollectionInLoop())
.verifyIssues();
JavaCheckVerifier.newVerifier()
CheckVerifier.newVerifier()
.onFile("src/test/files/AvoidGettingSizeCollectionInLoopGood.java")
.withCheck(new AvoidGettingSizeCollectionInLoop())
.verifyNoIssues();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package fr.cnumr.java.checks;

import org.junit.jupiter.api.Test;
import org.sonar.java.checks.verifier.JavaCheckVerifier;
import org.sonar.java.checks.verifier.CheckVerifier;

public class AvoidRegexPatternNotStaticTest {

@Test
public void testHasIssues() {
JavaCheckVerifier.newVerifier()
CheckVerifier.newVerifier()
.onFile("src/test/files/AvoidRegexPatternNotStatic.java")
.withCheck(new AvoidRegexPatternNotStatic())
.verifyIssues();
}

@Test
public void testHasNoIssues() {
JavaCheckVerifier.newVerifier()
CheckVerifier.newVerifier()
.onFiles(
"src/test/files/ValidRegexPattern.java",
"src/test/files/ValidRegexPattern2.java",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package fr.cnumr.java.checks;

import org.junit.jupiter.api.Test;
import org.sonar.java.checks.verifier.JavaCheckVerifier;
import org.sonar.java.checks.verifier.CheckVerifier;

class AvoidSQLRequestInLoopCheckTest {

@Test
void test() {
JavaCheckVerifier.newVerifier()
CheckVerifier.newVerifier()
.onFile("src/test/files/AvoidSQLRequestInLoopCheck.java")
.withCheck(new AvoidSQLRequestInLoop())
.verifyIssues();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package fr.cnumr.java.checks;

import org.junit.jupiter.api.Test;
import org.sonar.java.checks.verifier.JavaCheckVerifier;
import org.sonar.java.checks.verifier.CheckVerifier;

class AvoidSetConstantInBatchInsertTest {

@Test
void test() {
JavaCheckVerifier.newVerifier()
CheckVerifier.newVerifier()
.onFile("src/test/files/AvoidSetConstantInBatchUpdateCheck.java")
.withCheck(new AvoidSetConstantInBatchUpdate())
.verifyIssues();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package fr.cnumr.java.checks;

import org.junit.jupiter.api.Test;
import org.sonar.java.checks.verifier.JavaCheckVerifier;
import org.sonar.java.checks.verifier.CheckVerifier;

public class AvoidUsageOfStaticCollectionsTests {

@Test
public void testHasIssues() {
JavaCheckVerifier.newVerifier()
CheckVerifier.newVerifier()
.onFile("src/test/files/AvoidUsageOfStaticCollections.java")
.withCheck(new AvoidUsageOfStaticCollections())
.verifyIssues();
}

@Test
public void testNoIssues() {
JavaCheckVerifier.newVerifier()
CheckVerifier.newVerifier()
.onFile("src/test/files/GoodUsageOfStaticCollections.java")
.withCheck(new AvoidUsageOfStaticCollections())
.verifyNoIssues();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package fr.cnumr.java.checks;

import org.junit.jupiter.api.Test;
import org.sonar.java.checks.verifier.JavaCheckVerifier;
import org.sonar.java.checks.verifier.CheckVerifier;

class AvoidUsingGlobalVariablesCheckCheckTest {

@Test
void test() {
JavaCheckVerifier.newVerifier()
CheckVerifier.newVerifier()
.onFile("src/test/files/AvoidUsingGlobalVariablesCheck.java")
.withCheck(new AvoidUsingGlobalVariablesCheck())
.verifyIssues();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package fr.cnumr.java.checks;

import org.junit.jupiter.api.Test;
import org.sonar.java.checks.verifier.JavaCheckVerifier;
import org.sonar.java.checks.verifier.CheckVerifier;

class FreeResourcesOfAutoCloseableInterfaceTest {

@Test
void test() {
JavaCheckVerifier.newVerifier()
CheckVerifier.newVerifier()
.onFile("src/test/files/FreeResourcesOfAutoCloseableInterface.java")
.withCheck(new FreeResourcesOfAutoCloseableInterface())
.withJavaVersion(7)
Expand All @@ -16,7 +16,7 @@ void test() {

@Test
void test_no_java_version() {
JavaCheckVerifier.newVerifier()
CheckVerifier.newVerifier()
.onFile("src/test/files/FreeResourcesOfAutoCloseableInterface.java")
.withCheck(new FreeResourcesOfAutoCloseableInterface())
.verifyIssues();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package fr.cnumr.java.checks;

import org.junit.jupiter.api.Test;
import org.sonar.java.checks.verifier.JavaCheckVerifier;
import org.sonar.java.checks.verifier.CheckVerifier;

class IncrementCheckTest {

@Test
void test() {
JavaCheckVerifier.newVerifier()
CheckVerifier.newVerifier()
.onFile("src/test/files/IncrementCheck.java")
.withCheck(new IncrementCheck())
.verifyIssues();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package fr.cnumr.java.checks;

import org.junit.jupiter.api.Test;
import org.sonar.java.checks.verifier.JavaCheckVerifier;
import org.sonar.java.checks.verifier.CheckVerifier;

class InitializeBufferWithAppropriateSizeTest {

@Test
void test() {
JavaCheckVerifier.newVerifier()
CheckVerifier.newVerifier()
.onFile("src/test/files/InitializeBufferWithAppropriateSize.java")
.withCheck(new InitializeBufferWithAppropriateSize())
.verifyIssues();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package fr.cnumr.java.checks;

import org.junit.jupiter.api.Test;
import org.sonar.java.checks.verifier.JavaCheckVerifier;
import org.sonar.java.checks.verifier.CheckVerifier;

class NoFunctionCallWhenDeclaringForLoopTest {
@Test
void test() {
JavaCheckVerifier.newVerifier()
CheckVerifier.newVerifier()
.onFile("src/test/files/NoFunctionCallWhenDeclaringForLoop.java")
.withCheck(new NoFunctionCallWhenDeclaringForLoop())
.verifyIssues();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package fr.cnumr.java.checks;

import org.junit.jupiter.api.Test;
import org.sonar.java.checks.verifier.JavaCheckVerifier;
import org.sonar.java.checks.verifier.CheckVerifier;

class OptimizeReadFileExceptionCheckTest {

@Test
void test() {
JavaCheckVerifier.newVerifier()
CheckVerifier.newVerifier()
.onFile("src/test/files/OptimizeReadFileExceptionCheck.java")
.withCheck(new OptimizeReadFileExceptions())
.verifyIssues();
Expand Down
Loading