From 147d83a9e1a4a2476547b0d23c4aba19d9e996f6 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 9 Mar 2023 23:18:56 +0100 Subject: [PATCH 001/233] Initial commit --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..a33cf900 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# ecoCode-java-test-project +Java project to test the java plugin of ecoCode. From a91d8cc74d828d7ae8d2d2df1a409eee791ec3a1 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 9 Mar 2023 23:32:36 +0100 Subject: [PATCH 002/233] [ISSUE 65] first commit with test files for ecocode java plugin --- .gitignore | 7 + README.md | 34 +- pom.xml | 35 ++ .../java/checks/ArrayCopyCheck.java | 493 ++++++++++++++++++ .../checks/AvoidConcatenateStringsInLoop.java | 32 ++ .../java/checks/AvoidFullSQLRequestCheck.java | 30 ++ ...ingSizeCollectionInForEachLoopIgnored.java | 21 + ...voidGettingSizeCollectionInForLoopBad.java | 20 + ...oidGettingSizeCollectionInForLoopGood.java | 23 + ...GettingSizeCollectionInForLoopIgnored.java | 23 + ...idGettingSizeCollectionInWhileLoopBad.java | 22 + ...dGettingSizeCollectionInWhileLoopGood.java | 24 + ...ttingSizeCollectionInWhileLoopIgnored.java | 24 + .../checks/AvoidMultipleIfElseStatement.java | 38 ++ .../AvoidMultipleIfElseStatementNoIssue.java | 31 ++ .../checks/AvoidRegexPatternNotStatic.java | 11 + .../checks/AvoidSQLRequestInLoopCheck.java | 134 +++++ .../AvoidSetConstantInBatchUpdateCheck.java | 153 ++++++ .../AvoidSpringRepositoryCallInLoopCheck.java | 30 ++ .../checks/AvoidStatementForDMLQueries.java | 20 + .../checks/AvoidUsageOfStaticCollections.java | 19 + .../AvoidUsingGlobalVariablesCheck.java | 21 + ...FreeResourcesOfAutoCloseableInterface.java | 38 ++ .../checks/GoodUsageOfStaticCollections.java | 17 + .../checks/GoodWayConcatenateStringsLoop.java | 33 ++ .../java/checks/IncrementCheck.java | 36 ++ .../InitializeBufferWithAppropriateSize.java | 26 + .../NoFunctionCallWhenDeclaringForLoop.java | 58 +++ .../OptimizeReadFileExceptionCheck.java | 29 ++ .../OptimizeReadFileExceptionCheck2.java | 27 + .../OptimizeReadFileExceptionCheck3.java | 26 + .../OptimizeReadFileExceptionCheck4.java | 25 + .../OptimizeReadFileExceptionCheck5.java | 25 + ...arilyAssignValuesToVariablesTestCheck.java | 78 +++ ...esToVariablesTestCheckWithEmptyReturn.java | 18 + .../java/checks/UseCorrectForLoopCheck.java | 24 + .../java/checks/ValidRegexPattern.java | 12 + .../java/checks/ValidRegexPattern2.java | 12 + .../java/checks/ValidRegexPattern3.java | 16 + 39 files changed, 1743 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheck.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopBad.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopGood.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheck.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/GoodUsageOfStaticCollections.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/GoodWayConcatenateStringsLoop.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck2.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck3.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck4.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck5.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheck.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoopCheck.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern2.java create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern3.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..8c56452c --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +!.gitignore +!.github/**/*.* +.* +target +*.iml +lib/*.jar +bin \ No newline at end of file diff --git a/README.md b/README.md index a33cf900..458a90df 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,32 @@ -# ecoCode-java-test-project -Java project to test the java plugin of ecoCode. +Purpose of this project +--- +To check locally all rules on java language. +To do this : +- first launch local development environment (SonarQube) +- launch sonar maven command to send sonar metrics to local SonarQube +- check if each Java class contains (or not) the rule error defined for this class + +Step 0 : requirements +--- + +launch local environment with tools : +- `/tool_build.sh` +- `/tool_start.sh` (if docker environment already built) +- `/tool_docker-init.sh` (if docker environment not built yet) +check https://localhost:9000 +configure (if docker environment already built) : +- change password of admin user +- check if plugin is installed on "marketPlace" tab on Administration +- create a new profile on each language to test - extend from Sonar WAY +- make this new profile as default +- add all rules "eco-conception" tagged on this new profile + +Step 1 : compile and build +--- + +`mvn clean compile` + +Step 2 : Send Sonar metrics to local SonarQube +--- + +`mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.login=admin -Dsonar.password=XXX` diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000..62aa4caf --- /dev/null +++ b/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + + io.ecocode + ecocode-java-plugin-test-project + 0.3.0-SNAPSHOT + + ecoCode Java Sonar Plugin Test Project + + + 11 + ${java.version} + ${java.version} + + UTF-8 + ${encoding} + ${encoding} + + + + + org.springframework.data + spring-data-jpa + 2.7.8 + + + org.springframework + spring-beans + 5.3.25 + + + + \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java new file mode 100644 index 00000000..5e1aa513 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java @@ -0,0 +1,493 @@ +package fr.greencodeinitiative.java.checks; + +import java.util.Arrays; + +class ArrayCopyCheck { + + public void copyArrayOK() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Copy with clone + dest = src.clone(); + + // Copy with System.arraycopy() + System.arraycopy(src, 0, dest, 0, src.length); + + // Copy with Arrays.copyOf() + dest = Arrays.copyOf(src, src.length); + } + + public void nonRegression() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple assignation + for (int i = 0; i < len; i++) { + dest[i] = true; + } + + // Edit same array + for (int i = 0; i < len-1; i++) { + dest[i] = dest[i+1]; + } + + // Objects assignations + String a = null; + String b = "Sample Value"; + for (int i = 0; i < len; i++) { + a = b; + } + } + + public void copyWithForLoop() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple copy + for (int i = 0; i < len; i++) { // Noncompliant + dest[i] = src[i]; + } + + // Copy with nested conditions + for (int i = 0; i < len; i++) { // Noncompliant + if(i + 2 < len) { + dest[i] = src[i + 2]; + } + } + + // Copy with nested ELSE conditions + for (int i = 0; i < len; i++) { // Noncompliant + if(i + 2 >= len) { + i++; + } else { + dest[i] = src[i + 2]; + } + } + + // Copy with more nested conditions + for (int i = 0; i < len; i++) { // Noncompliant + if(i + 2 < len) { + if(dest != null) { + if(src != null) { + if(i > 1 && i + 2 < src.length) { + dest[i] = src[i + 2]; + } + } + } + } + } + + // Copy nested by try/catch + for (int i = 0; i < len; i++) { // Noncompliant + try { + dest[i] = src[i]; + } catch (RuntimeException e) { + e.printStackTrace(); + } + } + + // Copy nested by try/catch and if + for (int i = 0; i < len; i++) { // Noncompliant + try { + if(dest != null) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + } + + // Copy nested by try/catch in catch + for (int i = 0; i < len; i++) { // Noncompliant + try { + dest.toString(); + } catch (RuntimeException e) { + if(dest != null) { + dest[i] = src[i]; + } + } + } + + // Copy nested by try/catch in finally + for (int i = 0; i < len; i++) { // Noncompliant + try { + dest.toString(); + } catch (RuntimeException e) { + e.printStackTrace(); + } finally { + dest[i] = src[i]; + } + } + + // Array transformation + for (int i = 0; i < len; i++) { + dest[i] = transform(src[i]); + } + } + + public void copyWithForEachLoop() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple copy by foreach + int i = -1; + for (boolean b : src) { // Noncompliant + dest[++i] = b; + } + + // Copy with nested conditions by foreach + i = -1; + for (boolean b : src) { // Noncompliant + if(b) { + dest[++i] = b; + } + } + + // Copy with nested ELSE conditions by foreach + i = -1; + for (boolean b : src) { // Noncompliant + if(i + 2 >= len) { + i++; + } else { + dest[++i] = b; + } + } + + // Copy with more nested conditions + i = -1; + for (boolean b : src) { // Noncompliant + if(i + 2 < len) { + if(dest != null) { + if(src != null) { + if(i > 1 && i + 2 < src.length) { + dest[++i] = b; + } + } + } + } + } + + // Copy nested by try/catch + i = -1; + for (boolean b : src) { // Noncompliant + try { + dest[++i] = b; + } catch (RuntimeException e) { + e.printStackTrace(); + } + } + + // Copy nested by try/catch and if + i = -1; + for (boolean b : src) { // Noncompliant + try { + if(dest != null) { + dest[++i] = b; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + } + + // Copy nested by try/catch in catch + i = -1; + for (boolean b : src) { // Noncompliant + try { + dest.toString(); + } catch (RuntimeException e) { + if(dest != null) { + dest[++i] = b; + } + } + } + + // Copy nested by try/catch in finally + i = -1; + for (boolean b : src) { // Noncompliant + try { + dest.toString(); + } catch (RuntimeException e) { + e.printStackTrace(); + } finally { + dest[++i] = b; + } + } + + // Array transformation + i = -1; + for (boolean b : src) { + dest[++i] = transform(b); + } + + // Simple copy + i = 0; + for (boolean b : src) { // Noncompliant + dest[i] = src[i]; + i++; + } + + // Copy with nested conditions + i = 0; + for (boolean b : src) { // Noncompliant + if(b) { + dest[i] = src[i]; + } + i++; + } + + // Copy with nested ELSE conditions + i = 0; + for (boolean b : src) { // Noncompliant + if(i + 2 >= len) { + i++; + } else { + dest[i] = src[i + 2]; + } + i++; + } + + // Copy with more nested conditions + i = 0; + for (boolean b : src) { // Noncompliant + if(i + 2 < len) { + if(dest != null) { + if(src != null) { + if(i > 1 && i + 2 < src.length) { + dest[i] = src[i + 2]; + } + } + } + } + i++; + } + + // Copy nested by try/catch + i = 0; + for (boolean b : src) { // Noncompliant + try { + dest[i] = src[i]; + } catch (RuntimeException e) { + e.printStackTrace(); + } + i++; + } + + // Copy nested by try/catch and if + i = 0; + for (boolean b : src) { // Noncompliant + try { + if(dest != null) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + i++; + } + + // Copy nested by try/catch in catch + i = 0; + for (boolean b : src) { // Noncompliant + try { + dest.toString(); + } catch (RuntimeException e) { + if(dest != null) { + dest[i] = src[i]; + } + } + i++; + } + + // Copy nested by try/catch in finally + i = 0; + for (boolean b : src) { // Noncompliant + try { + dest.toString(); + } catch (RuntimeException e) { + e.printStackTrace(); + } finally { + dest[i] = src[i]; + } + i++; + } + + // Array transformation + i = 0; + for (boolean b : src) { + dest[i] = transform(src[i]); + i++; + } + } + + public void copyWithWhileLoop() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple copy + int i = 0; + while (i < len) { // Noncompliant + dest[i] = src[i]; + i++; + } + + // Copy with nested conditions + i = 0; + while (i < len) { // Noncompliant + if(i + 2 < len) { + dest[i] = src[i + 2]; + } + i++; + } + + // Copy with nested ELSE conditions + i = 0; + while (i < len) { // Noncompliant + if(i + 2 >= len) { + i++; + } else { + dest[i] = src[i + 2]; + } + i++; + } + + // Copy with more nested conditions + i = 0; + while (i < len) { // Noncompliant + if(i + 2 < len) { + if(dest != null) { + if(src != null) { + if(i > 1 && i + 2 < src.length) { + dest[i] = src[i + 2]; + } + } + } + } + i++; + } + + // Copy nested by try/catch and if + i = 0; + while (i < len) { // Noncompliant + try { + if(dest != null) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + i++; + } + + // Copy nested by try/catch in catch + i = 0; + while (i < len) { // Noncompliant + try { + dest.toString(); + } catch (RuntimeException e) { + if(dest != null) { + dest[i] = src[i]; + } + } + i++; + } + + // Array transformation + i = 0; + while (i < len) { + dest[i] = transform(src[i]); + i++; + } + } + + public void copyWithDoWhileLoop() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple copy + int i = 0; + do { // Noncompliant + dest[i] = src[i]; + i++; + } while (i < len); + + // Copy with nested conditions + i = 0; + do { // Noncompliant + if(i + 2 < len) { + dest[i] = src[i + 2]; + } + i++; + } while (i < len); + + // Copy with nested ELSE conditions + i = 0; + do { // Noncompliant + if(i + 2 >= len) { + i++; + } else { + dest[i] = src[i + 2]; + } + i++; + } while (i < len); + + // Copy with more nested conditions + i = 0; + do { // Noncompliant + if(i + 2 < len) { + if(dest != null) { + if(src != null) { + if(i > 1 && i + 2 < src.length) { + dest[i] = src[i + 2]; + } + } + } + } + i++; + } while (i < len); + + // Copy nested by try/catch and if + i = 0; + do { // Noncompliant + try { + if(dest != null) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + i++; + } while (i < len); + + // Copy nested by try/catch in catch + i = 0; + do { // Noncompliant + try { + dest.toString(); + } catch (RuntimeException e) { + if(dest != null) { + dest[i] = src[i]; + } + } + i++; + } while (i < len); + + // Array transformation + i = 0; + do { + dest[i] = transform(src[i]); + i++; + } while (i < len); + } + + private boolean transform(boolean a) { + return !a; + } + +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java new file mode 100644 index 00000000..1d141fc5 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java @@ -0,0 +1,32 @@ +package fr.greencodeinitiative.java.checks; + +public class AvoidConcatenateStringsInLoop { + + public String concatenateStrings(String[] strings) { + String result1 = ""; + + for (String string : strings) { + result1 += string; // Noncompliant + } + return result1; + } + + public String concatenateStrings2() { + String result2 = ""; + + for (int i = 0; i < 1000; ++i) { + result2 += "another"; // Noncompliant + } + return result2; + } + + public String concatenateStrings3() { + String result3 = ""; + + for (int i = 0; i < 1000; ++i) { + result3 = result3 + "another"; // Noncompliant + } + return result3; + } + +} diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheck.java new file mode 100644 index 00000000..0c4ff7b1 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheck.java @@ -0,0 +1,30 @@ +package fr.greencodeinitiative.java.checks; + +class AvoidFullSQLRequestCheck { + AvoidFullSQLRequestCheck(AvoidFullSQLRequestCheck mc) { + } + + public void literalSQLrequest() { + dummyCall(" sElEcT * fRoM myTable"); // Noncompliant + dummyCall(" sElEcT user fRoM myTable"); + + dummyCall("SELECTABLE 2*2 FROMAGE"); //not sql + dummyCall("SELECT *FROM table"); // Noncompliant + } + + + public void variableSQLrequest() { + String requestNonCompiliant = " SeLeCt * FrOm myTable"; // Noncompliant + String requestCompiliant = " SeLeCt user FrOm myTable"; + dummyCall(requestNonCompiliant); + dummyCall(requestCompiliant); + + String noSqlCompiliant = "SELECTABLE 2*2 FROMAGE"; //not sql + String requestNonCompiliant_nSpace = "SELECT *FROM table"; // Noncompliant + } + + private void dummyCall(String request) { + + } + +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java new file mode 100644 index 00000000..467899dd --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java @@ -0,0 +1,21 @@ +package fr.greencodeinitiative.java.checks; + +import java.util.ArrayList; +import java.util.List; + +class AvoidGettingSizeCollectionInForEachLoopIgnored { + AvoidGettingSizeCollectionInForEachLoopIgnored(AvoidGettingSizeCollectionInForEachLoopIgnored obj) { + + } + + public void ignoredLoop() { + List numberList = new ArrayList(); + numberList.add(10); + numberList.add(20); + + for (Integer i : numberList) { // Ignored + int size = numberList.size(); // Compliant with this rule + System.out.println("numberList.size()"); + } + } +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopBad.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopBad.java new file mode 100644 index 00000000..2428fb36 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopBad.java @@ -0,0 +1,20 @@ +package fr.greencodeinitiative.java.checks; + +import java.util.ArrayList; +import java.util.List; + +class AvoidGettingSizeCollectionInForLoopBad { + AvoidGettingSizeCollectionInForLoopBad() { + + } + + public void badForLoop() { + List numberList = new ArrayList(); + numberList.add(10); + numberList.add(20); + + for (int i = 0; i < numberList.size(); i++) { // Noncompliant + System.out.println("numberList.size()"); + } + } +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopGood.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopGood.java new file mode 100644 index 00000000..fed87f5d --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopGood.java @@ -0,0 +1,23 @@ +package fr.greencodeinitiative.java.checks; + +import java.util.Collection; +import java.util.ArrayList; +import java.util.List; + +class AvoidGettingSizeCollectionInForLoopGood { + AvoidGettingSizeCollectionInForLoopGood(AvoidGettingSizeCollectionInForLoopGood obj) { + + } + + public void goodForLoop() { + List numberList = new ArrayList(); + numberList.add(10); + numberList.add(20); + + int size = numberList.size(); + for (int i = 0; i < size; i++) { // Compliant + System.out.println("numberList.size()"); + int size2 = numberList.size(); // Compliant with this rule + } + } +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java new file mode 100644 index 00000000..d9c4d51b --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java @@ -0,0 +1,23 @@ +package fr.greencodeinitiative.java.checks; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +class AvoidGettingSizeCollectionInForLoopIgnored { + AvoidGettingSizeCollectionInForLoopIgnored() { + + } + + public void badForLoop() { + List numberList = new ArrayList(); + numberList.add(10); + numberList.add(20); + + Iterator it = numberList.iterator(); + for (; it.hasNext(); ) { // Ignored => compliant + it.next(); + System.out.println("numberList.size()"); + } + } +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java new file mode 100644 index 00000000..51b33bd0 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java @@ -0,0 +1,22 @@ +package fr.greencodeinitiative.java.checks; + +import java.util.ArrayList; +import java.util.List; + +class AvoidGettingSizeCollectionInWhileLoopBad { + AvoidGettingSizeCollectionInWhileLoopBad() { + + } + + public void badWhileLoop() { + List numberList = new ArrayList(); + numberList.add(10); + numberList.add(20); + + int i = 0; + while (i < numberList.size()) { // Noncompliant + System.out.println("numberList.size()"); + i++; + } + } +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java new file mode 100644 index 00000000..b88e73aa --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java @@ -0,0 +1,24 @@ +package fr.greencodeinitiative.java.checks; + +import java.util.ArrayList; +import java.util.List; + +class AvoidGettingSizeCollectionInWhileLoopGood { + AvoidGettingSizeCollectionInWhileLoopGood(AvoidGettingSizeCollectionInWhileLoopGood obj) { + + } + + public void goodWhileLoop() { + List numberList = new ArrayList(); + numberList.add(10); + numberList.add(20); + + int size = numberList.size(); + int i = 0; + while (i < size) { // Compliant + System.out.println("numberList.size()"); + int size2 = numberList.size(); // Compliant with this rule + i++; + } + } +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java new file mode 100644 index 00000000..62ed1fc4 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java @@ -0,0 +1,24 @@ +package fr.greencodeinitiative.java.checks; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +class AvoidGettingSizeCollectionInWhileLoopIgnored { + AvoidGettingSizeCollectionInWhileLoopIgnored() { + + } + + public void badWhileLoop() { + List numberList = new ArrayList(); + numberList.add(10); + numberList.add(20); + + Iterator it = numberList.iterator(); + int i = 0; + while (it.hasNext()) { // Ignored => compliant + it.next(); + System.out.println("numberList.size()"); + } + } +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java new file mode 100644 index 00000000..d84630d9 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java @@ -0,0 +1,38 @@ +package fr.greencodeinitiative.java.checks; + +class AvoidMultipleIfElseStatementCheck { + AvoidMultipleIfElseStatementCheck(AvoidMultipleIfElseStatementCheck mc) { + } + + public void methodWithMultipleIfElseIf() { + int nb1 = 0; + int nb2 = 10; + + if (nb1 == 1) { // Noncompliant + nb1 = 1; + } else if (nb1 == nb2) { + // + } else if (nb2 == nb1) { + // + } else { + // + } + nb1 = nb2; + } + + public void methodWithMultipleIfElse() { + int nb1 = 0; + int nb2 = 10; + + if (nb1 == 1) { // Noncompliant + nb1 = 1; + } else { + // + } + if (nb1 == 1) { // Noncompliant + nb1 = 1; + } else { + // + } + } +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java new file mode 100644 index 00000000..60d10293 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java @@ -0,0 +1,31 @@ +package fr.greencodeinitiative.java.checks; + +class AvoidMultipleIfElseStatementNoIssueCheck { + AvoidMultipleIfElseStatementNoIssueCheck(AvoidMultipleIfElseStatementNoIssueCheck mc) { + } + + public void methodWithOneIfElseIf() { + int nb1 = 0; + int nb2 = 10; + + if (nb1 == 1) { + nb1 = 1; + } else if (nb1 == nb2) { + // + } else { + // + } + nb1 = nb2; + } + + public void methodWithOneIfElse() { + int nb1 = 0; + int nb2 = 10; + + if (nb1 == 1) { + nb1 = 1; + } else { + // + } + } +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java new file mode 100644 index 00000000..8f9d6903 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java @@ -0,0 +1,11 @@ +package fr.greencodeinitiative.java.checks; + +import java.util.regex.Pattern; + +public class AvoidRegexPatternNotStatic { + + public boolean foo() { + final Pattern pattern = Pattern.compile("foo"); // Noncompliant + return pattern.matcher("foo").find(); + } +} diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheck.java new file mode 100644 index 00000000..6365bc95 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheck.java @@ -0,0 +1,134 @@ +package fr.greencodeinitiative.java.checks; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; + +class AvoidSQLRequestInLoopCheck { + AvoidSQLRequestInLoopCheck(AvoidSQLRequestInLoopCheck mc) { + } + + public void testWithNoLoop() { + try { + // create our mysql database connection + String myDriver = "driver"; + String myUrl = "driver"; + Class.forName(myDriver); + Connection conn = DriverManager.getConnection(myUrl, "toor", ""); + + // our SQL SELECT query. + // if you only need a few columns, specify them by name instead of using "*" + String query = "SELECT * FROM users"; + + // create the java statement + Statement st = conn.createStatement(); + ResultSet rs = st.executeQuery(query); + + // iterate through the java resultset + while (rs.next()) { + int id = rs.getInt("id"); + System.out.println(id); + } + st.close(); + } catch (Exception e) { + System.err.println("Got an exception! "); + System.err.println(e.getMessage()); + } + } + + public void testWithForLoop() { + try { + // create our mysql database connection + String myDriver = "driver"; + String myUrl = "driver"; + Class.forName(myDriver); + Connection conn = DriverManager.getConnection(myUrl, "toor", ""); + + // our SQL SELECT query. + // if you only need a few columns, specify them by name instead of using "*" + String baseQuery = "SELECT name FROM users where id = "; + + for (int i = 0; i < 20; i++) { + + // create the java statement + String query = baseQuery.concat("" + i); + Statement st = conn.createStatement(); + ResultSet rs = st.executeQuery(query); // Noncompliant + + // iterate through the java resultset + while (rs.next()) { + String name = rs.getString("name"); + System.out.println(name); + } + st.close(); + } + } catch (Exception e) { + System.err.println("Got an exception! "); + System.err.println(e.getMessage()); + } + } + + public void testWithForEachLoop() { + try { + // create our mysql database connection + String myDriver = "driver"; + String myUrl = "driver"; + Class.forName(myDriver); + Connection conn = DriverManager.getConnection(myUrl, "toor", ""); + + // our SQL SELECT query. + // if you only need a few columns, specify them by name instead of using "*" + String query = "SELECT * FROM users"; + int[] intArray = {10, 20, 30, 40, 50}; + for (int i : intArray) { + System.out.println(i); + // create the java statement + Statement st = conn.createStatement(); + ResultSet rs = st.executeQuery(query); // Noncompliant + + // iterate through the java resultset + while (rs.next()) { + int id = rs.getInt("id"); + System.out.println(id); + } + st.close(); + } + } catch (Exception e) { + System.err.println("Got an exception! "); + System.err.println(e.getMessage()); + } + } + + public void testWithWhileLoop() { + try { + // create our mysql database connection + String myDriver = "driver"; + String myUrl = "driver"; + Class.forName(myDriver); + Connection conn = DriverManager.getConnection(myUrl, "toor", ""); + + // our SQL SELECT query. + // if you only need a few columns, specify them by name instead of using "*" + String query = "SELECT * FROM users"; + int i = 0; + while (i < -1) { + + // create the java statement + Statement st = conn.createStatement(); + ResultSet rs = st.executeQuery(query); // Noncompliant + + // iterate through the java resultset + while (rs.next()) { + int id = rs.getInt("id"); + System.out.println(id); + } + st.close(); + } + } catch (Exception e) { + System.err.println("Got an exception! "); + System.err.println(e.getMessage()); + } + } + +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java new file mode 100644 index 00000000..21e61211 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java @@ -0,0 +1,153 @@ +package fr.greencodeinitiative.java.checks; + +import java.math.BigDecimal; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.stream.IntStream; + +class AvoidSetConstantInBatchUpdateCheck { + + Logger logger = Logger.getLogger(""); + + void literalSQLrequest() throws SQLException { //dirty call + + int x = 0; + Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle"); + PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?)"); + stmt.setInt(1, 101); + stmt.setString(2, "Ratan"); + stmt.setBigDecimal(3, BigDecimal.ONE); + stmt.setBigDecimal(4, BigDecimal.valueOf(x)); + stmt.setBoolean(5, Boolean.valueOf("true")); + int i = stmt.executeUpdate(); + System.out.println(i + " records inserted"); + con.close(); + } + + void batchInsertInForLoop(int[] data) throws SQLException { + + Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle"); + PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?,?,?,?,?,?,?,?)"); + for (int i = 0; i < data.length; i++) { + stmt.setInt(1, data[i]); + + stmt.setBoolean(2, true); // Noncompliant + stmt.setByte(3, (byte) 3); // Noncompliant + stmt.setBytes(4, "v".getBytes()); // Noncompliant + stmt.setShort(5, (short) 5); // Noncompliant + stmt.setInt(6, 6); // Noncompliant + stmt.setLong(7, (long) 7); // Noncompliant + stmt.setLong(7, 7l); // Noncompliant + stmt.setFloat(8, (float) 8.); // Noncompliant + stmt.setFloat(8, 8.f); // Noncompliant + stmt.setDouble(9, 9.); // Noncompliant + stmt.setDouble(9, 9.); // Noncompliant + stmt.setString(10, "10"); // Noncompliant + stmt.setBigDecimal(11, BigDecimal.valueOf(.77)); // Noncompliant + stmt.addBatch(); + } + int[] nr = stmt.executeBatch(); + logger.log(Level.INFO, "{} rows updated", IntStream.of(nr).sum()); + con.close(); + } + + + int[] batchInsertInForeachLoop(DummyClass[] data) throws SQLException { + + try (Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle")) { + PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?,?,?,?,?,?,?,?,?,?)"); + for (DummyClass o : data) { + stmt.setInt(1, o.getField1()); + stmt.setBoolean(2, Boolean.valueOf("false")); // Noncompliant + stmt.setByte(3, o.getField3()); + stmt.setBytes(4, "v".getBytes()); // Noncompliant + stmt.setShort(5, (short) 5); // Noncompliant + stmt.setInt(6, 6); // Noncompliant + stmt.setLong(7, 7); // Noncompliant + stmt.setFloat(8, (float) 8.); // Noncompliant + stmt.setDouble(9, o.getField4()); + stmt.setString(10, o.getField2()); + stmt.setBigDecimal(11, BigDecimal.valueOf(11)); // Noncompliant + stmt.addBatch(); + } + return stmt.executeBatch(); + } + } + + + int[] batchInsertInWhileLoop2(DummyClass[] data) throws SQLException { + + try (Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle")) { + PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?,?,?,?,?,?,?,?,?,?)"); + int i = 0; + while (i < data.length) { + DummyClass o = data[i]; + stmt.setInt(1, o.getField1()); + stmt.setBoolean(2, Boolean.TRUE); // Noncompliant + stmt.setByte(3, o.getField3()); + stmt.setByte(4, Byte.MAX_VALUE); // Noncompliant + stmt.setShort(5, Short.MIN_VALUE); // Noncompliant + stmt.setInt(6, Integer.MAX_VALUE); // Noncompliant + stmt.setLong(7, Long.MIN_VALUE); // Noncompliant + stmt.setFloat(8, Float.MAX_VALUE); // Noncompliant + stmt.setDouble(9, Double.MIN_VALUE); // Noncompliant + stmt.setString(10, o.getField2()); + stmt.setBigDecimal(11, BigDecimal.TEN); // Noncompliant + stmt.addBatch(); + i++; + } + return stmt.executeBatch(); + } + } + + int[] batchInsertInWhileLoop(DummyClass[] data) throws SQLException { + if (data.length == 0) { + return new int[]{}; + } + try (Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle")) { + PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?,?,?,?,?,?,?,?,?,?)"); + int i = 0; + do { + DummyClass o = data[i]; + stmt.setInt(1, o.getField1()); + stmt.setBoolean(2, Boolean.valueOf(true)); // Noncompliant + stmt.setByte(3, o.getField3()); + stmt.setByte(4, Byte.valueOf((byte) 3)); // Noncompliant + stmt.setShort(5, Short.valueOf((short) 55)); // Noncompliant + stmt.setInt(6, Integer.valueOf("222")); // Noncompliant + stmt.setLong(7, Long.valueOf(0)); // Noncompliant + stmt.setFloat(8, Float.valueOf(.33f)); // Noncompliant + stmt.setDouble(9, Double.valueOf(22)); // Noncompliant + stmt.setString(10, o.getField2()); + stmt.setBigDecimal(11, BigDecimal.valueOf(11)); // Noncompliant + stmt.addBatch(); + i++; + } while (i < data.length); + return stmt.executeBatch(); + } + } + + class DummyClass { + + public int getField1() { + return 0; + } + + public String getField2() { + return ""; + } + + public byte getField3() { + return 'A'; + } + + public double getField4() { + return .1; } + } + + +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java new file mode 100644 index 00000000..2b1579a7 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java @@ -0,0 +1,30 @@ +package fr.greencodeinitiative.java.checks; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.*; + +public class AvoidSpringRepositoryCallInLoopCheck { + @Autowired + private EmployeeRepository employeeRepository; + + public List smellGetAllEmployeesByIds(List ids) { + List employees = new ArrayList<>(); + for (Integer id : ids) { + Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop}} + if (employee.isPresent()) { + employees.add(employee.get()); + } + } + return employees; + } + + public class Employee { + } + + public interface EmployeeRepository extends JpaRepository { + + } + +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java new file mode 100644 index 00000000..428608f9 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java @@ -0,0 +1,20 @@ +package fr.greencodeinitiative.java.checks; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.*; +import java.sql.PreparedStatement; + +import javax.sql.DataSource; + + +class AvoidStatementForDMLQueries { + AvoidStatementForDMLQueries(AvoidStatementForDMLQueries mc) { + } + + public void insert() throws SQLException { + Connection connection = DriverManager.getConnection("URL"); + Statement statement = connection.createStatement(); + statement.executeUpdate("INSERT INTO persons(id, name) VALUES(2, 'Toto')"); // Noncompliant + } +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java new file mode 100644 index 00000000..50eb5071 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java @@ -0,0 +1,19 @@ +package fr.greencodeinitiative.java.checks; + +import java.util.*; + +/** + * Not compliant + */ +public class AvoidUsageOfStaticCollections { + + public static final List LIST = new ArrayList(); // Noncompliant + + public static final Set SET = new HashSet(); // Noncompliant + + public static final Map MAP = new HashMap(); // Noncompliant + + public AvoidUsageOfStaticCollections() { + } + +} diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java new file mode 100644 index 00000000..689986ee --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java @@ -0,0 +1,21 @@ +package fr.greencodeinitiative.java.checks; + +public class AvoidUsingGlobalVariablesCheck { + public static double price = 15.24; // Noncompliant + public static long pages = 1053; // Noncompliant + + public static void main(String[] args) { + double newPrice = AvoidUsingGlobalVariablesCheck.price; + long newPages = AvoidUsingGlobalVariablesCheck.pages; + System.out.println(newPrice); + System.out.println(newPages); + } + static{ // Noncompliant + int a = 4; + } + + public void printingA() { + System.out.println("a"); + } + +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java b/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java new file mode 100644 index 00000000..06dc1918 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java @@ -0,0 +1,38 @@ +package fr.greencodeinitiative.java.checks; + +import java.io.*; + +class FreeResourcesOfAutoCloseableInterface { + FreeResourcesOfAutoCloseableInterface(FreeResourcesOfAutoCloseableInterface mc) { + + } + + public void foo1() { + String fileName = "./FreeResourcesOfAutoCloseableInterface.java"; + try (FileReader fr = new FileReader(fileName); + BufferedReader br = new BufferedReader(fr)) { + } catch (IOException e) { + System.err.println(e.getMessage()); + } + } + + public void foo2() throws IOException { + String fileName = "./FreeResourcesOfAutoCloseableInterface.java"; + FileReader fr = null; + BufferedReader br = null; + try { // Noncompliant + fr = new FileReader(fileName); + br = new BufferedReader(fr); + System.out.println(br.readLine()); + } catch (IOException e) { + System.err.println(e.getMessage()); + } finally { + if (fr != null) { + fr.close(); + } + if (br != null) { + br.close(); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/GoodUsageOfStaticCollections.java b/src/main/java/fr/greencodeinitiative/java/checks/GoodUsageOfStaticCollections.java new file mode 100644 index 00000000..8f8e55c7 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/GoodUsageOfStaticCollections.java @@ -0,0 +1,17 @@ +package fr.greencodeinitiative.java.checks; + +import java.util.*; + +/** + * Compliant + */ +public class GoodUsageOfStaticCollections { + public static volatile GoodUsageOfStaticCollections INSTANCE = new GoodUsageOfStaticCollections(); + + public final List LIST = new ArrayList(); // Compliant + public final Set SET = new HashSet(); // Compliant + public final Map MAP = new HashMap(); // Compliant + + private GoodUsageOfStaticCollections() { + } +} diff --git a/src/main/java/fr/greencodeinitiative/java/checks/GoodWayConcatenateStringsLoop.java b/src/main/java/fr/greencodeinitiative/java/checks/GoodWayConcatenateStringsLoop.java new file mode 100644 index 00000000..6f279edd --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/GoodWayConcatenateStringsLoop.java @@ -0,0 +1,33 @@ +package fr.greencodeinitiative.java.checks; + +public class GoodWayConcatenateStringsLoop { + + public String concatenateStrings(String[] strings) { + StringBuilder result = new StringBuilder(); + + for (String string : strings) { + result.append(string); + } + return result.toString(); + } + + public void testConcateOutOfLoop() { + String result = ""; + result += "another"; + } + + public void testConcateOutOfLoop2() { + String result = ""; + result = result + "another"; + } + + public String changeValueStringInLoop() { + String result3 = ""; + + for (int i = 0; i < 1; ++i) { + result3 = "another"; + } + return result3; + } + +} diff --git a/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java new file mode 100644 index 00000000..302e393e --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java @@ -0,0 +1,36 @@ +package fr.greencodeinitiative.java.checks; + +class IncrementCheck { + IncrementCheck(IncrementCheck mc) { + } + + int foo1() { + int counter = 0; + return counter++; // Noncompliant + } + + int foo11() { + int counter = 0; + return ++counter; + } + + void foo2(int value) { + int counter = 0; + counter++; // Noncompliant + } + + void foo22(int value) { + int counter = 0; + ++counter; + } + + void foo3(int value) { + int counter = 0; + counter = counter + 197845 ; + } + + void foo4(int value) { + int counter =0; + counter = counter + 35 + 78 ; + } +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java b/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java new file mode 100644 index 00000000..925a8d1f --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java @@ -0,0 +1,26 @@ +package fr.greencodeinitiative.java.checks; + +class InitializeBufferWithAppropriateSize { + InitializeBufferWithAppropriateSize(InitializeBufferWithAppropriateSize mc) { + } + + public void testBufferCompliant() { + StringBuffer stringBuffer = new StringBuffer(16); + } + + public void testBufferCompliant2() { + StringBuffer stringBuffer = new StringBuffer(Integer.valueOf(16)); + } + + public void testBufferNonCompliant() { + StringBuffer stringBuffer = new StringBuffer(); // Noncompliant + } + + public void testBuilderCompliant() { + StringBuilder stringBuilder = new StringBuilder(16); + } + + public void testBuilderNonCompliant() { + StringBuilder stringBuilder = new StringBuilder(); // Noncompliant + } +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java new file mode 100644 index 00000000..f4fa54ac --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java @@ -0,0 +1,58 @@ +package fr.greencodeinitiative.java.checks; + +class NoFunctionCallWhenDeclaringForLoop { + NoFunctionCallWhenDeclaringForLoop(NoFunctionCallWhenDeclaringForLoop mc) { + } + + public int getMyValue() { + return 6; + } + + public int incrementeMyValue(int i) { + return i + 100; + } + + public void test1() { + for (int i = 0; i < 20; i++) { + System.out.println(i); + boolean b = getMyValue() > 6; + } + } + + public void test2() { + String[] cars = {"Volvo", "BMW", "Ford", "Mazda"}; + for (String i : cars) { + System.out.println(i); + } + + } + + public void test3() { + for (int i = getMyValue(); i < 20; i++) { // Noncompliant + System.out.println(i); + boolean b = getMyValue() > 6; + } + } + + public void test4() { + for (int i = 0; i < getMyValue(); i++) { // Noncompliant + System.out.println(i); + boolean b = getMyValue() > 6; + } + } + + public void test5() { + for (int i = 0; i < getMyValue(); incrementeMyValue(i)) { // Noncompliant + System.out.println(i); + boolean b = getMyValue() > 6; + } + } + + public void test6() { + for (int i = getMyValue(); i < getMyValue(); i++) { // Noncompliant + System.out.println(i); + boolean b = getMyValue() > 6; + } + } + +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck.java new file mode 100644 index 00000000..be2bd55b --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck.java @@ -0,0 +1,29 @@ +package fr.greencodeinitiative.java.checks; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Logger; + +import static java.lang.System.Logger.Level.ERROR; + +class OptimizeReadFileExceptionCheck { + + Logger logger = Logger.getLogger(""); + + OptimizeReadFileExceptionCheck(OptimizeReadFileExceptionCheck readFile) { + } + + public void readPreferences(String filename) { + //... + InputStream in = null; + try { + in = new FileInputStream(filename); // Noncompliant + } catch (FileNotFoundException e) { + logger.info(e.getMessage()); + } + //... + } +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck2.java b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck2.java new file mode 100644 index 00000000..50955d6c --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck2.java @@ -0,0 +1,27 @@ +package fr.greencodeinitiative.java.checks; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Logger; + +class OptimizeReadFileExceptionCheck2 { + + Logger logger = Logger.getLogger(""); + + OptimizeReadFileExceptionCheck2(OptimizeReadFileExceptionCheck2 readFile) { + } + + public void readPreferences(String filename) throws IOException { + //... + try (InputStream in = new FileInputStream(filename)) { // Noncompliant + logger.info("my log"); + } catch (FileNotFoundException e) { + logger.info(e.getMessage()); + } + //... + } +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck3.java b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck3.java new file mode 100644 index 00000000..83214c22 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck3.java @@ -0,0 +1,26 @@ +package fr.greencodeinitiative.java.checks; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Logger; + +class OptimizeReadFileExceptionCheck3 { + + Logger logger = Logger.getLogger(""); + + OptimizeReadFileExceptionCheck3(OptimizeReadFileExceptionCheck3 readFile) { + } + + public void readPreferences(String filename) { + //... + try (InputStream in = new FileInputStream(filename)) { // Noncompliant + logger.info("my log"); + } catch (IOException e) { + logger.info(e.getMessage()); + } + //... + } +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck4.java b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck4.java new file mode 100644 index 00000000..a4fd9508 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck4.java @@ -0,0 +1,25 @@ +package fr.greencodeinitiative.java.checks; + +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Logger; + +class OptimizeReadFileExceptionCheck4 { + + Logger logger = Logger.getLogger(""); + + OptimizeReadFileExceptionCheck4(OptimizeReadFileExceptionCheck4 readFile) { + } + + public void readPreferences(String filename) { + //... + try (InputStream in = new FileInputStream(filename)) { // Noncompliant + logger.info("my log"); + } catch (Exception e) { + logger.info(e.getMessage()); + } + //... + } +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck5.java b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck5.java new file mode 100644 index 00000000..bf279462 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck5.java @@ -0,0 +1,25 @@ +package fr.greencodeinitiative.java.checks; + +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Logger; + +class OptimizeReadFileExceptionCheck5 { + + Logger logger = Logger.getLogger(""); + + OptimizeReadFileExceptionCheck5(OptimizeReadFileExceptionCheck5 readFile) { + } + + public void readPreferences(String filename) { + //... + try (InputStream in = new FileInputStream(filename)) { // Noncompliant + logger.info("my log"); + } catch (Throwable e) { + logger.info(e.getMessage()); + } + //... + } +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheck.java new file mode 100644 index 00000000..3ed0cf70 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheck.java @@ -0,0 +1,78 @@ +package fr.greencodeinitiative.java.checks; + +class UnnecessarilyAssignValuesToVariablesTestCheck { + UnnecessarilyAssignValuesToVariablesTestCheck(UnnecessarilyAssignValuesToVariablesTestCheck mc) { + } + + public int testSwitchCase() throws Exception { + int variableFor = 5; + int variableIf = 5; + int variableWhile = 5; + int variableExp = 5; + int variableReturn = 5; + int variableCLass = 5; + int[] intArray = {10, 20, 30, 40, 50}; + + Exception variableException = new Exception("message"); + int variableNotUse = 5; // Noncompliant + + + variableNotUse = 10; + for (variableFor = 0; variableFor < 5; ++variableFor) { + System.out.println(variableFor); + } + + for (int ia : intArray) { + System.out.println((char) ia); + } + + if (variableIf > 10) { + System.out.println(variableIf); + } + + while (variableWhile > 10) { + System.out.println(variableWhile); + } + + variableExp += 1; + variableNotUse = variableExp; + TestClass testClass = new TestClass(variableCLass); + if (testClass.isTrue()) { + throw variableException; + } + return variableReturn; + } + + private class TestClass { + TestClass(int i) { + ++i; + } + + public boolean isTrue() { + return true; + } + } + + + private int getIntValue() { + return 3; + } + + public int testNonCompliantReturn() { + int i = getIntValue(); // Noncompliant + return i; + } + + public int testCompliantReturn() { + return getIntValue(); + } + + public void testNonCompliantThrow() throws Exception { + Exception exception = new Exception("dummy"); // Noncompliant + throw exception; + } + + public void testCompliantThrow() throws Exception { + throw new Exception("dummy"); + } +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java b/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java new file mode 100644 index 00000000..4dbb952c --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java @@ -0,0 +1,18 @@ +package fr.greencodeinitiative.java.checks; + +import java.util.ArrayList; + +class UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn { + UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn(UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn mc) { + } + + public void testSwitchCase() { + + ArrayList lst = new ArrayList(0); + if (lst == null) { + return; + } + System.out.println(lst); + } + +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoopCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoopCheck.java new file mode 100644 index 00000000..669f058f --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoopCheck.java @@ -0,0 +1,24 @@ +package fr.greencodeinitiative.java.checks; + +import java.util.Arrays; +import java.util.List; + +class UseCorrectForLoopCheck { + UseCorrectForLoopCheck(UseCorrectForLoopCheck mc) { + } + + private final Integer[] intArray = new Integer[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + private final List intList = Arrays.asList(intArray); + + public void testForEachLoop() { + int dummy = 0; + for (Integer i : intArray) { // Noncompliant + dummy += i; + } + + for (Integer i : intList) { + dummy += i; + } + System.out.println(dummy); + } +} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern.java b/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern.java new file mode 100644 index 00000000..5ed3652f --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern.java @@ -0,0 +1,12 @@ +package fr.greencodeinitiative.java.checks; + +import java.util.regex.Pattern; + +public class ValidRegexPattern { + + private static final Pattern pattern = Pattern.compile("foo"); // Compliant + + public boolean foo() { + return pattern.matcher("foo").find(); + } +} diff --git a/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern2.java b/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern2.java new file mode 100644 index 00000000..d6d9efd7 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern2.java @@ -0,0 +1,12 @@ +package fr.greencodeinitiative.java.checks; + +import java.util.regex.Pattern; + +public class ValidRegexPattern2 { + + private final Pattern pattern = Pattern.compile("foo"); // Compliant + + public boolean foo() { + return pattern.matcher("foo").find(); + } +} diff --git a/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern3.java b/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern3.java new file mode 100644 index 00000000..e1907345 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern3.java @@ -0,0 +1,16 @@ +package fr.greencodeinitiative.java.checks; + +import java.util.regex.Pattern; + +public class ValidRegexPattern3 { + + private final Pattern pattern; + + public ValidRegexPattern3() { + pattern = Pattern.compile("foo"); // Compliant + } + + public boolean foo() { + return pattern.matcher("foo").find(); + } +} From 44728f0c4ced10f193d3e6676031ba48a427414a Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 10 Mar 2023 12:11:39 +0100 Subject: [PATCH 003/233] [ISSUE 65] optimization on ArrayCopyCheck class (to limit some useless errors) --- .../java/checks/ArrayCopyCheck.java | 1033 +++++++++-------- 1 file changed, 547 insertions(+), 486 deletions(-) diff --git a/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java index 5e1aa513..2794cf96 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java @@ -4,490 +4,551 @@ class ArrayCopyCheck { - public void copyArrayOK() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Copy with clone - dest = src.clone(); - - // Copy with System.arraycopy() - System.arraycopy(src, 0, dest, 0, src.length); - - // Copy with Arrays.copyOf() - dest = Arrays.copyOf(src, src.length); - } - - public void nonRegression() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple assignation - for (int i = 0; i < len; i++) { - dest[i] = true; - } - - // Edit same array - for (int i = 0; i < len-1; i++) { - dest[i] = dest[i+1]; - } - - // Objects assignations - String a = null; - String b = "Sample Value"; - for (int i = 0; i < len; i++) { - a = b; - } - } - - public void copyWithForLoop() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple copy - for (int i = 0; i < len; i++) { // Noncompliant - dest[i] = src[i]; - } - - // Copy with nested conditions - for (int i = 0; i < len; i++) { // Noncompliant - if(i + 2 < len) { - dest[i] = src[i + 2]; - } - } - - // Copy with nested ELSE conditions - for (int i = 0; i < len; i++) { // Noncompliant - if(i + 2 >= len) { - i++; - } else { - dest[i] = src[i + 2]; - } - } - - // Copy with more nested conditions - for (int i = 0; i < len; i++) { // Noncompliant - if(i + 2 < len) { - if(dest != null) { - if(src != null) { - if(i > 1 && i + 2 < src.length) { - dest[i] = src[i + 2]; - } - } - } - } - } - - // Copy nested by try/catch - for (int i = 0; i < len; i++) { // Noncompliant - try { - dest[i] = src[i]; - } catch (RuntimeException e) { - e.printStackTrace(); - } - } - - // Copy nested by try/catch and if - for (int i = 0; i < len; i++) { // Noncompliant - try { - if(dest != null) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - } - - // Copy nested by try/catch in catch - for (int i = 0; i < len; i++) { // Noncompliant - try { - dest.toString(); - } catch (RuntimeException e) { - if(dest != null) { - dest[i] = src[i]; - } - } - } - - // Copy nested by try/catch in finally - for (int i = 0; i < len; i++) { // Noncompliant - try { - dest.toString(); - } catch (RuntimeException e) { - e.printStackTrace(); - } finally { - dest[i] = src[i]; - } - } - - // Array transformation - for (int i = 0; i < len; i++) { - dest[i] = transform(src[i]); - } - } - - public void copyWithForEachLoop() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple copy by foreach - int i = -1; - for (boolean b : src) { // Noncompliant - dest[++i] = b; - } - - // Copy with nested conditions by foreach - i = -1; - for (boolean b : src) { // Noncompliant - if(b) { - dest[++i] = b; - } - } - - // Copy with nested ELSE conditions by foreach - i = -1; - for (boolean b : src) { // Noncompliant - if(i + 2 >= len) { - i++; - } else { - dest[++i] = b; - } - } - - // Copy with more nested conditions - i = -1; - for (boolean b : src) { // Noncompliant - if(i + 2 < len) { - if(dest != null) { - if(src != null) { - if(i > 1 && i + 2 < src.length) { - dest[++i] = b; - } - } - } - } - } - - // Copy nested by try/catch - i = -1; - for (boolean b : src) { // Noncompliant - try { - dest[++i] = b; - } catch (RuntimeException e) { - e.printStackTrace(); - } - } - - // Copy nested by try/catch and if - i = -1; - for (boolean b : src) { // Noncompliant - try { - if(dest != null) { - dest[++i] = b; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - } - - // Copy nested by try/catch in catch - i = -1; - for (boolean b : src) { // Noncompliant - try { - dest.toString(); - } catch (RuntimeException e) { - if(dest != null) { - dest[++i] = b; - } - } - } - - // Copy nested by try/catch in finally - i = -1; - for (boolean b : src) { // Noncompliant - try { - dest.toString(); - } catch (RuntimeException e) { - e.printStackTrace(); - } finally { - dest[++i] = b; - } - } - - // Array transformation - i = -1; - for (boolean b : src) { - dest[++i] = transform(b); - } - - // Simple copy - i = 0; - for (boolean b : src) { // Noncompliant - dest[i] = src[i]; - i++; - } - - // Copy with nested conditions - i = 0; - for (boolean b : src) { // Noncompliant - if(b) { - dest[i] = src[i]; - } - i++; - } - - // Copy with nested ELSE conditions - i = 0; - for (boolean b : src) { // Noncompliant - if(i + 2 >= len) { - i++; - } else { - dest[i] = src[i + 2]; - } - i++; - } - - // Copy with more nested conditions - i = 0; - for (boolean b : src) { // Noncompliant - if(i + 2 < len) { - if(dest != null) { - if(src != null) { - if(i > 1 && i + 2 < src.length) { - dest[i] = src[i + 2]; - } - } - } - } - i++; - } - - // Copy nested by try/catch - i = 0; - for (boolean b : src) { // Noncompliant - try { - dest[i] = src[i]; - } catch (RuntimeException e) { - e.printStackTrace(); - } - i++; - } - - // Copy nested by try/catch and if - i = 0; - for (boolean b : src) { // Noncompliant - try { - if(dest != null) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - i++; - } - - // Copy nested by try/catch in catch - i = 0; - for (boolean b : src) { // Noncompliant - try { - dest.toString(); - } catch (RuntimeException e) { - if(dest != null) { - dest[i] = src[i]; - } - } - i++; - } - - // Copy nested by try/catch in finally - i = 0; - for (boolean b : src) { // Noncompliant - try { - dest.toString(); - } catch (RuntimeException e) { - e.printStackTrace(); - } finally { - dest[i] = src[i]; - } - i++; - } - - // Array transformation - i = 0; - for (boolean b : src) { - dest[i] = transform(src[i]); - i++; - } - } - - public void copyWithWhileLoop() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple copy - int i = 0; - while (i < len) { // Noncompliant - dest[i] = src[i]; - i++; - } - - // Copy with nested conditions - i = 0; - while (i < len) { // Noncompliant - if(i + 2 < len) { - dest[i] = src[i + 2]; - } - i++; - } - - // Copy with nested ELSE conditions - i = 0; - while (i < len) { // Noncompliant - if(i + 2 >= len) { - i++; - } else { - dest[i] = src[i + 2]; - } - i++; - } - - // Copy with more nested conditions - i = 0; - while (i < len) { // Noncompliant - if(i + 2 < len) { - if(dest != null) { - if(src != null) { - if(i > 1 && i + 2 < src.length) { - dest[i] = src[i + 2]; - } - } - } - } - i++; - } - - // Copy nested by try/catch and if - i = 0; - while (i < len) { // Noncompliant - try { - if(dest != null) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - i++; - } - - // Copy nested by try/catch in catch - i = 0; - while (i < len) { // Noncompliant - try { - dest.toString(); - } catch (RuntimeException e) { - if(dest != null) { - dest[i] = src[i]; - } - } - i++; - } - - // Array transformation - i = 0; - while (i < len) { - dest[i] = transform(src[i]); - i++; - } - } - - public void copyWithDoWhileLoop() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple copy - int i = 0; - do { // Noncompliant - dest[i] = src[i]; - i++; - } while (i < len); - - // Copy with nested conditions - i = 0; - do { // Noncompliant - if(i + 2 < len) { - dest[i] = src[i + 2]; - } - i++; - } while (i < len); - - // Copy with nested ELSE conditions - i = 0; - do { // Noncompliant - if(i + 2 >= len) { - i++; - } else { - dest[i] = src[i + 2]; - } - i++; - } while (i < len); - - // Copy with more nested conditions - i = 0; - do { // Noncompliant - if(i + 2 < len) { - if(dest != null) { - if(src != null) { - if(i > 1 && i + 2 < src.length) { - dest[i] = src[i + 2]; - } - } - } - } - i++; - } while (i < len); - - // Copy nested by try/catch and if - i = 0; - do { // Noncompliant - try { - if(dest != null) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - i++; - } while (i < len); - - // Copy nested by try/catch in catch - i = 0; - do { // Noncompliant - try { - dest.toString(); - } catch (RuntimeException e) { - if(dest != null) { - dest[i] = src[i]; - } - } - i++; - } while (i < len); - - // Array transformation - i = 0; - do { - dest[i] = transform(src[i]); - i++; - } while (i < len); - } - - private boolean transform(boolean a) { - return !a; - } - + public void copyArrayOK() { + final int len = 5; + final boolean[] src = new boolean[len]; + + // Copy with clone + boolean[] dest = src.clone(); + + // Copy with System.arraycopy() + System.arraycopy(src, 0, dest, 0, src.length); + + // Copy with Arrays.copyOf() + dest = Arrays.copyOf(src, src.length); + + System.out.println(dest); + } + + public void nonRegression() { + final int len = 5; + boolean[] dest = new boolean[len]; + + // Simple assignation + for (int i = 0; i < len; i++) { + dest[i] = true; + } + + // Edit same array + for (int i = 0; i < len - 1; i++) { + dest[i] = dest[i + 1]; + } + + // Objects assignations + String a = null; + String b = "Sample Value"; + for (int i = 0; i < len; i++) { + a = b; + } + + System.out.println(a); + } + + public void copyWithForLoop() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple copy + for (int i = 0; i < len; i++) { + dest[i] = src[i]; + } // Noncompliant + + // Copy with nested conditions + for (int i = 0; i < len; i++) { + if (i + 2 < len) { + dest[i] = src[i + 2]; + } + } // Noncompliant + + // Copy with nested ELSE conditions + for (int i = 0; i < len; i++) { + if (i + 2 >= len) { + System.out.println("just to have a 'if' + 'else'"); + } else { + dest[i] = src[i + 2]; + } + } // Noncompliant + + // Copy with more nested conditions + for (int i = 0; i < len; i++) { + if (i + 2 < len) { + if (dest != null) { + if (src != null) { + if (i > 1 && i + 2 < src.length) { + dest[i] = src[i + 2]; + } else { + System.out.println("just to have a 'else' 1"); + } + } else { + System.out.println("just to have a 'else' 2"); + } + } else { + System.out.println("just to have a 'else' 3"); + } + } + } // Noncompliant + + // Copy nested by try/catch + for (int i = 0; i < len; i++) { + try { + dest[i] = src[i]; + } catch (RuntimeException e) { + e.printStackTrace(); + } + } // Noncompliant + + // Copy nested by try/catch and if + for (int i = 0; i < len; i++) { + try { + if (dest != null) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + } // Noncompliant + + // Copy nested by try/catch in catch + for (int i = 0; i < len; i++) { + try { + Arrays.toString(dest); + } catch (RuntimeException e) { + e.printStackTrace(); + if (dest != null) { + dest[i] = src[i]; + } + } + } // Noncompliant + + // Copy nested by try/catch in finally + for (int i = 0; i < len; i++) { + try { + dest.toString(); + } catch (RuntimeException e) { + e.printStackTrace(); + } finally { + dest[i] = src[i]; + } + } // Noncompliant + + // Array transformation + for (int i = 0; i < len; i++) { + dest[i] = transform(src[i]); + } + } + + public void copyWithForEachLoop() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple copy by foreach + int i = -1; + for (boolean b : src) { + dest[++i] = b; + } // Noncompliant + + // Copy with nested conditions by foreach + i = -1; + for (boolean b : src) { + if (b) { + dest[++i] = b; + } + } // Noncompliant + + // Copy with nested ELSE conditions by foreach + i = -1; + for (boolean b : src) { + if (i + 2 >= len) { + i++; + } else { + dest[++i] = b; + } + } // Noncompliant + + // Copy with more nested conditions + i = -1; + for (boolean b : src) { + if (i + 2 < len) { + if (dest != null) { + if (src != null) { + if (i > 1 && i + 2 < src.length) { + dest[++i] = b; + } else { + System.out.println("just to have a 'else' 1"); + } + } else { + System.out.println("just to have a 'else' 2"); + } + } else { + System.out.println("just to have a 'else' 3"); + } + } else { + System.out.println("just to have a 'else' 4"); + } + } // Noncompliant + + // Copy nested by try/catch + i = -1; + for (boolean b : src) { + try { + dest[++i] = b; + } catch (RuntimeException e) { + e.printStackTrace(); + } + } // Noncompliant + + // Copy nested by try/catch and if + i = -1; + for (boolean b : src) { + try { + if (dest != null) { + dest[++i] = b; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + } // Noncompliant + + // Copy nested by try/catch in catch + i = -1; + for (boolean b : src) { + try { + if (b) { + Arrays.toString(dest); + } + } catch (RuntimeException e) { + e.printStackTrace(); + if (dest != null) { + dest[++i] = b; + } + } + } // Noncompliant + + // Copy nested by try/catch in finally + i = -1; + for (boolean b : src) { + try { + if (b) { + Arrays.toString(dest); + } + } catch (RuntimeException e) { + e.printStackTrace(); + } finally { + dest[++i] = b; + } + } // Noncompliant + + // Array transformation + i = -1; + for (boolean b : src) { + dest[++i] = transform(b); + } + + // Simple copy + i = 0; + for (boolean b : src) { + if (b) { + dest[i] = src[i]; + i++; + } + } // Noncompliant + + // Copy with nested conditions + i = 0; + for (boolean b : src) { + if (b) { + dest[i] = src[i]; + } + i++; + } // Noncompliant + + // Copy with nested ELSE conditions + i = 0; + for (boolean b : src) { + if (b) { + if (i + 2 >= len) { + i++; + } else { + dest[i] = src[i + 2]; + } + i++; + } + } // Noncompliant + + // Copy with more nested conditions + i = 0; + for (boolean b : src) { + if (b) { + if (i + 2 < len) { + if (dest != null) { + if (src != null) { + if (i > 1 && i + 2 < src.length) { + dest[i] = src[i + 2]; + } else { + System.out.println("just to have a 'else' 1"); + } + } else { + System.out.println("just to have a 'else' 2"); + } + } else { + System.out.println("just to have a 'else' 3"); + } + } else { + System.out.println("just to have a 'else' 4"); + } + i++; + } else { + System.out.println("just to have a 'else' 5"); + } + } // Noncompliant + + // Copy nested by try/catch + i = 0; + for (boolean b : src) { + try { + if (b) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + i++; + } // Noncompliant + + // Copy nested by try/catch and if + i = 0; + for (boolean b : src) { + try { + if (b && dest != null) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + i++; + } // Noncompliant + + // Copy nested by try/catch in catch + i = 0; + for (boolean b : src) { + try { + if (b) { + Arrays.toString(dest); + } + } catch (RuntimeException e) { + e.printStackTrace(); + if (dest != null) { + dest[i] = src[i]; + } + } + i++; + } // Noncompliant + + // Copy nested by try/catch in finally + i = 0; + for (boolean b : src) { + try { + if (b) { + Arrays.toString(dest); + } + } catch (RuntimeException e) { + e.printStackTrace(); + } finally { + dest[i] = src[i]; + } + i++; + } // Noncompliant + + // Array transformation + i = 0; + for (boolean b : src) { + if (b) { + dest[i] = transform(src[i]); + i++; + } + } + } + + public void copyWithWhileLoop() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple copy + int i = 0; + while (i < len) { + dest[i] = src[i]; + i++; + } // Noncompliant + + // Copy with nested conditions + i = 0; + while (i < len) { + if (i + 2 < len) { + dest[i] = src[i + 2]; + } + i++; + } // Noncompliant + + // Copy with nested ELSE conditions + i = 0; + while (i < len) { + if (i + 2 >= len) { + i++; + } else { + dest[i] = src[i + 2]; + } + i++; + } // Noncompliant + + // Copy with more nested conditions + i = 0; + while (i < len) { + if (i + 2 < len) { + if (dest != null) { + if (src != null) { + if (i > 1 && i + 2 < src.length) { + dest[i] = src[i + 2]; + } else { + System.out.println("just to have a 'else' 1"); + } + } else { + System.out.println("just to have a 'else' 2"); + } + } else { + System.out.println("just to have a 'else' 3"); + } + } + i++; + } // Noncompliant + + // Copy nested by try/catch and if + i = 0; + while (i < len) { + try { + if (dest != null) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + i++; + } // Noncompliant + + // Copy nested by try/catch in catch + i = 0; + while (i < len) { + try { + Arrays.toString(dest); + } catch (RuntimeException e) { + e.printStackTrace(); + if (dest != null) { + dest[i] = src[i]; + } + } + i++; + } // Noncompliant + + // Array transformation + i = 0; + while (i < len) { + dest[i] = transform(src[i]); + i++; + } + } + + public void copyWithDoWhileLoop() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple copy + int i = 0; + do { + dest[i] = src[i]; + i++; + } while (i < len); // Noncompliant + + // Copy with nested conditions + i = 0; + do { + if (i + 2 < len) { + dest[i] = src[i + 2]; + } + i++; + } while (i < len); // Noncompliant + + // Copy with nested ELSE conditions + i = 0; + do { + if (i + 2 >= len) { + i++; + } else { + dest[i] = src[i + 2]; + } + i++; + } while (i < len); // Noncompliant + + // Copy with more nested conditions + i = 0; + do { + if (i + 2 < len) { + if (dest != null) { + if (src != null) { + if (i > 1 && i + 2 < src.length) { + dest[i] = src[i + 2]; + } else { + System.out.println("just to have a 'else' 1"); + } + } else { + System.out.println("just to have a 'else' 2"); + } + } else { + System.out.println("just to have a 'else' 3"); + } + } + i++; + } while (i < len); // Noncompliant + + // Copy nested by try/catch and if + i = 0; + do { + try { + if (dest != null) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + i++; + } while (i < len); // Noncompliant + + // Copy nested by try/catch in catch + i = 0; + do { + try { + Arrays.toString(dest); + } catch (RuntimeException e) { + e.printStackTrace(); + if (dest != null) { + dest[i] = src[i]; + } + } + i++; + } while (i < len); // Noncompliant + + // Array transformation + i = 0; + do { + dest[i] = transform(src[i]); + i++; + } while (i < len); + } + + private boolean transform(boolean a) { + return !a; + } + } \ No newline at end of file From 89e9e6353c038aa96693562e1afa2a02904f5744 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 10 Mar 2023 12:21:18 +0100 Subject: [PATCH 004/233] [ISSUE 65] optimization on ArrayCopyCheck class (to limit some useless errors) - BIS --- .../java/checks/ArrayCopyCheck.java | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java index 2794cf96..259b0fb6 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java @@ -17,7 +17,7 @@ public void copyArrayOK() { // Copy with Arrays.copyOf() dest = Arrays.copyOf(src, src.length); - System.out.println(dest); + System.err.println(dest); } public void nonRegression() { @@ -41,7 +41,7 @@ public void nonRegression() { a = b; } - System.out.println(a); + System.err.println(a); } public void copyWithForLoop() { @@ -64,7 +64,7 @@ public void copyWithForLoop() { // Copy with nested ELSE conditions for (int i = 0; i < len; i++) { if (i + 2 >= len) { - System.out.println("just to have a 'if' + 'else'"); + System.err.println("just to have a 'if' + 'else'"); } else { dest[i] = src[i + 2]; } @@ -78,13 +78,13 @@ public void copyWithForLoop() { if (i > 1 && i + 2 < src.length) { dest[i] = src[i + 2]; } else { - System.out.println("just to have a 'else' 1"); + System.err.println("just to have a 'else' 1"); } } else { - System.out.println("just to have a 'else' 2"); + System.err.println("just to have a 'else' 2"); } } else { - System.out.println("just to have a 'else' 3"); + System.err.println("just to have a 'else' 3"); } } } // Noncompliant @@ -124,7 +124,7 @@ public void copyWithForLoop() { // Copy nested by try/catch in finally for (int i = 0; i < len; i++) { try { - dest.toString(); + Arrays.toString(dest); } catch (RuntimeException e) { e.printStackTrace(); } finally { @@ -176,16 +176,16 @@ public void copyWithForEachLoop() { if (i > 1 && i + 2 < src.length) { dest[++i] = b; } else { - System.out.println("just to have a 'else' 1"); + System.err.println("just to have a 'else' 1"); } } else { - System.out.println("just to have a 'else' 2"); + System.err.println("just to have a 'else' 2"); } } else { - System.out.println("just to have a 'else' 3"); + System.err.println("just to have a 'else' 3"); } } else { - System.out.println("just to have a 'else' 4"); + System.err.println("just to have a 'else' 4"); } } // Noncompliant @@ -287,20 +287,20 @@ public void copyWithForEachLoop() { if (i > 1 && i + 2 < src.length) { dest[i] = src[i + 2]; } else { - System.out.println("just to have a 'else' 1"); + System.err.println("just to have a 'else' 1"); } } else { - System.out.println("just to have a 'else' 2"); + System.err.println("just to have a 'else' 2"); } } else { - System.out.println("just to have a 'else' 3"); + System.err.println("just to have a 'else' 3"); } } else { - System.out.println("just to have a 'else' 4"); + System.err.println("just to have a 'else' 4"); } i++; } else { - System.out.println("just to have a 'else' 5"); + System.err.println("just to have a 'else' 5"); } } // Noncompliant @@ -412,13 +412,13 @@ public void copyWithWhileLoop() { if (i > 1 && i + 2 < src.length) { dest[i] = src[i + 2]; } else { - System.out.println("just to have a 'else' 1"); + System.err.println("just to have a 'else' 1"); } } else { - System.out.println("just to have a 'else' 2"); + System.err.println("just to have a 'else' 2"); } } else { - System.out.println("just to have a 'else' 3"); + System.err.println("just to have a 'else' 3"); } } i++; @@ -500,13 +500,13 @@ public void copyWithDoWhileLoop() { if (i > 1 && i + 2 < src.length) { dest[i] = src[i + 2]; } else { - System.out.println("just to have a 'else' 1"); + System.err.println("just to have a 'else' 1"); } } else { - System.out.println("just to have a 'else' 2"); + System.err.println("just to have a 'else' 2"); } } else { - System.out.println("just to have a 'else' 3"); + System.err.println("just to have a 'else' 3"); } } i++; From 129f981743e5ddd839c9a11094d58adc0cc9fbbc Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 10 Mar 2023 12:55:10 +0100 Subject: [PATCH 005/233] [ISSUE 65] upgrade README.md --- README.md | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 458a90df..8791d6ef 100644 --- a/README.md +++ b/README.md @@ -2,31 +2,28 @@ Purpose of this project --- To check locally all rules on java language. To do this : + - first launch local development environment (SonarQube) - launch sonar maven command to send sonar metrics to local SonarQube -- check if each Java class contains (or not) the rule error defined for this class +- on local SonarQube, check if each Java class contains (or not) the rule error defined for this class -Step 0 : requirements +Step 1 : prepare local environment --- -launch local environment with tools : -- `/tool_build.sh` -- `/tool_start.sh` (if docker environment already built) -- `/tool_docker-init.sh` (if docker environment not built yet) -check https://localhost:9000 -configure (if docker environment already built) : -- change password of admin user -- check if plugin is installed on "marketPlace" tab on Administration -- create a new profile on each language to test - extend from Sonar WAY -- make this new profile as default -- add all rules "eco-conception" tagged on this new profile +To launch local environment : please follow https://github.com/green-code-initiative/ecoCode/blob/main/INSTALL.md +(especially SonarQube configuration part) Step 1 : compile and build --- `mvn clean compile` -Step 2 : Send Sonar metrics to local SonarQube +Step 2 : send Sonar metrics to local SonarQube --- `mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.login=admin -Dsonar.password=XXX` + +Step 3 : check errors +--- +on local SonarQube, check if each Java class contains (or not) the rule error defined for this class +(for example : you can search for tag `eco-conception` rule on a special file) From bc5ab7ed4a5ebccf9aaa021e596e0ac3ac37c5b0 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Sat, 11 Mar 2023 22:50:27 +0100 Subject: [PATCH 006/233] add LICENCE.md --- LICENCE.md | 674 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 674 insertions(+) create mode 100644 LICENCE.md diff --git a/LICENCE.md b/LICENCE.md new file mode 100644 index 00000000..20d40b6b --- /dev/null +++ b/LICENCE.md @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. \ No newline at end of file From d5ca9e934cca4cab5ab3ea0932d5abf64359bf0c Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Sat, 11 Mar 2023 23:36:45 +0100 Subject: [PATCH 007/233] fix version project --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 62aa4caf..8bf9a4d7 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ io.ecocode ecocode-java-plugin-test-project - 0.3.0-SNAPSHOT + 0.0.1-SNAPSHOT ecoCode Java Sonar Plugin Test Project From e285b39f9d3da7ac63c9b13ecc80ed4a91d774af Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Sun, 12 Mar 2023 22:45:46 +0100 Subject: [PATCH 008/233] Add tool scripts --- tool_build.sh | 3 +++ tool_sonar.sh | 4 ++++ 2 files changed, 7 insertions(+) create mode 100755 tool_build.sh create mode 100755 tool_sonar.sh diff --git a/tool_build.sh b/tool_build.sh new file mode 100755 index 00000000..84820a4a --- /dev/null +++ b/tool_build.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +mvn clean package diff --git a/tool_sonar.sh b/tool_sonar.sh new file mode 100755 index 00000000..728a0f5a --- /dev/null +++ b/tool_sonar.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +# "sonar.login" variable : private TOKEN generated in your local SonarQube during installation +mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.login=sqa_919e0287178896de96aa019e300e85a93c9acc2d From bfee59ac33d1e6e0d0bfa18e87184fe6845113ab Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Sun, 12 Mar 2023 23:02:12 +0100 Subject: [PATCH 009/233] rename tool sonar --- tool_sonar.sh => tool_send_to_sonar.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tool_sonar.sh => tool_send_to_sonar.sh (100%) diff --git a/tool_sonar.sh b/tool_send_to_sonar.sh similarity index 100% rename from tool_sonar.sh rename to tool_send_to_sonar.sh From 362b8f06127987d2e2e965b055d0ff673e6b58be Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Sun, 12 Mar 2023 23:06:02 +0100 Subject: [PATCH 010/233] upgrade doc --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8791d6ef..c3c5d91c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ Purpose of this project --- + To check locally all rules on java language. To do this : @@ -16,14 +17,15 @@ To launch local environment : please follow https://github.com/green-code-initia Step 1 : compile and build --- -`mvn clean compile` +`./tool_build.sh` Step 2 : send Sonar metrics to local SonarQube --- -`mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.login=admin -Dsonar.password=XXX` +before, change the token inside script and then launch `./tool_send_to_sonar.sh` Step 3 : check errors --- + on local SonarQube, check if each Java class contains (or not) the rule error defined for this class (for example : you can search for tag `eco-conception` rule on a special file) From 1e49a9cfce1cc8b1525c5306ae78af1eba9d76bc Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Mon, 13 Mar 2023 13:55:04 +0100 Subject: [PATCH 011/233] upgrade doc --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c3c5d91c..1a773411 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,8 @@ Step 1 : compile and build Step 2 : send Sonar metrics to local SonarQube --- -before, change the token inside script and then launch `./tool_send_to_sonar.sh` +- first : change the token inside script (to give your personal SonarQube token, previously generated, please see install documention) +- secondly : launch `./tool_send_to_sonar.sh` Step 3 : check errors --- From dab4d8bfe093b2c4f7e04a9a0b6c8a2eb94a5160 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 17 Mar 2023 17:13:02 +0100 Subject: [PATCH 012/233] Update source files --- README.md | 2 +- .../java/checks/ArrayCopyCheck.java | 1043 ++++++++--------- .../checks/AvoidConcatenateStringsInLoop.java | 6 +- .../java/checks/AvoidFullSQLRequestCheck.java | 8 +- ...voidGettingSizeCollectionInForLoopBad.java | 2 +- ...idGettingSizeCollectionInWhileLoopBad.java | 2 +- .../checks/AvoidRegexPatternNotStatic.java | 2 +- .../checks/AvoidSQLRequestInLoopCheck.java | 6 +- .../AvoidSetConstantInBatchUpdateCheck.java | 72 +- .../checks/AvoidStatementForDMLQueries.java | 2 +- .../checks/AvoidUsageOfStaticCollections.java | 6 +- .../AvoidUsingGlobalVariablesCheck.java | 6 +- .../java/checks/IncrementCheck.java | 4 +- .../InitializeBufferWithAppropriateSize.java | 4 +- .../NoFunctionCallWhenDeclaringForLoop.java | 8 +- .../OptimizeReadFileExceptionCheck.java | 2 +- .../OptimizeReadFileExceptionCheck2.java | 2 +- .../OptimizeReadFileExceptionCheck3.java | 2 +- .../OptimizeReadFileExceptionCheck4.java | 2 +- .../OptimizeReadFileExceptionCheck5.java | 2 +- ...arilyAssignValuesToVariablesTestCheck.java | 6 +- .../java/checks/UseCorrectForLoopCheck.java | 2 +- 22 files changed, 565 insertions(+), 626 deletions(-) diff --git a/README.md b/README.md index 1a773411..3b45ed00 100644 --- a/README.md +++ b/README.md @@ -29,4 +29,4 @@ Step 3 : check errors --- on local SonarQube, check if each Java class contains (or not) the rule error defined for this class -(for example : you can search for tag `eco-conception` rule on a special file) +(for example : you can search for tag `eco-design` rule on a special file) diff --git a/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java index 259b0fb6..d1889051 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java @@ -1,554 +1,493 @@ -package fr.greencodeinitiative.java.checks; - import java.util.Arrays; - -class ArrayCopyCheck { - - public void copyArrayOK() { - final int len = 5; - final boolean[] src = new boolean[len]; - - // Copy with clone - boolean[] dest = src.clone(); - - // Copy with System.arraycopy() - System.arraycopy(src, 0, dest, 0, src.length); - - // Copy with Arrays.copyOf() - dest = Arrays.copyOf(src, src.length); - - System.err.println(dest); - } - - public void nonRegression() { - final int len = 5; - boolean[] dest = new boolean[len]; - - // Simple assignation - for (int i = 0; i < len; i++) { - dest[i] = true; - } - - // Edit same array - for (int i = 0; i < len - 1; i++) { - dest[i] = dest[i + 1]; - } - - // Objects assignations - String a = null; - String b = "Sample Value"; - for (int i = 0; i < len; i++) { - a = b; - } - - System.err.println(a); - } - - public void copyWithForLoop() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple copy - for (int i = 0; i < len; i++) { - dest[i] = src[i]; - } // Noncompliant - - // Copy with nested conditions - for (int i = 0; i < len; i++) { - if (i + 2 < len) { - dest[i] = src[i + 2]; - } - } // Noncompliant - - // Copy with nested ELSE conditions - for (int i = 0; i < len; i++) { - if (i + 2 >= len) { - System.err.println("just to have a 'if' + 'else'"); - } else { - dest[i] = src[i + 2]; - } - } // Noncompliant - - // Copy with more nested conditions - for (int i = 0; i < len; i++) { - if (i + 2 < len) { - if (dest != null) { - if (src != null) { - if (i > 1 && i + 2 < src.length) { - dest[i] = src[i + 2]; - } else { - System.err.println("just to have a 'else' 1"); - } - } else { - System.err.println("just to have a 'else' 2"); - } - } else { - System.err.println("just to have a 'else' 3"); - } - } - } // Noncompliant - - // Copy nested by try/catch - for (int i = 0; i < len; i++) { - try { - dest[i] = src[i]; - } catch (RuntimeException e) { - e.printStackTrace(); - } - } // Noncompliant - - // Copy nested by try/catch and if - for (int i = 0; i < len; i++) { - try { - if (dest != null) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - } // Noncompliant - - // Copy nested by try/catch in catch - for (int i = 0; i < len; i++) { - try { - Arrays.toString(dest); - } catch (RuntimeException e) { - e.printStackTrace(); - if (dest != null) { - dest[i] = src[i]; - } - } - } // Noncompliant - - // Copy nested by try/catch in finally - for (int i = 0; i < len; i++) { - try { - Arrays.toString(dest); - } catch (RuntimeException e) { - e.printStackTrace(); - } finally { - dest[i] = src[i]; - } - } // Noncompliant - - // Array transformation - for (int i = 0; i < len; i++) { - dest[i] = transform(src[i]); - } - } - - public void copyWithForEachLoop() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple copy by foreach - int i = -1; - for (boolean b : src) { - dest[++i] = b; - } // Noncompliant - - // Copy with nested conditions by foreach - i = -1; - for (boolean b : src) { - if (b) { - dest[++i] = b; - } - } // Noncompliant - - // Copy with nested ELSE conditions by foreach - i = -1; - for (boolean b : src) { - if (i + 2 >= len) { - i++; - } else { - dest[++i] = b; - } - } // Noncompliant - - // Copy with more nested conditions - i = -1; - for (boolean b : src) { - if (i + 2 < len) { - if (dest != null) { - if (src != null) { - if (i > 1 && i + 2 < src.length) { - dest[++i] = b; - } else { - System.err.println("just to have a 'else' 1"); - } - } else { - System.err.println("just to have a 'else' 2"); - } - } else { - System.err.println("just to have a 'else' 3"); - } - } else { - System.err.println("just to have a 'else' 4"); - } - } // Noncompliant - - // Copy nested by try/catch - i = -1; - for (boolean b : src) { - try { - dest[++i] = b; - } catch (RuntimeException e) { - e.printStackTrace(); - } - } // Noncompliant - - // Copy nested by try/catch and if - i = -1; - for (boolean b : src) { - try { - if (dest != null) { - dest[++i] = b; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - } // Noncompliant - - // Copy nested by try/catch in catch - i = -1; - for (boolean b : src) { - try { - if (b) { - Arrays.toString(dest); - } - } catch (RuntimeException e) { - e.printStackTrace(); - if (dest != null) { - dest[++i] = b; - } - } - } // Noncompliant - - // Copy nested by try/catch in finally - i = -1; - for (boolean b : src) { - try { - if (b) { - Arrays.toString(dest); - } - } catch (RuntimeException e) { - e.printStackTrace(); - } finally { - dest[++i] = b; - } - } // Noncompliant - - // Array transformation - i = -1; - for (boolean b : src) { - dest[++i] = transform(b); - } - - // Simple copy - i = 0; - for (boolean b : src) { - if (b) { - dest[i] = src[i]; - i++; - } - } // Noncompliant - - // Copy with nested conditions - i = 0; - for (boolean b : src) { - if (b) { - dest[i] = src[i]; - } - i++; - } // Noncompliant - - // Copy with nested ELSE conditions - i = 0; - for (boolean b : src) { - if (b) { - if (i + 2 >= len) { - i++; - } else { - dest[i] = src[i + 2]; - } - i++; - } - } // Noncompliant - - // Copy with more nested conditions - i = 0; - for (boolean b : src) { - if (b) { - if (i + 2 < len) { - if (dest != null) { - if (src != null) { - if (i > 1 && i + 2 < src.length) { - dest[i] = src[i + 2]; - } else { - System.err.println("just to have a 'else' 1"); - } - } else { - System.err.println("just to have a 'else' 2"); - } - } else { - System.err.println("just to have a 'else' 3"); - } - } else { - System.err.println("just to have a 'else' 4"); - } - i++; - } else { - System.err.println("just to have a 'else' 5"); - } - } // Noncompliant - - // Copy nested by try/catch - i = 0; - for (boolean b : src) { - try { - if (b) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - i++; - } // Noncompliant - - // Copy nested by try/catch and if - i = 0; - for (boolean b : src) { - try { - if (b && dest != null) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - i++; - } // Noncompliant - - // Copy nested by try/catch in catch - i = 0; - for (boolean b : src) { - try { - if (b) { - Arrays.toString(dest); - } - } catch (RuntimeException e) { - e.printStackTrace(); - if (dest != null) { - dest[i] = src[i]; - } - } - i++; - } // Noncompliant - - // Copy nested by try/catch in finally - i = 0; - for (boolean b : src) { - try { - if (b) { - Arrays.toString(dest); - } - } catch (RuntimeException e) { - e.printStackTrace(); - } finally { - dest[i] = src[i]; - } - i++; - } // Noncompliant - - // Array transformation - i = 0; - for (boolean b : src) { - if (b) { - dest[i] = transform(src[i]); - i++; - } - } - } - - public void copyWithWhileLoop() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple copy - int i = 0; - while (i < len) { - dest[i] = src[i]; - i++; - } // Noncompliant - - // Copy with nested conditions - i = 0; - while (i < len) { - if (i + 2 < len) { - dest[i] = src[i + 2]; - } - i++; - } // Noncompliant - - // Copy with nested ELSE conditions - i = 0; - while (i < len) { - if (i + 2 >= len) { - i++; - } else { - dest[i] = src[i + 2]; - } - i++; - } // Noncompliant - - // Copy with more nested conditions - i = 0; - while (i < len) { - if (i + 2 < len) { - if (dest != null) { - if (src != null) { - if (i > 1 && i + 2 < src.length) { - dest[i] = src[i + 2]; - } else { - System.err.println("just to have a 'else' 1"); - } - } else { - System.err.println("just to have a 'else' 2"); - } - } else { - System.err.println("just to have a 'else' 3"); - } - } - i++; - } // Noncompliant - - // Copy nested by try/catch and if - i = 0; - while (i < len) { - try { - if (dest != null) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - i++; - } // Noncompliant - - // Copy nested by try/catch in catch - i = 0; - while (i < len) { - try { - Arrays.toString(dest); - } catch (RuntimeException e) { - e.printStackTrace(); - if (dest != null) { - dest[i] = src[i]; - } - } - i++; - } // Noncompliant - - // Array transformation - i = 0; - while (i < len) { - dest[i] = transform(src[i]); - i++; - } - } - - public void copyWithDoWhileLoop() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple copy - int i = 0; - do { - dest[i] = src[i]; - i++; - } while (i < len); // Noncompliant - - // Copy with nested conditions - i = 0; - do { - if (i + 2 < len) { - dest[i] = src[i + 2]; - } - i++; - } while (i < len); // Noncompliant - - // Copy with nested ELSE conditions - i = 0; - do { - if (i + 2 >= len) { - i++; - } else { - dest[i] = src[i + 2]; - } - i++; - } while (i < len); // Noncompliant - - // Copy with more nested conditions - i = 0; - do { - if (i + 2 < len) { - if (dest != null) { - if (src != null) { - if (i > 1 && i + 2 < src.length) { - dest[i] = src[i + 2]; - } else { - System.err.println("just to have a 'else' 1"); - } - } else { - System.err.println("just to have a 'else' 2"); - } - } else { - System.err.println("just to have a 'else' 3"); - } - } - i++; - } while (i < len); // Noncompliant - - // Copy nested by try/catch and if - i = 0; - do { - try { - if (dest != null) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - i++; - } while (i < len); // Noncompliant - - // Copy nested by try/catch in catch - i = 0; - do { - try { - Arrays.toString(dest); - } catch (RuntimeException e) { - e.printStackTrace(); - if (dest != null) { - dest[i] = src[i]; - } - } - i++; - } while (i < len); // Noncompliant - - // Array transformation - i = 0; - do { - dest[i] = transform(src[i]); - i++; - } while (i < len); - } - - private boolean transform(boolean a) { - return !a; - } - +import java.util.Collection; +import java.util.Collections; + +class TestClass { + + public void copyArrayOK() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Copy with clone + dest = src.clone(); + + // Copy with System.arraycopy() + System.arraycopy(src, 0, dest, 0, src.length); + + // Copy with Arrays.copyOf() + dest = Arrays.copyOf(src, src.length); + } + + public void nonRegression() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple assignation + for (int i = 0; i < len; i++) { + dest[i] = true; + } + + // Edit same array + for (int i = 0; i < len-1; i++) { + dest[i] = dest[i+1]; + } + + // Objects assignations + String a = null; + String b = "Sample Value"; + for (int i = 0; i < len; i++) { + a = b; + } + } + + public void copyWithForLoop() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple copy + for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + dest[i] = src[i]; + } + + // Copy with nested conditions + for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 < len) { + dest[i] = src[i + 2]; + } + } + + // Copy with nested ELSE conditions + for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 >= len) { + i++; + } else { + dest[i] = src[i + 2]; + } + } + + // Copy with more nested conditions + for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 < len) { + if(dest != null) { + if(src != null) { + if(i > 1 && i + 2 < src.length) { + dest[i] = src[i + 2]; + } + } + } + } + } + + // Copy nested by try/catch + for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest[i] = src[i]; + } catch (RuntimeException e) { + e.printStackTrace(); + } + } + + // Copy nested by try/catch and if + for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + if(dest != null) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + } + + // Copy nested by try/catch in catch + for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest.toString(); + } catch (RuntimeException e) { + if(dest != null) { + dest[i] = src[i]; + } + } + } + + // Copy nested by try/catch in finally + for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest.toString(); + } catch (RuntimeException e) { + e.printStackTrace(); + } finally { + dest[i] = src[i]; + } + } + + // Array transformation + for (int i = 0; i < len; i++) { + dest[i] = transform(src[i]); + } + } + + public void copyWithForEachLoop() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple copy by foreach + int i = -1; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + dest[++i] = b; + } + + // Copy with nested conditions by foreach + i = -1; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(b) { + dest[++i] = b; + } + } + + // Copy with nested ELSE conditions by foreach + i = -1; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 >= len) { + i++; + } else { + dest[++i] = b; + } + } + + // Copy with more nested conditions + i = -1; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 < len) { + if(dest != null) { + if(src != null) { + if(i > 1 && i + 2 < src.length) { + dest[++i] = b; + } + } + } + } + } + + // Copy nested by try/catch + i = -1; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest[++i] = b; + } catch (RuntimeException e) { + e.printStackTrace(); + } + } + + // Copy nested by try/catch and if + i = -1; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + if(dest != null) { + dest[++i] = b; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + } + + // Copy nested by try/catch in catch + i = -1; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest.toString(); + } catch (RuntimeException e) { + if(dest != null) { + dest[++i] = b; + } + } + } + + // Copy nested by try/catch in finally + i = -1; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest.toString(); + } catch (RuntimeException e) { + e.printStackTrace(); + } finally { + dest[++i] = b; + } + } + + // Array transformation + i = -1; + for (boolean b : src) { + dest[++i] = transform(b); + } + + // Simple copy + int i = 0; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + dest[i] = src[i]; + i++; + } + + // Copy with nested conditions + i = 0; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(b) { + dest[i] = src[i]; + } + i++; + } + + // Copy with nested ELSE conditions + i = 0; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 >= len) { + i++; + } else { + dest[i] = src[i + 2]; + } + i++; + } + + // Copy with more nested conditions + i = 0; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 < len) { + if(dest != null) { + if(src != null) { + if(i > 1 && i + 2 < src.length) { + dest[i] = src[i + 2]; + } + } + } + } + i++; + } + + // Copy nested by try/catch + i = 0; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest[i] = src[i]; + } catch (RuntimeException e) { + e.printStackTrace(); + } + i++; + } + + // Copy nested by try/catch and if + i = 0; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + if(dest != null) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + i++; + } + + // Copy nested by try/catch in catch + i = 0; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest.toString(); + } catch (RuntimeException e) { + if(dest != null) { + dest[i] = src[i]; + } + } + i++; + } + + // Copy nested by try/catch in finally + i = 0; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest.toString(); + } catch (RuntimeException e) { + e.printStackTrace(); + } finally { + dest[i] = src[i]; + } + i++; + } + + // Array transformation + i = 0; + for (boolean b : src) { + dest[i] = transform(src[i]); + i++; + } + } + + public void copyWithWhileLoop() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple copy + int i = 0; + while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} + dest[i] = src[i]; + i++; + } + + // Copy with nested conditions + i = 0; + while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 < len) { + dest[i] = src[i + 2]; + } + i++; + } + + // Copy with nested ELSE conditions + i = 0; + while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 >= len) { + i++; + } else { + dest[i] = src[i + 2]; + } + i++; + } + + // Copy with more nested conditions + i = 0; + while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 < len) { + if(dest != null) { + if(src != null) { + if(i > 1 && i + 2 < src.length) { + dest[i] = src[i + 2]; + } + } + } + } + i++; + } + + // Copy nested by try/catch and if + i = 0; + while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + if(dest != null) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + i++; + } + + // Copy nested by try/catch in catch + i = 0; + while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest.toString(); + } catch (RuntimeException e) { + if(dest != null) { + dest[i] = src[i]; + } + } + i++; + } + + // Array transformation + i = 0; + while (i < len) { + dest[i] = transform(src[i]); + i++; + } + } + + public void copyWithDoWhileLoop() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple copy + int i = 0; + do { // Noncompliant {{Use System.arraycopy to copy arrays}} + dest[i] = src[i]; + i++; + } while (i < len); + + // Copy with nested conditions + i = 0; + do { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 < len) { + dest[i] = src[i + 2]; + } + i++; + } while (i < len); + + // Copy with nested ELSE conditions + i = 0; + do { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 >= len) { + i++; + } else { + dest[i] = src[i + 2]; + } + i++; + } while (i < len); + + // Copy with more nested conditions + i = 0; + do { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 < len) { + if(dest != null) { + if(src != null) { + if(i > 1 && i + 2 < src.length) { + dest[i] = src[i + 2]; + } + } + } + } + i++; + } while (i < len); + + // Copy nested by try/catch and if + i = 0; + do { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + if(dest != null) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + i++; + } while (i < len); + + // Copy nested by try/catch in catch + i = 0; + do { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest.toString(); + } catch (RuntimeException e) { + if(dest != null) { + dest[i] = src[i]; + } + } + i++; + } while (i < len); + + // Array transformation + i = 0; + do { + dest[i] = transform(src[i]); + i++; + } while (i < len); + } + + private boolean transform(boolean a) { + return !a; + } + } \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java index 1d141fc5..c5079ebe 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java @@ -6,7 +6,7 @@ public String concatenateStrings(String[] strings) { String result1 = ""; for (String string : strings) { - result1 += string; // Noncompliant + result1 += string; // Noncompliant {{Don't concatenate Strings in loop, use StringBuilder instead.}} } return result1; } @@ -15,7 +15,7 @@ public String concatenateStrings2() { String result2 = ""; for (int i = 0; i < 1000; ++i) { - result2 += "another"; // Noncompliant + result2 += "another"; // Noncompliant {{Don't concatenate Strings in loop, use StringBuilder instead.}} } return result2; } @@ -24,7 +24,7 @@ public String concatenateStrings3() { String result3 = ""; for (int i = 0; i < 1000; ++i) { - result3 = result3 + "another"; // Noncompliant + result3 = result3 + "another"; // Noncompliant {{Don't concatenate Strings in loop, use StringBuilder instead.}} } return result3; } diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheck.java index 0c4ff7b1..45c277e6 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheck.java @@ -5,22 +5,22 @@ class AvoidFullSQLRequestCheck { } public void literalSQLrequest() { - dummyCall(" sElEcT * fRoM myTable"); // Noncompliant + dummyCall(" sElEcT * fRoM myTable"); // Noncompliant {{Don't use the query SELECT * FROM}} dummyCall(" sElEcT user fRoM myTable"); dummyCall("SELECTABLE 2*2 FROMAGE"); //not sql - dummyCall("SELECT *FROM table"); // Noncompliant + dummyCall("SELECT *FROM table"); // Noncompliant {{Don't use the query SELECT * FROM}} } public void variableSQLrequest() { - String requestNonCompiliant = " SeLeCt * FrOm myTable"; // Noncompliant + String requestNonCompiliant = " SeLeCt * FrOm myTable"; // Noncompliant {{Don't use the query SELECT * FROM}} String requestCompiliant = " SeLeCt user FrOm myTable"; dummyCall(requestNonCompiliant); dummyCall(requestCompiliant); String noSqlCompiliant = "SELECTABLE 2*2 FROMAGE"; //not sql - String requestNonCompiliant_nSpace = "SELECT *FROM table"; // Noncompliant + String requestNonCompiliant_nSpace = "SELECT *FROM table"; // Noncompliant {{Don't use the query SELECT * FROM}} } private void dummyCall(String request) { diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopBad.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopBad.java index 2428fb36..f9905260 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopBad.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopBad.java @@ -13,7 +13,7 @@ public void badForLoop() { numberList.add(10); numberList.add(20); - for (int i = 0; i < numberList.size(); i++) { // Noncompliant + for (int i = 0; i < numberList.size(); i++) { // Noncompliant {{Avoid getting the size of the collection in the loop}} System.out.println("numberList.size()"); } } diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java index 51b33bd0..9b6fae75 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java @@ -14,7 +14,7 @@ public void badWhileLoop() { numberList.add(20); int i = 0; - while (i < numberList.size()) { // Noncompliant + while (i < numberList.size()) { // Noncompliant {{Avoid getting the size of the collection in the loop}} System.out.println("numberList.size()"); i++; } diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java index 8f9d6903..0474e452 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java @@ -5,7 +5,7 @@ public class AvoidRegexPatternNotStatic { public boolean foo() { - final Pattern pattern = Pattern.compile("foo"); // Noncompliant + final Pattern pattern = Pattern.compile("foo"); // Noncompliant {{Avoid using Pattern.compile() in a non-static context.}} return pattern.matcher("foo").find(); } } diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheck.java index 6365bc95..4981d0b4 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheck.java @@ -54,7 +54,7 @@ public void testWithForLoop() { // create the java statement String query = baseQuery.concat("" + i); Statement st = conn.createStatement(); - ResultSet rs = st.executeQuery(query); // Noncompliant + ResultSet rs = st.executeQuery(query); // Noncompliant {{Avoid SQL request in loop}} // iterate through the java resultset while (rs.next()) { @@ -85,7 +85,7 @@ public void testWithForEachLoop() { System.out.println(i); // create the java statement Statement st = conn.createStatement(); - ResultSet rs = st.executeQuery(query); // Noncompliant + ResultSet rs = st.executeQuery(query); // Noncompliant {{Avoid SQL request in loop}} // iterate through the java resultset while (rs.next()) { @@ -116,7 +116,7 @@ public void testWithWhileLoop() { // create the java statement Statement st = conn.createStatement(); - ResultSet rs = st.executeQuery(query); // Noncompliant + ResultSet rs = st.executeQuery(query); // Noncompliant {{Avoid SQL request in loop}} // iterate through the java resultset while (rs.next()) { diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java index 21e61211..e33e7e09 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java @@ -35,19 +35,19 @@ void batchInsertInForLoop(int[] data) throws SQLException { for (int i = 0; i < data.length; i++) { stmt.setInt(1, data[i]); - stmt.setBoolean(2, true); // Noncompliant - stmt.setByte(3, (byte) 3); // Noncompliant - stmt.setBytes(4, "v".getBytes()); // Noncompliant - stmt.setShort(5, (short) 5); // Noncompliant - stmt.setInt(6, 6); // Noncompliant - stmt.setLong(7, (long) 7); // Noncompliant - stmt.setLong(7, 7l); // Noncompliant - stmt.setFloat(8, (float) 8.); // Noncompliant - stmt.setFloat(8, 8.f); // Noncompliant - stmt.setDouble(9, 9.); // Noncompliant - stmt.setDouble(9, 9.); // Noncompliant - stmt.setString(10, "10"); // Noncompliant - stmt.setBigDecimal(11, BigDecimal.valueOf(.77)); // Noncompliant + stmt.setBoolean(2, true); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setByte(3, (byte) 3); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setBytes(4, "v".getBytes()); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setShort(5, (short) 5); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setInt(6, 6); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setLong(7, (long) 7); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setLong(7, 7l); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setFloat(8, (float) 8.); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setFloat(8, 8.f); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setDouble(9, 9.); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setDouble(9, 9.); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setString(10, "10"); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setBigDecimal(11, BigDecimal.valueOf(.77)); // Noncompliant {{Avoid setting constants in batch update}} stmt.addBatch(); } int[] nr = stmt.executeBatch(); @@ -62,16 +62,16 @@ int[] batchInsertInForeachLoop(DummyClass[] data) throws SQLException { PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?,?,?,?,?,?,?,?,?,?)"); for (DummyClass o : data) { stmt.setInt(1, o.getField1()); - stmt.setBoolean(2, Boolean.valueOf("false")); // Noncompliant + stmt.setBoolean(2, Boolean.valueOf("false")); // Noncompliant {{Avoid setting constants in batch update}} stmt.setByte(3, o.getField3()); - stmt.setBytes(4, "v".getBytes()); // Noncompliant - stmt.setShort(5, (short) 5); // Noncompliant - stmt.setInt(6, 6); // Noncompliant - stmt.setLong(7, 7); // Noncompliant - stmt.setFloat(8, (float) 8.); // Noncompliant + stmt.setBytes(4, "v".getBytes()); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setShort(5, (short) 5); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setInt(6, 6); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setLong(7, 7); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setFloat(8, (float) 8.); // Noncompliant {{Avoid setting constants in batch update}} stmt.setDouble(9, o.getField4()); stmt.setString(10, o.getField2()); - stmt.setBigDecimal(11, BigDecimal.valueOf(11)); // Noncompliant + stmt.setBigDecimal(11, BigDecimal.valueOf(11)); // Noncompliant {{Avoid setting constants in batch update}} stmt.addBatch(); } return stmt.executeBatch(); @@ -87,16 +87,16 @@ int[] batchInsertInWhileLoop2(DummyClass[] data) throws SQLException { while (i < data.length) { DummyClass o = data[i]; stmt.setInt(1, o.getField1()); - stmt.setBoolean(2, Boolean.TRUE); // Noncompliant + stmt.setBoolean(2, Boolean.TRUE); // Noncompliant {{Avoid setting constants in batch update}} stmt.setByte(3, o.getField3()); - stmt.setByte(4, Byte.MAX_VALUE); // Noncompliant - stmt.setShort(5, Short.MIN_VALUE); // Noncompliant - stmt.setInt(6, Integer.MAX_VALUE); // Noncompliant - stmt.setLong(7, Long.MIN_VALUE); // Noncompliant - stmt.setFloat(8, Float.MAX_VALUE); // Noncompliant - stmt.setDouble(9, Double.MIN_VALUE); // Noncompliant + stmt.setByte(4, Byte.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setShort(5, Short.MIN_VALUE); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setInt(6, Integer.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setLong(7, Long.MIN_VALUE); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setFloat(8, Float.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setDouble(9, Double.MIN_VALUE); // Noncompliant {{Avoid setting constants in batch update}} stmt.setString(10, o.getField2()); - stmt.setBigDecimal(11, BigDecimal.TEN); // Noncompliant + stmt.setBigDecimal(11, BigDecimal.TEN); // Noncompliant {{Avoid setting constants in batch update}} stmt.addBatch(); i++; } @@ -114,16 +114,16 @@ int[] batchInsertInWhileLoop(DummyClass[] data) throws SQLException { do { DummyClass o = data[i]; stmt.setInt(1, o.getField1()); - stmt.setBoolean(2, Boolean.valueOf(true)); // Noncompliant + stmt.setBoolean(2, Boolean.valueOf(true)); // Noncompliant {{Avoid setting constants in batch update}} stmt.setByte(3, o.getField3()); - stmt.setByte(4, Byte.valueOf((byte) 3)); // Noncompliant - stmt.setShort(5, Short.valueOf((short) 55)); // Noncompliant - stmt.setInt(6, Integer.valueOf("222")); // Noncompliant - stmt.setLong(7, Long.valueOf(0)); // Noncompliant - stmt.setFloat(8, Float.valueOf(.33f)); // Noncompliant - stmt.setDouble(9, Double.valueOf(22)); // Noncompliant + stmt.setByte(4, Byte.valueOf((byte) 3)); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setShort(5, Short.valueOf((short) 55)); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setInt(6, Integer.valueOf("222")); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setLong(7, Long.valueOf(0)); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setFloat(8, Float.valueOf(.33f)); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setDouble(9, Double.valueOf(22)); // Noncompliant {{Avoid setting constants in batch update}} stmt.setString(10, o.getField2()); - stmt.setBigDecimal(11, BigDecimal.valueOf(11)); // Noncompliant + stmt.setBigDecimal(11, BigDecimal.valueOf(11)); // Noncompliant {{Avoid setting constants in batch update}} stmt.addBatch(); i++; } while (i < data.length); diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java index 428608f9..87204a67 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java @@ -15,6 +15,6 @@ class AvoidStatementForDMLQueries { public void insert() throws SQLException { Connection connection = DriverManager.getConnection("URL"); Statement statement = connection.createStatement(); - statement.executeUpdate("INSERT INTO persons(id, name) VALUES(2, 'Toto')"); // Noncompliant + statement.executeUpdate("INSERT INTO persons(id, name) VALUES(2, 'Toto')"); // Noncompliant {{You must not use Statement for a DML query}} } } \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java index 50eb5071..ac1b9f0d 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java @@ -7,11 +7,11 @@ */ public class AvoidUsageOfStaticCollections { - public static final List LIST = new ArrayList(); // Noncompliant + public static final List LIST = new ArrayList(); // Noncompliant {{Avoid usage of static collections.}} - public static final Set SET = new HashSet(); // Noncompliant + public static final Set SET = new HashSet(); // Noncompliant {{Avoid usage of static collections.}} - public static final Map MAP = new HashMap(); // Noncompliant + public static final Map MAP = new HashMap(); // Noncompliant {{Avoid usage of static collections.}} public AvoidUsageOfStaticCollections() { } diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java index 689986ee..3dea9e35 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java @@ -1,8 +1,8 @@ package fr.greencodeinitiative.java.checks; public class AvoidUsingGlobalVariablesCheck { - public static double price = 15.24; // Noncompliant - public static long pages = 1053; // Noncompliant + public static double price = 15.24; // Noncompliant {{Avoid using global variables}} + public static long pages = 1053; // Noncompliant {{Avoid using global variables}} public static void main(String[] args) { double newPrice = AvoidUsingGlobalVariablesCheck.price; @@ -10,7 +10,7 @@ public static void main(String[] args) { System.out.println(newPrice); System.out.println(newPages); } - static{ // Noncompliant + static{ // Noncompliant {{Avoid using global variables}} int a = 4; } diff --git a/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java index 302e393e..7f5f6cc1 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java @@ -6,7 +6,7 @@ class IncrementCheck { int foo1() { int counter = 0; - return counter++; // Noncompliant + return counter++; // Noncompliant {{Use ++i instead of i++}} } int foo11() { @@ -16,7 +16,7 @@ int foo11() { void foo2(int value) { int counter = 0; - counter++; // Noncompliant + counter++; // Noncompliant {{Use ++i instead of i++}} } void foo22(int value) { diff --git a/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java b/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java index 925a8d1f..a02cc362 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java @@ -13,7 +13,7 @@ public void testBufferCompliant2() { } public void testBufferNonCompliant() { - StringBuffer stringBuffer = new StringBuffer(); // Noncompliant + StringBuffer stringBuffer = new StringBuffer(); // Noncompliant {{Initialize StringBuilder or StringBuffer with appropriate size}} } public void testBuilderCompliant() { @@ -21,6 +21,6 @@ public void testBuilderCompliant() { } public void testBuilderNonCompliant() { - StringBuilder stringBuilder = new StringBuilder(); // Noncompliant + StringBuilder stringBuilder = new StringBuilder(); // Noncompliant {{Initialize StringBuilder or StringBuffer with appropriate size}} } } \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java index f4fa54ac..28da0a82 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java @@ -28,28 +28,28 @@ public void test2() { } public void test3() { - for (int i = getMyValue(); i < 20; i++) { // Noncompliant + for (int i = getMyValue(); i < 20; i++) { // Noncompliant {{Do not call a function when declaring a for-type loop}} System.out.println(i); boolean b = getMyValue() > 6; } } public void test4() { - for (int i = 0; i < getMyValue(); i++) { // Noncompliant + for (int i = 0; i < getMyValue(); i++) { // Noncompliant {{Do not call a function when declaring a for-type loop}} System.out.println(i); boolean b = getMyValue() > 6; } } public void test5() { - for (int i = 0; i < getMyValue(); incrementeMyValue(i)) { // Noncompliant + for (int i = 0; i < getMyValue(); incrementeMyValue(i)) { // Noncompliant {{Do not call a function when declaring a for-type loop}} System.out.println(i); boolean b = getMyValue() > 6; } } public void test6() { - for (int i = getMyValue(); i < getMyValue(); i++) { // Noncompliant + for (int i = getMyValue(); i < getMyValue(); i++) { // Noncompliant {{Do not call a function when declaring a for-type loop}} System.out.println(i); boolean b = getMyValue() > 6; } diff --git a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck.java index be2bd55b..69911227 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck.java @@ -20,7 +20,7 @@ public void readPreferences(String filename) { //... InputStream in = null; try { - in = new FileInputStream(filename); // Noncompliant + in = new FileInputStream(filename); // Noncompliant {{Optimize Read File Exceptions}} } catch (FileNotFoundException e) { logger.info(e.getMessage()); } diff --git a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck2.java b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck2.java index 50955d6c..9b0833dd 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck2.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck2.java @@ -17,7 +17,7 @@ class OptimizeReadFileExceptionCheck2 { public void readPreferences(String filename) throws IOException { //... - try (InputStream in = new FileInputStream(filename)) { // Noncompliant + try (InputStream in = new FileInputStream(filename)) { // Noncompliant {{Optimize Read File Exceptions}} logger.info("my log"); } catch (FileNotFoundException e) { logger.info(e.getMessage()); diff --git a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck3.java b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck3.java index 83214c22..18c23448 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck3.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck3.java @@ -16,7 +16,7 @@ class OptimizeReadFileExceptionCheck3 { public void readPreferences(String filename) { //... - try (InputStream in = new FileInputStream(filename)) { // Noncompliant + try (InputStream in = new FileInputStream(filename)) { // Noncompliant {{Optimize Read File Exceptions}} logger.info("my log"); } catch (IOException e) { logger.info(e.getMessage()); diff --git a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck4.java b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck4.java index a4fd9508..38435808 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck4.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck4.java @@ -15,7 +15,7 @@ class OptimizeReadFileExceptionCheck4 { public void readPreferences(String filename) { //... - try (InputStream in = new FileInputStream(filename)) { // Noncompliant + try (InputStream in = new FileInputStream(filename)) { // Noncompliant {{Optimize Read File Exceptions}} logger.info("my log"); } catch (Exception e) { logger.info(e.getMessage()); diff --git a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck5.java b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck5.java index bf279462..7a0e84ab 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck5.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck5.java @@ -15,7 +15,7 @@ class OptimizeReadFileExceptionCheck5 { public void readPreferences(String filename) { //... - try (InputStream in = new FileInputStream(filename)) { // Noncompliant + try (InputStream in = new FileInputStream(filename)) { // Noncompliant {{Optimize Read File Exceptions}} logger.info("my log"); } catch (Throwable e) { logger.info(e.getMessage()); diff --git a/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheck.java index 3ed0cf70..4a591504 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheck.java @@ -14,7 +14,7 @@ public int testSwitchCase() throws Exception { int[] intArray = {10, 20, 30, 40, 50}; Exception variableException = new Exception("message"); - int variableNotUse = 5; // Noncompliant + int variableNotUse = 5; // Noncompliant {{The variable is not assigned}} variableNotUse = 10; @@ -59,7 +59,7 @@ private int getIntValue() { } public int testNonCompliantReturn() { - int i = getIntValue(); // Noncompliant + int i = getIntValue(); // Noncompliant {{Immediately return this expression instead of assigning it to the temporary variable}} return i; } @@ -68,7 +68,7 @@ public int testCompliantReturn() { } public void testNonCompliantThrow() throws Exception { - Exception exception = new Exception("dummy"); // Noncompliant + Exception exception = new Exception("dummy"); // Noncompliant {{Immediately throw this expression instead of assigning it to the temporary variable}} throw exception; } diff --git a/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoopCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoopCheck.java index 669f058f..dfdde5d1 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoopCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoopCheck.java @@ -12,7 +12,7 @@ class UseCorrectForLoopCheck { public void testForEachLoop() { int dummy = 0; - for (Integer i : intArray) { // Noncompliant + for (Integer i : intArray) { // Noncompliant {{Avoid the use of Foreach with Arrays}} dummy += i; } From 01504792a74f9b518f26b89433ba7951a63d57f6 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 17 Mar 2023 17:54:23 +0100 Subject: [PATCH 013/233] update source test files --- .../java/checks/ArrayCopyCheck.java | 144 +++++++++--------- .../checks/AvoidMultipleIfElseStatement.java | 12 +- .../AvoidSetConstantInBatchUpdateCheck.java | 31 ++-- .../java/checks/UseCorrectForLoopCheck.java | 4 +- 4 files changed, 94 insertions(+), 97 deletions(-) diff --git a/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java index d1889051..8d3bcbbd 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java @@ -48,28 +48,28 @@ public void copyWithForLoop() { boolean[] dest = new boolean[len]; // Simple copy - for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (int i = 0; i < len; i++) { dest[i] = src[i]; - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy with nested conditions - for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (int i = 0; i < len; i++) { if(i + 2 < len) { dest[i] = src[i + 2]; } - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy with nested ELSE conditions - for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (int i = 0; i < len; i++) { if(i + 2 >= len) { i++; } else { dest[i] = src[i + 2]; } - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy with more nested conditions - for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (int i = 0; i < len; i++) { if(i + 2 < len) { if(dest != null) { if(src != null) { @@ -79,19 +79,19 @@ public void copyWithForLoop() { } } } - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy nested by try/catch - for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (int i = 0; i < len; i++) { try { dest[i] = src[i]; } catch (RuntimeException e) { e.printStackTrace(); } - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy nested by try/catch and if - for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (int i = 0; i < len; i++) { try { if(dest != null) { dest[i] = src[i]; @@ -99,10 +99,10 @@ public void copyWithForLoop() { } catch (RuntimeException e) { e.printStackTrace(); } - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy nested by try/catch in catch - for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (int i = 0; i < len; i++) { try { dest.toString(); } catch (RuntimeException e) { @@ -110,10 +110,10 @@ public void copyWithForLoop() { dest[i] = src[i]; } } - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy nested by try/catch in finally - for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (int i = 0; i < len; i++) { try { dest.toString(); } catch (RuntimeException e) { @@ -121,7 +121,7 @@ public void copyWithForLoop() { } finally { dest[i] = src[i]; } - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Array transformation for (int i = 0; i < len; i++) { @@ -136,31 +136,31 @@ public void copyWithForEachLoop() { // Simple copy by foreach int i = -1; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (boolean b : src) { dest[++i] = b; - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy with nested conditions by foreach i = -1; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (boolean b : src) { if(b) { dest[++i] = b; } - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy with nested ELSE conditions by foreach i = -1; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (boolean b : src) { if(i + 2 >= len) { i++; } else { dest[++i] = b; } - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy with more nested conditions i = -1; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (boolean b : src) { if(i + 2 < len) { if(dest != null) { if(src != null) { @@ -170,21 +170,21 @@ public void copyWithForEachLoop() { } } } - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy nested by try/catch i = -1; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (boolean b : src) { try { dest[++i] = b; } catch (RuntimeException e) { e.printStackTrace(); } - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy nested by try/catch and if i = -1; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (boolean b : src) { try { if(dest != null) { dest[++i] = b; @@ -192,11 +192,11 @@ public void copyWithForEachLoop() { } catch (RuntimeException e) { e.printStackTrace(); } - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy nested by try/catch in catch i = -1; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (boolean b : src) { try { dest.toString(); } catch (RuntimeException e) { @@ -204,11 +204,11 @@ public void copyWithForEachLoop() { dest[++i] = b; } } - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy nested by try/catch in finally i = -1; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (boolean b : src) { try { dest.toString(); } catch (RuntimeException e) { @@ -216,7 +216,7 @@ public void copyWithForEachLoop() { } finally { dest[++i] = b; } - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Array transformation i = -1; @@ -226,34 +226,34 @@ public void copyWithForEachLoop() { // Simple copy int i = 0; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (boolean b : src) { dest[i] = src[i]; i++; - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy with nested conditions i = 0; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (boolean b : src) { if(b) { dest[i] = src[i]; } i++; - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy with nested ELSE conditions i = 0; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (boolean b : src) { if(i + 2 >= len) { i++; } else { dest[i] = src[i + 2]; } i++; - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy with more nested conditions i = 0; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (boolean b : src) { if(i + 2 < len) { if(dest != null) { if(src != null) { @@ -264,22 +264,22 @@ public void copyWithForEachLoop() { } } i++; - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy nested by try/catch i = 0; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (boolean b : src) { try { dest[i] = src[i]; } catch (RuntimeException e) { e.printStackTrace(); } i++; - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy nested by try/catch and if i = 0; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (boolean b : src) { try { if(dest != null) { dest[i] = src[i]; @@ -288,11 +288,11 @@ public void copyWithForEachLoop() { e.printStackTrace(); } i++; - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy nested by try/catch in catch i = 0; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (boolean b : src) { try { dest.toString(); } catch (RuntimeException e) { @@ -301,11 +301,11 @@ public void copyWithForEachLoop() { } } i++; - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy nested by try/catch in finally i = 0; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + for (boolean b : src) { try { dest.toString(); } catch (RuntimeException e) { @@ -314,7 +314,7 @@ public void copyWithForEachLoop() { dest[i] = src[i]; } i++; - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Array transformation i = 0; @@ -331,34 +331,34 @@ public void copyWithWhileLoop() { // Simple copy int i = 0; - while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} + while (i < len) { dest[i] = src[i]; i++; - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy with nested conditions i = 0; - while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} + while (i < len) { if(i + 2 < len) { dest[i] = src[i + 2]; } i++; - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy with nested ELSE conditions i = 0; - while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} + while (i < len) { if(i + 2 >= len) { i++; } else { dest[i] = src[i + 2]; } i++; - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy with more nested conditions i = 0; - while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} + while (i < len) { if(i + 2 < len) { if(dest != null) { if(src != null) { @@ -369,11 +369,11 @@ public void copyWithWhileLoop() { } } i++; - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy nested by try/catch and if i = 0; - while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} + while (i < len) { try { if(dest != null) { dest[i] = src[i]; @@ -382,11 +382,11 @@ public void copyWithWhileLoop() { e.printStackTrace(); } i++; - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy nested by try/catch in catch i = 0; - while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} + while (i < len) { try { dest.toString(); } catch (RuntimeException e) { @@ -395,7 +395,7 @@ public void copyWithWhileLoop() { } } i++; - } + } // Noncompliant {{Use System.arraycopy to copy arrays}} // Array transformation i = 0; @@ -412,34 +412,34 @@ public void copyWithDoWhileLoop() { // Simple copy int i = 0; - do { // Noncompliant {{Use System.arraycopy to copy arrays}} + do { dest[i] = src[i]; i++; - } while (i < len); + } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy with nested conditions i = 0; - do { // Noncompliant {{Use System.arraycopy to copy arrays}} + do { if(i + 2 < len) { dest[i] = src[i + 2]; } i++; - } while (i < len); + } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy with nested ELSE conditions i = 0; - do { // Noncompliant {{Use System.arraycopy to copy arrays}} + do { if(i + 2 >= len) { i++; } else { dest[i] = src[i + 2]; } i++; - } while (i < len); + } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy with more nested conditions i = 0; - do { // Noncompliant {{Use System.arraycopy to copy arrays}} + do { if(i + 2 < len) { if(dest != null) { if(src != null) { @@ -450,11 +450,11 @@ public void copyWithDoWhileLoop() { } } i++; - } while (i < len); + } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy nested by try/catch and if i = 0; - do { // Noncompliant {{Use System.arraycopy to copy arrays}} + do { try { if(dest != null) { dest[i] = src[i]; @@ -463,11 +463,11 @@ public void copyWithDoWhileLoop() { e.printStackTrace(); } i++; - } while (i < len); + } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} // Copy nested by try/catch in catch i = 0; - do { // Noncompliant {{Use System.arraycopy to copy arrays}} + do { try { dest.toString(); } catch (RuntimeException e) { @@ -476,7 +476,7 @@ public void copyWithDoWhileLoop() { } } i++; - } while (i < len); + } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} // Array transformation i = 0; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java index d84630d9..6dbc73db 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java @@ -8,7 +8,7 @@ public void methodWithMultipleIfElseIf() { int nb1 = 0; int nb2 = 10; - if (nb1 == 1) { // Noncompliant + if (nb1 == 1) { nb1 = 1; } else if (nb1 == nb2) { // @@ -16,7 +16,7 @@ public void methodWithMultipleIfElseIf() { // } else { // - } + } // Noncompliant {{Using a switch statement instead of multiple if-else if possible}} nb1 = nb2; } @@ -24,15 +24,15 @@ public void methodWithMultipleIfElse() { int nb1 = 0; int nb2 = 10; - if (nb1 == 1) { // Noncompliant + if (nb1 == 1) { nb1 = 1; } else { // - } - if (nb1 == 1) { // Noncompliant + } // Noncompliant {{Using a switch statement instead of multiple if-else if possible}} + if (nb1 == 1) { nb1 = 1; } else { // - } + } // Noncompliant {{Using a switch statement instead of multiple if-else if possible}} } } \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java index e33e7e09..122a48b4 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java @@ -1,26 +1,21 @@ package fr.greencodeinitiative.java.checks; import java.math.BigDecimal; -import java.sql.Connection; -import java.sql.DriverManager; import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.util.regex.Pattern; import java.util.stream.IntStream; +import java.util.stream.Stream; class AvoidSetConstantInBatchUpdateCheck { - Logger logger = Logger.getLogger(""); - - void literalSQLrequest() throws SQLException { //dirty call + void literalSQLrequest() { //dirty call int x = 0; Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle"); PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?)"); stmt.setInt(1, 101); stmt.setString(2, "Ratan"); - stmt.setBigDecimal(3, BigDecimal.ONE); + stmt.setBigDecimal(3, Bigdecimal.ONE); stmt.setBigDecimal(4, BigDecimal.valueOf(x)); stmt.setBoolean(5, Boolean.valueOf("true")); int i = stmt.executeUpdate(); @@ -28,7 +23,7 @@ void literalSQLrequest() throws SQLException { //dirty call con.close(); } - void batchInsertInForLoop(int[] data) throws SQLException { + void batchInsertInForLoop(int[] data) { Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle"); PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?,?,?,?,?,?,?,?)"); @@ -37,7 +32,7 @@ void batchInsertInForLoop(int[] data) throws SQLException { stmt.setBoolean(2, true); // Noncompliant {{Avoid setting constants in batch update}} stmt.setByte(3, (byte) 3); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setBytes(4, "v".getBytes()); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setByte(4, 'v'); // Noncompliant {{Avoid setting constants in batch update}} stmt.setShort(5, (short) 5); // Noncompliant {{Avoid setting constants in batch update}} stmt.setInt(6, 6); // Noncompliant {{Avoid setting constants in batch update}} stmt.setLong(7, (long) 7); // Noncompliant {{Avoid setting constants in batch update}} @@ -51,12 +46,12 @@ void batchInsertInForLoop(int[] data) throws SQLException { stmt.addBatch(); } int[] nr = stmt.executeBatch(); - logger.log(Level.INFO, "{} rows updated", IntStream.of(nr).sum()); + logger.log("{} rows updated", IntStream.of(nr).sum()); con.close(); } - int[] batchInsertInForeachLoop(DummyClass[] data) throws SQLException { + int[] batchInsertInForeachLoop(DummyClass[] data) { try (Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle")) { PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?,?,?,?,?,?,?,?,?,?)"); @@ -64,7 +59,7 @@ int[] batchInsertInForeachLoop(DummyClass[] data) throws SQLException { stmt.setInt(1, o.getField1()); stmt.setBoolean(2, Boolean.valueOf("false")); // Noncompliant {{Avoid setting constants in batch update}} stmt.setByte(3, o.getField3()); - stmt.setBytes(4, "v".getBytes()); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setByte(4, 'v'); // Noncompliant {{Avoid setting constants in batch update}} stmt.setShort(5, (short) 5); // Noncompliant {{Avoid setting constants in batch update}} stmt.setInt(6, 6); // Noncompliant {{Avoid setting constants in batch update}} stmt.setLong(7, 7); // Noncompliant {{Avoid setting constants in batch update}} @@ -79,7 +74,7 @@ int[] batchInsertInForeachLoop(DummyClass[] data) throws SQLException { } - int[] batchInsertInWhileLoop2(DummyClass[] data) throws SQLException { + int[] batchInsertInWhileLoop(DummyClass[] data) { try (Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle")) { PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?,?,?,?,?,?,?,?,?,?)"); @@ -90,6 +85,7 @@ int[] batchInsertInWhileLoop2(DummyClass[] data) throws SQLException { stmt.setBoolean(2, Boolean.TRUE); // Noncompliant {{Avoid setting constants in batch update}} stmt.setByte(3, o.getField3()); stmt.setByte(4, Byte.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setByte(4, Character.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}} stmt.setShort(5, Short.MIN_VALUE); // Noncompliant {{Avoid setting constants in batch update}} stmt.setInt(6, Integer.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}} stmt.setLong(7, Long.MIN_VALUE); // Noncompliant {{Avoid setting constants in batch update}} @@ -104,7 +100,7 @@ int[] batchInsertInWhileLoop2(DummyClass[] data) throws SQLException { } } - int[] batchInsertInWhileLoop(DummyClass[] data) throws SQLException { + int[] batchInsertInWhileLoop(DummyClass[] data) { if (data.length == 0) { return new int[]{}; } @@ -117,10 +113,11 @@ int[] batchInsertInWhileLoop(DummyClass[] data) throws SQLException { stmt.setBoolean(2, Boolean.valueOf(true)); // Noncompliant {{Avoid setting constants in batch update}} stmt.setByte(3, o.getField3()); stmt.setByte(4, Byte.valueOf((byte) 3)); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setByte(4, Character.valueOf('1')); // Noncompliant {{Avoid setting constants in batch update}} stmt.setShort(5, Short.valueOf((short) 55)); // Noncompliant {{Avoid setting constants in batch update}} stmt.setInt(6, Integer.valueOf("222")); // Noncompliant {{Avoid setting constants in batch update}} stmt.setLong(7, Long.valueOf(0)); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setFloat(8, Float.valueOf(.33f)); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setFloat(8, Float.valueOf(.33)); // Noncompliant {{Avoid setting constants in batch update}} stmt.setDouble(9, Double.valueOf(22)); // Noncompliant {{Avoid setting constants in batch update}} stmt.setString(10, o.getField2()); stmt.setBigDecimal(11, BigDecimal.valueOf(11)); // Noncompliant {{Avoid setting constants in batch update}} diff --git a/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoopCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoopCheck.java index dfdde5d1..fe5ee97c 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoopCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoopCheck.java @@ -12,9 +12,9 @@ class UseCorrectForLoopCheck { public void testForEachLoop() { int dummy = 0; - for (Integer i : intArray) { // Noncompliant {{Avoid the use of Foreach with Arrays}} + for (Integer i : intArray) { dummy += i; - } + } // Noncompliant {{Avoid the use of Foreach with Arrays}} for (Integer i : intList) { dummy += i; From f66a7ecb41b0a3a71fbcab8aa8f9442cc84adcda Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 23 Mar 2023 23:57:36 +0100 Subject: [PATCH 014/233] delete useless tool script --- tool_build.sh | 3 --- 1 file changed, 3 deletions(-) delete mode 100755 tool_build.sh diff --git a/tool_build.sh b/tool_build.sh deleted file mode 100755 index 84820a4a..00000000 --- a/tool_build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env sh - -mvn clean package From 7a2794b7a4e8bdf85e545d6b8b8db084675f3aaa Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Wed, 29 Mar 2023 23:17:33 +0200 Subject: [PATCH 015/233] improve shell and doc --- .gitignore | 6 +----- README.md | 12 ++++++------ tool_send_to_sonar.sh | 3 ++- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 8c56452c..71a8d562 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,3 @@ !.gitignore -!.github/**/*.* .* -target -*.iml -lib/*.jar -bin \ No newline at end of file +target \ No newline at end of file diff --git a/README.md b/README.md index 3b45ed00..95fa9de9 100644 --- a/README.md +++ b/README.md @@ -14,16 +14,16 @@ Step 1 : prepare local environment To launch local environment : please follow https://github.com/green-code-initiative/ecoCode/blob/main/INSTALL.md (especially SonarQube configuration part) -Step 1 : compile and build +Step 2 : send Sonar metrics to local SonarQube --- -`./tool_build.sh` +```sh +./tool_send_to_sonar.sh MY_SONAR_TOKEN -Step 2 : send Sonar metrics to local SonarQube ---- +or -- first : change the token inside script (to give your personal SonarQube token, previously generated, please see install documention) -- secondly : launch `./tool_send_to_sonar.sh` +mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.login=MY_SONAR_TOKEN +``` Step 3 : check errors --- diff --git a/tool_send_to_sonar.sh b/tool_send_to_sonar.sh index 728a0f5a..61de09a9 100755 --- a/tool_send_to_sonar.sh +++ b/tool_send_to_sonar.sh @@ -1,4 +1,5 @@ #!/usr/bin/env sh # "sonar.login" variable : private TOKEN generated in your local SonarQube during installation -mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.login=sqa_919e0287178896de96aa019e300e85a93c9acc2d +# (input paramater of this script) +mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.login=$1 From ef0d508e2da8ae2ef88344155c66fde88406d10f Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Wed, 29 Mar 2023 23:43:23 +0200 Subject: [PATCH 016/233] improve shell and doc and gitignor --- .gitignore | 3 ++- README.md | 11 ++++++++--- tool_build.sh | 3 +++ 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100755 tool_build.sh diff --git a/.gitignore b/.gitignore index 71a8d562..b4130041 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ !.gitignore .* -target \ No newline at end of file +target +*.iml diff --git a/README.md b/README.md index 95fa9de9..cb2f8c68 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,14 @@ Step 1 : prepare local environment --- To launch local environment : please follow https://github.com/green-code-initiative/ecoCode/blob/main/INSTALL.md -(especially SonarQube configuration part) +(especially SonarQube configuration part and get generated private token) -Step 2 : send Sonar metrics to local SonarQube +Step 2 : compile and build +--- + +`./tool_build.sh` + +Step 3 : send Sonar metrics to local SonarQube --- ```sh @@ -25,7 +30,7 @@ or mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.login=MY_SONAR_TOKEN ``` -Step 3 : check errors +Step 4 : check errors --- on local SonarQube, check if each Java class contains (or not) the rule error defined for this class diff --git a/tool_build.sh b/tool_build.sh new file mode 100755 index 00000000..bfac031a --- /dev/null +++ b/tool_build.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +mvn clean package -DskipTests From 152cd8900b2aebcbb596bce5407d54b72050b7d4 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Wed, 29 Mar 2023 23:44:01 +0200 Subject: [PATCH 017/233] correction of compile pbs to send to sonar next --- .../java/checks/ArrayCopyCheck.java | 974 +++++++++--------- .../AvoidSetConstantInBatchUpdateCheck.java | 35 +- 2 files changed, 504 insertions(+), 505 deletions(-) diff --git a/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java index 8d3bcbbd..b748dd29 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java @@ -1,493 +1,491 @@ import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; class TestClass { - public void copyArrayOK() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Copy with clone - dest = src.clone(); - - // Copy with System.arraycopy() - System.arraycopy(src, 0, dest, 0, src.length); - - // Copy with Arrays.copyOf() - dest = Arrays.copyOf(src, src.length); - } - - public void nonRegression() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple assignation - for (int i = 0; i < len; i++) { - dest[i] = true; - } - - // Edit same array - for (int i = 0; i < len-1; i++) { - dest[i] = dest[i+1]; - } - - // Objects assignations - String a = null; - String b = "Sample Value"; - for (int i = 0; i < len; i++) { - a = b; - } - } - - public void copyWithForLoop() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple copy - for (int i = 0; i < len; i++) { - dest[i] = src[i]; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with nested conditions - for (int i = 0; i < len; i++) { - if(i + 2 < len) { - dest[i] = src[i + 2]; - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with nested ELSE conditions - for (int i = 0; i < len; i++) { - if(i + 2 >= len) { - i++; - } else { - dest[i] = src[i + 2]; - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with more nested conditions - for (int i = 0; i < len; i++) { - if(i + 2 < len) { - if(dest != null) { - if(src != null) { - if(i > 1 && i + 2 < src.length) { - dest[i] = src[i + 2]; - } - } - } - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch - for (int i = 0; i < len; i++) { - try { - dest[i] = src[i]; - } catch (RuntimeException e) { - e.printStackTrace(); - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch and if - for (int i = 0; i < len; i++) { - try { - if(dest != null) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch in catch - for (int i = 0; i < len; i++) { - try { - dest.toString(); - } catch (RuntimeException e) { - if(dest != null) { - dest[i] = src[i]; - } - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch in finally - for (int i = 0; i < len; i++) { - try { - dest.toString(); - } catch (RuntimeException e) { - e.printStackTrace(); - } finally { - dest[i] = src[i]; - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Array transformation - for (int i = 0; i < len; i++) { - dest[i] = transform(src[i]); - } - } - - public void copyWithForEachLoop() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple copy by foreach - int i = -1; - for (boolean b : src) { - dest[++i] = b; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with nested conditions by foreach - i = -1; - for (boolean b : src) { - if(b) { - dest[++i] = b; - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with nested ELSE conditions by foreach - i = -1; - for (boolean b : src) { - if(i + 2 >= len) { - i++; - } else { - dest[++i] = b; - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with more nested conditions - i = -1; - for (boolean b : src) { - if(i + 2 < len) { - if(dest != null) { - if(src != null) { - if(i > 1 && i + 2 < src.length) { - dest[++i] = b; - } - } - } - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch - i = -1; - for (boolean b : src) { - try { - dest[++i] = b; - } catch (RuntimeException e) { - e.printStackTrace(); - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch and if - i = -1; - for (boolean b : src) { - try { - if(dest != null) { - dest[++i] = b; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch in catch - i = -1; - for (boolean b : src) { - try { - dest.toString(); - } catch (RuntimeException e) { - if(dest != null) { - dest[++i] = b; - } - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch in finally - i = -1; - for (boolean b : src) { - try { - dest.toString(); - } catch (RuntimeException e) { - e.printStackTrace(); - } finally { - dest[++i] = b; - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Array transformation - i = -1; - for (boolean b : src) { - dest[++i] = transform(b); - } - - // Simple copy - int i = 0; - for (boolean b : src) { - dest[i] = src[i]; - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with nested conditions - i = 0; - for (boolean b : src) { - if(b) { - dest[i] = src[i]; - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with nested ELSE conditions - i = 0; - for (boolean b : src) { - if(i + 2 >= len) { - i++; - } else { - dest[i] = src[i + 2]; - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with more nested conditions - i = 0; - for (boolean b : src) { - if(i + 2 < len) { - if(dest != null) { - if(src != null) { - if(i > 1 && i + 2 < src.length) { - dest[i] = src[i + 2]; - } - } - } - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch - i = 0; - for (boolean b : src) { - try { - dest[i] = src[i]; - } catch (RuntimeException e) { - e.printStackTrace(); - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch and if - i = 0; - for (boolean b : src) { - try { - if(dest != null) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch in catch - i = 0; - for (boolean b : src) { - try { - dest.toString(); - } catch (RuntimeException e) { - if(dest != null) { - dest[i] = src[i]; - } - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch in finally - i = 0; - for (boolean b : src) { - try { - dest.toString(); - } catch (RuntimeException e) { - e.printStackTrace(); - } finally { - dest[i] = src[i]; - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Array transformation - i = 0; - for (boolean b : src) { - dest[i] = transform(src[i]); - i++; - } - } - - public void copyWithWhileLoop() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple copy - int i = 0; - while (i < len) { - dest[i] = src[i]; - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with nested conditions - i = 0; - while (i < len) { - if(i + 2 < len) { - dest[i] = src[i + 2]; - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with nested ELSE conditions - i = 0; - while (i < len) { - if(i + 2 >= len) { - i++; - } else { - dest[i] = src[i + 2]; - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with more nested conditions - i = 0; - while (i < len) { - if(i + 2 < len) { - if(dest != null) { - if(src != null) { - if(i > 1 && i + 2 < src.length) { - dest[i] = src[i + 2]; - } - } - } - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch and if - i = 0; - while (i < len) { - try { - if(dest != null) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch in catch - i = 0; - while (i < len) { - try { - dest.toString(); - } catch (RuntimeException e) { - if(dest != null) { - dest[i] = src[i]; - } - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Array transformation - i = 0; - while (i < len) { - dest[i] = transform(src[i]); - i++; - } - } - - public void copyWithDoWhileLoop() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple copy - int i = 0; - do { - dest[i] = src[i]; - i++; - } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with nested conditions - i = 0; - do { - if(i + 2 < len) { - dest[i] = src[i + 2]; - } - i++; - } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with nested ELSE conditions - i = 0; - do { - if(i + 2 >= len) { - i++; - } else { - dest[i] = src[i + 2]; - } - i++; - } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with more nested conditions - i = 0; - do { - if(i + 2 < len) { - if(dest != null) { - if(src != null) { - if(i > 1 && i + 2 < src.length) { - dest[i] = src[i + 2]; - } - } - } - } - i++; - } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch and if - i = 0; - do { - try { - if(dest != null) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - i++; - } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch in catch - i = 0; - do { - try { - dest.toString(); - } catch (RuntimeException e) { - if(dest != null) { - dest[i] = src[i]; - } - } - i++; - } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Array transformation - i = 0; - do { - dest[i] = transform(src[i]); - i++; - } while (i < len); - } - - private boolean transform(boolean a) { - return !a; - } - + public void copyArrayOK() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Copy with clone + dest = src.clone(); + + // Copy with System.arraycopy() + System.arraycopy(src, 0, dest, 0, src.length); + + // Copy with Arrays.copyOf() + dest = Arrays.copyOf(src, src.length); + } + + public void nonRegression() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple assignation + for (int i = 0; i < len; i++) { + dest[i] = true; + } + + // Edit same array + for (int i = 0; i < len - 1; i++) { + dest[i] = dest[i + 1]; + } + + // Objects assignations + String a = null; + String b = "Sample Value"; + for (int i = 0; i < len; i++) { + a = b; + } + } + + public void copyWithForLoop() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple copy + for (int i = 0; i < len; i++) { + dest[i] = src[i]; + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy with nested conditions + for (int i = 0; i < len; i++) { + if (i + 2 < len) { + dest[i] = src[i + 2]; + } + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy with nested ELSE conditions + for (int i = 0; i < len; i++) { + if (i + 2 >= len) { + i++; + } else { + dest[i] = src[i + 2]; + } + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy with more nested conditions + for (int i = 0; i < len; i++) { + if (i + 2 < len) { + if (dest != null) { + if (src != null) { + if (i > 1 && i + 2 < src.length) { + dest[i] = src[i + 2]; + } + } + } + } + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy nested by try/catch + for (int i = 0; i < len; i++) { + try { + dest[i] = src[i]; + } catch (RuntimeException e) { + e.printStackTrace(); + } + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy nested by try/catch and if + for (int i = 0; i < len; i++) { + try { + if (dest != null) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy nested by try/catch in catch + for (int i = 0; i < len; i++) { + try { + dest.toString(); + } catch (RuntimeException e) { + if (dest != null) { + dest[i] = src[i]; + } + } + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy nested by try/catch in finally + for (int i = 0; i < len; i++) { + try { + dest.toString(); + } catch (RuntimeException e) { + e.printStackTrace(); + } finally { + dest[i] = src[i]; + } + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Array transformation + for (int i = 0; i < len; i++) { + dest[i] = transform(src[i]); + } + } + + public void copyWithForEachLoop() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple copy by foreach + int i = -1; + for (boolean b : src) { + dest[++i] = b; + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy with nested conditions by foreach + i = -1; + for (boolean b : src) { + if (b) { + dest[++i] = b; + } + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy with nested ELSE conditions by foreach + i = -1; + for (boolean b : src) { + if (i + 2 >= len) { + i++; + } else { + dest[++i] = b; + } + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy with more nested conditions + i = -1; + for (boolean b : src) { + if (i + 2 < len) { + if (dest != null) { + if (src != null) { + if (i > 1 && i + 2 < src.length) { + dest[++i] = b; + } + } + } + } + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy nested by try/catch + i = -1; + for (boolean b : src) { + try { + dest[++i] = b; + } catch (RuntimeException e) { + e.printStackTrace(); + } + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy nested by try/catch and if + i = -1; + for (boolean b : src) { + try { + if (dest != null) { + dest[++i] = b; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy nested by try/catch in catch + i = -1; + for (boolean b : src) { + try { + dest.toString(); + } catch (RuntimeException e) { + if (dest != null) { + dest[++i] = b; + } + } + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy nested by try/catch in finally + i = -1; + for (boolean b : src) { + try { + dest.toString(); + } catch (RuntimeException e) { + e.printStackTrace(); + } finally { + dest[++i] = b; + } + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Array transformation + i = -1; + for (boolean b : src) { + dest[++i] = transform(b); + } + + // Simple copy + i = 0; + for (boolean b : src) { + dest[i] = src[i]; + i++; + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy with nested conditions + i = 0; + for (boolean b : src) { + if (b) { + dest[i] = src[i]; + } + i++; + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy with nested ELSE conditions + i = 0; + for (boolean b : src) { + if (i + 2 >= len) { + i++; + } else { + dest[i] = src[i + 2]; + } + i++; + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy with more nested conditions + i = 0; + for (boolean b : src) { + if (i + 2 < len) { + if (dest != null) { + if (src != null) { + if (i > 1 && i + 2 < src.length) { + dest[i] = src[i + 2]; + } + } + } + } + i++; + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy nested by try/catch + i = 0; + for (boolean b : src) { + try { + dest[i] = src[i]; + } catch (RuntimeException e) { + e.printStackTrace(); + } + i++; + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy nested by try/catch and if + i = 0; + for (boolean b : src) { + try { + if (dest != null) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + i++; + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy nested by try/catch in catch + i = 0; + for (boolean b : src) { + try { + dest.toString(); + } catch (RuntimeException e) { + if (dest != null) { + dest[i] = src[i]; + } + } + i++; + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy nested by try/catch in finally + i = 0; + for (boolean b : src) { + try { + dest.toString(); + } catch (RuntimeException e) { + e.printStackTrace(); + } finally { + dest[i] = src[i]; + } + i++; + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Array transformation + i = 0; + for (boolean b : src) { + dest[i] = transform(src[i]); + i++; + } + } + + public void copyWithWhileLoop() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple copy + int i = 0; + while (i < len) { + dest[i] = src[i]; + i++; + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy with nested conditions + i = 0; + while (i < len) { + if (i + 2 < len) { + dest[i] = src[i + 2]; + } + i++; + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy with nested ELSE conditions + i = 0; + while (i < len) { + if (i + 2 >= len) { + i++; + } else { + dest[i] = src[i + 2]; + } + i++; + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy with more nested conditions + i = 0; + while (i < len) { + if (i + 2 < len) { + if (dest != null) { + if (src != null) { + if (i > 1 && i + 2 < src.length) { + dest[i] = src[i + 2]; + } + } + } + } + i++; + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy nested by try/catch and if + i = 0; + while (i < len) { + try { + if (dest != null) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + i++; + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy nested by try/catch in catch + i = 0; + while (i < len) { + try { + dest.toString(); + } catch (RuntimeException e) { + if (dest != null) { + dest[i] = src[i]; + } + } + i++; + } // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Array transformation + i = 0; + while (i < len) { + dest[i] = transform(src[i]); + i++; + } + } + + public void copyWithDoWhileLoop() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple copy + int i = 0; + do { + dest[i] = src[i]; + i++; + } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy with nested conditions + i = 0; + do { + if (i + 2 < len) { + dest[i] = src[i + 2]; + } + i++; + } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy with nested ELSE conditions + i = 0; + do { + if (i + 2 >= len) { + i++; + } else { + dest[i] = src[i + 2]; + } + i++; + } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy with more nested conditions + i = 0; + do { + if (i + 2 < len) { + if (dest != null) { + if (src != null) { + if (i > 1 && i + 2 < src.length) { + dest[i] = src[i + 2]; + } + } + } + } + i++; + } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy nested by try/catch and if + i = 0; + do { + try { + if (dest != null) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + i++; + } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Copy nested by try/catch in catch + i = 0; + do { + try { + dest.toString(); + } catch (RuntimeException e) { + if (dest != null) { + dest[i] = src[i]; + } + } + i++; + } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} + + // Array transformation + i = 0; + do { + dest[i] = transform(src[i]); + i++; + } while (i < len); + } + + private boolean transform(boolean a) { + return !a; + } + } \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java index 122a48b4..41bb443a 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java @@ -1,21 +1,22 @@ package fr.greencodeinitiative.java.checks; import java.math.BigDecimal; +import java.sql.Connection; +import java.sql.DriverManager; import java.sql.PreparedStatement; -import java.util.regex.Pattern; +import java.sql.SQLException; import java.util.stream.IntStream; -import java.util.stream.Stream; class AvoidSetConstantInBatchUpdateCheck { - void literalSQLrequest() { //dirty call + void literalSQLrequest() throws SQLException { //dirty call int x = 0; Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle"); PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?)"); stmt.setInt(1, 101); stmt.setString(2, "Ratan"); - stmt.setBigDecimal(3, Bigdecimal.ONE); + stmt.setBigDecimal(3, BigDecimal.ONE); stmt.setBigDecimal(4, BigDecimal.valueOf(x)); stmt.setBoolean(5, Boolean.valueOf("true")); int i = stmt.executeUpdate(); @@ -23,7 +24,7 @@ void literalSQLrequest() { //dirty call con.close(); } - void batchInsertInForLoop(int[] data) { + void batchInsertInForLoop(int[] data) throws SQLException { Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle"); PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?,?,?,?,?,?,?,?)"); @@ -32,7 +33,7 @@ void batchInsertInForLoop(int[] data) { stmt.setBoolean(2, true); // Noncompliant {{Avoid setting constants in batch update}} stmt.setByte(3, (byte) 3); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setByte(4, 'v'); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setByte(4, (byte) 'v'); // Noncompliant {{Avoid setting constants in batch update}} stmt.setShort(5, (short) 5); // Noncompliant {{Avoid setting constants in batch update}} stmt.setInt(6, 6); // Noncompliant {{Avoid setting constants in batch update}} stmt.setLong(7, (long) 7); // Noncompliant {{Avoid setting constants in batch update}} @@ -46,12 +47,12 @@ void batchInsertInForLoop(int[] data) { stmt.addBatch(); } int[] nr = stmt.executeBatch(); - logger.log("{} rows updated", IntStream.of(nr).sum()); + System.out.printf("{} rows updated", IntStream.of(nr).sum()); con.close(); } - int[] batchInsertInForeachLoop(DummyClass[] data) { + int[] batchInsertInForeachLoop(DummyClass[] data) throws SQLException { try (Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle")) { PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?,?,?,?,?,?,?,?,?,?)"); @@ -59,7 +60,7 @@ int[] batchInsertInForeachLoop(DummyClass[] data) { stmt.setInt(1, o.getField1()); stmt.setBoolean(2, Boolean.valueOf("false")); // Noncompliant {{Avoid setting constants in batch update}} stmt.setByte(3, o.getField3()); - stmt.setByte(4, 'v'); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setByte(4, (byte) 'v'); // Noncompliant {{Avoid setting constants in batch update}} stmt.setShort(5, (short) 5); // Noncompliant {{Avoid setting constants in batch update}} stmt.setInt(6, 6); // Noncompliant {{Avoid setting constants in batch update}} stmt.setLong(7, 7); // Noncompliant {{Avoid setting constants in batch update}} @@ -74,7 +75,7 @@ int[] batchInsertInForeachLoop(DummyClass[] data) { } - int[] batchInsertInWhileLoop(DummyClass[] data) { + int[] batchInsertInWhileLoop2(DummyClass[] data) throws SQLException { try (Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle")) { PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?,?,?,?,?,?,?,?,?,?)"); @@ -85,7 +86,7 @@ int[] batchInsertInWhileLoop(DummyClass[] data) { stmt.setBoolean(2, Boolean.TRUE); // Noncompliant {{Avoid setting constants in batch update}} stmt.setByte(3, o.getField3()); stmt.setByte(4, Byte.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setByte(4, Character.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setByte(4, (byte) Character.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}} stmt.setShort(5, Short.MIN_VALUE); // Noncompliant {{Avoid setting constants in batch update}} stmt.setInt(6, Integer.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}} stmt.setLong(7, Long.MIN_VALUE); // Noncompliant {{Avoid setting constants in batch update}} @@ -100,7 +101,7 @@ int[] batchInsertInWhileLoop(DummyClass[] data) { } } - int[] batchInsertInWhileLoop(DummyClass[] data) { + int[] batchInsertInWhileLoop(DummyClass[] data) throws SQLException { if (data.length == 0) { return new int[]{}; } @@ -113,11 +114,10 @@ int[] batchInsertInWhileLoop(DummyClass[] data) { stmt.setBoolean(2, Boolean.valueOf(true)); // Noncompliant {{Avoid setting constants in batch update}} stmt.setByte(3, o.getField3()); stmt.setByte(4, Byte.valueOf((byte) 3)); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setByte(4, Character.valueOf('1')); // Noncompliant {{Avoid setting constants in batch update}} stmt.setShort(5, Short.valueOf((short) 55)); // Noncompliant {{Avoid setting constants in batch update}} stmt.setInt(6, Integer.valueOf("222")); // Noncompliant {{Avoid setting constants in batch update}} stmt.setLong(7, Long.valueOf(0)); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setFloat(8, Float.valueOf(.33)); // Noncompliant {{Avoid setting constants in batch update}} + stmt.setFloat(8, Float.valueOf(.33f)); // Noncompliant {{Avoid setting constants in batch update}} stmt.setDouble(9, Double.valueOf(22)); // Noncompliant {{Avoid setting constants in batch update}} stmt.setString(10, o.getField2()); stmt.setBigDecimal(11, BigDecimal.valueOf(11)); // Noncompliant {{Avoid setting constants in batch update}} @@ -143,8 +143,9 @@ public byte getField3() { } public double getField4() { - return .1; } - } - + return .1; + } + } + } \ No newline at end of file From 48aacb3b255fe58731a4443d753e41a490e8f060 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Mon, 10 Apr 2023 10:45:58 +0200 Subject: [PATCH 018/233] [ISSUE 60] adding test use cases --- .../java/checks/IncrementCheck.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java index 7f5f6cc1..a88292b4 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java @@ -30,7 +30,19 @@ void foo3(int value) { } void foo4(int value) { - int counter =0; + int counter = 0; counter = counter + 35 + 78 ; } + + void foo50(int value) { + for (int i=0; i < 10; i++) { // Noncompliant {{Use ++i instead of i++}} + System.out.println(i); + } + } + + void foo51(int value) { + for (int i=0; i < 10; ++i) { + System.out.println(i); + } + } } \ No newline at end of file From dfc12d945344c186b0f5fd15c99e93b05245d7f1 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Wed, 12 Apr 2023 22:52:43 +0200 Subject: [PATCH 019/233] [ISSUE 166] correction of wrong message (#9) --- .../checks/UnnecessarilyAssignValuesToVariablesTestCheck.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheck.java index 4a591504..b61a58ec 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheck.java @@ -14,7 +14,7 @@ public int testSwitchCase() throws Exception { int[] intArray = {10, 20, 30, 40, 50}; Exception variableException = new Exception("message"); - int variableNotUse = 5; // Noncompliant {{The variable is not assigned}} + int variableNotUse = 5; // Noncompliant {{The variable is declared but not really used}} variableNotUse = 10; From 78003eca15b35a970701cf68464686e774450516 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 8 Jun 2023 08:13:40 +0200 Subject: [PATCH 020/233] upgrade authent method for SonarQube --- tool_send_to_sonar.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tool_send_to_sonar.sh b/tool_send_to_sonar.sh index 61de09a9..80bff055 100755 --- a/tool_send_to_sonar.sh +++ b/tool_send_to_sonar.sh @@ -2,4 +2,4 @@ # "sonar.login" variable : private TOKEN generated in your local SonarQube during installation # (input paramater of this script) -mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.login=$1 +mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.token=$1 From 6cf57753a9d53fe98b21aa1201ee1103366745ca Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 14 Jul 2023 22:03:26 +0700 Subject: [PATCH 021/233] update sonar scanner command --- tool_send_to_sonar.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tool_send_to_sonar.sh b/tool_send_to_sonar.sh index 80bff055..03abfae8 100755 --- a/tool_send_to_sonar.sh +++ b/tool_send_to_sonar.sh @@ -1,5 +1,8 @@ #!/usr/bin/env sh -# "sonar.login" variable : private TOKEN generated in your local SonarQube during installation +# "sonar.token" variable (or sonar.login before SONARQUBE 9.9) : private TOKEN generated in your local SonarQube during installation # (input paramater of this script) mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.token=$1 + +# command if you have a SONARQUBE < 9.9 (sonar.token existing for SONARQUBE >= 10.0) +# mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.login=$1 From 37a343f03309f7c8b63c2002a05e4fe2f36561af Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 15 Aug 2023 23:50:36 +0200 Subject: [PATCH 022/233] [ISSUE 216] upgrade EC2 rule pour Java (multiple If/Else/Elseif) --- .../checks/AvoidMultipleIfElseStatement.java | 266 ++++++++++++++++-- .../AvoidMultipleIfElseStatementNoIssue.java | 187 +++++++++++- 2 files changed, 422 insertions(+), 31 deletions(-) diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java index 6dbc73db..0ce74dcb 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java @@ -1,38 +1,266 @@ package fr.greencodeinitiative.java.checks; class AvoidMultipleIfElseStatementCheck { - AvoidMultipleIfElseStatementCheck(AvoidMultipleIfElseStatementCheck mc) { - } - public void methodWithMultipleIfElseIf() { +// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// // +// // NON COMPLIANT use cases +// // +// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + // NON COMPLIANT + // USE CASE : Non compliant use case to check if following is NON OK : + // - two uses of the same variable + // - usage of the same variable on different levels of IF statements + public int shouldBeCompliantBecauseVariableUsedMaximumTwiceInComposedElseStatements() + { int nb1 = 0; - int nb2 = 10; if (nb1 == 1) { + nb1 = 2; + } else { + if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 1; + } + } + + return nb1; + } + + // NON COMPLIANT + // USE CASE : non compliant use case to check if a variable is not used max twice on several IF / ELSE statements + // at the same level + public int shouldBeNotCompliantBecauseVariablesUsedMaximumTwiceAndDifferentsVariablesUsed() + { + int nb1 = 0; + int nb2 = 0; + int nb3 = 0; + + if (nb3 == 1 + && nb3 == 2 + && nb3 == 3) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} nb1 = 1; - } else if (nb1 == nb2) { - // - } else if (nb2 == nb1) { - // } else { - // - } // Noncompliant {{Using a switch statement instead of multiple if-else if possible}} - nb1 = nb2; + nb2 = 2; + } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + + if (nb2 == 2) { + nb1 = 3; + } else { + nb1 = 4; + } + + return nb1; + } + + // NON COMPLIANT + // USE CASE : NON compliant use case to check if following is NOT COMPLIANT : + // one variable is used maximum in two IF / ELSE / ELSEIF statements + public int shouldBeNotCompliantBecauseVariablesIsUsedMoreThanTwice() + { + int nb1 = 0; + + if (nb1 == 1) { + nb1 = 2; + } else { + nb1 = 3; + } + + if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 4; + } + + return nb1; + } + + // NON COMPLIANT + // USE CASE : NON compliant use case to check if following is NOT OK : + // - same variable used maximum twice : no compliant because 2 IFs and 1 ELSE + public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInIfStatementsAtDifferentsLevels() + { + int nb1 = 0; + + if (nb1 == 1) { + if (nb1 == 2) { + nb1 = 1; + } else { + nb1 = 3; + } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + } else { + nb1 = 2; + } + + return nb1; } - public void methodWithMultipleIfElse() { + + // NON COMPLIANT + // USE CASE : non compliant use case to check if following is NOT OK : + // - two uses of the same variable : use thre times with 2 IFs and 1 ELSE + // - usage of the same variable on different levels of IF statements + public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseStatements() + { + int nb1 = 0; + + if (nb1 == 1) { + nb1 = 2; + } else { + if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 1; + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 3; + } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + } + + return nb1; + } + + // NON COMPLIANT + // USE CASE : non compliant use case to check if following is NOT OK : + // - two uses of the same variable : use thre times with 2 IFs and 1 ELSE + // - usage of the same variable on different levels of IF statements + public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseStatementsScenario2() + { + int nb1 = 0; + + if (nb1 == 1) { + if (nb1 == 3) { + nb1 = 4; + } else { + nb1 = 5; + } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + } else { + if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 1; + } else { + nb1 = 3; + } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + } + + return nb1; + } + + + // NON COMPLIANT + // USE CASE : non compliant use case to check if following is NOT OK : + // - two uses of the same variable : use thre times with 2 IFs and 1 ELSE + // - usage of the same variable on different levels of IF statements + public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseStatementsScenario3() + { + int nb1 = 0; + int nb2 = 0; + + if (nb1 == 1) { + if (nb1 == 3) { + nb1 = 4; + } else { + nb1 = 5; + } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + } else if (nb2 == 2) { + if (nb1 == 4) { + nb1 = 5; + } else { + nb1 = 6; + } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + } + + return nb1; + } + + // NON COMPLIANT + // USE CASE : non compliant use case to check if following is NOT OK : + // - two uses of the same variable : use thre times with 2 IFs and 1 ELSE + // - usage of the same variable on different levels of IF statements + public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseStatementsScenario4() + { + int nb1 = 0; + int nb2 = 0; + + if (nb1 == 1) { + if (nb2 == 3) { + nb1 = 4; + } else { + nb1 = 5; + } + } else if (nb2 == 2) { + if (nb1 == 3) { + nb1 = 4; + } else { + nb1 = 5; + } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + } + + return nb1; + } + + // NON COMPLIANT + // USE CASE : NON compliant use case to check if following is NOT OK : + // - the same variable must used maximum twice + // - usage of the same variable on different levels of IF / ELSE statements + public int shouldBeNotCompliantBecauseVariableUsedMaximumTwiceInComposedElseStatements() + { + int nb1 = 0; + + if (nb1 == 1) { + nb1 = 2; + } else { + if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 1; + } else { + if (nb1 == 3) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 4; + } else { + nb1 = 5; + } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + } + + return nb1; + } + + // NON COMPLIANT + // USE CASE : NON compliant use case to check if following is NOT OK : + // - more than twice uses of the same variable + // - usage of the same variable on different kind of test statements (IF and ELSEIF) + public int shouldBeNotCompliantBecauseTheSameVariableIsUsedMoreThanTwice() // NOT Compliant + { int nb1 = 0; int nb2 = 10; if (nb1 == 1) { - nb1 = 1; + nb2 = 1; + } else if (nb1 == nb2) { + nb2 = 2; } else { - // - } // Noncompliant {{Using a switch statement instead of multiple if-else if possible}} + nb2 = 4; + } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + + return nb2; + } + + // NON COMPLIANT + // USE CASE : NON compliant use case to check if following is NOT OK : + // - more than twice uses of the same variable + // - usage of the same variable on different kind of test statements (IF and ELSEIF) + public int shouldBeNotCompliantBecauseTheSameVariableIsUsedManyTimes() // NOT Compliant + { + int nb1 = 0; + int nb2 = 10; + int nb3 = 11; + if (nb1 == 1) { - nb1 = 1; + nb2 = 1; + } else if (nb1 == nb2) { + nb2 = 2; + } else if (nb3 == nb1) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb2 = 3; } else { - // - } // Noncompliant {{Using a switch statement instead of multiple if-else if possible}} + nb2 = 4; + } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + + return nb2; } -} \ No newline at end of file + +} diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java index 60d10293..d3a57b7a 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java @@ -1,31 +1,194 @@ package fr.greencodeinitiative.java.checks; -class AvoidMultipleIfElseStatementNoIssueCheck { - AvoidMultipleIfElseStatementNoIssueCheck(AvoidMultipleIfElseStatementNoIssueCheck mc) { +class AvoidMultipleIfElseStatementCheckNoIssue { + + // inital RULES : please see HTML description file of this rule (resources directory) + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // COMPLIANT use cases + // + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + // COMPLIANT + // USE CASE : compliant use case to check if a variable is used maximum twice on several IF / ELSE statements + // at the same level AND no problem with several IF staments at the same level using different variables + public int shouldBeCompliantBecauseVariablesUsedMaximumTwiceAndDifferentsVariablesUsed() + { + int nb1 = 0; + int nb2 = 0; + int nb3 = 0; + + if (nb3 != 1 && nb1 > 1) { + nb1 = 1; + } else { + nb2 = 2; + } + + if (nb2 == 2) { + nb1 = 3; + } else { + nb1 = 4; + } + + return nb1; } - public void methodWithOneIfElseIf() { + // COMPLIANT + // USE CASE : compliant use case to check if a variable is used maximum twice on several IF / ELSE statements + // at the same level AND no problem with several IF staments at the same level using different variables + public int shouldBeCompliantBecauseVariablesUsedMaximumTwiceAndDifferentsVariablesUsedAtDiffLevels() + { + int nb1 = 0; + int nb2 = 0; + int nb3 = 0; + + if (nb1 < 1) { + if (nb2 == 2) { + nb3 = 3; + } else { + nb3 = 4; + } + } else { + nb2 = 2; + } + + if (nb3 >= 1) { + if (nb2 == 2) { + nb1 = 3; + } else { + nb1 = 4; + } + } else { + nb1 = 2; + } + + return nb1; + } + + // COMPLIANT + // USE CASE : compliant use case to check if a variable is used maximum twice on several IF / ELSE statements + // at the same level AND no problem with several IF staments at the same level using different variables + public int shouldBeCompliantBecauseVariablesUsedMaximumTwiceAndDiffVariablesUsedAtDiffLevelsScenario2() + { + int nb1 = 0; + int nb2 = 0; + int nb3 = 0; + + if (nb1 <= 1) { + if (nb2 == 2) { + if (nb3 == 2) { + nb3 = 3; + } else { + nb3 = 4; + } + } else { + nb3 = 4; + } + } else { + nb2 = 2; + } + + if (nb3 == 1) { + if (nb2 == 2) { + nb1 = 3; + } else { + nb1 = 4; + } + } else { + nb1 = 2; + } + + return nb1; + } + + // COMPLIANT + // USE CASE : compliant use case to check if one variable is used maximum twice in different IF statements + public int shouldBeCompliantBecauseVariableUsedMaximumTwiceInIfStatements() + { int nb1 = 0; - int nb2 = 10; if (nb1 == 1) { nb1 = 1; - } else if (nb1 == nb2) { - // + } + + if (nb1 == 2) { + nb1 = 3; + } + + return nb1; + } + + // COMPLIANT + // USE CASE : compliant use case to check if following is OK : + // - two uses of the same variable + // - usage of the same variable on different levels of IF statements + public int shouldBeCompliantBecauseSereralVariablesUsedMaximumTwiceInComposedElseStatements() + { + int nb1 = 0; + int nb2 = 0; + int nb3 = 0; + + if (nb1 == 1) { + nb1 = 2; } else { - // + if (nb2 == 2) { + nb1 = 1; + } else { + if (nb3 == 4) { + nb1 = 3; + } else { + nb1 = 6; + } + } } - nb1 = nb2; + + return nb1; } - public void methodWithOneIfElse() { + // COMPLIANT + // USE CASE : compliant use case to check if following is OK : + // - two uses of the same variable + // - usage of the same variable on different kind of test statements (IF and ELSEIF) + public int shouldBeCompliantBecauseVariableUsedMaximumTwiceInIfOrElseIfStatements() // Compliant + { int nb1 = 0; int nb2 = 10; if (nb1 == 1) { - nb1 = 1; + nb2 = 1; + } else if (nb1 == nb2) { + nb2 = 2; + } + + return nb2; + } + + // COMPLIANT + // USE CASE : compliant use case to check if following is OK : + // - two uses of the same variable + // - usage of the same variable on different kind of test statements (IF and ELSEIF) + public int shouldBeCompliantBecauseSeveralVariablesUsedMaximumTwiceInIfOrElseIfStatements() // Compliant + { + int nb1 = 0; + int nb2 = 10; + int nb3 = 3; + int nb4 = 1; + int nb5 = 2; + + if (nb1 == 1) { + nb2 = 1; + } else if (nb3 == nb2) { + nb2 = 2; + } else if (nb4 == nb5) { + nb2 = 4; } else { - // + nb2 = 3; } + + return nb2; } -} \ No newline at end of file + +} From a8b4dff28fa8f2945735ca4a72a37959b87e0713 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 1 Dec 2023 22:09:38 +0100 Subject: [PATCH 023/233] [ISSUE 112] add use case file for EC1 streams --- .../AvoidSpringRepositoryCallInLoopCheck.java | 12 +- ...voidSpringRepositoryCallInStreamCheck.java | 139 ++++++++++++++++++ 2 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java index 2b1579a7..33989f2f 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java @@ -12,7 +12,7 @@ public class AvoidSpringRepositoryCallInLoopCheck { public List smellGetAllEmployeesByIds(List ids) { List employees = new ArrayList<>(); for (Integer id : ids) { - Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop}} + Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop or stream}} if (employee.isPresent()) { employees.add(employee.get()); } @@ -21,6 +21,16 @@ public List smellGetAllEmployeesByIds(List ids) { } public class Employee { + private Integer id; + private String name; + + public Employee(Integer id, String name) { + this.id = id; + this.name = name; + } + + public Integer getId() { return id; } + public String getName() { return name; } } public interface EmployeeRepository extends JpaRepository { diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java new file mode 100644 index 00000000..636e55e2 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java @@ -0,0 +1,139 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.greencodeinitiative.java.checks; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +public class AvoidSpringRepositoryCallInStreamCheck { + + @Autowired + private EmployeeRepository employeeRepository; + + public void smellGetAllEmployeesByIdsForEach() { + List employees = new ArrayList<>(); + Stream stream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + stream.forEach(id -> { + Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop or stream}} + if (employee.isPresent()) { + employees.add(employee.get()); + } + }); + } + + public void smellGetAllEmployeesByIdsForEachOrdered() { + List employees = new ArrayList<>(); + Stream stream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + stream.forEachOrdered(id -> { + Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop or stream}} + if (employee.isPresent()) { + employees.add(employee.get()); + } + }); + } + + public List smellGetAllEmployeesByIdsMap() { + List employees = new ArrayList<>(); + Stream stream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + return stream.map(id -> { + Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop or stream}} + if (employee.isPresent()) { + employees.add(employee.get()); + } + }) + .collect(Collectors.toList()); + } + + public List smellGetAllEmployeesByIdsPeek() { + List employees = new ArrayList<>(); + Stream stream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + return stream.peek(id -> { + Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop or stream}} + if (employee.isPresent()) { + employees.add(employee.get()); + } + }) + .collect(Collectors.toList()); + } + + public List smellGetAllEmployeesByIdsWithOptional(List ids) { + List employees = new ArrayList<>(); + return ids + .stream() + .map(element -> { + Employee empl = new Employee(); + employees.add(empl); + return employeeRepository.findById(element).orElse(empl);// Noncompliant {{Avoid Spring repository call in loop or stream}} + }) + .collect(Collectors.toList()); + } + + public List smellGetAllEmployeesByIds(List ids) { + Stream stream = ids.stream(); + return stream.map(element -> { + Employee empl = new Employee(); + employees.add(empl); + return employeeRepository.findById(element);// Noncompliant {{Avoid Spring repository call in loop or stream}} + }) + .collect(Collectors.toList()); + } + + public List smellGetAllEmployeesByIdsWithoutStream(List ids) { + return employeeRepository.findAllById(ids); // Compliant + } + + public List smellDeleteEmployeeById(List ids) { + Stream stream = ids.stream(); + return stream.map(element -> { + Employee empl = new Employee(); + employees.add(empl); + return employeeRepository.deleteById(element);// Noncompliant {{Avoid Spring repository call in loop or stream}} + }) + .collect(Collectors.toList()); + } + + public List smellGetAllEmployeesByIdsWithSeveralMethods(List ids) { + Stream stream = ids.stream(); + return stream.map(element -> { + Employee empl = new Employee(); + return employeeRepository.findById(element).orElse(empl).anotherMethod().anotherOne();// Noncompliant {{Avoid Spring repository call in loop or stream}} + }) + .collect(Collectors.toList()); + } + + public class Employee { + private Integer id; + private String name; + + public Employee(Integer id, String name) { + this.id = id; + this.name = name; + } + + public Integer getId() { return id; } + public String getName() { return name; } + } + + public interface EmployeeRepository extends JpaRepository { + } +} \ No newline at end of file From 9e87447c24add57a96c953fb4d7275b66f1d8faa Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 1 Dec 2023 22:12:20 +0100 Subject: [PATCH 024/233] [ISSUE 112] add use case file for EC1 streams - add header --- .../AvoidSpringRepositoryCallInLoopCheck.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java index 33989f2f..ee932983 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.springframework.beans.factory.annotation.Autowired; From 8ed7e9261d8a8df3d60410a30b913282c6bced9a Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Sun, 3 Dec 2023 23:34:24 +0100 Subject: [PATCH 025/233] [ISSUE 247] add 2 new use cases for switch --- .../AvoidMultipleIfElseStatementNoIssue.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java index d3a57b7a..62a8373c 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java @@ -191,4 +191,40 @@ public int shouldBeCompliantBecauseSeveralVariablesUsedMaximumTwiceInIfOrElseIfS return nb2; } + // COMPLIANT + // USE CASE : Compliant use case to check if following is OK : + // - usage of the same variable on different levels of IF statements but with incompatible type for a switch + public float shouldBeCompliantBecauseVariableHasNotCompatibleTypeFloatForSwitch() + { + float nb1 = 0.0f; + + if (nb1 > 1) { + nb1 = 2.1f; + } else { + if (nb1 > 2) { + nb1 = 1.1f; + } + } + + return nb1; + } + + // COMPLIANT + // USE CASE : Compliant use case to check if following is OK : + // - usage of the same variable on different levels of IF statements but with incompatible type for a switch + public double shouldBeCompliantBecauseVariableHasNotCompatibleTypeDoubleForSwitch() + { + double nb1 = 0.0; + + if (nb1 > 1) { + nb1 = 2.1; + } else { + if (nb1 > 2) { + nb1 = 1.1; + } + } + + return nb1; + } + } From 5c920ef4dd1a384db69e2cb5df2d55192ff52b09 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 7 Dec 2023 23:30:43 +0100 Subject: [PATCH 026/233] [ISSUE 248] Add test to prove ISSUE 248 is already ok --- .../AvoidMultipleIfElseStatementNoIssue.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java index 62a8373c..fc7c8f79 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java @@ -227,4 +227,30 @@ public double shouldBeCompliantBecauseVariableHasNotCompatibleTypeDoubleForSwitc return nb1; } + // COMPLIANT + // USE CASE : Compliant use case to check if following is OK : + // - usage of the same variable on different levels of IF statements but with instanceof keys + // - with a variable used 4 times + public int shouldBeCompliantBecauseVariableUsed4TimesWithInstanceOfKeys() + { + int nb1 = 0; + Object obj = new Object(); + + if (obj instanceof String) { + nb1 = 1; + } else { + if (obj instanceof Integer) { + nb1 = 2; + } else { + if (obj instanceof Double) { + nb1 = 3; + } else { + nb1 = 4; + } + } + } + + return nb1; + } + } From 5ce922a0c2a7cc27ecce75f8276676ed9771c83d Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Wed, 17 Jan 2024 08:15:35 +0100 Subject: [PATCH 027/233] [TECH] add comment --- tool_send_to_sonar.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tool_send_to_sonar.sh b/tool_send_to_sonar.sh index 03abfae8..6a658d71 100755 --- a/tool_send_to_sonar.sh +++ b/tool_send_to_sonar.sh @@ -3,6 +3,7 @@ # "sonar.token" variable (or sonar.login before SONARQUBE 9.9) : private TOKEN generated in your local SonarQube during installation # (input paramater of this script) mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.token=$1 +# mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.token=$1 -Dsonar.host.url=https://sonar-staging.gcp.cicd.solocal.com/ # command if you have a SONARQUBE < 9.9 (sonar.token existing for SONARQUBE >= 10.0) # mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.login=$1 From 8f32648b3cc148c8054607e3c26bc86e7c3746b4 Mon Sep 17 00:00:00 2001 From: alograg Date: Wed, 17 Jan 2024 17:06:39 +0100 Subject: [PATCH 028/233] fix: :bug: Fix issues #228 #233 #235 #240 --- docker-compose.yml | 4 +- pom.xml | 2 +- .../java/JavaCheckRegistrar.java | 8 - .../checks/AvoidConcatenateStringsInLoop.java | 84 ------- .../AvoidUsingGlobalVariablesCheck.java | 66 ------ .../UnnecessarilyAssignValuesToVariables.java | 217 ------------------ .../java/checks/UseCorrectForLoop.java | 54 ----- .../files/AvoidConcatenateStringsInLoop.java | 49 ---- .../files/AvoidUsingGlobalVariablesCheck.java | 37 --- ...arilyAssignValuesToVariablesTestCheck.java | 95 -------- ...esToVariablesTestCheckWithEmptyReturn.java | 33 --- src/test/files/UseCorrectForLoopCheck.java | 41 ---- .../AvoidConcatenateStringsInLoopTest.java | 42 ---- ...oidUsingGlobalVariablesCheckCheckTest.java | 34 --- ...ecessarilyAssignValuesToVariablesTest.java | 42 ---- .../java/checks/UseCorrectLoopCheckTest.java | 34 --- 16 files changed, 3 insertions(+), 839 deletions(-) delete mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java delete mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java delete mode 100644 src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariables.java delete mode 100644 src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoop.java delete mode 100644 src/test/files/AvoidConcatenateStringsInLoop.java delete mode 100644 src/test/files/AvoidUsingGlobalVariablesCheck.java delete mode 100644 src/test/files/UnnecessarilyAssignValuesToVariablesTestCheck.java delete mode 100644 src/test/files/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java delete mode 100644 src/test/files/UseCorrectForLoopCheck.java delete mode 100644 src/test/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoopTest.java delete mode 100644 src/test/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheckCheckTest.java delete mode 100644 src/test/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTest.java delete mode 100644 src/test/java/fr/greencodeinitiative/java/checks/UseCorrectLoopCheckTest.java diff --git a/docker-compose.yml b/docker-compose.yml index 1782b705..bd446533 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,8 +16,8 @@ services: SONAR_ES_BOOTSTRAP_CHECKS_DISABLE: 'true' volumes: - type: bind - source: ./target/ecocode-java-plugin-1.5.1-SNAPSHOT.jar - target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-1.5.1-SNAPSHOT.jar + source: ./target/ecocode-java-plugin-1.5.2-SNAPSHOT.jar + target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-1.5.2-SNAPSHOT.jar - "extensions:/opt/sonarqube/extensions" - "logs:/opt/sonarqube/logs" - "data:/opt/sonarqube/data" diff --git a/pom.xml b/pom.xml index 25a26bf6..dac51ea0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.ecocode ecocode-java-plugin - 1.5.1-SNAPSHOT + 1.5.2-SNAPSHOT sonar-plugin diff --git a/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java b/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java index f972a202..f4ef343d 100644 --- a/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java +++ b/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java @@ -21,7 +21,6 @@ import java.util.List; import fr.greencodeinitiative.java.checks.ArrayCopyCheck; -import fr.greencodeinitiative.java.checks.AvoidConcatenateStringsInLoop; import fr.greencodeinitiative.java.checks.AvoidFullSQLRequest; import fr.greencodeinitiative.java.checks.AvoidGettingSizeCollectionInLoop; import fr.greencodeinitiative.java.checks.AvoidMultipleIfElseStatement; @@ -31,14 +30,11 @@ import fr.greencodeinitiative.java.checks.AvoidSpringRepositoryCallInLoopOrStreamCheck; import fr.greencodeinitiative.java.checks.AvoidStatementForDMLQueries; import fr.greencodeinitiative.java.checks.AvoidUsageOfStaticCollections; -import fr.greencodeinitiative.java.checks.AvoidUsingGlobalVariablesCheck; import fr.greencodeinitiative.java.checks.FreeResourcesOfAutoCloseableInterface; import fr.greencodeinitiative.java.checks.IncrementCheck; import fr.greencodeinitiative.java.checks.InitializeBufferWithAppropriateSize; import fr.greencodeinitiative.java.checks.NoFunctionCallWhenDeclaringForLoop; import fr.greencodeinitiative.java.checks.OptimizeReadFileExceptions; -import fr.greencodeinitiative.java.checks.UnnecessarilyAssignValuesToVariables; -import fr.greencodeinitiative.java.checks.UseCorrectForLoop; import org.sonar.plugins.java.api.CheckRegistrar; import org.sonar.plugins.java.api.JavaCheck; import org.sonarsource.api.sonarlint.SonarLintSide; @@ -54,7 +50,6 @@ public class JavaCheckRegistrar implements CheckRegistrar { private static final List> ANNOTATED_RULE_CLASSES = List.of( ArrayCopyCheck.class, IncrementCheck.class, - AvoidConcatenateStringsInLoop.class, AvoidUsageOfStaticCollections.class, AvoidGettingSizeCollectionInLoop.class, AvoidRegexPatternNotStatic.class, @@ -63,11 +58,8 @@ public class JavaCheckRegistrar implements CheckRegistrar { AvoidSpringRepositoryCallInLoopOrStreamCheck.class, AvoidSQLRequestInLoop.class, AvoidFullSQLRequest.class, - UseCorrectForLoop.class, - UnnecessarilyAssignValuesToVariables.class, OptimizeReadFileExceptions.class, InitializeBufferWithAppropriateSize.class, - AvoidUsingGlobalVariablesCheck.class, AvoidSetConstantInBatchUpdate.class, FreeResourcesOfAutoCloseableInterface.class, AvoidMultipleIfElseStatement.class diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java deleted file mode 100644 index 488ebd0c..00000000 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package fr.greencodeinitiative.java.checks; - -import java.util.Arrays; -import java.util.List; -import javax.annotation.Nonnull; - -import org.sonar.check.Rule; -import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; -import org.sonar.plugins.java.api.tree.AssignmentExpressionTree; -import org.sonar.plugins.java.api.tree.BaseTreeVisitor; -import org.sonar.plugins.java.api.tree.BinaryExpressionTree; -import org.sonar.plugins.java.api.tree.ExpressionTree; -import org.sonar.plugins.java.api.tree.Tree; -import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; - -/** - * @deprecated because not useless since JDK 8 - */ -@Deprecated(forRemoval = true) -@Rule(key = "EC75") -@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S75") -public class AvoidConcatenateStringsInLoop extends IssuableSubscriptionVisitor { - - public static final String MESSAGE_RULE = "Don't concatenate Strings in loop, use StringBuilder instead."; - private static final String STRING_CLASS = String.class.getName(); - - private final StringConcatenationVisitor visitor = new StringConcatenationVisitor(); - - @Override - public List nodesToVisit() { - return Arrays.asList( - Tree.Kind.FOR_STATEMENT, - Tree.Kind.FOR_EACH_STATEMENT, - Tree.Kind.WHILE_STATEMENT - ); - } - - @Override - public void visitNode(@Nonnull Tree tree) { - tree.accept(visitor); - } - - private class StringConcatenationVisitor extends BaseTreeVisitor { - @Override - public void visitBinaryExpression(BinaryExpressionTree tree) { - if (tree.is(Tree.Kind.PLUS) && isStringType(tree.leftOperand())) { - reportIssue(tree, MESSAGE_RULE); - } else { - super.visitBinaryExpression(tree); - } - } - - @Override - public void visitAssignmentExpression(AssignmentExpressionTree tree) { - if (tree.is(Tree.Kind.PLUS_ASSIGNMENT) && isStringType(tree.variable())) { - reportIssue(tree, MESSAGE_RULE); - } else { - super.visitAssignmentExpression(tree); - } - } - - private boolean isStringType(ExpressionTree expressionTree) { - return expressionTree.symbolType().is(STRING_CLASS); - } - } - -} diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java deleted file mode 100644 index 26a6dbdd..00000000 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package fr.greencodeinitiative.java.checks; - -import com.google.re2j.Pattern; -import org.sonar.check.Rule; -import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; -import org.sonar.plugins.java.api.tree.Tree; -import org.sonar.plugins.java.api.tree.Tree.Kind; -import org.sonar.plugins.java.api.tree.VariableTree; -import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; - -import java.util.Arrays; -import java.util.List; - -/** - * Check to avoid using global variables. - * - * @deprecated because not applicable to Java language, to be removed soon - */ -@Deprecated(forRemoval = true) -@Rule(key = "EC4") -@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "D4") -public class AvoidUsingGlobalVariablesCheck extends IssuableSubscriptionVisitor { - - private static final String ERROR_MESSAGE = "Avoid using global variables"; - private static final Pattern PATTERN = Pattern.compile("^.*(static).*$", Pattern.CASE_INSENSITIVE); - - @Override - public List nodesToVisit() { - return Arrays.asList(Kind.STATIC_INITIALIZER, Kind.VARIABLE, Kind.METHOD); - } - - @Override - public void visitNode(Tree tree) { - if (tree.is(Kind.STATIC_INITIALIZER)) { - reportIssue(tree, String.format(ERROR_MESSAGE, tree)); - } - if (tree.is(Kind.VARIABLE)) { - VariableTree variableTree = (VariableTree) tree; - int modifiersSize = (variableTree).modifiers().modifiers().size(); - for (int i = 0; i < modifiersSize; i++) { - String modifier = ((VariableTree) tree).modifiers().modifiers().get(i).modifier().toString(); - if (PATTERN.matcher(modifier).matches()) { - reportIssue(tree, String.format(ERROR_MESSAGE, modifier)); - } - } - } - } - -} diff --git a/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariables.java b/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariables.java deleted file mode 100644 index aba735bf..00000000 --- a/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariables.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package fr.greencodeinitiative.java.checks; - -import org.sonar.check.Rule; -import org.sonar.plugins.java.api.JavaFileScanner; -import org.sonar.plugins.java.api.JavaFileScannerContext; -import org.sonar.plugins.java.api.tree.*; -import org.sonar.plugins.java.api.tree.Tree.Kind; -import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; - -import javax.annotation.CheckForNull; -import java.util.*; - -/** - * @deprecated not applicable because of existing Sonarqube native rules : - * - unused variable : https://rules.sonarsource.com/java/tag/unused/RSPEC-1481/ - * - useless assignment : https://rules.sonarsource.com/java/tag/unused/RSPEC-1854 - * - immediately return : https://rules.sonarsource.com/java/RSPEC-1488/ - */ -@Deprecated(forRemoval = true) -@Rule(key = "EC63") -@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S63") -public class UnnecessarilyAssignValuesToVariables extends BaseTreeVisitor implements JavaFileScanner { - - protected static final String MESSAGERULE1 = "The variable is declared but not really used"; - protected static final String MESSAGERULE2 = "Immediately throw this expression instead of assigning it to the temporary variable"; - protected static final String MESSAGERULE3 = "Immediately return this expression instead of assigning it to the temporary variable"; - private JavaFileScannerContext context; - private String errorMessage; - private final Map variableList = new HashMap<>(); - private static final Map> linesWithIssuesByVariable = new HashMap<>(); - - @Override - public void scanFile(JavaFileScannerContext context) { - this.context = context; - scan(context.getTree()); - } - - @Override - public void visitBlock(BlockTree tree) { - GetVariableVisitor getVariableVisitor = new GetVariableVisitor(); - CheckUseVariableVisitor checkVariable = new CheckUseVariableVisitor(); - super.visitBlock(tree); - checkImmediatelyReturnedVariable(tree); - tree.accept(getVariableVisitor); - tree.accept(checkVariable); - - variableList.forEach(this::reportIfUnknow); - variableList.clear(); - } - - private void reportIfUnknow(String name, Tree tree) { - Integer issueLine = tree.firstToken().range().start().line(); - - if (!(linesWithIssuesByVariable.containsKey(name) && linesWithIssuesByVariable.get(name).contains(issueLine))) { - if (!linesWithIssuesByVariable.containsKey(name)) { - linesWithIssuesByVariable.put(name, new ArrayList<>()); - } - - linesWithIssuesByVariable.get(name).add(issueLine); - - context.reportIssue(this, tree, MESSAGERULE1); - } - } - - private class GetVariableVisitor extends BaseTreeVisitor { - @Override - public void visitVariable(VariableTree tree) { - if (!tree.parent().is(Kind.METHOD)) { - variableList.put(tree.simpleName().name(), tree); - } - super.visitVariable(tree); - } - } - - private class CheckUseVariableVisitor extends BaseTreeVisitor { - - @Override - public void visitIfStatement(IfStatementTree tree) { - variableList.remove(tree.condition().toString()); - super.visitIfStatement(tree); - } - - @Override - public void visitUnaryExpression(UnaryExpressionTree tree) { - variableList.remove(tree.expression().toString()); - super.visitUnaryExpression(tree); - } - - @Override - public void visitForEachStatement(ForEachStatement tree) { - variableList.remove(tree.expression().toString()); - super.visitForEachStatement(tree); - } - - @Override - public void visitMethodInvocation(MethodInvocationTree tree) { - tree.arguments().forEach(e -> { - if (variableList.containsKey(e.toString())) { - variableList.remove(e.toString()); - } - }); - super.visitMethodInvocation(tree); - } - - @Override - public void visitMemberSelectExpression(MemberSelectExpressionTree tree) { - variableList.remove(tree.expression().toString()); - super.visitMemberSelectExpression(tree); - } - - @Override - public void visitTypeCast(TypeCastTree tree) { - variableList.remove(tree.expression().toString()); - super.visitTypeCast(tree); - } - - @Override - public void visitBinaryExpression(BinaryExpressionTree tree) { - if (!tree.operatorToken().is(Kind.ASSIGNMENT)) { - variableList.remove(tree.leftOperand().toString()); - } - variableList.remove(tree.rightOperand().toString()); - super.visitBinaryExpression(tree); - } - - @Override - public void visitNewClass(NewClassTree tree) { - tree.arguments().forEach(e -> { - if (variableList.containsKey(e.toString())) { - variableList.remove(e.toString()); - } - }); - super.visitNewClass(tree); - } - - @Override - public void visitReturnStatement(ReturnStatementTree tree) { - if (tree != null) { - if (tree.expression() != null) { - variableList.remove(tree.expression().toString()); - } - super.visitReturnStatement(tree); - } - } - - @Override - public void visitThrowStatement(ThrowStatementTree tree) { - variableList.remove(tree.expression().toString()); - super.visitThrowStatement(tree); - } - - @Override - public void visitAssignmentExpression(AssignmentExpressionTree tree) { - variableList.remove(tree.expression().toString()); - super.visitAssignmentExpression(tree); - } - - } - - private void checkImmediatelyReturnedVariable(BlockTree tree) { - List statements = tree.body(); - int size = statements.size(); - if (size < 2) { - return; - } - StatementTree butLastStatement = statements.get(size - 2); - if (butLastStatement.is(Kind.VARIABLE)) { - VariableTree variableTree = (VariableTree) butLastStatement; - if (!variableTree.modifiers().annotations().isEmpty()) { - return; - } - StatementTree lastStatement = statements.get(size - 1); - String lastStatementIdentifier = getReturnOrThrowIdentifier(lastStatement); - if (lastStatementIdentifier != null) { - String identifier = variableTree.simpleName().name(); - if (lastStatementIdentifier.equals(identifier)) { - context.reportIssue(this, variableTree.initializer(), errorMessage); - } - } - } - } - - @CheckForNull - private String getReturnOrThrowIdentifier(StatementTree lastStatementOfBlock) { - errorMessage = null; - ExpressionTree expr = null; - if (lastStatementOfBlock.is(Kind.THROW_STATEMENT)) { - errorMessage = MESSAGERULE2; - expr = ((ThrowStatementTree) lastStatementOfBlock).expression(); - } else if (lastStatementOfBlock.is(Kind.RETURN_STATEMENT)) { - errorMessage = MESSAGERULE3; - expr = ((ReturnStatementTree) lastStatementOfBlock).expression(); - } - if (expr != null && expr.is(Kind.IDENTIFIER)) { - return ((IdentifierTree) expr).name(); - } - return null; - } - -} diff --git a/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoop.java b/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoop.java deleted file mode 100644 index 35c7f677..00000000 --- a/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoop.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package fr.greencodeinitiative.java.checks; - -import java.util.Arrays; -import java.util.List; - -import org.sonar.check.Rule; -import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; -import org.sonar.plugins.java.api.tree.ForEachStatement; -import org.sonar.plugins.java.api.tree.Tree; -import org.sonar.plugins.java.api.tree.Tree.Kind; -import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; - -/** - * @deprecated there aren't enough good arguments and not enough green measures / benchmarks - * (check discussion on https://github.com/green-code-initiative/ecoCode/issues/240) - */ -@Deprecated(forRemoval = true) -@Rule(key = "EC53") -@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S53") -public class UseCorrectForLoop extends IssuableSubscriptionVisitor { - - protected static final String MESSAGERULE = "Avoid the use of Foreach with Arrays"; - - @Override - public List nodesToVisit() { - return Arrays.asList(Tree.Kind.FOR_EACH_STATEMENT); - } - - @Override - public void visitNode(Tree tree) { - - ForEachStatement forEachTree = (ForEachStatement) tree; - if (forEachTree.expression().symbolType().isArray()) { - reportIssue(tree, MESSAGERULE); - } - } -} diff --git a/src/test/files/AvoidConcatenateStringsInLoop.java b/src/test/files/AvoidConcatenateStringsInLoop.java deleted file mode 100644 index 4e2a5877..00000000 --- a/src/test/files/AvoidConcatenateStringsInLoop.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package fr.greencodeinitiative.java.utils; - -public class AvoidConcatenateStringsInLoop { - - public String concatenateStrings(String[] strings) { - String result1 = ""; - - for (String string : strings) { - result1 += string; // Noncompliant {{Don't concatenate Strings in loop, use StringBuilder instead.}} - } - return result1; - } - - public String concatenateStrings2() { - String result2 = ""; - - for (int i = 0; i < 1000; ++i) { - result2 += "another"; // Noncompliant {{Don't concatenate Strings in loop, use StringBuilder instead.}} - } - return result2; - } - - public String concatenateStrings3() { - String result3 = ""; - - for (int i = 0; i < 1000; ++i) { - result3 = result3 + "another"; // Noncompliant {{Don't concatenate Strings in loop, use StringBuilder instead.}} - } - return result3; - } - -} diff --git a/src/test/files/AvoidUsingGlobalVariablesCheck.java b/src/test/files/AvoidUsingGlobalVariablesCheck.java deleted file mode 100644 index 557d6fc9..00000000 --- a/src/test/files/AvoidUsingGlobalVariablesCheck.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -public class Openclass { - public static double price = 15.24; // Noncompliant {{Avoid using global variables}} - public static long pages = 1053; // Noncompliant {{Avoid using global variables}} - - public static void main(String[] args) { - double newPrice = Openclass.price; - long newPages = Openclass.pages; - System.out.println(newPrice); - System.out.println(newPages); - static long years = 3000; // Noncompliant {{Avoid using global variables}} - } - static{ // Noncompliant {{Avoid using global variables}} - int a = 4; - } - - public void printingA() { - System.out.println(a); - } - -} \ No newline at end of file diff --git a/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheck.java b/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheck.java deleted file mode 100644 index 17eb069a..00000000 --- a/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheck.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package fr.greencodeinitiative.java.checks; - -class UnnecessarilyAssignValuesToVariablesTestCheck { - UnnecessarilyAssignValuesToVariablesTestCheck(UnnecessarilyAssignValuesToVariablesTestCheck mc) { - } - - public int testSwitchCase() throws Exception { - int variableFor = 5; - int variableIf = 5; - int variableWhile = 5; - int variableExp = 5; - int variableReturn = 5; - int variableCLass = 5; - int[] intArray = {10, 20, 30, 40, 50}; - - Exception variableException = new Exception("message"); - int variableNotUse = 5; // Noncompliant {{The variable is declared but not really used}} - - - variableNotUse = 10; - for (variableFor = 0; variableFor < 5; ++variableFor) { - System.out.println(variableFor); - } - - for (int ia : intArray) { - System.out.println((char) ia); - } - - if (variableIf > 10) { - System.out.println(variableIf); - } - - while (variableWhile > 10) { - System.out.println(variableWhile); - } - - variableExp += 1; - variableNotUse = variableExp; - TestClass testClass = new TestClass(variableCLass); - if (testClass.isTrue()) { - throw variableException; - } - return variableReturn; - } - - private class TestClass { - TestClass(int i) { - ++i; - } - - public boolean isTrue() { - return true; - } - } - - - private int getIntValue() { - return 3; - } - - public int testNonCompliantReturn() { - int i = getIntValue(); // Noncompliant {{Immediately return this expression instead of assigning it to the temporary variable}} - return i; - } - - public int testCompliantReturn() { - return getIntValue(); - } - - public void testNonCompliantThrow() throws Exception { - Exception exception = new Exception("dummy"); // Noncompliant {{Immediately throw this expression instead of assigning it to the temporary variable}} - throw exception; - } - - public void testCompliantThrow() throws Exception { - throw new Exception("dummy"); - } -} \ No newline at end of file diff --git a/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java b/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java deleted file mode 100644 index f70c4c41..00000000 --- a/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package fr.greencodeinitiative.java.checks; - -class UnnecessarilyAssignValuesToVariablesTestCheck { - UnnecessarilyAssignValuesToVariablesTestCheck(UnnecessarilyAssignValuesToVariablesTestCheck mc) { - } - - public void testSwitchCase() { - - ArrayList lst = new ArrayList(0); - if (lst == null) { - return; - } - System.out.println(lst); - } - -} \ No newline at end of file diff --git a/src/test/files/UseCorrectForLoopCheck.java b/src/test/files/UseCorrectForLoopCheck.java deleted file mode 100644 index 350ed6eb..00000000 --- a/src/test/files/UseCorrectForLoopCheck.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package fr.greencodeinitiative.java.checks; - -import java.util.Arrays; -import java.util.List; - -class UseCorrectForLoopCheck { - UseCorrectForLoopCheck(UseCorrectForLoopCheck mc) { - } - - private final Integer[] intArray = new Integer[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - private final List intList = Arrays.asList(intArray); - - public void testForEachLoop() { - int dummy = 0; - for (Integer i : intArray) { // Noncompliant {{Avoid the use of Foreach with Arrays}} - dummy += i; - } - - for (Integer i : intList) { - dummy += i; - } - System.out.println(dummy); - } -} \ No newline at end of file diff --git a/src/test/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoopTest.java b/src/test/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoopTest.java deleted file mode 100644 index fc857883..00000000 --- a/src/test/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoopTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package fr.greencodeinitiative.java.checks; - -import org.junit.jupiter.api.Test; -import org.sonar.java.checks.verifier.CheckVerifier; - -@Deprecated -class AvoidConcatenateStringsInLoopTest { - - @Test - void checkNonCompliantTests() { - CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidConcatenateStringsInLoop.java") - .withCheck(new AvoidConcatenateStringsInLoop()) - .verifyIssues(); - } - - @Test - void checkCompliantTests() { - CheckVerifier.newVerifier() - .onFile("src/test/files/GoodWayConcatenateStringsLoop.java") - .withCheck(new AvoidConcatenateStringsInLoop()) - .verifyNoIssues(); - } - -} diff --git a/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheckCheckTest.java b/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheckCheckTest.java deleted file mode 100644 index 31e05b15..00000000 --- a/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheckCheckTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package fr.greencodeinitiative.java.checks; - -import org.junit.jupiter.api.Test; -import org.sonar.java.checks.verifier.CheckVerifier; - -@Deprecated -class AvoidUsingGlobalVariablesCheckCheckTest { - - @Test - void test() { - CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidUsingGlobalVariablesCheck.java") - .withCheck(new AvoidUsingGlobalVariablesCheck()) - .verifyIssues(); - } - -} diff --git a/src/test/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTest.java b/src/test/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTest.java deleted file mode 100644 index dda74370..00000000 --- a/src/test/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package fr.greencodeinitiative.java.checks; - -import org.junit.jupiter.api.Test; -import org.sonar.java.checks.verifier.CheckVerifier; - -@Deprecated -class UnnecessarilyAssignValuesToVariablesTest { - - @Test - void test() { - CheckVerifier.newVerifier() - .onFile("src/test/files/UnnecessarilyAssignValuesToVariablesTestCheck.java") - .withCheck(new UnnecessarilyAssignValuesToVariables()) - .verifyIssues(); - } - - @Test - void testIgnoredEmptyReturn() { - CheckVerifier.newVerifier() - .onFile("src/test/files/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java") - .withCheck(new UnnecessarilyAssignValuesToVariables()) - .verifyNoIssues(); - } - -} \ No newline at end of file diff --git a/src/test/java/fr/greencodeinitiative/java/checks/UseCorrectLoopCheckTest.java b/src/test/java/fr/greencodeinitiative/java/checks/UseCorrectLoopCheckTest.java deleted file mode 100644 index a853a6f5..00000000 --- a/src/test/java/fr/greencodeinitiative/java/checks/UseCorrectLoopCheckTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package fr.greencodeinitiative.java.checks; - -import org.junit.jupiter.api.Test; -import org.sonar.java.checks.verifier.CheckVerifier; - -@Deprecated -class UseCorrectLoopCheckTest { - - @Test - void test() { - CheckVerifier.newVerifier() - .onFile("src/test/files/UseCorrectForLoopCheck.java") - .withCheck(new UseCorrectForLoop()) - .verifyIssues(); - } - -} \ No newline at end of file From 00bb38f353283789a66bdd2a8a67f77f0f4eb26d Mon Sep 17 00:00:00 2001 From: alograg Date: Thu, 18 Jan 2024 11:28:46 +0100 Subject: [PATCH 029/233] refactor: :rewind: Following instructions in code review of PR GH-6 --- docker-compose.yml | 4 ++-- pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index bd446533..1782b705 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,8 +16,8 @@ services: SONAR_ES_BOOTSTRAP_CHECKS_DISABLE: 'true' volumes: - type: bind - source: ./target/ecocode-java-plugin-1.5.2-SNAPSHOT.jar - target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-1.5.2-SNAPSHOT.jar + source: ./target/ecocode-java-plugin-1.5.1-SNAPSHOT.jar + target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-1.5.1-SNAPSHOT.jar - "extensions:/opt/sonarqube/extensions" - "logs:/opt/sonarqube/logs" - "data:/opt/sonarqube/data" diff --git a/pom.xml b/pom.xml index dac51ea0..25a26bf6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.ecocode ecocode-java-plugin - 1.5.2-SNAPSHOT + 1.5.1-SNAPSHOT sonar-plugin From 9287e3c7563a1ea35b1372d56cea52be6390ffa9 Mon Sep 17 00:00:00 2001 From: alograg Date: Thu, 18 Jan 2024 16:11:00 +0100 Subject: [PATCH 030/233] fix: :white_check_mark: Test update with the changes in ecoCode rules --- .../java/JavaCheckRegistrarTest.java | 2 +- .../java/JavaRulesDefinitionTest.java | 31 +++---------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/src/test/java/fr/greencodeinitiative/java/JavaCheckRegistrarTest.java b/src/test/java/fr/greencodeinitiative/java/JavaCheckRegistrarTest.java index c38b4c09..02270ca5 100644 --- a/src/test/java/fr/greencodeinitiative/java/JavaCheckRegistrarTest.java +++ b/src/test/java/fr/greencodeinitiative/java/JavaCheckRegistrarTest.java @@ -31,7 +31,7 @@ void checkNumberRules() { final JavaCheckRegistrar registrar = new JavaCheckRegistrar(); registrar.register(context); - assertThat(context.checkClasses()).hasSize(19); + assertThat(context.checkClasses()).hasSize(15); assertThat(context.testCheckClasses()).isEmpty(); } diff --git a/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java b/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java index 2c655143..0c0b373c 100644 --- a/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java +++ b/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java @@ -38,38 +38,17 @@ class JavaRulesDefinitionTest { private RulesDefinition.Repository repository; private RulesDefinition.Context context; + private int rulesSize; + @BeforeEach void init() { - // TODO: Remove this check after Git repo split - /* - On an IDE (like IntelliJ), if the developer runs the unit tests without building/generating the Maven goals on the - "ecocode-rules-specifications" module before, the unit tests will not see the generated HTML descriptions (from ASCIIDOC files). - The developer must therefore configure his IDE to build the `ecocode-rules-specifications` module before launching the Tests. - - When the `java-plugin` submodule is in a specific Git repository, `ecocode-rules-specifications` will be fetched from a classic - external Maven dependency. There will therefore no longer be any need to perform this specific configuration. - */ - if (JavaRulesDefinition.class.getResource("/io/ecocode/rules/java/EC4.json") == null) { - String message = "'ecocode-rules-specification' resources corrupted. Please check build of 'ecocode-rules-specification' module"; - if (System.getProperties().keySet().stream().anyMatch(k -> k.toString().startsWith("idea."))) { - message += "\n\nOn 'IntelliJ IDEA':" + - "\n1. go to settings :" + - "\n > Build, Execution, Deployment > Build Tools > Maven > Runner" + - "\n2. check option:" + - "\n > Delegate IDE build/run actions to Maven" + - "\n3. Click on menu: " + - "\n > Build > Build Project" - ; - } - fail(message); - } - final SonarRuntime sonarRuntime = mock(SonarRuntime.class); doReturn(Version.create(0, 0)).when(sonarRuntime).getApiVersion(); JavaRulesDefinition rulesDefinition = new JavaRulesDefinition(sonarRuntime); RulesDefinition.Context context = new RulesDefinition.Context(); rulesDefinition.define(context); repository = context.repository(rulesDefinition.repositoryKey()); + rulesSize = 15; } @Test @@ -78,12 +57,12 @@ void testMetadata() { assertThat(repository.name()).isEqualTo("ecoCode"); assertThat(repository.language()).isEqualTo("java"); assertThat(repository.key()).isEqualTo("ecocode-java"); - assertThat(repository.rules()).hasSize(19); + assertThat(repository.rules()).hasSize(rulesSize); } @Test void testRegistredRules() { - assertThat(repository.rules()).hasSize(19); + assertThat(repository.rules()).hasSize(rulesSize); } @Test From 89b0be42261e06092af4955c391184bdab284204 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 19 Jan 2024 11:44:35 +0100 Subject: [PATCH 031/233] delete unsed script for building --- tool_build.sh | 3 --- 1 file changed, 3 deletions(-) delete mode 100755 tool_build.sh diff --git a/tool_build.sh b/tool_build.sh deleted file mode 100755 index bfac031a..00000000 --- a/tool_build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env sh - -mvn clean package -DskipTests From 8f44fb028c413bc82a69d18b587e56b80c3dddd2 Mon Sep 17 00:00:00 2001 From: alograg Date: Fri, 19 Jan 2024 11:46:44 +0100 Subject: [PATCH 032/233] docs: :memo: Documentation of changes --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e20803f..26e18bff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Deleted +- Remove depreciated rules EC4, EC53, EC63 and EC75 + ## [1.5.0] - 2024-01-06 ### Added From 2a1a8be7f8e808509156df3726afd2eb18387006 Mon Sep 17 00:00:00 2001 From: alograg Date: Fri, 19 Jan 2024 12:38:22 +0100 Subject: [PATCH 033/233] fix: :bookmark: Version assigned according to pull request comment --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 25a26bf6..06248ead 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ 1.7 - 1.4.6 + 1.5.0-SNAPSHOT From a0e7ab7cad0742825ca5bbe8c1646ee6dc247f3b Mon Sep 17 00:00:00 2001 From: alograg Date: Fri, 19 Jan 2024 12:39:06 +0100 Subject: [PATCH 034/233] fix: :memo: Documentation of changes --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26e18bff..f08d7fd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Deleted -- Remove depreciated rules EC4, EC53, EC63 and EC75 +- Remove deprecated java rules ## [1.5.0] - 2024-01-06 From c07d9bfd41ed2eb85075df609166a3a5d5888b97 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 19 Jan 2024 11:44:35 +0100 Subject: [PATCH 035/233] delete unsed script for building --- tool_build.sh | 3 --- 1 file changed, 3 deletions(-) delete mode 100755 tool_build.sh diff --git a/tool_build.sh b/tool_build.sh deleted file mode 100755 index bfac031a..00000000 --- a/tool_build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env sh - -mvn clean package -DskipTests From f276d965b35074f5898251f8e70b4b4d0290c482 Mon Sep 17 00:00:00 2001 From: alograg Date: Fri, 19 Jan 2024 12:56:29 +0100 Subject: [PATCH 036/233] docs: :memo: Documentation of changes --- CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..8ca04542 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,17 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Added + +### Changed + +- Rules elimination test for [Remove deprecated rules EC4, EC53, EC63 and EC75 for JAVA](https://github.com/green-code-initiative/ecoCode/pull/272) + +### Deleted + From d9cfbd2f2741e928f3263cd5eac14a93d70f7d87 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Mon, 22 Jan 2024 19:23:48 +0100 Subject: [PATCH 037/233] EC2 rule : correction NullPointer with interface (no Issue) --- ...ltipleIfElseStatementInterfaceNoIssue.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java new file mode 100644 index 00000000..43dd875a --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java @@ -0,0 +1,24 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.greencodeinitiative.java.checks; + +interface AvoidMultipleIfElseStatementCheck { + + TransactionMetaData initMetaData(ITransactionFoundation transactionFoundation) throws ProgramException, MnemonicTemplateShellException; + +} From 5112e17217694743298a08236b3757c64841ad67 Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 24 Jan 2024 17:26:58 +0100 Subject: [PATCH 038/233] Update pom.xml Remove snapshot from version od EcoCode --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ef113352..8af9cbf8 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ 1.7 - 1.5.0-SNAPSHOT + 1.5.0 From c57f877c88f64631d6fd63ec255e6ba88914bfe7 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 25 Jan 2024 21:54:02 +0100 Subject: [PATCH 039/233] add new use case from ISSUE 9 of ecoCode-java repository --- ...MultipleIfElseStatementNoBlockNoIssue.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java new file mode 100644 index 00000000..b33c3a42 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java @@ -0,0 +1,27 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.greencodeinitiative.java.checks; + +class AvoidMultipleIfElseStatementNotBlock { + + public boolean equals(Object obj) { + if (this == obj) + return true; + } + +} From 2d9b91000e5a79b3b7b59c2b519ede4f240a5717 Mon Sep 17 00:00:00 2001 From: alograg Date: Fri, 2 Feb 2024 15:09:28 +0100 Subject: [PATCH 040/233] fix: :memo: Version et changes correction --- CHANGELOG.md | 2 +- docker-compose.yml | 4 ++-- pom.xml | 6 +++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b176df52..11f3b020 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Deleted -- Remove deprecated java rules +- Deprecated java rules EC4, EC53, EC63 and EC75 ## [1.5.0] - 2024-01-06 diff --git a/docker-compose.yml b/docker-compose.yml index 1782b705..bf8e84b6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,8 +16,8 @@ services: SONAR_ES_BOOTSTRAP_CHECKS_DISABLE: 'true' volumes: - type: bind - source: ./target/ecocode-java-plugin-1.5.1-SNAPSHOT.jar - target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-1.5.1-SNAPSHOT.jar + source: ./target/ecocode-java-plugin-1.6.0-SNAPSHOT.jar + target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-1.6.0-SNAPSHOT.jar - "extensions:/opt/sonarqube/extensions" - "logs:/opt/sonarqube/logs" - "data:/opt/sonarqube/data" diff --git a/pom.xml b/pom.xml index 8af9cbf8..1845604a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.ecocode ecocode-java-plugin - 1.5.2-SNAPSHOT + 1.6.0-SNAPSHOT sonar-plugin @@ -67,7 +67,11 @@ 1.7 +<<<<<<< HEAD 1.5.0 +======= + 1.6.0-SNAPSHOT +>>>>>>> 603fbcd (fix: :memo: Version et changes correction) From 8d25c52744a14692152be8a99f51485157a7abc8 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 2 Feb 2024 16:36:36 +0100 Subject: [PATCH 041/233] delete test files because of PR #6 on ecoCode-java repo (deletion of deprecated java rules EC4, EC53, EC63 and EC75) --- CHANGELOG.md | 17 ---- .../checks/AvoidConcatenateStringsInLoop.java | 32 -------- .../AvoidUsingGlobalVariablesCheck.java | 21 ----- ...arilyAssignValuesToVariablesTestCheck.java | 78 ------------------- ...esToVariablesTestCheckWithEmptyReturn.java | 18 ----- .../java/checks/UseCorrectForLoopCheck.java | 24 ------ 6 files changed, 190 deletions(-) delete mode 100644 CHANGELOG.md delete mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java delete mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java delete mode 100644 src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheck.java delete mode 100644 src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java delete mode 100644 src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoopCheck.java diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 8ca04542..00000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,17 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [Unreleased] - -### Added - -### Changed - -- Rules elimination test for [Remove deprecated rules EC4, EC53, EC63 and EC75 for JAVA](https://github.com/green-code-initiative/ecoCode/pull/272) - -### Deleted - diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java deleted file mode 100644 index c5079ebe..00000000 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java +++ /dev/null @@ -1,32 +0,0 @@ -package fr.greencodeinitiative.java.checks; - -public class AvoidConcatenateStringsInLoop { - - public String concatenateStrings(String[] strings) { - String result1 = ""; - - for (String string : strings) { - result1 += string; // Noncompliant {{Don't concatenate Strings in loop, use StringBuilder instead.}} - } - return result1; - } - - public String concatenateStrings2() { - String result2 = ""; - - for (int i = 0; i < 1000; ++i) { - result2 += "another"; // Noncompliant {{Don't concatenate Strings in loop, use StringBuilder instead.}} - } - return result2; - } - - public String concatenateStrings3() { - String result3 = ""; - - for (int i = 0; i < 1000; ++i) { - result3 = result3 + "another"; // Noncompliant {{Don't concatenate Strings in loop, use StringBuilder instead.}} - } - return result3; - } - -} diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java deleted file mode 100644 index 3dea9e35..00000000 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java +++ /dev/null @@ -1,21 +0,0 @@ -package fr.greencodeinitiative.java.checks; - -public class AvoidUsingGlobalVariablesCheck { - public static double price = 15.24; // Noncompliant {{Avoid using global variables}} - public static long pages = 1053; // Noncompliant {{Avoid using global variables}} - - public static void main(String[] args) { - double newPrice = AvoidUsingGlobalVariablesCheck.price; - long newPages = AvoidUsingGlobalVariablesCheck.pages; - System.out.println(newPrice); - System.out.println(newPages); - } - static{ // Noncompliant {{Avoid using global variables}} - int a = 4; - } - - public void printingA() { - System.out.println("a"); - } - -} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheck.java deleted file mode 100644 index b61a58ec..00000000 --- a/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheck.java +++ /dev/null @@ -1,78 +0,0 @@ -package fr.greencodeinitiative.java.checks; - -class UnnecessarilyAssignValuesToVariablesTestCheck { - UnnecessarilyAssignValuesToVariablesTestCheck(UnnecessarilyAssignValuesToVariablesTestCheck mc) { - } - - public int testSwitchCase() throws Exception { - int variableFor = 5; - int variableIf = 5; - int variableWhile = 5; - int variableExp = 5; - int variableReturn = 5; - int variableCLass = 5; - int[] intArray = {10, 20, 30, 40, 50}; - - Exception variableException = new Exception("message"); - int variableNotUse = 5; // Noncompliant {{The variable is declared but not really used}} - - - variableNotUse = 10; - for (variableFor = 0; variableFor < 5; ++variableFor) { - System.out.println(variableFor); - } - - for (int ia : intArray) { - System.out.println((char) ia); - } - - if (variableIf > 10) { - System.out.println(variableIf); - } - - while (variableWhile > 10) { - System.out.println(variableWhile); - } - - variableExp += 1; - variableNotUse = variableExp; - TestClass testClass = new TestClass(variableCLass); - if (testClass.isTrue()) { - throw variableException; - } - return variableReturn; - } - - private class TestClass { - TestClass(int i) { - ++i; - } - - public boolean isTrue() { - return true; - } - } - - - private int getIntValue() { - return 3; - } - - public int testNonCompliantReturn() { - int i = getIntValue(); // Noncompliant {{Immediately return this expression instead of assigning it to the temporary variable}} - return i; - } - - public int testCompliantReturn() { - return getIntValue(); - } - - public void testNonCompliantThrow() throws Exception { - Exception exception = new Exception("dummy"); // Noncompliant {{Immediately throw this expression instead of assigning it to the temporary variable}} - throw exception; - } - - public void testCompliantThrow() throws Exception { - throw new Exception("dummy"); - } -} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java b/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java deleted file mode 100644 index 4dbb952c..00000000 --- a/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java +++ /dev/null @@ -1,18 +0,0 @@ -package fr.greencodeinitiative.java.checks; - -import java.util.ArrayList; - -class UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn { - UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn(UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn mc) { - } - - public void testSwitchCase() { - - ArrayList lst = new ArrayList(0); - if (lst == null) { - return; - } - System.out.println(lst); - } - -} \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoopCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoopCheck.java deleted file mode 100644 index fe5ee97c..00000000 --- a/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoopCheck.java +++ /dev/null @@ -1,24 +0,0 @@ -package fr.greencodeinitiative.java.checks; - -import java.util.Arrays; -import java.util.List; - -class UseCorrectForLoopCheck { - UseCorrectForLoopCheck(UseCorrectForLoopCheck mc) { - } - - private final Integer[] intArray = new Integer[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - private final List intList = Arrays.asList(intArray); - - public void testForEachLoop() { - int dummy = 0; - for (Integer i : intArray) { - dummy += i; - } // Noncompliant {{Avoid the use of Foreach with Arrays}} - - for (Integer i : intList) { - dummy += i; - } - System.out.println(dummy); - } -} \ No newline at end of file From 9711e05b12cb98246b9cd4fb6b79624bfd5db751 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 2 Feb 2024 16:47:43 +0100 Subject: [PATCH 042/233] update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f39156e1..eb8b0ab5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Deleted -- Deprecated java rules EC4, EC53, EC63 and EC75 +- [#6](https://github.com/green-code-initiative/ecoCode-java/pull/6) Delete deprecated java rules EC4, EC53, EC63 and EC75 ## [1.5.2] - 2024-01-23 From 9154e78b14b810405ee413ed3dbdefb4e8fb5301 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 2 Feb 2024 23:36:52 +0100 Subject: [PATCH 043/233] prepare next release 1.6.0 --- CHANGELOG.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb8b0ab5..3b5501d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,12 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- [#12](https://github.com/green-code-initiative/ecoCode-java/issues/12) Add support for SonarQube 10.4 "DownloadOnlyWhenRequired" feature - ### Changed ### Deleted +## [1.6.0] - 2024-02-02 + +### Added + +- [#12](https://github.com/green-code-initiative/ecoCode-java/issues/12) Add support for SonarQube 10.4 "DownloadOnlyWhenRequired" feature + +### Deleted + - [#6](https://github.com/green-code-initiative/ecoCode-java/pull/6) Delete deprecated java rules EC4, EC53, EC63 and EC75 ## [1.5.2] - 2024-01-23 @@ -40,7 +46,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Update ecocode-rules-specifications to 1.4.6 -[unreleased](https://github.com/green-code-initiative/ecoCode-java/compare/1.5.2...HEAD) +[unreleased](https://github.com/green-code-initiative/ecoCode-java/compare/1.6.0...HEAD) +[1.6.0](https://github.com/green-code-initiative/ecoCode-java/compare/1.5.2...1.6.0) [1.5.2](https://github.com/green-code-initiative/ecoCode-java/compare/1.5.1...1.5.2) [1.5.1](https://github.com/green-code-initiative/ecoCode-java/compare/1.5.0...1.5.1) [1.5.0](https://github.com/green-code-initiative/ecoCode-java/releases/tag/1.5.0) From 3ec379a1aaa3f302e3c5d14a1f44c9cd6646fc26 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 2 Feb 2024 23:37:51 +0100 Subject: [PATCH 044/233] [maven-release-plugin] prepare release 1.6.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 54cc1333..718e7556 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.ecocode ecocode-java-plugin - 1.6.0-SNAPSHOT + 1.6.0 sonar-plugin @@ -30,7 +30,7 @@ scm:git:https://github.com/green-code-initiative/ecocode-java scm:git:https://github.com/green-code-initiative/ecocode-java https://github.com/green-code-initiative/ecocode-java - HEAD + 1.6.0 From 76d4e804f597aa9d47ccdd2b1fb9303ccf826440 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 2 Feb 2024 23:37:51 +0100 Subject: [PATCH 045/233] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 718e7556..0c711d4a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.ecocode ecocode-java-plugin - 1.6.0 + 1.6.1-SNAPSHOT sonar-plugin @@ -30,7 +30,7 @@ scm:git:https://github.com/green-code-initiative/ecocode-java scm:git:https://github.com/green-code-initiative/ecocode-java https://github.com/green-code-initiative/ecocode-java - 1.6.0 + HEAD From 0caee622fa835121b666fa5fa800c42bedae8951 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 2 Feb 2024 23:42:59 +0100 Subject: [PATCH 046/233] update docker-compose for next snapshot --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index bf8e84b6..4055484d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,8 +16,8 @@ services: SONAR_ES_BOOTSTRAP_CHECKS_DISABLE: 'true' volumes: - type: bind - source: ./target/ecocode-java-plugin-1.6.0-SNAPSHOT.jar - target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-1.6.0-SNAPSHOT.jar + source: ./target/ecocode-java-plugin-1.6.1-SNAPSHOT.jar + target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-1.6.1-SNAPSHOT.jar - "extensions:/opt/sonarqube/extensions" - "logs:/opt/sonarqube/logs" - "data:/opt/sonarqube/data" From 8e3bbb23c6a16f3be6b32509533b029b5b49c772 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 6 Feb 2024 22:10:20 +0100 Subject: [PATCH 047/233] [ISSUE 15] correction NullPointer in EC2 --- .../checks/AvoidMultipleIfElseStatement.java | 4 +- ...dMultipleIfElseStatementCompareMethod.java | 54 +++++++++++++++++++ .../AvoidMultipleIfElseStatementTest.java | 8 +++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/test/files/AvoidMultipleIfElseStatementCompareMethod.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java index 70c6c5e5..4dc77baa 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java @@ -305,7 +305,9 @@ private Integer internalGetVariableUsageOfNearestParent(Map= 0 && nbParentUsed == null; i--) { Map variablesParentLevelMap = pDataMap.get(i); - nbParentUsed = variablesParentLevelMap.get(variableName); + if (variablesParentLevelMap != null) { + nbParentUsed = variablesParentLevelMap.get(variableName); + } } return nbParentUsed; diff --git a/src/test/files/AvoidMultipleIfElseStatementCompareMethod.java b/src/test/files/AvoidMultipleIfElseStatementCompareMethod.java new file mode 100644 index 00000000..7c527516 --- /dev/null +++ b/src/test/files/AvoidMultipleIfElseStatementCompareMethod.java @@ -0,0 +1,54 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.greencodeinitiative.java.checks; + +class AvoidMultipleIfElseStatementCompareMethod { + + public int compare(FieldVo o1, FieldVo o2) { + + if (o1.getIdBlock().equals(o2.getIdBlock())) { + if (o1.getIdField().equals(o2.getIdField())) { + return 0; + } + // First original + if (o1.isOriginal() && !o2.isOriginal()) { + return -1; + } else if (!o1.isOriginal() && o2.isOriginal()) { + return 1; + } + // First min posgafld + Long result = o1.getColumnPos() - o2.getColumnPos(); + if (result != 0) { + return result.intValue(); + } + + // First min ordgaflc + result = o1.getIndex() - o2.getIndex(); + return result.intValue(); + } + // First BQRY block + if (o1.getIdBlock().startsWith("BQRY") && !o2.getIdBlock().startsWith("BQRY")) { + return -1; + } else if (!o1.getIdBlock().startsWith("BQRY") && o2.getIdBlock().startsWith("BQRY")) { + return 1; + } + // If both block don't start with BQRY, sort alpha with String.compareTo method + return o1.getIdBlock().compareTo(o2.getIdBlock()); + } + +} \ No newline at end of file diff --git a/src/test/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java b/src/test/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java index f3f8ecdb..2cf8869e 100644 --- a/src/test/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java +++ b/src/test/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java @@ -49,5 +49,13 @@ void testNotBlockStatement() { .verifyNoIssues(); } + @Test + void testCompareMethod() { + CheckVerifier.newVerifier() + .onFile("src/test/files/AvoidMultipleIfElseStatementCompareMethod.java") + .withCheck(new AvoidMultipleIfElseStatement()) + .verifyNoIssues(); + } + } From c9d40f187b03ecf0ae8df8ee0036a57d4976f33d Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 6 Feb 2024 22:16:13 +0100 Subject: [PATCH 048/233] [ISSUE 15] correction NullPointer in EC2 --- ...leIfElseStatementCompareMethodNoIssue.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java new file mode 100644 index 00000000..0a361545 --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java @@ -0,0 +1,37 @@ +package fr.greencodeinitiative.java.checks; + +class AvoidMultipleIfElseStatementCheck { + + public int compare(FieldVo o1, FieldVo o2) { + + if (o1.getIdBlock().equals(o2.getIdBlock())) { + if (o1.getIdField().equals(o2.getIdField())) { + return 0; + } + // First original + if (o1.isOriginal() && !o2.isOriginal()) { + return -1; + } else if (!o1.isOriginal() && o2.isOriginal()) { + return 1; + } + // First min posgafld + Long result = o1.getColumnPos() - o2.getColumnPos(); + if (result != 0) { + return result.intValue(); + } + + // First min ordgaflc + result = o1.getIndex() - o2.getIndex(); + return result.intValue(); + } + // First BQRY block + if (o1.getIdBlock().startsWith("BQRY") && !o2.getIdBlock().startsWith("BQRY")) { + return -1; + } else if (!o1.getIdBlock().startsWith("BQRY") && o2.getIdBlock().startsWith("BQRY")) { + return 1; + } + // If both block don't start with BQRY, sort alpha with String.compareTo method + return o1.getIdBlock().compareTo(o2.getIdBlock()); + } + +} From 7f6e0c4f9a3e111a242e21f6010ba9ce95812cfa Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 6 Feb 2024 22:22:11 +0100 Subject: [PATCH 049/233] [ISSUE 15] correction NullPointer in EC2 - CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b5501d3..db9acefc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- [#15](https://github.com/green-code-initiative/ecoCode-java/issues/15) correction NullPointer in EC2 rule + ### Deleted ## [1.6.0] - 2024-02-02 From 30c1271e6559211d5d221d83a31ffce53dab0552 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Sun, 17 Mar 2024 15:48:03 +0100 Subject: [PATCH 050/233] Add java rule EC80 : Optimize Database SQL Queries (Clause LIMIT) (#18) --- .../checks/OptimizeSQLQueriesWithLimit.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java new file mode 100644 index 00000000..63ede82e --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java @@ -0,0 +1,18 @@ +class OptimizeSQLQueriesWithLimit { + + public void literalSQLrequest() { + dummyCall("SELECT user FROM myTable"); // Noncompliant {{Optimize Database SQL Queries (Clause LIMIT)}} + dummyCall("SELECT user FROM myTable LIMIT 50"); // Compliant + } + + @Query("select t from Todo t where t.status != 'COMPLETED'") // Noncompliant {{Optimize Database SQL Queries (Clause LIMIT)}} + @Query("select t from Todo t where t.status != 'COMPLETED' LIMIT 25") // Compliant + + private void callQuery() { + String sql1 = "SELECT user FROM myTable"; // Noncompliant {{Optimize Database SQL Queries (Clause LIMIT)}} + String sql2 = "SELECT user FROM myTable LIMIT 50"; // Compliant + } + + private void dummyCall(String request) { + } +} \ No newline at end of file From dfd01558226934b8ae8ef23cbb1ea646dd60c552 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Mon, 29 Apr 2024 23:32:49 +0200 Subject: [PATCH 051/233] update to 1.5.1 of rules referentiel --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0c711d4a..1d596240 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ 1.7 - 1.5.0 + 1.5.1 From 16ac47bc8c7a9c65c6d834ba1de2061b67399162 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Wed, 15 May 2024 22:05:38 +0200 Subject: [PATCH 052/233] compatibility SonarQube 10.5.1 : check ok + updagre docker files + upgrade README.md + upgrade CHANGELOG.md --- CHANGELOG.md | 1 + Dockerfile | 2 +- README.md | 6 +++--- docker-compose.yml | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db9acefc..f55217d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - [#15](https://github.com/green-code-initiative/ecoCode-java/issues/15) correction NullPointer in EC2 rule +- check Sonarqube 10.5.1 compatibility + update docker files and README.md ### Deleted diff --git a/Dockerfile b/Dockerfile index 2b336220..a5a0fc78 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,5 +5,5 @@ COPY . /usr/src/ecocode WORKDIR /usr/src/ecocode RUN ./tool_build.sh -FROM sonarqube:10.3.0-community +FROM sonarqube:10.5.1-community COPY --from=builder /usr/src/ecocode/target/ecocode-*.jar /opt/sonarqube/extensions/plugins/ diff --git a/README.md b/README.md index 0a0d9226..7fab3c06 100644 --- a/README.md +++ b/README.md @@ -63,9 +63,9 @@ Ready to use binaries are available [from GitHub](https://github.com/green-code- 🧩 Compatibility ----------------- -| Plugin version | SonarQube version | Java version | -|----------------|-------------------|--------------| -| 1.5.+ | 9.4.+ LTS to 10.3 | 11 / 17 | +| Plugin version | SonarQube version | Java version | +|----------------|---------------------|--------------| +| 1.5.+ | 9.4.+ LTS to 10.5.1 | 11 / 17 | > 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). diff --git a/docker-compose.yml b/docker-compose.yml index 4055484d..cc1bbc24 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: "3.3" services: sonar: - image: sonarqube:10.3.0-community + image: sonarqube:10.5.1-community container_name: sonar_ecocode_java ports: - "9000:9000" From 4b547eab7f0b50389f5d66e2b7d9f370140289cd Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Wed, 15 May 2024 23:30:03 +0200 Subject: [PATCH 053/233] correction SonarCloud warnings --- .../fr/greencodeinitiative/java/JavaRulesDefinitionTest.java | 2 -- .../java/checks/AvoidGettingSizeCollectionInLoopTest.java | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java b/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java index 0c0b373c..ad1b5367 100644 --- a/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java +++ b/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java @@ -29,14 +29,12 @@ import org.sonar.api.utils.Version; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; class JavaRulesDefinitionTest { private RulesDefinition.Repository repository; - private RulesDefinition.Context context; private int rulesSize; diff --git a/src/test/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java b/src/test/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java index 8083c1db..c9576927 100644 --- a/src/test/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java +++ b/src/test/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java @@ -22,7 +22,7 @@ class AvoidGettingSizeCollectionInLoopTest { @Test - public void testBadForLoop() { + void testBadForLoop() { CheckVerifier.newVerifier() .onFile("src/test/files/AvoidGettingSizeCollectionInForLoopBad.java") .withCheck(new AvoidGettingSizeCollectionInLoop()) From a8c44d753554f82b8061f726872ae37973b9648b Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Wed, 15 May 2024 23:38:00 +0200 Subject: [PATCH 054/233] prepare 1.6.1 : update CHANGELOG --- CHANGELOG.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f55217d8..1ce62a86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,11 +11,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +### Deleted + +## [1.6.1] - 2024-05-15 + +### Changed + - [#15](https://github.com/green-code-initiative/ecoCode-java/issues/15) correction NullPointer in EC2 rule - check Sonarqube 10.5.1 compatibility + update docker files and README.md -### Deleted - ## [1.6.0] - 2024-02-02 ### Added @@ -49,7 +53,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Update ecocode-rules-specifications to 1.4.6 -[unreleased](https://github.com/green-code-initiative/ecoCode-java/compare/1.6.0...HEAD) +[unreleased](https://github.com/green-code-initiative/ecoCode-java/compare/1.6.1...HEAD) +[1.6.1](https://github.com/green-code-initiative/ecoCode-java/compare/1.6.0...1.6.1) [1.6.0](https://github.com/green-code-initiative/ecoCode-java/compare/1.5.2...1.6.0) [1.5.2](https://github.com/green-code-initiative/ecoCode-java/compare/1.5.1...1.5.2) [1.5.1](https://github.com/green-code-initiative/ecoCode-java/compare/1.5.0...1.5.1) From e6e9bb4fcbabec2f682bae167e7e502f0c4043a7 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Wed, 15 May 2024 23:38:26 +0200 Subject: [PATCH 055/233] [maven-release-plugin] prepare release 1.6.1 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 1d596240..88e49f71 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.ecocode ecocode-java-plugin - 1.6.1-SNAPSHOT + 1.6.1 sonar-plugin @@ -30,7 +30,7 @@ scm:git:https://github.com/green-code-initiative/ecocode-java scm:git:https://github.com/green-code-initiative/ecocode-java https://github.com/green-code-initiative/ecocode-java - HEAD + 1.6.1 From 1c0ae44893319051f95aa0192f63ffe33ad648e1 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Wed, 15 May 2024 23:38:26 +0200 Subject: [PATCH 056/233] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 88e49f71..fa0c7e93 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.ecocode ecocode-java-plugin - 1.6.1 + 1.6.2-SNAPSHOT sonar-plugin @@ -30,7 +30,7 @@ scm:git:https://github.com/green-code-initiative/ecocode-java scm:git:https://github.com/green-code-initiative/ecocode-java https://github.com/green-code-initiative/ecocode-java - 1.6.1 + HEAD From 716fe9ba75246cc51a24c33d15ed49adfc913367 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Wed, 15 May 2024 23:43:19 +0200 Subject: [PATCH 057/233] update docker-compose for new version --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index cc1bbc24..ee7dc875 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,8 +16,8 @@ services: SONAR_ES_BOOTSTRAP_CHECKS_DISABLE: 'true' volumes: - type: bind - source: ./target/ecocode-java-plugin-1.6.1-SNAPSHOT.jar - target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-1.6.1-SNAPSHOT.jar + source: ./target/ecocode-java-plugin-1.6.2-SNAPSHOT.jar + target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-1.6.2-SNAPSHOT.jar - "extensions:/opt/sonarqube/extensions" - "logs:/opt/sonarqube/logs" - "data:/opt/sonarqube/data" From ee0836c0fb67e94ec6b0e198d44bdc4379b2446c Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Wed, 29 May 2024 18:46:12 +0200 Subject: [PATCH 058/233] correction of code to be buildable to make an analysis to Sonar --- pom.xml | 6 +- .../java/checks/ArrayCopyCheck.java | 2 +- .../checks/AvoidMultipleIfElseStatement.java | 2 +- ...leIfElseStatementCompareMethodNoIssue.java | 35 +++++++++++- ...ltipleIfElseStatementInterfaceNoIssue.java | 4 +- ...MultipleIfElseStatementNoBlockNoIssue.java | 3 +- .../AvoidMultipleIfElseStatementNoIssue.java | 2 +- ...voidSpringRepositoryCallInStreamCheck.java | 56 +++++++------------ .../checks/OptimizeSQLQueriesWithLimit.java | 12 ++++ tool_send_to_sonar.sh | 2 +- 10 files changed, 79 insertions(+), 45 deletions(-) diff --git a/pom.xml b/pom.xml index 8bf9a4d7..c059b1fd 100644 --- a/pom.xml +++ b/pom.xml @@ -10,10 +10,12 @@ ecoCode Java Sonar Plugin Test Project - 11 + 17 ${java.version} ${java.version} + target + UTF-8 ${encoding} ${encoding} @@ -23,7 +25,7 @@ org.springframework.data spring-data-jpa - 2.7.8 + 3.3.0 org.springframework diff --git a/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java index b748dd29..1f93de18 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java @@ -1,6 +1,6 @@ import java.util.Arrays; -class TestClass { +class ArrayCopyCheck { public void copyArrayOK() { final int len = 5; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java index 0ce74dcb..329342a2 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java @@ -1,6 +1,6 @@ package fr.greencodeinitiative.java.checks; -class AvoidMultipleIfElseStatementCheck { +class AvoidMultipleIfElseStatement { // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java index 0a361545..573cdc9e 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java @@ -1,6 +1,6 @@ package fr.greencodeinitiative.java.checks; -class AvoidMultipleIfElseStatementCheck { +class AvoidMultipleIfElseStatementCompareMethodNoIssue { public int compare(FieldVo o1, FieldVo o2) { @@ -34,4 +34,37 @@ public int compare(FieldVo o1, FieldVo o2) { return o1.getIdBlock().compareTo(o2.getIdBlock()); } + public static class FieldVo { + + private String idBlock; + + private String idField; + + private boolean original; + + private long columnPos; + + private long index; + + public String getIdBlock() { + return idBlock; + } + + public String getIdField() { + return idField; + } + + public boolean isOriginal() { + return original; + } + + public long getColumnPos() { + return columnPos; + } + + public long getIndex() { + return index; + } + } + } diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java index 43dd875a..1409a4e2 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java @@ -17,8 +17,8 @@ */ package fr.greencodeinitiative.java.checks; -interface AvoidMultipleIfElseStatementCheck { +interface AvoidMultipleIfElseStatementInterfaceNoIssue { - TransactionMetaData initMetaData(ITransactionFoundation transactionFoundation) throws ProgramException, MnemonicTemplateShellException; + Object initMetaData(Object transactionFoundation) throws IllegalAccessException; } diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java index b33c3a42..d66bfed1 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java @@ -17,11 +17,12 @@ */ package fr.greencodeinitiative.java.checks; -class AvoidMultipleIfElseStatementNotBlock { +class AvoidMultipleIfElseStatementNoBlockNoIssue { public boolean equals(Object obj) { if (this == obj) return true; + return false; } } diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java index fc7c8f79..f4260daa 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java @@ -1,6 +1,6 @@ package fr.greencodeinitiative.java.checks; -class AvoidMultipleIfElseStatementCheckNoIssue { +class AvoidMultipleIfElseStatementNoIssue { // inital RULES : please see HTML description file of this rule (resources directory) diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java index 636e55e2..38fa0103 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java @@ -22,7 +22,6 @@ import java.util.*; import java.util.stream.Collectors; -import java.util.stream.IntStream; import java.util.stream.Stream; public class AvoidSpringRepositoryCallInStreamCheck { @@ -30,69 +29,58 @@ public class AvoidSpringRepositoryCallInStreamCheck { @Autowired private EmployeeRepository employeeRepository; - public void smellGetAllEmployeesByIdsForEach() { + public List smellGetAllEmployeesByIdsForEach() { List employees = new ArrayList<>(); Stream stream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); stream.forEach(id -> { Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop or stream}} - if (employee.isPresent()) { - employees.add(employee.get()); - } + employee.ifPresent(employees::add); }); + return employees; } - public void smellGetAllEmployeesByIdsForEachOrdered() { + public List smellGetAllEmployeesByIdsForEachOrdered() { List employees = new ArrayList<>(); Stream stream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); stream.forEachOrdered(id -> { Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop or stream}} - if (employee.isPresent()) { - employees.add(employee.get()); - } + employee.ifPresent(employees::add); }); + return employees; } - public List smellGetAllEmployeesByIdsMap() { + public List> smellGetAllEmployeesByIdsMap() { List employees = new ArrayList<>(); Stream stream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); return stream.map(id -> { Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop or stream}} - if (employee.isPresent()) { - employees.add(employee.get()); - } + employee.ifPresent(employees::add); + return employees; }) .collect(Collectors.toList()); } - public List smellGetAllEmployeesByIdsPeek() { - List employees = new ArrayList<>(); + public List smellGetAllEmployeesByIdsPeek() { Stream stream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); return stream.peek(id -> { Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop or stream}} - if (employee.isPresent()) { - employees.add(employee.get()); - } }) .collect(Collectors.toList()); } public List smellGetAllEmployeesByIdsWithOptional(List ids) { - List employees = new ArrayList<>(); return ids .stream() .map(element -> { - Employee empl = new Employee(); - employees.add(empl); - return employeeRepository.findById(element).orElse(empl);// Noncompliant {{Avoid Spring repository call in loop or stream}} + Employee employ = new Employee(1, "name"); + return employeeRepository.findById(element).orElse(employ);// Noncompliant {{Avoid Spring repository call in loop or stream}} }) .collect(Collectors.toList()); } - public List smellGetAllEmployeesByIds(List ids) { + public List> smellGetAllEmployeesByIds(List ids) { Stream stream = ids.stream(); return stream.map(element -> { - Employee empl = new Employee(); - employees.add(empl); return employeeRepository.findById(element);// Noncompliant {{Avoid Spring repository call in loop or stream}} }) .collect(Collectors.toList()); @@ -102,12 +90,10 @@ public List smellGetAllEmployeesByIdsWithoutStream(List ids) return employeeRepository.findAllById(ids); // Compliant } - public List smellDeleteEmployeeById(List ids) { + public List> smellDeleteEmployeeById(List ids) { Stream stream = ids.stream(); - return stream.map(element -> { - Employee empl = new Employee(); - employees.add(empl); - return employeeRepository.deleteById(element);// Noncompliant {{Avoid Spring repository call in loop or stream}} + return stream.map(id -> { + return employeeRepository.findById(id);// Noncompliant {{Avoid Spring repository call in loop or stream}} }) .collect(Collectors.toList()); } @@ -115,15 +101,15 @@ public List smellDeleteEmployeeById(List ids) { public List smellGetAllEmployeesByIdsWithSeveralMethods(List ids) { Stream stream = ids.stream(); return stream.map(element -> { - Employee empl = new Employee(); - return employeeRepository.findById(element).orElse(empl).anotherMethod().anotherOne();// Noncompliant {{Avoid Spring repository call in loop or stream}} + Employee empl = new Employee(1, "name"); + return employeeRepository.findById(element).orElse(empl);// Noncompliant {{Avoid Spring repository call in loop or stream}} }) .collect(Collectors.toList()); } - public class Employee { - private Integer id; - private String name; + public static class Employee { + private final Integer id; + private final String name; public Employee(Integer id, String name) { this.id = id; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java index 63ede82e..52c912f8 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java @@ -1,3 +1,8 @@ +import org.springframework.data.jpa.repository.Query; + +import java.util.ArrayList; +import java.util.List; + class OptimizeSQLQueriesWithLimit { public void literalSQLrequest() { @@ -6,7 +11,14 @@ public void literalSQLrequest() { } @Query("select t from Todo t where t.status != 'COMPLETED'") // Noncompliant {{Optimize Database SQL Queries (Clause LIMIT)}} + public List findAllUsers() { + return new ArrayList<>(); + } + @Query("select t from Todo t where t.status != 'COMPLETED' LIMIT 25") // Compliant + public List findFirstUsers() { + return new ArrayList<>(); + } private void callQuery() { String sql1 = "SELECT user FROM myTable"; // Noncompliant {{Optimize Database SQL Queries (Clause LIMIT)}} diff --git a/tool_send_to_sonar.sh b/tool_send_to_sonar.sh index 6a658d71..21470842 100755 --- a/tool_send_to_sonar.sh +++ b/tool_send_to_sonar.sh @@ -2,7 +2,7 @@ # "sonar.token" variable (or sonar.login before SONARQUBE 9.9) : private TOKEN generated in your local SonarQube during installation # (input paramater of this script) -mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.token=$1 +mvn clean org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.token=$1 # mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.token=$1 -Dsonar.host.url=https://sonar-staging.gcp.cicd.solocal.com/ # command if you have a SONARQUBE < 9.9 (sonar.token existing for SONARQUBE >= 10.0) From ea027b0b28513e170dac7f381ffe4513639b5db6 Mon Sep 17 00:00:00 2001 From: jycr Date: Thu, 30 May 2024 13:15:14 +0200 Subject: [PATCH 059/233] Add test to ensure all Rules are registered --- pom.xml | 6 ++++++ .../java/JavaCheckRegistrar.java | 2 +- .../java/JavaCheckRegistrarTest.java | 14 +++++++++++--- .../java/JavaRulesDefinitionTest.java | 7 ++----- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index fa0c7e93..c6df47a3 100644 --- a/pom.xml +++ b/pom.xml @@ -136,6 +136,12 @@ test + + org.reflections + reflections + 0.10.2 + test + diff --git a/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java b/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java index f4ef343d..50ada183 100644 --- a/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java +++ b/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java @@ -47,7 +47,7 @@ */ @SonarLintSide public class JavaCheckRegistrar implements CheckRegistrar { - private static final List> ANNOTATED_RULE_CLASSES = List.of( + static final List> ANNOTATED_RULE_CLASSES = List.of( ArrayCopyCheck.class, IncrementCheck.class, AvoidUsageOfStaticCollections.class, diff --git a/src/test/java/fr/greencodeinitiative/java/JavaCheckRegistrarTest.java b/src/test/java/fr/greencodeinitiative/java/JavaCheckRegistrarTest.java index 02270ca5..09655b68 100644 --- a/src/test/java/fr/greencodeinitiative/java/JavaCheckRegistrarTest.java +++ b/src/test/java/fr/greencodeinitiative/java/JavaCheckRegistrarTest.java @@ -17,7 +17,11 @@ */ package fr.greencodeinitiative.java; +import java.util.Set; + import org.junit.jupiter.api.Test; +import org.reflections.Reflections; +import org.sonar.check.Rule; import org.sonar.plugins.java.api.CheckRegistrar; import static org.assertj.core.api.Assertions.assertThat; @@ -30,10 +34,14 @@ void checkNumberRules() { final JavaCheckRegistrar registrar = new JavaCheckRegistrar(); registrar.register(context); - - assertThat(context.checkClasses()).hasSize(15); + assertThat(context.checkClasses()) + .describedAs("All implemented rules must be registered into " + JavaCheckRegistrar.class) + .containsExactlyInAnyOrder(getDefinedRules().toArray(new Class[0])); assertThat(context.testCheckClasses()).isEmpty(); - } + static Set> getDefinedRules() { + Reflections r = new Reflections(JavaCheckRegistrar.class.getPackageName() + ".checks"); + return r.getTypesAnnotatedWith(Rule.class); + } } diff --git a/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java b/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java index ad1b5367..ee6dff5b 100644 --- a/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java +++ b/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java @@ -28,6 +28,7 @@ import org.sonar.api.server.rule.RulesDefinition.Rule; import org.sonar.api.utils.Version; +import static fr.greencodeinitiative.java.JavaCheckRegistrar.ANNOTATED_RULE_CLASSES; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -36,8 +37,6 @@ class JavaRulesDefinitionTest { private RulesDefinition.Repository repository; - private int rulesSize; - @BeforeEach void init() { final SonarRuntime sonarRuntime = mock(SonarRuntime.class); @@ -46,7 +45,6 @@ void init() { RulesDefinition.Context context = new RulesDefinition.Context(); rulesDefinition.define(context); repository = context.repository(rulesDefinition.repositoryKey()); - rulesSize = 15; } @Test @@ -55,12 +53,11 @@ void testMetadata() { assertThat(repository.name()).isEqualTo("ecoCode"); assertThat(repository.language()).isEqualTo("java"); assertThat(repository.key()).isEqualTo("ecocode-java"); - assertThat(repository.rules()).hasSize(rulesSize); } @Test void testRegistredRules() { - assertThat(repository.rules()).hasSize(rulesSize); + assertThat(repository.rules()).hasSize(ANNOTATED_RULE_CLASSES.size()); } @Test From a6938a441a8c96e6f292d7ab365d62fabd2d11bb Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Wed, 12 Jun 2024 22:06:52 +0200 Subject: [PATCH 060/233] comment on TODO_DDC.md for docker port pb --- _TODOs_DDC.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/_TODOs_DDC.md b/_TODOs_DDC.md index d318d99e..85e767d8 100644 --- a/_TODOs_DDC.md +++ b/_TODOs_DDC.md @@ -7,4 +7,5 @@ - check usefulness - upgrade versions - enable github `dependabot` to create automatically PR with version upgrades of dependencides (when all dependencies will be ok) -- ménage dans les branches de dev (local et remote) \ No newline at end of file +- ménage dans les branches de dev (local et remote) +- docker-compose : ":9000" (génération port aléatoire pour l'IHM + repérage pour IHM) au lieu de "9000:9000" si erreur lors du démarrage "Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:9000 -> 0.0.0.0:0: listen tcp 0.0.0.0:9000: bind: address already in use" \ No newline at end of file From c0251589700af491130d626dec6fbaa3abc66751 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 19 Jul 2024 16:34:54 +0200 Subject: [PATCH 061/233] update docker port managment --- tool_send_to_sonar.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tool_send_to_sonar.sh b/tool_send_to_sonar.sh index 21470842..cb663d98 100755 --- a/tool_send_to_sonar.sh +++ b/tool_send_to_sonar.sh @@ -2,8 +2,7 @@ # "sonar.token" variable (or sonar.login before SONARQUBE 9.9) : private TOKEN generated in your local SonarQube during installation # (input paramater of this script) -mvn clean org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.token=$1 -# mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.token=$1 -Dsonar.host.url=https://sonar-staging.gcp.cicd.solocal.com/ +mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.host.url=http://localhost:$1 -Dsonar.token=$2 # command if you have a SONARQUBE < 9.9 (sonar.token existing for SONARQUBE >= 10.0) # mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.login=$1 From 42006efff8c87a3fa79eb85ff5739cac57403c3f Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 19 Jul 2024 16:59:36 +0200 Subject: [PATCH 062/233] add 10.6.0 SonarQube version + update docker port managment --- CHANGELOG.md | 2 ++ docker-compose.yml | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ce62a86..c1bd27c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Check + update for SonarQube 10.6.0 compatibility + ### Deleted ## [1.6.1] - 2024-05-15 diff --git a/docker-compose.yml b/docker-compose.yml index ee7dc875..6cc49eb8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,10 @@ version: "3.3" services: sonar: - image: sonarqube:10.5.1-community + image: sonarqube:10.6.0-community container_name: sonar_ecocode_java ports: - - "9000:9000" + - ":9000" networks: - sonarnet depends_on: From 688cffc2151534216acdefb1f2ee6fb17ed9ee0b Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Sun, 21 Jul 2024 15:59:13 +0200 Subject: [PATCH 063/233] [ISSUE 60] update compatibility to SonarQube 10.6.0 --- CHANGELOG.md | 3 ++- Dockerfile | 11 +++++++++-- README.md | 2 +- docker-compose.yml | 21 +++++++++++++++------ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1bd27c2..c63808b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- Check + update for SonarQube 10.6.0 compatibility +- [#60](https://github.com/green-code-initiative/ecoCode-java/issues/60) Check + update for SonarQube 10.6.0 compatibility +- refactoring docker system ### Deleted diff --git a/Dockerfile b/Dockerfile index a5a0fc78..421eacda 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,16 @@ -FROM maven:3-openjdk-11-slim AS builder +ARG MAVEN_BUILDER=3-openjdk-17-slim +ARG SONARQUBE_VERSION=10.6.0-community + +FROM maven:${MAVEN_BUILDER} AS builder COPY . /usr/src/ecocode WORKDIR /usr/src/ecocode +COPY src src/ +COPY pom.xml tool_build.sh ./ + RUN ./tool_build.sh -FROM sonarqube:10.5.1-community +FROM sonarqube:${SONARQUBE_VERSION} COPY --from=builder /usr/src/ecocode/target/ecocode-*.jar /opt/sonarqube/extensions/plugins/ +USER sonarqube diff --git a/README.md b/README.md index 7fab3c06..a28c0586 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ Ready to use binaries are available [from GitHub](https://github.com/green-code- | Plugin version | SonarQube version | Java version | |----------------|---------------------|--------------| -| 1.5.+ | 9.4.+ LTS to 10.5.1 | 11 / 17 | +| 1.6.+ | 9.4.+ LTS to 10.6.0 | 11 / 17 | > 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). diff --git a/docker-compose.yml b/docker-compose.yml index 6cc49eb8..e84e3895 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,23 +1,27 @@ -version: "3.3" +name: sonarqube_ecocode_java + services: sonar: - image: sonarqube:10.6.0-community + build: . container_name: sonar_ecocode_java ports: - ":9000" networks: - sonarnet depends_on: - - db + db: + condition: service_healthy environment: SONAR_JDBC_USERNAME: sonar SONAR_JDBC_PASSWORD: sonar SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonarqube SONAR_ES_BOOTSTRAP_CHECKS_DISABLE: 'true' + env_file: + - path: ./.default.docker.env + required: true + - path: ./.override.docker.env + required: false volumes: - - type: bind - source: ./target/ecocode-java-plugin-1.6.2-SNAPSHOT.jar - target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-1.6.2-SNAPSHOT.jar - "extensions:/opt/sonarqube/extensions" - "logs:/opt/sonarqube/logs" - "data:/opt/sonarqube/data" @@ -34,6 +38,11 @@ services: POSTGRES_PASSWORD: sonar POSTGRES_DB: sonarqube PGDATA: pg_data:/var/lib/postgresql/data/pgdata + healthcheck: + test: [ "CMD-SHELL", "pg_isready -U sonar -d sonarqube" ] + interval: 5s + timeout: 5s + retries: 5 networks: sonarnet: From 0316bc39d8281d7ac45cea542df517de4cbb039b Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Sun, 21 Jul 2024 16:35:22 +0200 Subject: [PATCH 064/233] upgrade ecocode-rules-spec to 1.6.2 --- CHANGELOG.md | 1 + pom.xml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c63808b2..1347d35d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#60](https://github.com/green-code-initiative/ecoCode-java/issues/60) Check + update for SonarQube 10.6.0 compatibility - refactoring docker system +- upgrade ecocode-rules-specifications to 1.6.2 ### Deleted diff --git a/pom.xml b/pom.xml index fa0c7e93..6d2e3734 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ 1.7 - 1.5.1 + 1.6.2 From 13aa2fa2aae9fb31896426ba126f5a8bc7f936ac Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Sun, 21 Jul 2024 16:37:30 +0200 Subject: [PATCH 065/233] prepare 1.6.2 : update CHANGELOG --- CHANGELOG.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1347d35d..554bf66d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,12 +11,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +### Deleted + +## [1.6.2] - 2024-07-21 + +### Changed + - [#60](https://github.com/green-code-initiative/ecoCode-java/issues/60) Check + update for SonarQube 10.6.0 compatibility - refactoring docker system - upgrade ecocode-rules-specifications to 1.6.2 -### Deleted - ## [1.6.1] - 2024-05-15 ### Changed From 660711d34208c0e0edef05dd0485c74918a53133 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Sun, 21 Jul 2024 16:37:53 +0200 Subject: [PATCH 066/233] [maven-release-plugin] prepare release 1.6.2 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 6d2e3734..2a0e11d2 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.ecocode ecocode-java-plugin - 1.6.2-SNAPSHOT + 1.6.2 sonar-plugin @@ -30,7 +30,7 @@ scm:git:https://github.com/green-code-initiative/ecocode-java scm:git:https://github.com/green-code-initiative/ecocode-java https://github.com/green-code-initiative/ecocode-java - HEAD + 1.6.2 From 49b32fe451f91fc0b1d9ff6b5bb0ee36512a83c1 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Sun, 21 Jul 2024 16:37:53 +0200 Subject: [PATCH 067/233] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 2a0e11d2..1c657cbb 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.ecocode ecocode-java-plugin - 1.6.2 + 1.6.3-SNAPSHOT sonar-plugin @@ -30,7 +30,7 @@ scm:git:https://github.com/green-code-initiative/ecocode-java scm:git:https://github.com/green-code-initiative/ecocode-java https://github.com/green-code-initiative/ecocode-java - 1.6.2 + HEAD From 4b849b5e3b23b9ec734d8746766b69b06e87df4d Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 23 Jul 2024 18:21:11 +0200 Subject: [PATCH 068/233] correction of docker env --- .default.docker.env | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .default.docker.env diff --git a/.default.docker.env b/.default.docker.env new file mode 100644 index 00000000..01ee4f28 --- /dev/null +++ b/.default.docker.env @@ -0,0 +1,5 @@ +# Set default Sonarqube environment variables used by docker-compose +# You can override these envvars by creating a '.override.docker.env' file +# For available envvars list, see https://docs.sonarsource.com/sonarqube/latest/setup-and-upgrade/configure-and-operate-a-server/environment-variables/ + +SONAR_LOG_LEVEL_WEB=INFO From 688974fc63950eef6771e1f2b66911403bb497d9 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 26 Jul 2024 21:27:54 +0200 Subject: [PATCH 069/233] [PR 49] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 554bf66d..855c493f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- [#49](https://github.com/green-code-initiative/ecoCode-java/pull/49) Add test to ensure all Rules are registered + ### Deleted ## [1.6.2] - 2024-07-21 From 753cdc24b3539996e4445ac1ea88bec3574da526 Mon Sep 17 00:00:00 2001 From: jycr Date: Sun, 1 Sep 2024 15:25:10 +0200 Subject: [PATCH 070/233] [ecoCode#336] Adds Maven Wrapper This Maven Wrapper is an easy way to ensure a developer has everything necessary to build this project. Executed command to add wrapper to project: ```sh mvn wrapper:wrapper -Dmaven=3.9.9 ``` --- .gitattributes | 6 +- .gitignore | 1 + .mvn/wrapper/maven-wrapper.properties | 19 ++ CHANGELOG.md | 1 + mvnw | 259 ++++++++++++++++++++++++++ mvnw.cmd | 149 +++++++++++++++ 6 files changed, 434 insertions(+), 1 deletion(-) create mode 100644 .mvn/wrapper/maven-wrapper.properties create mode 100755 mvnw create mode 100644 mvnw.cmd diff --git a/.gitattributes b/.gitattributes index 12b960c4..9039a78b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,4 +4,8 @@ # Ensure BAT files will always be checked out with CRLFs (regardless of the # OS they were checked out on). -*.bat text eol=crlf \ No newline at end of file +*.bat text eol=crlf + +# Ensure BAT files will always be checked out with CRLFs (regardless of the +# OS they were checked out on). +*.cmd text eol=crlf diff --git a/.gitignore b/.gitignore index 67cc592c..8554f83b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Ignore all files and folders starting with ".", except a few exceptions .* +!.mvn/ !.gitignore !.gitattributes !.github/ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 00000000..d58dfb70 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +wrapperVersion=3.3.2 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip diff --git a/CHANGELOG.md b/CHANGELOG.md index 855c493f..535e14f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - [#49](https://github.com/green-code-initiative/ecoCode-java/pull/49) Add test to ensure all Rules are registered +- [green-code-initiative/ecoCode#336](https://github.com/green-code-initiative/ecoCode/issues/336) [Adds Maven Wrapper](https://github.com/green-code-initiative/ecoCode-java/pull/67) ### Deleted diff --git a/mvnw b/mvnw new file mode 100755 index 00000000..19529ddf --- /dev/null +++ b/mvnw @@ -0,0 +1,259 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 00000000..249bdf38 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,149 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" From b1abd7bc8044f4189a66784446c0d4cb114fea8e Mon Sep 17 00:00:00 2001 From: jycr Date: Sun, 1 Sep 2024 15:28:09 +0200 Subject: [PATCH 071/233] Migrates scripts to use Maven Wrapper (to ensure consistency of Maven version used across different environments) --- .github/workflows/_BACKUP_manual_release.yml | 6 +++--- .github/workflows/build.yml | 4 ++-- .github/workflows/tag_release.yml | 2 +- tool_build.sh | 2 +- tool_compile.sh | 2 +- tool_release_1_prepare.sh | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/_BACKUP_manual_release.yml b/.github/workflows/_BACKUP_manual_release.yml index 90818a55..09307548 100644 --- a/.github/workflows/_BACKUP_manual_release.yml +++ b/.github/workflows/_BACKUP_manual_release.yml @@ -31,9 +31,9 @@ jobs: git config user.name 'github-actions[bot]' git config user.email '' - name: Maven release - run: mvn release:prepare -B -ff -DtagNameFormat=@{project.version} + run: ./mvnw release:prepare -B -ff -DtagNameFormat=@{project.version} - name: Maven release clean - run: mvn release:clean + run: ./mvnw release:clean - name: Get last TAG run: echo "LAST_TAG=$(git tag --sort=-version:refname | head -n 1)" >> $GITHUB_ENV - name: Extract release notes @@ -44,7 +44,7 @@ jobs: with: ref: ${{ env.LAST_TAG }} - name: Build project - run: mvn -e -B clean package -DskipTests + run: ./mvnw -e -B clean package -DskipTests - name: Create release id: create_release uses: actions/create-release@v1 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 60db5ba0..b6e2d7e4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,7 +38,7 @@ jobs: restore-keys: ${{ runner.os }}-m2 - name: Verify - run: mvn -e -B verify + run: ./mvnw -e -B verify - name: Set up JDK 17 uses: actions/setup-java@v3 @@ -57,4 +57,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: mvn -e -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=green-code-initiative_ecoCode-java + run: ./mvnw -e -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=green-code-initiative_ecoCode-java diff --git a/.github/workflows/tag_release.yml b/.github/workflows/tag_release.yml index b405ace1..75e6e624 100644 --- a/.github/workflows/tag_release.yml +++ b/.github/workflows/tag_release.yml @@ -29,7 +29,7 @@ jobs: id: extract-release-notes uses: ffurrer2/extract-release-notes@v1 - name: Build project - run: mvn -e -B clean package -DskipTests + run: ./mvnw -e -B clean package -DskipTests - name: Create release id: create_release uses: actions/create-release@v1 diff --git a/tool_build.sh b/tool_build.sh index bfac031a..a5f6a094 100755 --- a/tool_build.sh +++ b/tool_build.sh @@ -1,3 +1,3 @@ #!/usr/bin/env sh -mvn clean package -DskipTests +./mvnw clean package -DskipTests diff --git a/tool_compile.sh b/tool_compile.sh index 3d3e0d89..9d4da3c7 100755 --- a/tool_compile.sh +++ b/tool_compile.sh @@ -1,3 +1,3 @@ #!/usr/bin/env sh -mvn clean compile +./mvnw clean compile diff --git a/tool_release_1_prepare.sh b/tool_release_1_prepare.sh index e87b946d..7b996e3c 100755 --- a/tool_release_1_prepare.sh +++ b/tool_release_1_prepare.sh @@ -5,9 +5,9 @@ ### # creation of 2 commits with release and next SNAPSHOT -mvn release:prepare -B -ff -DpushChanges=false -DtagNameFormat=@{project.version} +./mvnw release:prepare -B -ff -DpushChanges=false -DtagNameFormat=@{project.version} sleep 2 # clean temporary files -mvn release:clean +./mvnw release:clean From 3a5825772b20b953d14e9c9d64dfedd2c192a55a Mon Sep 17 00:00:00 2001 From: jycr Date: Thu, 30 May 2024 19:47:45 +0200 Subject: [PATCH 072/233] feat: Adds "ecoCode way" profile. This profile aggregate all implemented rules by this plugin. This profile makes it easier to test ecoCode rules --- CHANGELOG.md | 2 + .../java/JavaEcoCodeWayProfile.java | 40 +++++++++++++++ .../java/JavaRulesDefinition.java | 2 +- .../java/ecoCode_way_profile.json | 21 ++++++++ .../java/JavaEcoCodeWayProfileTest.java | 51 +++++++++++++++++++ 5 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 src/main/java/fr/greencodeinitiative/java/JavaEcoCodeWayProfile.java create mode 100644 src/main/resources/fr/greencodeinitiative/java/ecoCode_way_profile.json create mode 100644 src/test/java/fr/greencodeinitiative/java/JavaEcoCodeWayProfileTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 855c493f..79b9ac3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ 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 + ### Changed - [#49](https://github.com/green-code-initiative/ecoCode-java/pull/49) Add test to ensure all Rules are registered diff --git a/src/main/java/fr/greencodeinitiative/java/JavaEcoCodeWayProfile.java b/src/main/java/fr/greencodeinitiative/java/JavaEcoCodeWayProfile.java new file mode 100644 index 00000000..d24fc82a --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/JavaEcoCodeWayProfile.java @@ -0,0 +1,40 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.greencodeinitiative.java; + +import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; +import org.sonarsource.analyzer.commons.BuiltInQualityProfileJsonLoader; + +import static fr.greencodeinitiative.java.JavaRulesDefinition.LANGUAGE; +import static fr.greencodeinitiative.java.JavaRulesDefinition.REPOSITORY_KEY; + +public final class JavaEcoCodeWayProfile implements BuiltInQualityProfilesDefinition { + static final String PROFILE_NAME = "ecoCode way"; + static final String PROFILE_PATH = JavaEcoCodeWayProfile.class.getPackageName().replace('.', '/') + "/ecoCode_way_profile.json"; + + @Override + public void define(Context context) { + NewBuiltInQualityProfile ecoCodeProfile = context.createBuiltInQualityProfile(PROFILE_NAME, LANGUAGE); + loadProfile(ecoCodeProfile); + ecoCodeProfile.done(); + } + + private void loadProfile(NewBuiltInQualityProfile profile) { + BuiltInQualityProfileJsonLoader.load(profile, REPOSITORY_KEY, PROFILE_PATH); + } +} diff --git a/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java b/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java index 958edc82..f9e03e30 100644 --- a/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java +++ b/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java @@ -31,7 +31,7 @@ public class JavaRulesDefinition implements RulesDefinition { private static final String RESOURCE_BASE_PATH = "io/ecocode/rules/java"; private static final String NAME = "ecoCode"; - private static final String LANGUAGE = "java"; + static final String LANGUAGE = "java"; static final String REPOSITORY_KEY = "ecocode-java"; private final SonarRuntime sonarRuntime; diff --git a/src/main/resources/fr/greencodeinitiative/java/ecoCode_way_profile.json b/src/main/resources/fr/greencodeinitiative/java/ecoCode_way_profile.json new file mode 100644 index 00000000..88e381ae --- /dev/null +++ b/src/main/resources/fr/greencodeinitiative/java/ecoCode_way_profile.json @@ -0,0 +1,21 @@ +{ + "name": "ecoCode way", + "language": "java", + "ruleKeys": [ + "EC1", + "EC2", + "EC3", + "EC5", + "EC27", + "EC28", + "EC32", + "EC67", + "EC69", + "EC72", + "EC74", + "EC76", + "EC77", + "EC78", + "EC79" + ] +} diff --git a/src/test/java/fr/greencodeinitiative/java/JavaEcoCodeWayProfileTest.java b/src/test/java/fr/greencodeinitiative/java/JavaEcoCodeWayProfileTest.java new file mode 100644 index 00000000..0d750163 --- /dev/null +++ b/src/test/java/fr/greencodeinitiative/java/JavaEcoCodeWayProfileTest.java @@ -0,0 +1,51 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.greencodeinitiative.java; + +import java.util.List; +import java.util.stream.Collectors; + +import org.junit.jupiter.api.Test; +import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; +import org.sonar.check.Rule; + +import static fr.greencodeinitiative.java.JavaCheckRegistrarTest.getDefinedRules; +import static fr.greencodeinitiative.java.JavaEcoCodeWayProfile.PROFILE_NAME; +import static fr.greencodeinitiative.java.JavaEcoCodeWayProfile.PROFILE_PATH; +import static fr.greencodeinitiative.java.JavaRulesDefinition.LANGUAGE; +import static org.assertj.core.api.Assertions.assertThat; + +class JavaEcoCodeWayProfileTest { + @Test + void should_create_ecocode_profile() { + BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); + + JavaEcoCodeWayProfile definition = new JavaEcoCodeWayProfile(); + definition.define(context); + + BuiltInQualityProfilesDefinition.BuiltInQualityProfile profile = context.profile(LANGUAGE, PROFILE_NAME); + + assertThat(profile.language()).isEqualTo(LANGUAGE); + assertThat(profile.name()).isEqualTo(PROFILE_NAME); + List definedRuleIds = getDefinedRules().stream().map(c -> c.getAnnotation(Rule.class).key()).collect(Collectors.toList()); + assertThat(profile.rules()) + .describedAs("All implemented rules must be declared in '%s' profile file: %s", PROFILE_NAME, PROFILE_PATH) + .map(BuiltInQualityProfilesDefinition.BuiltInActiveRule::ruleKey) + .containsExactlyInAnyOrderElementsOf(definedRuleIds); + } +} From 55781acd65f821cdb183bfeedf10987b4d39387f Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 6 Sep 2024 16:33:06 +0200 Subject: [PATCH 073/233] update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c60f73d..9bec3316 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - [#49](https://github.com/green-code-initiative/ecoCode-java/pull/49) Add test to ensure all Rules are registered -- [green-code-initiative/ecoCode#336](https://github.com/green-code-initiative/ecoCode/issues/336) [Adds Maven Wrapper](https://github.com/green-code-initiative/ecoCode-java/pull/67) +- [#336](https://github.com/green-code-initiative/ecoCode/issues/336) [Adds Maven Wrapper](https://github.com/green-code-initiative/ecoCode-java/pull/67) ### Deleted From 53d87f5b10077f4a16356345ac87c5d68492060b Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 18 Oct 2024 16:50:35 +0200 Subject: [PATCH 074/233] upgrade ecocode-rules-spec to 1.6.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 92836179..ea5912d7 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ 1.7 - 1.6.2 + 1.6.5 From d5f7ebd7bd54eac476086a9f3615b7c9d64b49b3 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Mon, 28 Oct 2024 21:50:54 +0100 Subject: [PATCH 075/233] upgrade gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8554f83b..3633a5cf 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ !.gitignore !.gitattributes !.github/ +!.default.docker.env # Ignore generated files target From f0eb9320120d0798fbc8a832d57c8af807ec733c Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Mon, 28 Oct 2024 22:05:23 +0100 Subject: [PATCH 076/233] update doc --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cb2f8c68..b0da22da 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Step 3 : send Sonar metrics to local SonarQube --- ```sh -./tool_send_to_sonar.sh MY_SONAR_TOKEN +./tool_send_to_sonar.sh MY_SONAR_PORT MY_SONAR_TOKEN or From 85cf20a5a835b799ee8c362e9af12bd199d7b4d0 Mon Sep 17 00:00:00 2001 From: jycr Date: Tue, 29 Oct 2024 16:01:06 +0100 Subject: [PATCH 077/233] refactor: Moves resources in dedicated subdirectory to prepare future merge with ecoCode-java repo --- .../test-projects/ecocode-java-plugin-test-project/.gitignore | 0 .../test-projects/ecocode-java-plugin-test-project/LICENCE.md | 0 .../it/test-projects/ecocode-java-plugin-test-project/README.md | 0 .../it/test-projects/ecocode-java-plugin-test-project/pom.xml | 0 .../java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java | 2 ++ .../java/checks/AvoidFullSQLRequestCheck.java | 0 .../checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java | 0 .../java/checks/AvoidGettingSizeCollectionInForLoopBad.java | 0 .../java/checks/AvoidGettingSizeCollectionInForLoopGood.java | 0 .../java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java | 0 .../java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java | 0 .../java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java | 0 .../checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java | 0 .../java/checks/AvoidMultipleIfElseStatement.java | 0 .../AvoidMultipleIfElseStatementCompareMethodNoIssue.java | 0 .../checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java | 0 .../java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java | 0 .../java/checks/AvoidMultipleIfElseStatementNoIssue.java | 0 .../java/checks/AvoidRegexPatternNotStatic.java | 0 .../java/checks/AvoidSQLRequestInLoopCheck.java | 0 .../java/checks/AvoidSetConstantInBatchUpdateCheck.java | 0 .../java/checks/AvoidSpringRepositoryCallInLoopCheck.java | 0 .../java/checks/AvoidSpringRepositoryCallInStreamCheck.java | 0 .../java/checks/AvoidStatementForDMLQueries.java | 0 .../java/checks/AvoidUsageOfStaticCollections.java | 0 .../java/checks/FreeResourcesOfAutoCloseableInterface.java | 0 .../java/checks/GoodUsageOfStaticCollections.java | 0 .../java/checks/GoodWayConcatenateStringsLoop.java | 0 .../java/fr/greencodeinitiative/java/checks/IncrementCheck.java | 0 .../java/checks/InitializeBufferWithAppropriateSize.java | 0 .../java/checks/NoFunctionCallWhenDeclaringForLoop.java | 0 .../java/checks/OptimizeReadFileExceptionCheck.java | 0 .../java/checks/OptimizeReadFileExceptionCheck2.java | 0 .../java/checks/OptimizeReadFileExceptionCheck3.java | 0 .../java/checks/OptimizeReadFileExceptionCheck4.java | 0 .../java/checks/OptimizeReadFileExceptionCheck5.java | 0 .../java/checks/OptimizeSQLQueriesWithLimit.java | 2 ++ .../fr/greencodeinitiative/java/checks/ValidRegexPattern.java | 0 .../fr/greencodeinitiative/java/checks/ValidRegexPattern2.java | 0 .../fr/greencodeinitiative/java/checks/ValidRegexPattern3.java | 0 .../ecocode-java-plugin-test-project/tool_send_to_sonar.sh | 0 41 files changed, 4 insertions(+) rename .gitignore => src/it/test-projects/ecocode-java-plugin-test-project/.gitignore (100%) rename LICENCE.md => src/it/test-projects/ecocode-java-plugin-test-project/LICENCE.md (100%) rename README.md => src/it/test-projects/ecocode-java-plugin-test-project/README.md (100%) rename pom.xml => src/it/test-projects/ecocode-java-plugin-test-project/pom.xml (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java (99%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheck.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopBad.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopGood.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheck.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/GoodUsageOfStaticCollections.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/GoodWayConcatenateStringsLoop.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck2.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck3.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck4.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck5.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java (95%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern2.java (100%) rename src/{ => it/test-projects/ecocode-java-plugin-test-project/src}/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern3.java (100%) rename tool_send_to_sonar.sh => src/it/test-projects/ecocode-java-plugin-test-project/tool_send_to_sonar.sh (100%) diff --git a/.gitignore b/src/it/test-projects/ecocode-java-plugin-test-project/.gitignore similarity index 100% rename from .gitignore rename to src/it/test-projects/ecocode-java-plugin-test-project/.gitignore diff --git a/LICENCE.md b/src/it/test-projects/ecocode-java-plugin-test-project/LICENCE.md similarity index 100% rename from LICENCE.md rename to src/it/test-projects/ecocode-java-plugin-test-project/LICENCE.md diff --git a/README.md b/src/it/test-projects/ecocode-java-plugin-test-project/README.md similarity index 100% rename from README.md rename to src/it/test-projects/ecocode-java-plugin-test-project/README.md diff --git a/pom.xml b/src/it/test-projects/ecocode-java-plugin-test-project/pom.xml similarity index 100% rename from pom.xml rename to src/it/test-projects/ecocode-java-plugin-test-project/pom.xml diff --git a/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java similarity index 99% rename from src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java index 1f93de18..adee2b5d 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java @@ -1,3 +1,5 @@ +package fr.greencodeinitiative.java.checks; + import java.util.Arrays; class ArrayCopyCheck { diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheck.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheck.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheck.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheck.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopBad.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopBad.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopBad.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopBad.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopGood.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopGood.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopGood.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopGood.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheck.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheck.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheck.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheck.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/GoodUsageOfStaticCollections.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/GoodUsageOfStaticCollections.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/GoodUsageOfStaticCollections.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/GoodUsageOfStaticCollections.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/GoodWayConcatenateStringsLoop.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/GoodWayConcatenateStringsLoop.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/GoodWayConcatenateStringsLoop.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/GoodWayConcatenateStringsLoop.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck2.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck2.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck2.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck2.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck3.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck3.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck3.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck3.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck4.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck4.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck4.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck4.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck5.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck5.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck5.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck5.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java similarity index 95% rename from src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java index 52c912f8..c21e2a4a 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java @@ -1,3 +1,5 @@ +package fr.greencodeinitiative.java.checks; + import org.springframework.data.jpa.repository.Query; import java.util.ArrayList; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern2.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern2.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern2.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern2.java diff --git a/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern3.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern3.java similarity index 100% rename from src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern3.java rename to src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern3.java diff --git a/tool_send_to_sonar.sh b/src/it/test-projects/ecocode-java-plugin-test-project/tool_send_to_sonar.sh similarity index 100% rename from tool_send_to_sonar.sh rename to src/it/test-projects/ecocode-java-plugin-test-project/tool_send_to_sonar.sh From fc369b9e8f97d0b6009560cd48c5831a03d0041e Mon Sep 17 00:00:00 2001 From: jycr Date: Sat, 19 Oct 2024 18:51:09 +0200 Subject: [PATCH 078/233] Update SonarQube dependencies --- pom.xml | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index ea5912d7..ede7da76 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ io.ecocode ecocode-java-plugin 1.6.3-SNAPSHOT - + sonar-plugin ecoCode - Java language @@ -53,8 +53,13 @@ green-code-initiative https://sonarcloud.io - 9.4.0.54424 - 7.19.0.31550 + + 9.9.7.96285 + + 9.8.0.203 + + + 7.16.0.30901 2.5.0.1358 @@ -66,7 +71,7 @@ 1.7 - + 1.6.5 @@ -88,9 +93,9 @@ - org.sonarsource.sonarqube + org.sonarsource.api.plugin sonar-plugin-api - ${sonarqube.version} + ${sonar.plugin.api.version} provided @@ -333,8 +338,11 @@
com/mycila/maven/plugin/license/templates/GPL-3.txt
- **/*.java + ${project.basedir}/src/**/*.java + + ${project.basedir}/src/it/test-projects/** +
From 5aec7d67eb350e08299fbacf87e9c53a7984c2a2 Mon Sep 17 00:00:00 2001 From: jycr Date: Tue, 29 Oct 2024 14:39:58 +0100 Subject: [PATCH 079/233] Adds SonarQube integration tests --- pom.xml | 139 ++++++ .../LaunchSonarqubeAndBuildProjectIT.java | 440 ++++++++++++++++++ .../tests/profile/ProfileBackup.java | 163 +++++++ .../tests/profile/ProfileMetadata.java | 42 ++ .../tests/profile/RuleMetadata.java | 40 ++ 5 files changed, 824 insertions(+) create mode 100644 src/it/java/io/ecocode/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java create mode 100644 src/it/java/io/ecocode/java/integration/tests/profile/ProfileBackup.java create mode 100644 src/it/java/io/ecocode/java/integration/tests/profile/ProfileMetadata.java create mode 100644 src/it/java/io/ecocode/java/integration/tests/profile/RuleMetadata.java diff --git a/pom.xml b/pom.xml index ede7da76..9c9e681f 100644 --- a/pom.xml +++ b/pom.xml @@ -74,6 +74,19 @@ 1.6.5 + + https://repo1.maven.org/maven2 + + false + + + ${sonarqube.version} + + + ${sonarjava.version} + + + @@ -147,6 +160,44 @@ 0.10.2 test + + + + org.sonarsource.orchestrator + sonar-orchestrator-junit5 + 4.9.0.1920 + test + + + org.sonarsource.java + test-classpath-reader + 8.5.0.37199 + test + + + org.sonarsource.sonarqube + sonar-ws + ${sonarqube.version} + test + + + io.github.jycr + java-data-url-handler + 0.0.1 + test + + + org.slf4j + slf4j-api + 2.0.13 + test + + + ch.qos.logback + logback-classic + 1.5.6 + test + @@ -356,6 +407,94 @@ + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.6.0 + + + add-integration-test-sources + process-test-sources + + add-test-source + + + + ${project.basedir}/src/it/java + + + + + add-integration-test-resources + generate-test-resources + + add-test-resource + + + + + ${project.basedir}/src/it/resources + + + true + ${project.basedir}/src/it/resources-filtered + + + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.2.5 + + + + integration-test + verify + + + + ${test-it.sonarqube.keepRunning} + ${test-it.orchestrator.artifactory.url} + ${test-it.sonarqube.version} + ${test-it.sonarqube.port} + + + ${project.baseUri}/target/${project.artifactId}-${project.version}.jar, + org.sonarsource.java|sonar-java-plugin|${test-it.sonarjava.version}, + + + + ${project.baseUri}/src/main/resources/fr/greencodeinitiative/java/ecoCode_way_profile.json, + + + + 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, + + + + java|ecoCode way, + + + + + + + + + + keep-running + + true + 9000 + + + diff --git a/src/it/java/io/ecocode/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java b/src/it/java/io/ecocode/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java new file mode 100644 index 00000000..f865cc18 --- /dev/null +++ b/src/it/java/io/ecocode/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java @@ -0,0 +1,440 @@ +package io.ecocode.java.integration.tests; + +import java.net.MalformedURLException; +import java.net.URI; +import java.nio.file.Path; +import java.text.MessageFormat; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Scanner; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.build.MavenBuild; +import com.sonar.orchestrator.container.Server; +import com.sonar.orchestrator.junit5.OrchestratorExtension; +import com.sonar.orchestrator.junit5.OrchestratorExtensionBuilder; +import com.sonar.orchestrator.locator.FileLocation; +import com.sonar.orchestrator.locator.Location; +import com.sonar.orchestrator.locator.MavenLocation; +import com.sonar.orchestrator.locator.URLLocation; +import io.ecocode.java.integration.tests.profile.ProfileBackup; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.sonarqube.ws.Issues; +import org.sonarqube.ws.Measures; +import org.sonarqube.ws.client.HttpConnector; +import org.sonarqube.ws.client.WsClient; +import org.sonarqube.ws.client.WsClientFactories; +import org.sonarqube.ws.client.issues.SearchRequest; +import org.sonarqube.ws.client.measures.ComponentRequest; + +import static java.lang.System.Logger.Level.INFO; +import static java.util.Optional.ofNullable; +import static java.util.function.Predicate.not; +import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toMap; +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonarqube.ws.Common.RuleType.CODE_SMELL; +import static org.sonarqube.ws.Common.Severity.MINOR; + +class LaunchSonarqubeAndBuildProjectIT { + private static final System.Logger LOGGER = System.getLogger(LaunchSonarqubeAndBuildProjectIT.class.getName()); + + private static OrchestratorExtension orchestrator; + private static List analyzedProjects; + + private static void launchSonarqube() { + String orchestratorArtifactoryUrl = systemProperty("test-it.orchestrator.artifactory.url"); + String sonarqubeVersion = systemProperty("test-it.sonarqube.version"); + Optional sonarqubePort = ofNullable(System.getProperty("test-it.sonarqube.port")).map(String::trim).filter(not(String::isEmpty)); + + OrchestratorExtensionBuilder orchestratorExtensionBuilder = OrchestratorExtension + .builderEnv() + .useDefaultAdminCredentialsForBuilds(true) + .setOrchestratorProperty("orchestrator.artifactory.url", orchestratorArtifactoryUrl) + .setSonarVersion(sonarqubeVersion) + .setServerProperty("sonar.forceAuthentication", "false") + .setServerProperty("sonar.web.javaOpts", "-Xmx1G"); + + sonarqubePort.ifPresent(s -> orchestratorExtensionBuilder.setServerProperty("sonar.web.port", s)); + + additionalPluginsToInstall().forEach(orchestratorExtensionBuilder::addPlugin); + additionalProfiles().forEach(orchestratorExtensionBuilder::restoreProfileAtStartup); + + orchestrator = orchestratorExtensionBuilder.build(); + orchestrator.start(); + LOGGER.log(INFO, () -> MessageFormat.format("SonarQube server available on: {0}", orchestrator.getServer().getUrl())); + } + + @BeforeAll + static void setup() { + LOGGER.log( + INFO, + "\n" + + "====================================================================================================\n" + + "Launching SonarQube server with following JAVA System properties: {0}\n" + + "====================================================================================================\n" + , + Stream + .of( + "test-it.sonarqube.keepRunning", + "test-it.orchestrator.artifactory.url", + "test-it.sonarqube.version", + "test-it.plugins", + "test-it.additional-profile-uris", + "test-it.test-projects", + "test-it.test-project-profile-by-language" + ) + .filter(k -> System.getProperty(k) != null) + .map(k -> MessageFormat + .format( + "-D{0}=\"{1}\"", + k, + System.getProperty(k).replaceAll("\\s+", " ") + ) + ) + .collect(Collectors.joining("\n", "\n\n", "\n\n")) + ); + launchSonarqube(); + launchAnalysis(); + } + + private static void launchAnalysis() { + Server server = orchestrator.getServer(); + Map qualityProfileByLanguage = testProjectProfileByLanguage(); + + analyzedProjects = getProjectsToAnalyze(); + + analyzedProjects + .stream() + // - Prepare/create SonarQube project for the test project + .peek(projectToAnalyze -> projectToAnalyze.provisionProjectIntoServer(server)) + // - Configure the test project + .peek(projectToAnalyze -> projectToAnalyze.associateProjectToQualityProfile(server, qualityProfileByLanguage)) + .map(ProjectToAnalyze::createMavenBuild) + // - Run SonarQube Scanner on test project + .peek(p -> LOGGER.log(INFO, () -> MessageFormat.format("Running SonarQube Scanner on project: {0}", p.getPom()))) + .forEach(orchestrator::executeBuild); + } + + @Test + void test() { + String projectKey = analyzedProjects.get(0).projectKey; + + Map measures = getMeasures(projectKey); + + assertThat(ofNullable(measures.get("code_smells")).map(Measures.Measure::getValue).map(Integer::parseInt).orElse(0)) + .isGreaterThan(1); + + List projectIssues = issuesForComponent(projectKey); + assertThat(projectIssues).isNotEmpty(); + + List issuesForArrayCopyCheck = issuesForFile(projectKey, "src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java"); + + assertThat(issuesForArrayCopyCheck) + .hasSize(1) + .first().satisfies(issue -> { + assertThat(issue.getRule()).isEqualTo("ecocode-java:EC69"); + assertThat(issue.getSeverity()).isEqualTo(MINOR); + assertThat(issue.getLine()).isEqualTo(18); + assertThat(issue.getTextRange().getStartLine()).isEqualTo(18); + assertThat(issue.getTextRange().getEndLine()).isEqualTo(18); + assertThat(issue.getTextRange().getStartOffset()).isEqualTo(15); + assertThat(issue.getTextRange().getEndOffset()).isEqualTo(27); + assertThat(issue.getMessage()).isEqualTo("Do not call a function when declaring a for-type loop"); + assertThat(issue.getDebt()).isEqualTo("5min"); + assertThat(issue.getEffort()).isEqualTo("5min"); + assertThat(issue.getType()).isEqualTo(CODE_SMELL); + }); + } + + @AfterAll + static void tearDown() { + if ("true".equalsIgnoreCase(System.getProperty("test-it.sonarqube.keepRunning"))) { + try (Scanner in = new Scanner(System.in)) { + LOGGER.log(INFO, () -> + MessageFormat.format( + "\n" + + "\n====================================================================================================" + + "\nSonarQube available at: {0} (to login: admin/admin)" + + "\n====================================================================================================" + + "\n", + orchestrator.getServer().getUrl() + ) + ); + do { + LOGGER.log(INFO, "✍ Please press CTRL+C to stop"); + } + while (!in.nextLine().isEmpty()); + } + } + if (orchestrator != null) { + orchestrator.stop(); + } + } + + private static String systemProperty(String propertyName) { + return ofNullable(System.getProperty(propertyName)) + .orElseThrow(() -> new IllegalStateException( + String.format( + "System property `%s` must be defined. See `%s` (in section: `plugin[maven-failsafe-plugin]/systemPropertyVariables`) for sample value.", + propertyName, + Path.of("pom.xml").toAbsolutePath() + ) + )); + } + + /** + * Projects to analyze + */ + private static List getProjectsToAnalyze() { + return commaSeparatedValues(systemProperty("test-it.test-projects")) + .map(projectToAnalyzeDefinition -> pipeSeparatedValues(projectToAnalyzeDefinition).collect(toList())) + .filter(projectToAnalyzeDefinition -> projectToAnalyzeDefinition.size() == 3) + .map(projectToAnalyzeDefinition -> { + // Project Key + String projectKey = projectToAnalyzeDefinition.get(0); + // Project Name + String projectName = projectToAnalyzeDefinition.get(1); + // Project POM URI + URI projectPom = URI.create(projectToAnalyzeDefinition.get(2)); + return new ProjectToAnalyze(projectPom, projectKey, projectName); + }) + .collect(toList()); + } + + private static Stream commaSeparatedValues(String value) { + return splitAndTrim(value, "\\s*,\\s*"); + } + + private static Stream pipeSeparatedValues(String value) { + return splitAndTrim(value, "\\s*\\|\\s*"); + } + + private static Stream splitAndTrim(String value, String regexSeparator) { + return Stream + .of(value.split(regexSeparator)) + .map(String::trim) + .filter(not(String::isEmpty)); + } + + private static Set additionalPluginsToInstall() { + return commaSeparatedValues(systemProperty("test-it.plugins")) + .map(LaunchSonarqubeAndBuildProjectIT::toPluginLocation) + .collect(Collectors.toSet()); + } + + private static Set additionalProfiles() { + return commaSeparatedValues(systemProperty("test-it.additional-profile-uris")) + .map(URI::create) + .map(ProfileBackup::new) + .map(ProfileBackup::profileDataUri) + .map(URLLocation::create) + .collect(Collectors.toSet()); + } + + private static Map testProjectProfileByLanguage() { + // Comma separated list of profiles to associate to each "test project" + // Syntaxe: `language:profileName` + return commaSeparatedValues(systemProperty("test-it.test-project-profile-by-language")) + .map(languageAndProfileDefinitions -> pipeSeparatedValues(languageAndProfileDefinitions).collect(toList())) + .filter(languageAndProfile -> languageAndProfile.size() == 2) + .collect(toMap( + // Language + languageAndProfile -> languageAndProfile.get(0), + // Profile name + languageAndProfile -> languageAndProfile.get(1) + )); + } + + private static Location toPluginLocation(String location) { + if (location.startsWith("file://")) { + try { + return FileLocation.of(URI.create(location).toURL()); + } catch (MalformedURLException e) { + throw new IllegalArgumentException(e); + } + } + List pluginGAVvalues = pipeSeparatedValues(location).collect(toList()); + if (pluginGAVvalues.size() != 3) { + throw new IllegalArgumentException("Invalid plugin GAV definition (`groupId|artifactId|version`): " + location); + } + return MavenLocation.of( + // groupId + pluginGAVvalues.get(0), + // artifactId + pluginGAVvalues.get(1), + // version + pluginGAVvalues.get(2) + ); + } + + private static class ProjectToAnalyze { + private final Path pom; + private final String projectKey; + private final String projectName; + + private ProjectToAnalyze(URI pom, String projectKey, String projectName) { + this.pom = Path.of(pom); + assertThat(this.pom).isRegularFile(); + this.projectKey = projectKey; + this.projectName = projectName; + } + + public MavenBuild createMavenBuild() { + return MavenBuild.create(pom.toFile()) + .setCleanPackageSonarGoals() + .setProperty("sonar.projectKey", projectKey) + .setProperty("sonar.projectName", projectName) + .setProperty("sonar.scm.disabled", "true"); + } + + private void provisionProjectIntoServer(Server server) { + server.provisionProject(projectKey, projectName); + + } + + private void associateProjectToQualityProfile(Server server, Map qualityProfileByLanguage) { + qualityProfileByLanguage.forEach((language, profileName) -> server.associateProjectToQualityProfile(projectKey, language, profileName)); + } + } + + private static List issuesForFile(String projectKey, String file) { + return issuesForComponent(projectKey + ":" + file); + } + + private static List issuesForComponent(String componentKey) { + return newWsClient(orchestrator) + .issues() + .search(new SearchRequest().setComponentKeys(Collections.singletonList(componentKey))) + .getIssuesList(); + } + + private static Map getMeasures(String componentKey) { + List metricKeys = List.of( + "alert_status", + "blocker_violations", + "branch_coverage", + "bugs", + "class_complexity", + "classes", + "code_smells", + "cognitive_complexity", + "comment_lines", + "comment_lines_data", + "comment_lines_density", + "complexity", + "complexity_in_classes", + "complexity_in_functions", + "conditions_to_cover", + "confirmed_issues", + "coverage", + "critical_violations", + "development_cost", + "directories", + "duplicated_blocks", + "duplicated_files", + "duplicated_lines", + "duplicated_lines_density", + "duplications_data", + "effort_to_reach_maintainability_rating_a", + "executable_lines_data", + "false_positive_issues", + "file_complexity", + "file_complexity_distribution", + "files", + "function_complexity", + "function_complexity_distribution", + "functions", + "generated_lines", + "generated_ncloc", + "info_violations", + "last_commit_date", + "line_coverage", + "lines", + "lines_to_cover", + "major_violations", + "minor_violations", + "ncloc", + "ncloc_data", + "ncloc_language_distribution", + "new_blocker_violations", + "new_branch_coverage", + "new_bugs", + "new_code_smells", + "new_conditions_to_cover", + "new_coverage", + "new_critical_violations", + "new_development_cost", + "new_duplicated_blocks", + "new_duplicated_lines", + "new_duplicated_lines_density", + "new_info_violations", + "new_line_coverage", + "new_lines", + "new_lines_to_cover", + "new_maintainability_rating", + "new_major_violations", + "new_minor_violations", + "new_reliability_rating", + "new_reliability_remediation_effort", + "new_security_hotspots", + "new_security_hotspots_reviewed", + "new_security_hotspots_reviewed_status", + "new_security_hotspots_to_review_status", + "new_security_rating", + "new_security_remediation_effort", + "new_security_review_rating", + "new_technical_debt", + "new_violations", + "new_vulnerabilities", + "open_issues", + "projects", + "public_api", + "public_documented_api_density", + "public_undocumented_api", + "quality_gate_details", + "quality_profiles", + "reliability_rating", + "reliability_remediation_effort", + "reopened_issues", + "security_hotspots", + "security_hotspots_reviewed", + "security_hotspots_reviewed_status", + "security_hotspots_to_review_status", + "security_rating", + "security_remediation_effort", + "security_review_rating", + "skipped_tests", + "sqale_rating", + "statements", + "unanalyzed_c", + "unanalyzed_cpp", + "violations" + ); + return newWsClient(orchestrator) + .measures() + .component( + new ComponentRequest() + .setComponent(componentKey) + .setMetricKeys(metricKeys) + ) + .getComponent().getMeasuresList() + .stream() + .collect(Collectors.toMap(Measures.Measure::getMetric, Function.identity())); + } + + + private static WsClient newWsClient(Orchestrator orchestrator) { + return WsClientFactories.getDefault().newClient(HttpConnector.newBuilder() + .url(orchestrator.getServer().getUrl()) + .build()); + } +} \ No newline at end of file diff --git a/src/it/java/io/ecocode/java/integration/tests/profile/ProfileBackup.java b/src/it/java/io/ecocode/java/integration/tests/profile/ProfileBackup.java new file mode 100644 index 00000000..4b672876 --- /dev/null +++ b/src/it/java/io/ecocode/java/integration/tests/profile/ProfileBackup.java @@ -0,0 +1,163 @@ +package io.ecocode.java.integration.tests.profile; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; +import java.text.MessageFormat; +import java.util.Base64; +import java.util.List; +import java.util.stream.Collectors; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES; + +/** + * Manage XML Backup file of profile based on JSON official profile. + * + *

Example, following JSON profile:

+ *
+ * {
+ *  "name": "ecoCode way",
+ *  "language": "java",
+ *  "ruleKeys": [
+ * 	    "EC1",
+ * 	    "EC2"
+ *  ]
+ * }
+ * 
+ *

may produce following XML profile:

+ *
+ * <?xml version='1.0' encoding='UTF-8'?>
+ * <profile>
+ * 	<name>ecoCode way</name>
+ * 	<language>java</language>
+ * 	<rules>
+ * 		<rule>
+ * 			<repositoryKey>ecocode-java</repositoryKey>
+ * 			<key>EC1</key>
+ * 			<type>CODE_SMELL</type>
+ * 			<priority>MINOR</priority>
+ * 			<parameters />
+ * 		</rule>
+ * 		<rule>
+ * 			<repositoryKey>ecocode-java</repositoryKey>
+ * 			<key>EC2</key>
+ * 			<type>CODE_SMELL</type>
+ * 			<priority>MINOR</priority>
+ * 			<parameters />
+ * 		</rule>
+ * 	</rules>
+ * </profile>
+ * 
+ */ +public class ProfileBackup { + private static final MessageFormat TEMPLATE_PROFIL = new MessageFormat( + "\n" + + "\n" + + " {0}\n" + + " {1}\n" + + " \n" + + " {2}\n" + + " \n" + + "\n" + ); + private static final MessageFormat TEMPLATE_RULE = new MessageFormat( + "\n" + + " {0}\n" + + " {1}\n" + + " {2}\n" + + " {3}\n" + + " \n" + + "\n" + ); + + private final ObjectMapper mapper; + private final URI jsonProfile; + + public ProfileBackup(URI jsonProfile) { + this.mapper = new ObjectMapper(); + // Ignore unknown properties + this.mapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false); + + this.jsonProfile = jsonProfile; + } + + private transient ProfileMetadata profileMetadata; + + private ProfileMetadata profileMetadata() { + if (profileMetadata == null) { + try (InputStream profilJsonFile = jsonProfile.toURL().openStream()) { + profileMetadata = mapper.readValue(profilJsonFile, ProfileMetadata.class); + } catch (IOException e) { + throw new RuntimeException("Unable to load JSON Profile: " + jsonProfile, e); + } + } + return profileMetadata; + } + + private RuleMetadata loadRule(String language, String ruleKey) { + try (InputStream ruleMetadataJsonFile = ClassLoader.getSystemResourceAsStream("io/ecocode/rules/" + language + "/" + ruleKey + ".json")) { + RuleMetadata result = mapper.readValue(ruleMetadataJsonFile, RuleMetadata.class); + result.setKey(ruleKey); + return result; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private String xmlProfile() throws IOException { + ProfileMetadata profileMetadata = profileMetadata(); + String language = profileMetadata.getLanguage(); + List rules = profileMetadata.getRuleKeys().stream() + .map(ruleKey -> this.loadRule(language, ruleKey)) + .collect(Collectors.toList()); + StringBuilder output = new StringBuilder(); + String repositoryKey = "ecocode-" + profileMetadata.getLanguage(); + rules.forEach(rule -> output.append( + xmlRule( + repositoryKey, + rule.getKey(), + rule.getType(), + rule.getDefaultSeverity().toUpperCase() + )) + ); + return TEMPLATE_PROFIL.format(new Object[]{ + profileMetadata.getName(), + profileMetadata.getLanguage(), + output.toString() + }); + } + + private String xmlRule(String repositoryKey, String key, String type, String priority) { + return TEMPLATE_RULE.format(new Object[]{ + repositoryKey, + key, + type, + priority + }); + } + + /** + * Get the content of XML Profil in datauri format. + */ + public URL profileDataUri() { + try { + String xmlProfileContent = xmlProfile(); + String xmlProfileBase64encoded = Base64.getEncoder().encodeToString(xmlProfileContent.getBytes()); + return new URL("data:text/xml;base64," + xmlProfileBase64encoded); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public String language() { + return profileMetadata().getLanguage(); + } + + + public String name() { + return profileMetadata().getName(); + } +} \ No newline at end of file diff --git a/src/it/java/io/ecocode/java/integration/tests/profile/ProfileMetadata.java b/src/it/java/io/ecocode/java/integration/tests/profile/ProfileMetadata.java new file mode 100644 index 00000000..85b65f41 --- /dev/null +++ b/src/it/java/io/ecocode/java/integration/tests/profile/ProfileMetadata.java @@ -0,0 +1,42 @@ +package io.ecocode.java.integration.tests.profile; + +import java.util.List; + +public class ProfileMetadata { + private String name; + private String language; + private List ruleKeys; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + public List getRuleKeys() { + return ruleKeys; + } + + public void setRuleKeys(List ruleKeys) { + this.ruleKeys = ruleKeys; + } + + @Override + public String toString() { + return "ProfileMetadata{" + + "name='" + name + '\'' + + ", language='" + language + '\'' + + ", ruleKeys=" + ruleKeys + + '}'; + } +} diff --git a/src/it/java/io/ecocode/java/integration/tests/profile/RuleMetadata.java b/src/it/java/io/ecocode/java/integration/tests/profile/RuleMetadata.java new file mode 100644 index 00000000..21bd763a --- /dev/null +++ b/src/it/java/io/ecocode/java/integration/tests/profile/RuleMetadata.java @@ -0,0 +1,40 @@ +package io.ecocode.java.integration.tests.profile; + +public class RuleMetadata { + private String key; + private String type; + private String defaultSeverity; + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getDefaultSeverity() { + return defaultSeverity; + } + + public void setDefaultSeverity(String defaultSeverity) { + this.defaultSeverity = defaultSeverity; + } + + @Override + public String toString() { + return "RuleMetadata{" + + "key='" + key + '\'' + + ", type='" + type + '\'' + + ", defaultSeverity='" + defaultSeverity + '\'' + + '}'; + } +} From 177b20ffb250345a78a3617bc1d0df18982d8c42 Mon Sep 17 00:00:00 2001 From: jycr Date: Tue, 29 Oct 2024 15:55:26 +0100 Subject: [PATCH 080/233] Updates documentation and changelog --- CHANGELOG.md | 1 + README.md | 28 ++++++++----------- pom.xml | 4 +-- .../LaunchSonarqubeAndBuildProjectIT.java | 14 ++++++++-- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bec3316..467e7113 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index a28c0586..dff59056 100644 --- a/README.md +++ b/README.md @@ -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 -``` -... 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). +NB: To install other `ecocode` plugins, you can : +- 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 ------------------ diff --git a/pom.xml b/pom.xml index 9c9e681f..0da8b0b3 100644 --- a/pom.xml +++ b/pom.xml @@ -86,7 +86,7 @@ ${sonarjava.version} - + @@ -466,7 +466,7 @@ ${project.baseUri}/target/${project.artifactId}-${project.version}.jar, - org.sonarsource.java|sonar-java-plugin|${test-it.sonarjava.version}, + org.sonarsource.java:sonar-java-plugin:${test-it.sonarjava.version}, diff --git a/src/it/java/io/ecocode/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java b/src/it/java/io/ecocode/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java index f865cc18..279e141e 100644 --- a/src/it/java/io/ecocode/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java +++ b/src/it/java/io/ecocode/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java @@ -218,6 +218,10 @@ private static Stream pipeSeparatedValues(String value) { return splitAndTrim(value, "\\s*\\|\\s*"); } + private static Stream colonSeparatedValues(String value) { + return splitAndTrim(value, "\\s*\\:\\s*"); + } + private static Stream splitAndTrim(String value, String regexSeparator) { return Stream .of(value.split(regexSeparator)) @@ -226,9 +230,13 @@ private static Stream splitAndTrim(String value, String regexSeparator) } private static Set additionalPluginsToInstall() { - return commaSeparatedValues(systemProperty("test-it.plugins")) + Set plugins = commaSeparatedValues(systemProperty("test-it.plugins")) .map(LaunchSonarqubeAndBuildProjectIT::toPluginLocation) .collect(Collectors.toSet()); + commaSeparatedValues(System.getProperty("test-it.additional-plugins", "")) + .map(LaunchSonarqubeAndBuildProjectIT::toPluginLocation) + .forEach(plugins::add); + return plugins; } private static Set additionalProfiles() { @@ -262,9 +270,9 @@ private static Location toPluginLocation(String location) { throw new IllegalArgumentException(e); } } - List pluginGAVvalues = pipeSeparatedValues(location).collect(toList()); + List pluginGAVvalues = colonSeparatedValues(location).collect(toList()); if (pluginGAVvalues.size() != 3) { - throw new IllegalArgumentException("Invalid plugin GAV definition (`groupId|artifactId|version`): " + location); + throw new IllegalArgumentException("Invalid plugin GAV definition (`groupId:artifactId:version`): " + location); } return MavenLocation.of( // groupId From 8a2dd086e0fb9c7d5beaac7a28b008042ab570a1 Mon Sep 17 00:00:00 2001 From: jycr Date: Tue, 29 Oct 2024 16:20:15 +0100 Subject: [PATCH 081/233] Upgrade Java for Maven build (keep target compilation to Java 11) --- .github/workflows/build.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b6e2d7e4..bcfbdeab 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 @@ -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: From 7cd4b19cc0c48751c16101dd10c28a3cc0fea2d0 Mon Sep 17 00:00:00 2001 From: jycr Date: Wed, 30 Oct 2024 23:48:44 +0100 Subject: [PATCH 082/233] Remove no longer necessary files --- .../.gitignore | 4 - .../LICENCE.md | 674 ------------------ .../README.md | 37 - .../tool_send_to_sonar.sh | 8 - 4 files changed, 723 deletions(-) delete mode 100644 src/it/test-projects/ecocode-java-plugin-test-project/.gitignore delete mode 100644 src/it/test-projects/ecocode-java-plugin-test-project/LICENCE.md delete mode 100644 src/it/test-projects/ecocode-java-plugin-test-project/README.md delete mode 100755 src/it/test-projects/ecocode-java-plugin-test-project/tool_send_to_sonar.sh diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/.gitignore b/src/it/test-projects/ecocode-java-plugin-test-project/.gitignore deleted file mode 100644 index b4130041..00000000 --- a/src/it/test-projects/ecocode-java-plugin-test-project/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -!.gitignore -.* -target -*.iml diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/LICENCE.md b/src/it/test-projects/ecocode-java-plugin-test-project/LICENCE.md deleted file mode 100644 index 20d40b6b..00000000 --- a/src/it/test-projects/ecocode-java-plugin-test-project/LICENCE.md +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. \ No newline at end of file diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/README.md b/src/it/test-projects/ecocode-java-plugin-test-project/README.md deleted file mode 100644 index b0da22da..00000000 --- a/src/it/test-projects/ecocode-java-plugin-test-project/README.md +++ /dev/null @@ -1,37 +0,0 @@ -Purpose of this project ---- - -To check locally all rules on java language. -To do this : - -- first launch local development environment (SonarQube) -- launch sonar maven command to send sonar metrics to local SonarQube -- on local SonarQube, check if each Java class contains (or not) the rule error defined for this class - -Step 1 : prepare local environment ---- - -To launch local environment : please follow https://github.com/green-code-initiative/ecoCode/blob/main/INSTALL.md -(especially SonarQube configuration part and get generated private token) - -Step 2 : compile and build ---- - -`./tool_build.sh` - -Step 3 : send Sonar metrics to local SonarQube ---- - -```sh -./tool_send_to_sonar.sh MY_SONAR_PORT MY_SONAR_TOKEN - -or - -mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.login=MY_SONAR_TOKEN -``` - -Step 4 : check errors ---- - -on local SonarQube, check if each Java class contains (or not) the rule error defined for this class -(for example : you can search for tag `eco-design` rule on a special file) diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/tool_send_to_sonar.sh b/src/it/test-projects/ecocode-java-plugin-test-project/tool_send_to_sonar.sh deleted file mode 100755 index cb663d98..00000000 --- a/src/it/test-projects/ecocode-java-plugin-test-project/tool_send_to_sonar.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env sh - -# "sonar.token" variable (or sonar.login before SONARQUBE 9.9) : private TOKEN generated in your local SonarQube during installation -# (input paramater of this script) -mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.host.url=http://localhost:$1 -Dsonar.token=$2 - -# command if you have a SONARQUBE < 9.9 (sonar.token existing for SONARQUBE >= 10.0) -# mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar -Dsonar.login=$1 From 61e760386696de3bf7fc0a172a6c65452ca731e7 Mon Sep 17 00:00:00 2001 From: jycr Date: Wed, 30 Oct 2024 23:53:51 +0100 Subject: [PATCH 083/233] Update compatibility matrix --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index dff59056..1af3e3bb 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ You can give a try with a one command: ... 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) - NB: To install other `ecocode` plugins, you can : + - 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. For example : @@ -57,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). From f209741130262f0d53e60a3620d3c7823a9035f9 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Sun, 3 Nov 2024 22:14:51 +0100 Subject: [PATCH 084/233] update version + README.md --- README.md | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1af3e3bb..9c130f9b 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Ready to use binaries are available [from GitHub](https://github.com/green-code- | 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) | +| 1.7.+ | 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). diff --git a/pom.xml b/pom.xml index 0da8b0b3..9a15a966 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.ecocode ecocode-java-plugin - 1.6.3-SNAPSHOT + 1.7.0-SNAPSHOT sonar-plugin From 7d6784219b6ae8d0e6d70d4857fd01efb5a0d6df Mon Sep 17 00:00:00 2001 From: Vincent Marmin <3215889+vincent314@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:12:17 +0100 Subject: [PATCH 085/233] chore: rename rule keys ECXXX to the Green Code Initiative naming convention GCIXXX --- CHANGELOG.md | 1 + pom.xml | 10 +++---- .../LaunchSonarqubeAndBuildProjectIT.java | 4 +-- .../tests/profile/ProfileBackup.java | 10 +++---- .../java/JavaRulesDefinition.java | 2 +- .../java/checks/ArrayCopyCheck.java | 2 +- .../java/checks/AvoidFullSQLRequest.java | 2 +- .../AvoidGettingSizeCollectionInLoop.java | 2 +- .../checks/AvoidMultipleIfElseStatement.java | 2 +- .../checks/AvoidRegexPatternNotStatic.java | 2 +- .../java/checks/AvoidSQLRequestInLoop.java | 2 +- .../checks/AvoidSetConstantInBatchUpdate.java | 2 +- ...ringRepositoryCallInLoopOrStreamCheck.java | 2 +- .../checks/AvoidStatementForDMLQueries.java | 2 +- .../checks/AvoidUsageOfStaticCollections.java | 2 +- ...FreeResourcesOfAutoCloseableInterface.java | 2 +- .../java/checks/IncrementCheck.java | 2 +- .../InitializeBufferWithAppropriateSize.java | 2 +- .../NoFunctionCallWhenDeclaringForLoop.java | 2 +- .../checks/OptimizeReadFileExceptions.java | 2 +- .../java/ecoCode_way_profile.json | 30 +++++++++---------- .../java/JavaRulesDefinitionTest.java | 6 ++-- 22 files changed, 47 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 467e7113..c6a598bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#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 +- Rename rules ECXXX to the new Green Code Initiative naming convention GCIXXX ### Changed diff --git a/pom.xml b/pom.xml index 9a15a966..5af212f4 100644 --- a/pom.xml +++ b/pom.xml @@ -71,8 +71,8 @@ 1.7 - - 1.6.5 + + main-SNAPSHOT https://repo1.maven.org/maven2 @@ -91,9 +91,9 @@ - ${project.groupId} - ecocode-rules-specifications - ${ecocode-rules-specifications.version} + org.green-code-initiative + creedengo-rules-specifications + ${creedengo-rules-specifications.version} java diff --git a/src/it/java/io/ecocode/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java b/src/it/java/io/ecocode/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java index 279e141e..aa487a47 100644 --- a/src/it/java/io/ecocode/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java +++ b/src/it/java/io/ecocode/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java @@ -141,7 +141,7 @@ void test() { assertThat(issuesForArrayCopyCheck) .hasSize(1) .first().satisfies(issue -> { - assertThat(issue.getRule()).isEqualTo("ecocode-java:EC69"); + assertThat(issue.getRule()).isEqualTo("ecocode-java:GCI69"); assertThat(issue.getSeverity()).isEqualTo(MINOR); assertThat(issue.getLine()).isEqualTo(18); assertThat(issue.getTextRange().getStartLine()).isEqualTo(18); @@ -445,4 +445,4 @@ private static WsClient newWsClient(Orchestrator orchestrator) { .url(orchestrator.getServer().getUrl()) .build()); } -} \ No newline at end of file +} diff --git a/src/it/java/io/ecocode/java/integration/tests/profile/ProfileBackup.java b/src/it/java/io/ecocode/java/integration/tests/profile/ProfileBackup.java index 4b672876..43cadad2 100644 --- a/src/it/java/io/ecocode/java/integration/tests/profile/ProfileBackup.java +++ b/src/it/java/io/ecocode/java/integration/tests/profile/ProfileBackup.java @@ -22,8 +22,8 @@ * "name": "ecoCode way", * "language": "java", * "ruleKeys": [ - * "EC1", - * "EC2" + * "GCI1", + * "GCI2" * ] * } * @@ -36,14 +36,14 @@ * <rules> * <rule> * <repositoryKey>ecocode-java</repositoryKey> - * <key>EC1</key> + * <key>GCI1</key> * <type>CODE_SMELL</type> * <priority>MINOR</priority> * <parameters /> * </rule> * <rule> * <repositoryKey>ecocode-java</repositoryKey> - * <key>EC2</key> + * <key>GCI2</key> * <type>CODE_SMELL</type> * <priority>MINOR</priority> * <parameters /> @@ -160,4 +160,4 @@ public String language() { public String name() { return profileMetadata().getName(); } -} \ No newline at end of file +} diff --git a/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java b/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java index f9e03e30..f71aa81f 100644 --- a/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java +++ b/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java @@ -28,7 +28,7 @@ * That allows to list the rules in the page "Rules". */ public class JavaRulesDefinition implements RulesDefinition { - private static final String RESOURCE_BASE_PATH = "io/ecocode/rules/java"; + private static final String RESOURCE_BASE_PATH = "org/green-code-initiative/rules/java"; private static final String NAME = "ecoCode"; static final String LANGUAGE = "java"; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java index b594af9d..c4f642ef 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java @@ -53,7 +53,7 @@ * @author Aubay * @formatter:off */ -@Rule(key = "EC27") +@Rule(key = "GCI27") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "GRPS0027") public class ArrayCopyCheck extends IssuableSubscriptionVisitor { diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequest.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequest.java index 88ff715c..5b9c9dd2 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequest.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequest.java @@ -31,7 +31,7 @@ import org.sonar.plugins.java.api.tree.Tree.Kind; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule(key = "EC74") +@Rule(key = "GCI74") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S74") public class AvoidFullSQLRequest extends IssuableSubscriptionVisitor { diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java index c81d7953..9e8c247d 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java @@ -34,7 +34,7 @@ import org.sonar.plugins.java.api.tree.WhileStatementTree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule(key = "EC3") +@Rule(key = "GCI3") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "GSCIL") public class AvoidGettingSizeCollectionInLoop extends IssuableSubscriptionVisitor { protected static final String MESSAGERULE = "Avoid getting the size of the collection in the loop"; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java index 4dc77baa..c16c9b73 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java @@ -43,7 +43,7 @@ * - an "ELSE" statement is considered as a second IF statement using the same variables used on previous * - IF and ELSEIF statements are considered as an IF statement */ -@Rule(key = "EC2") +@Rule(key = "GCI2") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "AMIES") public class AvoidMultipleIfElseStatement extends IssuableSubscriptionVisitor { diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java index 2561a6c0..3384e1d6 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java @@ -32,7 +32,7 @@ import org.sonar.plugins.java.api.tree.Tree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule(key = "EC77") +@Rule(key = "GCI77") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S77") public class AvoidRegexPatternNotStatic extends IssuableSubscriptionVisitor { diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java index 1e3aab82..99ddd555 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java @@ -30,7 +30,7 @@ import org.sonar.plugins.java.api.tree.Tree.Kind; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule(key = "EC72") +@Rule(key = "GCI72") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S72") public class AvoidSQLRequestInLoop extends IssuableSubscriptionVisitor { diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java index 4fe31abd..0ad96d1a 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java @@ -39,7 +39,7 @@ import static org.sonar.plugins.java.api.tree.Tree.Kind.MEMBER_SELECT; import static org.sonar.plugins.java.api.tree.Tree.Kind.METHOD_INVOCATION; -@Rule(key = "EC78") +@Rule(key = "GCI78") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S78") public class AvoidSetConstantInBatchUpdate extends IssuableSubscriptionVisitor { diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java index 3222799c..bf0e408a 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java @@ -26,7 +26,7 @@ import org.sonar.plugins.java.api.tree.*; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule(key = "EC1") +@Rule(key = "GCI1") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "GRC1") public class AvoidSpringRepositoryCallInLoopOrStreamCheck extends IssuableSubscriptionVisitor { diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java index 592f92cb..99b5209f 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java @@ -31,7 +31,7 @@ import org.sonar.plugins.java.api.tree.Tree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule(key = "EC5") +@Rule(key = "GCI5") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "SDMLQ1") public class AvoidStatementForDMLQueries extends IssuableSubscriptionVisitor { diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java index 18a7fb7f..544899e3 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java @@ -30,7 +30,7 @@ import org.sonar.plugins.java.api.tree.VariableTree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule(key = "EC76") +@Rule(key = "GCI76") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S76") public class AvoidUsageOfStaticCollections extends IssuableSubscriptionVisitor { diff --git a/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java b/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java index 47cbc2eb..a7515428 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java @@ -35,7 +35,7 @@ import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule(key = "EC79") +@Rule(key = "GCI79") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S79") public class FreeResourcesOfAutoCloseableInterface extends IssuableSubscriptionVisitor { private final Deque withinTry = new LinkedList<>(); diff --git a/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java index 00c3094d..9b73a1d8 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java @@ -26,7 +26,7 @@ import org.sonar.plugins.java.api.tree.Tree.Kind; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule(key = "EC67") +@Rule(key = "GCI67") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S67") public class IncrementCheck extends IssuableSubscriptionVisitor { diff --git a/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java b/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java index 44caa872..d86f53d4 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java @@ -27,7 +27,7 @@ import org.sonar.plugins.java.api.tree.Tree.Kind; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule(key = "EC32") +@Rule(key = "GCI32") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "GRSP0032") public class InitializeBufferWithAppropriateSize extends IssuableSubscriptionVisitor { diff --git a/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java index d4088bd2..461cac30 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java @@ -37,7 +37,7 @@ import org.sonar.plugins.java.api.tree.Tree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule(key = "EC69") +@Rule(key = "GCI69") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S69") public class NoFunctionCallWhenDeclaringForLoop extends IssuableSubscriptionVisitor { diff --git a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java index 2362404b..7a7fddaf 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java @@ -32,7 +32,7 @@ import org.sonar.plugins.java.api.tree.TryStatementTree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; -@Rule(key = "EC28") +@Rule(key = "GCI28") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "GRSP0028") public class OptimizeReadFileExceptions extends IssuableSubscriptionVisitor { diff --git a/src/main/resources/fr/greencodeinitiative/java/ecoCode_way_profile.json b/src/main/resources/fr/greencodeinitiative/java/ecoCode_way_profile.json index 88e381ae..9bb5d9ec 100644 --- a/src/main/resources/fr/greencodeinitiative/java/ecoCode_way_profile.json +++ b/src/main/resources/fr/greencodeinitiative/java/ecoCode_way_profile.json @@ -2,20 +2,20 @@ "name": "ecoCode way", "language": "java", "ruleKeys": [ - "EC1", - "EC2", - "EC3", - "EC5", - "EC27", - "EC28", - "EC32", - "EC67", - "EC69", - "EC72", - "EC74", - "EC76", - "EC77", - "EC78", - "EC79" + "GCI1", + "GCI2", + "GCI3", + "GCI5", + "GCI27", + "GCI28", + "GCI32", + "GCI67", + "GCI69", + "GCI72", + "GCI74", + "GCI76", + "GCI77", + "GCI78", + "GCI79" ] } diff --git a/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java b/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java index ee6dff5b..3db32ecd 100644 --- a/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java +++ b/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java @@ -61,18 +61,18 @@ void testRegistredRules() { } @Test - @DisplayName("All rule keys must be prefixed by 'EC'") + @DisplayName("All rule keys must be prefixed by 'GCI'") void testRuleKeyPrefix() { SoftAssertions assertions = new SoftAssertions(); repository.rules().forEach( - rule -> assertions.assertThat(rule.key()).startsWith("EC") + rule -> assertions.assertThat(rule.key()).startsWith("GCI") ); assertions.assertAll(); } @Test void assertRuleProperties() { - Rule rule = repository.rule("EC67"); + Rule rule = repository.rule("GCI67"); assertThat(rule).isNotNull(); assertThat(rule.name()).isEqualTo("Use ++i instead of i++"); assertThat(rule.debtRemediationFunction().type()).isEqualTo(Type.CONSTANT_ISSUE); From a0dbaea430727b60abb79b174110d5a0baeaf381 Mon Sep 17 00:00:00 2001 From: Vincent Marmin <3215889+vincent314@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:44:44 +0100 Subject: [PATCH 086/233] chore: move packages fr.green-code-initiative to org.green-code-initiative --- pom.xml | 4 +-- .../java/checks/ArrayCopyCheck.java | 4 +-- .../java/checks/AvoidFullSQLRequestCheck.java | 4 +-- ...ingSizeCollectionInForEachLoopIgnored.java | 4 +-- ...voidGettingSizeCollectionInForLoopBad.java | 4 +-- ...oidGettingSizeCollectionInForLoopGood.java | 4 +-- ...GettingSizeCollectionInForLoopIgnored.java | 4 +-- ...idGettingSizeCollectionInWhileLoopBad.java | 4 +-- ...dGettingSizeCollectionInWhileLoopGood.java | 4 +-- ...ttingSizeCollectionInWhileLoopIgnored.java | 4 +-- .../checks/AvoidMultipleIfElseStatement.java | 2 +- ...leIfElseStatementCompareMethodNoIssue.java | 2 +- ...ltipleIfElseStatementInterfaceNoIssue.java | 2 +- ...MultipleIfElseStatementNoBlockNoIssue.java | 2 +- .../AvoidMultipleIfElseStatementNoIssue.java | 2 +- .../checks/AvoidRegexPatternNotStatic.java | 2 +- .../checks/AvoidSQLRequestInLoopCheck.java | 4 +-- .../AvoidSetConstantInBatchUpdateCheck.java | 4 +-- .../AvoidSpringRepositoryCallInLoopCheck.java | 4 +-- ...voidSpringRepositoryCallInStreamCheck.java | 4 +-- .../checks/AvoidStatementForDMLQueries.java | 4 +-- .../checks/AvoidUsageOfStaticCollections.java | 2 +- ...FreeResourcesOfAutoCloseableInterface.java | 4 +-- .../checks/GoodUsageOfStaticCollections.java | 2 +- .../checks/GoodWayConcatenateStringsLoop.java | 2 +- .../java/checks/IncrementCheck.java | 4 +-- .../InitializeBufferWithAppropriateSize.java | 4 +-- .../NoFunctionCallWhenDeclaringForLoop.java | 4 +-- .../OptimizeReadFileExceptionCheck.java | 4 +-- .../OptimizeReadFileExceptionCheck2.java | 4 +-- .../OptimizeReadFileExceptionCheck3.java | 4 +-- .../OptimizeReadFileExceptionCheck4.java | 4 +-- .../OptimizeReadFileExceptionCheck5.java | 4 +-- .../checks/OptimizeSQLQueriesWithLimit.java | 4 +-- .../java/checks/ValidRegexPattern.java | 2 +- .../java/checks/ValidRegexPattern2.java | 2 +- .../java/checks/ValidRegexPattern3.java | 2 +- .../java/JavaCheckRegistrar.java | 32 +++++++++---------- .../java/JavaEcoCodeWayProfile.java | 6 ++-- .../greencodeinitiative/java/JavaPlugin.java | 2 +- .../java/JavaRulesDefinition.java | 2 +- .../java/checks/ArrayCopyCheck.java | 2 +- .../java/checks/AvoidFullSQLRequest.java | 2 +- .../AvoidGettingSizeCollectionInLoop.java | 2 +- .../checks/AvoidMultipleIfElseStatement.java | 2 +- .../checks/AvoidRegexPatternNotStatic.java | 2 +- .../java/checks/AvoidSQLRequestInLoop.java | 2 +- .../checks/AvoidSetConstantInBatchUpdate.java | 6 ++-- ...ringRepositoryCallInLoopOrStreamCheck.java | 2 +- .../checks/AvoidStatementForDMLQueries.java | 2 +- .../checks/AvoidUsageOfStaticCollections.java | 2 +- ...FreeResourcesOfAutoCloseableInterface.java | 2 +- .../java/checks/IncrementCheck.java | 2 +- .../InitializeBufferWithAppropriateSize.java | 2 +- .../NoFunctionCallWhenDeclaringForLoop.java | 2 +- .../checks/OptimizeReadFileExceptions.java | 2 +- .../checks/enums/ConstOrLiteralDeclare.java | 4 +-- .../java/utils/PrinterVisitor.java | 2 +- .../java/utils/StringUtils.java | 2 +- .../java/ecoCode_way_profile.json | 0 src/test/files/AvoidFullSQLRequestCheck.java | 4 +-- ...ingSizeCollectionInForEachLoopIgnored.java | 4 +-- ...voidGettingSizeCollectionInForLoopBad.java | 4 +-- ...oidGettingSizeCollectionInForLoopGood.java | 4 +-- ...GettingSizeCollectionInForLoopIgnored.java | 4 +-- ...idGettingSizeCollectionInWhileLoopBad.java | 4 +-- ...dGettingSizeCollectionInWhileLoopGood.java | 4 +-- ...ttingSizeCollectionInWhileLoopIgnored.java | 4 +-- .../files/AvoidMultipleIfElseStatement.java | 2 +- ...dMultipleIfElseStatementCompareMethod.java | 4 +-- ...AvoidMultipleIfElseStatementInterface.java | 2 +- .../AvoidMultipleIfElseStatementNoIssue.java | 2 +- .../AvoidMultipleIfElseStatementNotBlock.java | 4 +-- .../files/AvoidRegexPatternNotStatic.java | 2 +- .../files/AvoidSQLRequestInLoopCheck.java | 4 +-- .../AvoidSetConstantInBatchUpdateCheck.java | 4 +-- .../AvoidSpringRepositoryCallInLoopCheck.java | 4 +-- ...voidSpringRepositoryCallInStreamCheck.java | 4 +-- .../files/AvoidStatementForDMLQueries.java | 4 +-- .../files/AvoidUsageOfStaticCollections.java | 2 +- ...FreeResourcesOfAutoCloseableInterface.java | 6 ++-- .../files/GoodUsageOfStaticCollections.java | 2 +- .../files/GoodWayConcatenateStringsLoop.java | 2 +- .../InitializeBufferWithAppropriateSize.java | 4 +-- .../files/OptimizeReadFileExceptionCheck.java | 4 +-- .../OptimizeReadFileExceptionCheck2.java | 4 +-- .../OptimizeReadFileExceptionCheck3.java | 4 +-- .../OptimizeReadFileExceptionCheck4.java | 4 +-- .../OptimizeReadFileExceptionCheck5.java | 4 +-- src/test/files/ValidRegexPattern.java | 2 +- src/test/files/ValidRegexPattern2.java | 2 +- src/test/files/ValidRegexPattern3.java | 2 +- .../java/JavaCheckRegistrarTest.java | 2 +- .../java/JavaEcoCodeWayProfileTest.java | 10 +++--- .../java/JavaPluginTest.java | 2 +- .../java/JavaRulesDefinitionTest.java | 4 +-- .../java/checks/ArrayCopyCheckTest.java | 4 +-- .../checks/AvoidFullSQLRequestCheckTest.java | 4 +-- .../AvoidGettingSizeCollectionInLoopTest.java | 2 +- .../AvoidMultipleIfElseStatementTest.java | 2 +- .../AvoidRegexPatternNotStaticTest.java | 2 +- .../AvoidSQLRequestInLoopCheckTest.java | 4 +-- .../AvoidSetConstantInBatchInsertTest.java | 4 +-- ...idSpringRepositoryCallInLoopCheckTest.java | 4 +-- ...SpringRepositoryCallInStreamCheckTest.java | 4 +-- .../AvoidStatementForDMLQueriesTest.java | 2 +- .../AvoidUsageOfStaticCollectionsTests.java | 2 +- ...ResourcesOfAutoCloseableInterfaceTest.java | 4 +-- .../java/checks/IncrementCheckTest.java | 4 +-- ...itializeBufferWithAppropriateSizeTest.java | 4 +-- ...oFunctionCallWhenDeclaringForLoopTest.java | 2 +- .../OptimizeReadFileExceptionCheckTest.java | 2 +- .../java/utils/FilesUtils.java | 2 +- .../java/utils/StringUtilsTest.java | 2 +- 114 files changed, 195 insertions(+), 195 deletions(-) rename src/main/java/{fr => org}/greencodeinitiative/java/JavaCheckRegistrar.java (72%) rename src/main/java/{fr => org}/greencodeinitiative/java/JavaEcoCodeWayProfile.java (89%) rename src/main/java/{fr => org}/greencodeinitiative/java/JavaPlugin.java (97%) rename src/main/java/{fr => org}/greencodeinitiative/java/JavaRulesDefinition.java (98%) rename src/main/java/{fr => org}/greencodeinitiative/java/checks/ArrayCopyCheck.java (99%) rename src/main/java/{fr => org}/greencodeinitiative/java/checks/AvoidFullSQLRequest.java (97%) rename src/main/java/{fr => org}/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java (99%) rename src/main/java/{fr => org}/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java (99%) rename src/main/java/{fr => org}/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java (98%) rename src/main/java/{fr => org}/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java (98%) rename src/main/java/{fr => org}/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java (94%) rename src/main/java/{fr => org}/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java (99%) rename src/main/java/{fr => org}/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java (98%) rename src/main/java/{fr => org}/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java (98%) rename src/main/java/{fr => org}/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java (98%) rename src/main/java/{fr => org}/greencodeinitiative/java/checks/IncrementCheck.java (97%) rename src/main/java/{fr => org}/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java (97%) rename src/main/java/{fr => org}/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java (99%) rename src/main/java/{fr => org}/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java (98%) rename src/main/java/{fr => org}/greencodeinitiative/java/checks/enums/ConstOrLiteralDeclare.java (99%) rename src/main/java/{fr => org}/greencodeinitiative/java/utils/PrinterVisitor.java (98%) rename src/main/java/{fr => org}/greencodeinitiative/java/utils/StringUtils.java (96%) rename src/main/resources/{fr => org}/greencodeinitiative/java/ecoCode_way_profile.json (100%) rename src/test/java/{fr => org}/greencodeinitiative/java/JavaCheckRegistrarTest.java (97%) rename src/test/java/{fr => org}/greencodeinitiative/java/JavaEcoCodeWayProfileTest.java (84%) rename src/test/java/{fr => org}/greencodeinitiative/java/JavaPluginTest.java (97%) rename src/test/java/{fr => org}/greencodeinitiative/java/JavaRulesDefinitionTest.java (96%) rename src/test/java/{fr => org}/greencodeinitiative/java/checks/ArrayCopyCheckTest.java (96%) rename src/test/java/{fr => org}/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java (96%) rename src/test/java/{fr => org}/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java (98%) rename src/test/java/{fr => org}/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java (98%) rename src/test/java/{fr => org}/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java (97%) rename src/test/java/{fr => org}/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java (96%) rename src/test/java/{fr => org}/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java (96%) rename src/test/java/{fr => org}/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java (92%) rename src/test/java/{fr => org}/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java (93%) rename src/test/java/{fr => org}/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java (96%) rename src/test/java/{fr => org}/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java (97%) rename src/test/java/{fr => org}/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java (97%) rename src/test/java/{fr => org}/greencodeinitiative/java/checks/IncrementCheckTest.java (96%) rename src/test/java/{fr => org}/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java (96%) rename src/test/java/{fr => org}/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java (96%) rename src/test/java/{fr => org}/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java (97%) rename src/test/java/{fr => org}/greencodeinitiative/java/utils/FilesUtils.java (98%) rename src/test/java/{fr => org}/greencodeinitiative/java/utils/StringUtilsTest.java (97%) diff --git a/pom.xml b/pom.xml index 5af212f4..eda274bc 100644 --- a/pom.xml +++ b/pom.xml @@ -238,7 +238,7 @@ true ecocodejava - fr.greencodeinitiative.java.JavaPlugin + org.greencodeinitiative.java.JavaPlugin true ${sonarqube.version} true @@ -470,7 +470,7 @@ - ${project.baseUri}/src/main/resources/fr/greencodeinitiative/java/ecoCode_way_profile.json, + ${project.baseUri}/src/main/resources/org/greencodeinitiative/java/ecoCode_way_profile.json, diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java index adee2b5d..85197155 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Arrays; @@ -490,4 +490,4 @@ private boolean transform(boolean a) { return !a; } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheck.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheck.java index 45c277e6..5fbcf140 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheck.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheck.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; class AvoidFullSQLRequestCheck { AvoidFullSQLRequestCheck(AvoidFullSQLRequestCheck mc) { @@ -27,4 +27,4 @@ private void dummyCall(String request) { } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java index 467899dd..fbec63c7 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.ArrayList; import java.util.List; @@ -18,4 +18,4 @@ public void ignoredLoop() { System.out.println("numberList.size()"); } } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopBad.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopBad.java index f9905260..782ffbec 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopBad.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopBad.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.ArrayList; import java.util.List; @@ -17,4 +17,4 @@ public void badForLoop() { System.out.println("numberList.size()"); } } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopGood.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopGood.java index fed87f5d..20bfd37f 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopGood.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopGood.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Collection; import java.util.ArrayList; @@ -20,4 +20,4 @@ public void goodForLoop() { int size2 = numberList.size(); // Compliant with this rule } } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java index d9c4d51b..e12525b0 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.ArrayList; import java.util.Iterator; @@ -20,4 +20,4 @@ public void badForLoop() { System.out.println("numberList.size()"); } } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java index 9b6fae75..858db7bc 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.ArrayList; import java.util.List; @@ -19,4 +19,4 @@ public void badWhileLoop() { i++; } } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java index b88e73aa..774589c2 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.ArrayList; import java.util.List; @@ -21,4 +21,4 @@ public void goodWhileLoop() { i++; } } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java index 62ed1fc4..60f82d79 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.ArrayList; import java.util.Iterator; @@ -21,4 +21,4 @@ public void badWhileLoop() { System.out.println("numberList.size()"); } } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java index 329342a2..2127b164 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; class AvoidMultipleIfElseStatement { diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java index 573cdc9e..c2c60686 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; class AvoidMultipleIfElseStatementCompareMethodNoIssue { diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java index 1409a4e2..37d87eb6 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; interface AvoidMultipleIfElseStatementInterfaceNoIssue { diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java index d66bfed1..b120cee0 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; class AvoidMultipleIfElseStatementNoBlockNoIssue { diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java index f4260daa..2c4a87da 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; class AvoidMultipleIfElseStatementNoIssue { diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java index 0474e452..6ca37ede 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.regex.Pattern; diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheck.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheck.java index 4981d0b4..b0a7929c 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheck.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheck.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.sql.Connection; import java.sql.DriverManager; @@ -131,4 +131,4 @@ public void testWithWhileLoop() { } } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java index 41bb443a..57f9b046 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.math.BigDecimal; import java.sql.Connection; @@ -148,4 +148,4 @@ public double getField4() { } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java index ee932983..bc6c276f 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.repository.JpaRepository; @@ -54,4 +54,4 @@ public interface EmployeeRepository extends JpaRepository { } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java index 38fa0103..746b77bf 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.repository.JpaRepository; @@ -122,4 +122,4 @@ public Employee(Integer id, String name) { public interface EmployeeRepository extends JpaRepository { } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java index 87204a67..94bd2d86 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.sql.Connection; import java.sql.DriverManager; @@ -17,4 +17,4 @@ public void insert() throws SQLException { Statement statement = connection.createStatement(); statement.executeUpdate("INSERT INTO persons(id, name) VALUES(2, 'Toto')"); // Noncompliant {{You must not use Statement for a DML query}} } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java index ac1b9f0d..85b078d9 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.*; diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java index 06dc1918..741b5a7a 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.io.*; @@ -35,4 +35,4 @@ public void foo2() throws IOException { } } } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/GoodUsageOfStaticCollections.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/GoodUsageOfStaticCollections.java index 8f8e55c7..e5006c45 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/GoodUsageOfStaticCollections.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/GoodUsageOfStaticCollections.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.*; diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/GoodWayConcatenateStringsLoop.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/GoodWayConcatenateStringsLoop.java index 6f279edd..55455686 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/GoodWayConcatenateStringsLoop.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/GoodWayConcatenateStringsLoop.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; public class GoodWayConcatenateStringsLoop { diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java index a88292b4..35210be4 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; class IncrementCheck { IncrementCheck(IncrementCheck mc) { @@ -45,4 +45,4 @@ void foo51(int value) { System.out.println(i); } } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java index a02cc362..2c38adc7 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; class InitializeBufferWithAppropriateSize { InitializeBufferWithAppropriateSize(InitializeBufferWithAppropriateSize mc) { @@ -23,4 +23,4 @@ public void testBuilderCompliant() { public void testBuilderNonCompliant() { StringBuilder stringBuilder = new StringBuilder(); // Noncompliant {{Initialize StringBuilder or StringBuffer with appropriate size}} } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java index 28da0a82..41ca01e7 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; class NoFunctionCallWhenDeclaringForLoop { NoFunctionCallWhenDeclaringForLoop(NoFunctionCallWhenDeclaringForLoop mc) { @@ -55,4 +55,4 @@ public void test6() { } } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck.java index 69911227..1b07e9d8 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -26,4 +26,4 @@ public void readPreferences(String filename) { } //... } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck2.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck2.java index 9b0833dd..fb7eeac2 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck2.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck2.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -24,4 +24,4 @@ public void readPreferences(String filename) throws IOException { } //... } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck3.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck3.java index 18c23448..eef28168 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck3.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck3.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.io.FileInputStream; import java.io.IOException; @@ -23,4 +23,4 @@ public void readPreferences(String filename) { } //... } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck4.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck4.java index 38435808..b5fba918 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck4.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck4.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.io.FileInputStream; import java.io.InputStream; @@ -22,4 +22,4 @@ public void readPreferences(String filename) { } //... } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck5.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck5.java index 7a0e84ab..7343b86c 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck5.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck5.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.io.FileInputStream; import java.io.InputStream; @@ -22,4 +22,4 @@ public void readPreferences(String filename) { } //... } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java index c21e2a4a..a00f2a97 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import org.springframework.data.jpa.repository.Query; @@ -29,4 +29,4 @@ private void callQuery() { private void dummyCall(String request) { } -} \ No newline at end of file +} diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern.java index 5ed3652f..66a001b4 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.regex.Pattern; diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern2.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern2.java index d6d9efd7..d8ec0756 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern2.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern2.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.regex.Pattern; diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern3.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern3.java index e1907345..8005b5c8 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern3.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern3.java @@ -1,4 +1,4 @@ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.regex.Pattern; diff --git a/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java b/src/main/java/org/greencodeinitiative/java/JavaCheckRegistrar.java similarity index 72% rename from src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java rename to src/main/java/org/greencodeinitiative/java/JavaCheckRegistrar.java index 50ada183..72b63d1c 100644 --- a/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java +++ b/src/main/java/org/greencodeinitiative/java/JavaCheckRegistrar.java @@ -15,26 +15,26 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java; +package org.greencodeinitiative.java; import java.util.Collections; import java.util.List; -import fr.greencodeinitiative.java.checks.ArrayCopyCheck; -import fr.greencodeinitiative.java.checks.AvoidFullSQLRequest; -import fr.greencodeinitiative.java.checks.AvoidGettingSizeCollectionInLoop; -import fr.greencodeinitiative.java.checks.AvoidMultipleIfElseStatement; -import fr.greencodeinitiative.java.checks.AvoidRegexPatternNotStatic; -import fr.greencodeinitiative.java.checks.AvoidSQLRequestInLoop; -import fr.greencodeinitiative.java.checks.AvoidSetConstantInBatchUpdate; -import fr.greencodeinitiative.java.checks.AvoidSpringRepositoryCallInLoopOrStreamCheck; -import fr.greencodeinitiative.java.checks.AvoidStatementForDMLQueries; -import fr.greencodeinitiative.java.checks.AvoidUsageOfStaticCollections; -import fr.greencodeinitiative.java.checks.FreeResourcesOfAutoCloseableInterface; -import fr.greencodeinitiative.java.checks.IncrementCheck; -import fr.greencodeinitiative.java.checks.InitializeBufferWithAppropriateSize; -import fr.greencodeinitiative.java.checks.NoFunctionCallWhenDeclaringForLoop; -import fr.greencodeinitiative.java.checks.OptimizeReadFileExceptions; +import org.greencodeinitiative.java.checks.ArrayCopyCheck; +import org.greencodeinitiative.java.checks.AvoidFullSQLRequest; +import org.greencodeinitiative.java.checks.AvoidGettingSizeCollectionInLoop; +import org.greencodeinitiative.java.checks.AvoidMultipleIfElseStatement; +import org.greencodeinitiative.java.checks.AvoidRegexPatternNotStatic; +import org.greencodeinitiative.java.checks.AvoidSQLRequestInLoop; +import org.greencodeinitiative.java.checks.AvoidSetConstantInBatchUpdate; +import org.greencodeinitiative.java.checks.AvoidSpringRepositoryCallInLoopOrStreamCheck; +import org.greencodeinitiative.java.checks.AvoidStatementForDMLQueries; +import org.greencodeinitiative.java.checks.AvoidUsageOfStaticCollections; +import org.greencodeinitiative.java.checks.FreeResourcesOfAutoCloseableInterface; +import org.greencodeinitiative.java.checks.IncrementCheck; +import org.greencodeinitiative.java.checks.InitializeBufferWithAppropriateSize; +import org.greencodeinitiative.java.checks.NoFunctionCallWhenDeclaringForLoop; +import org.greencodeinitiative.java.checks.OptimizeReadFileExceptions; import org.sonar.plugins.java.api.CheckRegistrar; import org.sonar.plugins.java.api.JavaCheck; import org.sonarsource.api.sonarlint.SonarLintSide; diff --git a/src/main/java/fr/greencodeinitiative/java/JavaEcoCodeWayProfile.java b/src/main/java/org/greencodeinitiative/java/JavaEcoCodeWayProfile.java similarity index 89% rename from src/main/java/fr/greencodeinitiative/java/JavaEcoCodeWayProfile.java rename to src/main/java/org/greencodeinitiative/java/JavaEcoCodeWayProfile.java index d24fc82a..3046f8ec 100644 --- a/src/main/java/fr/greencodeinitiative/java/JavaEcoCodeWayProfile.java +++ b/src/main/java/org/greencodeinitiative/java/JavaEcoCodeWayProfile.java @@ -15,13 +15,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java; +package org.greencodeinitiative.java; import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; import org.sonarsource.analyzer.commons.BuiltInQualityProfileJsonLoader; -import static fr.greencodeinitiative.java.JavaRulesDefinition.LANGUAGE; -import static fr.greencodeinitiative.java.JavaRulesDefinition.REPOSITORY_KEY; +import static org.greencodeinitiative.java.JavaRulesDefinition.LANGUAGE; +import static org.greencodeinitiative.java.JavaRulesDefinition.REPOSITORY_KEY; public final class JavaEcoCodeWayProfile implements BuiltInQualityProfilesDefinition { static final String PROFILE_NAME = "ecoCode way"; diff --git a/src/main/java/fr/greencodeinitiative/java/JavaPlugin.java b/src/main/java/org/greencodeinitiative/java/JavaPlugin.java similarity index 97% rename from src/main/java/fr/greencodeinitiative/java/JavaPlugin.java rename to src/main/java/org/greencodeinitiative/java/JavaPlugin.java index ff070c1b..fc734139 100644 --- a/src/main/java/fr/greencodeinitiative/java/JavaPlugin.java +++ b/src/main/java/org/greencodeinitiative/java/JavaPlugin.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java; +package org.greencodeinitiative.java; import org.sonar.api.Plugin; diff --git a/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java b/src/main/java/org/greencodeinitiative/java/JavaRulesDefinition.java similarity index 98% rename from src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java rename to src/main/java/org/greencodeinitiative/java/JavaRulesDefinition.java index f71aa81f..57999df4 100644 --- a/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java +++ b/src/main/java/org/greencodeinitiative/java/JavaRulesDefinition.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java; +package org.greencodeinitiative.java; import java.util.ArrayList; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java b/src/main/java/org/greencodeinitiative/java/checks/ArrayCopyCheck.java similarity index 99% rename from src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java rename to src/main/java/org/greencodeinitiative/java/checks/ArrayCopyCheck.java index c4f642ef..d2e53acc 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java +++ b/src/main/java/org/greencodeinitiative/java/checks/ArrayCopyCheck.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.ArrayList; import java.util.Arrays; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequest.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequest.java similarity index 97% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequest.java rename to src/main/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequest.java index 5b9c9dd2..5706ae0e 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequest.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequest.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.List; import java.util.function.Predicate; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java similarity index 99% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java rename to src/main/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java index 9e8c247d..212f88ef 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java similarity index 99% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java rename to src/main/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java index c16c9b73..f39a047c 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java similarity index 98% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java rename to src/main/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java index 3384e1d6..3a43007a 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Collections; import java.util.List; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java similarity index 98% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java rename to src/main/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java index 99ddd555..af880418 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java similarity index 94% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java rename to src/main/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java index 0ad96d1a..dc8a4baf 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java @@ -15,14 +15,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.sql.PreparedStatement; import java.util.List; import java.util.stream.Stream; -import fr.greencodeinitiative.java.checks.enums.ConstOrLiteralDeclare; -import static fr.greencodeinitiative.java.checks.enums.ConstOrLiteralDeclare.isLiteral; +import org.greencodeinitiative.java.checks.enums.ConstOrLiteralDeclare; +import static org.greencodeinitiative.java.checks.enums.ConstOrLiteralDeclare.isLiteral; import static java.util.Arrays.asList; import org.sonar.check.Rule; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java similarity index 99% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java rename to src/main/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java index bf0e408a..f7c40992 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java similarity index 98% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java rename to src/main/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java index 99b5209f..3d261f24 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Collections; import java.util.List; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java similarity index 98% rename from src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java rename to src/main/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java index 544899e3..267c8bd4 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Collections; import java.util.List; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java b/src/main/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java similarity index 98% rename from src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java rename to src/main/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java index a7515428..7f24a380 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java +++ b/src/main/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.ArrayList; import java.util.Arrays; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java b/src/main/java/org/greencodeinitiative/java/checks/IncrementCheck.java similarity index 97% rename from src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java rename to src/main/java/org/greencodeinitiative/java/checks/IncrementCheck.java index 9b73a1d8..881a760a 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java +++ b/src/main/java/org/greencodeinitiative/java/checks/IncrementCheck.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Collections; import java.util.List; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java b/src/main/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java similarity index 97% rename from src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java rename to src/main/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java index d86f53d4..906ca7ca 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java +++ b/src/main/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Collections; import java.util.List; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/src/main/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java similarity index 99% rename from src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java rename to src/main/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java index 461cac30..ea34e776 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java +++ b/src/main/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.ArrayList; import java.util.Collection; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java b/src/main/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java similarity index 98% rename from src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java rename to src/main/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java index 7a7fddaf..999f1e36 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java +++ b/src/main/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Arrays; diff --git a/src/main/java/fr/greencodeinitiative/java/checks/enums/ConstOrLiteralDeclare.java b/src/main/java/org/greencodeinitiative/java/checks/enums/ConstOrLiteralDeclare.java similarity index 99% rename from src/main/java/fr/greencodeinitiative/java/checks/enums/ConstOrLiteralDeclare.java rename to src/main/java/org/greencodeinitiative/java/checks/enums/ConstOrLiteralDeclare.java index db01a76b..11a092b2 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/enums/ConstOrLiteralDeclare.java +++ b/src/main/java/org/greencodeinitiative/java/checks/enums/ConstOrLiteralDeclare.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks.enums; +package org.greencodeinitiative.java.checks.enums; import java.math.BigDecimal; import java.util.Set; @@ -226,4 +226,4 @@ public static final boolean isLiteral(Tree arg) { arg.is(STRING_LITERAL) || arg.is(CHAR_LITERAL); } -} \ No newline at end of file +} diff --git a/src/main/java/fr/greencodeinitiative/java/utils/PrinterVisitor.java b/src/main/java/org/greencodeinitiative/java/utils/PrinterVisitor.java similarity index 98% rename from src/main/java/fr/greencodeinitiative/java/utils/PrinterVisitor.java rename to src/main/java/org/greencodeinitiative/java/utils/PrinterVisitor.java index 2b709d79..f881be7c 100644 --- a/src/main/java/fr/greencodeinitiative/java/utils/PrinterVisitor.java +++ b/src/main/java/org/greencodeinitiative/java/utils/PrinterVisitor.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.utils; +package org.greencodeinitiative.java.utils; import java.util.List; import java.util.function.Consumer; diff --git a/src/main/java/fr/greencodeinitiative/java/utils/StringUtils.java b/src/main/java/org/greencodeinitiative/java/utils/StringUtils.java similarity index 96% rename from src/main/java/fr/greencodeinitiative/java/utils/StringUtils.java rename to src/main/java/org/greencodeinitiative/java/utils/StringUtils.java index b9b81c52..c42f9b34 100644 --- a/src/main/java/fr/greencodeinitiative/java/utils/StringUtils.java +++ b/src/main/java/org/greencodeinitiative/java/utils/StringUtils.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.utils; +package org.greencodeinitiative.java.utils; public final class StringUtils { diff --git a/src/main/resources/fr/greencodeinitiative/java/ecoCode_way_profile.json b/src/main/resources/org/greencodeinitiative/java/ecoCode_way_profile.json similarity index 100% rename from src/main/resources/fr/greencodeinitiative/java/ecoCode_way_profile.json rename to src/main/resources/org/greencodeinitiative/java/ecoCode_way_profile.json diff --git a/src/test/files/AvoidFullSQLRequestCheck.java b/src/test/files/AvoidFullSQLRequestCheck.java index b388252a..d4fd8079 100644 --- a/src/test/files/AvoidFullSQLRequestCheck.java +++ b/src/test/files/AvoidFullSQLRequestCheck.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.regex.Pattern; @@ -46,4 +46,4 @@ private void dummyCall(String request) { } -} \ No newline at end of file +} diff --git a/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java b/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java index 46963cd7..3d0c6f61 100644 --- a/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java +++ b/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Collection; import java.util.ArrayList; @@ -36,4 +36,4 @@ public void ignoredLoop() { System.out.println("numberList.size()"); } } -} \ No newline at end of file +} diff --git a/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java b/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java index 3c74c86d..fe499174 100644 --- a/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java +++ b/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Collection; import java.util.ArrayList; @@ -35,4 +35,4 @@ public void badForLoop() { System.out.println("numberList.size()"); } } -} \ No newline at end of file +} diff --git a/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java b/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java index 5f2bcd2e..bd490193 100644 --- a/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java +++ b/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Collection; import java.util.ArrayList; @@ -37,4 +37,4 @@ public void goodForLoop() { int size = numberList.size(); // Compliant with this rule } } -} \ No newline at end of file +} diff --git a/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java b/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java index 544e08e7..9b7a934e 100644 --- a/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java +++ b/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Collection; import java.util.ArrayList; @@ -37,4 +37,4 @@ public void badForLoop() { System.out.println("numberList.size()"); } } -} \ No newline at end of file +} diff --git a/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java b/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java index f47570c9..69efe46d 100644 --- a/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java +++ b/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Collection; import java.util.ArrayList; @@ -37,4 +37,4 @@ public void badWhileLoop() { i++; } } -} \ No newline at end of file +} diff --git a/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java b/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java index 57668687..36746291 100644 --- a/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java +++ b/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Collection; import java.util.ArrayList; @@ -39,4 +39,4 @@ public void goodWhileLoop() { i++; } } -} \ No newline at end of file +} diff --git a/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java b/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java index 10c752f4..0c185a3c 100644 --- a/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java +++ b/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Collection; import java.util.ArrayList; @@ -38,4 +38,4 @@ public void badWhileLoop() { System.out.println("numberList.size()"); } } -} \ No newline at end of file +} diff --git a/src/test/files/AvoidMultipleIfElseStatement.java b/src/test/files/AvoidMultipleIfElseStatement.java index 435218fa..231b9d24 100644 --- a/src/test/files/AvoidMultipleIfElseStatement.java +++ b/src/test/files/AvoidMultipleIfElseStatement.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; class AvoidMultipleIfElseStatementCheck { diff --git a/src/test/files/AvoidMultipleIfElseStatementCompareMethod.java b/src/test/files/AvoidMultipleIfElseStatementCompareMethod.java index 7c527516..83a2a386 100644 --- a/src/test/files/AvoidMultipleIfElseStatementCompareMethod.java +++ b/src/test/files/AvoidMultipleIfElseStatementCompareMethod.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; class AvoidMultipleIfElseStatementCompareMethod { @@ -51,4 +51,4 @@ public int compare(FieldVo o1, FieldVo o2) { return o1.getIdBlock().compareTo(o2.getIdBlock()); } -} \ No newline at end of file +} diff --git a/src/test/files/AvoidMultipleIfElseStatementInterface.java b/src/test/files/AvoidMultipleIfElseStatementInterface.java index 43dd875a..bd0ece23 100644 --- a/src/test/files/AvoidMultipleIfElseStatementInterface.java +++ b/src/test/files/AvoidMultipleIfElseStatementInterface.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; interface AvoidMultipleIfElseStatementCheck { diff --git a/src/test/files/AvoidMultipleIfElseStatementNoIssue.java b/src/test/files/AvoidMultipleIfElseStatementNoIssue.java index 32f4716b..4308213f 100644 --- a/src/test/files/AvoidMultipleIfElseStatementNoIssue.java +++ b/src/test/files/AvoidMultipleIfElseStatementNoIssue.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; class AvoidMultipleIfElseStatementCheckNoIssue { diff --git a/src/test/files/AvoidMultipleIfElseStatementNotBlock.java b/src/test/files/AvoidMultipleIfElseStatementNotBlock.java index 3e8f613a..55eb1187 100644 --- a/src/test/files/AvoidMultipleIfElseStatementNotBlock.java +++ b/src/test/files/AvoidMultipleIfElseStatementNotBlock.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; class AvoidMultipleIfElseStatementNotBlock { @@ -24,4 +24,4 @@ public boolean equals(Object obj) { return true; } -} \ No newline at end of file +} diff --git a/src/test/files/AvoidRegexPatternNotStatic.java b/src/test/files/AvoidRegexPatternNotStatic.java index b5e19c6e..aeeffc56 100644 --- a/src/test/files/AvoidRegexPatternNotStatic.java +++ b/src/test/files/AvoidRegexPatternNotStatic.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.regex.Pattern; diff --git a/src/test/files/AvoidSQLRequestInLoopCheck.java b/src/test/files/AvoidSQLRequestInLoopCheck.java index 753a717a..81fa6ccc 100644 --- a/src/test/files/AvoidSQLRequestInLoopCheck.java +++ b/src/test/files/AvoidSQLRequestInLoopCheck.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.sql.Connection; import java.sql.DriverManager; @@ -148,4 +148,4 @@ public void testWithWhileLoop() { } } -} \ No newline at end of file +} diff --git a/src/test/files/AvoidSetConstantInBatchUpdateCheck.java b/src/test/files/AvoidSetConstantInBatchUpdateCheck.java index 03f5e86a..b30220c0 100644 --- a/src/test/files/AvoidSetConstantInBatchUpdateCheck.java +++ b/src/test/files/AvoidSetConstantInBatchUpdateCheck.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.math.BigDecimal; import java.sql.PreparedStatement; @@ -164,4 +164,4 @@ public double getField4() { } -} \ No newline at end of file +} diff --git a/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java b/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java index a18b484f..a3f7f9a1 100644 --- a/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java +++ b/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.repository.JpaRepository; @@ -54,4 +54,4 @@ public interface EmployeeRepository extends JpaRepository { } -} \ No newline at end of file +} diff --git a/src/test/files/AvoidSpringRepositoryCallInStreamCheck.java b/src/test/files/AvoidSpringRepositoryCallInStreamCheck.java index 35dc70ce..6a291a05 100644 --- a/src/test/files/AvoidSpringRepositoryCallInStreamCheck.java +++ b/src/test/files/AvoidSpringRepositoryCallInStreamCheck.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.repository.JpaRepository; @@ -136,4 +136,4 @@ public Employee(Integer id, String name) { public interface EmployeeRepository extends JpaRepository { } -} \ No newline at end of file +} diff --git a/src/test/files/AvoidStatementForDMLQueries.java b/src/test/files/AvoidStatementForDMLQueries.java index 5059b093..230d9209 100644 --- a/src/test/files/AvoidStatementForDMLQueries.java +++ b/src/test/files/AvoidStatementForDMLQueries.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.sql.Connection; import java.sql.DriverManager; @@ -31,4 +31,4 @@ public void insert() { Statement statement = connection.createStatement(); statement.executeUpdate("INSERT INTO persons(id, name) VALUES(2, 'Toto')"); // Noncompliant {{You must not use Statement for a DML query}} } -} \ No newline at end of file +} diff --git a/src/test/files/AvoidUsageOfStaticCollections.java b/src/test/files/AvoidUsageOfStaticCollections.java index 35309972..2481c731 100644 --- a/src/test/files/AvoidUsageOfStaticCollections.java +++ b/src/test/files/AvoidUsageOfStaticCollections.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.*; diff --git a/src/test/files/FreeResourcesOfAutoCloseableInterface.java b/src/test/files/FreeResourcesOfAutoCloseableInterface.java index e1eaab59..52365b64 100644 --- a/src/test/files/FreeResourcesOfAutoCloseableInterface.java +++ b/src/test/files/FreeResourcesOfAutoCloseableInterface.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.io.*; @@ -43,11 +43,11 @@ public void foo2() { System.err.println(e.getMessage()); } finally { if (fr) { - fr.close(); + org.close(); } if (br) { br.close(); } } } -} \ No newline at end of file +} diff --git a/src/test/files/GoodUsageOfStaticCollections.java b/src/test/files/GoodUsageOfStaticCollections.java index 6d2d3c20..74641bb5 100644 --- a/src/test/files/GoodUsageOfStaticCollections.java +++ b/src/test/files/GoodUsageOfStaticCollections.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.*; diff --git a/src/test/files/GoodWayConcatenateStringsLoop.java b/src/test/files/GoodWayConcatenateStringsLoop.java index c11c1ab6..978b2fc2 100644 --- a/src/test/files/GoodWayConcatenateStringsLoop.java +++ b/src/test/files/GoodWayConcatenateStringsLoop.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.utils; +package org.greencodeinitiative.java.utils; public class GoodWayConcatenateStringsLoop { diff --git a/src/test/files/InitializeBufferWithAppropriateSize.java b/src/test/files/InitializeBufferWithAppropriateSize.java index b5852a19..3dc5934d 100644 --- a/src/test/files/InitializeBufferWithAppropriateSize.java +++ b/src/test/files/InitializeBufferWithAppropriateSize.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.sql.Connection; import java.sql.DriverManager; @@ -45,4 +45,4 @@ public void testBuilderCompliant() { public void testBuilderNonCompliant() { StringBuilder stringBuilder = new StringBuilder(); // Noncompliant {{Initialize StringBuilder or StringBuffer with appropriate size}} } -} \ No newline at end of file +} diff --git a/src/test/files/OptimizeReadFileExceptionCheck.java b/src/test/files/OptimizeReadFileExceptionCheck.java index e9fd260c..cbe6156b 100644 --- a/src/test/files/OptimizeReadFileExceptionCheck.java +++ b/src/test/files/OptimizeReadFileExceptionCheck.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Arrays; import java.util.List; @@ -34,4 +34,4 @@ public void readPreferences(String filename) { } //... } -} \ No newline at end of file +} diff --git a/src/test/files/OptimizeReadFileExceptionCheck2.java b/src/test/files/OptimizeReadFileExceptionCheck2.java index 689dc187..8345a7fb 100644 --- a/src/test/files/OptimizeReadFileExceptionCheck2.java +++ b/src/test/files/OptimizeReadFileExceptionCheck2.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Arrays; import java.util.List; @@ -33,4 +33,4 @@ public void readPreferences(String filename) { } //... } -} \ No newline at end of file +} diff --git a/src/test/files/OptimizeReadFileExceptionCheck3.java b/src/test/files/OptimizeReadFileExceptionCheck3.java index 92dc1501..6a942ac2 100644 --- a/src/test/files/OptimizeReadFileExceptionCheck3.java +++ b/src/test/files/OptimizeReadFileExceptionCheck3.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Arrays; import java.util.List; @@ -33,4 +33,4 @@ public void readPreferences(String filename) { } //... } -} \ No newline at end of file +} diff --git a/src/test/files/OptimizeReadFileExceptionCheck4.java b/src/test/files/OptimizeReadFileExceptionCheck4.java index 5914e0fa..fd041449 100644 --- a/src/test/files/OptimizeReadFileExceptionCheck4.java +++ b/src/test/files/OptimizeReadFileExceptionCheck4.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Arrays; import java.util.List; @@ -33,4 +33,4 @@ public void readPreferences(String filename) { } //... } -} \ No newline at end of file +} diff --git a/src/test/files/OptimizeReadFileExceptionCheck5.java b/src/test/files/OptimizeReadFileExceptionCheck5.java index 6d8b553e..cb07f731 100644 --- a/src/test/files/OptimizeReadFileExceptionCheck5.java +++ b/src/test/files/OptimizeReadFileExceptionCheck5.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.Arrays; import java.util.List; @@ -33,4 +33,4 @@ public void readPreferences(String filename) { } //... } -} \ No newline at end of file +} diff --git a/src/test/files/ValidRegexPattern.java b/src/test/files/ValidRegexPattern.java index aacb701e..1f0873c6 100644 --- a/src/test/files/ValidRegexPattern.java +++ b/src/test/files/ValidRegexPattern.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.regex.Pattern; diff --git a/src/test/files/ValidRegexPattern2.java b/src/test/files/ValidRegexPattern2.java index a674b9bc..97760e1b 100644 --- a/src/test/files/ValidRegexPattern2.java +++ b/src/test/files/ValidRegexPattern2.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.regex.Pattern; diff --git a/src/test/files/ValidRegexPattern3.java b/src/test/files/ValidRegexPattern3.java index 08676938..70d83690 100644 --- a/src/test/files/ValidRegexPattern3.java +++ b/src/test/files/ValidRegexPattern3.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import java.util.regex.Pattern; diff --git a/src/test/java/fr/greencodeinitiative/java/JavaCheckRegistrarTest.java b/src/test/java/org/greencodeinitiative/java/JavaCheckRegistrarTest.java similarity index 97% rename from src/test/java/fr/greencodeinitiative/java/JavaCheckRegistrarTest.java rename to src/test/java/org/greencodeinitiative/java/JavaCheckRegistrarTest.java index 09655b68..0401dec9 100644 --- a/src/test/java/fr/greencodeinitiative/java/JavaCheckRegistrarTest.java +++ b/src/test/java/org/greencodeinitiative/java/JavaCheckRegistrarTest.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java; +package org.greencodeinitiative.java; import java.util.Set; diff --git a/src/test/java/fr/greencodeinitiative/java/JavaEcoCodeWayProfileTest.java b/src/test/java/org/greencodeinitiative/java/JavaEcoCodeWayProfileTest.java similarity index 84% rename from src/test/java/fr/greencodeinitiative/java/JavaEcoCodeWayProfileTest.java rename to src/test/java/org/greencodeinitiative/java/JavaEcoCodeWayProfileTest.java index 0d750163..9f161eda 100644 --- a/src/test/java/fr/greencodeinitiative/java/JavaEcoCodeWayProfileTest.java +++ b/src/test/java/org/greencodeinitiative/java/JavaEcoCodeWayProfileTest.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java; +package org.greencodeinitiative.java; import java.util.List; import java.util.stream.Collectors; @@ -24,10 +24,10 @@ import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; import org.sonar.check.Rule; -import static fr.greencodeinitiative.java.JavaCheckRegistrarTest.getDefinedRules; -import static fr.greencodeinitiative.java.JavaEcoCodeWayProfile.PROFILE_NAME; -import static fr.greencodeinitiative.java.JavaEcoCodeWayProfile.PROFILE_PATH; -import static fr.greencodeinitiative.java.JavaRulesDefinition.LANGUAGE; +import static org.greencodeinitiative.java.JavaCheckRegistrarTest.getDefinedRules; +import static org.greencodeinitiative.java.JavaEcoCodeWayProfile.PROFILE_NAME; +import static org.greencodeinitiative.java.JavaEcoCodeWayProfile.PROFILE_PATH; +import static org.greencodeinitiative.java.JavaRulesDefinition.LANGUAGE; import static org.assertj.core.api.Assertions.assertThat; class JavaEcoCodeWayProfileTest { diff --git a/src/test/java/fr/greencodeinitiative/java/JavaPluginTest.java b/src/test/java/org/greencodeinitiative/java/JavaPluginTest.java similarity index 97% rename from src/test/java/fr/greencodeinitiative/java/JavaPluginTest.java rename to src/test/java/org/greencodeinitiative/java/JavaPluginTest.java index 0f2167d3..9c35fdc1 100644 --- a/src/test/java/fr/greencodeinitiative/java/JavaPluginTest.java +++ b/src/test/java/org/greencodeinitiative/java/JavaPluginTest.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java; +package org.greencodeinitiative.java; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java b/src/test/java/org/greencodeinitiative/java/JavaRulesDefinitionTest.java similarity index 96% rename from src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java rename to src/test/java/org/greencodeinitiative/java/JavaRulesDefinitionTest.java index 3db32ecd..b2d4091b 100644 --- a/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java +++ b/src/test/java/org/greencodeinitiative/java/JavaRulesDefinitionTest.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java; +package org.greencodeinitiative.java; import org.assertj.core.api.SoftAssertions; import org.junit.jupiter.api.BeforeEach; @@ -28,7 +28,7 @@ import org.sonar.api.server.rule.RulesDefinition.Rule; import org.sonar.api.utils.Version; -import static fr.greencodeinitiative.java.JavaCheckRegistrar.ANNOTATED_RULE_CLASSES; +import static org.greencodeinitiative.java.JavaCheckRegistrar.ANNOTATED_RULE_CLASSES; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; diff --git a/src/test/java/fr/greencodeinitiative/java/checks/ArrayCopyCheckTest.java b/src/test/java/org/greencodeinitiative/java/checks/ArrayCopyCheckTest.java similarity index 96% rename from src/test/java/fr/greencodeinitiative/java/checks/ArrayCopyCheckTest.java rename to src/test/java/org/greencodeinitiative/java/checks/ArrayCopyCheckTest.java index 5f0b1276..9a73afaa 100644 --- a/src/test/java/fr/greencodeinitiative/java/checks/ArrayCopyCheckTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/ArrayCopyCheckTest.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -33,4 +33,4 @@ void test() { .verifyIssues(); } -} \ No newline at end of file +} diff --git a/src/test/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java b/src/test/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java similarity index 96% rename from src/test/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java rename to src/test/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java index 25ead7c4..8ed30033 100644 --- a/src/test/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -30,4 +30,4 @@ void test() { .verifyIssues(); } -} \ No newline at end of file +} diff --git a/src/test/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java b/src/test/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java similarity index 98% rename from src/test/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java rename to src/test/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java index c9576927..fda429f4 100644 --- a/src/test/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; diff --git a/src/test/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java b/src/test/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java similarity index 98% rename from src/test/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java rename to src/test/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java index 2cf8869e..7f0d11fb 100644 --- a/src/test/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; diff --git a/src/test/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java b/src/test/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java similarity index 97% rename from src/test/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java rename to src/test/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java index 17502322..a01be0b5 100644 --- a/src/test/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; diff --git a/src/test/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java b/src/test/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java similarity index 96% rename from src/test/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java rename to src/test/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java index 5abed41f..7bc0dc7f 100644 --- a/src/test/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -30,4 +30,4 @@ void test() { .verifyIssues(); } -} \ No newline at end of file +} diff --git a/src/test/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java b/src/test/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java similarity index 96% rename from src/test/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java rename to src/test/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java index 8c138fde..c9b300ff 100644 --- a/src/test/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -30,4 +30,4 @@ void test() { .verifyIssues(); } -} \ No newline at end of file +} diff --git a/src/test/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java b/src/test/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java similarity index 92% rename from src/test/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java rename to src/test/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java index 2a855e0c..ff5bdc7a 100644 --- a/src/test/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java @@ -15,9 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; -import fr.greencodeinitiative.java.utils.FilesUtils; +import org.greencodeinitiative.java.utils.FilesUtils; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; diff --git a/src/test/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java b/src/test/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java similarity index 93% rename from src/test/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java rename to src/test/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java index e9fd4f35..1df0cadc 100644 --- a/src/test/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java @@ -15,9 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; -import fr.greencodeinitiative.java.utils.FilesUtils; +import org.greencodeinitiative.java.utils.FilesUtils; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; diff --git a/src/test/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java b/src/test/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java similarity index 96% rename from src/test/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java rename to src/test/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java index b74683eb..d247444b 100644 --- a/src/test/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; diff --git a/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java b/src/test/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java similarity index 97% rename from src/test/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java rename to src/test/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java index 2ac4ed35..4067128c 100644 --- a/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java +++ b/src/test/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; diff --git a/src/test/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java b/src/test/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java similarity index 97% rename from src/test/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java rename to src/test/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java index 9a9ca492..1fe62d2b 100644 --- a/src/test/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -38,4 +38,4 @@ void test_no_java_version() { .withCheck(new FreeResourcesOfAutoCloseableInterface()) .verifyIssues(); } -} \ No newline at end of file +} diff --git a/src/test/java/fr/greencodeinitiative/java/checks/IncrementCheckTest.java b/src/test/java/org/greencodeinitiative/java/checks/IncrementCheckTest.java similarity index 96% rename from src/test/java/fr/greencodeinitiative/java/checks/IncrementCheckTest.java rename to src/test/java/org/greencodeinitiative/java/checks/IncrementCheckTest.java index e9d5b98e..74630178 100644 --- a/src/test/java/fr/greencodeinitiative/java/checks/IncrementCheckTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/IncrementCheckTest.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -30,4 +30,4 @@ void test() { .verifyIssues(); } -} \ No newline at end of file +} diff --git a/src/test/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java b/src/test/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java similarity index 96% rename from src/test/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java rename to src/test/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java index deef83e8..5ff8ac9d 100644 --- a/src/test/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -30,4 +30,4 @@ void test() { .verifyIssues(); } -} \ No newline at end of file +} diff --git a/src/test/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java b/src/test/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java similarity index 96% rename from src/test/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java rename to src/test/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java index ef3c983f..29b4db49 100644 --- a/src/test/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; diff --git a/src/test/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java b/src/test/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java similarity index 97% rename from src/test/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java rename to src/test/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java index b3ef8c89..5ddb7251 100644 --- a/src/test/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.checks; +package org.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; diff --git a/src/test/java/fr/greencodeinitiative/java/utils/FilesUtils.java b/src/test/java/org/greencodeinitiative/java/utils/FilesUtils.java similarity index 98% rename from src/test/java/fr/greencodeinitiative/java/utils/FilesUtils.java rename to src/test/java/org/greencodeinitiative/java/utils/FilesUtils.java index ed06d4ce..f543b334 100644 --- a/src/test/java/fr/greencodeinitiative/java/utils/FilesUtils.java +++ b/src/test/java/org/greencodeinitiative/java/utils/FilesUtils.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.utils; +package org.greencodeinitiative.java.utils; import java.io.File; import java.io.IOException; diff --git a/src/test/java/fr/greencodeinitiative/java/utils/StringUtilsTest.java b/src/test/java/org/greencodeinitiative/java/utils/StringUtilsTest.java similarity index 97% rename from src/test/java/fr/greencodeinitiative/java/utils/StringUtilsTest.java rename to src/test/java/org/greencodeinitiative/java/utils/StringUtilsTest.java index 9e6d9328..8d95da5e 100644 --- a/src/test/java/fr/greencodeinitiative/java/utils/StringUtilsTest.java +++ b/src/test/java/org/greencodeinitiative/java/utils/StringUtilsTest.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package fr.greencodeinitiative.java.utils; +package org.greencodeinitiative.java.utils; import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.Test; From d7f2ca368477574ef9a28570dffd0e7757690339 Mon Sep 17 00:00:00 2001 From: Vincent Marmin <3215889+vincent314@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:52:32 +0100 Subject: [PATCH 087/233] fix: add @Deprecated annotation for previous ECXXX rules --- .../java/org/greencodeinitiative/java/checks/ArrayCopyCheck.java | 1 + .../org/greencodeinitiative/java/checks/AvoidFullSQLRequest.java | 1 + .../java/checks/AvoidGettingSizeCollectionInLoop.java | 1 + .../java/checks/AvoidMultipleIfElseStatement.java | 1 + .../java/checks/AvoidRegexPatternNotStatic.java | 1 + .../greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java | 1 + .../java/checks/AvoidSetConstantInBatchUpdate.java | 1 + .../checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java | 1 + .../java/checks/AvoidStatementForDMLQueries.java | 1 + .../java/checks/AvoidUsageOfStaticCollections.java | 1 + .../java/checks/FreeResourcesOfAutoCloseableInterface.java | 1 + .../java/org/greencodeinitiative/java/checks/IncrementCheck.java | 1 + .../java/checks/InitializeBufferWithAppropriateSize.java | 1 + .../java/checks/NoFunctionCallWhenDeclaringForLoop.java | 1 + .../java/checks/OptimizeReadFileExceptions.java | 1 + 15 files changed, 15 insertions(+) diff --git a/src/main/java/org/greencodeinitiative/java/checks/ArrayCopyCheck.java b/src/main/java/org/greencodeinitiative/java/checks/ArrayCopyCheck.java index d2e53acc..e417a13e 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/ArrayCopyCheck.java +++ b/src/main/java/org/greencodeinitiative/java/checks/ArrayCopyCheck.java @@ -54,6 +54,7 @@ * @formatter:off */ @Rule(key = "GCI27") +@DeprecatedRuleKey(repositoryKey = "ecocode-java", ruleKey = "EC27") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "GRPS0027") public class ArrayCopyCheck extends IssuableSubscriptionVisitor { diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequest.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequest.java index 5706ae0e..a87f6c28 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequest.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequest.java @@ -32,6 +32,7 @@ import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; @Rule(key = "GCI74") +@DeprecatedRuleKey(repositoryKey = "ecocode-java", ruleKey = "EC74") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S74") public class AvoidFullSQLRequest extends IssuableSubscriptionVisitor { diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java index 212f88ef..9aeabf5a 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java @@ -35,6 +35,7 @@ import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; @Rule(key = "GCI3") +@DeprecatedRuleKey(repositoryKey = "ecocode-java", ruleKey = "EC3") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "GSCIL") public class AvoidGettingSizeCollectionInLoop extends IssuableSubscriptionVisitor { protected static final String MESSAGERULE = "Avoid getting the size of the collection in the loop"; diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java index f39a047c..fbc4c146 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java @@ -44,6 +44,7 @@ * - IF and ELSEIF statements are considered as an IF statement */ @Rule(key = "GCI2") +@DeprecatedRuleKey(repositoryKey = "ecocode-java", ruleKey = "EC2") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "AMIES") public class AvoidMultipleIfElseStatement extends IssuableSubscriptionVisitor { diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java index 3a43007a..bf8dcc5c 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java @@ -33,6 +33,7 @@ import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; @Rule(key = "GCI77") +@DeprecatedRuleKey(repositoryKey = "ecocode-java", ruleKey = "EC77") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S77") public class AvoidRegexPatternNotStatic extends IssuableSubscriptionVisitor { diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java index af880418..24543451 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java @@ -31,6 +31,7 @@ import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; @Rule(key = "GCI72") +@DeprecatedRuleKey(repositoryKey = "ecocode-java", ruleKey = "EC72") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S72") public class AvoidSQLRequestInLoop extends IssuableSubscriptionVisitor { diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java index dc8a4baf..c97cc639 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java @@ -40,6 +40,7 @@ import static org.sonar.plugins.java.api.tree.Tree.Kind.METHOD_INVOCATION; @Rule(key = "GCI78") +@DeprecatedRuleKey(repositoryKey = "ecocode-java", ruleKey = "EC78") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S78") public class AvoidSetConstantInBatchUpdate extends IssuableSubscriptionVisitor { diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java index f7c40992..3c2bb0cb 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java @@ -27,6 +27,7 @@ import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; @Rule(key = "GCI1") +@DeprecatedRuleKey(repositoryKey = "ecocode-java", ruleKey = "EC1") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "GRC1") public class AvoidSpringRepositoryCallInLoopOrStreamCheck extends IssuableSubscriptionVisitor { diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java index 3d261f24..11bfea75 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java @@ -32,6 +32,7 @@ import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; @Rule(key = "GCI5") +@DeprecatedRuleKey(repositoryKey = "ecocode-java", ruleKey = "EC5") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "SDMLQ1") public class AvoidStatementForDMLQueries extends IssuableSubscriptionVisitor { diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java index 267c8bd4..73b4a2dd 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java @@ -31,6 +31,7 @@ import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; @Rule(key = "GCI76") +@DeprecatedRuleKey(repositoryKey = "ecocode-java", ruleKey = "EC76") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S76") public class AvoidUsageOfStaticCollections extends IssuableSubscriptionVisitor { diff --git a/src/main/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java b/src/main/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java index 7f24a380..0a6adf9e 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java +++ b/src/main/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java @@ -36,6 +36,7 @@ @Rule(key = "GCI79") +@DeprecatedRuleKey(repositoryKey = "ecocode-java", ruleKey = "EC79") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S79") public class FreeResourcesOfAutoCloseableInterface extends IssuableSubscriptionVisitor { private final Deque withinTry = new LinkedList<>(); diff --git a/src/main/java/org/greencodeinitiative/java/checks/IncrementCheck.java b/src/main/java/org/greencodeinitiative/java/checks/IncrementCheck.java index 881a760a..9c2e6a83 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/IncrementCheck.java +++ b/src/main/java/org/greencodeinitiative/java/checks/IncrementCheck.java @@ -27,6 +27,7 @@ import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; @Rule(key = "GCI67") +@DeprecatedRuleKey(repositoryKey = "ecocode-java", ruleKey = "EC67") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S67") public class IncrementCheck extends IssuableSubscriptionVisitor { diff --git a/src/main/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java b/src/main/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java index 906ca7ca..89d6744c 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java +++ b/src/main/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java @@ -28,6 +28,7 @@ import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; @Rule(key = "GCI32") +@DeprecatedRuleKey(repositoryKey = "ecocode-java", ruleKey = "EC32") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "GRSP0032") public class InitializeBufferWithAppropriateSize extends IssuableSubscriptionVisitor { diff --git a/src/main/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/src/main/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java index ea34e776..8bfb9d23 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java +++ b/src/main/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java @@ -38,6 +38,7 @@ import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; @Rule(key = "GCI69") +@DeprecatedRuleKey(repositoryKey = "ecocode-java", ruleKey = "EC69") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S69") public class NoFunctionCallWhenDeclaringForLoop extends IssuableSubscriptionVisitor { diff --git a/src/main/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java b/src/main/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java index 999f1e36..6e2ee33a 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java +++ b/src/main/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java @@ -33,6 +33,7 @@ import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; @Rule(key = "GCI28") +@DeprecatedRuleKey(repositoryKey = "ecocode-java", ruleKey = "EC28") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "GRSP0028") public class OptimizeReadFileExceptions extends IssuableSubscriptionVisitor { From 6b58d4197802b565b767fa043626057277f82453 Mon Sep 17 00:00:00 2001 From: Vincent Marmin <3215889+vincent314@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:56:17 +0100 Subject: [PATCH 088/233] chore: set Copyright year to 2024 --- pom.xml | 2 +- .../checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java | 2 +- .../checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java | 2 +- .../java/checks/AvoidSpringRepositoryCallInLoopCheck.java | 2 +- .../java/checks/AvoidSpringRepositoryCallInStreamCheck.java | 2 +- .../java/org/greencodeinitiative/java/JavaCheckRegistrar.java | 2 +- .../org/greencodeinitiative/java/JavaEcoCodeWayProfile.java | 2 +- src/main/java/org/greencodeinitiative/java/JavaPlugin.java | 2 +- .../org/greencodeinitiative/java/JavaRulesDefinition.java | 2 +- .../org/greencodeinitiative/java/checks/ArrayCopyCheck.java | 2 +- .../greencodeinitiative/java/checks/AvoidFullSQLRequest.java | 2 +- .../java/checks/AvoidGettingSizeCollectionInLoop.java | 2 +- .../java/checks/AvoidMultipleIfElseStatement.java | 2 +- .../java/checks/AvoidRegexPatternNotStatic.java | 2 +- .../java/checks/AvoidSQLRequestInLoop.java | 2 +- .../java/checks/AvoidSetConstantInBatchUpdate.java | 2 +- .../checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java | 2 +- .../java/checks/AvoidStatementForDMLQueries.java | 2 +- .../java/checks/AvoidUsageOfStaticCollections.java | 2 +- .../java/checks/FreeResourcesOfAutoCloseableInterface.java | 2 +- .../org/greencodeinitiative/java/checks/IncrementCheck.java | 2 +- .../java/checks/InitializeBufferWithAppropriateSize.java | 2 +- .../java/checks/NoFunctionCallWhenDeclaringForLoop.java | 2 +- .../java/checks/OptimizeReadFileExceptions.java | 2 +- .../java/checks/enums/ConstOrLiteralDeclare.java | 2 +- .../org/greencodeinitiative/java/utils/PrinterVisitor.java | 2 +- .../java/org/greencodeinitiative/java/utils/StringUtils.java | 2 +- src/test/files/ArrayCopyCheck.java | 4 ++-- src/test/files/AvoidFullSQLRequestCheck.java | 2 +- .../files/AvoidGettingSizeCollectionInForEachLoopIgnored.java | 2 +- src/test/files/AvoidGettingSizeCollectionInForLoopBad.java | 2 +- src/test/files/AvoidGettingSizeCollectionInForLoopGood.java | 2 +- .../files/AvoidGettingSizeCollectionInForLoopIgnored.java | 2 +- src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java | 2 +- src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java | 2 +- .../files/AvoidGettingSizeCollectionInWhileLoopIgnored.java | 2 +- src/test/files/AvoidMultipleIfElseStatement.java | 2 +- src/test/files/AvoidMultipleIfElseStatementCompareMethod.java | 2 +- src/test/files/AvoidMultipleIfElseStatementInterface.java | 2 +- src/test/files/AvoidMultipleIfElseStatementNoIssue.java | 2 +- src/test/files/AvoidMultipleIfElseStatementNotBlock.java | 2 +- src/test/files/AvoidRegexPatternNotStatic.java | 2 +- src/test/files/AvoidSQLRequestInLoopCheck.java | 2 +- src/test/files/AvoidSetConstantInBatchUpdateCheck.java | 2 +- src/test/files/AvoidSpringRepositoryCallInLoopCheck.java | 2 +- src/test/files/AvoidSpringRepositoryCallInStreamCheck.java | 2 +- src/test/files/AvoidStatementForDMLQueries.java | 2 +- src/test/files/AvoidUsageOfStaticCollections.java | 2 +- src/test/files/FreeResourcesOfAutoCloseableInterface.java | 2 +- src/test/files/GoodUsageOfStaticCollections.java | 2 +- src/test/files/GoodWayConcatenateStringsLoop.java | 2 +- src/test/files/IncrementCheck.java | 4 ++-- src/test/files/InitializeBufferWithAppropriateSize.java | 2 +- src/test/files/NoFunctionCallWhenDeclaringForLoop.java | 4 ++-- src/test/files/OptimizeReadFileExceptionCheck.java | 2 +- src/test/files/OptimizeReadFileExceptionCheck2.java | 2 +- src/test/files/OptimizeReadFileExceptionCheck3.java | 2 +- src/test/files/OptimizeReadFileExceptionCheck4.java | 2 +- src/test/files/OptimizeReadFileExceptionCheck5.java | 2 +- src/test/files/ValidRegexPattern.java | 2 +- src/test/files/ValidRegexPattern2.java | 2 +- src/test/files/ValidRegexPattern3.java | 2 +- .../org/greencodeinitiative/java/JavaCheckRegistrarTest.java | 2 +- .../greencodeinitiative/java/JavaEcoCodeWayProfileTest.java | 2 +- .../java/org/greencodeinitiative/java/JavaPluginTest.java | 2 +- .../org/greencodeinitiative/java/JavaRulesDefinitionTest.java | 2 +- .../greencodeinitiative/java/checks/ArrayCopyCheckTest.java | 2 +- .../java/checks/AvoidFullSQLRequestCheckTest.java | 2 +- .../java/checks/AvoidGettingSizeCollectionInLoopTest.java | 2 +- .../java/checks/AvoidMultipleIfElseStatementTest.java | 2 +- .../java/checks/AvoidRegexPatternNotStaticTest.java | 2 +- .../java/checks/AvoidSQLRequestInLoopCheckTest.java | 2 +- .../java/checks/AvoidSetConstantInBatchInsertTest.java | 2 +- .../java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java | 2 +- .../checks/AvoidSpringRepositoryCallInStreamCheckTest.java | 2 +- .../java/checks/AvoidStatementForDMLQueriesTest.java | 2 +- .../java/checks/AvoidUsageOfStaticCollectionsTests.java | 2 +- .../checks/FreeResourcesOfAutoCloseableInterfaceTest.java | 2 +- .../greencodeinitiative/java/checks/IncrementCheckTest.java | 2 +- .../java/checks/InitializeBufferWithAppropriateSizeTest.java | 2 +- .../java/checks/NoFunctionCallWhenDeclaringForLoopTest.java | 2 +- .../java/checks/OptimizeReadFileExceptionCheckTest.java | 2 +- .../java/org/greencodeinitiative/java/utils/FilesUtils.java | 2 +- .../org/greencodeinitiative/java/utils/StringUtilsTest.java | 2 +- 84 files changed, 87 insertions(+), 87 deletions(-) diff --git a/pom.xml b/pom.xml index eda274bc..b69b44e5 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ ecoCode - Java language Provides rules to reduce the environmental footprint of your Java programs - 2023 + 2024 https://github.com/green-code-initiative/ecoCode-java diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java index 37d87eb6..c1aef731 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java index b120cee0..8bbb202e 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java index bc6c276f..310a2577 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java index 746b77bf..e1fe5fb1 100644 --- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java +++ b/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/JavaCheckRegistrar.java b/src/main/java/org/greencodeinitiative/java/JavaCheckRegistrar.java index 72b63d1c..9994e5ab 100644 --- a/src/main/java/org/greencodeinitiative/java/JavaCheckRegistrar.java +++ b/src/main/java/org/greencodeinitiative/java/JavaCheckRegistrar.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/JavaEcoCodeWayProfile.java b/src/main/java/org/greencodeinitiative/java/JavaEcoCodeWayProfile.java index 3046f8ec..121cb7a7 100644 --- a/src/main/java/org/greencodeinitiative/java/JavaEcoCodeWayProfile.java +++ b/src/main/java/org/greencodeinitiative/java/JavaEcoCodeWayProfile.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/JavaPlugin.java b/src/main/java/org/greencodeinitiative/java/JavaPlugin.java index fc734139..e8daf490 100644 --- a/src/main/java/org/greencodeinitiative/java/JavaPlugin.java +++ b/src/main/java/org/greencodeinitiative/java/JavaPlugin.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/JavaRulesDefinition.java b/src/main/java/org/greencodeinitiative/java/JavaRulesDefinition.java index 57999df4..3725a9ce 100644 --- a/src/main/java/org/greencodeinitiative/java/JavaRulesDefinition.java +++ b/src/main/java/org/greencodeinitiative/java/JavaRulesDefinition.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/checks/ArrayCopyCheck.java b/src/main/java/org/greencodeinitiative/java/checks/ArrayCopyCheck.java index e417a13e..86294b62 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/ArrayCopyCheck.java +++ b/src/main/java/org/greencodeinitiative/java/checks/ArrayCopyCheck.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequest.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequest.java index a87f6c28..7f05d29c 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequest.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java index 9aeabf5a..eaf85aca 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java index fbc4c146..9c27de75 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java index bf8dcc5c..4be3b228 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java index 24543451..b00f710f 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java index c97cc639..70f7a0df 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java index 3c2bb0cb..02b8e198 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java index 11bfea75..69217dd9 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java b/src/main/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java index 73b4a2dd..474b267d 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java +++ b/src/main/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java b/src/main/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java index 0a6adf9e..76f10091 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java +++ b/src/main/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/checks/IncrementCheck.java b/src/main/java/org/greencodeinitiative/java/checks/IncrementCheck.java index 9c2e6a83..f2838ecb 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/IncrementCheck.java +++ b/src/main/java/org/greencodeinitiative/java/checks/IncrementCheck.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java b/src/main/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java index 89d6744c..176364c8 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java +++ b/src/main/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/src/main/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java index 8bfb9d23..be1c6b3e 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java +++ b/src/main/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java b/src/main/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java index 6e2ee33a..3d95b6ba 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java +++ b/src/main/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/checks/enums/ConstOrLiteralDeclare.java b/src/main/java/org/greencodeinitiative/java/checks/enums/ConstOrLiteralDeclare.java index 11a092b2..99c20707 100644 --- a/src/main/java/org/greencodeinitiative/java/checks/enums/ConstOrLiteralDeclare.java +++ b/src/main/java/org/greencodeinitiative/java/checks/enums/ConstOrLiteralDeclare.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/utils/PrinterVisitor.java b/src/main/java/org/greencodeinitiative/java/utils/PrinterVisitor.java index f881be7c..701ebe7b 100644 --- a/src/main/java/org/greencodeinitiative/java/utils/PrinterVisitor.java +++ b/src/main/java/org/greencodeinitiative/java/utils/PrinterVisitor.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main/java/org/greencodeinitiative/java/utils/StringUtils.java b/src/main/java/org/greencodeinitiative/java/utils/StringUtils.java index c42f9b34..46b723e4 100644 --- a/src/main/java/org/greencodeinitiative/java/utils/StringUtils.java +++ b/src/main/java/org/greencodeinitiative/java/utils/StringUtils.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/ArrayCopyCheck.java b/src/test/files/ArrayCopyCheck.java index 09c780ea..3e85bb93 100644 --- a/src/test/files/ArrayCopyCheck.java +++ b/src/test/files/ArrayCopyCheck.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -507,4 +507,4 @@ private boolean transform(boolean a) { return !a; } -} \ No newline at end of file +} diff --git a/src/test/files/AvoidFullSQLRequestCheck.java b/src/test/files/AvoidFullSQLRequestCheck.java index d4fd8079..c2864520 100644 --- a/src/test/files/AvoidFullSQLRequestCheck.java +++ b/src/test/files/AvoidFullSQLRequestCheck.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java b/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java index 3d0c6f61..811863fd 100644 --- a/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java +++ b/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java b/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java index fe499174..4bc2cc0b 100644 --- a/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java +++ b/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java b/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java index bd490193..b8a1e592 100644 --- a/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java +++ b/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java b/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java index 9b7a934e..f22ca28e 100644 --- a/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java +++ b/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java b/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java index 69efe46d..50ee0155 100644 --- a/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java +++ b/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java b/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java index 36746291..2f799668 100644 --- a/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java +++ b/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java b/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java index 0c185a3c..4c9bfc95 100644 --- a/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java +++ b/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/AvoidMultipleIfElseStatement.java b/src/test/files/AvoidMultipleIfElseStatement.java index 231b9d24..96181a67 100644 --- a/src/test/files/AvoidMultipleIfElseStatement.java +++ b/src/test/files/AvoidMultipleIfElseStatement.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/AvoidMultipleIfElseStatementCompareMethod.java b/src/test/files/AvoidMultipleIfElseStatementCompareMethod.java index 83a2a386..2eb67447 100644 --- a/src/test/files/AvoidMultipleIfElseStatementCompareMethod.java +++ b/src/test/files/AvoidMultipleIfElseStatementCompareMethod.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/AvoidMultipleIfElseStatementInterface.java b/src/test/files/AvoidMultipleIfElseStatementInterface.java index bd0ece23..6b79f62c 100644 --- a/src/test/files/AvoidMultipleIfElseStatementInterface.java +++ b/src/test/files/AvoidMultipleIfElseStatementInterface.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/AvoidMultipleIfElseStatementNoIssue.java b/src/test/files/AvoidMultipleIfElseStatementNoIssue.java index 4308213f..b7d92232 100644 --- a/src/test/files/AvoidMultipleIfElseStatementNoIssue.java +++ b/src/test/files/AvoidMultipleIfElseStatementNoIssue.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/AvoidMultipleIfElseStatementNotBlock.java b/src/test/files/AvoidMultipleIfElseStatementNotBlock.java index 55eb1187..18607235 100644 --- a/src/test/files/AvoidMultipleIfElseStatementNotBlock.java +++ b/src/test/files/AvoidMultipleIfElseStatementNotBlock.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/AvoidRegexPatternNotStatic.java b/src/test/files/AvoidRegexPatternNotStatic.java index aeeffc56..129ad2af 100644 --- a/src/test/files/AvoidRegexPatternNotStatic.java +++ b/src/test/files/AvoidRegexPatternNotStatic.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/AvoidSQLRequestInLoopCheck.java b/src/test/files/AvoidSQLRequestInLoopCheck.java index 81fa6ccc..e894ea20 100644 --- a/src/test/files/AvoidSQLRequestInLoopCheck.java +++ b/src/test/files/AvoidSQLRequestInLoopCheck.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/AvoidSetConstantInBatchUpdateCheck.java b/src/test/files/AvoidSetConstantInBatchUpdateCheck.java index b30220c0..0b6b74f4 100644 --- a/src/test/files/AvoidSetConstantInBatchUpdateCheck.java +++ b/src/test/files/AvoidSetConstantInBatchUpdateCheck.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java b/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java index a3f7f9a1..ab492606 100644 --- a/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java +++ b/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/AvoidSpringRepositoryCallInStreamCheck.java b/src/test/files/AvoidSpringRepositoryCallInStreamCheck.java index 6a291a05..d623db61 100644 --- a/src/test/files/AvoidSpringRepositoryCallInStreamCheck.java +++ b/src/test/files/AvoidSpringRepositoryCallInStreamCheck.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/AvoidStatementForDMLQueries.java b/src/test/files/AvoidStatementForDMLQueries.java index 230d9209..dfe7266c 100644 --- a/src/test/files/AvoidStatementForDMLQueries.java +++ b/src/test/files/AvoidStatementForDMLQueries.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/AvoidUsageOfStaticCollections.java b/src/test/files/AvoidUsageOfStaticCollections.java index 2481c731..30213cf3 100644 --- a/src/test/files/AvoidUsageOfStaticCollections.java +++ b/src/test/files/AvoidUsageOfStaticCollections.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/FreeResourcesOfAutoCloseableInterface.java b/src/test/files/FreeResourcesOfAutoCloseableInterface.java index 52365b64..e2174a5d 100644 --- a/src/test/files/FreeResourcesOfAutoCloseableInterface.java +++ b/src/test/files/FreeResourcesOfAutoCloseableInterface.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/GoodUsageOfStaticCollections.java b/src/test/files/GoodUsageOfStaticCollections.java index 74641bb5..200f9732 100644 --- a/src/test/files/GoodUsageOfStaticCollections.java +++ b/src/test/files/GoodUsageOfStaticCollections.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/GoodWayConcatenateStringsLoop.java b/src/test/files/GoodWayConcatenateStringsLoop.java index 978b2fc2..eb84f353 100644 --- a/src/test/files/GoodWayConcatenateStringsLoop.java +++ b/src/test/files/GoodWayConcatenateStringsLoop.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/IncrementCheck.java b/src/test/files/IncrementCheck.java index 54b20bf9..1055e656 100644 --- a/src/test/files/IncrementCheck.java +++ b/src/test/files/IncrementCheck.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -60,4 +60,4 @@ void foo51(int value) { System.out.println(i); } } -} \ No newline at end of file +} diff --git a/src/test/files/InitializeBufferWithAppropriateSize.java b/src/test/files/InitializeBufferWithAppropriateSize.java index 3dc5934d..260ead6d 100644 --- a/src/test/files/InitializeBufferWithAppropriateSize.java +++ b/src/test/files/InitializeBufferWithAppropriateSize.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/NoFunctionCallWhenDeclaringForLoop.java b/src/test/files/NoFunctionCallWhenDeclaringForLoop.java index da72a3ef..8321c888 100644 --- a/src/test/files/NoFunctionCallWhenDeclaringForLoop.java +++ b/src/test/files/NoFunctionCallWhenDeclaringForLoop.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -70,4 +70,4 @@ public void test6() { } } -} \ No newline at end of file +} diff --git a/src/test/files/OptimizeReadFileExceptionCheck.java b/src/test/files/OptimizeReadFileExceptionCheck.java index cbe6156b..5eace2a6 100644 --- a/src/test/files/OptimizeReadFileExceptionCheck.java +++ b/src/test/files/OptimizeReadFileExceptionCheck.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/OptimizeReadFileExceptionCheck2.java b/src/test/files/OptimizeReadFileExceptionCheck2.java index 8345a7fb..e974b3d7 100644 --- a/src/test/files/OptimizeReadFileExceptionCheck2.java +++ b/src/test/files/OptimizeReadFileExceptionCheck2.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/OptimizeReadFileExceptionCheck3.java b/src/test/files/OptimizeReadFileExceptionCheck3.java index 6a942ac2..83aac949 100644 --- a/src/test/files/OptimizeReadFileExceptionCheck3.java +++ b/src/test/files/OptimizeReadFileExceptionCheck3.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/OptimizeReadFileExceptionCheck4.java b/src/test/files/OptimizeReadFileExceptionCheck4.java index fd041449..33caa46d 100644 --- a/src/test/files/OptimizeReadFileExceptionCheck4.java +++ b/src/test/files/OptimizeReadFileExceptionCheck4.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/OptimizeReadFileExceptionCheck5.java b/src/test/files/OptimizeReadFileExceptionCheck5.java index cb07f731..5367ffd9 100644 --- a/src/test/files/OptimizeReadFileExceptionCheck5.java +++ b/src/test/files/OptimizeReadFileExceptionCheck5.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/ValidRegexPattern.java b/src/test/files/ValidRegexPattern.java index 1f0873c6..942432a6 100644 --- a/src/test/files/ValidRegexPattern.java +++ b/src/test/files/ValidRegexPattern.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/ValidRegexPattern2.java b/src/test/files/ValidRegexPattern2.java index 97760e1b..92f88c82 100644 --- a/src/test/files/ValidRegexPattern2.java +++ b/src/test/files/ValidRegexPattern2.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/files/ValidRegexPattern3.java b/src/test/files/ValidRegexPattern3.java index 70d83690..e6dfb88c 100644 --- a/src/test/files/ValidRegexPattern3.java +++ b/src/test/files/ValidRegexPattern3.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/JavaCheckRegistrarTest.java b/src/test/java/org/greencodeinitiative/java/JavaCheckRegistrarTest.java index 0401dec9..9ced970b 100644 --- a/src/test/java/org/greencodeinitiative/java/JavaCheckRegistrarTest.java +++ b/src/test/java/org/greencodeinitiative/java/JavaCheckRegistrarTest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/JavaEcoCodeWayProfileTest.java b/src/test/java/org/greencodeinitiative/java/JavaEcoCodeWayProfileTest.java index 9f161eda..b812a49a 100644 --- a/src/test/java/org/greencodeinitiative/java/JavaEcoCodeWayProfileTest.java +++ b/src/test/java/org/greencodeinitiative/java/JavaEcoCodeWayProfileTest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/JavaPluginTest.java b/src/test/java/org/greencodeinitiative/java/JavaPluginTest.java index 9c35fdc1..7712f993 100644 --- a/src/test/java/org/greencodeinitiative/java/JavaPluginTest.java +++ b/src/test/java/org/greencodeinitiative/java/JavaPluginTest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/JavaRulesDefinitionTest.java b/src/test/java/org/greencodeinitiative/java/JavaRulesDefinitionTest.java index b2d4091b..8f6f2ddb 100644 --- a/src/test/java/org/greencodeinitiative/java/JavaRulesDefinitionTest.java +++ b/src/test/java/org/greencodeinitiative/java/JavaRulesDefinitionTest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/checks/ArrayCopyCheckTest.java b/src/test/java/org/greencodeinitiative/java/checks/ArrayCopyCheckTest.java index 9a73afaa..7e32f4e8 100644 --- a/src/test/java/org/greencodeinitiative/java/checks/ArrayCopyCheckTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/ArrayCopyCheckTest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java b/src/test/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java index 8ed30033..8453f31f 100644 --- a/src/test/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java b/src/test/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java index fda429f4..9b74a62d 100644 --- a/src/test/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java b/src/test/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java index 7f0d11fb..e7bd1327 100644 --- a/src/test/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java b/src/test/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java index a01be0b5..2445c941 100644 --- a/src/test/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java b/src/test/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java index 7bc0dc7f..9e7b6329 100644 --- a/src/test/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java b/src/test/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java index c9b300ff..bd0bc6f9 100644 --- a/src/test/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java b/src/test/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java index ff5bdc7a..c8e05f31 100644 --- a/src/test/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java b/src/test/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java index 1df0cadc..4076c7eb 100644 --- a/src/test/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java b/src/test/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java index d247444b..62625423 100644 --- a/src/test/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java b/src/test/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java index 4067128c..4697c217 100644 --- a/src/test/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java +++ b/src/test/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java b/src/test/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java index 1fe62d2b..03c20959 100644 --- a/src/test/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/checks/IncrementCheckTest.java b/src/test/java/org/greencodeinitiative/java/checks/IncrementCheckTest.java index 74630178..4b075d0c 100644 --- a/src/test/java/org/greencodeinitiative/java/checks/IncrementCheckTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/IncrementCheckTest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java b/src/test/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java index 5ff8ac9d..f1149849 100644 --- a/src/test/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java b/src/test/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java index 29b4db49..32bf0c49 100644 --- a/src/test/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java b/src/test/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java index 5ddb7251..293f2437 100644 --- a/src/test/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java +++ b/src/test/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/utils/FilesUtils.java b/src/test/java/org/greencodeinitiative/java/utils/FilesUtils.java index f543b334..78cfcd23 100644 --- a/src/test/java/org/greencodeinitiative/java/utils/FilesUtils.java +++ b/src/test/java/org/greencodeinitiative/java/utils/FilesUtils.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/test/java/org/greencodeinitiative/java/utils/StringUtilsTest.java b/src/test/java/org/greencodeinitiative/java/utils/StringUtilsTest.java index 8d95da5e..011518c7 100644 --- a/src/test/java/org/greencodeinitiative/java/utils/StringUtilsTest.java +++ b/src/test/java/org/greencodeinitiative/java/utils/StringUtilsTest.java @@ -1,6 +1,6 @@ /* * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * Copyright © 2024 Green Code Initiative (https://www.ecocode.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by From d619ac784554a6da1c60bce05c273f1748ceceff Mon Sep 17 00:00:00 2001 From: Vincent Marmin <3215889+vincent314@users.noreply.github.com> Date: Wed, 11 Dec 2024 14:53:17 +0100 Subject: [PATCH 089/233] fix: bump version of creedengo-rules-specifications to 2.0.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b69b44e5..bbe7112f 100644 --- a/pom.xml +++ b/pom.xml @@ -72,7 +72,7 @@ 1.7 - main-SNAPSHOT + 2.0.0 https://repo1.maven.org/maven2 From 465698319c4e50ea2a1007b38b05eb5bdb147636 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Mon, 16 Dec 2024 00:09:51 +0100 Subject: [PATCH 090/233] migration from ecocode to creedengo --- .github/workflows/_BACKUP_manual_release.yml | 4 +- .github/workflows/build.yml | 2 +- .github/workflows/build_container.yml | 2 +- .github/workflows/tag_release.yml | 6 +-- Dockerfile | 6 +-- README.md | 2 +- docker-compose.yml | 6 +-- pom.xml | 39 ++++++++++--------- .../LaunchSonarqubeAndBuildProjectIT.java | 8 ++-- .../tests/profile/ProfileBackup.java | 14 +++---- .../tests/profile/ProfileMetadata.java | 2 +- .../tests/profile/RuleMetadata.java | 2 +- .../pom.xml | 6 +-- .../java/checks/ArrayCopyCheck.java | 2 +- .../java/checks/AvoidFullSQLRequestCheck.java | 2 +- ...ingSizeCollectionInForEachLoopIgnored.java | 2 +- ...voidGettingSizeCollectionInForLoopBad.java | 2 +- ...oidGettingSizeCollectionInForLoopGood.java | 2 +- ...GettingSizeCollectionInForLoopIgnored.java | 2 +- ...idGettingSizeCollectionInWhileLoopBad.java | 2 +- ...dGettingSizeCollectionInWhileLoopGood.java | 2 +- ...ttingSizeCollectionInWhileLoopIgnored.java | 2 +- .../checks/AvoidMultipleIfElseStatement.java | 2 +- ...leIfElseStatementCompareMethodNoIssue.java | 2 +- ...ltipleIfElseStatementInterfaceNoIssue.java | 6 +-- ...MultipleIfElseStatementNoBlockNoIssue.java | 6 +-- .../AvoidMultipleIfElseStatementNoIssue.java | 2 +- .../checks/AvoidRegexPatternNotStatic.java | 2 +- .../checks/AvoidSQLRequestInLoopCheck.java | 2 +- .../AvoidSetConstantInBatchUpdateCheck.java | 2 +- .../AvoidSpringRepositoryCallInLoopCheck.java | 6 +-- ...voidSpringRepositoryCallInStreamCheck.java | 6 +-- .../checks/AvoidStatementForDMLQueries.java | 2 +- .../checks/AvoidUsageOfStaticCollections.java | 2 +- ...FreeResourcesOfAutoCloseableInterface.java | 2 +- .../checks/GoodUsageOfStaticCollections.java | 2 +- .../checks/GoodWayConcatenateStringsLoop.java | 2 +- .../java/checks/IncrementCheck.java | 2 +- .../InitializeBufferWithAppropriateSize.java | 2 +- .../NoFunctionCallWhenDeclaringForLoop.java | 2 +- .../OptimizeReadFileExceptionCheck.java | 2 +- .../OptimizeReadFileExceptionCheck2.java | 2 +- .../OptimizeReadFileExceptionCheck3.java | 2 +- .../OptimizeReadFileExceptionCheck4.java | 2 +- .../OptimizeReadFileExceptionCheck5.java | 2 +- .../checks/OptimizeSQLQueriesWithLimit.java | 2 +- .../java/checks/ValidRegexPattern.java | 2 +- .../java/checks/ValidRegexPattern2.java | 2 +- .../java/checks/ValidRegexPattern3.java | 2 +- .../java/JavaCheckRegistrar.java | 36 ++++++++--------- .../java/JavaCreedengoWayProfile.java} | 22 +++++------ .../{ => creedengo}/java/JavaPlugin.java | 6 +-- .../java/JavaRulesDefinition.java | 10 ++--- .../java/checks/ArrayCopyCheck.java | 6 +-- .../java/checks/AvoidFullSQLRequest.java | 6 +-- .../AvoidGettingSizeCollectionInLoop.java | 6 +-- .../checks/AvoidMultipleIfElseStatement.java | 8 ++-- .../checks/AvoidRegexPatternNotStatic.java | 6 +-- .../java/checks/AvoidSQLRequestInLoop.java | 6 +-- .../checks/AvoidSetConstantInBatchUpdate.java | 10 ++--- ...ringRepositoryCallInLoopOrStreamCheck.java | 6 +-- .../checks/AvoidStatementForDMLQueries.java | 6 +-- .../checks/AvoidUsageOfStaticCollections.java | 6 +-- ...FreeResourcesOfAutoCloseableInterface.java | 6 +-- .../java/checks/IncrementCheck.java | 6 +-- .../InitializeBufferWithAppropriateSize.java | 6 +-- .../NoFunctionCallWhenDeclaringForLoop.java | 6 +-- .../checks/OptimizeReadFileExceptions.java | 6 +-- .../checks/enums/ConstOrLiteralDeclare.java | 6 +-- .../java/utils/PrinterVisitor.java | 6 +-- .../java/utils/StringUtils.java | 6 +-- .../java/creedengo_way_profile.json} | 2 +- src/test/files/ArrayCopyCheck.java | 4 +- src/test/files/AvoidFullSQLRequestCheck.java | 6 +-- ...ingSizeCollectionInForEachLoopIgnored.java | 6 +-- ...voidGettingSizeCollectionInForLoopBad.java | 6 +-- ...oidGettingSizeCollectionInForLoopGood.java | 6 +-- ...GettingSizeCollectionInForLoopIgnored.java | 6 +-- ...idGettingSizeCollectionInWhileLoopBad.java | 6 +-- ...dGettingSizeCollectionInWhileLoopGood.java | 6 +-- ...ttingSizeCollectionInWhileLoopIgnored.java | 6 +-- .../files/AvoidMultipleIfElseStatement.java | 6 +-- ...dMultipleIfElseStatementCompareMethod.java | 6 +-- ...AvoidMultipleIfElseStatementInterface.java | 6 +-- .../AvoidMultipleIfElseStatementNoIssue.java | 6 +-- .../AvoidMultipleIfElseStatementNotBlock.java | 6 +-- .../files/AvoidRegexPatternNotStatic.java | 6 +-- .../files/AvoidSQLRequestInLoopCheck.java | 6 +-- .../AvoidSetConstantInBatchUpdateCheck.java | 6 +-- .../AvoidSpringRepositoryCallInLoopCheck.java | 6 +-- ...voidSpringRepositoryCallInStreamCheck.java | 6 +-- .../files/AvoidStatementForDMLQueries.java | 6 +-- .../files/AvoidUsageOfStaticCollections.java | 6 +-- ...FreeResourcesOfAutoCloseableInterface.java | 6 +-- .../files/GoodUsageOfStaticCollections.java | 6 +-- .../files/GoodWayConcatenateStringsLoop.java | 6 +-- src/test/files/IncrementCheck.java | 4 +- .../InitializeBufferWithAppropriateSize.java | 6 +-- .../NoFunctionCallWhenDeclaringForLoop.java | 4 +- .../files/OptimizeReadFileExceptionCheck.java | 6 +-- .../OptimizeReadFileExceptionCheck2.java | 6 +-- .../OptimizeReadFileExceptionCheck3.java | 6 +-- .../OptimizeReadFileExceptionCheck4.java | 6 +-- .../OptimizeReadFileExceptionCheck5.java | 6 +-- src/test/files/ValidRegexPattern.java | 6 +-- src/test/files/ValidRegexPattern2.java | 6 +-- src/test/files/ValidRegexPattern3.java | 6 +-- .../java/JavaCheckRegistrarTest.java | 6 +-- .../java/JavaCreedengoWayProfileTest.java} | 20 +++++----- .../{ => creedengo}/java/JavaPluginTest.java | 6 +-- .../java/JavaRulesDefinitionTest.java | 12 +++--- .../java/checks/ArrayCopyCheckTest.java | 6 +-- .../checks/AvoidFullSQLRequestCheckTest.java | 6 +-- .../AvoidGettingSizeCollectionInLoopTest.java | 6 +-- .../AvoidMultipleIfElseStatementTest.java | 6 +-- .../AvoidRegexPatternNotStaticTest.java | 6 +-- .../AvoidSQLRequestInLoopCheckTest.java | 6 +-- .../AvoidSetConstantInBatchInsertTest.java | 6 +-- ...idSpringRepositoryCallInLoopCheckTest.java | 8 ++-- ...SpringRepositoryCallInStreamCheckTest.java | 8 ++-- .../AvoidStatementForDMLQueriesTest.java | 6 +-- .../AvoidUsageOfStaticCollectionsTests.java | 6 +-- ...ResourcesOfAutoCloseableInterfaceTest.java | 6 +-- .../java/checks/IncrementCheckTest.java | 6 +-- ...itializeBufferWithAppropriateSizeTest.java | 6 +-- ...oFunctionCallWhenDeclaringForLoopTest.java | 6 +-- .../OptimizeReadFileExceptionCheckTest.java | 6 +-- .../java/utils/FilesUtils.java | 6 +-- .../java/utils/StringUtilsTest.java | 6 +-- 129 files changed, 369 insertions(+), 368 deletions(-) rename src/it/java/{io/ecocode => org/greencodeinitiative/creedengo}/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java (97%) rename src/it/java/{io/ecocode => org/greencodeinitiative/creedengo}/java/integration/tests/profile/ProfileBackup.java (90%) rename src/it/java/{io/ecocode => org/greencodeinitiative/creedengo}/java/integration/tests/profile/ProfileMetadata.java (90%) rename src/it/java/{io/ecocode => org/greencodeinitiative/creedengo}/java/integration/tests/profile/RuleMetadata.java (90%) rename src/it/test-projects/{ecocode-java-plugin-test-project => creedengo-java-plugin-test-project}/pom.xml (87%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/ArrayCopyCheck.java (99%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/AvoidFullSQLRequestCheck.java (94%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java (91%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/AvoidGettingSizeCollectionInForLoopBad.java (90%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/AvoidGettingSizeCollectionInForLoopGood.java (91%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java (90%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java (90%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java (91%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java (91%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/AvoidMultipleIfElseStatement.java (99%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java (97%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java (76%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java (77%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/AvoidMultipleIfElseStatementNoIssue.java (99%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/AvoidRegexPatternNotStatic.java (84%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/AvoidSQLRequestInLoopCheck.java (98%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/AvoidSetConstantInBatchUpdateCheck.java (99%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/AvoidSpringRepositoryCallInLoopCheck.java (88%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/AvoidSpringRepositoryCallInStreamCheck.java (95%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/AvoidStatementForDMLQueries.java (91%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/AvoidUsageOfStaticCollections.java (90%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/FreeResourcesOfAutoCloseableInterface.java (95%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/GoodUsageOfStaticCollections.java (89%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/GoodWayConcatenateStringsLoop.java (92%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/IncrementCheck.java (94%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/InitializeBufferWithAppropriateSize.java (93%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/NoFunctionCallWhenDeclaringForLoop.java (96%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/OptimizeReadFileExceptionCheck.java (92%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/OptimizeReadFileExceptionCheck2.java (92%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/OptimizeReadFileExceptionCheck3.java (92%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/OptimizeReadFileExceptionCheck4.java (91%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/OptimizeReadFileExceptionCheck5.java (91%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/OptimizeSQLQueriesWithLimit.java (94%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/ValidRegexPattern.java (80%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/ValidRegexPattern2.java (80%) rename src/it/test-projects/{ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative => creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo}/java/checks/ValidRegexPattern3.java (83%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/JavaCheckRegistrar.java (65%) rename src/main/java/org/greencodeinitiative/{java/JavaEcoCodeWayProfile.java => creedengo/java/JavaCreedengoWayProfile.java} (54%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/JavaPlugin.java (82%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/JavaRulesDefinition.java (83%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/checks/ArrayCopyCheck.java (97%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/checks/AvoidFullSQLRequest.java (89%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/checks/AvoidGettingSizeCollectionInLoop.java (95%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/checks/AvoidMultipleIfElseStatement.java (98%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/checks/AvoidRegexPatternNotStatic.java (91%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/checks/AvoidSQLRequestInLoop.java (94%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/checks/AvoidSetConstantInBatchUpdate.java (89%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java (95%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/checks/AvoidStatementForDMLQueries.java (91%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/checks/AvoidUsageOfStaticCollections.java (90%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/checks/FreeResourcesOfAutoCloseableInterface.java (93%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/checks/IncrementCheck.java (86%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/checks/InitializeBufferWithAppropriateSize.java (88%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/checks/NoFunctionCallWhenDeclaringForLoop.java (95%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/checks/OptimizeReadFileExceptions.java (94%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/checks/enums/ConstOrLiteralDeclare.java (96%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/utils/PrinterVisitor.java (89%) rename src/main/java/org/greencodeinitiative/{ => creedengo}/java/utils/StringUtils.java (81%) rename src/main/resources/org/greencodeinitiative/{java/ecoCode_way_profile.json => creedengo/java/creedengo_way_profile.json} (87%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/JavaCheckRegistrarTest.java (87%) rename src/test/java/org/greencodeinitiative/{java/JavaEcoCodeWayProfileTest.java => creedengo/java/JavaCreedengoWayProfileTest.java} (69%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/JavaPluginTest.java (84%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/JavaRulesDefinitionTest.java (87%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/checks/ArrayCopyCheckTest.java (81%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/checks/AvoidFullSQLRequestCheckTest.java (80%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/checks/AvoidGettingSizeCollectionInLoopTest.java (91%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/checks/AvoidMultipleIfElseStatementTest.java (89%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/checks/AvoidRegexPatternNotStaticTest.java (85%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/checks/AvoidSQLRequestInLoopCheckTest.java (80%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/checks/AvoidSetConstantInBatchInsertTest.java (81%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java (78%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java (78%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/checks/AvoidStatementForDMLQueriesTest.java (80%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/checks/AvoidUsageOfStaticCollectionsTests.java (84%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java (85%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/checks/IncrementCheckTest.java (80%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/checks/InitializeBufferWithAppropriateSizeTest.java (81%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java (81%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/checks/OptimizeReadFileExceptionCheckTest.java (89%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/utils/FilesUtils.java (92%) rename src/test/java/org/greencodeinitiative/{ => creedengo}/java/utils/StringUtilsTest.java (84%) diff --git a/.github/workflows/_BACKUP_manual_release.yml b/.github/workflows/_BACKUP_manual_release.yml index 09307548..6b9164a1 100644 --- a/.github/workflows/_BACKUP_manual_release.yml +++ b/.github/workflows/_BACKUP_manual_release.yml @@ -60,7 +60,7 @@ jobs: id: export_jar_files uses: actions/upload-artifact@v3 with: - name: ecocode-plugins + name: creedengo-plugins path: lib - name: Export LAST_TAG id: export_last_tag @@ -77,7 +77,7 @@ jobs: id: import_jar_files uses: actions/download-artifact@v3 with: - name: ecocode-plugins + name: creedengo-plugins path: lib - name: Upload Release Asset - Java Plugin id: upload-release-asset diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bcfbdeab..ca18beeb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -51,4 +51,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: ./mvnw -e -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=green-code-initiative_ecoCode-java + run: ./mvnw -e -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=green-code-initiative_creedengo-java diff --git a/.github/workflows/build_container.yml b/.github/workflows/build_container.yml index eda94a3e..e2fc184c 100644 --- a/.github/workflows/build_container.yml +++ b/.github/workflows/build_container.yml @@ -14,7 +14,7 @@ on: env: # github.repository as / -# IMAGE_NAME: sonarqube-ecocode +# IMAGE_NAME: sonarqube-creedengo # IMAGES: | # ghcr.io/${{ github.repository_owner }}/sonarqube-ecocode IMAGE_NAME: sonarqube-ecocode-java diff --git a/.github/workflows/tag_release.yml b/.github/workflows/tag_release.yml index 75e6e624..0dcf0090 100644 --- a/.github/workflows/tag_release.yml +++ b/.github/workflows/tag_release.yml @@ -45,7 +45,7 @@ jobs: id: export_jar_files uses: actions/upload-artifact@v3 with: - name: ecocode-plugins + name: creedengo-plugins path: target - name: Export UPLOAD_URL id: export_upload_url @@ -60,7 +60,7 @@ jobs: id: import_jar_files uses: actions/download-artifact@v3 with: - name: ecocode-plugins + name: creedengo-plugins path: target - name: Upload Release Asset - Java Plugin id: upload-release-asset @@ -69,6 +69,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{needs.build.outputs.upload_url}} - asset_path: target/ecocode-java-plugin-${{ github.ref_name }}.jar + asset_path: target/creedengo-java-plugin-${{ github.ref_name }}.jar asset_name: ecocode-java-plugin-${{ github.ref_name }}.jar asset_content_type: application/zip diff --git a/Dockerfile b/Dockerfile index 421eacda..502c2224 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,14 +3,14 @@ ARG SONARQUBE_VERSION=10.6.0-community FROM maven:${MAVEN_BUILDER} AS builder -COPY . /usr/src/ecocode +COPY . /usr/src/creedengo -WORKDIR /usr/src/ecocode +WORKDIR /usr/src/creedengo COPY src src/ COPY pom.xml tool_build.sh ./ RUN ./tool_build.sh FROM sonarqube:${SONARQUBE_VERSION} -COPY --from=builder /usr/src/ecocode/target/ecocode-*.jar /opt/sonarqube/extensions/plugins/ +COPY --from=builder /usr/src/creedengo/target/creedengo-*.jar /opt/sonarqube/extensions/plugins/ USER sonarqube diff --git a/README.md b/README.md index 9c130f9b..c9e4ea4d 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ You can give a try with a one command: ./mvnw verify -Pkeep-running ``` -... 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) +... 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/creedengo-java-plugin-test-project) NB: To install other `ecocode` plugins, you can : diff --git a/docker-compose.yml b/docker-compose.yml index e84e3895..98a460d4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,9 @@ -name: sonarqube_ecocode_java +name: sonarqube_creedengo_java services: sonar: build: . - container_name: sonar_ecocode_java + container_name: sonar_creedengo_java ports: - ":9000" networks: @@ -28,7 +28,7 @@ services: db: image: postgres:12 - container_name: postgresql_ecocode_java + container_name: postgresql_creedengo_java networks: - sonarnet volumes: diff --git a/pom.xml b/pom.xml index bbe7112f..51dd9136 100644 --- a/pom.xml +++ b/pom.xml @@ -2,17 +2,17 @@ 4.0.0 - io.ecocode - ecocode-java-plugin - 1.7.0-SNAPSHOT + org.green-code-initiative + creedengo-java-plugin + 2.0.0-SNAPSHOT sonar-plugin - ecoCode - Java language + creedengo - Java language Provides rules to reduce the environmental footprint of your Java programs 2024 - https://github.com/green-code-initiative/ecoCode-java + https://github.com/green-code-initiative/creedengo-java green-code-initiative https://github.com/green-code-initiative @@ -27,15 +27,15 @@ - scm:git:https://github.com/green-code-initiative/ecocode-java - scm:git:https://github.com/green-code-initiative/ecocode-java - https://github.com/green-code-initiative/ecocode-java + scm:git:https://github.com/green-code-initiative/creedengo-java + scm:git:https://github.com/green-code-initiative/creedengo-java + https://github.com/green-code-initiative/creedengo-java HEAD GitHub - https://github.com/green-code-initiative/ecoCode-java/issues + https://github.com/green-code-initiative/creedengo-java/issues @@ -55,10 +55,10 @@ 9.9.7.96285 - + 9.8.0.203 - + 7.16.0.30901 2.5.0.1358 @@ -237,8 +237,8 @@ ${sonar-packaging.version} true - ecocodejava - org.greencodeinitiative.java.JavaPlugin + creedengojava + org.greencodeinitiative.creedengo.java.JavaPlugin true ${sonarqube.version} true @@ -298,7 +298,7 @@ - io.ecocode:ecocode-rules-specifications:* + org.green-code-initiative:creedengo-rules-specifications:* META-INF/** @@ -383,7 +383,7 @@ Green Code Initiative - https://www.ecocode.io + https://green-code-initiative.org @@ -470,15 +470,15 @@ - ${project.baseUri}/src/main/resources/org/greencodeinitiative/java/ecoCode_way_profile.json, + ${project.baseUri}/src/main/resources/org/greencodeinitiative/creedengo/java/creedengo_way_profile.json, - 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, + org.green-code-initiative:creedengo-java-plugin-test-project|creedengo Java Sonar Plugin Test Project|${project.baseUri}/src/it/test-projects/creedengo-java-plugin-test-project/pom.xml, - java|ecoCode way, + java|creedengo way, @@ -493,7 +493,8 @@ keep-running true - 9000 + + 33333 diff --git a/src/it/java/io/ecocode/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java similarity index 97% rename from src/it/java/io/ecocode/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java rename to src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java index aa487a47..8a556d02 100644 --- a/src/it/java/io/ecocode/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java +++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java @@ -1,4 +1,4 @@ -package io.ecocode.java.integration.tests; +package org.greencodeinitiative.creedengo.java.integration.tests; import java.net.MalformedURLException; import java.net.URI; @@ -23,7 +23,7 @@ import com.sonar.orchestrator.locator.Location; import com.sonar.orchestrator.locator.MavenLocation; import com.sonar.orchestrator.locator.URLLocation; -import io.ecocode.java.integration.tests.profile.ProfileBackup; +import org.greencodeinitiative.creedengo.java.integration.tests.profile.ProfileBackup; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -136,12 +136,12 @@ void test() { List projectIssues = issuesForComponent(projectKey); assertThat(projectIssues).isNotEmpty(); - List issuesForArrayCopyCheck = issuesForFile(projectKey, "src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java"); + List issuesForArrayCopyCheck = issuesForFile(projectKey, "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java"); assertThat(issuesForArrayCopyCheck) .hasSize(1) .first().satisfies(issue -> { - assertThat(issue.getRule()).isEqualTo("ecocode-java:GCI69"); + assertThat(issue.getRule()).isEqualTo("creedengo-java:GCI69"); assertThat(issue.getSeverity()).isEqualTo(MINOR); assertThat(issue.getLine()).isEqualTo(18); assertThat(issue.getTextRange().getStartLine()).isEqualTo(18); diff --git a/src/it/java/io/ecocode/java/integration/tests/profile/ProfileBackup.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/ProfileBackup.java similarity index 90% rename from src/it/java/io/ecocode/java/integration/tests/profile/ProfileBackup.java rename to src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/ProfileBackup.java index 43cadad2..26feba22 100644 --- a/src/it/java/io/ecocode/java/integration/tests/profile/ProfileBackup.java +++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/ProfileBackup.java @@ -1,4 +1,4 @@ -package io.ecocode.java.integration.tests.profile; +package org.greencodeinitiative.creedengo.java.integration.tests.profile; import java.io.IOException; import java.io.InputStream; @@ -19,7 +19,7 @@ *

Example, following JSON profile:

*
  * {
- *  "name": "ecoCode way",
+ *  "name": "creedengo way",
  *  "language": "java",
  *  "ruleKeys": [
  * 	    "GCI1",
@@ -31,18 +31,18 @@
  * 
  * <?xml version='1.0' encoding='UTF-8'?>
  * <profile>
- * 	<name>ecoCode way</name>
+ * 	<name>creedengo way</name>
  * 	<language>java</language>
  * 	<rules>
  * 		<rule>
- * 			<repositoryKey>ecocode-java</repositoryKey>
+ * 			<repositoryKey>creedengo-java</repositoryKey>
  * 			<key>GCI1</key>
  * 			<type>CODE_SMELL</type>
  * 			<priority>MINOR</priority>
  * 			<parameters />
  * 		</rule>
  * 		<rule>
- * 			<repositoryKey>ecocode-java</repositoryKey>
+ * 			<repositoryKey>creedengo-java</repositoryKey>
  * 			<key>GCI2</key>
  * 			<type>CODE_SMELL</type>
  * 			<priority>MINOR</priority>
@@ -98,7 +98,7 @@ private ProfileMetadata profileMetadata() {
 	}
 
 	private RuleMetadata loadRule(String language, String ruleKey) {
-		try (InputStream ruleMetadataJsonFile = ClassLoader.getSystemResourceAsStream("io/ecocode/rules/" + language + "/" + ruleKey + ".json")) {
+		try (InputStream ruleMetadataJsonFile = ClassLoader.getSystemResourceAsStream("org/green-code-initiative/rules/" + language + "/" + ruleKey + ".json")) {
 			RuleMetadata result = mapper.readValue(ruleMetadataJsonFile, RuleMetadata.class);
 			result.setKey(ruleKey);
 			return result;
@@ -114,7 +114,7 @@ private String xmlProfile() throws IOException {
 		                                          .map(ruleKey -> this.loadRule(language, ruleKey))
 		                                          .collect(Collectors.toList());
 		StringBuilder output = new StringBuilder();
-		String repositoryKey = "ecocode-" + profileMetadata.getLanguage();
+		String repositoryKey = "creedengo-" + profileMetadata.getLanguage();
 		rules.forEach(rule -> output.append(
 				xmlRule(
 						repositoryKey,
diff --git a/src/it/java/io/ecocode/java/integration/tests/profile/ProfileMetadata.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/ProfileMetadata.java
similarity index 90%
rename from src/it/java/io/ecocode/java/integration/tests/profile/ProfileMetadata.java
rename to src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/ProfileMetadata.java
index 85b65f41..80789148 100644
--- a/src/it/java/io/ecocode/java/integration/tests/profile/ProfileMetadata.java
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/ProfileMetadata.java
@@ -1,4 +1,4 @@
-package io.ecocode.java.integration.tests.profile;
+package org.greencodeinitiative.creedengo.java.integration.tests.profile;
 
 import java.util.List;
 
diff --git a/src/it/java/io/ecocode/java/integration/tests/profile/RuleMetadata.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/RuleMetadata.java
similarity index 90%
rename from src/it/java/io/ecocode/java/integration/tests/profile/RuleMetadata.java
rename to src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/RuleMetadata.java
index 21bd763a..8f6bc99f 100644
--- a/src/it/java/io/ecocode/java/integration/tests/profile/RuleMetadata.java
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/RuleMetadata.java
@@ -1,4 +1,4 @@
-package io.ecocode.java.integration.tests.profile;
+package org.greencodeinitiative.creedengo.java.integration.tests.profile;
 
 public class RuleMetadata {
 	private String key;
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/pom.xml b/src/it/test-projects/creedengo-java-plugin-test-project/pom.xml
similarity index 87%
rename from src/it/test-projects/ecocode-java-plugin-test-project/pom.xml
rename to src/it/test-projects/creedengo-java-plugin-test-project/pom.xml
index c059b1fd..cfb7ba4f 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/pom.xml
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/pom.xml
@@ -3,11 +3,11 @@
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     4.0.0
 
-    io.ecocode
-    ecocode-java-plugin-test-project
+    org.green-code-initiative
+    creedengo-java-plugin-test-project
     0.0.1-SNAPSHOT
 
-    ecoCode Java Sonar Plugin Test Project
+    creedengo Java Sonar Plugin Test Project
 
     
         17
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java
similarity index 99%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java
index 85197155..a7dbff89 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Arrays;
 
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheck.java
similarity index 94%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheck.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheck.java
index 5fbcf140..a525a429 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheck.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheck.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 class AvoidFullSQLRequestCheck {
     AvoidFullSQLRequestCheck(AvoidFullSQLRequestCheck mc) {
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java
similarity index 91%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java
index fbec63c7..c24f9c92 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.ArrayList;
 import java.util.List;
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopBad.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java
similarity index 90%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopBad.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java
index 782ffbec..d3b8af41 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopBad.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.ArrayList;
 import java.util.List;
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopGood.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopGood.java
similarity index 91%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopGood.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopGood.java
index 20bfd37f..88d98861 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopGood.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopGood.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Collection;
 import java.util.ArrayList;
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java
similarity index 90%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java
index e12525b0..91775b0f 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.ArrayList;
 import java.util.Iterator;
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java
similarity index 90%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java
index 858db7bc..7410af92 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.ArrayList;
 import java.util.List;
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java
similarity index 91%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java
index 774589c2..a09e89e5 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.ArrayList;
 import java.util.List;
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java
similarity index 91%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java
index 60f82d79..c22b216b 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.ArrayList;
 import java.util.Iterator;
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java
similarity index 99%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java
index 2127b164..23ad4ccf 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 class AvoidMultipleIfElseStatement {
 
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java
similarity index 97%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java
index c2c60686..1095d923 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 class AvoidMultipleIfElseStatementCompareMethodNoIssue {
 
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java
similarity index 76%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java
index c1aef731..d6771090 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 interface AvoidMultipleIfElseStatementInterfaceNoIssue {
 
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java
similarity index 77%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java
index 8bbb202e..cf1a104e 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 class AvoidMultipleIfElseStatementNoBlockNoIssue {
 
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoIssue.java
similarity index 99%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoIssue.java
index 2c4a87da..f787785c 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementNoIssue.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoIssue.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 class AvoidMultipleIfElseStatementNoIssue {
 
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java
similarity index 84%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java
index 6ca37ede..20d9c24d 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.regex.Pattern;
 
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheck.java
similarity index 98%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheck.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheck.java
index b0a7929c..cb185891 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheck.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheck.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java
similarity index 99%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java
index 57f9b046..30654d98 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdateCheck.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.math.BigDecimal;
 import java.sql.Connection;
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheck.java
similarity index 88%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheck.java
index 310a2577..6e1a2d89 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheck.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.jpa.repository.JpaRepository;
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheck.java
similarity index 95%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheck.java
index e1fe5fb1..1716a3d7 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheck.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheck.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.jpa.repository.JpaRepository;
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java
similarity index 91%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java
index 94bd2d86..def8b5b8 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java
similarity index 90%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java
index 85b078d9..476fbda8 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.*;
 
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java
similarity index 95%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java
index 741b5a7a..95ed3506 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.io.*;
 
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/GoodUsageOfStaticCollections.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GoodUsageOfStaticCollections.java
similarity index 89%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/GoodUsageOfStaticCollections.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GoodUsageOfStaticCollections.java
index e5006c45..ebe2f8bc 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/GoodUsageOfStaticCollections.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GoodUsageOfStaticCollections.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.*;
 
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/GoodWayConcatenateStringsLoop.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GoodWayConcatenateStringsLoop.java
similarity index 92%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/GoodWayConcatenateStringsLoop.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GoodWayConcatenateStringsLoop.java
index 55455686..605a67c8 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/GoodWayConcatenateStringsLoop.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GoodWayConcatenateStringsLoop.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 public class GoodWayConcatenateStringsLoop {
 
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java
similarity index 94%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java
index 35210be4..fc513b96 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 class IncrementCheck {
     IncrementCheck(IncrementCheck mc) {
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java
similarity index 93%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java
index 2c38adc7..8cc73e29 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 class InitializeBufferWithAppropriateSize {
 	InitializeBufferWithAppropriateSize(InitializeBufferWithAppropriateSize mc) {
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
similarity index 96%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
index 41ca01e7..bb5ae326 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 class NoFunctionCallWhenDeclaringForLoop {
     NoFunctionCallWhenDeclaringForLoop(NoFunctionCallWhenDeclaringForLoop mc) {
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java
similarity index 92%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java
index 1b07e9d8..91520bd5 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck2.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java
similarity index 92%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck2.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java
index fb7eeac2..205b814a 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck2.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck3.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java
similarity index 92%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck3.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java
index eef28168..a26b6ea7 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck3.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.io.FileInputStream;
 import java.io.IOException;
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck4.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java
similarity index 91%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck4.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java
index b5fba918..80a75d9d 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck4.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.io.FileInputStream;
 import java.io.InputStream;
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck5.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java
similarity index 91%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck5.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java
index 7343b86c..2115bef1 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheck5.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.io.FileInputStream;
 import java.io.InputStream;
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeSQLQueriesWithLimit.java
similarity index 94%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeSQLQueriesWithLimit.java
index a00f2a97..e592528d 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/OptimizeSQLQueriesWithLimit.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeSQLQueriesWithLimit.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.springframework.data.jpa.repository.Query;
 
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ValidRegexPattern.java
similarity index 80%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ValidRegexPattern.java
index 66a001b4..9943c20d 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ValidRegexPattern.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.regex.Pattern;
 
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern2.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ValidRegexPattern2.java
similarity index 80%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern2.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ValidRegexPattern2.java
index d8ec0756..3ceb82a5 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern2.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ValidRegexPattern2.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.regex.Pattern;
 
diff --git a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern3.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ValidRegexPattern3.java
similarity index 83%
rename from src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern3.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ValidRegexPattern3.java
index 8005b5c8..a9b64c2b 100644
--- a/src/it/test-projects/ecocode-java-plugin-test-project/src/main/java/fr/greencodeinitiative/java/checks/ValidRegexPattern3.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ValidRegexPattern3.java
@@ -1,4 +1,4 @@
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.regex.Pattern;
 
diff --git a/src/main/java/org/greencodeinitiative/java/JavaCheckRegistrar.java b/src/main/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrar.java
similarity index 65%
rename from src/main/java/org/greencodeinitiative/java/JavaCheckRegistrar.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrar.java
index 9994e5ab..60ae37d8 100644
--- a/src/main/java/org/greencodeinitiative/java/JavaCheckRegistrar.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrar.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,26 +15,26 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java;
+package org.greencodeinitiative.creedengo.java;
 
 import java.util.Collections;
 import java.util.List;
 
-import org.greencodeinitiative.java.checks.ArrayCopyCheck;
-import org.greencodeinitiative.java.checks.AvoidFullSQLRequest;
-import org.greencodeinitiative.java.checks.AvoidGettingSizeCollectionInLoop;
-import org.greencodeinitiative.java.checks.AvoidMultipleIfElseStatement;
-import org.greencodeinitiative.java.checks.AvoidRegexPatternNotStatic;
-import org.greencodeinitiative.java.checks.AvoidSQLRequestInLoop;
-import org.greencodeinitiative.java.checks.AvoidSetConstantInBatchUpdate;
-import org.greencodeinitiative.java.checks.AvoidSpringRepositoryCallInLoopOrStreamCheck;
-import org.greencodeinitiative.java.checks.AvoidStatementForDMLQueries;
-import org.greencodeinitiative.java.checks.AvoidUsageOfStaticCollections;
-import org.greencodeinitiative.java.checks.FreeResourcesOfAutoCloseableInterface;
-import org.greencodeinitiative.java.checks.IncrementCheck;
-import org.greencodeinitiative.java.checks.InitializeBufferWithAppropriateSize;
-import org.greencodeinitiative.java.checks.NoFunctionCallWhenDeclaringForLoop;
-import org.greencodeinitiative.java.checks.OptimizeReadFileExceptions;
+import org.greencodeinitiative.creedengo.java.checks.ArrayCopyCheck;
+import org.greencodeinitiative.creedengo.java.checks.AvoidFullSQLRequest;
+import org.greencodeinitiative.creedengo.java.checks.AvoidGettingSizeCollectionInLoop;
+import org.greencodeinitiative.creedengo.java.checks.AvoidMultipleIfElseStatement;
+import org.greencodeinitiative.creedengo.java.checks.AvoidRegexPatternNotStatic;
+import org.greencodeinitiative.creedengo.java.checks.AvoidSQLRequestInLoop;
+import org.greencodeinitiative.creedengo.java.checks.AvoidSetConstantInBatchUpdate;
+import org.greencodeinitiative.creedengo.java.checks.AvoidSpringRepositoryCallInLoopOrStreamCheck;
+import org.greencodeinitiative.creedengo.java.checks.AvoidStatementForDMLQueries;
+import org.greencodeinitiative.creedengo.java.checks.AvoidUsageOfStaticCollections;
+import org.greencodeinitiative.creedengo.java.checks.FreeResourcesOfAutoCloseableInterface;
+import org.greencodeinitiative.creedengo.java.checks.IncrementCheck;
+import org.greencodeinitiative.creedengo.java.checks.InitializeBufferWithAppropriateSize;
+import org.greencodeinitiative.creedengo.java.checks.NoFunctionCallWhenDeclaringForLoop;
+import org.greencodeinitiative.creedengo.java.checks.OptimizeReadFileExceptions;
 import org.sonar.plugins.java.api.CheckRegistrar;
 import org.sonar.plugins.java.api.JavaCheck;
 import org.sonarsource.api.sonarlint.SonarLintSide;
diff --git a/src/main/java/org/greencodeinitiative/java/JavaEcoCodeWayProfile.java b/src/main/java/org/greencodeinitiative/creedengo/java/JavaCreedengoWayProfile.java
similarity index 54%
rename from src/main/java/org/greencodeinitiative/java/JavaEcoCodeWayProfile.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/JavaCreedengoWayProfile.java
index 121cb7a7..3d48034c 100644
--- a/src/main/java/org/greencodeinitiative/java/JavaEcoCodeWayProfile.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/JavaCreedengoWayProfile.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,23 +15,23 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java;
+package org.greencodeinitiative.creedengo.java;
 
 import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition;
 import org.sonarsource.analyzer.commons.BuiltInQualityProfileJsonLoader;
 
-import static org.greencodeinitiative.java.JavaRulesDefinition.LANGUAGE;
-import static org.greencodeinitiative.java.JavaRulesDefinition.REPOSITORY_KEY;
+import static org.greencodeinitiative.creedengo.java.JavaRulesDefinition.LANGUAGE;
+import static org.greencodeinitiative.creedengo.java.JavaRulesDefinition.REPOSITORY_KEY;
 
-public final class JavaEcoCodeWayProfile implements BuiltInQualityProfilesDefinition {
-	static final String PROFILE_NAME = "ecoCode way";
-	static final String PROFILE_PATH = JavaEcoCodeWayProfile.class.getPackageName().replace('.', '/') + "/ecoCode_way_profile.json";
+public final class JavaCreedengoWayProfile implements BuiltInQualityProfilesDefinition {
+	static final String PROFILE_NAME = "creedengo way";
+	static final String PROFILE_PATH = JavaCreedengoWayProfile.class.getPackageName().replace('.', '/') + "/creedengo_way_profile.json";
 
 	@Override
 	public void define(Context context) {
-		NewBuiltInQualityProfile ecoCodeProfile = context.createBuiltInQualityProfile(PROFILE_NAME, LANGUAGE);
-		loadProfile(ecoCodeProfile);
-		ecoCodeProfile.done();
+		NewBuiltInQualityProfile creedengoProfile = context.createBuiltInQualityProfile(PROFILE_NAME, LANGUAGE);
+		loadProfile(creedengoProfile);
+		creedengoProfile.done();
 	}
 
 	private void loadProfile(NewBuiltInQualityProfile profile) {
diff --git a/src/main/java/org/greencodeinitiative/java/JavaPlugin.java b/src/main/java/org/greencodeinitiative/creedengo/java/JavaPlugin.java
similarity index 82%
rename from src/main/java/org/greencodeinitiative/java/JavaPlugin.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/JavaPlugin.java
index e8daf490..ce2a95ce 100644
--- a/src/main/java/org/greencodeinitiative/java/JavaPlugin.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/JavaPlugin.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java;
+package org.greencodeinitiative.creedengo.java;
 
 import org.sonar.api.Plugin;
 
diff --git a/src/main/java/org/greencodeinitiative/java/JavaRulesDefinition.java b/src/main/java/org/greencodeinitiative/creedengo/java/JavaRulesDefinition.java
similarity index 83%
rename from src/main/java/org/greencodeinitiative/java/JavaRulesDefinition.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/JavaRulesDefinition.java
index 3725a9ce..ff30929f 100644
--- a/src/main/java/org/greencodeinitiative/java/JavaRulesDefinition.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/JavaRulesDefinition.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java;
+package org.greencodeinitiative.creedengo.java;
 
 import java.util.ArrayList;
 
@@ -30,9 +30,9 @@
 public class JavaRulesDefinition implements RulesDefinition {
     private static final String RESOURCE_BASE_PATH = "org/green-code-initiative/rules/java";
 
-    private static final String NAME = "ecoCode";
+    private static final String NAME = "creedengo";
     static final String LANGUAGE = "java";
-    static final String REPOSITORY_KEY = "ecocode-java";
+    static final String REPOSITORY_KEY = "creedengo-java";
 
     private final SonarRuntime sonarRuntime;
 
diff --git a/src/main/java/org/greencodeinitiative/java/checks/ArrayCopyCheck.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java
similarity index 97%
rename from src/main/java/org/greencodeinitiative/java/checks/ArrayCopyCheck.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java
index 86294b62..bc4d569e 100644
--- a/src/main/java/org/greencodeinitiative/java/checks/ArrayCopyCheck.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.ArrayList;
 import java.util.Arrays;
diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequest.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequest.java
similarity index 89%
rename from src/main/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequest.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequest.java
index 7f05d29c..e2c7fb67 100644
--- a/src/main/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequest.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.List;
 import java.util.function.Predicate;
diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInLoop.java
similarity index 95%
rename from src/main/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInLoop.java
index eaf85aca..53f2e085 100644
--- a/src/main/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInLoop.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Arrays;
 import java.util.List;
diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java
similarity index 98%
rename from src/main/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java
index 9c27de75..7343979c 100644
--- a/src/main/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.HashMap;
 import java.util.List;
@@ -35,7 +35,7 @@
 import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
 
 /**
- * FUNCTIONAL DESCRIPTION : please see ASCIIDOC description file of this rule (inside `ecocode-rules-spcifications`)
+ * FUNCTIONAL DESCRIPTION : please see ASCIIDOC description file of this rule (inside `creedengo-rules-spcifications`)
  * TECHNICAL CHOICES :
  * - Kind.IF_STATEMENT, Kind.ELSE_STATEMENT, Kind.ELSEIF_STATEMENT not used because it isn't possible
  * to keep parent references to check later if variables already used or not in parent tree
diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java
similarity index 91%
rename from src/main/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java
index 4be3b228..beb1cea6 100644
--- a/src/main/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Collections;
 import java.util.List;
diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoop.java
similarity index 94%
rename from src/main/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoop.java
index b00f710f..0e830dcf 100644
--- a/src/main/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoop.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Arrays;
 import java.util.List;
diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdate.java
similarity index 89%
rename from src/main/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdate.java
index 70f7a0df..20c3e23e 100644
--- a/src/main/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdate.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,14 +15,14 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.sql.PreparedStatement;
 import java.util.List;
 import java.util.stream.Stream;
 
-import org.greencodeinitiative.java.checks.enums.ConstOrLiteralDeclare;
-import static org.greencodeinitiative.java.checks.enums.ConstOrLiteralDeclare.isLiteral;
+import org.greencodeinitiative.creedengo.java.checks.enums.ConstOrLiteralDeclare;
+import static org.greencodeinitiative.creedengo.java.checks.enums.ConstOrLiteralDeclare.isLiteral;
 import static java.util.Arrays.asList;
 
 import org.sonar.check.Rule;
diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java
similarity index 95%
rename from src/main/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java
index 02b8e198..a71777c0 100644
--- a/src/main/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopOrStreamCheck.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Arrays;
 import java.util.List;
diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java
similarity index 91%
rename from src/main/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java
index 69217dd9..cb335e04 100644
--- a/src/main/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Collections;
 import java.util.List;
diff --git a/src/main/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java
similarity index 90%
rename from src/main/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java
index 474b267d..8017381a 100644
--- a/src/main/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Collections;
 import java.util.List;
diff --git a/src/main/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java
similarity index 93%
rename from src/main/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java
index 76f10091..2b669145 100644
--- a/src/main/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.ArrayList;
 import java.util.Arrays;
diff --git a/src/main/java/org/greencodeinitiative/java/checks/IncrementCheck.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java
similarity index 86%
rename from src/main/java/org/greencodeinitiative/java/checks/IncrementCheck.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java
index f2838ecb..d5a2a42b 100644
--- a/src/main/java/org/greencodeinitiative/java/checks/IncrementCheck.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Collections;
 import java.util.List;
diff --git a/src/main/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java
similarity index 88%
rename from src/main/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java
index 176364c8..7bcb3b73 100644
--- a/src/main/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Collections;
 import java.util.List;
diff --git a/src/main/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
similarity index 95%
rename from src/main/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
index be1c6b3e..8ebb8dbf 100644
--- a/src/main/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.ArrayList;
 import java.util.Collection;
diff --git a/src/main/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptions.java
similarity index 94%
rename from src/main/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptions.java
index 3d95b6ba..76a74b28 100644
--- a/src/main/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptions.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 
 import java.util.Arrays;
diff --git a/src/main/java/org/greencodeinitiative/java/checks/enums/ConstOrLiteralDeclare.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/enums/ConstOrLiteralDeclare.java
similarity index 96%
rename from src/main/java/org/greencodeinitiative/java/checks/enums/ConstOrLiteralDeclare.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/checks/enums/ConstOrLiteralDeclare.java
index 99c20707..1ef973a5 100644
--- a/src/main/java/org/greencodeinitiative/java/checks/enums/ConstOrLiteralDeclare.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/enums/ConstOrLiteralDeclare.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks.enums;
+package org.greencodeinitiative.creedengo.java.checks.enums;
 
 import java.math.BigDecimal;
 import java.util.Set;
diff --git a/src/main/java/org/greencodeinitiative/java/utils/PrinterVisitor.java b/src/main/java/org/greencodeinitiative/creedengo/java/utils/PrinterVisitor.java
similarity index 89%
rename from src/main/java/org/greencodeinitiative/java/utils/PrinterVisitor.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/utils/PrinterVisitor.java
index 701ebe7b..fa245893 100644
--- a/src/main/java/org/greencodeinitiative/java/utils/PrinterVisitor.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/utils/PrinterVisitor.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.utils;
+package org.greencodeinitiative.creedengo.java.utils;
 
 import java.util.List;
 import java.util.function.Consumer;
diff --git a/src/main/java/org/greencodeinitiative/java/utils/StringUtils.java b/src/main/java/org/greencodeinitiative/creedengo/java/utils/StringUtils.java
similarity index 81%
rename from src/main/java/org/greencodeinitiative/java/utils/StringUtils.java
rename to src/main/java/org/greencodeinitiative/creedengo/java/utils/StringUtils.java
index 46b723e4..ce66a882 100644
--- a/src/main/java/org/greencodeinitiative/java/utils/StringUtils.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/utils/StringUtils.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.utils;
+package org.greencodeinitiative.creedengo.java.utils;
 
 public final class StringUtils {
 
diff --git a/src/main/resources/org/greencodeinitiative/java/ecoCode_way_profile.json b/src/main/resources/org/greencodeinitiative/creedengo/java/creedengo_way_profile.json
similarity index 87%
rename from src/main/resources/org/greencodeinitiative/java/ecoCode_way_profile.json
rename to src/main/resources/org/greencodeinitiative/creedengo/java/creedengo_way_profile.json
index 9bb5d9ec..eed2a19a 100644
--- a/src/main/resources/org/greencodeinitiative/java/ecoCode_way_profile.json
+++ b/src/main/resources/org/greencodeinitiative/creedengo/java/creedengo_way_profile.json
@@ -1,5 +1,5 @@
 {
-  "name": "ecoCode way",
+  "name": "creedengo way",
   "language": "java",
   "ruleKeys": [
 	"GCI1",
diff --git a/src/test/files/ArrayCopyCheck.java b/src/test/files/ArrayCopyCheck.java
index 3e85bb93..79d8353d 100644
--- a/src/test/files/ArrayCopyCheck.java
+++ b/src/test/files/ArrayCopyCheck.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
diff --git a/src/test/files/AvoidFullSQLRequestCheck.java b/src/test/files/AvoidFullSQLRequestCheck.java
index c2864520..2d6b2e6a 100644
--- a/src/test/files/AvoidFullSQLRequestCheck.java
+++ b/src/test/files/AvoidFullSQLRequestCheck.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.regex.Pattern;
 
diff --git a/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java b/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java
index 811863fd..ce4eeac9 100644
--- a/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java
+++ b/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Collection;
 import java.util.ArrayList;
diff --git a/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java b/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java
index 4bc2cc0b..c21f81c8 100644
--- a/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java
+++ b/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Collection;
 import java.util.ArrayList;
diff --git a/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java b/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java
index b8a1e592..691bc334 100644
--- a/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java
+++ b/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Collection;
 import java.util.ArrayList;
diff --git a/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java b/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java
index f22ca28e..ced5bf08 100644
--- a/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java
+++ b/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Collection;
 import java.util.ArrayList;
diff --git a/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java b/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java
index 50ee0155..def86d2b 100644
--- a/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java
+++ b/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Collection;
 import java.util.ArrayList;
diff --git a/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java b/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java
index 2f799668..713998d5 100644
--- a/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java
+++ b/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Collection;
 import java.util.ArrayList;
diff --git a/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java b/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java
index 4c9bfc95..99009585 100644
--- a/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java
+++ b/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Collection;
 import java.util.ArrayList;
diff --git a/src/test/files/AvoidMultipleIfElseStatement.java b/src/test/files/AvoidMultipleIfElseStatement.java
index 96181a67..52bc42ac 100644
--- a/src/test/files/AvoidMultipleIfElseStatement.java
+++ b/src/test/files/AvoidMultipleIfElseStatement.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 class AvoidMultipleIfElseStatementCheck {
 
diff --git a/src/test/files/AvoidMultipleIfElseStatementCompareMethod.java b/src/test/files/AvoidMultipleIfElseStatementCompareMethod.java
index 2eb67447..fdf00d60 100644
--- a/src/test/files/AvoidMultipleIfElseStatementCompareMethod.java
+++ b/src/test/files/AvoidMultipleIfElseStatementCompareMethod.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 class AvoidMultipleIfElseStatementCompareMethod {
 
diff --git a/src/test/files/AvoidMultipleIfElseStatementInterface.java b/src/test/files/AvoidMultipleIfElseStatementInterface.java
index 6b79f62c..c9c76041 100644
--- a/src/test/files/AvoidMultipleIfElseStatementInterface.java
+++ b/src/test/files/AvoidMultipleIfElseStatementInterface.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 interface AvoidMultipleIfElseStatementCheck {
 
diff --git a/src/test/files/AvoidMultipleIfElseStatementNoIssue.java b/src/test/files/AvoidMultipleIfElseStatementNoIssue.java
index b7d92232..53e72dd1 100644
--- a/src/test/files/AvoidMultipleIfElseStatementNoIssue.java
+++ b/src/test/files/AvoidMultipleIfElseStatementNoIssue.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 class AvoidMultipleIfElseStatementCheckNoIssue {
 
diff --git a/src/test/files/AvoidMultipleIfElseStatementNotBlock.java b/src/test/files/AvoidMultipleIfElseStatementNotBlock.java
index 18607235..46a5691f 100644
--- a/src/test/files/AvoidMultipleIfElseStatementNotBlock.java
+++ b/src/test/files/AvoidMultipleIfElseStatementNotBlock.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 class AvoidMultipleIfElseStatementNotBlock {
 
diff --git a/src/test/files/AvoidRegexPatternNotStatic.java b/src/test/files/AvoidRegexPatternNotStatic.java
index 129ad2af..76387635 100644
--- a/src/test/files/AvoidRegexPatternNotStatic.java
+++ b/src/test/files/AvoidRegexPatternNotStatic.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.regex.Pattern;
 
diff --git a/src/test/files/AvoidSQLRequestInLoopCheck.java b/src/test/files/AvoidSQLRequestInLoopCheck.java
index e894ea20..f75e0c92 100644
--- a/src/test/files/AvoidSQLRequestInLoopCheck.java
+++ b/src/test/files/AvoidSQLRequestInLoopCheck.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
diff --git a/src/test/files/AvoidSetConstantInBatchUpdateCheck.java b/src/test/files/AvoidSetConstantInBatchUpdateCheck.java
index 0b6b74f4..6e4ecf41 100644
--- a/src/test/files/AvoidSetConstantInBatchUpdateCheck.java
+++ b/src/test/files/AvoidSetConstantInBatchUpdateCheck.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.math.BigDecimal;
 import java.sql.PreparedStatement;
diff --git a/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java b/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java
index ab492606..3d386901 100644
--- a/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java
+++ b/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.jpa.repository.JpaRepository;
diff --git a/src/test/files/AvoidSpringRepositoryCallInStreamCheck.java b/src/test/files/AvoidSpringRepositoryCallInStreamCheck.java
index d623db61..6acf592f 100644
--- a/src/test/files/AvoidSpringRepositoryCallInStreamCheck.java
+++ b/src/test/files/AvoidSpringRepositoryCallInStreamCheck.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.jpa.repository.JpaRepository;
diff --git a/src/test/files/AvoidStatementForDMLQueries.java b/src/test/files/AvoidStatementForDMLQueries.java
index dfe7266c..a056dbbe 100644
--- a/src/test/files/AvoidStatementForDMLQueries.java
+++ b/src/test/files/AvoidStatementForDMLQueries.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
diff --git a/src/test/files/AvoidUsageOfStaticCollections.java b/src/test/files/AvoidUsageOfStaticCollections.java
index 30213cf3..f14de6aa 100644
--- a/src/test/files/AvoidUsageOfStaticCollections.java
+++ b/src/test/files/AvoidUsageOfStaticCollections.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.*;
 
diff --git a/src/test/files/FreeResourcesOfAutoCloseableInterface.java b/src/test/files/FreeResourcesOfAutoCloseableInterface.java
index e2174a5d..08ba1622 100644
--- a/src/test/files/FreeResourcesOfAutoCloseableInterface.java
+++ b/src/test/files/FreeResourcesOfAutoCloseableInterface.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.io.*;
 
diff --git a/src/test/files/GoodUsageOfStaticCollections.java b/src/test/files/GoodUsageOfStaticCollections.java
index 200f9732..9da5eae2 100644
--- a/src/test/files/GoodUsageOfStaticCollections.java
+++ b/src/test/files/GoodUsageOfStaticCollections.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.*;
 
diff --git a/src/test/files/GoodWayConcatenateStringsLoop.java b/src/test/files/GoodWayConcatenateStringsLoop.java
index eb84f353..a082875e 100644
--- a/src/test/files/GoodWayConcatenateStringsLoop.java
+++ b/src/test/files/GoodWayConcatenateStringsLoop.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.utils;
+package org.greencodeinitiative.creedengo.java.utils;
 
 public class GoodWayConcatenateStringsLoop {
 
diff --git a/src/test/files/IncrementCheck.java b/src/test/files/IncrementCheck.java
index 1055e656..d3c77559 100644
--- a/src/test/files/IncrementCheck.java
+++ b/src/test/files/IncrementCheck.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
diff --git a/src/test/files/InitializeBufferWithAppropriateSize.java b/src/test/files/InitializeBufferWithAppropriateSize.java
index 260ead6d..a83c21e7 100644
--- a/src/test/files/InitializeBufferWithAppropriateSize.java
+++ b/src/test/files/InitializeBufferWithAppropriateSize.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
diff --git a/src/test/files/NoFunctionCallWhenDeclaringForLoop.java b/src/test/files/NoFunctionCallWhenDeclaringForLoop.java
index 8321c888..10214628 100644
--- a/src/test/files/NoFunctionCallWhenDeclaringForLoop.java
+++ b/src/test/files/NoFunctionCallWhenDeclaringForLoop.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
diff --git a/src/test/files/OptimizeReadFileExceptionCheck.java b/src/test/files/OptimizeReadFileExceptionCheck.java
index 5eace2a6..2bafe97a 100644
--- a/src/test/files/OptimizeReadFileExceptionCheck.java
+++ b/src/test/files/OptimizeReadFileExceptionCheck.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Arrays;
 import java.util.List;
diff --git a/src/test/files/OptimizeReadFileExceptionCheck2.java b/src/test/files/OptimizeReadFileExceptionCheck2.java
index e974b3d7..4d1e7614 100644
--- a/src/test/files/OptimizeReadFileExceptionCheck2.java
+++ b/src/test/files/OptimizeReadFileExceptionCheck2.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Arrays;
 import java.util.List;
diff --git a/src/test/files/OptimizeReadFileExceptionCheck3.java b/src/test/files/OptimizeReadFileExceptionCheck3.java
index 83aac949..7b9292f0 100644
--- a/src/test/files/OptimizeReadFileExceptionCheck3.java
+++ b/src/test/files/OptimizeReadFileExceptionCheck3.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Arrays;
 import java.util.List;
diff --git a/src/test/files/OptimizeReadFileExceptionCheck4.java b/src/test/files/OptimizeReadFileExceptionCheck4.java
index 33caa46d..5096450f 100644
--- a/src/test/files/OptimizeReadFileExceptionCheck4.java
+++ b/src/test/files/OptimizeReadFileExceptionCheck4.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Arrays;
 import java.util.List;
diff --git a/src/test/files/OptimizeReadFileExceptionCheck5.java b/src/test/files/OptimizeReadFileExceptionCheck5.java
index 5367ffd9..8754e265 100644
--- a/src/test/files/OptimizeReadFileExceptionCheck5.java
+++ b/src/test/files/OptimizeReadFileExceptionCheck5.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.Arrays;
 import java.util.List;
diff --git a/src/test/files/ValidRegexPattern.java b/src/test/files/ValidRegexPattern.java
index 942432a6..c52eb0e1 100644
--- a/src/test/files/ValidRegexPattern.java
+++ b/src/test/files/ValidRegexPattern.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.regex.Pattern;
 
diff --git a/src/test/files/ValidRegexPattern2.java b/src/test/files/ValidRegexPattern2.java
index 92f88c82..4c2c0e02 100644
--- a/src/test/files/ValidRegexPattern2.java
+++ b/src/test/files/ValidRegexPattern2.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.regex.Pattern;
 
diff --git a/src/test/files/ValidRegexPattern3.java b/src/test/files/ValidRegexPattern3.java
index e6dfb88c..8cf41661 100644
--- a/src/test/files/ValidRegexPattern3.java
+++ b/src/test/files/ValidRegexPattern3.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import java.util.regex.Pattern;
 
diff --git a/src/test/java/org/greencodeinitiative/java/JavaCheckRegistrarTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrarTest.java
similarity index 87%
rename from src/test/java/org/greencodeinitiative/java/JavaCheckRegistrarTest.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrarTest.java
index 9ced970b..68ce968f 100644
--- a/src/test/java/org/greencodeinitiative/java/JavaCheckRegistrarTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrarTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java;
+package org.greencodeinitiative.creedengo.java;
 
 import java.util.Set;
 
diff --git a/src/test/java/org/greencodeinitiative/java/JavaEcoCodeWayProfileTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/JavaCreedengoWayProfileTest.java
similarity index 69%
rename from src/test/java/org/greencodeinitiative/java/JavaEcoCodeWayProfileTest.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/JavaCreedengoWayProfileTest.java
index b812a49a..7db81345 100644
--- a/src/test/java/org/greencodeinitiative/java/JavaEcoCodeWayProfileTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/JavaCreedengoWayProfileTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java;
+package org.greencodeinitiative.creedengo.java;
 
 import java.util.List;
 import java.util.stream.Collectors;
@@ -24,18 +24,18 @@
 import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition;
 import org.sonar.check.Rule;
 
-import static org.greencodeinitiative.java.JavaCheckRegistrarTest.getDefinedRules;
-import static org.greencodeinitiative.java.JavaEcoCodeWayProfile.PROFILE_NAME;
-import static org.greencodeinitiative.java.JavaEcoCodeWayProfile.PROFILE_PATH;
-import static org.greencodeinitiative.java.JavaRulesDefinition.LANGUAGE;
+import static org.greencodeinitiative.creedengo.java.JavaCheckRegistrarTest.getDefinedRules;
+import static org.greencodeinitiative.creedengo.java.JavaCreedengoWayProfile.PROFILE_NAME;
+import static org.greencodeinitiative.creedengo.java.JavaCreedengoWayProfile.PROFILE_PATH;
+import static org.greencodeinitiative.creedengo.java.JavaRulesDefinition.LANGUAGE;
 import static org.assertj.core.api.Assertions.assertThat;
 
-class JavaEcoCodeWayProfileTest {
+class JavaCreedengoWayProfileTest {
 	@Test
-	void should_create_ecocode_profile() {
+	void should_create_creedengo_profile() {
 		BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context();
 
-		JavaEcoCodeWayProfile definition = new JavaEcoCodeWayProfile();
+		JavaCreedengoWayProfile definition = new JavaCreedengoWayProfile();
 		definition.define(context);
 
 		BuiltInQualityProfilesDefinition.BuiltInQualityProfile profile = context.profile(LANGUAGE, PROFILE_NAME);
diff --git a/src/test/java/org/greencodeinitiative/java/JavaPluginTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/JavaPluginTest.java
similarity index 84%
rename from src/test/java/org/greencodeinitiative/java/JavaPluginTest.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/JavaPluginTest.java
index 7712f993..b54f59bc 100644
--- a/src/test/java/org/greencodeinitiative/java/JavaPluginTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/JavaPluginTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java;
+package org.greencodeinitiative.creedengo.java;
 
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
diff --git a/src/test/java/org/greencodeinitiative/java/JavaRulesDefinitionTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/JavaRulesDefinitionTest.java
similarity index 87%
rename from src/test/java/org/greencodeinitiative/java/JavaRulesDefinitionTest.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/JavaRulesDefinitionTest.java
index 8f6f2ddb..d0f53da3 100644
--- a/src/test/java/org/greencodeinitiative/java/JavaRulesDefinitionTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/JavaRulesDefinitionTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java;
+package org.greencodeinitiative.creedengo.java;
 
 import org.assertj.core.api.SoftAssertions;
 import org.junit.jupiter.api.BeforeEach;
@@ -28,7 +28,7 @@
 import org.sonar.api.server.rule.RulesDefinition.Rule;
 import org.sonar.api.utils.Version;
 
-import static org.greencodeinitiative.java.JavaCheckRegistrar.ANNOTATED_RULE_CLASSES;
+import static org.greencodeinitiative.creedengo.java.JavaCheckRegistrar.ANNOTATED_RULE_CLASSES;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
@@ -50,9 +50,9 @@ void init() {
     @Test
     @DisplayName("Test repository metadata")
     void testMetadata() {
-        assertThat(repository.name()).isEqualTo("ecoCode");
+        assertThat(repository.name()).isEqualTo("creedengo");
         assertThat(repository.language()).isEqualTo("java");
-        assertThat(repository.key()).isEqualTo("ecocode-java");
+        assertThat(repository.key()).isEqualTo("creedengo-java");
     }
 
     @Test
diff --git a/src/test/java/org/greencodeinitiative/java/checks/ArrayCopyCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheckTest.java
similarity index 81%
rename from src/test/java/org/greencodeinitiative/java/checks/ArrayCopyCheckTest.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheckTest.java
index 7e32f4e8..49deaa19 100644
--- a/src/test/java/org/greencodeinitiative/java/checks/ArrayCopyCheckTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheckTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.junit.jupiter.api.Test;
 import org.sonar.java.checks.verifier.CheckVerifier;
diff --git a/src/test/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheckTest.java
similarity index 80%
rename from src/test/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheckTest.java
index 8453f31f..889721b1 100644
--- a/src/test/java/org/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheckTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.junit.jupiter.api.Test;
 import org.sonar.java.checks.verifier.CheckVerifier;
diff --git a/src/test/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInLoopTest.java
similarity index 91%
rename from src/test/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInLoopTest.java
index 9b74a62d..4d4b3fd6 100644
--- a/src/test/java/org/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInLoopTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.junit.jupiter.api.Test;
 import org.sonar.java.checks.verifier.CheckVerifier;
diff --git a/src/test/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementTest.java
similarity index 89%
rename from src/test/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementTest.java
index e7bd1327..f63326e5 100644
--- a/src/test/java/org/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.junit.jupiter.api.Test;
 import org.sonar.java.checks.verifier.CheckVerifier;
diff --git a/src/test/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticTest.java
similarity index 85%
rename from src/test/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticTest.java
index 2445c941..874b03b2 100644
--- a/src/test/java/org/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.junit.jupiter.api.Test;
 import org.sonar.java.checks.verifier.CheckVerifier;
diff --git a/src/test/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheckTest.java
similarity index 80%
rename from src/test/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheckTest.java
index 9e7b6329..bd64a6a7 100644
--- a/src/test/java/org/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheckTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.junit.jupiter.api.Test;
 import org.sonar.java.checks.verifier.CheckVerifier;
diff --git a/src/test/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchInsertTest.java
similarity index 81%
rename from src/test/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchInsertTest.java
index bd0bc6f9..9dffe6f9 100644
--- a/src/test/java/org/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchInsertTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.junit.jupiter.api.Test;
 import org.sonar.java.checks.verifier.CheckVerifier;
diff --git a/src/test/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java
similarity index 78%
rename from src/test/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java
index c8e05f31..8041f0a7 100644
--- a/src/test/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,9 +15,9 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
-import org.greencodeinitiative.java.utils.FilesUtils;
+import org.greencodeinitiative.creedengo.java.utils.FilesUtils;
 import org.junit.jupiter.api.Test;
 import org.sonar.java.checks.verifier.CheckVerifier;
 
diff --git a/src/test/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java
similarity index 78%
rename from src/test/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java
index 4076c7eb..1be55d7e 100644
--- a/src/test/java/org/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,9 +15,9 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
-import org.greencodeinitiative.java.utils.FilesUtils;
+import org.greencodeinitiative.creedengo.java.utils.FilesUtils;
 import org.junit.jupiter.api.Test;
 import org.sonar.java.checks.verifier.CheckVerifier;
 
diff --git a/src/test/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueriesTest.java
similarity index 80%
rename from src/test/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueriesTest.java
index 62625423..3caac84a 100644
--- a/src/test/java/org/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueriesTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.junit.jupiter.api.Test;
 import org.sonar.java.checks.verifier.CheckVerifier;
diff --git a/src/test/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsTests.java
similarity index 84%
rename from src/test/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsTests.java
index 4697c217..876525f2 100644
--- a/src/test/java/org/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsTests.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.junit.jupiter.api.Test;
 import org.sonar.java.checks.verifier.CheckVerifier;
diff --git a/src/test/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java
similarity index 85%
rename from src/test/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java
index 03c20959..aecce2d7 100644
--- a/src/test/java/org/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.junit.jupiter.api.Test;
 import org.sonar.java.checks.verifier.CheckVerifier;
diff --git a/src/test/java/org/greencodeinitiative/java/checks/IncrementCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheckTest.java
similarity index 80%
rename from src/test/java/org/greencodeinitiative/java/checks/IncrementCheckTest.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheckTest.java
index 4b075d0c..d11de845 100644
--- a/src/test/java/org/greencodeinitiative/java/checks/IncrementCheckTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheckTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.junit.jupiter.api.Test;
 import org.sonar.java.checks.verifier.CheckVerifier;
diff --git a/src/test/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSizeTest.java
similarity index 81%
rename from src/test/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSizeTest.java
index f1149849..0261b8f9 100644
--- a/src/test/java/org/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSizeTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.junit.jupiter.api.Test;
 import org.sonar.java.checks.verifier.CheckVerifier;
diff --git a/src/test/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java
similarity index 81%
rename from src/test/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java
index 32bf0c49..e4dff73e 100644
--- a/src/test/java/org/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.junit.jupiter.api.Test;
 import org.sonar.java.checks.verifier.CheckVerifier;
diff --git a/src/test/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheckTest.java
similarity index 89%
rename from src/test/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheckTest.java
index 293f2437..d3f1def0 100644
--- a/src/test/java/org/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheckTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.junit.jupiter.api.Test;
 import org.sonar.java.checks.verifier.CheckVerifier;
diff --git a/src/test/java/org/greencodeinitiative/java/utils/FilesUtils.java b/src/test/java/org/greencodeinitiative/creedengo/java/utils/FilesUtils.java
similarity index 92%
rename from src/test/java/org/greencodeinitiative/java/utils/FilesUtils.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/utils/FilesUtils.java
index 78cfcd23..d32c90de 100644
--- a/src/test/java/org/greencodeinitiative/java/utils/FilesUtils.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/utils/FilesUtils.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.utils;
+package org.greencodeinitiative.creedengo.java.utils;
 
 import java.io.File;
 import java.io.IOException;
diff --git a/src/test/java/org/greencodeinitiative/java/utils/StringUtilsTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/utils/StringUtilsTest.java
similarity index 84%
rename from src/test/java/org/greencodeinitiative/java/utils/StringUtilsTest.java
rename to src/test/java/org/greencodeinitiative/creedengo/java/utils/StringUtilsTest.java
index 011518c7..de5082de 100644
--- a/src/test/java/org/greencodeinitiative/java/utils/StringUtilsTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/utils/StringUtilsTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.java.utils;
+package org.greencodeinitiative.creedengo.java.utils;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import org.junit.jupiter.api.Test;

From fa8857e34919521ec15778d43b07b828dbcd1169 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Mon, 16 Dec 2024 00:27:08 +0100
Subject: [PATCH 091/233] migration from ecocode to creedengo - NEXT

---
 .github/workflows/_BACKUP_manual_release.yml |  4 +--
 .github/workflows/build_container.yml        |  6 ++--
 .github/workflows/tag_release.yml            |  2 +-
 CHANGELOG.md                                 | 32 ++++++++++----------
 CODE_STYLE.md                                |  2 +-
 CONTRIBUTING.md                              |  2 +-
 INSTALL.md                                   |  6 ++--
 README.md                                    | 32 ++++++++++----------
 RULES.md                                     |  2 +-
 9 files changed, 44 insertions(+), 44 deletions(-)

diff --git a/.github/workflows/_BACKUP_manual_release.yml b/.github/workflows/_BACKUP_manual_release.yml
index 6b9164a1..af210fe8 100644
--- a/.github/workflows/_BACKUP_manual_release.yml
+++ b/.github/workflows/_BACKUP_manual_release.yml
@@ -86,6 +86,6 @@ jobs:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
         with:
           upload_url: ${{needs.build.outputs.upload_url}}
-          asset_path: lib/ecocode-java-plugin-${{ needs.build.outputs.last_tag }}.jar
-          asset_name: ecocode-java-plugin-${{ needs.build.outputs.last_tag }}.jar
+          asset_path: lib/creedengo-java-plugin-${{ needs.build.outputs.last_tag }}.jar
+          asset_name: creedengo-java-plugin-${{ needs.build.outputs.last_tag }}.jar
           asset_content_type: application/zip
diff --git a/.github/workflows/build_container.yml b/.github/workflows/build_container.yml
index e2fc184c..08fb38b2 100644
--- a/.github/workflows/build_container.yml
+++ b/.github/workflows/build_container.yml
@@ -16,10 +16,10 @@ env:
   # github.repository as /
 #  IMAGE_NAME: sonarqube-creedengo
 #  IMAGES: |
-#    ghcr.io/${{ github.repository_owner }}/sonarqube-ecocode
-  IMAGE_NAME: sonarqube-ecocode-java
+#    ghcr.io/${{ github.repository_owner }}/sonarqube-creedengo
+  IMAGE_NAME: sonarqube-creedengo-java
   IMAGES: |
-    ghcr.io/${{ github.repository_owner }}/sonarqube-ecocode-java
+    ghcr.io/${{ github.repository_owner }}/sonarqube-creedengo-java
 
 jobs:
   Build:
diff --git a/.github/workflows/tag_release.yml b/.github/workflows/tag_release.yml
index 0dcf0090..6fd2f0a2 100644
--- a/.github/workflows/tag_release.yml
+++ b/.github/workflows/tag_release.yml
@@ -70,5 +70,5 @@ jobs:
         with:
           upload_url: ${{needs.build.outputs.upload_url}}
           asset_path: target/creedengo-java-plugin-${{ github.ref_name }}.jar
-          asset_name: ecocode-java-plugin-${{ github.ref_name }}.jar
+          asset_name: creedengo-java-plugin-${{ github.ref_name }}.jar
           asset_content_type: application/zip
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c6a598bb..ee6bb182 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,14 +9,14 @@ 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
+- [#59](https://github.com/green-code-initiative/creedengo-java/pull/59) Add builtin profile `ecoCode way` to aggregate all implemented ecoCode rules by this plugin
+- [#53](https://github.com/green-code-initiative/creedengo-java/issues/53) Improve integration tests
 - Rename rules ECXXX to the new Green Code Initiative naming convention GCIXXX
 
 ### Changed
 
-- [#49](https://github.com/green-code-initiative/ecoCode-java/pull/49) Add test to ensure all Rules are registered
-- [#336](https://github.com/green-code-initiative/ecoCode/issues/336) [Adds Maven Wrapper](https://github.com/green-code-initiative/ecoCode-java/pull/67)
+- [#49](https://github.com/green-code-initiative/creedengo-java/pull/49) Add test to ensure all Rules are registered
+- [#336](https://github.com/green-code-initiative/creedengo-rules-specifications/issues/336) [Adds Maven Wrapper](https://github.com/green-code-initiative/creedengo-java/pull/67)
 
 ### Deleted
 
@@ -24,7 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed
 
-- [#60](https://github.com/green-code-initiative/ecoCode-java/issues/60) Check + update for SonarQube 10.6.0 compatibility
+- [#60](https://github.com/green-code-initiative/creedengo-java/issues/60) Check + update for SonarQube 10.6.0 compatibility
 - refactoring docker system
 - upgrade ecocode-rules-specifications to 1.6.2
 
@@ -32,30 +32,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed
 
-- [#15](https://github.com/green-code-initiative/ecoCode-java/issues/15) correction NullPointer in EC2 rule
+- [#15](https://github.com/green-code-initiative/creedengo-java/issues/15) correction NullPointer in EC2 rule
 - check Sonarqube 10.5.1 compatibility + update docker files and README.md
 
 ## [1.6.0] - 2024-02-02
 
 ### Added
 
-- [#12](https://github.com/green-code-initiative/ecoCode-java/issues/12) Add support for SonarQube 10.4 "DownloadOnlyWhenRequired" feature
+- [#12](https://github.com/green-code-initiative/creedengo-java/issues/12) Add support for SonarQube 10.4 "DownloadOnlyWhenRequired" feature
 
 ### Deleted
 
-- [#6](https://github.com/green-code-initiative/ecoCode-java/pull/6) Delete deprecated java rules EC4, EC53, EC63 and EC75
+- [#6](https://github.com/green-code-initiative/creedengo-java/pull/6) Delete deprecated java rules EC4, EC53, EC63 and EC75
 
 ## [1.5.2] - 2024-01-23
 
 ### Changed
 
-- [#9](https://github.com/green-code-initiative/ecoCode-java/issues/9) EC2 rule : correction no block statement use case
+- [#9](https://github.com/green-code-initiative/creedengo-java/issues/9) EC2 rule : correction no block statement use case
 
 ## [1.5.1] - 2024-01-23
 
 ### Changed
 
-- [#7](https://github.com/green-code-initiative/ecoCode-java/issues/7) EC2 rule : correction NullPointer with interface
+- [#7](https://github.com/green-code-initiative/creedengo-java/issues/7) EC2 rule : correction NullPointer with interface
 
 ## [1.5.0] - 2024-01-06
 
@@ -68,9 +68,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - Update ecocode-rules-specifications to 1.4.6
 
-[unreleased](https://github.com/green-code-initiative/ecoCode-java/compare/1.6.1...HEAD)
-[1.6.1](https://github.com/green-code-initiative/ecoCode-java/compare/1.6.0...1.6.1)
-[1.6.0](https://github.com/green-code-initiative/ecoCode-java/compare/1.5.2...1.6.0)
-[1.5.2](https://github.com/green-code-initiative/ecoCode-java/compare/1.5.1...1.5.2)
-[1.5.1](https://github.com/green-code-initiative/ecoCode-java/compare/1.5.0...1.5.1)
-[1.5.0](https://github.com/green-code-initiative/ecoCode-java/releases/tag/1.5.0)
+[unreleased](https://github.com/green-code-initiative/creedengo-java/compare/1.6.1...HEAD)
+[1.6.1](https://github.com/green-code-initiative/creedengo-java/compare/1.6.0...1.6.1)
+[1.6.0](https://github.com/green-code-initiative/creedengo-java/compare/1.5.2...1.6.0)
+[1.5.2](https://github.com/green-code-initiative/creedengo-java/compare/1.5.1...1.5.2)
+[1.5.1](https://github.com/green-code-initiative/creedengo-java/compare/1.5.0...1.5.1)
+[1.5.0](https://github.com/green-code-initiative/creedengo-java/releases/tag/1.5.0)
diff --git a/CODE_STYLE.md b/CODE_STYLE.md
index 86b0ab3f..c46ab38c 100644
--- a/CODE_STYLE.md
+++ b/CODE_STYLE.md
@@ -1 +1 @@
-Please read common [CODE_STYLE.md](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/CODE_STYLE.md) in `ecoCode-common` repository.
+Please read common [CODE_STYLE.md](https://github.com/green-code-initiative/creedengo-common/blob/main/doc/CODE_STYLE.md) in `creedengo-common` repository.
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 77e81dc6..aeeae916 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1 +1 @@
-Please read common [CONTRIBUTING.md](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/CONTRIBUTING.md) in `ecoCode-common` repository.
+Please read common [CONTRIBUTING.md](https://github.com/green-code-initiative/creedengo-common/blob/main/doc/CONTRIBUTING.md) in `creedengo-common` repository.
diff --git a/INSTALL.md b/INSTALL.md
index ee50d0ae..82cd69dc 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -1,8 +1,8 @@
 Common installation notes / requirements
 ========================================
 
-Please read common [INSTALL.md](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/INSTALL.md)
-in `ecoCode-common` repository. Please follow the specific guides below for additional information on installing the
+Please read common [INSTALL.md](https://github.com/green-code-initiative/creedengo-common/blob/main/doc/INSTALL.md)
+in `creedengo-common` repository. Please follow the specific guides below for additional information on installing the
 desired plugins.
 
 Special points for Standard plugins
@@ -14,7 +14,7 @@ Project structure
 Here is a preview of project tree :
 
 ```txt
-ecoCode-java             # Root directory
+creedengo-java             # Root directory
 |
 +--src                  # source directory
 |
diff --git a/README.md b/README.md
index c9e4ea4d..d5843580 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,12 @@
-EcoCode-java
+creedengo-java
 ===========
 
-_ecoCode_ is a collective project aiming to reduce environmental footprint of software at the code level. The goal of
+_creedengo_ is a collective project aiming to reduce environmental footprint of software at the code level. The goal of
 the project is to provide a list of static code analyzers to highlight code structures that may have a negative
 ecological impact: energy and resources over-consumption, "fatware", shortening terminals' lifespan, etc.
 
-_ecoCode_ is based on evolving catalogs
-of [good practices](https://github.com/green-code-initiative/ecoCode/blob/main/docs/rules), for various technologies.
+_creedengo_ is based on evolving catalogs
+of [good practices](https://github.com/green-code-initiative/creedengo-rules-specifications/blob/main/docs/rules), for various technologies.
 This
 SonarQube plugin then implements these catalogs as rules for scanning your Java projects.
 
@@ -14,14 +14,14 @@ SonarQube plugin then implements these catalogs as rules for scanning your Java
 > refer to the contribution section.
 
 [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
-[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/CODE_OF_CONDUCT.md)
+[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](https://github.com/green-code-initiative/creedengo-common/blob/main/doc/CODE_OF_CONDUCT.md)
 
 🌿 SonarQube Plugins
 -------------------
 
-This plugin is part of the ecoCode project.\
+This plugin is part of the creedengo project.\
 You can find a list of all our other plugins in
-the [ecoCode repository](https://github.com/green-code-initiative/ecoCode#-sonarqube-plugins)
+the [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-sonarqube-plugins)
 
 🚀 Getting Started
 ------------------
@@ -32,9 +32,9 @@ You can give a try with a one command:
 ./mvnw verify -Pkeep-running
 ```
 
-... 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/creedengo-java-plugin-test-project)
+... then you can use Java test project repository to test the environment : see [Java test project in `./src/it/test-projects/creedengo-java-plugin-test-project`](./src/it/test-projects/creedengo-java-plugin-test-project)
 
-NB: To install other `ecocode` plugins, you can :
+NB: To install other `creedengo` plugins, you can :
 
 - 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.
 
@@ -43,16 +43,16 @@ NB: To install other `ecocode` plugins, you can :
   ```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)
+- install different creedengo plugins with Marketplace (inside admin panel of SonarQube)
 
-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)
+You can also directly use a [all-in-one docker-compose](https://github.com/green-code-initiative/creedengo-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).
+... and configure local SonarQube (security config and quality profile : see [configuration](https://github.com/green-code-initiative/creedengo-common/blob/main/doc/INSTALL.md#configuration-sonarqube) for more details).
 
 🛒 Distribution
 ------------------
 
-Ready to use binaries are available [from GitHub](https://github.com/green-code-initiative/ecoCode-java/releases).
+Ready to use binaries are available [from GitHub](https://github.com/green-code-initiative/creedengo-java/releases).
 
 🧩 Compatibility
 -----------------
@@ -63,17 +63,17 @@ Ready to use binaries are available [from GitHub](https://github.com/green-code-
 | 1.7.+          | 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).
+> main [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-plugins-version-compatibility).
 
 🤝 Contribution
 ---------------
 
-check [ecoCode repository](https://github.com/green-code-initiative/ecoCode#-contribution)
+check [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-contribution)
 
 🤓 Main contributors
 --------------------
 
-check [ecoCode repository](https://github.com/green-code-initiative/ecoCode#-main-contributors)
+check [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-main-contributors)
 
 Links
 -----
diff --git a/RULES.md b/RULES.md
index 13bf375f..43f0724e 100644
--- a/RULES.md
+++ b/RULES.md
@@ -1 +1 @@
-Please read [RULES.md](https://github.com/green-code-initiative/ecoCode/blob/main/RULES.md) in `ecoCode` repository.
+Please read [RULES.md](https://github.com/green-code-initiative/creedengo-rules-specifications/blob/main/RULES.md) in `ecoCode` repository.

From 2cfa25c39478d09431870b709bd3dade369f08ef Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Mon, 16 Dec 2024 00:28:44 +0100
Subject: [PATCH 092/233] migration from ecocode to creedengo - NEXT 2

---
 RULES.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/RULES.md b/RULES.md
index 43f0724e..d48fa61d 100644
--- a/RULES.md
+++ b/RULES.md
@@ -1 +1 @@
-Please read [RULES.md](https://github.com/green-code-initiative/creedengo-rules-specifications/blob/main/RULES.md) in `ecoCode` repository.
+Please read [RULES.md](https://github.com/green-code-initiative/creedengo-rules-specifications/blob/main/RULES.md) in `creedengo-rules-specifications` repository.

From aea5634b8423f1afb3bf3536fa17ff8f80eeb6a7 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Tue, 17 Dec 2024 23:37:46 +0100
Subject: [PATCH 093/233] update README.md / Dockerfile for 10.7 compatibility

---
 Dockerfile | 2 +-
 README.md  | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/Dockerfile b/Dockerfile
index 502c2224..d9cdbbeb 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,5 +1,5 @@
 ARG MAVEN_BUILDER=3-openjdk-17-slim
-ARG SONARQUBE_VERSION=10.6.0-community
+ARG SONARQUBE_VERSION=10.7.0-community
 
 FROM maven:${MAVEN_BUILDER} AS builder
 
diff --git a/README.md b/README.md
index d5843580..715d23e6 100644
--- a/README.md
+++ b/README.md
@@ -61,6 +61,7 @@ Ready to use binaries are available [from GitHub](https://github.com/green-code-
 |----------------|---------------------|------------------------------------------------------------------------------------------------|
 | 1.6.+          | 9.4.+ LTS to 10.6.0 | 11 / 17                                                                                        |
 | 1.7.+          | 9.9.+ LTS to 10.6.0 | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) |
+| 2.0.+          | 9.9.+ LTS to 10.7.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 [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-plugins-version-compatibility).

From d118701c24ed379f5c3ec1d777a51bbf9ea201ed Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Wed, 18 Dec 2024 22:17:26 +0100
Subject: [PATCH 094/233] add script shell for temp tests

---
 .../creedengo-java-plugin-test-project/tool_send_to_sonar.sh  | 4 ++++
 1 file changed, 4 insertions(+)
 create mode 100755 src/it/test-projects/creedengo-java-plugin-test-project/tool_send_to_sonar.sh

diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/tool_send_to_sonar.sh b/src/it/test-projects/creedengo-java-plugin-test-project/tool_send_to_sonar.sh
new file mode 100755
index 00000000..4f0175e8
--- /dev/null
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/tool_send_to_sonar.sh
@@ -0,0 +1,4 @@
+#!/usr/bin/env sh
+
+# "sonar.login" kept only for SONARQUBE < 10
+mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.11.0.3922:sonar -Dsonar.host.url=http://localhost:$1 -Dsonar.login=$2 -Dsonar.token=$2

From 4810b94bd562bbdbe7c95dae9f37c41b5303de26 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Wed, 18 Dec 2024 22:59:13 +0100
Subject: [PATCH 095/233] prepare 2.0.0 : update CHANGELOG

---
 CHANGELOG.md | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index ee6bb182..e84c5757 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,17 +9,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Added
 
+### Changed
+
+### Deleted
+
+## [2.0.0] - 2024-12-18
+
+### Added
+
 - [#59](https://github.com/green-code-initiative/creedengo-java/pull/59) Add builtin profile `ecoCode way` to aggregate all implemented ecoCode rules by this plugin
 - [#53](https://github.com/green-code-initiative/creedengo-java/issues/53) Improve integration tests
 - Rename rules ECXXX to the new Green Code Initiative naming convention GCIXXX
+- migration from ecocode to creedengo - all over the code
 
 ### Changed
 
 - [#49](https://github.com/green-code-initiative/creedengo-java/pull/49) Add test to ensure all Rules are registered
 - [#336](https://github.com/green-code-initiative/creedengo-rules-specifications/issues/336) [Adds Maven Wrapper](https://github.com/green-code-initiative/creedengo-java/pull/67)
 
-### Deleted
-
 ## [1.6.2] - 2024-07-21
 
 ### Changed
@@ -68,7 +75,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - Update ecocode-rules-specifications to 1.4.6
 
-[unreleased](https://github.com/green-code-initiative/creedengo-java/compare/1.6.1...HEAD)
+[unreleased](https://github.com/green-code-initiative/creedengo-java/compare/2.0.0...HEAD)
+[2.0.0](https://github.com/green-code-initiative/creedengo-java/compare/1.6.2...2.0.0)
+[1.6.2](https://github.com/green-code-initiative/creedengo-java/compare/1.6.1...1.6.2)
 [1.6.1](https://github.com/green-code-initiative/creedengo-java/compare/1.6.0...1.6.1)
 [1.6.0](https://github.com/green-code-initiative/creedengo-java/compare/1.5.2...1.6.0)
 [1.5.2](https://github.com/green-code-initiative/creedengo-java/compare/1.5.1...1.5.2)

From 864e9df04eede1f34411bdbeaeac57d793d6a95c Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Wed, 18 Dec 2024 23:00:06 +0100
Subject: [PATCH 096/233] [maven-release-plugin] prepare release 2.0.0

---
 pom.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 51dd9136..0a81e9a2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
 
     org.green-code-initiative
     creedengo-java-plugin
-    2.0.0-SNAPSHOT
+    2.0.0
 
     sonar-plugin
 
@@ -30,7 +30,7 @@
         scm:git:https://github.com/green-code-initiative/creedengo-java
         scm:git:https://github.com/green-code-initiative/creedengo-java
         https://github.com/green-code-initiative/creedengo-java
-        HEAD
+        2.0.0
     
 
     

From 34298565d63ba0c132150075358f2763ee4cd9f9 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Wed, 18 Dec 2024 23:00:06 +0100
Subject: [PATCH 097/233] [maven-release-plugin] prepare for next development
 iteration

---
 pom.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 0a81e9a2..c12e4d3d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
 
     org.green-code-initiative
     creedengo-java-plugin
-    2.0.0
+    2.0.1-SNAPSHOT
 
     sonar-plugin
 
@@ -30,7 +30,7 @@
         scm:git:https://github.com/green-code-initiative/creedengo-java
         scm:git:https://github.com/green-code-initiative/creedengo-java
         https://github.com/green-code-initiative/creedengo-java
-        2.0.0
+        HEAD
     
 
     

From e9619a6bac982d4324a5cb4aafe94040048d3374 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Wed, 1 Jan 2025 21:48:12 +0100
Subject: [PATCH 098/233] Create dependabot.yml

---
 .github/dependabot.yml | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 .github/dependabot.yml

diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 00000000..a3d018fb
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,11 @@
+# To get started with Dependabot version updates, you'll need to specify which
+# package ecosystems to update and where the package manifests are located.
+# Please see the documentation for all configuration options:
+# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
+
+version: 2
+updates:
+  - package-ecosystem: "maven" # See documentation for possible values
+    directory: "/" # Location of package manifests
+    schedule:
+      interval: "monthly"

From 228faa15bb776d38038f79cee63dc4008a17056d Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Wed, 1 Jan 2025 21:07:43 +0000
Subject: [PATCH 099/233] Bump org.jacoco:jacoco-maven-plugin from 0.8.10 to
 0.8.12

Bumps [org.jacoco:jacoco-maven-plugin](https://github.com/jacoco/jacoco) from 0.8.10 to 0.8.12.
- [Release notes](https://github.com/jacoco/jacoco/releases)
- [Commits](https://github.com/jacoco/jacoco/compare/v0.8.10...v0.8.12)

---
updated-dependencies:
- dependency-name: org.jacoco:jacoco-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] 
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index c12e4d3d..6059372a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -215,7 +215,7 @@
             
                 org.jacoco
                 jacoco-maven-plugin
-                0.8.10
+                0.8.12
                 
                     
                         prepare-agent

From d20a420d5ab7f65551c034981c254f059469c51f Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Wed, 1 Jan 2025 21:07:50 +0000
Subject: [PATCH 100/233] Bump org.apache.maven.plugins:maven-dependency-plugin

Bumps [org.apache.maven.plugins:maven-dependency-plugin](https://github.com/apache/maven-dependency-plugin) from 3.6.0 to 3.8.1.
- [Release notes](https://github.com/apache/maven-dependency-plugin/releases)
- [Commits](https://github.com/apache/maven-dependency-plugin/compare/maven-dependency-plugin-3.6.0...maven-dependency-plugin-3.8.1)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-dependency-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] 
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index c12e4d3d..47241040 100644
--- a/pom.xml
+++ b/pom.xml
@@ -311,7 +311,7 @@
             
                 org.apache.maven.plugins
                 maven-dependency-plugin
-                3.6.0
+                3.8.1
                 
                     
                     

From f69a0125ec4e0c8430e06f88b17b08521427b2c3 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Wed, 1 Jan 2025 21:07:54 +0000
Subject: [PATCH 101/233] Bump org.apache.maven.plugins:maven-surefire-plugin
 from 3.1.2 to 3.5.2

Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.1.2 to 3.5.2.
- [Release notes](https://github.com/apache/maven-surefire/releases)
- [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.1.2...surefire-3.5.2)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-surefire-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] 
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index c12e4d3d..f202571a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -210,7 +210,7 @@
             
                 org.apache.maven.plugins
                 maven-surefire-plugin
-                3.1.2
+                3.5.2
             
             
                 org.jacoco

From 2bd9ff684eacab22eb97aa148dc51a23d7cd783d Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Wed, 1 Jan 2025 23:41:38 +0100
Subject: [PATCH 102/233] update CHANGELOG.md

---
 CHANGELOG.md | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index e84c5757..b329c7d9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed
 
+- upgrade some libraries versions
+
 ### Deleted
 
 ## [2.0.0] - 2024-12-18

From feec689cc0a05d25a5770e710fb9c0469563660c Mon Sep 17 00:00:00 2001
From: E000391 
Date: Thu, 30 May 2024 08:40:05 +0200
Subject: [PATCH 103/233] add rule

---
 .../checks/UseOptionalOrElseGetVsOrElse.java  | 45 +++++++++++++++++++
 .../files/UseOptionalOrElseGetVsOrElse.java   |  8 ++++
 .../UseOptionalOrElseGetVsOrElseTest.java     | 14 ++++++
 3 files changed, 67 insertions(+)
 create mode 100644 src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java
 create mode 100644 src/test/files/UseOptionalOrElseGetVsOrElse.java
 create mode 100644 src/test/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElseTest.java

diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java
new file mode 100644
index 00000000..ad413edf
--- /dev/null
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java
@@ -0,0 +1,45 @@
+package fr.greencodeinitiative.java.checks;
+
+import org.sonar.check.Rule;
+import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
+import org.sonar.plugins.java.api.tree.BaseTreeVisitor;
+import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree;
+import org.sonar.plugins.java.api.tree.MethodInvocationTree;
+import org.sonar.plugins.java.api.tree.Tree;
+import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
+
+import javax.annotation.Nonnull;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+@Rule(key = "XXX")
+@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "XXX")
+public class UseOptionalOrElseGetVsOrElse extends IssuableSubscriptionVisitor {
+
+    private static final String MESSAGE_RULE = "Use optional orElseGet instead of orElse.";
+    private final UseOptionalOrElseGetVsOrElseVisitor visitorInFile = new UseOptionalOrElseGetVsOrElseVisitor();
+
+    @Override
+    public List nodesToVisit() {
+        return Collections.singletonList(Tree.Kind.METHOD_INVOCATION);
+    }
+
+    @Override
+    public void visitNode(@Nonnull Tree tree) {
+        tree.accept(visitorInFile);
+    }
+
+    private class UseOptionalOrElseGetVsOrElseVisitor extends BaseTreeVisitor {
+        @Override
+        public void visitMethodInvocation(MethodInvocationTree tree) {
+            if (tree.methodSelect().is(Tree.Kind.MEMBER_SELECT) &&
+                    Objects.requireNonNull(tree.methodSelect().firstToken()).text().equals("Optional")) {
+                MemberSelectExpressionTree memberSelect = (MemberSelectExpressionTree) tree.methodSelect();
+                if (memberSelect.identifier().name().equals("orElse")) {
+                    reportIssue(memberSelect, MESSAGE_RULE);
+                }
+            }
+        }
+    }
+}
diff --git a/src/test/files/UseOptionalOrElseGetVsOrElse.java b/src/test/files/UseOptionalOrElseGetVsOrElse.java
new file mode 100644
index 00000000..198c5d3d
--- /dev/null
+++ b/src/test/files/UseOptionalOrElseGetVsOrElse.java
@@ -0,0 +1,8 @@
+class UseOptionalOrElseGetVsOrElse {
+
+    public static final String name = Optional.of("ecoCode").orElse(getUnpredictedMethod()); // Noncompliant {{Use optional orElseGet instead of orElse.}}
+
+    public static final String name = Optional.of("ecoCode").orElseGet(getUnpredictedMethod()); // Compliant
+
+    public static final String name = randomClass.orElse(); // Compliant
+}
diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElseTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElseTest.java
new file mode 100644
index 00000000..8e0600dd
--- /dev/null
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElseTest.java
@@ -0,0 +1,14 @@
+package fr.greencodeinitiative.java.checks;
+
+import org.junit.jupiter.api.Test;
+import org.sonar.java.checks.verifier.CheckVerifier;
+
+class UseOptionalOrElseGetVsOrElseTest {
+    @Test
+    void test() {
+        CheckVerifier.newVerifier()
+                .onFile("src/test/files/UseOptionalOrElseGetVsOrElse.java")
+                .withCheck(new UseOptionalOrElseGetVsOrElse())
+                .verifyIssues();
+    }
+}

From 4f97eed10ca4c4c732439a51b5455fd9a43ddee2 Mon Sep 17 00:00:00 2001
From: E000391 
Date: Thu, 30 May 2024 11:30:02 +0200
Subject: [PATCH 104/233] clean code

---
 .../checks/UseOptionalOrElseGetVsOrElse.java  | 22 +++++++++++++++----
 .../files/UseOptionalOrElseGetVsOrElse.java   | 21 ++++++++++++++++--
 .../UseOptionalOrElseGetVsOrElseTest.java     | 17 ++++++++++++++
 3 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java
index ad413edf..39b71e4f 100644
--- a/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java
@@ -1,3 +1,20 @@
+/*
+ * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
 package fr.greencodeinitiative.java.checks;
 
 import org.sonar.check.Rule;
@@ -6,15 +23,12 @@
 import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree;
 import org.sonar.plugins.java.api.tree.MethodInvocationTree;
 import org.sonar.plugins.java.api.tree.Tree;
-import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
-
 import javax.annotation.Nonnull;
 import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 
-@Rule(key = "XXX")
-@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "XXX")
+@Rule(key = "EC1369")
 public class UseOptionalOrElseGetVsOrElse extends IssuableSubscriptionVisitor {
 
     private static final String MESSAGE_RULE = "Use optional orElseGet instead of orElse.";
diff --git a/src/test/files/UseOptionalOrElseGetVsOrElse.java b/src/test/files/UseOptionalOrElseGetVsOrElse.java
index 198c5d3d..a35928c5 100644
--- a/src/test/files/UseOptionalOrElseGetVsOrElse.java
+++ b/src/test/files/UseOptionalOrElseGetVsOrElse.java
@@ -1,8 +1,25 @@
+/*
+ * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
 class UseOptionalOrElseGetVsOrElse {
 
     public static final String name = Optional.of("ecoCode").orElse(getUnpredictedMethod()); // Noncompliant {{Use optional orElseGet instead of orElse.}}
 
-    public static final String name = Optional.of("ecoCode").orElseGet(getUnpredictedMethod()); // Compliant
+    public static final String name = Optional.of("ecoCode").orElseGet(() -> getUnpredictedMethod()); // Compliant
 
-    public static final String name = randomClass.orElse(); // Compliant
+    public static final String name = randomClass.orElse(getUnpredictedMethod()); // Compliant
 }
diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElseTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElseTest.java
index 8e0600dd..b2ad3624 100644
--- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElseTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElseTest.java
@@ -1,3 +1,20 @@
+/*
+ * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
 package fr.greencodeinitiative.java.checks;
 
 import org.junit.jupiter.api.Test;

From 3e0aae2690773460c6000988c0c818d9e9785a50 Mon Sep 17 00:00:00 2001
From: E000391 
Date: Thu, 30 May 2024 12:17:44 +0200
Subject: [PATCH 105/233] add rule to javaCheckRegistrar

---
 .../creedengo/java/JavaCheckRegistrar.java    | 41 ++++++++++---------
 .../java/JavaCheckRegistrarTest.java          | 21 ++++------
 2 files changed, 28 insertions(+), 34 deletions(-)

diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrar.java b/src/main/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrar.java
index 60ae37d8..15fdc26a 100644
--- a/src/main/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrar.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrar.java
@@ -1,6 +1,6 @@
 /*
- * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,26 +15,26 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.creedengo.java;
+package fr.greencodeinitiative.java;
 
 import java.util.Collections;
 import java.util.List;
 
-import org.greencodeinitiative.creedengo.java.checks.ArrayCopyCheck;
-import org.greencodeinitiative.creedengo.java.checks.AvoidFullSQLRequest;
-import org.greencodeinitiative.creedengo.java.checks.AvoidGettingSizeCollectionInLoop;
-import org.greencodeinitiative.creedengo.java.checks.AvoidMultipleIfElseStatement;
-import org.greencodeinitiative.creedengo.java.checks.AvoidRegexPatternNotStatic;
-import org.greencodeinitiative.creedengo.java.checks.AvoidSQLRequestInLoop;
-import org.greencodeinitiative.creedengo.java.checks.AvoidSetConstantInBatchUpdate;
-import org.greencodeinitiative.creedengo.java.checks.AvoidSpringRepositoryCallInLoopOrStreamCheck;
-import org.greencodeinitiative.creedengo.java.checks.AvoidStatementForDMLQueries;
-import org.greencodeinitiative.creedengo.java.checks.AvoidUsageOfStaticCollections;
-import org.greencodeinitiative.creedengo.java.checks.FreeResourcesOfAutoCloseableInterface;
-import org.greencodeinitiative.creedengo.java.checks.IncrementCheck;
-import org.greencodeinitiative.creedengo.java.checks.InitializeBufferWithAppropriateSize;
-import org.greencodeinitiative.creedengo.java.checks.NoFunctionCallWhenDeclaringForLoop;
-import org.greencodeinitiative.creedengo.java.checks.OptimizeReadFileExceptions;
+(??)import org.greencodeinitiative.creedengo.java.checks.ArrayCopyCheck;
+(??)import org.greencodeinitiative.creedengo.java.checks.AvoidFullSQLRequest;
+(??)import org.greencodeinitiative.creedengo.java.checks.AvoidGettingSizeCollectionInLoop;
+(??)import org.greencodeinitiative.creedengo.java.checks.AvoidMultipleIfElseStatement;
+(??)import org.greencodeinitiative.creedengo.java.checks.AvoidRegexPatternNotStatic;
+(??)import org.greencodeinitiative.creedengo.java.checks.AvoidSQLRequestInLoop;
+(??)import org.greencodeinitiative.creedengo.java.checks.AvoidSetConstantInBatchUpdate;
+(??)import org.greencodeinitiative.creedengo.java.checks.AvoidSpringRepositoryCallInLoopOrStreamCheck;
+(??)import org.greencodeinitiative.creedengo.java.checks.AvoidStatementForDMLQueries;
+(??)import org.greencodeinitiative.creedengo.java.checks.AvoidUsageOfStaticCollections;
+(??)import org.greencodeinitiative.creedengo.java.checks.FreeResourcesOfAutoCloseableInterface;
+(??)import org.greencodeinitiative.creedengo.java.checks.IncrementCheck;
+(??)import org.greencodeinitiative.creedengo.java.checks.InitializeBufferWithAppropriateSize;
+(??)import org.greencodeinitiative.creedengo.java.checks.NoFunctionCallWhenDeclaringForLoop;
+(??)import org.greencodeinitiative.creedengo.java.checks.OptimizeReadFileExceptions;
 import org.sonar.plugins.java.api.CheckRegistrar;
 import org.sonar.plugins.java.api.JavaCheck;
 import org.sonarsource.api.sonarlint.SonarLintSide;
@@ -47,7 +47,7 @@
  */
 @SonarLintSide
 public class JavaCheckRegistrar implements CheckRegistrar {
-    static final List> ANNOTATED_RULE_CLASSES = List.of(
+    private static final List> ANNOTATED_RULE_CLASSES = List.of(
             ArrayCopyCheck.class,
             IncrementCheck.class,
             AvoidUsageOfStaticCollections.class,
@@ -62,7 +62,8 @@ public class JavaCheckRegistrar implements CheckRegistrar {
             InitializeBufferWithAppropriateSize.class,
             AvoidSetConstantInBatchUpdate.class,
             FreeResourcesOfAutoCloseableInterface.class,
-            AvoidMultipleIfElseStatement.class
+            AvoidMultipleIfElseStatement.class,
+            UseOptionalOrElseGetVsOrElse.class
     );
 
     /**
diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrarTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrarTest.java
index 68ce968f..ff3abfc5 100644
--- a/src/test/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrarTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrarTest.java
@@ -1,6 +1,6 @@
 /*
- * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,13 +15,9 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package org.greencodeinitiative.creedengo.java;
-
-import java.util.Set;
+package fr.greencodeinitiative.java;
 
 import org.junit.jupiter.api.Test;
-import org.reflections.Reflections;
-import org.sonar.check.Rule;
 import org.sonar.plugins.java.api.CheckRegistrar;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -34,14 +30,11 @@ void checkNumberRules() {
 
         final JavaCheckRegistrar registrar = new JavaCheckRegistrar();
         registrar.register(context);
-        assertThat(context.checkClasses())
-                .describedAs("All implemented rules must be registered into " + JavaCheckRegistrar.class)
-                .containsExactlyInAnyOrder(getDefinedRules().toArray(new Class[0]));
+(??)        assertThat(context.checkClasses())
+(??)                .describedAs("All implemented rules must be registered into " + JavaCheckRegistrar.class)
+(??)                .containsExactlyInAnyOrder(getDefinedRules().toArray(new Class[0]));
         assertThat(context.testCheckClasses()).isEmpty();
-    }
 
-    static Set> getDefinedRules() {
-        Reflections r = new Reflections(JavaCheckRegistrar.class.getPackageName() + ".checks");
-        return r.getTypesAnnotatedWith(Rule.class);
     }
+
 }

From 0a3ce07b3d7fd4ed70f84e1f40d56c47d8c630df Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Thu, 2 Jan 2025 01:08:55 +0100
Subject: [PATCH 106/233] add rule GCI94

---
 CHANGELOG.md                                  |  2 ++
 .../checks/UseOptionalOrElseGetVsOrElse.java  | 34 +++++++++++++++++++
 .../creedengo/java/JavaCheckRegistrar.java    | 24 +++----------
 .../checks/UseOptionalOrElseGetVsOrElse.java  |  8 ++---
 .../creedengo/java/creedengo_way_profile.json |  3 +-
 .../files/UseOptionalOrElseGetVsOrElse.java   | 19 ++++++++---
 .../java/JavaCheckRegistrarTest.java          | 21 ++++++++----
 .../UseOptionalOrElseGetVsOrElseTest.java     |  6 ++--
 8 files changed, 79 insertions(+), 38 deletions(-)
 create mode 100644 src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java

diff --git a/CHANGELOG.md b/CHANGELOG.md
index b329c7d9..c03b5eaa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Added
 
+- [#88](https://github.com/green-code-initiative/creedengo-java/pull/88) Add new Java rule GCI94 (Use orElseGet instead of orElse)
+
 ### Changed
 
 - upgrade some libraries versions
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java
new file mode 100644
index 00000000..93a29f74
--- /dev/null
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java
@@ -0,0 +1,34 @@
+import java.util.Optional;
+
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+class UseOptionalOrElseGetVsOrElse {
+
+    private static Optional variable = Optional.empty();
+
+    public static final String NAME = Optional.of("creedengo").orElse(getUnpredictedMethod()); // Noncompliant {{Use optional orElseGet instead of orElse.}}
+
+    public static final String NAME2 = Optional.of("creedengo").orElseGet(() -> getUnpredictedMethod()); // Compliant
+
+    public static final String NAME3 = variable.orElse(getUnpredictedMethod()); // Compliant
+
+    private static String getUnpredictedMethod() {
+        return "unpredicted";
+    }
+
+}
diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrar.java b/src/main/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrar.java
index 15fdc26a..a4037e0a 100644
--- a/src/main/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrar.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrar.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,26 +15,12 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package fr.greencodeinitiative.java;
+package org.greencodeinitiative.creedengo.java;
 
 import java.util.Collections;
 import java.util.List;
 
-(??)import org.greencodeinitiative.creedengo.java.checks.ArrayCopyCheck;
-(??)import org.greencodeinitiative.creedengo.java.checks.AvoidFullSQLRequest;
-(??)import org.greencodeinitiative.creedengo.java.checks.AvoidGettingSizeCollectionInLoop;
-(??)import org.greencodeinitiative.creedengo.java.checks.AvoidMultipleIfElseStatement;
-(??)import org.greencodeinitiative.creedengo.java.checks.AvoidRegexPatternNotStatic;
-(??)import org.greencodeinitiative.creedengo.java.checks.AvoidSQLRequestInLoop;
-(??)import org.greencodeinitiative.creedengo.java.checks.AvoidSetConstantInBatchUpdate;
-(??)import org.greencodeinitiative.creedengo.java.checks.AvoidSpringRepositoryCallInLoopOrStreamCheck;
-(??)import org.greencodeinitiative.creedengo.java.checks.AvoidStatementForDMLQueries;
-(??)import org.greencodeinitiative.creedengo.java.checks.AvoidUsageOfStaticCollections;
-(??)import org.greencodeinitiative.creedengo.java.checks.FreeResourcesOfAutoCloseableInterface;
-(??)import org.greencodeinitiative.creedengo.java.checks.IncrementCheck;
-(??)import org.greencodeinitiative.creedengo.java.checks.InitializeBufferWithAppropriateSize;
-(??)import org.greencodeinitiative.creedengo.java.checks.NoFunctionCallWhenDeclaringForLoop;
-(??)import org.greencodeinitiative.creedengo.java.checks.OptimizeReadFileExceptions;
+import org.greencodeinitiative.creedengo.java.checks.*;
 import org.sonar.plugins.java.api.CheckRegistrar;
 import org.sonar.plugins.java.api.JavaCheck;
 import org.sonarsource.api.sonarlint.SonarLintSide;
@@ -47,7 +33,7 @@
  */
 @SonarLintSide
 public class JavaCheckRegistrar implements CheckRegistrar {
-    private static final List> ANNOTATED_RULE_CLASSES = List.of(
+    static final List> ANNOTATED_RULE_CLASSES = List.of(
             ArrayCopyCheck.class,
             IncrementCheck.class,
             AvoidUsageOfStaticCollections.class,
diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java
index 39b71e4f..ec971a6c 100644
--- a/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package fr.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.sonar.check.Rule;
 import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
@@ -28,7 +28,7 @@
 import java.util.List;
 import java.util.Objects;
 
-@Rule(key = "EC1369")
+@Rule(key = "GCI94")
 public class UseOptionalOrElseGetVsOrElse extends IssuableSubscriptionVisitor {
 
     private static final String MESSAGE_RULE = "Use optional orElseGet instead of orElse.";
diff --git a/src/main/resources/org/greencodeinitiative/creedengo/java/creedengo_way_profile.json b/src/main/resources/org/greencodeinitiative/creedengo/java/creedengo_way_profile.json
index eed2a19a..b5a4b85f 100644
--- a/src/main/resources/org/greencodeinitiative/creedengo/java/creedengo_way_profile.json
+++ b/src/main/resources/org/greencodeinitiative/creedengo/java/creedengo_way_profile.json
@@ -16,6 +16,7 @@
 	"GCI76",
 	"GCI77",
 	"GCI78",
-	"GCI79"
+	"GCI79",
+	"GCI94"
   ]
 }
diff --git a/src/test/files/UseOptionalOrElseGetVsOrElse.java b/src/test/files/UseOptionalOrElseGetVsOrElse.java
index a35928c5..93a29f74 100644
--- a/src/test/files/UseOptionalOrElseGetVsOrElse.java
+++ b/src/test/files/UseOptionalOrElseGetVsOrElse.java
@@ -1,6 +1,8 @@
+import java.util.Optional;
+
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -17,9 +19,16 @@
  */
 class UseOptionalOrElseGetVsOrElse {
 
-    public static final String name = Optional.of("ecoCode").orElse(getUnpredictedMethod()); // Noncompliant {{Use optional orElseGet instead of orElse.}}
+    private static Optional variable = Optional.empty();
+
+    public static final String NAME = Optional.of("creedengo").orElse(getUnpredictedMethod()); // Noncompliant {{Use optional orElseGet instead of orElse.}}
+
+    public static final String NAME2 = Optional.of("creedengo").orElseGet(() -> getUnpredictedMethod()); // Compliant
+
+    public static final String NAME3 = variable.orElse(getUnpredictedMethod()); // Compliant
 
-    public static final String name = Optional.of("ecoCode").orElseGet(() -> getUnpredictedMethod()); // Compliant
+    private static String getUnpredictedMethod() {
+        return "unpredicted";
+    }
 
-    public static final String name = randomClass.orElse(getUnpredictedMethod()); // Compliant
 }
diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrarTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrarTest.java
index ff3abfc5..89541a50 100644
--- a/src/test/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrarTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrarTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,9 +15,13 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package fr.greencodeinitiative.java;
+package org.greencodeinitiative.creedengo.java;
+
+import java.util.Set;
 
 import org.junit.jupiter.api.Test;
+import org.reflections.Reflections;
+import org.sonar.check.Rule;
 import org.sonar.plugins.java.api.CheckRegistrar;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -30,11 +34,16 @@ void checkNumberRules() {
 
         final JavaCheckRegistrar registrar = new JavaCheckRegistrar();
         registrar.register(context);
-(??)        assertThat(context.checkClasses())
-(??)                .describedAs("All implemented rules must be registered into " + JavaCheckRegistrar.class)
-(??)                .containsExactlyInAnyOrder(getDefinedRules().toArray(new Class[0]));
+        assertThat(context.checkClasses())
+                .describedAs("All implemented rules must be registered into " + JavaCheckRegistrar.class)
+                .containsExactlyInAnyOrder(getDefinedRules().toArray(new Class[0]));
         assertThat(context.testCheckClasses()).isEmpty();
 
     }
 
+    static Set> getDefinedRules() {
+        Reflections r = new Reflections(JavaCheckRegistrar.class.getPackageName() + ".checks");
+        return r.getTypesAnnotatedWith(Rule.class);
+    }
+
 }
diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElseTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElseTest.java
index b2ad3624..2edc2711 100644
--- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElseTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElseTest.java
@@ -1,6 +1,6 @@
 /*
- * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-package fr.greencodeinitiative.java.checks;
+package org.greencodeinitiative.creedengo.java.checks;
 
 import org.junit.jupiter.api.Test;
 import org.sonar.java.checks.verifier.CheckVerifier;

From a168de0c91e33354775d250e1f519af0c682b7d6 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Thu, 2 Jan 2025 01:11:44 +0100
Subject: [PATCH 107/233] add rule GCI94 - correction

---
 .../creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java  | 5 +++--
 src/test/files/UseOptionalOrElseGetVsOrElse.java             | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java
index 93a29f74..20a0decc 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java
@@ -1,5 +1,3 @@
-import java.util.Optional;
-
 /*
  * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
  * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
@@ -17,6 +15,9 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
+
+import java.util.Optional;
+
 class UseOptionalOrElseGetVsOrElse {
 
     private static Optional variable = Optional.empty();
diff --git a/src/test/files/UseOptionalOrElseGetVsOrElse.java b/src/test/files/UseOptionalOrElseGetVsOrElse.java
index 93a29f74..20a0decc 100644
--- a/src/test/files/UseOptionalOrElseGetVsOrElse.java
+++ b/src/test/files/UseOptionalOrElseGetVsOrElse.java
@@ -1,5 +1,3 @@
-import java.util.Optional;
-
 /*
  * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
  * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
@@ -17,6 +15,9 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
+
+import java.util.Optional;
+
 class UseOptionalOrElseGetVsOrElse {
 
     private static Optional variable = Optional.empty();

From 2f490a0e0762e453b9cd678c6a4018f388f6965d Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Thu, 2 Jan 2025 23:35:04 +0100
Subject: [PATCH 108/233] refactoring IT classes and add GCI94 IT

---
 pom.xml                                       |   6 +
 .../java/integration/tests/BaseIT.java        |  28 +++
 .../java/integration/tests/GCI69IT.java       |  39 +++
 .../java/integration/tests/GCI94IT.java       |  39 +++
 ...va => LaunchSonarqubeAndBuildProject.java} | 228 +++++++++---------
 5 files changed, 228 insertions(+), 112 deletions(-)
 create mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BaseIT.java
 create mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI69IT.java
 create mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI94IT.java
 rename src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/{LaunchSonarqubeAndBuildProjectIT.java => LaunchSonarqubeAndBuildProject.java} (85%)

diff --git a/pom.xml b/pom.xml
index d2eb8d79..63e0f178 100644
--- a/pom.xml
+++ b/pom.xml
@@ -198,6 +198,12 @@
             1.5.6
             test
         
+        
+            org.projectlombok
+            lombok
+            1.18.36
+            test
+        
     
 
     
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BaseIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BaseIT.java
new file mode 100644
index 00000000..0c7e8803
--- /dev/null
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BaseIT.java
@@ -0,0 +1,28 @@
+package org.greencodeinitiative.creedengo.java.integration.tests;
+
+import org.junit.jupiter.api.Test;
+import org.sonarqube.ws.Issues;
+import org.sonarqube.ws.Measures;
+
+import java.util.*;
+
+import static java.util.Optional.ofNullable;
+import static org.assertj.core.api.Assertions.assertThat;
+
+class BaseIT extends LaunchSonarqubeAndBuildProject {
+
+	@Test
+	void testMeasuresAndIssues() {
+		String projectKey = analyzedProjects.get(0).getProjectKey();
+
+		Map measures = getMeasures(projectKey);
+
+		assertThat(ofNullable(measures.get("code_smells")).map(Measures.Measure::getValue).map(Integer::parseInt).orElse(0))
+				.isGreaterThan(1);
+
+		List projectIssues = issuesForComponent(projectKey);
+		assertThat(projectIssues).isNotEmpty();
+
+	}
+
+}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI69IT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI69IT.java
new file mode 100644
index 00000000..0784a856
--- /dev/null
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI69IT.java
@@ -0,0 +1,39 @@
+package org.greencodeinitiative.creedengo.java.integration.tests;
+
+import org.junit.jupiter.api.Test;
+import org.sonarqube.ws.Issues;
+
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonarqube.ws.Common.RuleType.CODE_SMELL;
+import static org.sonarqube.ws.Common.Severity.MINOR;
+
+class GCI69IT extends LaunchSonarqubeAndBuildProject {
+
+    @Test
+    void testGCI69() {
+        String projectKey = analyzedProjects.get(0).getProjectKey();
+
+        List issuesForArrayCopyCheck = issuesForFile(projectKey, "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java");
+
+        assertThat(issuesForArrayCopyCheck)
+                .hasSize(1)
+                .first().satisfies(issue -> verifyIssue(issue, IssueDetails.builder()
+                        .rule("creedengo-java:GCI69")
+                        .message("Do not call a function when declaring a for-type loop")
+                        .line(18)
+                        .startLine(18)
+                        .endLine(18)
+                        .startOffset(15)
+                        .endOffset(27)
+                        .severity(MINOR)
+                        .type(CODE_SMELL)
+                        .debt("5min")
+                        .effort("5min")
+                        .build())
+                );
+
+    }
+
+}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI94IT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI94IT.java
new file mode 100644
index 00000000..61211154
--- /dev/null
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI94IT.java
@@ -0,0 +1,39 @@
+package org.greencodeinitiative.creedengo.java.integration.tests;
+
+import org.junit.jupiter.api.Test;
+import org.sonarqube.ws.Issues;
+
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonarqube.ws.Common.RuleType.CODE_SMELL;
+import static org.sonarqube.ws.Common.Severity.MINOR;
+
+class GCI94IT extends LaunchSonarqubeAndBuildProject {
+
+    @Test
+    void testGCI94() {
+        String projectKey = analyzedProjects.get(0).getProjectKey();
+
+        List issuesForArrayCopyCheck = issuesForFile(projectKey, "src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java");
+
+        assertThat(issuesForArrayCopyCheck)
+                .hasSize(1)
+                .first().satisfies(issue -> verifyIssue(issue, IssueDetails.builder()
+                        .rule("creedengo-java:GCI94")
+                        .message("Use optional orElseGet instead of orElse.")
+                        .line(25)
+                        .startLine(25)
+                        .endLine(25)
+                        .startOffset(38)
+                        .endOffset(69)
+                        .severity(MINOR)
+                        .type(CODE_SMELL)
+                        .debt("1min")
+                        .effort("1min")
+                        .build())
+        );
+
+    }
+
+}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/LaunchSonarqubeAndBuildProject.java
similarity index 85%
rename from src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java
rename to src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/LaunchSonarqubeAndBuildProject.java
index 8a556d02..58ed4956 100644
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/LaunchSonarqubeAndBuildProjectIT.java
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/LaunchSonarqubeAndBuildProject.java
@@ -23,10 +23,13 @@
 import com.sonar.orchestrator.locator.Location;
 import com.sonar.orchestrator.locator.MavenLocation;
 import com.sonar.orchestrator.locator.URLLocation;
+import lombok.Builder;
+import lombok.Getter;
 import org.greencodeinitiative.creedengo.java.integration.tests.profile.ProfileBackup;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
+import org.sonarqube.ws.Common;
 import org.sonarqube.ws.Issues;
 import org.sonarqube.ws.Measures;
 import org.sonarqube.ws.client.HttpConnector;
@@ -44,34 +47,12 @@
 import static org.sonarqube.ws.Common.RuleType.CODE_SMELL;
 import static org.sonarqube.ws.Common.Severity.MINOR;
 
-class LaunchSonarqubeAndBuildProjectIT {
-	private static final System.Logger LOGGER = System.getLogger(LaunchSonarqubeAndBuildProjectIT.class.getName());
+abstract class LaunchSonarqubeAndBuildProject {
 
-	private static OrchestratorExtension orchestrator;
-	private static List analyzedProjects;
+	private static final System.Logger LOGGER = System.getLogger(LaunchSonarqubeAndBuildProject.class.getName());
 
-	private static void launchSonarqube() {
-		String orchestratorArtifactoryUrl = systemProperty("test-it.orchestrator.artifactory.url");
-		String sonarqubeVersion = systemProperty("test-it.sonarqube.version");
-		Optional sonarqubePort = ofNullable(System.getProperty("test-it.sonarqube.port")).map(String::trim).filter(not(String::isEmpty));
-
-		OrchestratorExtensionBuilder orchestratorExtensionBuilder = OrchestratorExtension
-				.builderEnv()
-				.useDefaultAdminCredentialsForBuilds(true)
-				.setOrchestratorProperty("orchestrator.artifactory.url", orchestratorArtifactoryUrl)
-				.setSonarVersion(sonarqubeVersion)
-				.setServerProperty("sonar.forceAuthentication", "false")
-				.setServerProperty("sonar.web.javaOpts", "-Xmx1G");
-
-		sonarqubePort.ifPresent(s -> orchestratorExtensionBuilder.setServerProperty("sonar.web.port", s));
-
-		additionalPluginsToInstall().forEach(orchestratorExtensionBuilder::addPlugin);
-		additionalProfiles().forEach(orchestratorExtensionBuilder::restoreProfileAtStartup);
-
-		orchestrator = orchestratorExtensionBuilder.build();
-		orchestrator.start();
-		LOGGER.log(INFO, () -> MessageFormat.format("SonarQube server available on: {0}", orchestrator.getServer().getUrl()));
-	}
+	protected static OrchestratorExtension orchestrator;
+	protected static List analyzedProjects;
 
 	@BeforeAll
 	static void setup() {
@@ -106,55 +87,6 @@ static void setup() {
 		launchAnalysis();
 	}
 
-	private static void launchAnalysis() {
-		Server server = orchestrator.getServer();
-		Map qualityProfileByLanguage = testProjectProfileByLanguage();
-
-		analyzedProjects = getProjectsToAnalyze();
-
-		analyzedProjects
-				.stream()
-				// - Prepare/create SonarQube project for the test project
-				.peek(projectToAnalyze -> projectToAnalyze.provisionProjectIntoServer(server))
-				// - Configure the test project
-				.peek(projectToAnalyze -> projectToAnalyze.associateProjectToQualityProfile(server, qualityProfileByLanguage))
-				.map(ProjectToAnalyze::createMavenBuild)
-				// - Run SonarQube Scanner on test project
-				.peek(p -> LOGGER.log(INFO, () -> MessageFormat.format("Running SonarQube Scanner on project: {0}", p.getPom())))
-				.forEach(orchestrator::executeBuild);
-	}
-
-	@Test
-	void test() {
-		String projectKey = analyzedProjects.get(0).projectKey;
-
-		Map measures = getMeasures(projectKey);
-
-		assertThat(ofNullable(measures.get("code_smells")).map(Measures.Measure::getValue).map(Integer::parseInt).orElse(0))
-				.isGreaterThan(1);
-
-		List projectIssues = issuesForComponent(projectKey);
-		assertThat(projectIssues).isNotEmpty();
-
-		List issuesForArrayCopyCheck = issuesForFile(projectKey, "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java");
-
-		assertThat(issuesForArrayCopyCheck)
-				.hasSize(1)
-				.first().satisfies(issue -> {
-					assertThat(issue.getRule()).isEqualTo("creedengo-java:GCI69");
-					assertThat(issue.getSeverity()).isEqualTo(MINOR);
-					assertThat(issue.getLine()).isEqualTo(18);
-					assertThat(issue.getTextRange().getStartLine()).isEqualTo(18);
-					assertThat(issue.getTextRange().getEndLine()).isEqualTo(18);
-					assertThat(issue.getTextRange().getStartOffset()).isEqualTo(15);
-					assertThat(issue.getTextRange().getEndOffset()).isEqualTo(27);
-					assertThat(issue.getMessage()).isEqualTo("Do not call a function when declaring a for-type loop");
-					assertThat(issue.getDebt()).isEqualTo("5min");
-					assertThat(issue.getEffort()).isEqualTo("5min");
-					assertThat(issue.getType()).isEqualTo(CODE_SMELL);
-				});
-	}
-
 	@AfterAll
 	static void tearDown() {
 		if ("true".equalsIgnoreCase(System.getProperty("test-it.sonarqube.keepRunning"))) {
@@ -180,6 +112,47 @@ static void tearDown() {
 		}
 	}
 
+	private static void launchSonarqube() {
+		String orchestratorArtifactoryUrl = systemProperty("test-it.orchestrator.artifactory.url");
+		String sonarqubeVersion = systemProperty("test-it.sonarqube.version");
+		Optional sonarqubePort = ofNullable(System.getProperty("test-it.sonarqube.port")).map(String::trim).filter(not(String::isEmpty));
+
+		OrchestratorExtensionBuilder orchestratorExtensionBuilder = OrchestratorExtension
+				.builderEnv()
+				.useDefaultAdminCredentialsForBuilds(true)
+				.setOrchestratorProperty("orchestrator.artifactory.url", orchestratorArtifactoryUrl)
+				.setSonarVersion(sonarqubeVersion)
+				.setServerProperty("sonar.forceAuthentication", "false")
+				.setServerProperty("sonar.web.javaOpts", "-Xmx1G");
+
+		sonarqubePort.ifPresent(s -> orchestratorExtensionBuilder.setServerProperty("sonar.web.port", s));
+
+		additionalPluginsToInstall().forEach(orchestratorExtensionBuilder::addPlugin);
+		additionalProfiles().forEach(orchestratorExtensionBuilder::restoreProfileAtStartup);
+
+		orchestrator = orchestratorExtensionBuilder.build();
+		orchestrator.start();
+		LOGGER.log(INFO, () -> MessageFormat.format("SonarQube server available on: {0}", orchestrator.getServer().getUrl()));
+	}
+
+	private static void launchAnalysis() {
+		Server server = orchestrator.getServer();
+		Map qualityProfileByLanguage = testProjectProfileByLanguage();
+
+		analyzedProjects = getProjectsToAnalyze();
+
+		analyzedProjects
+				.stream()
+				// - Prepare/create SonarQube project for the test project
+				.peek(projectToAnalyze -> projectToAnalyze.provisionProjectIntoServer(server))
+				// - Configure the test project
+				.peek(projectToAnalyze -> projectToAnalyze.associateProjectToQualityProfile(server, qualityProfileByLanguage))
+				.map(ProjectToAnalyze::createMavenBuild)
+				// - Run SonarQube Scanner on test project
+				.peek(p -> LOGGER.log(INFO, () -> MessageFormat.format("Running SonarQube Scanner on project: {0}", p.getPom())))
+				.forEach(orchestrator::executeBuild);
+	}
+
 	private static String systemProperty(String propertyName) {
 		return ofNullable(System.getProperty(propertyName))
 				.orElseThrow(() -> new IllegalStateException(
@@ -231,10 +204,10 @@ private static Stream splitAndTrim(String value, String regexSeparator)
 
 	private static Set additionalPluginsToInstall() {
 		Set plugins = commaSeparatedValues(systemProperty("test-it.plugins"))
-				.map(LaunchSonarqubeAndBuildProjectIT::toPluginLocation)
+				.map(LaunchSonarqubeAndBuildProject::toPluginLocation)
 				.collect(Collectors.toSet());
 		commaSeparatedValues(System.getProperty("test-it.additional-plugins", ""))
-				.map(LaunchSonarqubeAndBuildProjectIT::toPluginLocation)
+				.map(LaunchSonarqubeAndBuildProject::toPluginLocation)
 				.forEach(plugins::add);
 		return plugins;
 	}
@@ -284,48 +257,18 @@ private static Location toPluginLocation(String location) {
 		);
 	}
 
-	private static class ProjectToAnalyze {
-		private final Path pom;
-		private final String projectKey;
-		private final String projectName;
-
-		private ProjectToAnalyze(URI pom, String projectKey, String projectName) {
-			this.pom = Path.of(pom);
-			assertThat(this.pom).isRegularFile();
-			this.projectKey = projectKey;
-			this.projectName = projectName;
-		}
-
-		public MavenBuild createMavenBuild() {
-			return MavenBuild.create(pom.toFile())
-			                 .setCleanPackageSonarGoals()
-			                 .setProperty("sonar.projectKey", projectKey)
-			                 .setProperty("sonar.projectName", projectName)
-			                 .setProperty("sonar.scm.disabled", "true");
-		}
-
-		private void provisionProjectIntoServer(Server server) {
-			server.provisionProject(projectKey, projectName);
-
-		}
-
-		private void associateProjectToQualityProfile(Server server, Map qualityProfileByLanguage) {
-			qualityProfileByLanguage.forEach((language, profileName) -> server.associateProjectToQualityProfile(projectKey, language, profileName));
-		}
-	}
-
-	private static List issuesForFile(String projectKey, String file) {
+	protected static List issuesForFile(String projectKey, String file) {
 		return issuesForComponent(projectKey + ":" + file);
 	}
 
-	private static List issuesForComponent(String componentKey) {
+	protected static List issuesForComponent(String componentKey) {
 		return newWsClient(orchestrator)
 				.issues()
 				.search(new SearchRequest().setComponentKeys(Collections.singletonList(componentKey)))
 				.getIssuesList();
 	}
 
-	private static Map getMeasures(String componentKey) {
+	protected static Map getMeasures(String componentKey) {
 		List metricKeys = List.of(
 				"alert_status",
 				"blocker_violations",
@@ -439,10 +382,71 @@ private static Map getMeasures(String componentKey) {
 				.collect(Collectors.toMap(Measures.Measure::getMetric, Function.identity()));
 	}
 
-
-	private static WsClient newWsClient(Orchestrator orchestrator) {
+	protected static WsClient newWsClient(Orchestrator orchestrator) {
 		return WsClientFactories.getDefault().newClient(HttpConnector.newBuilder()
 		                                                             .url(orchestrator.getServer().getUrl())
 		                                                             .build());
 	}
+
+	@Getter
+	protected static class ProjectToAnalyze {
+		private final Path pom;
+		private final String projectKey;
+		private final String projectName;
+
+		private ProjectToAnalyze(URI pom, String projectKey, String projectName) {
+			this.pom = Path.of(pom);
+			assertThat(this.pom).isRegularFile();
+			this.projectKey = projectKey;
+			this.projectName = projectName;
+		}
+
+		public MavenBuild createMavenBuild() {
+			return MavenBuild.create(pom.toFile())
+					.setCleanPackageSonarGoals()
+					.setProperty("sonar.projectKey", projectKey)
+					.setProperty("sonar.projectName", projectName)
+					.setProperty("sonar.scm.disabled", "true");
+		}
+
+		private void provisionProjectIntoServer(Server server) {
+			server.provisionProject(projectKey, projectName);
+
+		}
+
+		private void associateProjectToQualityProfile(Server server, Map qualityProfileByLanguage) {
+			qualityProfileByLanguage.forEach((language, profileName) -> server.associateProjectToQualityProfile(projectKey, language, profileName));
+		}
+	}
+
+	@Getter
+	@Builder
+	protected static class IssueDetails {
+		private String rule;
+		private String message;
+		private int line;
+		private int startLine;
+		private int endLine;
+		private int startOffset;
+		private int endOffset;
+		private Common.RuleType type;
+		private Common.Severity severity;
+		private String debt;
+		private String effort;
+	}
+
+	protected void verifyIssue(Issues.Issue issueToCheck, IssueDetails issueSource) {
+		assertThat(issueToCheck.getRule()).isEqualTo(issueSource.getRule());
+		assertThat(issueToCheck.getMessage()).isEqualTo(issueSource.getMessage());
+		assertThat(issueToCheck.getLine()).isEqualTo(issueSource.getLine());
+		assertThat(issueToCheck.getTextRange().getStartLine()).isEqualTo(issueSource.getStartLine());
+		assertThat(issueToCheck.getTextRange().getEndLine()).isEqualTo(issueSource.getEndLine());
+		assertThat(issueToCheck.getTextRange().getStartOffset()).isEqualTo(issueSource.getStartOffset());
+		assertThat(issueToCheck.getTextRange().getEndOffset()).isEqualTo(issueSource.getEndOffset());
+		assertThat(issueToCheck.getSeverity()).isEqualTo(issueSource.getSeverity());
+		assertThat(issueToCheck.getType()).isEqualTo(issueSource.getType());
+		assertThat(issueToCheck.getDebt()).isEqualTo(issueSource.getDebt());
+		assertThat(issueToCheck.getEffort()).isEqualTo(issueSource.getEffort());
+	}
+
 }

From 7c977d363f7b2f9bd4ef463a7bf1ad0767fef3f7 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Fri, 3 Jan 2025 09:13:48 +0100
Subject: [PATCH 109/233] update CHANGELOG.md

---
 CHANGELOG.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index c03b5eaa..b9488721 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Changed
 
 - upgrade some libraries versions
+- improve Integration Tests system to be more flexible (add new IT for each rule)
 
 ### Deleted
 

From a5b7b6a0e55b9eb5383fb3a7caf46798552710ad Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Fri, 3 Jan 2025 15:59:01 +0100
Subject: [PATCH 110/233] rafacto IT files + small UT corrections + add Java
 rule implem for GCI82

---
 CHANGELOG.md                                  |   3 +-
 pom.xml                                       |   3 +-
 .../java/integration/tests/BaseIT.java        |  28 ----
 ...ldProject.java => BuildProjectEngine.java} |  43 +-----
 .../java/integration/tests/GCI69IT.java       |  39 ------
 .../java/integration/tests/GCI94IT.java       |  39 ------
 .../java/integration/tests/GCIRulesIT.java    |  93 +++++++++++++
 ...GettingSizeCollectionInForLoopIgnored.java |   9 +-
 .../MakeNonReassignedVariablesConstants.java  |  69 ++++++++++
 .../creedengo/java/JavaCheckRegistrar.java    |   3 +-
 .../MakeNonReassignedVariablesConstants.java  | 129 ++++++++++++++++++
 .../creedengo/java/creedengo_way_profile.json |   1 +
 ...GettingSizeCollectionInForLoopIgnored.java |   9 +-
 .../MakeNonReassignedVariablesConstants.java  |  69 ++++++++++
 ...keNonReassignedVariablesConstantsTest.java |  33 +++++
 15 files changed, 413 insertions(+), 157 deletions(-)
 delete mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BaseIT.java
 rename src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/{LaunchSonarqubeAndBuildProject.java => BuildProjectEngine.java} (88%)
 delete mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI69IT.java
 delete mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI94IT.java
 create mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
 create mode 100644 src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
 create mode 100644 src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
 create mode 100644 src/test/files/MakeNonReassignedVariablesConstants.java
 create mode 100644 src/test/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstantsTest.java

diff --git a/CHANGELOG.md b/CHANGELOG.md
index b9488721..d46e8710 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Added
 
-- [#88](https://github.com/green-code-initiative/creedengo-java/pull/88) Add new Java rule GCI94 (Use orElseGet instead of orElse)
+- [#88](https://github.com/green-code-initiative/creedengo-java/pull/88) Add new Java rule GCI94 - Use orElseGet instead of orElse
+- [#88](https://github.com/green-code-initiative/creedengo-java/pull/88) Add new Java rule GCI82 - Make non reassigned variables constants
 
 ### Changed
 
diff --git a/pom.xml b/pom.xml
index 63e0f178..8940b3f5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -72,7 +72,8 @@
         1.7
 
         
-        2.0.0
+        main-SNAPSHOT
+
 
         
         https://repo1.maven.org/maven2
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BaseIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BaseIT.java
deleted file mode 100644
index 0c7e8803..00000000
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BaseIT.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.greencodeinitiative.creedengo.java.integration.tests;
-
-import org.junit.jupiter.api.Test;
-import org.sonarqube.ws.Issues;
-import org.sonarqube.ws.Measures;
-
-import java.util.*;
-
-import static java.util.Optional.ofNullable;
-import static org.assertj.core.api.Assertions.assertThat;
-
-class BaseIT extends LaunchSonarqubeAndBuildProject {
-
-	@Test
-	void testMeasuresAndIssues() {
-		String projectKey = analyzedProjects.get(0).getProjectKey();
-
-		Map measures = getMeasures(projectKey);
-
-		assertThat(ofNullable(measures.get("code_smells")).map(Measures.Measure::getValue).map(Integer::parseInt).orElse(0))
-				.isGreaterThan(1);
-
-		List projectIssues = issuesForComponent(projectKey);
-		assertThat(projectIssues).isNotEmpty();
-
-	}
-
-}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/LaunchSonarqubeAndBuildProject.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BuildProjectEngine.java
similarity index 88%
rename from src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/LaunchSonarqubeAndBuildProject.java
rename to src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BuildProjectEngine.java
index 58ed4956..e85b3f00 100644
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/LaunchSonarqubeAndBuildProject.java
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BuildProjectEngine.java
@@ -23,13 +23,10 @@
 import com.sonar.orchestrator.locator.Location;
 import com.sonar.orchestrator.locator.MavenLocation;
 import com.sonar.orchestrator.locator.URLLocation;
-import lombok.Builder;
 import lombok.Getter;
 import org.greencodeinitiative.creedengo.java.integration.tests.profile.ProfileBackup;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.sonarqube.ws.Common;
 import org.sonarqube.ws.Issues;
 import org.sonarqube.ws.Measures;
 import org.sonarqube.ws.client.HttpConnector;
@@ -44,12 +41,10 @@
 import static java.util.stream.Collectors.toList;
 import static java.util.stream.Collectors.toMap;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonarqube.ws.Common.RuleType.CODE_SMELL;
-import static org.sonarqube.ws.Common.Severity.MINOR;
 
-abstract class LaunchSonarqubeAndBuildProject {
+abstract class BuildProjectEngine {
 
-	private static final System.Logger LOGGER = System.getLogger(LaunchSonarqubeAndBuildProject.class.getName());
+	private static final System.Logger LOGGER = System.getLogger(BuildProjectEngine.class.getName());
 
 	protected static OrchestratorExtension orchestrator;
 	protected static List analyzedProjects;
@@ -204,10 +199,10 @@ private static Stream splitAndTrim(String value, String regexSeparator)
 
 	private static Set additionalPluginsToInstall() {
 		Set plugins = commaSeparatedValues(systemProperty("test-it.plugins"))
-				.map(LaunchSonarqubeAndBuildProject::toPluginLocation)
+				.map(BuildProjectEngine::toPluginLocation)
 				.collect(Collectors.toSet());
 		commaSeparatedValues(System.getProperty("test-it.additional-plugins", ""))
-				.map(LaunchSonarqubeAndBuildProject::toPluginLocation)
+				.map(BuildProjectEngine::toPluginLocation)
 				.forEach(plugins::add);
 		return plugins;
 	}
@@ -419,34 +414,4 @@ private void associateProjectToQualityProfile(Server server, Map
 		}
 	}
 
-	@Getter
-	@Builder
-	protected static class IssueDetails {
-		private String rule;
-		private String message;
-		private int line;
-		private int startLine;
-		private int endLine;
-		private int startOffset;
-		private int endOffset;
-		private Common.RuleType type;
-		private Common.Severity severity;
-		private String debt;
-		private String effort;
-	}
-
-	protected void verifyIssue(Issues.Issue issueToCheck, IssueDetails issueSource) {
-		assertThat(issueToCheck.getRule()).isEqualTo(issueSource.getRule());
-		assertThat(issueToCheck.getMessage()).isEqualTo(issueSource.getMessage());
-		assertThat(issueToCheck.getLine()).isEqualTo(issueSource.getLine());
-		assertThat(issueToCheck.getTextRange().getStartLine()).isEqualTo(issueSource.getStartLine());
-		assertThat(issueToCheck.getTextRange().getEndLine()).isEqualTo(issueSource.getEndLine());
-		assertThat(issueToCheck.getTextRange().getStartOffset()).isEqualTo(issueSource.getStartOffset());
-		assertThat(issueToCheck.getTextRange().getEndOffset()).isEqualTo(issueSource.getEndOffset());
-		assertThat(issueToCheck.getSeverity()).isEqualTo(issueSource.getSeverity());
-		assertThat(issueToCheck.getType()).isEqualTo(issueSource.getType());
-		assertThat(issueToCheck.getDebt()).isEqualTo(issueSource.getDebt());
-		assertThat(issueToCheck.getEffort()).isEqualTo(issueSource.getEffort());
-	}
-
 }
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI69IT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI69IT.java
deleted file mode 100644
index 0784a856..00000000
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI69IT.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package org.greencodeinitiative.creedengo.java.integration.tests;
-
-import org.junit.jupiter.api.Test;
-import org.sonarqube.ws.Issues;
-
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonarqube.ws.Common.RuleType.CODE_SMELL;
-import static org.sonarqube.ws.Common.Severity.MINOR;
-
-class GCI69IT extends LaunchSonarqubeAndBuildProject {
-
-    @Test
-    void testGCI69() {
-        String projectKey = analyzedProjects.get(0).getProjectKey();
-
-        List issuesForArrayCopyCheck = issuesForFile(projectKey, "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java");
-
-        assertThat(issuesForArrayCopyCheck)
-                .hasSize(1)
-                .first().satisfies(issue -> verifyIssue(issue, IssueDetails.builder()
-                        .rule("creedengo-java:GCI69")
-                        .message("Do not call a function when declaring a for-type loop")
-                        .line(18)
-                        .startLine(18)
-                        .endLine(18)
-                        .startOffset(15)
-                        .endOffset(27)
-                        .severity(MINOR)
-                        .type(CODE_SMELL)
-                        .debt("5min")
-                        .effort("5min")
-                        .build())
-                );
-
-    }
-
-}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI94IT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI94IT.java
deleted file mode 100644
index 61211154..00000000
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI94IT.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package org.greencodeinitiative.creedengo.java.integration.tests;
-
-import org.junit.jupiter.api.Test;
-import org.sonarqube.ws.Issues;
-
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonarqube.ws.Common.RuleType.CODE_SMELL;
-import static org.sonarqube.ws.Common.Severity.MINOR;
-
-class GCI94IT extends LaunchSonarqubeAndBuildProject {
-
-    @Test
-    void testGCI94() {
-        String projectKey = analyzedProjects.get(0).getProjectKey();
-
-        List issuesForArrayCopyCheck = issuesForFile(projectKey, "src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java");
-
-        assertThat(issuesForArrayCopyCheck)
-                .hasSize(1)
-                .first().satisfies(issue -> verifyIssue(issue, IssueDetails.builder()
-                        .rule("creedengo-java:GCI94")
-                        .message("Use optional orElseGet instead of orElse.")
-                        .line(25)
-                        .startLine(25)
-                        .endLine(25)
-                        .startOffset(38)
-                        .endOffset(69)
-                        .severity(MINOR)
-                        .type(CODE_SMELL)
-                        .debt("1min")
-                        .effort("1min")
-                        .build())
-        );
-
-    }
-
-}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
new file mode 100644
index 00000000..8b68d551
--- /dev/null
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
@@ -0,0 +1,93 @@
+package org.greencodeinitiative.creedengo.java.integration.tests;
+
+import org.assertj.core.groups.Tuple;
+import org.junit.jupiter.api.Test;
+import org.sonarqube.ws.Issues;
+import org.sonarqube.ws.Measures;
+
+import java.util.List;
+import java.util.Map;
+
+import static java.util.Optional.ofNullable;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonarqube.ws.Common.RuleType.CODE_SMELL;
+import static org.sonarqube.ws.Common.Severity.MINOR;
+
+class GCIRulesIT extends BuildProjectEngine {
+
+    @Test
+    void testMeasuresAndIssues() {
+        String projectKey = analyzedProjects.get(0).getProjectKey();
+
+        Map measures = getMeasures(projectKey);
+
+        assertThat(ofNullable(measures.get("code_smells")).map(Measures.Measure::getValue).map(Integer::parseInt).orElse(0))
+                .isGreaterThan(1);
+
+        List projectIssues = issuesForComponent(projectKey);
+        assertThat(projectIssues).isNotEmpty();
+
+    }
+
+    @Test
+    void testGCI69() {
+        String projectKey = analyzedProjects.get(0).getProjectKey();
+
+        List issues = issuesForFile(projectKey,
+                "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java");
+
+        assertThat(issues)
+            .hasSize(1)
+            .extracting("rule", "message", "line", "textRange.startLine", "textRange.endLine",
+                    "textRange.startOffset", "textRange.endOffset", "severity", "type", "debt", "effort")
+            .containsExactly(
+                    Tuple.tuple("creedengo-java:GCI69", "Do not call a function when declaring a for-type loop",
+                            18, 18, 18, 15, 27, MINOR, CODE_SMELL, "5min", "5min")
+            );
+
+    }
+
+    @Test
+    void testGCI82() {
+        String projectKey = analyzedProjects.get(0).getProjectKey();
+
+        List issues = issuesForFile(projectKey,
+                "src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java");
+
+        assertThat(issues)
+                .hasSize(4)
+                .extracting("rule", "message", "line", "textRange.startLine", "textRange.endLine",
+                        "textRange.startOffset", "textRange.endOffset", "severity", "type", "debt", "effort")
+                .contains(
+                        Tuple.tuple("creedengo-java:GCI82", "The variable is never reassigned and can be 'final'",
+                                7, 7, 7, 4, 67, MINOR, CODE_SMELL, "5min", "5min"),
+                        Tuple.tuple("creedengo-java:GCI82", "The variable is never reassigned and can be 'final'",
+                                12, 12, 12, 4, 56, MINOR, CODE_SMELL, "5min", "5min"),
+                        Tuple.tuple("creedengo-java:GCI82", "The variable is never reassigned and can be 'final'",
+                                13, 13, 13, 4, 50, MINOR, CODE_SMELL, "5min", "5min"),
+                        Tuple.tuple("creedengo-java:GCI82", "The variable is never reassigned and can be 'final'",
+                                45, 45, 45, 8, 25, MINOR, CODE_SMELL, "5min", "5min")
+                );
+
+    }
+
+    @Test
+    void testGCI94() {
+        String projectKey = analyzedProjects.get(0).getProjectKey();
+
+        List issues = issuesForFile(projectKey,
+                "src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java");
+
+        assertThat(issues)
+                .hasSize(1)
+                .extracting("rule", "message", "line", "textRange.startLine", "textRange.endLine",
+                        "textRange.startOffset", "textRange.endOffset", "severity", "type", "debt", "effort")
+                .containsExactly(
+                        Tuple.tuple(
+                                "creedengo-java:GCI94", "Use optional orElseGet instead of orElse.",
+                                25, 25, 25, 38, 69, MINOR, CODE_SMELL, "1min", "1min")
+                );
+
+    }
+
+}
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java
index 91775b0f..3ef6359e 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java
@@ -10,14 +10,15 @@ class AvoidGettingSizeCollectionInForLoopIgnored {
     }
 
     public void badForLoop() {
-        List numberList = new ArrayList();
+        final List numberList = new ArrayList();
         numberList.add(10);
         numberList.add(20);
 
-        Iterator it = numberList.iterator();
+        final Iterator it = numberList.iterator();
         for (; it.hasNext(); ) { // Ignored => compliant
-            it.next();
-            System.out.println("numberList.size()");
+            System.out.println(it.next());
         }
     }
+
+
 }
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
new file mode 100644
index 00000000..bef640d4
--- /dev/null
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
@@ -0,0 +1,69 @@
+import java.util.logging.Logger;
+
+public class MakeNonReassignedVariablesConstants {
+
+    private final Logger logger = Logger.getLogger(""); // Compliant
+
+    private Object myNonFinalAndNotReassignedObject = new Object(); // Noncompliant {{The variable is never reassigned and can be 'final'}}
+    private Object myNonFinalAndReassignedObject = new Object(); // Compliant
+    private final Object myFinalAndNotReassignedObject = new Object(); // Compliant
+
+    private static final String CONSTANT = "toto";  // Compliant
+    private String varDefinedInClassNotReassigned = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
+    private String varDefinedInClassNotUsed = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
+    private String varDefinedInClassReassigned = "0"; // Compliant
+    private String varDefinedInConstructorReassigned = "1"; // Compliant
+
+    public MakeNonReassignedVariablesConstants() {
+        varDefinedInConstructorReassigned = "3";
+        logger.info(varDefinedInConstructorReassigned);
+    }
+
+    void localVariableReassigned() {
+        String y1 = "10"; // Compliant
+        final String PI = "3.14159"; // Compliant
+
+        y1 = "titi";
+
+        logger.info(y1);
+        logger.info(PI);
+    }
+
+    void localVariableIncrement() {
+        String y2 = "10"; // Compliant
+        y2 += "titi";
+        logger.info(y2);
+    }
+
+    void localIntVariableIncrement() {
+        int y3 = 10; // Compliant
+        ++y3;
+        logger.info(y3+"");
+    }
+
+    void localVariableNotReassigned() {
+        String y4 = "10"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
+        final String PI2 = "3.14159"; // Compliant
+
+        logger.info(y4);
+        logger.info(PI2);
+    }
+
+    void classVariableReassigned() {
+        varDefinedInClassReassigned = "1";
+
+        logger.info(varDefinedInClassReassigned);
+        logger.info(varDefinedInClassNotReassigned);
+        logger.info(CONSTANT);
+    }
+
+    void classVariableReassignedBis() {
+        varDefinedInClassReassigned = "2"; // method to avoid sonarqube error asking for moving class variable "varDefinedInClassReassigned" to local variable method
+        myNonFinalAndReassignedObject = new Object();
+
+        logger.info(varDefinedInClassReassigned);
+        logger.info(myNonFinalAndReassignedObject.toString());
+        logger.info(myFinalAndNotReassignedObject.toString());
+    }
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrar.java b/src/main/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrar.java
index a4037e0a..791f0cef 100644
--- a/src/main/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrar.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrar.java
@@ -49,7 +49,8 @@ public class JavaCheckRegistrar implements CheckRegistrar {
             AvoidSetConstantInBatchUpdate.class,
             FreeResourcesOfAutoCloseableInterface.class,
             AvoidMultipleIfElseStatement.class,
-            UseOptionalOrElseGetVsOrElse.class
+            UseOptionalOrElseGetVsOrElse.class,
+            MakeNonReassignedVariablesConstants.class
     );
 
     /**
diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
new file mode 100644
index 00000000..6323cc01
--- /dev/null
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
@@ -0,0 +1,129 @@
+package org.greencodeinitiative.creedengo.java.checks;
+
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.check.Rule;
+import org.sonar.java.model.ModifiersUtils;
+import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
+import org.sonar.plugins.java.api.tree.*;
+import org.sonar.plugins.java.api.tree.Tree.Kind;
+
+import javax.annotation.Nonnull;
+import java.util.List;
+
+@Rule(key = "GCI82")
+public class MakeNonReassignedVariablesConstants extends IssuableSubscriptionVisitor {
+
+    protected static final String MESSAGE_RULE = "The variable is never reassigned and can be 'final'";
+
+    private static final Logger LOGGER = Loggers.get(MakeNonReassignedVariablesConstants.class);
+
+    @Override
+    public List nodesToVisit() {
+        return List.of(Kind.VARIABLE);
+    }
+
+    @Override
+    public void visitNode(@Nonnull Tree tree) {
+        VariableTree variableTree = (VariableTree) tree;
+        LOGGER.debug("Variable > " + getVariableNameForLogger(variableTree));
+        LOGGER.debug("   => isNotFinalAndNotStatic(variableTree) = " + isNotFinalAndNotStatic(variableTree));
+        LOGGER.debug("   => usages = " + variableTree.symbol().usages().size());
+        LOGGER.debug("   => isNotReassigned = " + isNotReassigned(variableTree));
+
+        if (isNotFinalAndNotStatic(variableTree) && isNotReassigned(variableTree)) {
+            reportIssue(tree, MESSAGE_RULE);
+        } else {
+            super.visitNode(tree);
+        }
+    }
+
+    private static boolean isNotReassigned(VariableTree variableTree) {
+        return variableTree.symbol()
+                .usages()
+                .stream()
+                .noneMatch(MakeNonReassignedVariablesConstants::parentIsAssignment);
+    }
+
+    private static boolean parentIsAssignment(Tree tree) {
+        return parentIsKind(tree,
+                Kind.ASSIGNMENT,
+                Kind.MULTIPLY_ASSIGNMENT,
+                Kind.DIVIDE_ASSIGNMENT,
+                Kind.REMAINDER_ASSIGNMENT,
+                Kind.PLUS_ASSIGNMENT,
+                Kind.MINUS_ASSIGNMENT,
+                Kind.LEFT_SHIFT_ASSIGNMENT,
+                Kind.RIGHT_SHIFT_ASSIGNMENT,
+                Kind.UNSIGNED_RIGHT_SHIFT_ASSIGNMENT,
+                Kind.AND_ASSIGNMENT,
+                Kind.XOR_ASSIGNMENT,
+                Kind.OR_ASSIGNMENT,
+                Kind.POSTFIX_INCREMENT,
+                Kind.POSTFIX_DECREMENT,
+                Kind.PREFIX_INCREMENT,
+                Kind.PREFIX_DECREMENT
+        );
+    }
+
+    private static boolean parentIsKind(Tree tree, Kind... orKind) {
+        Tree parent = tree.parent();
+        if (parent == null) return false;
+
+        for (Kind k : orKind) {
+            if (parent.is(k)) return true;
+        }
+
+        return false;
+    }
+
+    private static boolean isNotFinalAndNotStatic(VariableTree variableTree) {
+//        return ModifiersUtils.hasNoneOf(variableTree.modifiers(), Modifier.FINAL, Modifier.STATIC);
+        return hasNoneOf(variableTree.modifiers(), Modifier.FINAL, Modifier.STATIC);
+    }
+
+    private static boolean hasNoneOf(ModifiersTree modifiersTree, Modifier... unexpectedModifiers) {
+        return !hasAnyOf(modifiersTree, unexpectedModifiers);
+    }
+
+    private static boolean hasAnyOf(ModifiersTree modifiersTree, Modifier... expectedModifiers) {
+        for(Modifier expectedModifier : expectedModifiers) {
+            if (hasModifier(modifiersTree, expectedModifier)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public static boolean hasModifier(ModifiersTree modifiersTree, Modifier expectedModifier) {
+        for(ModifierKeywordTree modifierKeywordTree : modifiersTree.modifiers()) {
+            if (modifierKeywordTree.modifier() == expectedModifier) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    private String getVariableNameForLogger(VariableTree variableTree) {
+        String name = variableTree.simpleName().name();
+
+        if (variableTree.parent() != null) return name;
+
+        if (variableTree.parent().is(Kind.CLASS)) {
+            ClassTree cTree = (ClassTree) variableTree.parent();
+            name += "  ---  from CLASS '" + cTree.simpleName() + "'";
+        }
+        if (variableTree.parent().is(Kind.BLOCK)) {
+            BlockTree bTree = (BlockTree) variableTree.parent();
+            if (bTree.parent() != null && bTree.parent().is(Kind.METHOD)) {
+                MethodTree mTree = (MethodTree) bTree.parent();
+                name += "  ---  from METHOD '" + mTree.simpleName() + "'";
+            }
+        }
+
+        return name;
+
+    }
+
+}
diff --git a/src/main/resources/org/greencodeinitiative/creedengo/java/creedengo_way_profile.json b/src/main/resources/org/greencodeinitiative/creedengo/java/creedengo_way_profile.json
index b5a4b85f..8c613661 100644
--- a/src/main/resources/org/greencodeinitiative/creedengo/java/creedengo_way_profile.json
+++ b/src/main/resources/org/greencodeinitiative/creedengo/java/creedengo_way_profile.json
@@ -17,6 +17,7 @@
 	"GCI77",
 	"GCI78",
 	"GCI79",
+	  "GCI82",
 	"GCI94"
   ]
 }
diff --git a/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java b/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java
index ced5bf08..c1fa56cb 100644
--- a/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java
+++ b/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java
@@ -21,20 +21,19 @@
 import java.util.ArrayList;
 import java.util.List;
 
-class AvoidGettingSizeCollectionInForLoopBad {
+class GCI69AvoidGettingSizeCollectionInForLoopBad {
     AvoidGettingSizeCollectionInForLoopBad() {
 
     }
 
     public void badForLoop() {
-        List numberList = new ArrayList();
+        final List numberList = new ArrayList();
         numberList.add(10);
         numberList.add(20);
 
-        Iterator it = numberList.iterator();
+        final Iterator it = numberList.iterator();
         for (; it.hasNext(); ) { // Ignored => compliant
-            it.next();
-            System.out.println("numberList.size()");
+            System.out.println(it.next());
         }
     }
 }
diff --git a/src/test/files/MakeNonReassignedVariablesConstants.java b/src/test/files/MakeNonReassignedVariablesConstants.java
new file mode 100644
index 00000000..a8e40393
--- /dev/null
+++ b/src/test/files/MakeNonReassignedVariablesConstants.java
@@ -0,0 +1,69 @@
+import java.util.logging.Logger;
+
+public class GCI82MakeNonReassignedVariablesConstants {
+
+    private final Logger logger = Logger.getLogger(""); // Compliant
+
+    private Object myNonFinalAndNotReassignedObject = new Object(); // Noncompliant {{The variable is never reassigned and can be 'final'}}
+    private Object myNonFinalAndReassignedObject = new Object(); // Compliant
+    private final Object myFinalAndNotReassignedObject = new Object(); // Compliant
+
+    private static final String CONSTANT = "toto";  // Compliant
+    private String varDefinedInClassNotReassigned = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
+    private String varDefinedInClassNotUsed = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
+    private String varDefinedInClassReassigned = "0"; // Compliant
+    private String varDefinedInConstructorReassigned = "1"; // Compliant
+
+    public GCI82MakeNonReassignedVariablesConstants() {
+        varDefinedInConstructorReassigned = "3";
+        logger.info(varDefinedInConstructorReassigned);
+    }
+
+    void localVariableReassigned() {
+        String y1 = "10"; // Compliant
+        final String PI = "3.14159"; // Compliant
+
+        y1 = "titi";
+
+        logger.info(y1);
+        logger.info(PI);
+    }
+
+    void localVariableIncrement() {
+        String y2 = "10"; // Compliant
+        y2 += "titi";
+        logger.info(y2);
+    }
+
+    void localIntVariableIncrement() {
+        int y3 = 10; // Compliant
+        ++y3;
+        logger.info(y3+"");
+    }
+
+    void localVariableNotReassigned() {
+        String y4 = "10"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
+        final String PI2 = "3.14159"; // Compliant
+
+        logger.info(y4);
+        logger.info(PI2);
+    }
+
+    void classVariableReassigned() {
+        varDefinedInClassReassigned = "1";
+
+        logger.info(varDefinedInClassReassigned);
+        logger.info(varDefinedInClassNotReassigned);
+        logger.info(CONSTANT);
+    }
+
+    void classVariableReassignedBis() {
+        varDefinedInClassReassigned = "2"; // method to avoid sonarqube error asking for moving class variable "varDefinedInClassReassigned" to local variable method
+        myNonFinalAndReassignedObject = new Object();
+
+        logger.info(varDefinedInClassReassigned);
+        logger.info(myNonFinalAndReassignedObject.toString());
+        logger.info(myFinalAndNotReassignedObject.toString());
+    }
+
+}
\ No newline at end of file
diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstantsTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstantsTest.java
new file mode 100644
index 00000000..837a632e
--- /dev/null
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstantsTest.java
@@ -0,0 +1,33 @@
+/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.greencodeinitiative.creedengo.java.checks;
+
+import org.junit.jupiter.api.Test;
+import org.sonar.java.checks.verifier.CheckVerifier;
+
+class MakeNonReassignedVariablesConstantsTest {
+
+    @Test
+    void test() {
+        CheckVerifier.newVerifier()
+                .onFile("src/test/files/MakeNonReassignedVariablesConstants.java")
+                .withCheck(new MakeNonReassignedVariablesConstants())
+                .verifyIssues();
+    }
+
+}

From adc70f9a2dc15926f17b9fef909f261e2ead8849 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Fri, 3 Jan 2025 16:41:02 +0100
Subject: [PATCH 111/233] update creedengo-rules-spec

---
 pom.xml | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 8940b3f5..54cfa95a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -72,8 +72,7 @@
         1.7
 
         
-        main-SNAPSHOT
-
+        2.1.0
 
         
         https://repo1.maven.org/maven2

From ee5d5f64389c6ca3080d1ac2c6c6e34cfbd8cd59 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Fri, 3 Jan 2025 17:00:11 +0100
Subject: [PATCH 112/233] clean code

---
 .../java/checks/MakeNonReassignedVariablesConstants.java        | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
index 6323cc01..6533256d 100644
--- a/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
@@ -3,7 +3,6 @@
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.check.Rule;
-import org.sonar.java.model.ModifiersUtils;
 import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
 import org.sonar.plugins.java.api.tree.*;
 import org.sonar.plugins.java.api.tree.Tree.Kind;
@@ -78,7 +77,6 @@ private static boolean parentIsKind(Tree tree, Kind... orKind) {
     }
 
     private static boolean isNotFinalAndNotStatic(VariableTree variableTree) {
-//        return ModifiersUtils.hasNoneOf(variableTree.modifiers(), Modifier.FINAL, Modifier.STATIC);
         return hasNoneOf(variableTree.modifiers(), Modifier.FINAL, Modifier.STATIC);
     }
 

From 38952d789e7d19c3c27d5c799b2dcabf4b50f6a8 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Fri, 3 Jan 2025 17:19:47 +0100
Subject: [PATCH 113/233] minor corrections

---
 CHANGELOG.md                                                  | 2 +-
 .../creedengo/java/creedengo_way_profile.json                 | 2 +-
 src/test/files/MakeNonReassignedVariablesConstants.java       | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index d46e8710..277f0dd9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Added
 
 - [#88](https://github.com/green-code-initiative/creedengo-java/pull/88) Add new Java rule GCI94 - Use orElseGet instead of orElse
-- [#88](https://github.com/green-code-initiative/creedengo-java/pull/88) Add new Java rule GCI82 - Make non reassigned variables constants
+- [#89](https://github.com/green-code-initiative/creedengo-java/pull/89) Add new Java rule GCI82 - Make non reassigned variables constants
 
 ### Changed
 
diff --git a/src/main/resources/org/greencodeinitiative/creedengo/java/creedengo_way_profile.json b/src/main/resources/org/greencodeinitiative/creedengo/java/creedengo_way_profile.json
index 8c613661..059bf0f5 100644
--- a/src/main/resources/org/greencodeinitiative/creedengo/java/creedengo_way_profile.json
+++ b/src/main/resources/org/greencodeinitiative/creedengo/java/creedengo_way_profile.json
@@ -17,7 +17,7 @@
 	"GCI77",
 	"GCI78",
 	"GCI79",
-	  "GCI82",
+	"GCI82",
 	"GCI94"
   ]
 }
diff --git a/src/test/files/MakeNonReassignedVariablesConstants.java b/src/test/files/MakeNonReassignedVariablesConstants.java
index a8e40393..bef640d4 100644
--- a/src/test/files/MakeNonReassignedVariablesConstants.java
+++ b/src/test/files/MakeNonReassignedVariablesConstants.java
@@ -1,6 +1,6 @@
 import java.util.logging.Logger;
 
-public class GCI82MakeNonReassignedVariablesConstants {
+public class MakeNonReassignedVariablesConstants {
 
     private final Logger logger = Logger.getLogger(""); // Compliant
 
@@ -14,7 +14,7 @@ public class GCI82MakeNonReassignedVariablesConstants {
     private String varDefinedInClassReassigned = "0"; // Compliant
     private String varDefinedInConstructorReassigned = "1"; // Compliant
 
-    public GCI82MakeNonReassignedVariablesConstants() {
+    public MakeNonReassignedVariablesConstants() {
         varDefinedInConstructorReassigned = "3";
         logger.info(varDefinedInConstructorReassigned);
     }

From 379696dc5ced1f8e2b2aa4377e37247e848eae84 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Fri, 3 Jan 2025 23:35:22 +0100
Subject: [PATCH 114/233] delete dependabot config - disable for now auto
 update

---
 .github/dependabot.yml | 11 -----------
 1 file changed, 11 deletions(-)
 delete mode 100644 .github/dependabot.yml

diff --git a/.github/dependabot.yml b/.github/dependabot.yml
deleted file mode 100644
index a3d018fb..00000000
--- a/.github/dependabot.yml
+++ /dev/null
@@ -1,11 +0,0 @@
-# To get started with Dependabot version updates, you'll need to specify which
-# package ecosystems to update and where the package manifests are located.
-# Please see the documentation for all configuration options:
-# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
-
-version: 2
-updates:
-  - package-ecosystem: "maven" # See documentation for possible values
-    directory: "/" # Location of package manifests
-    schedule:
-      interval: "monthly"

From f42d73e81447852b7a964009c46e86f7be6dc646 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Sun, 5 Jan 2025 22:21:56 +0100
Subject: [PATCH 115/233] update lib versions

---
 pom.xml | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/pom.xml b/pom.xml
index 54cfa95a..232c3412 100644
--- a/pom.xml
+++ b/pom.xml
@@ -165,13 +165,13 @@
         
             org.sonarsource.orchestrator
             sonar-orchestrator-junit5
-            4.9.0.1920
+            5.1.0.2254
             test
         
         
             org.sonarsource.java
             test-classpath-reader
-            8.5.0.37199
+            8.8.0.37665
             test
         
         
@@ -211,7 +211,7 @@
             
                 org.apache.maven.plugins
                 maven-compiler-plugin
-                3.11.0
+                3.13.0
             
             
                 org.apache.maven.plugins
@@ -261,7 +261,7 @@
                 
                 org.codehaus.mojo
                 buildnumber-maven-plugin
-                3.1.0
+                3.2.1
                 
                     
                         validate
@@ -279,7 +279,7 @@
                 
                 org.apache.maven.plugins
                 maven-shade-plugin
-                3.5.0
+                3.6.0
                 
                     
                         package
@@ -385,7 +385,7 @@
             
                 com.mycila
                 license-maven-plugin
-                4.1
+                4.6
                 
                     
                         Green Code Initiative
@@ -456,7 +456,7 @@
                 
                 org.apache.maven.plugins
                 maven-failsafe-plugin
-                3.2.5
+                3.5.2
                 
                     
                         

From 670e15b1f1c2964ac2ab7d75a82420e56b1b1647 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Mon, 6 Jan 2025 00:19:36 +0100
Subject: [PATCH 116/233] improve GCI89 - get code from PR 45

---
 CHANGELOG.md                                  |  1 +
 .../java/integration/tests/GCIRulesIT.java    | 32 ++++++-
 ...voidGettingSizeCollectionInForLoopBad.java |  7 +-
 .../NoFunctionCallWhenDeclaringForLoop.java   | 95 +++++++++++++++----
 .../NoFunctionCallWhenDeclaringForLoop.java   | 13 ++-
 ...voidGettingSizeCollectionInForLoopBad.java | 25 +----
 .../NoFunctionCallWhenDeclaringForLoop.java   | 78 +++++++++++----
 7 files changed, 184 insertions(+), 67 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 277f0dd9..1248b379 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - upgrade some libraries versions
 - improve Integration Tests system to be more flexible (add new IT for each rule)
+- [#21](https://github.com/green-code-initiative/ecoCode-java/issues/21) Improvement: some method calls are legitimate in a for loop expression
 
 ### Deleted
 
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
index 8b68d551..671b1462 100644
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
@@ -29,20 +29,46 @@ void testMeasuresAndIssues() {
 
     }
 
+    @Test
+    void testGCI3() {
+        String projectKey = analyzedProjects.get(0).getProjectKey();
+
+        List issues = issuesForFile(projectKey,
+                "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java");
+
+        assertThat(issues)
+                .hasSize(2)
+                .extracting("rule", "message", "line", "textRange.startLine", "textRange.endLine",
+                        "textRange.startOffset", "textRange.endOffset", "severity", "type", "debt", "effort")
+                .containsExactly(
+                        Tuple.tuple("creedengo-java:GCI3", "Avoid getting the size of the collection in the loop",
+                                13, 13, 13, 28, 45, MINOR, CODE_SMELL, "5min", "5min"),
+                        Tuple.tuple("creedengo-java:GCI69", "Do not call a function when declaring a for-type loop",
+                                13, 13, 13, 28, 45, MINOR, CODE_SMELL, "5min", "5min")
+                );
+
+    }
+
     @Test
     void testGCI69() {
         String projectKey = analyzedProjects.get(0).getProjectKey();
 
         List issues = issuesForFile(projectKey,
-                "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java");
+                "src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java");
 
         assertThat(issues)
-            .hasSize(1)
+            .hasSize(4)
             .extracting("rule", "message", "line", "textRange.startLine", "textRange.endLine",
                     "textRange.startOffset", "textRange.endOffset", "severity", "type", "debt", "effort")
             .containsExactly(
                     Tuple.tuple("creedengo-java:GCI69", "Do not call a function when declaring a for-type loop",
-                            18, 18, 18, 15, 27, MINOR, CODE_SMELL, "5min", "5min")
+                            58, 58, 58, 28, 40, MINOR, CODE_SMELL, "5min", "5min"),
+                    Tuple.tuple("creedengo-java:GCI69", "Do not call a function when declaring a for-type loop",
+                            66, 66, 66, 34, 46, MINOR, CODE_SMELL, "5min", "5min"),
+                    Tuple.tuple("creedengo-java:GCI69", "Do not call a function when declaring a for-type loop",
+                            74, 74, 74, 39, 51, MINOR, CODE_SMELL, "5min", "5min"),
+                    Tuple.tuple("creedengo-java:GCI69", "Do not call a function when declaring a for-type loop",
+                            101, 101, 101, 108, 132, MINOR, CODE_SMELL, "5min", "5min")
             );
 
     }
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java
index d3b8af41..03efe7c7 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java
@@ -4,16 +4,13 @@
 import java.util.List;
 
 class AvoidGettingSizeCollectionInForLoopBad {
-    AvoidGettingSizeCollectionInForLoopBad() {
-
-    }
 
     public void badForLoop() {
-        List numberList = new ArrayList();
+        final List numberList = new ArrayList();
         numberList.add(10);
         numberList.add(20);
 
-        for (int i = 0; i < numberList.size(); i++) { // Noncompliant {{Avoid getting the size of the collection in the loop}}
+        for (int i = 0; i < numberList.size(); ++i) { // Noncompliant
             System.out.println("numberList.size()");
         }
     }
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
index bb5ae326..42326070 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
@@ -1,58 +1,119 @@
-package org.greencodeinitiative.creedengo.java.checks;
-
+package org.greencodeinitiative.creedengo.java.integration.tests;/*
+ * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
+ * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Arrays;
 class NoFunctionCallWhenDeclaringForLoop {
-    NoFunctionCallWhenDeclaringForLoop(NoFunctionCallWhenDeclaringForLoop mc) {
-    }
 
     public int getMyValue() {
         return 6;
     }
 
-    public int incrementeMyValue(int i) {
+    public int incrementeMyValue(final int i) {
         return i + 100;
     }
 
     public void test1() {
-        for (int i = 0; i < 20; i++) {
+        for (int i = 0; i < 20; ++i) {
             System.out.println(i);
-            boolean b = getMyValue() > 6;
+            final boolean b = getMyValue() > 6;
+            System.out.println(b);
         }
     }
 
     public void test2() {
-        String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
-        for (String i : cars) {
+        final String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
+        for (final String i : cars) {
             System.out.println(i);
         }
 
     }
 
+    // compliant, the function is called only once in the initialization so it's not a performance issue
     public void test3() {
-        for (int i = getMyValue(); i < 20; i++) {  // Noncompliant {{Do not call a function when declaring a for-type loop}}
+        for (int i = getMyValue(); i < 20; ++i) {
             System.out.println(i);
-            boolean b = getMyValue() > 6;
+            final boolean b = getMyValue() > 6;
+            System.out.println(b);
         }
     }
 
     public void test4() {
-        for (int i = 0; i < getMyValue(); i++) {  // Noncompliant {{Do not call a function when declaring a for-type loop}}
+        for (int i = 0; i < getMyValue(); ++i) {  // Noncompliant {{Do not call a function when declaring a for-type loop}}
             System.out.println(i);
-            boolean b = getMyValue() > 6;
+            final boolean b = getMyValue() > 6;
+            System.out.println(b);
         }
     }
 
     public void test5() {
-        for (int i = 0; i < getMyValue(); incrementeMyValue(i)) {  // Noncompliant {{Do not call a function when declaring a for-type loop}}
+        for (final int i = 0; i < getMyValue(); incrementeMyValue(i)) {  // Noncompliant {{Do not call a function when declaring a for-type loop}}
             System.out.println(i);
-            boolean b = getMyValue() > 6;
+            final boolean b = getMyValue() > 6;
+            System.out.println(b);
         }
     }
 
     public void test6() {
-        for (int i = getMyValue(); i < getMyValue(); i++) { // Noncompliant {{Do not call a function when declaring a for-type loop}}
+        for (int i = getMyValue(); i < getMyValue(); ++i) { // Noncompliant {{Do not call a function when declaring a for-type loop}}
             System.out.println(i);
-            boolean b = getMyValue() > 6;
+            final boolean b = getMyValue() > 6;
+            System.out.println(b);
+        }
+    }
+
+    // compliant, iterators are allowed to be called in a for loop
+    public void test7() {
+        final List joursSemaine = Arrays.asList("Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche");
+
+        String jour = null;
+        // iterator is allowed
+        for (final Iterator iterator = joursSemaine.iterator(); iterator.hasNext(); jour = iterator.next()) {
+            System.out.println(jour);
+        }
+
+        // subclass of iterator is allowed
+        for (final ListIterator iterator = joursSemaine.listIterator(); iterator.hasNext(); jour = iterator.next()) {
+            System.out.println(jour);
+        }
+
+        // iterator called in an indirect way is allowed
+        for (final OtherClassWithIterator otherClass = new OtherClassWithIterator(joursSemaine.iterator()); otherClass.iterator.hasNext(); jour = otherClass.iterator.next()) {
+            System.out.println(jour);
+        }
+        // but using a method that returns an iterator causes an issue
+        for (final OtherClassWithIterator otherClass = new OtherClassWithIterator(joursSemaine.iterator()); otherClass.getIterator().hasNext(); jour = otherClass.getIterator().next()) {  // Noncompliant {{Do not call a function when declaring a for-type loop}}
+            System.out.println(jour);
         }
+
     }
 
 }
+
+class OtherClassWithIterator {
+    public final Iterator iterator;
+
+    public OtherClassWithIterator(Iterator iterator){
+        this.iterator = iterator;
+    }
+
+    public Iterator getIterator(){
+        return iterator;
+    }
+}
diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
index 8ebb8dbf..b364b55a 100644
--- a/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
@@ -59,23 +59,30 @@ public void visitNode(Tree tree) {
         if (null != condition) {
             method.condition().accept(invocationMethodVisitor);
         }
+
         // update
-        // initaliser
         method.update().accept(invocationMethodVisitor);
-        method.initializer().accept(invocationMethodVisitor);
     }
 
     private class MethodInvocationInForStatementVisitor extends BaseTreeVisitor {
 
         @Override
         public void visitMethodInvocation(MethodInvocationTree tree) {
-            if (!lineAlreadyHasThisIssue(tree)) {
+            if (!lineAlreadyHasThisIssue(tree) && !isIteratorMethod(tree)) {
                 report(tree);
                 return;
             }
             super.visitMethodInvocation(tree);
         }
 
+        private boolean isIteratorMethod(MethodInvocationTree tree) {
+            boolean isIterator = tree.methodSymbol().owner().type().isSubtypeOf("java.util.Iterator");
+            String methodName = tree.methodSelect().lastToken().text();
+            boolean isMethodNext = methodName.equals("next");
+            boolean isMethodHasNext = methodName.equals("hasNext");
+            return isIterator && (isMethodNext || isMethodHasNext);
+        }
+
         private boolean lineAlreadyHasThisIssue(Tree tree) {
             if (tree.firstToken() != null) {
                 final String classname = getFullyQualifiedNameOfClassOf(tree);
diff --git a/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java b/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java
index c21f81c8..b437655d 100644
--- a/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java
+++ b/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java
@@ -1,37 +1,16 @@
-/*
- * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
 package org.greencodeinitiative.creedengo.java.checks;
 
-import java.util.Collection;
 import java.util.ArrayList;
 import java.util.List;
 
 class AvoidGettingSizeCollectionInForLoopBad {
-    AvoidGettingSizeCollectionInForLoopBad() {
-
-    }
 
     public void badForLoop() {
-        List numberList = new ArrayList();
+        final List numberList = new ArrayList();
         numberList.add(10);
         numberList.add(20);
 
-        for (int i = 0; i < numberList.size(); i++) { // Noncompliant {{Avoid getting the size of the collection in the loop}}
+        for (int i = 0; i < numberList.size(); ++i) { // Noncompliant {{Avoid getting the size of the collection in the loop}}
             System.out.println("numberList.size()");
         }
     }
diff --git a/src/test/files/NoFunctionCallWhenDeclaringForLoop.java b/src/test/files/NoFunctionCallWhenDeclaringForLoop.java
index 10214628..42326070 100644
--- a/src/test/files/NoFunctionCallWhenDeclaringForLoop.java
+++ b/src/test/files/NoFunctionCallWhenDeclaringForLoop.java
@@ -1,4 +1,4 @@
-/*
+package org.greencodeinitiative.creedengo.java.integration.tests;/*
  * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
  * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
  *
@@ -15,59 +15,105 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Arrays;
 class NoFunctionCallWhenDeclaringForLoop {
-    NoFunctionCallWhenDeclaringForLoop(NoFunctionCallWhenDeclaringForLoop mc) {
-    }
 
     public int getMyValue() {
         return 6;
     }
 
-    public int incrementeMyValue(int i) {
+    public int incrementeMyValue(final int i) {
         return i + 100;
     }
 
     public void test1() {
-        for (int i = 0; i < 20; i++) {
+        for (int i = 0; i < 20; ++i) {
             System.out.println(i);
-            boolean b = getMyValue() > 6;
+            final boolean b = getMyValue() > 6;
+            System.out.println(b);
         }
     }
 
     public void test2() {
-        String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
-        for (String i : cars) {
+        final String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
+        for (final String i : cars) {
             System.out.println(i);
         }
 
     }
 
+    // compliant, the function is called only once in the initialization so it's not a performance issue
     public void test3() {
-        for (int i = getMyValue(); i < 20; i++) {  // Noncompliant {{Do not call a function when declaring a for-type loop}}
+        for (int i = getMyValue(); i < 20; ++i) {
             System.out.println(i);
-            boolean b = getMyValue() > 6;
+            final boolean b = getMyValue() > 6;
+            System.out.println(b);
         }
     }
 
     public void test4() {
-        for (int i = 0; i < getMyValue(); i++) {  // Noncompliant {{Do not call a function when declaring a for-type loop}}
+        for (int i = 0; i < getMyValue(); ++i) {  // Noncompliant {{Do not call a function when declaring a for-type loop}}
             System.out.println(i);
-            boolean b = getMyValue() > 6;
+            final boolean b = getMyValue() > 6;
+            System.out.println(b);
         }
     }
 
     public void test5() {
-        for (int i = 0; i < getMyValue(); incrementeMyValue(i)) {  // Noncompliant {{Do not call a function when declaring a for-type loop}}
+        for (final int i = 0; i < getMyValue(); incrementeMyValue(i)) {  // Noncompliant {{Do not call a function when declaring a for-type loop}}
             System.out.println(i);
-            boolean b = getMyValue() > 6;
+            final boolean b = getMyValue() > 6;
+            System.out.println(b);
         }
     }
 
     public void test6() {
-        for (int i = getMyValue(); i < getMyValue(); i++) { // Noncompliant {{Do not call a function when declaring a for-type loop}}
+        for (int i = getMyValue(); i < getMyValue(); ++i) { // Noncompliant {{Do not call a function when declaring a for-type loop}}
             System.out.println(i);
-            boolean b = getMyValue() > 6;
+            final boolean b = getMyValue() > 6;
+            System.out.println(b);
         }
     }
 
+    // compliant, iterators are allowed to be called in a for loop
+    public void test7() {
+        final List joursSemaine = Arrays.asList("Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche");
+
+        String jour = null;
+        // iterator is allowed
+        for (final Iterator iterator = joursSemaine.iterator(); iterator.hasNext(); jour = iterator.next()) {
+            System.out.println(jour);
+        }
+
+        // subclass of iterator is allowed
+        for (final ListIterator iterator = joursSemaine.listIterator(); iterator.hasNext(); jour = iterator.next()) {
+            System.out.println(jour);
+        }
+
+        // iterator called in an indirect way is allowed
+        for (final OtherClassWithIterator otherClass = new OtherClassWithIterator(joursSemaine.iterator()); otherClass.iterator.hasNext(); jour = otherClass.iterator.next()) {
+            System.out.println(jour);
+        }
+        // but using a method that returns an iterator causes an issue
+        for (final OtherClassWithIterator otherClass = new OtherClassWithIterator(joursSemaine.iterator()); otherClass.getIterator().hasNext(); jour = otherClass.getIterator().next()) {  // Noncompliant {{Do not call a function when declaring a for-type loop}}
+            System.out.println(jour);
+        }
+
+    }
+
+}
+
+class OtherClassWithIterator {
+    public final Iterator iterator;
+
+    public OtherClassWithIterator(Iterator iterator){
+        this.iterator = iterator;
+    }
+
+    public Iterator getIterator(){
+        return iterator;
+    }
 }

From 863f3a6e74de63dfe0c16802e38a64daa4d702dc Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Mon, 6 Jan 2025 00:31:28 +0100
Subject: [PATCH 117/233] changelog fix

---
 CHANGELOG.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1248b379..43b38ae9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - upgrade some libraries versions
 - improve Integration Tests system to be more flexible (add new IT for each rule)
-- [#21](https://github.com/green-code-initiative/ecoCode-java/issues/21) Improvement: some method calls are legitimate in a for loop expression
+- [#21](https://github.com/green-code-initiative/creedengo-java/issues/21) Improvement: some method calls are legitimate in a for loop expression
 
 ### Deleted
 

From 841655b1e2aed4ec0771ff775ad15c89d1ccf94c Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Tue, 7 Jan 2025 23:12:46 +0100
Subject: [PATCH 118/233] update to 24.12.0 sonarqube version

---
 CHANGELOG.md |  1 +
 Dockerfile   |  2 +-
 README.md    | 10 +++++-----
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 43b38ae9..208ef200 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - upgrade some libraries versions
 - improve Integration Tests system to be more flexible (add new IT for each rule)
 - [#21](https://github.com/green-code-initiative/creedengo-java/issues/21) Improvement: some method calls are legitimate in a for loop expression
+- check compatibility with SonarQube 10.7.0 and 24.12.0
 
 ### Deleted
 
diff --git a/Dockerfile b/Dockerfile
index d9cdbbeb..cf1d0fe9 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,5 +1,5 @@
 ARG MAVEN_BUILDER=3-openjdk-17-slim
-ARG SONARQUBE_VERSION=10.7.0-community
+ARG SONARQUBE_VERSION=24.12.0.100206-community
 
 FROM maven:${MAVEN_BUILDER} AS builder
 
diff --git a/README.md b/README.md
index 715d23e6..a51c0bd1 100644
--- a/README.md
+++ b/README.md
@@ -57,11 +57,11 @@ 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                                                                                        |
-| 1.7.+          | 9.9.+ LTS to 10.6.0 | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) |
-| 2.0.+          | 9.9.+ LTS to 10.7.0 | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) |
+| Plugin version | SonarQube version    | Java version                                                                                   |
+|----------------|----------------------|------------------------------------------------------------------------------------------------|
+| 1.6.+          | 9.4.+ LTS to 10.6.0  | 11 / 17                                                                                        |
+| 1.7.+          | 9.9.+ LTS to 10.6.0  | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) |
+| 2.0.+          | 9.9.+ LTS to 24.12.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 [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-plugins-version-compatibility).

From faef5eeace7000467705abe1d5c8c6f197712450 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Tue, 7 Jan 2025 23:45:34 +0100
Subject: [PATCH 119/233] upgrade actions/upload-artifact and
 actions/download-artifact from v3 to v4

---
 .github/workflows/tag_release.yml | 4 ++--
 CHANGELOG.md                      | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/tag_release.yml b/.github/workflows/tag_release.yml
index 6fd2f0a2..c91930cb 100644
--- a/.github/workflows/tag_release.yml
+++ b/.github/workflows/tag_release.yml
@@ -43,7 +43,7 @@ jobs:
           body: ${{ steps.extract-release-notes.outputs.release_notes }}
       - name: Export plugin Jar files
         id: export_jar_files
-        uses: actions/upload-artifact@v3
+        uses: actions/upload-artifact@v4
         with:
           name: creedengo-plugins
           path: target
@@ -58,7 +58,7 @@ jobs:
     steps:
       - name: Import plugin JAR files
         id: import_jar_files
-        uses: actions/download-artifact@v3
+        uses: actions/download-artifact@v4
         with:
           name: creedengo-plugins
           path: target
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 208ef200..84d77354 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - improve Integration Tests system to be more flexible (add new IT for each rule)
 - [#21](https://github.com/green-code-initiative/creedengo-java/issues/21) Improvement: some method calls are legitimate in a for loop expression
 - check compatibility with SonarQube 10.7.0 and 24.12.0
+- upgrade actions/upload-artifact and actions/download-artifact from v3 to v4)
 
 ### Deleted
 

From 1e6a38713b36ddcf449b6d8b606d66d439627dcf Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Tue, 7 Jan 2025 23:50:01 +0100
Subject: [PATCH 120/233] update CHANGELOG.md for next release

---
 CHANGELOG.md | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 84d77354..3b490662 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Added
 
+### Changed
+
+### Deleted
+
+## [2.1.0] - 2025-01-07
+
+### Added
+
 - [#88](https://github.com/green-code-initiative/creedengo-java/pull/88) Add new Java rule GCI94 - Use orElseGet instead of orElse
 - [#89](https://github.com/green-code-initiative/creedengo-java/pull/89) Add new Java rule GCI82 - Make non reassigned variables constants
 
@@ -20,8 +28,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - check compatibility with SonarQube 10.7.0 and 24.12.0
 - upgrade actions/upload-artifact and actions/download-artifact from v3 to v4)
 
-### Deleted
-
 ## [2.0.0] - 2024-12-18
 
 ### Added
@@ -84,7 +90,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - Update ecocode-rules-specifications to 1.4.6
 
-[unreleased](https://github.com/green-code-initiative/creedengo-java/compare/2.0.0...HEAD)
+[unreleased](https://github.com/green-code-initiative/creedengo-java/compare/2.1.0...HEAD)
+[2.1.0](https://github.com/green-code-initiative/creedengo-java/compare/2.0.0...2.1.0)
 [2.0.0](https://github.com/green-code-initiative/creedengo-java/compare/1.6.2...2.0.0)
 [1.6.2](https://github.com/green-code-initiative/creedengo-java/compare/1.6.1...1.6.2)
 [1.6.1](https://github.com/green-code-initiative/creedengo-java/compare/1.6.0...1.6.1)

From 8920f9ba900c033b1cfc74f4c9c52e8529c95280 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Tue, 7 Jan 2025 23:54:04 +0100
Subject: [PATCH 121/233] update pom.xml for next release

---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 232c3412..04a77182 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
 
     org.green-code-initiative
     creedengo-java-plugin
-    2.0.1-SNAPSHOT
+    2.1.0-SNAPSHOT
 
     sonar-plugin
 

From b88462aa16fbd8bab69cf2f9a04a4f108b63bed0 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Tue, 7 Jan 2025 23:54:58 +0100
Subject: [PATCH 122/233] [maven-release-plugin] prepare release 2.1.0

---
 pom.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 04a77182..0579536f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
 
     org.green-code-initiative
     creedengo-java-plugin
-    2.1.0-SNAPSHOT
+    2.1.0
 
     sonar-plugin
 
@@ -30,7 +30,7 @@
         scm:git:https://github.com/green-code-initiative/creedengo-java
         scm:git:https://github.com/green-code-initiative/creedengo-java
         https://github.com/green-code-initiative/creedengo-java
-        HEAD
+        2.1.0
     
 
     

From d97e2f808cb973b2c6f75267de14a0f7dea3c796 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Tue, 7 Jan 2025 23:54:58 +0100
Subject: [PATCH 123/233] [maven-release-plugin] prepare for next development
 iteration

---
 pom.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 0579536f..a0daed84 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
 
     org.green-code-initiative
     creedengo-java-plugin
-    2.1.0
+    2.1.1-SNAPSHOT
 
     sonar-plugin
 
@@ -30,7 +30,7 @@
         scm:git:https://github.com/green-code-initiative/creedengo-java
         scm:git:https://github.com/green-code-initiative/creedengo-java
         https://github.com/green-code-initiative/creedengo-java
-        2.1.0
+        HEAD
     
 
     

From 26a4c418c37ad4bae76fc9731e2c12c8182381e3 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Fri, 14 Feb 2025 23:28:21 +0100
Subject: [PATCH 124/233] updates for 25.1 and 25.2 compatibility

---
 CHANGELOG.md                                     |  2 ++
 Dockerfile                                       |  5 ++++-
 README.md                                        | 10 +++++-----
 pom.xml                                          | 16 +++++++++++++++-
 .../integration/tests/BuildProjectEngine.java    | 16 ++++++++--------
 .../java/integration/tests/GCIRulesIT.java       |  2 +-
 .../tool_send_to_sonar.sh                        |  4 +++-
 7 files changed, 38 insertions(+), 17 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3b490662..22620e31 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed
 
+- compatibility updates for SonarQube 25.1.0 and 25.2.0 compatibility
+
 ### Deleted
 
 ## [2.1.0] - 2025-01-07
diff --git a/Dockerfile b/Dockerfile
index cf1d0fe9..0128aab2 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,5 +1,8 @@
 ARG MAVEN_BUILDER=3-openjdk-17-slim
-ARG SONARQUBE_VERSION=24.12.0.100206-community
+
+#ARG SONARQUBE_VERSION=24.12.0.100206-community
+#ARG SONARQUBE_VERSION=25.1.0.102122-community
+ARG SONARQUBE_VERSION=25.2.0.102705-community
 
 FROM maven:${MAVEN_BUILDER} AS builder
 
diff --git a/README.md b/README.md
index a51c0bd1..3e3b36e4 100644
--- a/README.md
+++ b/README.md
@@ -57,11 +57,11 @@ 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                                                                                        |
-| 1.7.+          | 9.9.+ LTS to 10.6.0  | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) |
-| 2.0.+          | 9.9.+ LTS to 24.12.0 | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) |
+| Plugin version | SonarQube version   | Java version                                                                                   |
+|----------------|---------------------|------------------------------------------------------------------------------------------------|
+| 1.6.+          | 9.4.+ LTS to 10.6.0 | 11 / 17                                                                                        |
+| 1.7.+          | 9.9.+ LTS to 10.6.0 | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) |
+| 2.0.+          | 9.9.+ LTS to 25.2.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 [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-plugins-version-compatibility).
diff --git a/pom.xml b/pom.xml
index a0daed84..b98bbc3a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -80,7 +80,21 @@
         false
 
         
-        ${sonarqube.version}
+
+
+
+
+
+        
+
+
+
+
+        
+
+
+        25.2.0.102705
+        
 
         
         ${sonarjava.version}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BuildProjectEngine.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BuildProjectEngine.java
index e85b3f00..c9c40f98 100644
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BuildProjectEngine.java
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BuildProjectEngine.java
@@ -269,7 +269,7 @@ protected static Map getMeasures(String componentKey)
 				"blocker_violations",
 				"branch_coverage",
 				"bugs",
-				"class_complexity",
+//				"class_complexity", // suppr en 25.1
 				"classes",
 				"code_smells",
 				"cognitive_complexity",
@@ -277,14 +277,14 @@ protected static Map getMeasures(String componentKey)
 				"comment_lines_data",
 				"comment_lines_density",
 				"complexity",
-				"complexity_in_classes",
-				"complexity_in_functions",
+//				"complexity_in_classes", // suppr en 25.1
+//				"complexity_in_functions", // suppr en 25.1
 				"conditions_to_cover",
 				"confirmed_issues",
 				"coverage",
 				"critical_violations",
 				"development_cost",
-				"directories",
+//				"directories", // suppr en 10.2
 				"duplicated_blocks",
 				"duplicated_files",
 				"duplicated_lines",
@@ -293,11 +293,11 @@ protected static Map getMeasures(String componentKey)
 				"effort_to_reach_maintainability_rating_a",
 				"executable_lines_data",
 				"false_positive_issues",
-				"file_complexity",
-				"file_complexity_distribution",
+//				"file_complexity", // suppr en 25.1
+//				"file_complexity_distribution", // suppr en 25.1
 				"files",
-				"function_complexity",
-				"function_complexity_distribution",
+//				"function_complexity", // suppr en 25.1
+//				"function_complexity_distribution", // suppr en 25.1
 				"functions",
 				"generated_lines",
 				"generated_ncloc",
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
index 671b1462..46eaeb66 100644
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
@@ -40,7 +40,7 @@ void testGCI3() {
                 .hasSize(2)
                 .extracting("rule", "message", "line", "textRange.startLine", "textRange.endLine",
                         "textRange.startOffset", "textRange.endOffset", "severity", "type", "debt", "effort")
-                .containsExactly(
+                .containsExactlyInAnyOrder(
                         Tuple.tuple("creedengo-java:GCI3", "Avoid getting the size of the collection in the loop",
                                 13, 13, 13, 28, 45, MINOR, CODE_SMELL, "5min", "5min"),
                         Tuple.tuple("creedengo-java:GCI69", "Do not call a function when declaring a for-type loop",
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/tool_send_to_sonar.sh b/src/it/test-projects/creedengo-java-plugin-test-project/tool_send_to_sonar.sh
index 4f0175e8..c3309abd 100755
--- a/src/it/test-projects/creedengo-java-plugin-test-project/tool_send_to_sonar.sh
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/tool_send_to_sonar.sh
@@ -1,4 +1,6 @@
 #!/usr/bin/env sh
 
 # "sonar.login" kept only for SONARQUBE < 10
-mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.11.0.3922:sonar -Dsonar.host.url=http://localhost:$1 -Dsonar.login=$2 -Dsonar.token=$2
+
+# mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.11.0.3922:sonar -Dsonar.host.url=http://localhost:$1 -Dsonar.login=$2 -Dsonar.token=$2
+mvn org.sonarsource.scanner.maven:sonar-maven-plugin:4.0.0.4121:sonar -Dsonar.host.url=http://localhost:$1 -Dsonar.login=$2 -Dsonar.token=$2

From 956793184bb423c06d4f27cfb4eafaffd8cffcb9 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Thu, 13 Mar 2025 22:26:37 +0100
Subject: [PATCH 125/233] updates for 25.3.0compatibility

---
 CHANGELOG.md | 2 +-
 Dockerfile   | 3 ++-
 README.md    | 2 +-
 pom.xml      | 3 ++-
 4 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 22620e31..3d45bd0e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed
 
-- compatibility updates for SonarQube 25.1.0 and 25.2.0 compatibility
+- compatibility updates for SonarQube 25.1.0, 25.2.0 and 25.3.0 compatibility
 
 ### Deleted
 
diff --git a/Dockerfile b/Dockerfile
index 0128aab2..e946c289 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,7 +2,8 @@ ARG MAVEN_BUILDER=3-openjdk-17-slim
 
 #ARG SONARQUBE_VERSION=24.12.0.100206-community
 #ARG SONARQUBE_VERSION=25.1.0.102122-community
-ARG SONARQUBE_VERSION=25.2.0.102705-community
+#ARG SONARQUBE_VERSION=25.2.0.102705-community
+ARG SONARQUBE_VERSION=25.3.0.104237-community
 
 FROM maven:${MAVEN_BUILDER} AS builder
 
diff --git a/README.md b/README.md
index 3e3b36e4..7da0e6a4 100644
--- a/README.md
+++ b/README.md
@@ -61,7 +61,7 @@ Ready to use binaries are available [from GitHub](https://github.com/green-code-
 |----------------|---------------------|------------------------------------------------------------------------------------------------|
 | 1.6.+          | 9.4.+ LTS to 10.6.0 | 11 / 17                                                                                        |
 | 1.7.+          | 9.9.+ LTS to 10.6.0 | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) |
-| 2.0.+          | 9.9.+ LTS to 25.2.0 | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) |
+| 2.0.+          | 9.9.+ LTS to 25.3.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 [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-plugins-version-compatibility).
diff --git a/pom.xml b/pom.xml
index b98bbc3a..1e8d5910 100644
--- a/pom.xml
+++ b/pom.xml
@@ -93,7 +93,8 @@
         
 
 
-        25.2.0.102705
+
+        25.3.0.104237
         
 
         

From d0882756db62cbb64d36483de25cf62bbf7ffc8d Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Thu, 13 Mar 2025 22:28:59 +0100
Subject: [PATCH 126/233] upgrade creedengo-rules-specifications lib to 2.2.2

---
 CHANGELOG.md | 1 +
 pom.xml      | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3d45bd0e..4f9ea971 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Changed
 
 - compatibility updates for SonarQube 25.1.0, 25.2.0 and 25.3.0 compatibility
+- upgrade creedengo-rules-specifications lib to 2.2.2
 
 ### Deleted
 
diff --git a/pom.xml b/pom.xml
index 1e8d5910..7f19608e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -72,7 +72,7 @@
         1.7
 
         
-        2.1.0
+        2.2.2
 
         
         https://repo1.maven.org/maven2

From 31c151dfdb0465739ac0b57d9490b1a404b5dd1d Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Thu, 13 Mar 2025 22:36:21 +0100
Subject: [PATCH 127/233] upgrade for next release 2.1.1

---
 CHANGELOG.md | 11 ++++++++---
 README.md    |  2 +-
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4f9ea971..9ebaeb2f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,11 +11,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed
 
+### Deleted
+
+## [2.1.1] - 2025-03-13
+
+### Changed
+
 - compatibility updates for SonarQube 25.1.0, 25.2.0 and 25.3.0 compatibility
 - upgrade creedengo-rules-specifications lib to 2.2.2
 
-### Deleted
-
 ## [2.1.0] - 2025-01-07
 
 ### Added
@@ -93,7 +97,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - Update ecocode-rules-specifications to 1.4.6
 
-[unreleased](https://github.com/green-code-initiative/creedengo-java/compare/2.1.0...HEAD)
+[unreleased](https://github.com/green-code-initiative/creedengo-java/compare/2.1.1...HEAD)
+[2.1.1](https://github.com/green-code-initiative/creedengo-java/compare/2.1.0...2.1.1)
 [2.1.0](https://github.com/green-code-initiative/creedengo-java/compare/2.0.0...2.1.0)
 [2.0.0](https://github.com/green-code-initiative/creedengo-java/compare/1.6.2...2.0.0)
 [1.6.2](https://github.com/green-code-initiative/creedengo-java/compare/1.6.1...1.6.2)
diff --git a/README.md b/README.md
index 7da0e6a4..486327a1 100644
--- a/README.md
+++ b/README.md
@@ -61,7 +61,7 @@ Ready to use binaries are available [from GitHub](https://github.com/green-code-
 |----------------|---------------------|------------------------------------------------------------------------------------------------|
 | 1.6.+          | 9.4.+ LTS to 10.6.0 | 11 / 17                                                                                        |
 | 1.7.+          | 9.9.+ LTS to 10.6.0 | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) |
-| 2.0.+          | 9.9.+ LTS to 25.3.0 | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) |
+| 2.+            | 9.9.+ LTS to 25.3.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 [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-plugins-version-compatibility).

From 7b54a10f0b01d6bfa3d4740d293412faa48d32de Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Thu, 13 Mar 2025 22:37:42 +0100
Subject: [PATCH 128/233] [maven-release-plugin] prepare release 2.1.1

---
 pom.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 7f19608e..7b8b9020 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
 
     org.green-code-initiative
     creedengo-java-plugin
-    2.1.1-SNAPSHOT
+    2.1.1
 
     sonar-plugin
 
@@ -30,7 +30,7 @@
         scm:git:https://github.com/green-code-initiative/creedengo-java
         scm:git:https://github.com/green-code-initiative/creedengo-java
         https://github.com/green-code-initiative/creedengo-java
-        HEAD
+        2.1.1
     
 
     

From e50f547bd1aa286abb21a066e32e0bdd69b81222 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Thu, 13 Mar 2025 22:37:42 +0100
Subject: [PATCH 129/233] [maven-release-plugin] prepare for next development
 iteration

---
 pom.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 7b8b9020..1aebb225 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
 
     org.green-code-initiative
     creedengo-java-plugin
-    2.1.1
+    2.1.2-SNAPSHOT
 
     sonar-plugin
 
@@ -30,7 +30,7 @@
         scm:git:https://github.com/green-code-initiative/creedengo-java
         scm:git:https://github.com/green-code-initiative/creedengo-java
         https://github.com/green-code-initiative/creedengo-java
-        2.1.1
+        HEAD
     
 
     

From 61caa2d0152791bb4a3622448b9958979c23f470 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Thu, 20 Mar 2025 23:54:19 +0100
Subject: [PATCH 130/233] update DockerFile to install public certficates for
 accessing other SonarQube plugins

---
 Dockerfile                | 25 ++++++++++++++++++++++++-
 downloads-sonarsource.crt | 26 ++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 downloads-sonarsource.crt

diff --git a/Dockerfile b/Dockerfile
index e946c289..dd45b67f 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -16,5 +16,28 @@ COPY pom.xml tool_build.sh ./
 RUN ./tool_build.sh
 
 FROM sonarqube:${SONARQUBE_VERSION}
+
 COPY --from=builder /usr/src/creedengo/target/creedengo-*.jar /opt/sonarqube/extensions/plugins/
-USER sonarqube
+
+# Install the ca-certificate package
+USER root
+# RUN apt-get update && apt-get install -y ca-certificates
+# Copy SSL certificates to the container
+COPY downloads-sonarsource.crt /usr/local/share/ca-certificates/
+# Update SSL certificates in system inside the container
+# RUN update-ca-certificates
+
+## Update SSL certificates in the JDK inside the container
+RUN $JAVA_HOME/bin/keytool -import -trustcacerts -file /usr/local/share/ca-certificates/downloads-sonarsource.crt -alias downloads-sonarsource -keystore $JAVA_HOME/lib/security/cacerts -storepass changeit -noprompt
+
+## Process manuel
+# GENERATION CERTIFICAT
+# openssl s_client -showcerts -connect downloads.sonarsource.com:443 /dev/null | openssl x509 > downloads-sonarsource.crt
+# COPIE CERTIFICAT SUR CONTENEUR
+# dk cp downloads-sonarsource.crt sonar_creedengo_java:/tmp/.
+# AJOUT CERTIFICAT DANS LE KEYSTORE (en root)
+# dk exec -u root -it sonar_creedengo_java /bin/bash
+# $JAVA_HOME/bin/keytool -import -trustcacerts -file /tmp/downloads-sonarsource.crt -alias downloads-sonarsource -keystore $JAVA_HOME/lib/security/cacerts -storepass changeit -noprompt
+# RELANCE CONTENEUR pour relancer le service sonarqube
+
+USER sonarqube
\ No newline at end of file
diff --git a/downloads-sonarsource.crt b/downloads-sonarsource.crt
new file mode 100644
index 00000000..01e7ff70
--- /dev/null
+++ b/downloads-sonarsource.crt
@@ -0,0 +1,26 @@
+-----BEGIN CERTIFICATE-----
+MIIEZzCCA0+gAwIBAgIQb93rHKoediFVBatlARo+izANBgkqhkiG9w0BAQsFADCB
+hzELMAkGA1UEBhMCRlIxFjAUBgNVBAgTDUlsZS1kZS1mcmFuY2UxDjAMBgNVBAcT
+BVBhcmlzMRIwEAYDVQQKEwlDYXBnZW1pbmkxFDASBgNVBAsTC0dyb3VwIEluZnJh
+MSYwJAYDVQQDEx16dG56aWEtaW50ZXJuZXQuY2FwZ2VtaW5pLmNvbTAeFw0yNTAz
+MjAxOTUyNDVaFw0yNTA0MDMyMDUyNDVaMFExITAfBgNVBAMTGGJpbmFyaWVzLnNv
+bmFyc291cmNlLmNvbTEVMBMGA1UECgwMWnNjYWxlciBJbmMuMRUwEwYDVQQLDAxa
+c2NhbGVyIEluYy4wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDPn2/p
+TD/pccqvIL7ek6xkyRJz+GV2a5BhZLHBzErFyUE+UyT3h4jxkwHTnSDcFHPynyud
+MxpBdPxpbAAmzp+kqs/kOjMiSoRdgjv4U/Lerypiox+wYns/zvN/9tUuHPSdbRu7
+5BZZw7GotNwN0i8eQy0MZsoy+T5dCFEy2xwKVUqJtg0seiHFrr6jp7RVfLwdAmkE
+Zg1+vPYLB2iDzii3Me1ym71ewcG/Ow+QavNUjOprwJpxLOwfeeX9SYt0KcpW0FXV
+PriGAGLLcko1X8JS1AwlKCNdS6QesX2uGxATHFK1tncj974n+ogHaVdjRP5wGNyx
+p9SnpWN3jFM8l7YpAgMBAAGjggECMIH/MD4GA1UdEQQ3MDWCGGJpbmFyaWVzLnNv
+bmFyc291cmNlLmNvbYIZZG93bmxvYWRzLnNvbmFyc291cmNlLmNvbTAOBgNVHQ8B
+Af8EBAMCBaAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwDAYDVR0TAQH/BAIwADBKBgNV
+HR8EQzBBMD+gPaA7hjlodHRwOi8vZ2F0ZXdheS56c2NhbGVyLm5ldC96c2NhbGVy
+LXpzY3JsLTgxMjQyNTk5LTkxMC5jcmwwHQYDVR0OBBYEFHaP8PqoHXC3EtPdtrNB
+G5mJm2JYMB8GA1UdIwQYMBaAFLD7L1k58j8FcvBXLU2Z4ZbZvg8IMA0GCSqGSIb3
+DQEBCwUAA4IBAQBGHb5Xw5VKtAoJbWY/irUgsXmgtNRioJreF5vX97/lbngJpk1C
+VtMPI0OrF8UHtgZkJuf/aK5NwOshqVHNxQ56Y+qF5ctd379mkvvnGuNVs2t8NpgW
+pOOoRqLH+f4SF2/5bzZkwlMjfxs6h2AJuW3iNNgns7mG8pQ3/chK99+tqwLZ4E+J
+uRVmeCcFHgy2BdvspB7QZE9J8cWjMrkk7q5JH2PTj1ksst5XhdjoS3lI8sbRBlbV
+hkctVQHpKr3ksnHycoboqNHbcAimYtYjsvDi/JV9rIOLnGelttfZtrDB0nCL0p/u
+Ir+1+11jcCSCkqo+cj+kkZshTmduOrU+soBN
+-----END CERTIFICATE-----

From 69eff58984776e15f485c9fe652bd9a71f20bfa1 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Sat, 22 Mar 2025 23:09:43 +0100
Subject: [PATCH 131/233] improve IT : refactor

---
 .../java/integration/tests/GCIRulesIT.java    | 143 +++++++++---------
 1 file changed, 75 insertions(+), 68 deletions(-)

diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
index 46eaeb66..468558ab 100644
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
@@ -2,9 +2,11 @@
 
 import org.assertj.core.groups.Tuple;
 import org.junit.jupiter.api.Test;
+import org.sonarqube.ws.Common;
 import org.sonarqube.ws.Issues;
 import org.sonarqube.ws.Measures;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -15,6 +17,48 @@
 
 class GCIRulesIT extends BuildProjectEngine {
 
+    private static final String[] EXTRACT_FIELDS = new String[]{"rule", "message", "line", "textRange.startLine", "textRange.endLine",
+            "textRange.startOffset", "textRange.endOffset", "severity", "type", "debt", "effort"};
+    private static final Common.Severity SEVERITY = MINOR;
+    private static final Common.RuleType TYPE = CODE_SMELL;
+    private static final String DEBT = "5min";
+    private static final String EFFORT = "5min";
+
+    private void checkIssuesForFile(String filePath, String ruleId, String ruleMsg, int[] lines, int[] startOffsets, int[] endOffsets) {
+        String[] ruleIds = new String[lines.length];
+        String[] ruleMsgs = new String[lines.length];
+        for (int i = 0; i < lines.length; i++) {
+            ruleIds[i] = ruleId;
+            ruleMsgs[i] = ruleMsg;
+        }
+        checkIssuesForFile(filePath, ruleIds, ruleMsgs, lines, startOffsets, endOffsets, SEVERITY, TYPE, DEBT, EFFORT);
+    }
+
+    private void checkIssuesForFile(String filePath, String ruleId, String ruleMsg, int[] lines, int[] startOffsets, int[] endOffsets, Common.Severity severity, Common.RuleType type, String debt, String effort) {
+        String[] ruleIds = new String[lines.length];
+        String[] ruleMsgs = new String[lines.length];
+        for (int i = 0; i < lines.length; i++) {
+            ruleIds[i] = ruleId;
+            ruleMsgs[i] = ruleMsg;
+        }
+        checkIssuesForFile(filePath, ruleIds, ruleMsgs, lines, startOffsets, endOffsets, severity, type, debt, effort);
+    }
+
+    private void checkIssuesForFile(String filePath, String[] ruleIds, String[] ruleMsgs, int[] lines, int[] startOffsets, int[] endOffsets, Common.Severity severity, Common.RuleType type, String debt, String effort) {
+        String projectKey = analyzedProjects.get(0).getProjectKey();
+        List issues = issuesForFile(projectKey, filePath);
+
+        List expectedTuples = new ArrayList<>();
+        for (int i = 0; i < lines.length; i++) {
+            expectedTuples.add(Tuple.tuple(ruleIds[i], ruleMsgs[i], lines[i], lines[i], lines[i], startOffsets[i], endOffsets[i], severity, type, debt, effort));
+        }
+
+        assertThat(issues)
+                .hasSize(lines.length)
+                .extracting(EXTRACT_FIELDS)
+                .containsExactlyElementsOf(expectedTuples);
+    }
+
     @Test
     void testMeasuresAndIssues() {
         String projectKey = analyzedProjects.get(0).getProjectKey();
@@ -31,89 +75,52 @@ void testMeasuresAndIssues() {
 
     @Test
     void testGCI3() {
-        String projectKey = analyzedProjects.get(0).getProjectKey();
 
-        List issues = issuesForFile(projectKey,
-                "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java");
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java";
+        String[] ruleIds = {"creedengo-java:GCI3", "creedengo-java:GCI69"};
+        String[] ruleMsgs = {"Avoid getting the size of the collection in the loop", "Do not call a function when declaring a for-type loop"};
+        int[] lines = new int[]{13, 13};
+        int[] startOffsets = new int[]{28, 28};
+        int[] endOffsets = new int[]{45, 45};
 
-        assertThat(issues)
-                .hasSize(2)
-                .extracting("rule", "message", "line", "textRange.startLine", "textRange.endLine",
-                        "textRange.startOffset", "textRange.endOffset", "severity", "type", "debt", "effort")
-                .containsExactlyInAnyOrder(
-                        Tuple.tuple("creedengo-java:GCI3", "Avoid getting the size of the collection in the loop",
-                                13, 13, 13, 28, 45, MINOR, CODE_SMELL, "5min", "5min"),
-                        Tuple.tuple("creedengo-java:GCI69", "Do not call a function when declaring a for-type loop",
-                                13, 13, 13, 28, 45, MINOR, CODE_SMELL, "5min", "5min")
-                );
+        checkIssuesForFile(filePath, ruleIds, ruleMsgs, lines, startOffsets, endOffsets, MINOR, CODE_SMELL, "5min", "5min");
 
     }
 
     @Test
     void testGCI69() {
-        String projectKey = analyzedProjects.get(0).getProjectKey();
-
-        List issues = issuesForFile(projectKey,
-                "src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java");
-
-        assertThat(issues)
-            .hasSize(4)
-            .extracting("rule", "message", "line", "textRange.startLine", "textRange.endLine",
-                    "textRange.startOffset", "textRange.endOffset", "severity", "type", "debt", "effort")
-            .containsExactly(
-                    Tuple.tuple("creedengo-java:GCI69", "Do not call a function when declaring a for-type loop",
-                            58, 58, 58, 28, 40, MINOR, CODE_SMELL, "5min", "5min"),
-                    Tuple.tuple("creedengo-java:GCI69", "Do not call a function when declaring a for-type loop",
-                            66, 66, 66, 34, 46, MINOR, CODE_SMELL, "5min", "5min"),
-                    Tuple.tuple("creedengo-java:GCI69", "Do not call a function when declaring a for-type loop",
-                            74, 74, 74, 39, 51, MINOR, CODE_SMELL, "5min", "5min"),
-                    Tuple.tuple("creedengo-java:GCI69", "Do not call a function when declaring a for-type loop",
-                            101, 101, 101, 108, 132, MINOR, CODE_SMELL, "5min", "5min")
-            );
-
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java";
+        String ruleId = "creedengo-java:GCI69";
+        String ruleMsg = "Do not call a function when declaring a for-type loop";
+        int[] lines = new int[]{58, 66, 74, 101};
+        int[] startOffsets = new int[]{28, 34, 39, 108};
+        int[] endOffsets = new int[]{40, 46, 51, 132};
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, lines, startOffsets, endOffsets);
     }
 
     @Test
     void testGCI82() {
-        String projectKey = analyzedProjects.get(0).getProjectKey();
-
-        List issues = issuesForFile(projectKey,
-                "src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java");
-
-        assertThat(issues)
-                .hasSize(4)
-                .extracting("rule", "message", "line", "textRange.startLine", "textRange.endLine",
-                        "textRange.startOffset", "textRange.endOffset", "severity", "type", "debt", "effort")
-                .contains(
-                        Tuple.tuple("creedengo-java:GCI82", "The variable is never reassigned and can be 'final'",
-                                7, 7, 7, 4, 67, MINOR, CODE_SMELL, "5min", "5min"),
-                        Tuple.tuple("creedengo-java:GCI82", "The variable is never reassigned and can be 'final'",
-                                12, 12, 12, 4, 56, MINOR, CODE_SMELL, "5min", "5min"),
-                        Tuple.tuple("creedengo-java:GCI82", "The variable is never reassigned and can be 'final'",
-                                13, 13, 13, 4, 50, MINOR, CODE_SMELL, "5min", "5min"),
-                        Tuple.tuple("creedengo-java:GCI82", "The variable is never reassigned and can be 'final'",
-                                45, 45, 45, 8, 25, MINOR, CODE_SMELL, "5min", "5min")
-                );
-
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java";
+        String ruleId = "creedengo-java:GCI82";
+        String ruleMsg = "The variable is never reassigned and can be 'final'";
+        int[] lines = new int[]{7, 12, 13, 45};
+        int[] startOffsets = new int[]{4, 4, 4, 8};
+        int[] endOffsets = new int[]{67, 56, 50, 25};
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, lines, startOffsets, endOffsets);
     }
 
     @Test
     void testGCI94() {
-        String projectKey = analyzedProjects.get(0).getProjectKey();
-
-        List issues = issuesForFile(projectKey,
-                "src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java");
-
-        assertThat(issues)
-                .hasSize(1)
-                .extracting("rule", "message", "line", "textRange.startLine", "textRange.endLine",
-                        "textRange.startOffset", "textRange.endOffset", "severity", "type", "debt", "effort")
-                .containsExactly(
-                        Tuple.tuple(
-                                "creedengo-java:GCI94", "Use optional orElseGet instead of orElse.",
-                                25, 25, 25, 38, 69, MINOR, CODE_SMELL, "1min", "1min")
-                );
-
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java";
+        String ruleId = "creedengo-java:GCI94";
+        String ruleMsg = "Use optional orElseGet instead of orElse.";
+        int[] lines = new int[]{25};
+        int[] startOffsets = new int[]{38};
+        int[] endOffsets = new int[]{69};
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, lines, startOffsets, endOffsets, SEVERITY, TYPE, "1min", "1min");
     }
 
 }

From 27274a62e1c5df8783e5f418c45c47ca1264fe31 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Sun, 23 Mar 2025 23:36:21 +0100
Subject: [PATCH 132/233] improve IT : refactor with paging

---
 .../integration/tests/BuildProjectEngine.java |  30 ++++-
 .../java/integration/tests/GCIRulesIT.java    | 111 ++++++++++--------
 .../creedengo/java/checks/ArrayCopyCheck.java |   1 +
 3 files changed, 89 insertions(+), 53 deletions(-)

diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BuildProjectEngine.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BuildProjectEngine.java
index c9c40f98..f1f83f90 100644
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BuildProjectEngine.java
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BuildProjectEngine.java
@@ -252,15 +252,33 @@ private static Location toPluginLocation(String location) {
 		);
 	}
 
-	protected static List issuesForFile(String projectKey, String file) {
-		return issuesForComponent(projectKey + ":" + file);
+	protected static List issuesForFile(String projectKey, String file, String ruleId) {
+		return issuesForComponent(projectKey + ":" + file, ruleId);
 	}
 
-	protected static List issuesForComponent(String componentKey) {
-		return newWsClient(orchestrator)
+	protected static List issuesForComponent(String componentKey, String ruleId) {
+
+		SearchRequest searchRequest = new SearchRequest()
+				.setComponentKeys(Collections.singletonList(componentKey))
+				.setPs("500"); // nb issues per page returned (default 100)
+
+		if (ruleId != null) {
+			searchRequest.setRules(Collections.singletonList(ruleId)); // only keep issues for this rule
+		}
+
+		Issues.SearchWsResponse resp = newWsClient(orchestrator)
 				.issues()
-				.search(new SearchRequest().setComponentKeys(Collections.singletonList(componentKey)))
-				.getIssuesList();
+				.search(searchRequest);
+
+//		System.out.println("--- NB ISSUES : " + resp.getIssuesCount());
+//		System.out.println("--- NB ISSUES_LIST : " + resp.getIssuesList().size());
+//		resp.getIssuesList().forEach(issue -> {
+////			if (issue.getRule().equals("creedengo-java:GCI27")) {
+//				System.out.println("--- Issue --- " + issue.getRule() + " / " + issue.getLine());
+////			}
+//		});
+
+		return resp.getIssuesList();
 	}
 
 	protected static Map getMeasures(String componentKey) {
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
index 468558ab..1f120a61 100644
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
@@ -17,46 +17,40 @@
 
 class GCIRulesIT extends BuildProjectEngine {
 
-    private static final String[] EXTRACT_FIELDS = new String[]{"rule", "message", "line", "textRange.startLine", "textRange.endLine",
-            "textRange.startOffset", "textRange.endOffset", "severity", "type", "debt", "effort"};
+    private static final String[] EXTRACT_FIELDS = new String[]{
+            "rule", "message",
+//            "line"
+            "textRange.startLine", "textRange.endLine",
+//            "textRange.startOffset", "textRange.endOffset",
+            "severity", "type",
+//            "debt",
+            "effort"
+    };
     private static final Common.Severity SEVERITY = MINOR;
     private static final Common.RuleType TYPE = CODE_SMELL;
-    private static final String DEBT = "5min";
-    private static final String EFFORT = "5min";
-
-    private void checkIssuesForFile(String filePath, String ruleId, String ruleMsg, int[] lines, int[] startOffsets, int[] endOffsets) {
-        String[] ruleIds = new String[lines.length];
-        String[] ruleMsgs = new String[lines.length];
-        for (int i = 0; i < lines.length; i++) {
-            ruleIds[i] = ruleId;
-            ruleMsgs[i] = ruleMsg;
-        }
-        checkIssuesForFile(filePath, ruleIds, ruleMsgs, lines, startOffsets, endOffsets, SEVERITY, TYPE, DEBT, EFFORT);
-    }
+    private static final String EFFORT_1MIN = "1min";
+    private static final String EFFORT_5MIN = "5min";
+    private static final String EFFORT_20MIN = "20min";
 
-    private void checkIssuesForFile(String filePath, String ruleId, String ruleMsg, int[] lines, int[] startOffsets, int[] endOffsets, Common.Severity severity, Common.RuleType type, String debt, String effort) {
-        String[] ruleIds = new String[lines.length];
-        String[] ruleMsgs = new String[lines.length];
-        for (int i = 0; i < lines.length; i++) {
-            ruleIds[i] = ruleId;
-            ruleMsgs[i] = ruleMsg;
-        }
-        checkIssuesForFile(filePath, ruleIds, ruleMsgs, lines, startOffsets, endOffsets, severity, type, debt, effort);
+    private void checkIssuesForFile(String filePath, String ruleId, String ruleMsg, int[] startLines, int[] endLines) {
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_5MIN);
     }
 
-    private void checkIssuesForFile(String filePath, String[] ruleIds, String[] ruleMsgs, int[] lines, int[] startOffsets, int[] endOffsets, Common.Severity severity, Common.RuleType type, String debt, String effort) {
+    private void checkIssuesForFile(String filePath, String ruleId, String ruleMsg, int[] startLines, int[] endLines, Common.Severity severity, Common.RuleType type, String effort) {
         String projectKey = analyzedProjects.get(0).getProjectKey();
-        List issues = issuesForFile(projectKey, filePath);
+        List issues = issuesForFile(projectKey, filePath, ruleId);
 
         List expectedTuples = new ArrayList<>();
-        for (int i = 0; i < lines.length; i++) {
-            expectedTuples.add(Tuple.tuple(ruleIds[i], ruleMsgs[i], lines[i], lines[i], lines[i], startOffsets[i], endOffsets[i], severity, type, debt, effort));
+        for (int i = 0; i < startLines.length; i++) {
+            expectedTuples.add(Tuple.tuple(ruleId, ruleMsg, startLines[i], endLines[i], severity, type, effort));
         }
 
         assertThat(issues)
-                .hasSize(lines.length)
+                .hasSizeGreaterThanOrEqualTo(startLines.length)
+//                .hasSize(lines.length)
                 .extracting(EXTRACT_FIELDS)
-                .containsExactlyElementsOf(expectedTuples);
+                .containsAll(expectedTuples);
+//                .containsExactlyElementsOf(expectedTuples);
     }
 
     @Test
@@ -68,22 +62,48 @@ void testMeasuresAndIssues() {
         assertThat(ofNullable(measures.get("code_smells")).map(Measures.Measure::getValue).map(Integer::parseInt).orElse(0))
                 .isGreaterThan(1);
 
-        List projectIssues = issuesForComponent(projectKey);
+        List projectIssues = issuesForComponent(projectKey, null);
         assertThat(projectIssues).isNotEmpty();
 
     }
 
+    @Test
+    void testGCI27() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java";
+        String ruleId = "creedengo-java:GCI27";
+        String ruleMsg = "Use System.arraycopy to copy arrays";
+        int[] startLines = new int[]{
+                51, 56, 63, 72, 85, 94,
+                105, 116, 139, 145, 153, 163,
+                177, 187, 199, 211, 229, 236,
+                245, 256, 271, 282, 295, 308,
+                334, 341, 350, 361, 376, 389,
+                415, 422, 431, 442, 457, 470
+        };
+        int[] endLines = new int[]{
+                53, 60, 69, 82, 91, 102,
+                113, 124, 141, 149, 159, 173,
+                183, 195, 207, 219, 232, 241,
+                252, 267, 278, 291, 304, 317,
+                337, 346, 357, 372, 385, 398,
+                418, 427, 438, 453, 466, 479
+        };
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
+
+    }
+
     @Test
     void testGCI3() {
 
         String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java";
-        String[] ruleIds = {"creedengo-java:GCI3", "creedengo-java:GCI69"};
-        String[] ruleMsgs = {"Avoid getting the size of the collection in the loop", "Do not call a function when declaring a for-type loop"};
-        int[] lines = new int[]{13, 13};
-        int[] startOffsets = new int[]{28, 28};
-        int[] endOffsets = new int[]{45, 45};
+        int[] startLines = new int[]{13};
+        int[] endLines = new int[]{13};
+        String ruleId = "creedengo-java:GCI3";
+        String ruleMsg = "Avoid getting the size of the collection in the loop";
 
-        checkIssuesForFile(filePath, ruleIds, ruleMsgs, lines, startOffsets, endOffsets, MINOR, CODE_SMELL, "5min", "5min");
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
 
     }
 
@@ -92,11 +112,10 @@ void testGCI69() {
         String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java";
         String ruleId = "creedengo-java:GCI69";
         String ruleMsg = "Do not call a function when declaring a for-type loop";
-        int[] lines = new int[]{58, 66, 74, 101};
-        int[] startOffsets = new int[]{28, 34, 39, 108};
-        int[] endOffsets = new int[]{40, 46, 51, 132};
+        int[] startLines = new int[]{58, 66, 74, 101};
+        int[] endLines = new int[]{58, 66, 74, 101};
 
-        checkIssuesForFile(filePath, ruleId, ruleMsg, lines, startOffsets, endOffsets);
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
     }
 
     @Test
@@ -104,11 +123,10 @@ void testGCI82() {
         String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java";
         String ruleId = "creedengo-java:GCI82";
         String ruleMsg = "The variable is never reassigned and can be 'final'";
-        int[] lines = new int[]{7, 12, 13, 45};
-        int[] startOffsets = new int[]{4, 4, 4, 8};
-        int[] endOffsets = new int[]{67, 56, 50, 25};
+        int[] startLines = new int[]{7, 12, 13, 45};
+        int[] endLines = new int[]{7, 12, 13, 45};
 
-        checkIssuesForFile(filePath, ruleId, ruleMsg, lines, startOffsets, endOffsets);
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
     }
 
     @Test
@@ -116,11 +134,10 @@ void testGCI94() {
         String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java";
         String ruleId = "creedengo-java:GCI94";
         String ruleMsg = "Use optional orElseGet instead of orElse.";
-        int[] lines = new int[]{25};
-        int[] startOffsets = new int[]{38};
-        int[] endOffsets = new int[]{69};
+        int[] startLines = new int[]{25};
+        int[] endLines = new int[]{25};
 
-        checkIssuesForFile(filePath, ruleId, ruleMsg, lines, startOffsets, endOffsets, SEVERITY, TYPE, "1min", "1min");
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_1MIN);
     }
 
 }
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java
index a7dbff89..4a7d153c 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java
@@ -484,6 +484,7 @@ public void copyWithDoWhileLoop() {
             dest[i] = transform(src[i]);
             i++;
         } while (i < len);
+
     }
 
     private boolean transform(boolean a) {

From 27741b0445cb9d4ead9ea52a41f1abd1921f7967 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Sun, 30 Mar 2025 23:19:03 +0200
Subject: [PATCH 133/233] update TI system and create all Integration tests

---
 .../integration/tests/BuildProjectEngine.java |  26 +--
 .../java/integration/tests/GCI1RuleIT.java    |  39 +++++
 .../java/integration/tests/GCI28RuleIT.java   |  87 ++++++++++
 .../java/integration/tests/GCI2RuleIT.java    |  97 +++++++++++
 .../java/integration/tests/GCI3RuleIT.java    |  98 +++++++++++
 .../java/integration/tests/GCI76RuleIT.java   |  29 ++++
 .../java/integration/tests/GCI77RuleIT.java   |  59 +++++++
 .../java/integration/tests/GCIRulesBase.java  |  88 ++++++++++
 .../java/integration/tests/GCIRulesIT.java    | 153 +++++++++++-------
 .../checks/AvoidMultipleIfElseStatement.java  |   2 +-
 ... => AvoidRegexPatternNotStaticValid1.java} |   2 +-
 ... => AvoidRegexPatternNotStaticValid2.java} |   2 +-
 ... => AvoidRegexPatternNotStaticValid3.java} |   4 +-
 .../AvoidSetConstantInBatchUpdateCheck.java   |   2 +-
 ...AvoidUsageOfStaticCollectionsGoodWay.java} |   6 +-
 .../checks/GoodWayConcatenateStringsLoop.java |  33 ----
 ...DCToCheckOptimizeSQLQueriesWithLimit.java} |   2 +-
 .../checks/AvoidSetConstantInBatchUpdate.java |   6 +-
 ... => AvoidRegexPatternNotStaticValid1.java} |   2 +-
 ... => AvoidRegexPatternNotStaticValid2.java} |   2 +-
 ... => AvoidRegexPatternNotStaticValid3.java} |   4 +-
 .../AvoidSetConstantInBatchUpdateCheck.java   |   1 -
 ...AvoidUsageOfStaticCollectionsGoodWay.java} |   6 +-
 .../files/GoodWayConcatenateStringsLoop.java  |  50 ------
 .../AvoidRegexPatternNotStaticTest.java       |   6 +-
 .../AvoidUsageOfStaticCollectionsTests.java   |   2 +-
 26 files changed, 632 insertions(+), 176 deletions(-)
 create mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI1RuleIT.java
 create mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI28RuleIT.java
 create mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI2RuleIT.java
 create mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI3RuleIT.java
 create mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI76RuleIT.java
 create mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI77RuleIT.java
 create mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesBase.java
 rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ValidRegexPattern.java => AvoidRegexPatternNotStaticValid1.java} (84%)
 rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ValidRegexPattern2.java => AvoidRegexPatternNotStaticValid2.java} (83%)
 rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ValidRegexPattern3.java => AvoidRegexPatternNotStaticValid3.java} (73%)
 rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{GoodUsageOfStaticCollections.java => AvoidUsageOfStaticCollectionsGoodWay.java} (60%)
 delete mode 100644 src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GoodWayConcatenateStringsLoop.java
 rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{OptimizeSQLQueriesWithLimit.java => ZzzDDCToCheckOptimizeSQLQueriesWithLimit.java} (95%)
 rename src/test/files/{ValidRegexPattern.java => AvoidRegexPatternNotStaticValid1.java} (95%)
 rename src/test/files/{ValidRegexPattern2.java => AvoidRegexPatternNotStaticValid2.java} (95%)
 rename src/test/files/{ValidRegexPattern3.java => AvoidRegexPatternNotStaticValid3.java} (92%)
 rename src/test/files/{GoodUsageOfStaticCollections.java => AvoidUsageOfStaticCollectionsGoodWay.java} (84%)
 delete mode 100644 src/test/files/GoodWayConcatenateStringsLoop.java

diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BuildProjectEngine.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BuildProjectEngine.java
index f1f83f90..dc1c0c8d 100644
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BuildProjectEngine.java
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BuildProjectEngine.java
@@ -27,11 +27,13 @@
 import org.greencodeinitiative.creedengo.java.integration.tests.profile.ProfileBackup;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
+import org.sonarqube.ws.Components;
 import org.sonarqube.ws.Issues;
 import org.sonarqube.ws.Measures;
 import org.sonarqube.ws.client.HttpConnector;
 import org.sonarqube.ws.client.WsClient;
 import org.sonarqube.ws.client.WsClientFactories;
+import org.sonarqube.ws.client.components.ShowRequest;
 import org.sonarqube.ws.client.issues.SearchRequest;
 import org.sonarqube.ws.client.measures.ComponentRequest;
 
@@ -252,11 +254,11 @@ private static Location toPluginLocation(String location) {
 		);
 	}
 
-	protected static List issuesForFile(String projectKey, String file, String ruleId) {
-		return issuesForComponent(projectKey + ":" + file, ruleId);
+	protected static Issues.SearchWsResponse searchIssuesForFile(String projectKey, String file, String ruleId) {
+		return searchIssuesForComponent(projectKey + ":" + file, ruleId);
 	}
 
-	protected static List issuesForComponent(String componentKey, String ruleId) {
+	protected static Issues.SearchWsResponse searchIssuesForComponent(String componentKey, String ruleId) {
 
 		SearchRequest searchRequest = new SearchRequest()
 				.setComponentKeys(Collections.singletonList(componentKey))
@@ -266,19 +268,19 @@ protected static List issuesForComponent(String componentKey, Stri
 			searchRequest.setRules(Collections.singletonList(ruleId)); // only keep issues for this rule
 		}
 
-		Issues.SearchWsResponse resp = newWsClient(orchestrator)
+		return newWsClient(orchestrator)
 				.issues()
 				.search(searchRequest);
+	}
 
-//		System.out.println("--- NB ISSUES : " + resp.getIssuesCount());
-//		System.out.println("--- NB ISSUES_LIST : " + resp.getIssuesList().size());
-//		resp.getIssuesList().forEach(issue -> {
-////			if (issue.getRule().equals("creedengo-java:GCI27")) {
-//				System.out.println("--- Issue --- " + issue.getRule() + " / " + issue.getLine());
-////			}
-//		});
+	protected static Components.ShowWsResponse showComponent(String componentKey) {
 
-		return resp.getIssuesList();
+		ShowRequest showRequest = new org.sonarqube.ws.client.components.ShowRequest()
+				.setComponent(componentKey);
+
+		return newWsClient(orchestrator)
+				.components()
+				.show(showRequest);
 	}
 
 	protected static Map getMeasures(String componentKey) {
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI1RuleIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI1RuleIT.java
new file mode 100644
index 00000000..19262eda
--- /dev/null
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI1RuleIT.java
@@ -0,0 +1,39 @@
+package org.greencodeinitiative.creedengo.java.integration.tests;
+
+import org.junit.jupiter.api.Test;
+
+class GCI1RuleIT extends GCIRulesBase {
+
+    @Test
+    void testGCI1_loop() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheck.java";
+
+        int[] startLines = new int[]{32};
+
+        int[] endLines = new int[]{32};
+
+        String ruleId = "creedengo-java:GCI1";
+        String ruleMsg = "Avoid Spring repository call in loop or stream";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_50MIN);
+
+    }
+
+    @Test
+    void testGCI1_stream() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheck.java";
+
+        int[] startLines = new int[]{36, 46, 56, 66, 76, 84, 96, 105};
+
+        int[] endLines = new int[]{36, 46, 56, 66, 76, 84, 96, 105};
+
+        String ruleId = "creedengo-java:GCI1";
+        String ruleMsg = "Avoid Spring repository call in loop or stream";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_50MIN);
+
+    }
+
+}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI28RuleIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI28RuleIT.java
new file mode 100644
index 00000000..53203707
--- /dev/null
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI28RuleIT.java
@@ -0,0 +1,87 @@
+package org.greencodeinitiative.creedengo.java.integration.tests;
+
+import org.junit.jupiter.api.Test;
+
+class GCI28RuleIT extends GCIRulesBase {
+
+    @Test
+    void testGCI28() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java";
+
+        int[] startLines = new int[]{23};
+
+        int[] endLines = new int[]{23};
+
+        String ruleId = "creedengo-java:GCI28";
+        String ruleMsg = "Optimize Read File Exceptions";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI28_2() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java";
+
+        int[] startLines = new int[]{20};
+
+        int[] endLines = new int[]{20};
+
+        String ruleId = "creedengo-java:GCI28";
+        String ruleMsg = "Optimize Read File Exceptions";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI28_3() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java";
+
+        int[] startLines = new int[]{19};
+
+        int[] endLines = new int[]{19};
+
+        String ruleId = "creedengo-java:GCI28";
+        String ruleMsg = "Optimize Read File Exceptions";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI28_4() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java";
+
+        int[] startLines = new int[]{18};
+
+        int[] endLines = new int[]{18};
+
+        String ruleId = "creedengo-java:GCI28";
+        String ruleMsg = "Optimize Read File Exceptions";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI28_5() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java";
+
+        int[] startLines = new int[]{18};
+
+        int[] endLines = new int[]{18};
+
+        String ruleId = "creedengo-java:GCI28";
+        String ruleMsg = "Optimize Read File Exceptions";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI2RuleIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI2RuleIT.java
new file mode 100644
index 00000000..d4557cca
--- /dev/null
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI2RuleIT.java
@@ -0,0 +1,97 @@
+package org.greencodeinitiative.creedengo.java.integration.tests;
+
+import org.junit.jupiter.api.Test;
+
+class GCI2RuleIT extends GCIRulesBase {
+
+    @Test
+    void testGCI2() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java";
+
+        int[] startLines = new int[]{
+                24, 43, 45, 71, 88, 110,
+                112, 131, 135, 137, 158, 164,
+                190, 209, 212, 214, 211, 236,
+                257, 259
+        };
+
+        int[] endLines = new int[]{
+                24, 43, 47, 71, 90, 110,
+                114, 133, 135, 139, 160, 166,
+                192, 209, 212, 216, 217, 238,
+                257, 261
+        };
+
+        String ruleId = "creedengo-java:GCI2";
+        String ruleMsg = "Use a switch statement instead of multiple if-else if possible";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI2_compareMethodNoIssue() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java";
+
+        int[] startLines = new int[]{};
+
+        int[] endLines = new int[]{};
+
+        String ruleId = "creedengo-java:GCI2";
+        String ruleMsg = "Use a switch statement instead of multiple if-else if possible";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI2_interfaceNoIssue() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java";
+
+        int[] startLines = new int[]{};
+
+        int[] endLines = new int[]{};
+
+        String ruleId = "creedengo-java:GCI2";
+        String ruleMsg = "Use a switch statement instead of multiple if-else if possible";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI2_noBlockNoIssue() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java";
+
+        int[] startLines = new int[]{};
+
+        int[] endLines = new int[]{};
+
+        String ruleId = "creedengo-java:GCI2";
+        String ruleMsg = "Use a switch statement instead of multiple if-else if possible";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI2_noIssue() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoIssue.java";
+
+        int[] startLines = new int[]{};
+
+        int[] endLines = new int[]{};
+
+        String ruleId = "creedengo-java:GCI2";
+        String ruleMsg = "Use a switch statement instead of multiple if-else if possible";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI3RuleIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI3RuleIT.java
new file mode 100644
index 00000000..95b40a84
--- /dev/null
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI3RuleIT.java
@@ -0,0 +1,98 @@
+package org.greencodeinitiative.creedengo.java.integration.tests;
+
+import org.junit.jupiter.api.Test;
+
+class GCI3RuleIT extends GCIRulesBase {
+
+    @Test
+    void testGCI3_forEachLoopIgnored() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java";
+        int[] startLines = new int[]{};
+        int[] endLines = new int[]{};
+        String ruleId = "creedengo-java:GCI3";
+        String ruleMsg = "Avoid getting the size of the collection in the loop";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI3_forLoopBad() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java";
+        int[] startLines = new int[]{13};
+        int[] endLines = new int[]{13};
+        String ruleId = "creedengo-java:GCI3";
+        String ruleMsg = "Avoid getting the size of the collection in the loop";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI3_forEachLoopGood() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopGood.java";
+        int[] startLines = new int[]{};
+        int[] endLines = new int[]{};
+        String ruleId = "creedengo-java:GCI3";
+        String ruleMsg = "Avoid getting the size of the collection in the loop";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI3_forLoopIgnored() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java";
+        int[] startLines = new int[]{};
+        int[] endLines = new int[]{};
+        String ruleId = "creedengo-java:GCI3";
+        String ruleMsg = "Avoid getting the size of the collection in the loop";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI3_whileLoopBad() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java";
+        int[] startLines = new int[]{17};
+        int[] endLines = new int[]{17};
+        String ruleId = "creedengo-java:GCI3";
+        String ruleMsg = "Avoid getting the size of the collection in the loop";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI3_whileLoopGood() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java";
+        int[] startLines = new int[]{};
+        int[] endLines = new int[]{};
+        String ruleId = "creedengo-java:GCI3";
+        String ruleMsg = "Avoid getting the size of the collection in the loop";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI3_whileLoopIgnored() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java";
+        int[] startLines = new int[]{};
+        int[] endLines = new int[]{};
+        String ruleId = "creedengo-java:GCI3";
+        String ruleMsg = "Avoid getting the size of the collection in the loop";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI76RuleIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI76RuleIT.java
new file mode 100644
index 00000000..f2f9ce30
--- /dev/null
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI76RuleIT.java
@@ -0,0 +1,29 @@
+package org.greencodeinitiative.creedengo.java.integration.tests;
+
+import org.junit.jupiter.api.Test;
+
+class GCI76RuleIT extends GCIRulesBase {
+
+    @Test
+    void testGCI76() {
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java";
+        String ruleId = "creedengo-java:GCI76";
+        String ruleMsg = "Avoid usage of static collections.";
+        int[] startLines = new int[]{10, 12, 14};
+        int[] endLines = new int[]{10, 12, 14};
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
+    }
+
+    @Test
+    void testGCI76_good() {
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsGoodWay.java";
+        String ruleId = "creedengo-java:GCI76";
+        String ruleMsg = "Avoid usage of static collections.";
+        int[] startLines = new int[]{};
+        int[] endLines = new int[]{};
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
+    }
+
+}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI77RuleIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI77RuleIT.java
new file mode 100644
index 00000000..ab8258de
--- /dev/null
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI77RuleIT.java
@@ -0,0 +1,59 @@
+package org.greencodeinitiative.creedengo.java.integration.tests;
+
+import org.junit.jupiter.api.Test;
+
+class GCI77RuleIT extends GCIRulesBase {
+
+    @Test
+    void testGCI77_invalid() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java";
+        int[] startLines = new int[]{8};
+        int[] endLines = new int[]{8};
+        String ruleId = "creedengo-java:GCI77";
+        String ruleMsg = "Avoid using Pattern.compile() in a non-static context.";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
+
+    }
+
+    @Test
+    void testGCI77_valid1() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid1.java";
+        int[] startLines = new int[]{};
+        int[] endLines = new int[]{};
+        String ruleId = "creedengo-java:GCI77";
+        String ruleMsg = "Avoid using Pattern.compile() in a non-static context.";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
+
+    }
+
+    @Test
+    void testGCI77_valid2() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid2.java";
+        int[] startLines = new int[]{};
+        int[] endLines = new int[]{};
+        String ruleId = "creedengo-java:GCI77";
+        String ruleMsg = "Avoid using Pattern.compile() in a non-static context.";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
+
+    }
+
+    @Test
+    void testGCI77_valid3() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid3.java";
+        int[] startLines = new int[]{};
+        int[] endLines = new int[]{};
+        String ruleId = "creedengo-java:GCI77";
+        String ruleMsg = "Avoid using Pattern.compile() in a non-static context.";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
+
+    }
+
+}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesBase.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesBase.java
new file mode 100644
index 00000000..9084cb6b
--- /dev/null
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesBase.java
@@ -0,0 +1,88 @@
+package org.greencodeinitiative.creedengo.java.integration.tests;
+
+import org.assertj.core.groups.Tuple;
+import org.sonarqube.ws.Common;
+import org.sonarqube.ws.Components;
+import org.sonarqube.ws.Issues;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonarqube.ws.Common.RuleType.CODE_SMELL;
+import static org.sonarqube.ws.Common.Severity.MINOR;
+
+class GCIRulesBase extends BuildProjectEngine {
+
+    protected static final String[] EXTRACT_FIELDS = new String[]{
+            "rule", "message",
+//            "line"
+            "textRange.startLine", "textRange.endLine",
+//            "textRange.startOffset", "textRange.endOffset",
+            "severity", "type",
+//            "debt",
+            "effort"
+    };
+    protected static final Common.Severity SEVERITY = MINOR;
+    protected static final Common.RuleType TYPE = CODE_SMELL;
+    protected static final String EFFORT_1MIN = "1min";
+    protected static final String EFFORT_5MIN = "5min";
+    protected static final String EFFORT_10MIN = "10min";
+    protected static final String EFFORT_15MIN = "15min";
+    protected static final String EFFORT_20MIN = "20min";
+    protected static final String EFFORT_50MIN = "50min";
+
+    protected void checkIssuesForFile(String filePath, String ruleId, String ruleMsg, int[] startLines, int[] endLines) {
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_5MIN);
+    }
+
+    protected void checkIssuesForFile(String filePath, String ruleId, String ruleMsg, int[] startLines, int[] endLines, Common.Severity severity, Common.RuleType type, String effort) {
+
+        assertThat(startLines.length)
+                .isEqualTo(endLines.length);
+
+        String projectKey = analyzedProjects.get(0).getProjectKey();
+
+        String componentKey = projectKey + ":" + filePath;
+
+//        System.out.println("--- COMPONENT KEY : " + componentKey);
+
+        // launch the search
+        Components.ShowWsResponse respComponent = showComponent(componentKey);
+        Components.Component comp = respComponent.getComponent();
+//        System.out.println("--- COMPONENT --- " + comp);
+//        System.out.println("--- COMPONENT KEY --- " + comp.getKey());
+//        System.out.println("--- COMPONENT PATH --- " + comp.getPath());
+//        System.out.println("--- PATH ok --- " + filePath.equals(comp.getPath()));
+        assertThat(filePath)
+            .withFailMessage("File not found: " + filePath)
+            .isEqualTo(comp.getPath());
+
+        // check issues
+        Issues.SearchWsResponse respIssues = searchIssuesForComponent(componentKey, ruleId);
+
+//		System.out.println("--- NB ISSUES : " + respIssues.getIssuesCount());
+//		System.out.println("--- NB ISSUES_LIST : " + respIssues.getIssuesList().size());
+//        respIssues.getIssuesList().forEach(issue -> {
+////			if (issue.getRule().equals("creedengo-java:GCI27")) {
+//				System.out.println("--- Issue --- " + issue.getRule() + " / " + issue.getLine());
+////			}
+//		});
+
+//        List issues = issuesForFile(projectKey, filePath, ruleId);
+        List issues = respIssues.getIssuesList();
+
+        List expectedTuples = new ArrayList<>();
+        for (int i = 0; i < startLines.length; i++) {
+            expectedTuples.add(Tuple.tuple(ruleId, ruleMsg, startLines[i], endLines[i], severity, type, effort));
+        }
+
+        assertThat(issues)
+                .hasSizeGreaterThanOrEqualTo(startLines.length)
+//                .hasSize(lines.length)
+                .extracting(EXTRACT_FIELDS)
+                .containsAll(expectedTuples);
+//                .containsExactlyElementsOf(expectedTuples);
+    }
+
+}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
index 1f120a61..54ad4197 100644
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
@@ -1,57 +1,16 @@
 package org.greencodeinitiative.creedengo.java.integration.tests;
 
-import org.assertj.core.groups.Tuple;
 import org.junit.jupiter.api.Test;
-import org.sonarqube.ws.Common;
 import org.sonarqube.ws.Issues;
 import org.sonarqube.ws.Measures;
 
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
 import static java.util.Optional.ofNullable;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonarqube.ws.Common.RuleType.CODE_SMELL;
-import static org.sonarqube.ws.Common.Severity.MINOR;
-
-class GCIRulesIT extends BuildProjectEngine {
-
-    private static final String[] EXTRACT_FIELDS = new String[]{
-            "rule", "message",
-//            "line"
-            "textRange.startLine", "textRange.endLine",
-//            "textRange.startOffset", "textRange.endOffset",
-            "severity", "type",
-//            "debt",
-            "effort"
-    };
-    private static final Common.Severity SEVERITY = MINOR;
-    private static final Common.RuleType TYPE = CODE_SMELL;
-    private static final String EFFORT_1MIN = "1min";
-    private static final String EFFORT_5MIN = "5min";
-    private static final String EFFORT_20MIN = "20min";
-
-    private void checkIssuesForFile(String filePath, String ruleId, String ruleMsg, int[] startLines, int[] endLines) {
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_5MIN);
-    }
 
-    private void checkIssuesForFile(String filePath, String ruleId, String ruleMsg, int[] startLines, int[] endLines, Common.Severity severity, Common.RuleType type, String effort) {
-        String projectKey = analyzedProjects.get(0).getProjectKey();
-        List issues = issuesForFile(projectKey, filePath, ruleId);
-
-        List expectedTuples = new ArrayList<>();
-        for (int i = 0; i < startLines.length; i++) {
-            expectedTuples.add(Tuple.tuple(ruleId, ruleMsg, startLines[i], endLines[i], severity, type, effort));
-        }
-
-        assertThat(issues)
-                .hasSizeGreaterThanOrEqualTo(startLines.length)
-//                .hasSize(lines.length)
-                .extracting(EXTRACT_FIELDS)
-                .containsAll(expectedTuples);
-//                .containsExactlyElementsOf(expectedTuples);
-    }
+class GCIRulesIT extends GCIRulesBase {
 
     @Test
     void testMeasuresAndIssues() {
@@ -62,7 +21,7 @@ void testMeasuresAndIssues() {
         assertThat(ofNullable(measures.get("code_smells")).map(Measures.Measure::getValue).map(Integer::parseInt).orElse(0))
                 .isGreaterThan(1);
 
-        List projectIssues = issuesForComponent(projectKey, null);
+        List projectIssues = searchIssuesForComponent(projectKey, null).getIssuesList();
         assertThat(projectIssues).isNotEmpty();
 
     }
@@ -95,25 +54,96 @@ void testGCI27() {
     }
 
     @Test
-    void testGCI3() {
+    void testGCI74() {
 
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java";
-        int[] startLines = new int[]{13};
-        int[] endLines = new int[]{13};
-        String ruleId = "creedengo-java:GCI3";
-        String ruleMsg = "Avoid getting the size of the collection in the loop";
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheck.java";
+        int[] startLines = new int[]{8, 12, 17, 23};
+        int[] endLines = new int[]{8, 12, 17, 23};
+        String ruleId = "creedengo-java:GCI74";
+        String ruleMsg = "Don't use the query SELECT * FROM";
 
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
 
     }
 
     @Test
-    void testGCI69() {
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java";
-        String ruleId = "creedengo-java:GCI69";
-        String ruleMsg = "Do not call a function when declaring a for-type loop";
-        int[] startLines = new int[]{58, 66, 74, 101};
-        int[] endLines = new int[]{58, 66, 74, 101};
+    void testGCI78() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java";
+        int[] startLines = new int[]{
+                34, 35, 36, 37, 38, 39,
+                40, 41, 42, 43, 44, 45,
+                46, 61, 63, 64, 65, 66,
+                67, 70, 86, 88, 90, 91,
+                92, 93, 94, 96, 114, 116,
+                117, 118, 119, 120, 121, 123
+        };
+        int[] endLines = new int[]{
+                34, 35, 36, 37, 38, 39,
+                40, 41, 42, 43, 44, 45,
+                46, 61, 63, 64, 65, 66,
+                67, 70, 86, 88, 90, 91,
+                92, 93, 94, 96, 114, 116,
+                117, 118, 119, 120, 121, 123
+        };
+        String ruleId = "creedengo-java:GCI78";
+        String ruleMsg = "Avoid setting constants in batch update";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_15MIN);
+
+    }
+
+    @Test
+    void testGCI72() {
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheck.java";
+        String ruleId = "creedengo-java:GCI72";
+        String ruleMsg = "Avoid SQL request in loop";
+        int[] startLines = new int[]{57, 88, 119};
+        int[] endLines = new int[]{57, 88, 119};
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_10MIN);
+    }
+
+    @Test
+    void testGCI5() {
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java";
+        String ruleId = "creedengo-java:GCI5";
+        String ruleMsg = "You must not use Statement for a DML query";
+        int[] startLines = new int[]{18};
+        int[] endLines = new int[]{18};
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_10MIN);
+    }
+
+    @Test
+    void testGCI79() {
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java";
+        String ruleId = "creedengo-java:GCI79";
+        String ruleMsg = "try-with-resources Statement needs to be implemented for any object that implements the AutoClosable interface.";
+        int[] startLines = new int[]{23};
+        int[] endLines = new int[]{36};
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_15MIN);
+    }
+
+    @Test
+    void testGCI32() {
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java";
+        String ruleId = "creedengo-java:GCI32";
+        String ruleMsg = "Initialize StringBuilder or StringBuffer with appropriate size";
+        int[] startLines = new int[]{16, 24};
+        int[] endLines = new int[]{16, 24};
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+    }
+
+    @Test
+    void testGCI67() {
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java";
+        String ruleId = "creedengo-java:GCI67";
+        String ruleMsg = "Use ++i instead of i++";
+        int[] startLines = new int[]{9, 19, 38};
+        int[] endLines = new int[]{9, 19, 38};
 
         checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
     }
@@ -129,6 +159,17 @@ void testGCI82() {
         checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
     }
 
+    @Test
+    void testGCI69() {
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java";
+        String ruleId = "creedengo-java:GCI69";
+        String ruleMsg = "Do not call a function when declaring a for-type loop";
+        int[] startLines = new int[]{58, 66, 74, 101};
+        int[] endLines = new int[]{58, 66, 74, 101};
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+    }
+
     @Test
     void testGCI94() {
         String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java";
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java
index 23ad4ccf..3e4ee746 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java
@@ -109,7 +109,7 @@ public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseSta
         } else {
             if (nb1 == 2) {  // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
                 nb1 = 1;
-            } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
+            } else {
                 nb1 = 3;
             } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}}
         }
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ValidRegexPattern.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid1.java
similarity index 84%
rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ValidRegexPattern.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid1.java
index 9943c20d..29ff6bbe 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ValidRegexPattern.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid1.java
@@ -2,7 +2,7 @@
 
 import java.util.regex.Pattern;
 
-public class ValidRegexPattern {
+public class AvoidRegexPatternNotStaticValid1 {
 
     private static final Pattern pattern = Pattern.compile("foo"); // Compliant
 
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ValidRegexPattern2.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid2.java
similarity index 83%
rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ValidRegexPattern2.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid2.java
index 3ceb82a5..b238d4c2 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ValidRegexPattern2.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid2.java
@@ -2,7 +2,7 @@
 
 import java.util.regex.Pattern;
 
-public class ValidRegexPattern2 {
+public class AvoidRegexPatternNotStaticValid2 {
 
     private final Pattern pattern = Pattern.compile("foo"); // Compliant
 
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ValidRegexPattern3.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid3.java
similarity index 73%
rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ValidRegexPattern3.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid3.java
index a9b64c2b..0e748b13 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ValidRegexPattern3.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid3.java
@@ -2,11 +2,11 @@
 
 import java.util.regex.Pattern;
 
-public class ValidRegexPattern3 {
+public class AvoidRegexPatternNotStaticValid3 {
 
     private final Pattern pattern;
 
-    public ValidRegexPattern3() {
+    public AvoidRegexPatternNotStaticValid3() {
         pattern = Pattern.compile("foo"); // Compliant
     }
 
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java
index 30654d98..342f6588 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java
@@ -86,7 +86,7 @@ int[] batchInsertInWhileLoop2(DummyClass[] data) throws SQLException {
                 stmt.setBoolean(2, Boolean.TRUE); // Noncompliant {{Avoid setting constants in batch update}}
                 stmt.setByte(3, o.getField3());
                 stmt.setByte(4, Byte.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}}
-                stmt.setByte(4, (byte) Character.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}}
+//                stmt.setByte(4, Character.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}}
                 stmt.setShort(5, Short.MIN_VALUE); // Noncompliant {{Avoid setting constants in batch update}}
                 stmt.setInt(6, Integer.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}}
                 stmt.setLong(7, Long.MIN_VALUE); // Noncompliant {{Avoid setting constants in batch update}}
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GoodUsageOfStaticCollections.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsGoodWay.java
similarity index 60%
rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GoodUsageOfStaticCollections.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsGoodWay.java
index ebe2f8bc..bf6d3e06 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GoodUsageOfStaticCollections.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsGoodWay.java
@@ -5,13 +5,13 @@
 /**
  * Compliant
  */
-public class GoodUsageOfStaticCollections {
-    public static volatile GoodUsageOfStaticCollections INSTANCE = new GoodUsageOfStaticCollections();
+public class AvoidUsageOfStaticCollectionsGoodWay {
+    public static volatile AvoidUsageOfStaticCollectionsGoodWay INSTANCE = new AvoidUsageOfStaticCollectionsGoodWay();
 
     public final List LIST = new ArrayList(); // Compliant
     public final Set SET = new HashSet(); // Compliant
     public final Map MAP = new HashMap(); // Compliant
 
-    private GoodUsageOfStaticCollections() {
+    private AvoidUsageOfStaticCollectionsGoodWay() {
     }
 }
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GoodWayConcatenateStringsLoop.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GoodWayConcatenateStringsLoop.java
deleted file mode 100644
index 605a67c8..00000000
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GoodWayConcatenateStringsLoop.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package org.greencodeinitiative.creedengo.java.checks;
-
-public class GoodWayConcatenateStringsLoop {
-
-    public String concatenateStrings(String[] strings) {
-        StringBuilder result = new StringBuilder();
-
-        for (String string : strings) {
-            result.append(string);
-        }
-        return result.toString();
-    }
-
-    public void testConcateOutOfLoop() {
-        String result = "";
-        result += "another";
-    }
-
-    public void testConcateOutOfLoop2() {
-        String result = "";
-        result = result + "another";
-    }
-
-    public String changeValueStringInLoop() {
-        String result3 = "";
-
-        for (int i = 0; i < 1; ++i) {
-            result3 = "another";
-        }
-        return result3;
-    }
-
-}
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeSQLQueriesWithLimit.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ZzzDDCToCheckOptimizeSQLQueriesWithLimit.java
similarity index 95%
rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeSQLQueriesWithLimit.java
rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ZzzDDCToCheckOptimizeSQLQueriesWithLimit.java
index e592528d..f90c2cb4 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeSQLQueriesWithLimit.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ZzzDDCToCheckOptimizeSQLQueriesWithLimit.java
@@ -5,7 +5,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-class OptimizeSQLQueriesWithLimit {
+class ZzzDDCToCheckOptimizeSQLQueriesWithLimit {
 
     public void literalSQLrequest() {
         dummyCall("SELECT user FROM myTable"); // Noncompliant {{Optimize Database SQL Queries (Clause LIMIT)}}
diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdate.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdate.java
index 20c3e23e..76f9ed51 100644
--- a/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdate.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdate.java
@@ -44,7 +44,7 @@
 @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S78")
 public class AvoidSetConstantInBatchUpdate extends IssuableSubscriptionVisitor {
 
-    protected static final String MESSAGERULE = "Avoid setting constants in batch update";
+    protected static final String MESSAGE_RULE = "Avoid setting constants in batch update";
     private final AvoidSetConstantInBatchUpdateVisitor visitorInFile = new AvoidSetConstantInBatchUpdateVisitor();
 
     @Override
@@ -71,14 +71,14 @@ private class AvoidSetConstantInBatchUpdateVisitor extends BaseTreeVisitor {
         @Override
         public void visitMethodInvocation(MethodInvocationTree tree) {
             if (setters.matches(tree) && isConstant(tree.arguments().get(1))) {
-                reportIssue(tree, MESSAGERULE);
+                reportIssue(tree, MESSAGE_RULE);
             } else {
                 super.visitMethodInvocation(tree);
             }
         }
     }
 
-    private static final boolean isConstant(Tree arg) {
+    private static boolean isConstant(Tree arg) {
 
         if (arg.is(METHOD_INVOCATION)) {
             MethodInvocationTree m = (MethodInvocationTree) arg;
diff --git a/src/test/files/ValidRegexPattern.java b/src/test/files/AvoidRegexPatternNotStaticValid1.java
similarity index 95%
rename from src/test/files/ValidRegexPattern.java
rename to src/test/files/AvoidRegexPatternNotStaticValid1.java
index c52eb0e1..638ffd96 100644
--- a/src/test/files/ValidRegexPattern.java
+++ b/src/test/files/AvoidRegexPatternNotStaticValid1.java
@@ -19,7 +19,7 @@
 
 import java.util.regex.Pattern;
 
-public class ValidRegexPattern {
+public class AvoidRegexPatternNotStaticValid1 {
 
     private static final Pattern pattern = Pattern.compile("foo"); // Compliant
 
diff --git a/src/test/files/ValidRegexPattern2.java b/src/test/files/AvoidRegexPatternNotStaticValid2.java
similarity index 95%
rename from src/test/files/ValidRegexPattern2.java
rename to src/test/files/AvoidRegexPatternNotStaticValid2.java
index 4c2c0e02..0ef9517c 100644
--- a/src/test/files/ValidRegexPattern2.java
+++ b/src/test/files/AvoidRegexPatternNotStaticValid2.java
@@ -19,7 +19,7 @@
 
 import java.util.regex.Pattern;
 
-public class ValidRegexPattern2 {
+public class AvoidRegexPatternNotStaticValid2 {
 
     private final Pattern pattern = Pattern.compile("foo"); // Compliant
 
diff --git a/src/test/files/ValidRegexPattern3.java b/src/test/files/AvoidRegexPatternNotStaticValid3.java
similarity index 92%
rename from src/test/files/ValidRegexPattern3.java
rename to src/test/files/AvoidRegexPatternNotStaticValid3.java
index 8cf41661..f1378974 100644
--- a/src/test/files/ValidRegexPattern3.java
+++ b/src/test/files/AvoidRegexPatternNotStaticValid3.java
@@ -19,11 +19,11 @@
 
 import java.util.regex.Pattern;
 
-public class ValidRegexPattern3 {
+public class AvoidRegexPatternNotStaticValid3 {
 
     private final Pattern pattern;
 
-    public ValidRegexPattern3() {
+    public AvoidRegexPatternNotStaticValid3() {
         pattern = Pattern.compile("foo"); // Compliant
     }
 
diff --git a/src/test/files/AvoidSetConstantInBatchUpdateCheck.java b/src/test/files/AvoidSetConstantInBatchUpdateCheck.java
index 6e4ecf41..d7b8013b 100644
--- a/src/test/files/AvoidSetConstantInBatchUpdateCheck.java
+++ b/src/test/files/AvoidSetConstantInBatchUpdateCheck.java
@@ -102,7 +102,6 @@ int[] batchInsertInWhileLoop(DummyClass[] data) {
                 stmt.setBoolean(2, Boolean.TRUE); // Noncompliant {{Avoid setting constants in batch update}}
                 stmt.setByte(3, o.getField3());
                 stmt.setByte(4, Byte.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}}
-                stmt.setByte(4, Character.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}}
                 stmt.setShort(5, Short.MIN_VALUE); // Noncompliant {{Avoid setting constants in batch update}}
                 stmt.setInt(6, Integer.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}}
                 stmt.setLong(7, Long.MIN_VALUE); // Noncompliant {{Avoid setting constants in batch update}}
diff --git a/src/test/files/GoodUsageOfStaticCollections.java b/src/test/files/AvoidUsageOfStaticCollectionsGoodWay.java
similarity index 84%
rename from src/test/files/GoodUsageOfStaticCollections.java
rename to src/test/files/AvoidUsageOfStaticCollectionsGoodWay.java
index 9da5eae2..e7a60938 100644
--- a/src/test/files/GoodUsageOfStaticCollections.java
+++ b/src/test/files/AvoidUsageOfStaticCollectionsGoodWay.java
@@ -22,13 +22,13 @@
 /**
  * Compliant
  */
-public class GoodUsageOfStaticCollections {
-    public static volatile GoodUsageOfStaticCollections INSTANCE = new GoodUsageOfStaticCollections();
+public class AvoidUsageOfStaticCollectionsGoodWay {
+    public static volatile AvoidUsageOfStaticCollectionsGoodWay INSTANCE = new AvoidUsageOfStaticCollectionsGoodWay();
 
     public final List LIST = new ArrayList(); // Compliant
     public final Set SET = new HashSet(); // Compliant
     public final Map MAP = new HashMap(); // Compliant
 
-    private GoodUsageOfStaticCollections() {
+    private AvoidUsageOfStaticCollectionsGoodWay() {
     }
 }
diff --git a/src/test/files/GoodWayConcatenateStringsLoop.java b/src/test/files/GoodWayConcatenateStringsLoop.java
deleted file mode 100644
index a082875e..00000000
--- a/src/test/files/GoodWayConcatenateStringsLoop.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs
- * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package org.greencodeinitiative.creedengo.java.utils;
-
-public class GoodWayConcatenateStringsLoop {
-
-    public String concatenateStrings(String[] strings) {
-        StringBuilder result = new StringBuilder();
-
-        for (String string : strings) {
-            result.append(string);
-        }
-        return result.toString();
-    }
-
-    public void testConcateOutOfLoop() {
-        String result = "";
-        result += "another";
-    }
-
-    public void testConcateOutOfLoop2() {
-        String result = "";
-        result = result + "another";
-    }
-
-    public String changeValueStringInLoop() {
-        String result3 = "";
-
-        for (int i = 0; i < 1; ++i) {
-            result3 = "another";
-        }
-        return result3;
-    }
-
-}
diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticTest.java
index 874b03b2..c654160c 100644
--- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticTest.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticTest.java
@@ -34,9 +34,9 @@ void testHasIssues() {
     void testHasNoIssues() {
         CheckVerifier.newVerifier()
                 .onFiles(
-                        "src/test/files/ValidRegexPattern.java",
-                        "src/test/files/ValidRegexPattern2.java",
-                        "src/test/files/ValidRegexPattern3.java"
+                        "src/test/files/AvoidRegexPatternNotStaticValid1.java",
+                        "src/test/files/AvoidRegexPatternNotStaticValid2.java",
+                        "src/test/files/AvoidRegexPatternNotStaticValid3.java"
                 )
                 .withCheck(new AvoidRegexPatternNotStatic())
                 .verifyNoIssues();
diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsTests.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsTests.java
index 876525f2..6512a044 100644
--- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsTests.java
+++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsTests.java
@@ -33,7 +33,7 @@ void testHasIssues() {
     @Test
     void testNoIssues() {
         CheckVerifier.newVerifier()
-                .onFile("src/test/files/GoodUsageOfStaticCollections.java")
+                .onFile("src/test/files/AvoidUsageOfStaticCollectionsGoodWay.java")
                 .withCheck(new AvoidUsageOfStaticCollections())
                 .verifyNoIssues();
     }

From e00f19c8928baf3a33f940714afd2625f1c1ddd5 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Fri, 11 Apr 2025 19:43:04 +0200
Subject: [PATCH 134/233] log dependency correction

---
 pom.xml | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/pom.xml b/pom.xml
index 1aebb225..3274401b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -140,6 +140,14 @@
             ${google.re2j}
         
 
+        
+            org.slf4j
+            slf4j-api
+            2.0.17
+            
+            provided
+        
+
         
         
             org.sonarsource.java
@@ -201,12 +209,6 @@
             0.0.1
             test
         
-        
-            org.slf4j
-            slf4j-api
-            2.0.13
-            test
-        
         
             ch.qos.logback
             logback-classic

From 77b907c0e39c728046013f0b28ed225ce96a83d3 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Fri, 11 Apr 2025 19:51:25 +0200
Subject: [PATCH 135/233] optimize integration tests

---
 .../java/integration/tests/GCI1RuleIT.java    |  39 --
 .../java/integration/tests/GCI28RuleIT.java   |  87 -----
 .../java/integration/tests/GCI2RuleIT.java    |  97 -----
 .../java/integration/tests/GCI3RuleIT.java    |  98 -----
 .../java/integration/tests/GCI76RuleIT.java   |  29 --
 .../java/integration/tests/GCI77RuleIT.java   |  59 ---
 .../java/integration/tests/GCIRulesIT.java    | 367 ++++++++++++++++++
 7 files changed, 367 insertions(+), 409 deletions(-)
 delete mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI1RuleIT.java
 delete mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI28RuleIT.java
 delete mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI2RuleIT.java
 delete mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI3RuleIT.java
 delete mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI76RuleIT.java
 delete mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI77RuleIT.java

diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI1RuleIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI1RuleIT.java
deleted file mode 100644
index 19262eda..00000000
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI1RuleIT.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package org.greencodeinitiative.creedengo.java.integration.tests;
-
-import org.junit.jupiter.api.Test;
-
-class GCI1RuleIT extends GCIRulesBase {
-
-    @Test
-    void testGCI1_loop() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheck.java";
-
-        int[] startLines = new int[]{32};
-
-        int[] endLines = new int[]{32};
-
-        String ruleId = "creedengo-java:GCI1";
-        String ruleMsg = "Avoid Spring repository call in loop or stream";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_50MIN);
-
-    }
-
-    @Test
-    void testGCI1_stream() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheck.java";
-
-        int[] startLines = new int[]{36, 46, 56, 66, 76, 84, 96, 105};
-
-        int[] endLines = new int[]{36, 46, 56, 66, 76, 84, 96, 105};
-
-        String ruleId = "creedengo-java:GCI1";
-        String ruleMsg = "Avoid Spring repository call in loop or stream";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_50MIN);
-
-    }
-
-}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI28RuleIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI28RuleIT.java
deleted file mode 100644
index 53203707..00000000
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI28RuleIT.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package org.greencodeinitiative.creedengo.java.integration.tests;
-
-import org.junit.jupiter.api.Test;
-
-class GCI28RuleIT extends GCIRulesBase {
-
-    @Test
-    void testGCI28() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java";
-
-        int[] startLines = new int[]{23};
-
-        int[] endLines = new int[]{23};
-
-        String ruleId = "creedengo-java:GCI28";
-        String ruleMsg = "Optimize Read File Exceptions";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
-
-    }
-
-    @Test
-    void testGCI28_2() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java";
-
-        int[] startLines = new int[]{20};
-
-        int[] endLines = new int[]{20};
-
-        String ruleId = "creedengo-java:GCI28";
-        String ruleMsg = "Optimize Read File Exceptions";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
-
-    }
-
-    @Test
-    void testGCI28_3() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java";
-
-        int[] startLines = new int[]{19};
-
-        int[] endLines = new int[]{19};
-
-        String ruleId = "creedengo-java:GCI28";
-        String ruleMsg = "Optimize Read File Exceptions";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
-
-    }
-
-    @Test
-    void testGCI28_4() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java";
-
-        int[] startLines = new int[]{18};
-
-        int[] endLines = new int[]{18};
-
-        String ruleId = "creedengo-java:GCI28";
-        String ruleMsg = "Optimize Read File Exceptions";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
-
-    }
-
-    @Test
-    void testGCI28_5() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java";
-
-        int[] startLines = new int[]{18};
-
-        int[] endLines = new int[]{18};
-
-        String ruleId = "creedengo-java:GCI28";
-        String ruleMsg = "Optimize Read File Exceptions";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
-
-    }
-
-}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI2RuleIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI2RuleIT.java
deleted file mode 100644
index d4557cca..00000000
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI2RuleIT.java
+++ /dev/null
@@ -1,97 +0,0 @@
-package org.greencodeinitiative.creedengo.java.integration.tests;
-
-import org.junit.jupiter.api.Test;
-
-class GCI2RuleIT extends GCIRulesBase {
-
-    @Test
-    void testGCI2() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java";
-
-        int[] startLines = new int[]{
-                24, 43, 45, 71, 88, 110,
-                112, 131, 135, 137, 158, 164,
-                190, 209, 212, 214, 211, 236,
-                257, 259
-        };
-
-        int[] endLines = new int[]{
-                24, 43, 47, 71, 90, 110,
-                114, 133, 135, 139, 160, 166,
-                192, 209, 212, 216, 217, 238,
-                257, 261
-        };
-
-        String ruleId = "creedengo-java:GCI2";
-        String ruleMsg = "Use a switch statement instead of multiple if-else if possible";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
-
-    }
-
-    @Test
-    void testGCI2_compareMethodNoIssue() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java";
-
-        int[] startLines = new int[]{};
-
-        int[] endLines = new int[]{};
-
-        String ruleId = "creedengo-java:GCI2";
-        String ruleMsg = "Use a switch statement instead of multiple if-else if possible";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
-
-    }
-
-    @Test
-    void testGCI2_interfaceNoIssue() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java";
-
-        int[] startLines = new int[]{};
-
-        int[] endLines = new int[]{};
-
-        String ruleId = "creedengo-java:GCI2";
-        String ruleMsg = "Use a switch statement instead of multiple if-else if possible";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
-
-    }
-
-    @Test
-    void testGCI2_noBlockNoIssue() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java";
-
-        int[] startLines = new int[]{};
-
-        int[] endLines = new int[]{};
-
-        String ruleId = "creedengo-java:GCI2";
-        String ruleMsg = "Use a switch statement instead of multiple if-else if possible";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
-
-    }
-
-    @Test
-    void testGCI2_noIssue() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoIssue.java";
-
-        int[] startLines = new int[]{};
-
-        int[] endLines = new int[]{};
-
-        String ruleId = "creedengo-java:GCI2";
-        String ruleMsg = "Use a switch statement instead of multiple if-else if possible";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
-
-    }
-
-}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI3RuleIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI3RuleIT.java
deleted file mode 100644
index 95b40a84..00000000
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI3RuleIT.java
+++ /dev/null
@@ -1,98 +0,0 @@
-package org.greencodeinitiative.creedengo.java.integration.tests;
-
-import org.junit.jupiter.api.Test;
-
-class GCI3RuleIT extends GCIRulesBase {
-
-    @Test
-    void testGCI3_forEachLoopIgnored() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java";
-        int[] startLines = new int[]{};
-        int[] endLines = new int[]{};
-        String ruleId = "creedengo-java:GCI3";
-        String ruleMsg = "Avoid getting the size of the collection in the loop";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
-
-    }
-
-    @Test
-    void testGCI3_forLoopBad() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java";
-        int[] startLines = new int[]{13};
-        int[] endLines = new int[]{13};
-        String ruleId = "creedengo-java:GCI3";
-        String ruleMsg = "Avoid getting the size of the collection in the loop";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
-
-    }
-
-    @Test
-    void testGCI3_forEachLoopGood() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopGood.java";
-        int[] startLines = new int[]{};
-        int[] endLines = new int[]{};
-        String ruleId = "creedengo-java:GCI3";
-        String ruleMsg = "Avoid getting the size of the collection in the loop";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
-
-    }
-
-    @Test
-    void testGCI3_forLoopIgnored() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java";
-        int[] startLines = new int[]{};
-        int[] endLines = new int[]{};
-        String ruleId = "creedengo-java:GCI3";
-        String ruleMsg = "Avoid getting the size of the collection in the loop";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
-
-    }
-
-    @Test
-    void testGCI3_whileLoopBad() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java";
-        int[] startLines = new int[]{17};
-        int[] endLines = new int[]{17};
-        String ruleId = "creedengo-java:GCI3";
-        String ruleMsg = "Avoid getting the size of the collection in the loop";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
-
-    }
-
-    @Test
-    void testGCI3_whileLoopGood() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java";
-        int[] startLines = new int[]{};
-        int[] endLines = new int[]{};
-        String ruleId = "creedengo-java:GCI3";
-        String ruleMsg = "Avoid getting the size of the collection in the loop";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
-
-    }
-
-    @Test
-    void testGCI3_whileLoopIgnored() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java";
-        int[] startLines = new int[]{};
-        int[] endLines = new int[]{};
-        String ruleId = "creedengo-java:GCI3";
-        String ruleMsg = "Avoid getting the size of the collection in the loop";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
-
-    }
-
-}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI76RuleIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI76RuleIT.java
deleted file mode 100644
index f2f9ce30..00000000
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI76RuleIT.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.greencodeinitiative.creedengo.java.integration.tests;
-
-import org.junit.jupiter.api.Test;
-
-class GCI76RuleIT extends GCIRulesBase {
-
-    @Test
-    void testGCI76() {
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java";
-        String ruleId = "creedengo-java:GCI76";
-        String ruleMsg = "Avoid usage of static collections.";
-        int[] startLines = new int[]{10, 12, 14};
-        int[] endLines = new int[]{10, 12, 14};
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
-    }
-
-    @Test
-    void testGCI76_good() {
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsGoodWay.java";
-        String ruleId = "creedengo-java:GCI76";
-        String ruleMsg = "Avoid usage of static collections.";
-        int[] startLines = new int[]{};
-        int[] endLines = new int[]{};
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
-    }
-
-}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI77RuleIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI77RuleIT.java
deleted file mode 100644
index ab8258de..00000000
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCI77RuleIT.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package org.greencodeinitiative.creedengo.java.integration.tests;
-
-import org.junit.jupiter.api.Test;
-
-class GCI77RuleIT extends GCIRulesBase {
-
-    @Test
-    void testGCI77_invalid() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java";
-        int[] startLines = new int[]{8};
-        int[] endLines = new int[]{8};
-        String ruleId = "creedengo-java:GCI77";
-        String ruleMsg = "Avoid using Pattern.compile() in a non-static context.";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
-
-    }
-
-    @Test
-    void testGCI77_valid1() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid1.java";
-        int[] startLines = new int[]{};
-        int[] endLines = new int[]{};
-        String ruleId = "creedengo-java:GCI77";
-        String ruleMsg = "Avoid using Pattern.compile() in a non-static context.";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
-
-    }
-
-    @Test
-    void testGCI77_valid2() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid2.java";
-        int[] startLines = new int[]{};
-        int[] endLines = new int[]{};
-        String ruleId = "creedengo-java:GCI77";
-        String ruleMsg = "Avoid using Pattern.compile() in a non-static context.";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
-
-    }
-
-    @Test
-    void testGCI77_valid3() {
-
-        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid3.java";
-        int[] startLines = new int[]{};
-        int[] endLines = new int[]{};
-        String ruleId = "creedengo-java:GCI77";
-        String ruleMsg = "Avoid using Pattern.compile() in a non-static context.";
-
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
-
-    }
-
-}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
index 54ad4197..dfd7957c 100644
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
@@ -66,6 +66,239 @@ void testGCI74() {
 
     }
 
+    @Test
+    void testGCI3_forEachLoopIgnored() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java";
+        int[] startLines = new int[]{};
+        int[] endLines = new int[]{};
+        String ruleId = "creedengo-java:GCI3";
+        String ruleMsg = "Avoid getting the size of the collection in the loop";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI3_forLoopBad() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java";
+        int[] startLines = new int[]{13};
+        int[] endLines = new int[]{13};
+        String ruleId = "creedengo-java:GCI3";
+        String ruleMsg = "Avoid getting the size of the collection in the loop";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI3_forEachLoopGood() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopGood.java";
+        int[] startLines = new int[]{};
+        int[] endLines = new int[]{};
+        String ruleId = "creedengo-java:GCI3";
+        String ruleMsg = "Avoid getting the size of the collection in the loop";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI3_forLoopIgnored() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java";
+        int[] startLines = new int[]{};
+        int[] endLines = new int[]{};
+        String ruleId = "creedengo-java:GCI3";
+        String ruleMsg = "Avoid getting the size of the collection in the loop";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI3_whileLoopBad() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java";
+        int[] startLines = new int[]{17};
+        int[] endLines = new int[]{17};
+        String ruleId = "creedengo-java:GCI3";
+        String ruleMsg = "Avoid getting the size of the collection in the loop";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI3_whileLoopGood() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java";
+        int[] startLines = new int[]{};
+        int[] endLines = new int[]{};
+        String ruleId = "creedengo-java:GCI3";
+        String ruleMsg = "Avoid getting the size of the collection in the loop";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI3_whileLoopIgnored() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java";
+        int[] startLines = new int[]{};
+        int[] endLines = new int[]{};
+        String ruleId = "creedengo-java:GCI3";
+        String ruleMsg = "Avoid getting the size of the collection in the loop";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI2() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java";
+
+        int[] startLines = new int[]{
+                24, 43, 45, 71, 88, 110,
+                112, 131, 135, 137, 158, 164,
+                190, 209, 212, 214, 211, 236,
+                257, 259
+        };
+
+        int[] endLines = new int[]{
+                24, 43, 47, 71, 90, 110,
+                114, 133, 135, 139, 160, 166,
+                192, 209, 212, 216, 217, 238,
+                257, 261
+        };
+
+        String ruleId = "creedengo-java:GCI2";
+        String ruleMsg = "Use a switch statement instead of multiple if-else if possible";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI2_compareMethodNoIssue() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java";
+
+        int[] startLines = new int[]{};
+
+        int[] endLines = new int[]{};
+
+        String ruleId = "creedengo-java:GCI2";
+        String ruleMsg = "Use a switch statement instead of multiple if-else if possible";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI2_interfaceNoIssue() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java";
+
+        int[] startLines = new int[]{};
+
+        int[] endLines = new int[]{};
+
+        String ruleId = "creedengo-java:GCI2";
+        String ruleMsg = "Use a switch statement instead of multiple if-else if possible";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI2_noBlockNoIssue() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java";
+
+        int[] startLines = new int[]{};
+
+        int[] endLines = new int[]{};
+
+        String ruleId = "creedengo-java:GCI2";
+        String ruleMsg = "Use a switch statement instead of multiple if-else if possible";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI2_noIssue() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoIssue.java";
+
+        int[] startLines = new int[]{};
+
+        int[] endLines = new int[]{};
+
+        String ruleId = "creedengo-java:GCI2";
+        String ruleMsg = "Use a switch statement instead of multiple if-else if possible";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI77_invalid() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java";
+        int[] startLines = new int[]{8};
+        int[] endLines = new int[]{8};
+        String ruleId = "creedengo-java:GCI77";
+        String ruleMsg = "Avoid using Pattern.compile() in a non-static context.";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
+
+    }
+
+    @Test
+    void testGCI77_valid1() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid1.java";
+        int[] startLines = new int[]{};
+        int[] endLines = new int[]{};
+        String ruleId = "creedengo-java:GCI77";
+        String ruleMsg = "Avoid using Pattern.compile() in a non-static context.";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
+
+    }
+
+    @Test
+    void testGCI77_valid2() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid2.java";
+        int[] startLines = new int[]{};
+        int[] endLines = new int[]{};
+        String ruleId = "creedengo-java:GCI77";
+        String ruleMsg = "Avoid using Pattern.compile() in a non-static context.";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
+
+    }
+
+    @Test
+    void testGCI77_valid3() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid3.java";
+        int[] startLines = new int[]{};
+        int[] endLines = new int[]{};
+        String ruleId = "creedengo-java:GCI77";
+        String ruleMsg = "Avoid using Pattern.compile() in a non-static context.";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
+
+    }
+
     @Test
     void testGCI78() {
 
@@ -93,6 +326,38 @@ void testGCI78() {
 
     }
 
+    @Test
+    void testGCI1_loop() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheck.java";
+
+        int[] startLines = new int[]{32};
+
+        int[] endLines = new int[]{32};
+
+        String ruleId = "creedengo-java:GCI1";
+        String ruleMsg = "Avoid Spring repository call in loop or stream";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_50MIN);
+
+    }
+
+    @Test
+    void testGCI1_stream() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheck.java";
+
+        int[] startLines = new int[]{36, 46, 56, 66, 76, 84, 96, 105};
+
+        int[] endLines = new int[]{36, 46, 56, 66, 76, 84, 96, 105};
+
+        String ruleId = "creedengo-java:GCI1";
+        String ruleMsg = "Avoid Spring repository call in loop or stream";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_50MIN);
+
+    }
+
     @Test
     void testGCI72() {
         String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheck.java";
@@ -115,6 +380,28 @@ void testGCI5() {
         checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_10MIN);
     }
 
+    @Test
+    void testGCI76() {
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java";
+        String ruleId = "creedengo-java:GCI76";
+        String ruleMsg = "Avoid usage of static collections.";
+        int[] startLines = new int[]{10, 12, 14};
+        int[] endLines = new int[]{10, 12, 14};
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
+    }
+
+    @Test
+    void testGCI76_good() {
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsGoodWay.java";
+        String ruleId = "creedengo-java:GCI76";
+        String ruleMsg = "Avoid usage of static collections.";
+        int[] startLines = new int[]{};
+        int[] endLines = new int[]{};
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
+    }
+
     @Test
     void testGCI79() {
         String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java";
@@ -170,6 +457,86 @@ void testGCI69() {
         checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
     }
 
+    @Test
+    void testGCI28() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java";
+
+        int[] startLines = new int[]{23};
+
+        int[] endLines = new int[]{23};
+
+        String ruleId = "creedengo-java:GCI28";
+        String ruleMsg = "Optimize Read File Exceptions";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI28_2() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java";
+
+        int[] startLines = new int[]{20};
+
+        int[] endLines = new int[]{20};
+
+        String ruleId = "creedengo-java:GCI28";
+        String ruleMsg = "Optimize Read File Exceptions";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI28_3() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java";
+
+        int[] startLines = new int[]{19};
+
+        int[] endLines = new int[]{19};
+
+        String ruleId = "creedengo-java:GCI28";
+        String ruleMsg = "Optimize Read File Exceptions";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI28_4() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java";
+
+        int[] startLines = new int[]{18};
+
+        int[] endLines = new int[]{18};
+
+        String ruleId = "creedengo-java:GCI28";
+        String ruleMsg = "Optimize Read File Exceptions";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
+    @Test
+    void testGCI28_5() {
+
+        String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java";
+
+        int[] startLines = new int[]{18};
+
+        int[] endLines = new int[]{18};
+
+        String ruleId = "creedengo-java:GCI28";
+        String ruleMsg = "Optimize Read File Exceptions";
+
+        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
+
+    }
+
     @Test
     void testGCI94() {
         String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java";

From 014017132747cee1dca9fab694b86c8406e0a912 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Sun, 11 May 2025 00:13:10 +0200
Subject: [PATCH 136/233] corretcion technical Integration tests + update all
 version libraries

---
 CHANGELOG.md |  4 ++++
 README.md    |  2 +-
 pom.xml      | 42 ++++++++++++++++++++++--------------------
 3 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9ebaeb2f..16cf4fea 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed
 
+- compatibility updates for SonarQube 25.5.0
+- upgrade libraries versions
+- correction of technical problem with Integration tests (because of Maven format in technical answer to "sonar-orchestrator-junit5" library)
+
 ### Deleted
 
 ## [2.1.1] - 2025-03-13
diff --git a/README.md b/README.md
index 486327a1..f8942f41 100644
--- a/README.md
+++ b/README.md
@@ -61,7 +61,7 @@ Ready to use binaries are available [from GitHub](https://github.com/green-code-
 |----------------|---------------------|------------------------------------------------------------------------------------------------|
 | 1.6.+          | 9.4.+ LTS to 10.6.0 | 11 / 17                                                                                        |
 | 1.7.+          | 9.9.+ LTS to 10.6.0 | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) |
-| 2.+            | 9.9.+ LTS to 25.3.0 | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) |
+| 2.+            | 9.9.+ LTS to 25.5.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 [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-plugins-version-compatibility).
diff --git a/pom.xml b/pom.xml
index 3274401b..8cd13073 100644
--- a/pom.xml
+++ b/pom.xml
@@ -53,23 +53,29 @@
         green-code-initiative
         https://sonarcloud.io
 
-        
-        9.9.7.96285
+        
+        9.9.0.65466
+
         
-        9.8.0.203
+        11.4.0.2922
 
         
-        7.16.0.30901
+        
+        8.9.1.38281
+        
+
 
-        2.5.0.1358
+        2.17.0.3322
 
         1.23.0.740
 
-        5.9.1
-        3.23.1
-        5.3.1
+        5.12.2
+
+        3.27.3
+
+        5.17.0
 
-        1.7
+        1.8
 
         
         2.2.2
@@ -80,22 +86,18 @@
         false
 
         
-
-
+
 
 
 
-        
-
 
 
 
-        
-
 
 
-        25.3.0.104237
-        
+
+
+        25.5.0.107428
 
         
         ${sonarjava.version}
@@ -188,7 +190,7 @@
         
             org.sonarsource.orchestrator
             sonar-orchestrator-junit5
-            5.1.0.2254
+            5.6.1.2597
             test
         
         
@@ -200,7 +202,7 @@
         
             org.sonarsource.sonarqube
             sonar-ws
-            ${sonarqube.version}
+            ${test-it.sonarqube.version}
             test
         
         
@@ -263,7 +265,7 @@
                     creedengojava
                     org.greencodeinitiative.creedengo.java.JavaPlugin
                     true
-                    ${sonarqube.version}
+                    ${sonarqube-plugin-api-min.version}
                     true
                     ${java.version}
                     java

From 355eb08004a5493544579edf6284dff275d211da Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Mon, 19 May 2025 23:22:50 +0200
Subject: [PATCH 137/233] go to jdk 17 as required in README.md

---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 8cd13073..ae43a190 100644
--- a/pom.xml
+++ b/pom.xml
@@ -40,7 +40,7 @@
 
     
 
-        11
+        17
         ${java.version}
         ${java.version}
         

From 7c576c4f284f22b128c79b9cc3a4820dd7196758 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Mon, 19 May 2025 23:24:58 +0200
Subject: [PATCH 138/233] go to jdk 17 as required in README.md - CHANGELOG

---
 CHANGELOG.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 16cf4fea..23418684 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - compatibility updates for SonarQube 25.5.0
 - upgrade libraries versions
 - correction of technical problem with Integration tests (because of Maven format in technical answer to "sonar-orchestrator-junit5" library)
+- upgrade JDK from 11 to 17
 
 ### Deleted
 

From 81e55418c510aabd236edcac177332e17992c5e2 Mon Sep 17 00:00:00 2001
From: Julien Bureau 
Date: Tue, 20 May 2025 14:41:56 +0200
Subject: [PATCH 139/233] fix: mvnw execution on windows (auto crlf > force lf)
 crash when run ./tool_build.sh on docker

---
 .gitattributes | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitattributes b/.gitattributes
index 9039a78b..62749323 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,6 +1,7 @@
 # Ensure all SH files are checked out with LF line endings (regardless of the
 # OS they were checked out on).
 *.sh text eol=lf
+mvnw text eol=lf
 
 # Ensure BAT files will always be checked out with CRLFs (regardless of the
 # OS they were checked out on).

From 16c5e6a71254aa8cddc0a43a17eb32871792465a Mon Sep 17 00:00:00 2001
From: Maxime DANIEL 
Date: Tue, 20 May 2025 15:30:26 +0200
Subject: [PATCH 140/233] cleanup and add Enumeration to GCI69

---
 .../NoFunctionCallWhenDeclaringForLoop.java   | 25 +++++++----
 .../NoFunctionCallWhenDeclaringForLoop.java   | 42 +++++++++++++++++--
 2 files changed, 56 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
index b364b55a..1e57e86b 100644
--- a/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
@@ -26,6 +26,7 @@
 
 import org.sonar.check.Rule;
 import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
+import org.sonar.plugins.java.api.semantic.MethodMatchers;
 import org.sonar.plugins.java.api.tree.BaseTreeVisitor;
 import org.sonar.plugins.java.api.tree.ClassTree;
 import org.sonar.plugins.java.api.tree.CompilationUnitTree;
@@ -44,6 +45,20 @@ public class NoFunctionCallWhenDeclaringForLoop extends IssuableSubscriptionVisi
 
     protected static final String MESSAGERULE = "Do not call a function when declaring a for-type loop";
 
+    private static final String ITERATOR = "java.util.Iterator";
+    private static final MethodMatchers ITERATOR_METHODS = MethodMatchers.create()
+            .ofSubTypes(ITERATOR)
+            .names("hasNext", "next")
+            .withAnyParameters()
+            .build();
+    private static final String ENUMERATION = "java.util.Enumeration";
+    private static final MethodMatchers ENUMERATION_METHODS = MethodMatchers.create()
+            .ofSubTypes(ENUMERATION)
+            .names("hasMoreElements", "nextElement")
+            .withAnyParameters()
+            .build();
+
+    
     private static final Map> linesWithIssuesByClass = new HashMap<>();
 
     @Override
@@ -68,19 +83,15 @@ private class MethodInvocationInForStatementVisitor extends BaseTreeVisitor {
 
         @Override
         public void visitMethodInvocation(MethodInvocationTree tree) {
-            if (!lineAlreadyHasThisIssue(tree) && !isIteratorMethod(tree)) {
+            if (!lineAlreadyHasThisIssue(tree) && !isMethodAllowed(tree)) {
                 report(tree);
                 return;
             }
             super.visitMethodInvocation(tree);
         }
 
-        private boolean isIteratorMethod(MethodInvocationTree tree) {
-            boolean isIterator = tree.methodSymbol().owner().type().isSubtypeOf("java.util.Iterator");
-            String methodName = tree.methodSelect().lastToken().text();
-            boolean isMethodNext = methodName.equals("next");
-            boolean isMethodHasNext = methodName.equals("hasNext");
-            return isIterator && (isMethodNext || isMethodHasNext);
+        private boolean isMethodAllowed(MethodInvocationTree tree) {
+            return ITERATOR_METHODS.matches(tree) || ENUMERATION_METHODS.matches(tree);
         }
 
         private boolean lineAlreadyHasThisIssue(Tree tree) {
diff --git a/src/test/files/NoFunctionCallWhenDeclaringForLoop.java b/src/test/files/NoFunctionCallWhenDeclaringForLoop.java
index 42326070..542cad39 100644
--- a/src/test/files/NoFunctionCallWhenDeclaringForLoop.java
+++ b/src/test/files/NoFunctionCallWhenDeclaringForLoop.java
@@ -19,6 +19,10 @@
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.Collections;
+
+
 class NoFunctionCallWhenDeclaringForLoop {
 
     public int getMyValue() {
@@ -94,11 +98,33 @@ public void test7() {
         }
 
         // iterator called in an indirect way is allowed
-        for (final OtherClassWithIterator otherClass = new OtherClassWithIterator(joursSemaine.iterator()); otherClass.iterator.hasNext(); jour = otherClass.iterator.next()) {
+        for (final OtherClassWrapper otherClass = new OtherClassWrapper(joursSemaine.iterator()); otherClass.iterator.hasNext(); jour = otherClass.iterator.next()) {
             System.out.println(jour);
         }
+
         // but using a method that returns an iterator causes an issue
-        for (final OtherClassWithIterator otherClass = new OtherClassWithIterator(joursSemaine.iterator()); otherClass.getIterator().hasNext(); jour = otherClass.getIterator().next()) {  // Noncompliant {{Do not call a function when declaring a for-type loop}}
+        for (final OtherClassWrapper otherClass = new OtherClassWrapper(joursSemaine.iterator()); otherClass.getIterator().hasNext(); jour = otherClass.getIterator().next()) {  // Noncompliant {{Do not call a function when declaring a for-type loop}}
+            System.out.println(jour);
+        }
+
+    }
+
+    // compliant, enumeration is allowed
+    public void test8() {
+        final List joursSemaine = Arrays.asList("Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche");
+
+        String jour = null;
+        for (final Enumeration enumeration = Collections.enumeration(joursSemaine); enumeration.hasMoreElements(); jour = enumeration.nextElement()) {
+            System.out.println(jour);
+        }
+
+        // enumeration called in an indirect way is allowed
+        for(final OtherClassWrapper otherClass = new OtherClassWrapper(Collections.enumeration(joursSemaine)); otherClass.enumeration.hasMoreElements(); jour = otherClass.enumeration.nextElement()) {
+            System.out.println(jour);
+        }
+
+        // but using a method that returns an enumeration causes an issue
+        for(final OtherClassWrapper otherClass = new OtherClassWrapper(Collections.enumeration(joursSemaine)); otherClass.getEnumeration().hasMoreElements(); jour = otherClass.getEnumeration().nextElement()) {  // Noncompliant {{Do not call a function when declaring a for-type loop}}
             System.out.println(jour);
         }
 
@@ -106,14 +132,22 @@ public void test7() {
 
 }
 
-class OtherClassWithIterator {
+class OtherClassWrapper {
     public final Iterator iterator;
+    public final Enumeration enumeration;
 
-    public OtherClassWithIterator(Iterator iterator){
+    public OtherClassWrapper(Iterator iterator){
         this.iterator = iterator;
     }
+    public OtherClassWrapper(Enumeration enumeration){
+        this.enumeration = enumeration;
+    }
 
     public Iterator getIterator(){
         return iterator;
     }
+
+    public Enumeration getEnumeration(){
+        return enumeration;
+    }
 }

From 6aa2cdacc6a21eaa1383a7944494200480a4077d Mon Sep 17 00:00:00 2001
From: Maxime DANIEL 
Date: Tue, 20 May 2025 15:52:00 +0200
Subject: [PATCH 141/233] fix integration test

---
 .../java/integration/tests/GCIRulesIT.java    |  4 +-
 .../NoFunctionCallWhenDeclaringForLoop.java   | 42 +++++++++++++++++--
 2 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
index dfd7957c..ca9cb010 100644
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
@@ -451,8 +451,8 @@ void testGCI69() {
         String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java";
         String ruleId = "creedengo-java:GCI69";
         String ruleMsg = "Do not call a function when declaring a for-type loop";
-        int[] startLines = new int[]{58, 66, 74, 101};
-        int[] endLines = new int[]{58, 66, 74, 101};
+        int[] startLines = new int[]{62, 70, 78, 106, 127};
+        int[] endLines = new int[]{62, 70, 78, 106, 127};
 
         checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
     }
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
index 42326070..542cad39 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
@@ -19,6 +19,10 @@
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.Collections;
+
+
 class NoFunctionCallWhenDeclaringForLoop {
 
     public int getMyValue() {
@@ -94,11 +98,33 @@ public void test7() {
         }
 
         // iterator called in an indirect way is allowed
-        for (final OtherClassWithIterator otherClass = new OtherClassWithIterator(joursSemaine.iterator()); otherClass.iterator.hasNext(); jour = otherClass.iterator.next()) {
+        for (final OtherClassWrapper otherClass = new OtherClassWrapper(joursSemaine.iterator()); otherClass.iterator.hasNext(); jour = otherClass.iterator.next()) {
             System.out.println(jour);
         }
+
         // but using a method that returns an iterator causes an issue
-        for (final OtherClassWithIterator otherClass = new OtherClassWithIterator(joursSemaine.iterator()); otherClass.getIterator().hasNext(); jour = otherClass.getIterator().next()) {  // Noncompliant {{Do not call a function when declaring a for-type loop}}
+        for (final OtherClassWrapper otherClass = new OtherClassWrapper(joursSemaine.iterator()); otherClass.getIterator().hasNext(); jour = otherClass.getIterator().next()) {  // Noncompliant {{Do not call a function when declaring a for-type loop}}
+            System.out.println(jour);
+        }
+
+    }
+
+    // compliant, enumeration is allowed
+    public void test8() {
+        final List joursSemaine = Arrays.asList("Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche");
+
+        String jour = null;
+        for (final Enumeration enumeration = Collections.enumeration(joursSemaine); enumeration.hasMoreElements(); jour = enumeration.nextElement()) {
+            System.out.println(jour);
+        }
+
+        // enumeration called in an indirect way is allowed
+        for(final OtherClassWrapper otherClass = new OtherClassWrapper(Collections.enumeration(joursSemaine)); otherClass.enumeration.hasMoreElements(); jour = otherClass.enumeration.nextElement()) {
+            System.out.println(jour);
+        }
+
+        // but using a method that returns an enumeration causes an issue
+        for(final OtherClassWrapper otherClass = new OtherClassWrapper(Collections.enumeration(joursSemaine)); otherClass.getEnumeration().hasMoreElements(); jour = otherClass.getEnumeration().nextElement()) {  // Noncompliant {{Do not call a function when declaring a for-type loop}}
             System.out.println(jour);
         }
 
@@ -106,14 +132,22 @@ public void test7() {
 
 }
 
-class OtherClassWithIterator {
+class OtherClassWrapper {
     public final Iterator iterator;
+    public final Enumeration enumeration;
 
-    public OtherClassWithIterator(Iterator iterator){
+    public OtherClassWrapper(Iterator iterator){
         this.iterator = iterator;
     }
+    public OtherClassWrapper(Enumeration enumeration){
+        this.enumeration = enumeration;
+    }
 
     public Iterator getIterator(){
         return iterator;
     }
+
+    public Enumeration getEnumeration(){
+        return enumeration;
+    }
 }

From 25617602c9a8f343c51d6d5ae5fe614bef2cee84 Mon Sep 17 00:00:00 2001
From: Maxime DANIEL 
Date: Tue, 20 May 2025 16:48:31 +0200
Subject: [PATCH 142/233] update changelog

---
 CHANGELOG.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 23418684..6f1ba95b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed
 
+- GCI69 Java : calls to hasMoreElements() and nextElement() methods from java.util.Enumeration interface aren't flagged anymore when called in a for loop
 - compatibility updates for SonarQube 25.5.0
 - upgrade libraries versions
 - correction of technical problem with Integration tests (because of Maven format in technical answer to "sonar-orchestrator-junit5" library)

From 1044ad5cf51e914e2a5638c07f5192758f7da0c7 Mon Sep 17 00:00:00 2001
From: Maxime DANIEL 
Date: Wed, 21 May 2025 10:38:58 +0200
Subject: [PATCH 143/233] make test code compilable

---
 .../java/checks/NoFunctionCallWhenDeclaringForLoop.java       | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
index 542cad39..1c225677 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java
@@ -133,8 +133,8 @@ public void test8() {
 }
 
 class OtherClassWrapper {
-    public final Iterator iterator;
-    public final Enumeration enumeration;
+    public Iterator iterator = null;
+    public Enumeration enumeration = null;
 
     public OtherClassWrapper(Iterator iterator){
         this.iterator = iterator;

From 5103e4b3c350cb4a005866013f288458373e95d8 Mon Sep 17 00:00:00 2001
From: Maxime DANIEL 
Date: Wed, 21 May 2025 12:19:10 +0200
Subject: [PATCH 144/233] improve rule 82: - remove false positives with
 reasignement using this.var - remove false positives with passing of a
 variable to a function it can be reassinged in

---
 CHANGELOG.md                                  |  3 +-
 .../java/integration/tests/GCIRulesIT.java    |  4 +-
 .../MakeNonReassignedVariablesConstants.java  | 79 +++++++++++++++++++
 .../MakeNonReassignedVariablesConstants.java  | 36 ++++++++-
 .../MakeNonReassignedVariablesConstants.java  | 79 +++++++++++++++++++
 5 files changed, 197 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 23418684..bf03dd44 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,7 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Added
 
 ### Changed
-
+- GCI82 - remove false positives with reasignement using this.var
+- GCI82 - remove false positives with passing a variable to a function it can be reassinged in
 - compatibility updates for SonarQube 25.5.0
 - upgrade libraries versions
 - correction of technical problem with Integration tests (because of Maven format in technical answer to "sonar-orchestrator-junit5" library)
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
index dfd7957c..574283f8 100644
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
@@ -440,8 +440,8 @@ void testGCI82() {
         String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java";
         String ruleId = "creedengo-java:GCI82";
         String ruleMsg = "The variable is never reassigned and can be 'final'";
-        int[] startLines = new int[]{7, 12, 13, 45};
-        int[] endLines = new int[]{7, 12, 13, 45};
+        int[] startLines = new int[]{7, 12, 13, 18, 24, 27, 46, 73, 106, 119};
+        int[] endLines = new int[]{7, 12, 13, 18, 24, 27, 46, 73, 106, 119};
 
         checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
     }
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
index bef640d4..87bca5ed 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
@@ -14,9 +14,37 @@ public class MakeNonReassignedVariablesConstants {
     private String varDefinedInClassReassigned = "0"; // Compliant
     private String varDefinedInConstructorReassigned = "1"; // Compliant
 
+    // using "this" 
+    private String varDefinedInClassNotReassignedByThis = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
+    private String varDefinedInClassReassignedByThis = "0"; // Compliant
+    private String varDefinedInConstructorReassignedByThis = "1"; // Compliant
+
+    // passing through a method
+    private String varDefinedInClassReassignedInMethod = "0"; // Compliant
+    private String varDefinedInClassInFinalMethod = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
+    private String varDefinedInClassNotReassignedInMethod = "0"; // Compliant (erreur au niveau de la définition du constructeur)
+    private String varDefinedInClassReassignedInConstructor = "0"; // Compliant
+    private String varDefinedInClassInFinalConstructor = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
+    private String varDefinedInClassNotReassignedInConstructor = "0"; // Compliant (erreur au niveau de la définition du constructeur)
+
     public MakeNonReassignedVariablesConstants() {
         varDefinedInConstructorReassigned = "3";
+        this.varDefinedInConstructorReassignedByThis = "3";
         logger.info(varDefinedInConstructorReassigned);
+        logger.info(this.varDefinedInConstructorReassignedByThis);
+    }
+
+    public void parameterReassigned(String reassigned) {
+        reassigned = "10";
+        logger.info(reassigned);
+    }
+
+    public void parameterNotReassigned(final String notReassigned) {
+        logger.info(notReassigned);
+    }
+
+    public void parameterNotReassignedNotFinal(String notReassigned) { // Noncompliant {{The variable is never reassigned and can be 'final'}}
+        logger.info(notReassigned);
     }
 
     void localVariableReassigned() {
@@ -66,4 +94,55 @@ void classVariableReassignedBis() {
         logger.info(myFinalAndNotReassignedObject.toString());
     }
 
+    void classVariableReassignedByThis() {
+        this.varDefinedInClassReassignedByThis = "1";
+
+        logger.info(this.varDefinedInClassReassignedByThis);
+        logger.info(this.varDefinedInClassNotReassignedByThis);
+    }
+
+    void reassignedInMethod() {
+        String varDefinedInMethodReassignedInMethod = "0"; // Compliant
+        String varDefinedInMethodInFinalMethod = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
+        String varDefinedInMethodNotReassignedInMethod = "0"; // Compliant (erreur au niveau de la définition de la méthode)
+
+        this.parameterReassigned(varDefinedInMethodReassignedInMethod);
+        this.parameterReassigned(this.varDefinedInClassReassignedInMethod);
+        this.parameterNotReassigned(varDefinedInMethodInFinalMethod);
+        this.parameterNotReassigned(this.varDefinedInClassInFinalMethod);
+        this.parameterNotReassignedNotFinal(varDefinedInMethodNotReassignedInMethod);
+        this.parameterNotReassignedNotFinal(this.varDefinedInClassNotReassignedInMethod);
+    }
+
+    void reassignedInConstructor(){
+        String varDefinedInMethodReassignedInConstructor = "0"; // Compliant
+        String varDefinedInMethodInFinalConstructor = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
+        String varDefinedInMethodNotReassignedInConstructor = "0"; // Compliant (erreur au niveau de la définition de la méthode)
+
+        Object o = null;
+        o = new reassignedInConstructor(varDefinedInMethodReassignedInConstructor);
+        o = new reassignedInConstructor(this.varDefinedInClassReassignedInConstructor);
+        o = new notReassignedInConstructor(varDefinedInMethodInFinalConstructor);
+        o = new notReassignedInConstructor(this.varDefinedInClassInFinalConstructor);
+        o = new notReassignedInConstructorNotFinal(varDefinedInMethodNotReassignedInConstructor);
+        o = new notReassignedInConstructorNotFinal(this.varDefinedInClassNotReassignedInConstructor);
+    }
+
+}
+
+class reassignedInConstructor{
+    reassignedInConstructor(String reassignedInConstructor) {
+        reassignedInConstructor = "10";
+        System.out.println(reassignedInConstructor);
+    }
+}
+class notReassignedInConstructor{
+    notReassignedInConstructor(final String notReassignedInConstructor) {
+        System.out.println(notReassignedInConstructor);
+    }
+}
+class notReassignedInConstructorNotFinal{
+    notReassignedInConstructorNotFinal(String notReassignedInConstructorNotFinal) { // Noncompliant {{The variable is never reassigned and can be 'final'}}
+        System.out.println(notReassignedInConstructorNotFinal);
+    }
 }
\ No newline at end of file
diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
index 6533256d..f32ce079 100644
--- a/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
@@ -29,6 +29,7 @@ public void visitNode(@Nonnull Tree tree) {
         LOGGER.debug("   => isNotFinalAndNotStatic(variableTree) = " + isNotFinalAndNotStatic(variableTree));
         LOGGER.debug("   => usages = " + variableTree.symbol().usages().size());
         LOGGER.debug("   => isNotReassigned = " + isNotReassigned(variableTree));
+        LOGGER.debug("   => isPassedAsNonFinalParameter = " + isPassedAsNonFinalParameter(variableTree));
 
         if (isNotFinalAndNotStatic(variableTree) && isNotReassigned(variableTree)) {
             reportIssue(tree, MESSAGE_RULE);
@@ -41,10 +42,43 @@ private static boolean isNotReassigned(VariableTree variableTree) {
         return variableTree.symbol()
                 .usages()
                 .stream()
-                .noneMatch(MakeNonReassignedVariablesConstants::parentIsAssignment);
+                .noneMatch(MakeNonReassignedVariablesConstants::parentIsAssignment) 
+            && !isPassedAsNonFinalParameter(variableTree); // if a variable is passed into a method as a non-final parameter, it may have been reassigned
+    }
+
+    private static boolean isPassedAsNonFinalParameter(VariableTree variableTree) {
+        return variableTree.symbol()
+                .usages()
+                .stream()
+                .anyMatch(MakeNonReassignedVariablesConstants::parentIsNonFinalParameter);
+    }
+
+    private static boolean parentIsNonFinalParameter(Tree tree) {
+        // Skip the parent if it is a member select (e.g. "this.myVar")
+        while (tree.parent().is(Kind.MEMBER_SELECT)) {
+            tree = tree.parent();
+        }
+        if(!parentIsKind(tree, Kind.ARGUMENTS))
+            return false;
+        if(tree.parent() == null)
+            return false;
+        Arguments arguments = (Arguments) tree.parent();
+        if (parentIsKind(tree, Kind.METHOD_INVOCATION, Kind.NEW_CLASS)) {
+            MethodTree methodTree = arguments.parent().is(Kind.METHOD_INVOCATION)
+                ? ((MethodInvocationTree) arguments.parent()).methodSymbol().declaration()
+                : ((NewClassTree) arguments.parent()).methodSymbol().declaration();
+            int argument_idx = arguments.indexOf(tree);
+            return methodTree != null && !hasModifier(methodTree.parameters().get(argument_idx).modifiers(), Modifier.FINAL);
+        }
+        return false;
+        
     }
 
     private static boolean parentIsAssignment(Tree tree) {
+        // Skip the parent if it is a member select (e.g. "this.myVar")
+        while (tree.parent().is(Kind.MEMBER_SELECT)) {
+            tree = tree.parent();   
+        }
         return parentIsKind(tree,
                 Kind.ASSIGNMENT,
                 Kind.MULTIPLY_ASSIGNMENT,
diff --git a/src/test/files/MakeNonReassignedVariablesConstants.java b/src/test/files/MakeNonReassignedVariablesConstants.java
index bef640d4..87bca5ed 100644
--- a/src/test/files/MakeNonReassignedVariablesConstants.java
+++ b/src/test/files/MakeNonReassignedVariablesConstants.java
@@ -14,9 +14,37 @@ public class MakeNonReassignedVariablesConstants {
     private String varDefinedInClassReassigned = "0"; // Compliant
     private String varDefinedInConstructorReassigned = "1"; // Compliant
 
+    // using "this" 
+    private String varDefinedInClassNotReassignedByThis = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
+    private String varDefinedInClassReassignedByThis = "0"; // Compliant
+    private String varDefinedInConstructorReassignedByThis = "1"; // Compliant
+
+    // passing through a method
+    private String varDefinedInClassReassignedInMethod = "0"; // Compliant
+    private String varDefinedInClassInFinalMethod = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
+    private String varDefinedInClassNotReassignedInMethod = "0"; // Compliant (erreur au niveau de la définition du constructeur)
+    private String varDefinedInClassReassignedInConstructor = "0"; // Compliant
+    private String varDefinedInClassInFinalConstructor = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
+    private String varDefinedInClassNotReassignedInConstructor = "0"; // Compliant (erreur au niveau de la définition du constructeur)
+
     public MakeNonReassignedVariablesConstants() {
         varDefinedInConstructorReassigned = "3";
+        this.varDefinedInConstructorReassignedByThis = "3";
         logger.info(varDefinedInConstructorReassigned);
+        logger.info(this.varDefinedInConstructorReassignedByThis);
+    }
+
+    public void parameterReassigned(String reassigned) {
+        reassigned = "10";
+        logger.info(reassigned);
+    }
+
+    public void parameterNotReassigned(final String notReassigned) {
+        logger.info(notReassigned);
+    }
+
+    public void parameterNotReassignedNotFinal(String notReassigned) { // Noncompliant {{The variable is never reassigned and can be 'final'}}
+        logger.info(notReassigned);
     }
 
     void localVariableReassigned() {
@@ -66,4 +94,55 @@ void classVariableReassignedBis() {
         logger.info(myFinalAndNotReassignedObject.toString());
     }
 
+    void classVariableReassignedByThis() {
+        this.varDefinedInClassReassignedByThis = "1";
+
+        logger.info(this.varDefinedInClassReassignedByThis);
+        logger.info(this.varDefinedInClassNotReassignedByThis);
+    }
+
+    void reassignedInMethod() {
+        String varDefinedInMethodReassignedInMethod = "0"; // Compliant
+        String varDefinedInMethodInFinalMethod = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
+        String varDefinedInMethodNotReassignedInMethod = "0"; // Compliant (erreur au niveau de la définition de la méthode)
+
+        this.parameterReassigned(varDefinedInMethodReassignedInMethod);
+        this.parameterReassigned(this.varDefinedInClassReassignedInMethod);
+        this.parameterNotReassigned(varDefinedInMethodInFinalMethod);
+        this.parameterNotReassigned(this.varDefinedInClassInFinalMethod);
+        this.parameterNotReassignedNotFinal(varDefinedInMethodNotReassignedInMethod);
+        this.parameterNotReassignedNotFinal(this.varDefinedInClassNotReassignedInMethod);
+    }
+
+    void reassignedInConstructor(){
+        String varDefinedInMethodReassignedInConstructor = "0"; // Compliant
+        String varDefinedInMethodInFinalConstructor = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
+        String varDefinedInMethodNotReassignedInConstructor = "0"; // Compliant (erreur au niveau de la définition de la méthode)
+
+        Object o = null;
+        o = new reassignedInConstructor(varDefinedInMethodReassignedInConstructor);
+        o = new reassignedInConstructor(this.varDefinedInClassReassignedInConstructor);
+        o = new notReassignedInConstructor(varDefinedInMethodInFinalConstructor);
+        o = new notReassignedInConstructor(this.varDefinedInClassInFinalConstructor);
+        o = new notReassignedInConstructorNotFinal(varDefinedInMethodNotReassignedInConstructor);
+        o = new notReassignedInConstructorNotFinal(this.varDefinedInClassNotReassignedInConstructor);
+    }
+
+}
+
+class reassignedInConstructor{
+    reassignedInConstructor(String reassignedInConstructor) {
+        reassignedInConstructor = "10";
+        System.out.println(reassignedInConstructor);
+    }
+}
+class notReassignedInConstructor{
+    notReassignedInConstructor(final String notReassignedInConstructor) {
+        System.out.println(notReassignedInConstructor);
+    }
+}
+class notReassignedInConstructorNotFinal{
+    notReassignedInConstructorNotFinal(String notReassignedInConstructorNotFinal) { // Noncompliant {{The variable is never reassigned and can be 'final'}}
+        System.out.println(notReassignedInConstructorNotFinal);
+    }
 }
\ No newline at end of file

From bbbc666edee070cf96859bb6c9fcde7c1ba22812 Mon Sep 17 00:00:00 2001
From: Maxime DANIEL 
Date: Wed, 21 May 2025 15:01:26 +0200
Subject: [PATCH 145/233] update doc

---
 .../java/checks/MakeNonReassignedVariablesConstants.java | 9 ++++-----
 src/test/files/MakeNonReassignedVariablesConstants.java  | 9 ++++-----
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
index 87bca5ed..8e24b914 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
@@ -22,10 +22,10 @@ public class MakeNonReassignedVariablesConstants {
     // passing through a method
     private String varDefinedInClassReassignedInMethod = "0"; // Compliant
     private String varDefinedInClassInFinalMethod = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
-    private String varDefinedInClassNotReassignedInMethod = "0"; // Compliant (erreur au niveau de la définition du constructeur)
+    private String varDefinedInClassNotReassignedInMethod = "0"; // Compliant (the String was passed as a non-final parameter to the method)
     private String varDefinedInClassReassignedInConstructor = "0"; // Compliant
     private String varDefinedInClassInFinalConstructor = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
-    private String varDefinedInClassNotReassignedInConstructor = "0"; // Compliant (erreur au niveau de la définition du constructeur)
+    private String varDefinedInClassNotReassignedInConstructor = "0"; // Compliant (the String was passed as a non-final parameter to the constructor)
 
     public MakeNonReassignedVariablesConstants() {
         varDefinedInConstructorReassigned = "3";
@@ -104,7 +104,7 @@ void classVariableReassignedByThis() {
     void reassignedInMethod() {
         String varDefinedInMethodReassignedInMethod = "0"; // Compliant
         String varDefinedInMethodInFinalMethod = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
-        String varDefinedInMethodNotReassignedInMethod = "0"; // Compliant (erreur au niveau de la définition de la méthode)
+        String varDefinedInMethodNotReassignedInMethod = "0"; // Compliant (the String was passed as a non-final parameter to the method)
 
         this.parameterReassigned(varDefinedInMethodReassignedInMethod);
         this.parameterReassigned(this.varDefinedInClassReassignedInMethod);
@@ -117,8 +117,7 @@ void reassignedInMethod() {
     void reassignedInConstructor(){
         String varDefinedInMethodReassignedInConstructor = "0"; // Compliant
         String varDefinedInMethodInFinalConstructor = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
-        String varDefinedInMethodNotReassignedInConstructor = "0"; // Compliant (erreur au niveau de la définition de la méthode)
-
+        String varDefinedInMethodNotReassignedInConstructor = "0"; // Compliant (the String was passed as a non-final parameter to the constructor)
         Object o = null;
         o = new reassignedInConstructor(varDefinedInMethodReassignedInConstructor);
         o = new reassignedInConstructor(this.varDefinedInClassReassignedInConstructor);
diff --git a/src/test/files/MakeNonReassignedVariablesConstants.java b/src/test/files/MakeNonReassignedVariablesConstants.java
index 87bca5ed..8e24b914 100644
--- a/src/test/files/MakeNonReassignedVariablesConstants.java
+++ b/src/test/files/MakeNonReassignedVariablesConstants.java
@@ -22,10 +22,10 @@ public class MakeNonReassignedVariablesConstants {
     // passing through a method
     private String varDefinedInClassReassignedInMethod = "0"; // Compliant
     private String varDefinedInClassInFinalMethod = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
-    private String varDefinedInClassNotReassignedInMethod = "0"; // Compliant (erreur au niveau de la définition du constructeur)
+    private String varDefinedInClassNotReassignedInMethod = "0"; // Compliant (the String was passed as a non-final parameter to the method)
     private String varDefinedInClassReassignedInConstructor = "0"; // Compliant
     private String varDefinedInClassInFinalConstructor = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
-    private String varDefinedInClassNotReassignedInConstructor = "0"; // Compliant (erreur au niveau de la définition du constructeur)
+    private String varDefinedInClassNotReassignedInConstructor = "0"; // Compliant (the String was passed as a non-final parameter to the constructor)
 
     public MakeNonReassignedVariablesConstants() {
         varDefinedInConstructorReassigned = "3";
@@ -104,7 +104,7 @@ void classVariableReassignedByThis() {
     void reassignedInMethod() {
         String varDefinedInMethodReassignedInMethod = "0"; // Compliant
         String varDefinedInMethodInFinalMethod = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
-        String varDefinedInMethodNotReassignedInMethod = "0"; // Compliant (erreur au niveau de la définition de la méthode)
+        String varDefinedInMethodNotReassignedInMethod = "0"; // Compliant (the String was passed as a non-final parameter to the method)
 
         this.parameterReassigned(varDefinedInMethodReassignedInMethod);
         this.parameterReassigned(this.varDefinedInClassReassignedInMethod);
@@ -117,8 +117,7 @@ void reassignedInMethod() {
     void reassignedInConstructor(){
         String varDefinedInMethodReassignedInConstructor = "0"; // Compliant
         String varDefinedInMethodInFinalConstructor = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}}
-        String varDefinedInMethodNotReassignedInConstructor = "0"; // Compliant (erreur au niveau de la définition de la méthode)
-
+        String varDefinedInMethodNotReassignedInConstructor = "0"; // Compliant (the String was passed as a non-final parameter to the constructor)
         Object o = null;
         o = new reassignedInConstructor(varDefinedInMethodReassignedInConstructor);
         o = new reassignedInConstructor(this.varDefinedInClassReassignedInConstructor);

From ca68b31e3b964309dada69d04ef511b80836dbed Mon Sep 17 00:00:00 2001
From: Maxime DANIEL 
Date: Wed, 21 May 2025 15:29:02 +0200
Subject: [PATCH 146/233] update changelog with PR link

---
 CHANGELOG.md | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index bf03dd44..e6b6f792 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,8 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Added
 
 ### Changed
-- GCI82 - remove false positives with reasignement using this.var
-- GCI82 - remove false positives with passing a variable to a function it can be reassinged in
+- [#103](https://github.com/green-code-initiative/creedengo-java/pull/103) GCI82 - remove false positives with reasignement using this.var
+- [#103](https://github.com/green-code-initiative/creedengo-java/pull/103) GCI82 - remove false positives with passing a variable to a function it can be reassinged in
 - compatibility updates for SonarQube 25.5.0
 - upgrade libraries versions
 - correction of technical problem with Integration tests (because of Maven format in technical answer to "sonar-orchestrator-junit5" library)

From b8f46840e20c478e9f8548d8eedce02aa7fc5932 Mon Sep 17 00:00:00 2001
From: Maxime DANIEL 
Date: Wed, 21 May 2025 15:30:58 +0200
Subject: [PATCH 147/233] correct pr link

---
 CHANGELOG.md | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index e6b6f792..015bcb7a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,8 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Added
 
 ### Changed
-- [#103](https://github.com/green-code-initiative/creedengo-java/pull/103) GCI82 - remove false positives with reasignement using this.var
-- [#103](https://github.com/green-code-initiative/creedengo-java/pull/103) GCI82 - remove false positives with passing a variable to a function it can be reassinged in
+- [#110](https://github.com/green-code-initiative/creedengo-java/pull/110) GCI82 - remove false positives with reasignement using this.var
+- [#110](https://github.com/green-code-initiative/creedengo-java/pull/110) GCI82 - remove false positives with passing a variable to a function it can be reassinged in
 - compatibility updates for SonarQube 25.5.0
 - upgrade libraries versions
 - correction of technical problem with Integration tests (because of Maven format in technical answer to "sonar-orchestrator-junit5" library)

From 22dd46203152011c053cea08f60e423481c2fd69 Mon Sep 17 00:00:00 2001
From: Maxime DANIEL 
Date: Wed, 21 May 2025 15:31:57 +0200
Subject: [PATCH 148/233] update changelog with PR

---
 CHANGELOG.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6f1ba95b..9680c577 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed
 
-- GCI69 Java : calls to hasMoreElements() and nextElement() methods from java.util.Enumeration interface aren't flagged anymore when called in a for loop
+- [#103](https://github.com/green-code-initiative/creedengo-java/pull/103) GCI69 Java : calls to hasMoreElements() and nextElement() methods from java.util.Enumeration interface aren't flagged anymore when called in a for loop
 - compatibility updates for SonarQube 25.5.0
 - upgrade libraries versions
 - correction of technical problem with Integration tests (because of Maven format in technical answer to "sonar-orchestrator-junit5" library)

From 2db61c3d788a3f0b6e224fe0f2dd800c73f1d5f1 Mon Sep 17 00:00:00 2001
From: Maxime Malgorn <9255967+utarwyn@users.noreply.github.com>
Date: Fri, 23 May 2025 21:42:28 +0200
Subject: [PATCH 149/233] Fix build workflow for forks (#115)

---
 .github/workflows/build.yml | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index ca18beeb..4052eda6 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -5,12 +5,12 @@ on:
     branches:
       - main
     paths-ignore:
-      - '*.md'
-      - '.github/**/*.yml'
+      - "*.md"
+      - ".github/**/*.yml"
     tags:
-      - '[0-9]+.[0-9]+.[0-9]+'
+      - "[0-9]+.[0-9]+.[0-9]+"
   pull_request:
-    types: [ opened, synchronize, reopened ]
+    types: [opened, synchronize, reopened]
 
 jobs:
   build:
@@ -22,32 +22,27 @@ jobs:
       - name: Checkout
         uses: actions/checkout@v4
         with:
-          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of analysis
+          fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
 
       - name: Set up JDK 17
-        uses: actions/setup-java@v3
+        uses: actions/setup-java@v4
         with:
-          distribution: 'temurin'
+          distribution: "temurin"
           java-version: 17
-
-      - name: Cache Maven packages
-        uses: actions/cache@v3
-        with:
-          path: ~/.m2
-          key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
-          restore-keys: ${{ runner.os }}-m2
+          cache: maven
 
       - name: Verify
         run: ./mvnw -e -B verify
 
       - name: Cache SonarQube packages
-        uses: actions/cache@v3
+        uses: actions/cache@v4
         with:
           path: ~/.sonar/cache
           key: ${{ runner.os }}-sonar
           restore-keys: ${{ runner.os }}-sonar
 
       - name: SonarQube Scan
+        if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
         env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
           SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

From 43bd13477ff092711e6da84bc865f3df6cd4d369 Mon Sep 17 00:00:00 2001
From: Luc Fouin 
Date: Thu, 30 May 2024 11:46:20 +0200
Subject: [PATCH 150/233] =?UTF-8?q?fix:=20=F0=9F=A9=B9=20"++i"=20statement?=
 =?UTF-8?q?=20is=20not=20always=20bad?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

In some cases, postfix increment may be intentional.

Closes #4
---
 CHANGELOG.md                                  |  1 +
 .../java/integration/tests/GCIRulesIT.java    |  4 +-
 .../creedengo/java/checks/IncrementCheck.java | 47 +++++++++++---
 .../creedengo/java/checks/IncrementCheck.java | 10 +++
 src/test/files/IncrementCheck.java            | 65 +++++++++++++++----
 5 files changed, 106 insertions(+), 21 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 23418684..9a688cf3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - upgrade libraries versions
 - correction of technical problem with Integration tests (because of Maven format in technical answer to "sonar-orchestrator-junit5" library)
 - upgrade JDK from 11 to 17
+- [#4](https://github.com/green-code-initiative/creedengo-java/issues/4) Improvement: "++i" statement is not so bad
 
 ### Deleted
 
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
index dfd7957c..3a51b723 100644
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
@@ -429,8 +429,8 @@ void testGCI67() {
         String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java";
         String ruleId = "creedengo-java:GCI67";
         String ruleMsg = "Use ++i instead of i++";
-        int[] startLines = new int[]{9, 19, 38};
-        int[] endLines = new int[]{9, 19, 38};
+        int[] startLines = new int[]{9, 24, 47};
+        int[] endLines = new int[]{9, 24, 47};
 
         checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
     }
diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java
index fc513b96..b42caa96 100644
--- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java
+++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java
@@ -9,40 +9,71 @@ int foo1() {
         return counter++; // Noncompliant {{Use ++i instead of i++}}
     }
 
+    private int j = 0;
+    int foo10() {
+        return this.j++; // Compliant because maybe the use case needs to return j AND increment it
+    }
+
     int foo11() {
         int counter = 0;
         return ++counter;
     }
 
-    void foo2(int value) {
+    int foo2() {
         int counter = 0;
         counter++; // Noncompliant {{Use ++i instead of i++}}
+        return counter;
     }
 
-    void foo22(int value) {
+    int foo22() {
         int counter = 0;
         ++counter;
+        return counter;
     }
 
-    void foo3(int value) {
+    int foo3() {
         int counter = 0;
         counter = counter + 197845 ;
+        return counter;
     }
 
-    void foo4(int value) {
+    int foo4() {
         int counter = 0;
         counter = counter + 35 + 78 ;
+        return counter;
     }
 
-    void foo50(int value) {
+    void foo50() {
         for (int i=0; i < 10; i++) { // Noncompliant {{Use ++i instead of i++}}
-            System.out.println(i);
+            System.out.println(i); //NOSONAR
         }
     }
 
-    void foo51(int value) {
+    void foo51() {
         for (int i=0; i < 10; ++i) {
-            System.out.println(i);
+            System.out.println(i); //NOSONAR
         }
     }
+
+    void bar61(int value) {
+        // For test purpose
+    }
+
+    int foo61() {
+        int i = 0;
+        bar61(i++); // Compliant because maybe bar61 needs the unincremented value
+        return i;
+    }
+
+    int foo62() {
+        int i = 0;
+        bar61(2 + i++); // Compliant because maybe bar61 needs the unincremented value
+        return i;
+    }
+
+    void foo71() {
+        int counter = 0;
+        int a = 2 + counter++;  // Compliant because we probably want to increment counter
+                                // then to add it to 2 to initialize a
+    }
 }
diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java
index d5a2a42b..c418ad6d 100644
--- a/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java
@@ -22,7 +22,10 @@
 
 import org.sonar.check.Rule;
 import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
+import org.sonar.plugins.java.api.tree.Arguments;
+import org.sonar.plugins.java.api.tree.BinaryExpressionTree;
 import org.sonar.plugins.java.api.tree.Tree;
+import org.sonar.plugins.java.api.tree.UnaryExpressionTree;
 import org.sonar.plugins.java.api.tree.Tree.Kind;
 import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
 
@@ -40,6 +43,13 @@ public List nodesToVisit() {
 
     @Override
     public void visitNode(Tree tree) {
+        UnaryExpressionTree unaryExprTree = (UnaryExpressionTree) tree;
+
+        if (unaryExprTree.parent() instanceof BinaryExpressionTree
+            || unaryExprTree.parent() instanceof Arguments
+            || unaryExprTree.expression().is(Tree.Kind.MEMBER_SELECT)) {
+            return ;
+        }
         reportIssue(tree, MESSAGERULE);
     }
 }
diff --git a/src/test/files/IncrementCheck.java b/src/test/files/IncrementCheck.java
index d3c77559..86da5166 100644
--- a/src/test/files/IncrementCheck.java
+++ b/src/test/files/IncrementCheck.java
@@ -15,8 +15,15 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
-class MyClass {
-    MyClass(MyClass mc) {
+package org.greencodeinitiative.creedengo.java.checks;
+
+private class Foo {
+    public int i; //NOSONAR
+}
+
+class IncrementCheck {
+
+    IncrementCheck(IncrementCheck mc) {
     }
 
     int foo1() {
@@ -24,40 +31,76 @@ int foo1() {
         return counter++; // Noncompliant {{Use ++i instead of i++}}
     }
 
+    private int j = 0;
+    int foo10() {
+        return this.j++; // Compliant because maybe the use case needs to return j AND increment it
+    }
+
     int foo11() {
         int counter = 0;
         return ++counter;
     }
 
-    void foo2(int value) {
+    int foo12() {
+        Foo f;
+        return f.i++; // Compliant because maybe the use case needs to return j AND increment it
+    }
+
+    int foo2() {
         int counter = 0;
         counter++; // Noncompliant {{Use ++i instead of i++}}
+        return counter;
     }
 
-    void foo22(int value) {
+    int foo22() {
         int counter = 0;
         ++counter;
+        return counter;
     }
 
-    void foo3(int value) {
+    int foo3() {
         int counter = 0;
         counter = counter + 197845 ;
+        return counter;
     }
 
-    void foo4(int value) {
-        int counter =0;
+    int foo4() {
+        int counter = 0;
         counter = counter + 35 + 78 ;
+        return counter;
     }
 
-    void foo50(int value) {
+    void foo50() {
         for (int i=0; i < 10; i++) { // Noncompliant {{Use ++i instead of i++}}
-            System.out.println(i);
+            System.out.println(i); //NOSONAR
         }
     }
 
-    void foo51(int value) {
+    void foo51() {
         for (int i=0; i < 10; ++i) {
-            System.out.println(i);
+            System.out.println(i); //NOSONAR
         }
     }
+
+    void bar61(int value) {
+        // For test purpose
+    }
+
+    int foo61() {
+        int i = 0;
+        bar61(i++); // Compliant because maybe bar61 needs the unincremented value
+        return i;
+    }
+
+    int foo62() {
+        int i = 0;
+        bar61(2 + i++); // Compliant because maybe bar61 needs the unincremented value
+        return i;
+    }
+
+    void foo71() {
+        int counter = 0;
+        int a = 2 + counter++;  // Compliant because we probably want to increment counter
+                                // then to add it to 2 to initialize a
+    }
 }

From 17e2739ba94232a245b289638c2c9558598607ec Mon Sep 17 00:00:00 2001
From: Maxime DANIEL 
Date: Mon, 7 Jul 2025 14:26:34 +0200
Subject: [PATCH 151/233] fix bug and improve changelog

---
 CHANGELOG.md                                                   | 3 +--
 .../java/checks/MakeNonReassignedVariablesConstants.java       | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index ff98bef1..a21679bd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,8 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Added
 
 ### Changed
-- [#110](https://github.com/green-code-initiative/creedengo-java/pull/110) GCI82 - remove false positives with reasignement using this.var
-- [#110](https://github.com/green-code-initiative/creedengo-java/pull/110) GCI82 - remove false positives with passing a variable to a function it can be reassinged in
+- [#110](https://github.com/green-code-initiative/creedengo-java/pull/110) GCI82 - remove false positives with reassignment using this and with passing a variable to a function it can be reassigned in
 - compatibility updates for SonarQube 25.5.0
 - upgrade libraries versions
 - correction of technical problem with Integration tests (because of Maven format in technical answer to "sonar-orchestrator-junit5" library)
diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
index f32ce079..0ae099e4 100644
--- a/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
@@ -63,7 +63,7 @@ private static boolean parentIsNonFinalParameter(Tree tree) {
         if(tree.parent() == null)
             return false;
         Arguments arguments = (Arguments) tree.parent();
-        if (parentIsKind(tree, Kind.METHOD_INVOCATION, Kind.NEW_CLASS)) {
+        if (parentIsKind(arguments, Kind.METHOD_INVOCATION, Kind.NEW_CLASS)) {
             MethodTree methodTree = arguments.parent().is(Kind.METHOD_INVOCATION)
                 ? ((MethodInvocationTree) arguments.parent()).methodSymbol().declaration()
                 : ((NewClassTree) arguments.parent()).methodSymbol().declaration();

From 138e9c4447ad83cb77ecc5d8245889f89f3f6ce8 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Fri, 29 Aug 2025 19:04:52 +0200
Subject: [PATCH 152/233] license plugin correction for JDK17

---
 pom.xml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index ae43a190..e95d7bad 100644
--- a/pom.xml
+++ b/pom.xml
@@ -404,7 +404,8 @@
             
                 com.mycila
                 license-maven-plugin
-                4.6
+                
+                4.1
                 
                     
                         Green Code Initiative

From d123216db668bfd44aafb60fd3a0eec9912e7336 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Fri, 5 Sep 2025 22:00:30 +0200
Subject: [PATCH 153/233] Create dependabot.yml

---
 .github/dependabot.yml | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 .github/dependabot.yml

diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 00000000..273fff0a
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,11 @@
+# To get started with Dependabot version updates, you'll need to specify which
+# package ecosystems to update and where the package manifests are located.
+# Please see the documentation for all configuration options:
+# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
+
+version: 2
+updates:
+  - package-ecosystem: "maven" # See documentation for possible values
+    directory: "/" # Location of package manifests
+    schedule:
+      interval: "weekly"

From 0d1786690e425b5688a4d31c3f1c23c1debd334f Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Fri, 5 Sep 2025 23:37:28 +0200
Subject: [PATCH 154/233] upgrade internal lib and check Sonar 25.9.0

---
 CHANGELOG.md |  2 +-
 Dockerfile   |  4 +++-
 README.md    |  2 +-
 pom.xml      | 45 ++++++++++++++++-----------------------------
 4 files changed, 21 insertions(+), 32 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index e657561c..228441cc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - [#103](https://github.com/green-code-initiative/creedengo-java/pull/103) GCI69 Java : calls to hasMoreElements() and nextElement() methods from java.util.Enumeration interface aren't flagged anymore when called in a for loop
 - [#110](https://github.com/green-code-initiative/creedengo-java/pull/110) GCI82 - remove false positives with reassignment using this and with passing a variable to a function it can be reassigned in
-- compatibility updates for SonarQube 25.5.0
+- compatibility updates for SonarQube 25.9.0
 - upgrade libraries versions
 - correction of technical problem with Integration tests (because of Maven format in technical answer to "sonar-orchestrator-junit5" library)
 - upgrade JDK from 11 to 17
diff --git a/Dockerfile b/Dockerfile
index dd45b67f..5099a0a4 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,9 +1,11 @@
 ARG MAVEN_BUILDER=3-openjdk-17-slim
 
+#ARG SONARQUBE_VERSION=9.9.0-community
 #ARG SONARQUBE_VERSION=24.12.0.100206-community
 #ARG SONARQUBE_VERSION=25.1.0.102122-community
 #ARG SONARQUBE_VERSION=25.2.0.102705-community
-ARG SONARQUBE_VERSION=25.3.0.104237-community
+#ARG SONARQUBE_VERSION=25.3.0.104237-community
+ARG SONARQUBE_VERSION=25.9.0.112764-community
 
 FROM maven:${MAVEN_BUILDER} AS builder
 
diff --git a/README.md b/README.md
index f8942f41..b692a7ae 100644
--- a/README.md
+++ b/README.md
@@ -61,7 +61,7 @@ Ready to use binaries are available [from GitHub](https://github.com/green-code-
 |----------------|---------------------|------------------------------------------------------------------------------------------------|
 | 1.6.+          | 9.4.+ LTS to 10.6.0 | 11 / 17                                                                                        |
 | 1.7.+          | 9.9.+ LTS to 10.6.0 | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) |
-| 2.+            | 9.9.+ LTS to 25.5.0 | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) |
+| 2.+            | 9.9.0 LTS to 25.9.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 [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-plugins-version-compatibility).
diff --git a/pom.xml b/pom.xml
index e95d7bad..79926fed 100644
--- a/pom.xml
+++ b/pom.xml
@@ -57,28 +57,20 @@
         9.9.0.65466
 
         
-        11.4.0.2922
+        13.0.0.3026
 
         
-        
-        8.9.1.38281
-        
-
+        
+        8.9.3.40165
+        
+
 
-        2.17.0.3322
+        2.18.0.3393
 
         1.23.0.740
 
-        5.12.2
-
-        3.27.3
-
-        5.17.0
-
-        1.8
-
         
-        2.2.2
+        2.5.0
 
         
         https://repo1.maven.org/maven2
@@ -97,7 +89,8 @@
 
 
 
-        25.5.0.107428
+
+        25.9.0.112764
 
         
         ${sonarjava.version}
@@ -139,7 +132,7 @@
         
             com.google.re2j
             re2j
-            ${google.re2j}
+            1.8
         
 
         
@@ -161,21 +154,21 @@
         
             org.junit.jupiter
             junit-jupiter
-            ${junit.jupiter.version}
+            5.13.4
             test
         
 
         
             org.assertj
             assertj-core
-            ${assertJ.version}
+            3.27.4
             test
         
 
         
             org.mockito
             mockito-junit-jupiter
-            ${mockito.version}
+            5.19.0
             test
         
 
@@ -190,13 +183,7 @@
         
             org.sonarsource.orchestrator
             sonar-orchestrator-junit5
-            5.6.1.2597
-            test
-        
-        
-            org.sonarsource.java
-            test-classpath-reader
-            8.8.0.37665
+            5.6.2.2625
             test
         
         
@@ -214,13 +201,13 @@
         
             ch.qos.logback
             logback-classic
-            1.5.6
+            1.5.18
             test
         
         
             org.projectlombok
             lombok
-            1.18.36
+            1.18.40
             test
         
     

From f77367496a1a6e30ac0b75ba2060b287649a54dc Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Fri, 5 Sep 2025 23:59:19 +0200
Subject: [PATCH 155/233] upgrade internal lib bis

---
 .github/dependabot.yml | 8 ++++++++
 pom.xml                | 4 ++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 273fff0a..77d8a84c 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -9,3 +9,11 @@ updates:
     directory: "/" # Location of package manifests
     schedule:
       interval: "weekly"
+    ignore:
+      # Ignore all versions : cf pom.xml comments
+      - dependency-name: "org.sonarsource.java.sonar-java-plugin"
+      # Ignore all versions : cf pom.xml comments
+      - dependency-name: "com.mycila:license-maven-plugin"
+      # Ignore specific versions of another dependency
+      - dependency-name: "org.springframework.data.spring-data-jpa"
+        versions: [ "3.x" ]
diff --git a/pom.xml b/pom.xml
index 79926fed..346d4c2d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -227,7 +227,7 @@
             
                 org.jacoco
                 jacoco-maven-plugin
-                0.8.12
+                0.8.13
                 
                     
                         prepare-agent
@@ -320,12 +320,12 @@
                     
                 
             
+            
             
                 org.apache.maven.plugins
                 maven-dependency-plugin
                 3.8.1
                 
-                    
                     
                         copy
                         test-compile

From c16c58031fa8448c1d4619f4729b66b32d8324fe Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Sat, 6 Sep 2025 21:29:49 +0200
Subject: [PATCH 156/233] update dependabot

---
 .github/dependabot.yml | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 77d8a84c..99d22bd1 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -11,9 +11,6 @@ updates:
       interval: "weekly"
     ignore:
       # Ignore all versions : cf pom.xml comments
-      - dependency-name: "org.sonarsource.java.sonar-java-plugin"
+      - dependency-name: "org.sonarsource.java:sonar-java-plugin"
       # Ignore all versions : cf pom.xml comments
       - dependency-name: "com.mycila:license-maven-plugin"
-      # Ignore specific versions of another dependency
-      - dependency-name: "org.springframework.data.spring-data-jpa"
-        versions: [ "3.x" ]

From 5c77eb98f7c607e51486bc6205307a819f130a07 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Sat, 6 Sep 2025 21:37:43 +0200
Subject: [PATCH 157/233] update libraries

---
 pom.xml | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/pom.xml b/pom.xml
index 346d4c2d..cc3c5462 100644
--- a/pom.xml
+++ b/pom.xml
@@ -337,19 +337,19 @@
                                 
                                     org.slf4j
                                     slf4j-api
-                                    1.7.30
+                                    2.0.17
                                     jar
                                 
                                 
                                     org.apache.commons
                                     commons-collections4
-                                    4.0
+                                    4.5.0
                                     jar
                                 
                                 
                                     javax
                                     javaee-api
-                                    6.0
+                                    8.0.1
                                     jar
                                 
                                 
@@ -367,7 +367,7 @@
                                 
                                     org.springframework
                                     spring-context
-                                    5.2.3.RELEASE
+                                    6.2.10
                                     jar
                                 
                                 
@@ -425,7 +425,7 @@
                 
                 org.codehaus.mojo
                 build-helper-maven-plugin
-                3.6.0
+                3.6.1
                 
                     
                         add-integration-test-sources

From 42c2453c487357113b1624ea2b8b2f27c4ddcbb3 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Sat, 6 Sep 2025 22:25:04 +0200
Subject: [PATCH 158/233] update dependabot + libraries

---
 .github/dependabot.yml |  2 ++
 pom.xml                | 14 +++++++++-----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 99d22bd1..27768551 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -14,3 +14,5 @@ updates:
       - dependency-name: "org.sonarsource.java:sonar-java-plugin"
       # Ignore all versions : cf pom.xml comments
       - dependency-name: "com.mycila:license-maven-plugin"
+      - dependency-name: "org.springframework.data:spring-data-commons"
+        update-types: "version-update:semver-major"
diff --git a/pom.xml b/pom.xml
index cc3c5462..ecdfb2a1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -222,7 +222,7 @@
             
                 org.apache.maven.plugins
                 maven-surefire-plugin
-                3.5.2
+                3.5.3
             
             
                 org.jacoco
@@ -355,13 +355,13 @@
                                 
                                     org.springframework
                                     spring-webmvc
-                                    5.2.3.RELEASE
+                                    6.2.10
                                     jar
                                 
                                 
                                     org.springframework
                                     spring-web
-                                    5.2.3.RELEASE
+                                    6.2.10
                                     jar
                                 
                                 
@@ -379,7 +379,11 @@
                                 
                                     org.springframework.data
                                     spring-data-commons
-                                    2.2.4.RELEASE
+                                    
+                                    2.7.18
+                                    
+                                    
+                                    
                                     jar
                                 
                             
@@ -463,7 +467,7 @@
                 
                 org.apache.maven.plugins
                 maven-failsafe-plugin
-                3.5.2
+                3.5.3
                 
                     
                         

From 213e0ab1872c31059d528d5b7ea35c28fbe7bbff Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Sat, 6 Sep 2025 22:27:27 +0200
Subject: [PATCH 159/233] update dependabot FIX

---
 .github/dependabot.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 27768551..5d53e306 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -15,4 +15,4 @@ updates:
       # Ignore all versions : cf pom.xml comments
       - dependency-name: "com.mycila:license-maven-plugin"
       - dependency-name: "org.springframework.data:spring-data-commons"
-        update-types: "version-update:semver-major"
+        update-types: ["version-update:semver-patch", "version-update:semver-minor"]

From 0449ce6c34661de23bdaa29d9a3e55fd3ec4107b Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Sat, 6 Sep 2025 22:56:37 +0200
Subject: [PATCH 160/233] update libraries

---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index ecdfb2a1..41f7bd40 100644
--- a/pom.xml
+++ b/pom.xml
@@ -217,7 +217,7 @@
             
                 org.apache.maven.plugins
                 maven-compiler-plugin
-                3.13.0
+                3.14.0
             
             
                 org.apache.maven.plugins

From 8e5668585aefe4c42115ef2286a0f6dab3070494 Mon Sep 17 00:00:00 2001
From: PREISNER Julien 
Date: Sat, 30 Aug 2025 14:15:04 +0200
Subject: [PATCH 161/233] refactor: don't unnecessarily call methods when
 writing with LOGGER.debug()

---
 .../checks/MakeNonReassignedVariablesConstants.java | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
index 0ae099e4..495bc4e2 100644
--- a/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
+++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java
@@ -25,12 +25,13 @@ public List nodesToVisit() {
     @Override
     public void visitNode(@Nonnull Tree tree) {
         VariableTree variableTree = (VariableTree) tree;
-        LOGGER.debug("Variable > " + getVariableNameForLogger(variableTree));
-        LOGGER.debug("   => isNotFinalAndNotStatic(variableTree) = " + isNotFinalAndNotStatic(variableTree));
-        LOGGER.debug("   => usages = " + variableTree.symbol().usages().size());
-        LOGGER.debug("   => isNotReassigned = " + isNotReassigned(variableTree));
-        LOGGER.debug("   => isPassedAsNonFinalParameter = " + isPassedAsNonFinalParameter(variableTree));
-
+        if (LOGGER.isDebugEnabled()) {
+            LOGGER.debug("Variable > {}", getVariableNameForLogger(variableTree));
+            LOGGER.debug("   => isNotFinalAndNotStatic(variableTree) = {}", isNotFinalAndNotStatic(variableTree));
+            LOGGER.debug("   => usages = {}", variableTree.symbol().usages().size());
+            LOGGER.debug("   => isNotReassigned = {}", isNotReassigned(variableTree));
+            LOGGER.debug("   => isPassedAsNonFinalParameter = {}", isPassedAsNonFinalParameter(variableTree));
+        }
         if (isNotFinalAndNotStatic(variableTree) && isNotReassigned(variableTree)) {
             reportIssue(tree, MESSAGE_RULE);
         } else {

From 5cfbc858ab18f221d4ad1bd5c11dda1308015d7c Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Sat, 10 Jan 2026 23:44:07 +0100
Subject: [PATCH 162/233] update crceedengo-rules-spec to 2.6.7

---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 41f7bd40..dcc2cd69 100644
--- a/pom.xml
+++ b/pom.xml
@@ -70,7 +70,7 @@
         1.23.0.740
 
         
-        2.5.0
+        2.6.7
 
         
         https://repo1.maven.org/maven2

From 049a7fb8b5b4fea84b66d4c6cf4baa95a8e0697a Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Sun, 11 Jan 2026 19:19:10 +0100
Subject: [PATCH 163/233] update for sonarqube 25.12

---
 CHANGELOG.md | 2 +-
 pom.xml      | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 228441cc..89a5ef14 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - [#103](https://github.com/green-code-initiative/creedengo-java/pull/103) GCI69 Java : calls to hasMoreElements() and nextElement() methods from java.util.Enumeration interface aren't flagged anymore when called in a for loop
 - [#110](https://github.com/green-code-initiative/creedengo-java/pull/110) GCI82 - remove false positives with reassignment using this and with passing a variable to a function it can be reassigned in
-- compatibility updates for SonarQube 25.9.0
+- compatibility updates for SonarQube 25.12.0
 - upgrade libraries versions
 - correction of technical problem with Integration tests (because of Maven format in technical answer to "sonar-orchestrator-junit5" library)
 - upgrade JDK from 11 to 17
diff --git a/pom.xml b/pom.xml
index dcc2cd69..82f3182c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -90,7 +90,8 @@
 
 
 
-        25.9.0.112764
+
+        25.12.0.117093
 
         
         ${sonarjava.version}

From 605670075b7c2eee60f3bd416158c9f8d0a27e58 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Sun, 11 Jan 2026 19:31:35 +0100
Subject: [PATCH 164/233] update for sonarqube 25.12 - docker

---
 Dockerfile | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/Dockerfile b/Dockerfile
index 5099a0a4..00a72653 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -5,7 +5,10 @@ ARG MAVEN_BUILDER=3-openjdk-17-slim
 #ARG SONARQUBE_VERSION=25.1.0.102122-community
 #ARG SONARQUBE_VERSION=25.2.0.102705-community
 #ARG SONARQUBE_VERSION=25.3.0.104237-community
-ARG SONARQUBE_VERSION=25.9.0.112764-community
+#ARG SONARQUBE_VERSION=25.9.0.112764-community
+ARG SONARQUBE_VERSION=25.11.0.114957-community
+#ARG SONARQUBE_VERSION=25.12.0.117093-community
+#ARG SONARQUBE_VERSION=26.1.0.118079-community
 
 FROM maven:${MAVEN_BUILDER} AS builder
 

From 8217d23eb13c452f436cdbab545157a88bc9e5e3 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Sun, 11 Jan 2026 19:33:28 +0100
Subject: [PATCH 165/233] update for sonarqube 25.12 - README.md

---
 README.md | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index b692a7ae..cb0f6b88 100644
--- a/README.md
+++ b/README.md
@@ -57,11 +57,11 @@ 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                                                                                        |
-| 1.7.+          | 9.9.+ LTS to 10.6.0 | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) |
-| 2.+            | 9.9.0 LTS to 25.9.0 | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) |
+| Plugin version | SonarQube version    | Java version                                                                                   |
+|----------------|----------------------|------------------------------------------------------------------------------------------------|
+| 1.6.+          | 9.4.+ LTS to 10.6.0  | 11 / 17                                                                                        |
+| 1.7.+          | 9.9.+ LTS to 10.6.0  | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) |
+| 2.+            | 9.9.0 LTS to 25.12.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 [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-plugins-version-compatibility).

From 71bb51eeea74386f2e9f57dd751ee000305dd821 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Sun, 11 Jan 2026 21:23:09 +0100
Subject: [PATCH 166/233] prepare 2.1.2 version : update CHANGELOG.md

---
 CHANGELOG.md | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 89a5ef14..c9449d30 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed
 
+### Deleted
+
+## [2.1.2] - 2026-01-11
+
+### Changed
+
 - [#103](https://github.com/green-code-initiative/creedengo-java/pull/103) GCI69 Java : calls to hasMoreElements() and nextElement() methods from java.util.Enumeration interface aren't flagged anymore when called in a for loop
 - [#110](https://github.com/green-code-initiative/creedengo-java/pull/110) GCI82 - remove false positives with reassignment using this and with passing a variable to a function it can be reassigned in
 - compatibility updates for SonarQube 25.12.0
@@ -19,8 +25,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - upgrade JDK from 11 to 17
 - [#4](https://github.com/green-code-initiative/creedengo-java/issues/4) Improvement: "++i" statement is not so bad
 
-### Deleted
-
 ## [2.1.1] - 2025-03-13
 
 ### Changed
@@ -105,7 +109,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - Update ecocode-rules-specifications to 1.4.6
 
-[unreleased](https://github.com/green-code-initiative/creedengo-java/compare/2.1.1...HEAD)
+[unreleased](https://github.com/green-code-initiative/creedengo-java/compare/2.1.2...HEAD)
+[2.1.2](https://github.com/green-code-initiative/creedengo-java/compare/2.1.1...2.1.2)
 [2.1.1](https://github.com/green-code-initiative/creedengo-java/compare/2.1.0...2.1.1)
 [2.1.0](https://github.com/green-code-initiative/creedengo-java/compare/2.0.0...2.1.0)
 [2.0.0](https://github.com/green-code-initiative/creedengo-java/compare/1.6.2...2.0.0)

From ec767792e48d2aab701102b25127a98aa7502342 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Sun, 11 Jan 2026 21:24:39 +0100
Subject: [PATCH 167/233] [maven-release-plugin] prepare release 2.1.2

---
 pom.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 82f3182c..19b8cf0e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
 
     org.green-code-initiative
     creedengo-java-plugin
-    2.1.2-SNAPSHOT
+    2.1.2
 
     sonar-plugin
 
@@ -30,7 +30,7 @@
         scm:git:https://github.com/green-code-initiative/creedengo-java
         scm:git:https://github.com/green-code-initiative/creedengo-java
         https://github.com/green-code-initiative/creedengo-java
-        HEAD
+        2.1.2
     
 
     

From 2ae1a74edf195c301145056433f02f1ccabc86a5 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Sun, 11 Jan 2026 21:24:40 +0100
Subject: [PATCH 168/233] [maven-release-plugin] prepare for next development
 iteration

---
 pom.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 19b8cf0e..4433c476 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
 
     org.green-code-initiative
     creedengo-java-plugin
-    2.1.2
+    2.1.3-SNAPSHOT
 
     sonar-plugin
 
@@ -30,7 +30,7 @@
         scm:git:https://github.com/green-code-initiative/creedengo-java
         scm:git:https://github.com/green-code-initiative/creedengo-java
         https://github.com/green-code-initiative/creedengo-java
-        2.1.2
+        HEAD
     
 
     

From 66ca409f964c4eab1a634d2882715aba0353f195 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO 
Date: Mon, 12 Jan 2026 00:00:16 +0100
Subject: [PATCH 169/233] update IT system to use common component

---
 pom.xml                                       |  61 +--
 .../integration/tests/BuildProjectEngine.java | 437 ------------------
 .../java/integration/tests/GCIRulesBase.java  |  88 ----
 .../java/integration/tests/GCIRulesIT.java    |   2 +
 .../tests/profile/ProfileBackup.java          | 163 -------
 .../tests/profile/ProfileMetadata.java        |  42 --
 .../tests/profile/RuleMetadata.java           |  40 --
 7 files changed, 36 insertions(+), 797 deletions(-)
 delete mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BuildProjectEngine.java
 delete mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesBase.java
 delete mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/ProfileBackup.java
 delete mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/ProfileMetadata.java
 delete mode 100644 src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/RuleMetadata.java

diff --git a/pom.xml b/pom.xml
index 4433c476..9c136942 100644
--- a/pom.xml
+++ b/pom.xml
@@ -182,35 +182,42 @@
 
         
         
-            org.sonarsource.orchestrator
-            sonar-orchestrator-junit5
-            5.6.2.2625
-            test
-        
-        
-            org.sonarsource.sonarqube
-            sonar-ws
-            ${test-it.sonarqube.version}
-            test
-        
-        
-            io.github.jycr
-            java-data-url-handler
-            0.0.1
-            test
-        
-        
-            ch.qos.logback
-            logback-classic
-            1.5.18
-            test
-        
-        
-            org.projectlombok
-            lombok
-            1.18.40
+            org.green-code-initiative
+            creedengo-integration-test
+            main-SNAPSHOT
             test
         
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
     
 
     
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BuildProjectEngine.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BuildProjectEngine.java
deleted file mode 100644
index dc1c0c8d..00000000
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BuildProjectEngine.java
+++ /dev/null
@@ -1,437 +0,0 @@
-package org.greencodeinitiative.creedengo.java.integration.tests;
-
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.nio.file.Path;
-import java.text.MessageFormat;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Scanner;
-import java.util.Set;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import com.sonar.orchestrator.Orchestrator;
-import com.sonar.orchestrator.build.MavenBuild;
-import com.sonar.orchestrator.container.Server;
-import com.sonar.orchestrator.junit5.OrchestratorExtension;
-import com.sonar.orchestrator.junit5.OrchestratorExtensionBuilder;
-import com.sonar.orchestrator.locator.FileLocation;
-import com.sonar.orchestrator.locator.Location;
-import com.sonar.orchestrator.locator.MavenLocation;
-import com.sonar.orchestrator.locator.URLLocation;
-import lombok.Getter;
-import org.greencodeinitiative.creedengo.java.integration.tests.profile.ProfileBackup;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
-import org.sonarqube.ws.Components;
-import org.sonarqube.ws.Issues;
-import org.sonarqube.ws.Measures;
-import org.sonarqube.ws.client.HttpConnector;
-import org.sonarqube.ws.client.WsClient;
-import org.sonarqube.ws.client.WsClientFactories;
-import org.sonarqube.ws.client.components.ShowRequest;
-import org.sonarqube.ws.client.issues.SearchRequest;
-import org.sonarqube.ws.client.measures.ComponentRequest;
-
-import static java.lang.System.Logger.Level.INFO;
-import static java.util.Optional.ofNullable;
-import static java.util.function.Predicate.not;
-import static java.util.stream.Collectors.toList;
-import static java.util.stream.Collectors.toMap;
-import static org.assertj.core.api.Assertions.assertThat;
-
-abstract class BuildProjectEngine {
-
-	private static final System.Logger LOGGER = System.getLogger(BuildProjectEngine.class.getName());
-
-	protected static OrchestratorExtension orchestrator;
-	protected static List analyzedProjects;
-
-	@BeforeAll
-	static void setup() {
-		LOGGER.log(
-				INFO,
-				"\n" +
-						"====================================================================================================\n" +
-						"Launching SonarQube server with following JAVA System properties: {0}\n" +
-						"====================================================================================================\n"
-				,
-				Stream
-						.of(
-								"test-it.sonarqube.keepRunning",
-								"test-it.orchestrator.artifactory.url",
-								"test-it.sonarqube.version",
-								"test-it.plugins",
-								"test-it.additional-profile-uris",
-								"test-it.test-projects",
-								"test-it.test-project-profile-by-language"
-						)
-						.filter(k -> System.getProperty(k) != null)
-						.map(k -> MessageFormat
-								.format(
-										"-D{0}=\"{1}\"",
-										k,
-										System.getProperty(k).replaceAll("\\s+", " ")
-								)
-						)
-						.collect(Collectors.joining("\n", "\n\n", "\n\n"))
-		);
-		launchSonarqube();
-		launchAnalysis();
-	}
-
-	@AfterAll
-	static void tearDown() {
-		if ("true".equalsIgnoreCase(System.getProperty("test-it.sonarqube.keepRunning"))) {
-			try (Scanner in = new Scanner(System.in)) {
-				LOGGER.log(INFO, () ->
-						MessageFormat.format(
-								"\n" +
-										"\n====================================================================================================" +
-										"\nSonarQube available at: {0} (to login: admin/admin)" +
-										"\n====================================================================================================" +
-										"\n",
-								orchestrator.getServer().getUrl()
-						)
-				);
-				do {
-					LOGGER.log(INFO, "✍ Please press CTRL+C to stop");
-				}
-				while (!in.nextLine().isEmpty());
-			}
-		}
-		if (orchestrator != null) {
-			orchestrator.stop();
-		}
-	}
-
-	private static void launchSonarqube() {
-		String orchestratorArtifactoryUrl = systemProperty("test-it.orchestrator.artifactory.url");
-		String sonarqubeVersion = systemProperty("test-it.sonarqube.version");
-		Optional sonarqubePort = ofNullable(System.getProperty("test-it.sonarqube.port")).map(String::trim).filter(not(String::isEmpty));
-
-		OrchestratorExtensionBuilder orchestratorExtensionBuilder = OrchestratorExtension
-				.builderEnv()
-				.useDefaultAdminCredentialsForBuilds(true)
-				.setOrchestratorProperty("orchestrator.artifactory.url", orchestratorArtifactoryUrl)
-				.setSonarVersion(sonarqubeVersion)
-				.setServerProperty("sonar.forceAuthentication", "false")
-				.setServerProperty("sonar.web.javaOpts", "-Xmx1G");
-
-		sonarqubePort.ifPresent(s -> orchestratorExtensionBuilder.setServerProperty("sonar.web.port", s));
-
-		additionalPluginsToInstall().forEach(orchestratorExtensionBuilder::addPlugin);
-		additionalProfiles().forEach(orchestratorExtensionBuilder::restoreProfileAtStartup);
-
-		orchestrator = orchestratorExtensionBuilder.build();
-		orchestrator.start();
-		LOGGER.log(INFO, () -> MessageFormat.format("SonarQube server available on: {0}", orchestrator.getServer().getUrl()));
-	}
-
-	private static void launchAnalysis() {
-		Server server = orchestrator.getServer();
-		Map qualityProfileByLanguage = testProjectProfileByLanguage();
-
-		analyzedProjects = getProjectsToAnalyze();
-
-		analyzedProjects
-				.stream()
-				// - Prepare/create SonarQube project for the test project
-				.peek(projectToAnalyze -> projectToAnalyze.provisionProjectIntoServer(server))
-				// - Configure the test project
-				.peek(projectToAnalyze -> projectToAnalyze.associateProjectToQualityProfile(server, qualityProfileByLanguage))
-				.map(ProjectToAnalyze::createMavenBuild)
-				// - Run SonarQube Scanner on test project
-				.peek(p -> LOGGER.log(INFO, () -> MessageFormat.format("Running SonarQube Scanner on project: {0}", p.getPom())))
-				.forEach(orchestrator::executeBuild);
-	}
-
-	private static String systemProperty(String propertyName) {
-		return ofNullable(System.getProperty(propertyName))
-				.orElseThrow(() -> new IllegalStateException(
-						String.format(
-								"System property `%s` must be defined. See `%s` (in section: `plugin[maven-failsafe-plugin]/systemPropertyVariables`) for sample value.",
-								propertyName,
-								Path.of("pom.xml").toAbsolutePath()
-						)
-				));
-	}
-
-	/**
-	 * Projects to analyze
-	 */
-	private static List getProjectsToAnalyze() {
-		return commaSeparatedValues(systemProperty("test-it.test-projects"))
-				.map(projectToAnalyzeDefinition -> pipeSeparatedValues(projectToAnalyzeDefinition).collect(toList()))
-				.filter(projectToAnalyzeDefinition -> projectToAnalyzeDefinition.size() == 3)
-				.map(projectToAnalyzeDefinition -> {
-					// Project Key
-					String projectKey = projectToAnalyzeDefinition.get(0);
-					// Project Name
-					String projectName = projectToAnalyzeDefinition.get(1);
-					// Project POM URI
-					URI projectPom = URI.create(projectToAnalyzeDefinition.get(2));
-					return new ProjectToAnalyze(projectPom, projectKey, projectName);
-				})
-				.collect(toList());
-	}
-
-	private static Stream commaSeparatedValues(String value) {
-		return splitAndTrim(value, "\\s*,\\s*");
-	}
-
-	private static Stream pipeSeparatedValues(String value) {
-		return splitAndTrim(value, "\\s*\\|\\s*");
-	}
-
-	private static Stream colonSeparatedValues(String value) {
-		return splitAndTrim(value, "\\s*\\:\\s*");
-	}
-
-	private static Stream splitAndTrim(String value, String regexSeparator) {
-		return Stream
-				.of(value.split(regexSeparator))
-				.map(String::trim)
-				.filter(not(String::isEmpty));
-	}
-
-	private static Set additionalPluginsToInstall() {
-		Set plugins = commaSeparatedValues(systemProperty("test-it.plugins"))
-				.map(BuildProjectEngine::toPluginLocation)
-				.collect(Collectors.toSet());
-		commaSeparatedValues(System.getProperty("test-it.additional-plugins", ""))
-				.map(BuildProjectEngine::toPluginLocation)
-				.forEach(plugins::add);
-		return plugins;
-	}
-
-	private static Set additionalProfiles() {
-		return commaSeparatedValues(systemProperty("test-it.additional-profile-uris"))
-				.map(URI::create)
-				.map(ProfileBackup::new)
-				.map(ProfileBackup::profileDataUri)
-				.map(URLLocation::create)
-				.collect(Collectors.toSet());
-	}
-
-	private static Map testProjectProfileByLanguage() {
-		// Comma separated list of profiles to associate to each "test project"
-		// Syntaxe: `language:profileName`
-		return commaSeparatedValues(systemProperty("test-it.test-project-profile-by-language"))
-				.map(languageAndProfileDefinitions -> pipeSeparatedValues(languageAndProfileDefinitions).collect(toList()))
-				.filter(languageAndProfile -> languageAndProfile.size() == 2)
-				.collect(toMap(
-						// Language
-						languageAndProfile -> languageAndProfile.get(0),
-						// Profile name
-						languageAndProfile -> languageAndProfile.get(1)
-				));
-	}
-
-	private static Location toPluginLocation(String location) {
-		if (location.startsWith("file://")) {
-			try {
-				return FileLocation.of(URI.create(location).toURL());
-			} catch (MalformedURLException e) {
-				throw new IllegalArgumentException(e);
-			}
-		}
-		List pluginGAVvalues = colonSeparatedValues(location).collect(toList());
-		if (pluginGAVvalues.size() != 3) {
-			throw new IllegalArgumentException("Invalid plugin GAV definition (`groupId:artifactId:version`): " + location);
-		}
-		return MavenLocation.of(
-				// groupId
-				pluginGAVvalues.get(0),
-				// artifactId
-				pluginGAVvalues.get(1),
-				// version
-				pluginGAVvalues.get(2)
-		);
-	}
-
-	protected static Issues.SearchWsResponse searchIssuesForFile(String projectKey, String file, String ruleId) {
-		return searchIssuesForComponent(projectKey + ":" + file, ruleId);
-	}
-
-	protected static Issues.SearchWsResponse searchIssuesForComponent(String componentKey, String ruleId) {
-
-		SearchRequest searchRequest = new SearchRequest()
-				.setComponentKeys(Collections.singletonList(componentKey))
-				.setPs("500"); // nb issues per page returned (default 100)
-
-		if (ruleId != null) {
-			searchRequest.setRules(Collections.singletonList(ruleId)); // only keep issues for this rule
-		}
-
-		return newWsClient(orchestrator)
-				.issues()
-				.search(searchRequest);
-	}
-
-	protected static Components.ShowWsResponse showComponent(String componentKey) {
-
-		ShowRequest showRequest = new org.sonarqube.ws.client.components.ShowRequest()
-				.setComponent(componentKey);
-
-		return newWsClient(orchestrator)
-				.components()
-				.show(showRequest);
-	}
-
-	protected static Map getMeasures(String componentKey) {
-		List metricKeys = List.of(
-				"alert_status",
-				"blocker_violations",
-				"branch_coverage",
-				"bugs",
-//				"class_complexity", // suppr en 25.1
-				"classes",
-				"code_smells",
-				"cognitive_complexity",
-				"comment_lines",
-				"comment_lines_data",
-				"comment_lines_density",
-				"complexity",
-//				"complexity_in_classes", // suppr en 25.1
-//				"complexity_in_functions", // suppr en 25.1
-				"conditions_to_cover",
-				"confirmed_issues",
-				"coverage",
-				"critical_violations",
-				"development_cost",
-//				"directories", // suppr en 10.2
-				"duplicated_blocks",
-				"duplicated_files",
-				"duplicated_lines",
-				"duplicated_lines_density",
-				"duplications_data",
-				"effort_to_reach_maintainability_rating_a",
-				"executable_lines_data",
-				"false_positive_issues",
-//				"file_complexity", // suppr en 25.1
-//				"file_complexity_distribution", // suppr en 25.1
-				"files",
-//				"function_complexity", // suppr en 25.1
-//				"function_complexity_distribution", // suppr en 25.1
-				"functions",
-				"generated_lines",
-				"generated_ncloc",
-				"info_violations",
-				"last_commit_date",
-				"line_coverage",
-				"lines",
-				"lines_to_cover",
-				"major_violations",
-				"minor_violations",
-				"ncloc",
-				"ncloc_data",
-				"ncloc_language_distribution",
-				"new_blocker_violations",
-				"new_branch_coverage",
-				"new_bugs",
-				"new_code_smells",
-				"new_conditions_to_cover",
-				"new_coverage",
-				"new_critical_violations",
-				"new_development_cost",
-				"new_duplicated_blocks",
-				"new_duplicated_lines",
-				"new_duplicated_lines_density",
-				"new_info_violations",
-				"new_line_coverage",
-				"new_lines",
-				"new_lines_to_cover",
-				"new_maintainability_rating",
-				"new_major_violations",
-				"new_minor_violations",
-				"new_reliability_rating",
-				"new_reliability_remediation_effort",
-				"new_security_hotspots",
-				"new_security_hotspots_reviewed",
-				"new_security_hotspots_reviewed_status",
-				"new_security_hotspots_to_review_status",
-				"new_security_rating",
-				"new_security_remediation_effort",
-				"new_security_review_rating",
-				"new_technical_debt",
-				"new_violations",
-				"new_vulnerabilities",
-				"open_issues",
-				"projects",
-				"public_api",
-				"public_documented_api_density",
-				"public_undocumented_api",
-				"quality_gate_details",
-				"quality_profiles",
-				"reliability_rating",
-				"reliability_remediation_effort",
-				"reopened_issues",
-				"security_hotspots",
-				"security_hotspots_reviewed",
-				"security_hotspots_reviewed_status",
-				"security_hotspots_to_review_status",
-				"security_rating",
-				"security_remediation_effort",
-				"security_review_rating",
-				"skipped_tests",
-				"sqale_rating",
-				"statements",
-				"unanalyzed_c",
-				"unanalyzed_cpp",
-				"violations"
-		);
-		return newWsClient(orchestrator)
-				.measures()
-				.component(
-						new ComponentRequest()
-								.setComponent(componentKey)
-								.setMetricKeys(metricKeys)
-				)
-				.getComponent().getMeasuresList()
-				.stream()
-				.collect(Collectors.toMap(Measures.Measure::getMetric, Function.identity()));
-	}
-
-	protected static WsClient newWsClient(Orchestrator orchestrator) {
-		return WsClientFactories.getDefault().newClient(HttpConnector.newBuilder()
-		                                                             .url(orchestrator.getServer().getUrl())
-		                                                             .build());
-	}
-
-	@Getter
-	protected static class ProjectToAnalyze {
-		private final Path pom;
-		private final String projectKey;
-		private final String projectName;
-
-		private ProjectToAnalyze(URI pom, String projectKey, String projectName) {
-			this.pom = Path.of(pom);
-			assertThat(this.pom).isRegularFile();
-			this.projectKey = projectKey;
-			this.projectName = projectName;
-		}
-
-		public MavenBuild createMavenBuild() {
-			return MavenBuild.create(pom.toFile())
-					.setCleanPackageSonarGoals()
-					.setProperty("sonar.projectKey", projectKey)
-					.setProperty("sonar.projectName", projectName)
-					.setProperty("sonar.scm.disabled", "true");
-		}
-
-		private void provisionProjectIntoServer(Server server) {
-			server.provisionProject(projectKey, projectName);
-
-		}
-
-		private void associateProjectToQualityProfile(Server server, Map qualityProfileByLanguage) {
-			qualityProfileByLanguage.forEach((language, profileName) -> server.associateProjectToQualityProfile(projectKey, language, profileName));
-		}
-	}
-
-}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesBase.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesBase.java
deleted file mode 100644
index 9084cb6b..00000000
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesBase.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package org.greencodeinitiative.creedengo.java.integration.tests;
-
-import org.assertj.core.groups.Tuple;
-import org.sonarqube.ws.Common;
-import org.sonarqube.ws.Components;
-import org.sonarqube.ws.Issues;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonarqube.ws.Common.RuleType.CODE_SMELL;
-import static org.sonarqube.ws.Common.Severity.MINOR;
-
-class GCIRulesBase extends BuildProjectEngine {
-
-    protected static final String[] EXTRACT_FIELDS = new String[]{
-            "rule", "message",
-//            "line"
-            "textRange.startLine", "textRange.endLine",
-//            "textRange.startOffset", "textRange.endOffset",
-            "severity", "type",
-//            "debt",
-            "effort"
-    };
-    protected static final Common.Severity SEVERITY = MINOR;
-    protected static final Common.RuleType TYPE = CODE_SMELL;
-    protected static final String EFFORT_1MIN = "1min";
-    protected static final String EFFORT_5MIN = "5min";
-    protected static final String EFFORT_10MIN = "10min";
-    protected static final String EFFORT_15MIN = "15min";
-    protected static final String EFFORT_20MIN = "20min";
-    protected static final String EFFORT_50MIN = "50min";
-
-    protected void checkIssuesForFile(String filePath, String ruleId, String ruleMsg, int[] startLines, int[] endLines) {
-        checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_5MIN);
-    }
-
-    protected void checkIssuesForFile(String filePath, String ruleId, String ruleMsg, int[] startLines, int[] endLines, Common.Severity severity, Common.RuleType type, String effort) {
-
-        assertThat(startLines.length)
-                .isEqualTo(endLines.length);
-
-        String projectKey = analyzedProjects.get(0).getProjectKey();
-
-        String componentKey = projectKey + ":" + filePath;
-
-//        System.out.println("--- COMPONENT KEY : " + componentKey);
-
-        // launch the search
-        Components.ShowWsResponse respComponent = showComponent(componentKey);
-        Components.Component comp = respComponent.getComponent();
-//        System.out.println("--- COMPONENT --- " + comp);
-//        System.out.println("--- COMPONENT KEY --- " + comp.getKey());
-//        System.out.println("--- COMPONENT PATH --- " + comp.getPath());
-//        System.out.println("--- PATH ok --- " + filePath.equals(comp.getPath()));
-        assertThat(filePath)
-            .withFailMessage("File not found: " + filePath)
-            .isEqualTo(comp.getPath());
-
-        // check issues
-        Issues.SearchWsResponse respIssues = searchIssuesForComponent(componentKey, ruleId);
-
-//		System.out.println("--- NB ISSUES : " + respIssues.getIssuesCount());
-//		System.out.println("--- NB ISSUES_LIST : " + respIssues.getIssuesList().size());
-//        respIssues.getIssuesList().forEach(issue -> {
-////			if (issue.getRule().equals("creedengo-java:GCI27")) {
-//				System.out.println("--- Issue --- " + issue.getRule() + " / " + issue.getLine());
-////			}
-//		});
-
-//        List issues = issuesForFile(projectKey, filePath, ruleId);
-        List issues = respIssues.getIssuesList();
-
-        List expectedTuples = new ArrayList<>();
-        for (int i = 0; i < startLines.length; i++) {
-            expectedTuples.add(Tuple.tuple(ruleId, ruleMsg, startLines[i], endLines[i], severity, type, effort));
-        }
-
-        assertThat(issues)
-                .hasSizeGreaterThanOrEqualTo(startLines.length)
-//                .hasSize(lines.length)
-                .extracting(EXTRACT_FIELDS)
-                .containsAll(expectedTuples);
-//                .containsExactlyElementsOf(expectedTuples);
-    }
-
-}
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
index eff99826..ff5bf687 100644
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
+++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
@@ -7,6 +7,8 @@
 import java.util.List;
 import java.util.Map;
 
+import org.greencodeinitiative.creedengo.integration.tests.GCIRulesBase;
+
 import static java.util.Optional.ofNullable;
 import static org.assertj.core.api.Assertions.assertThat;
 
diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/ProfileBackup.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/ProfileBackup.java
deleted file mode 100644
index 26feba22..00000000
--- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/ProfileBackup.java
+++ /dev/null
@@ -1,163 +0,0 @@
-package org.greencodeinitiative.creedengo.java.integration.tests.profile;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URL;
-import java.text.MessageFormat;
-import java.util.Base64;
-import java.util.List;
-import java.util.stream.Collectors;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
-
-/**
- * Manage XML Backup file of profile based on JSON official profile.
- *
- * 

Example, following JSON profile:

- *
- * {
- *  "name": "creedengo way",
- *  "language": "java",
- *  "ruleKeys": [
- * 	    "GCI1",
- * 	    "GCI2"
- *  ]
- * }
- * 
- *

may produce following XML profile:

- *
- * <?xml version='1.0' encoding='UTF-8'?>
- * <profile>
- * 	<name>creedengo way</name>
- * 	<language>java</language>
- * 	<rules>
- * 		<rule>
- * 			<repositoryKey>creedengo-java</repositoryKey>
- * 			<key>GCI1</key>
- * 			<type>CODE_SMELL</type>
- * 			<priority>MINOR</priority>
- * 			<parameters />
- * 		</rule>
- * 		<rule>
- * 			<repositoryKey>creedengo-java</repositoryKey>
- * 			<key>GCI2</key>
- * 			<type>CODE_SMELL</type>
- * 			<priority>MINOR</priority>
- * 			<parameters />
- * 		</rule>
- * 	</rules>
- * </profile>
- * 
- */ -public class ProfileBackup { - private static final MessageFormat TEMPLATE_PROFIL = new MessageFormat( - "\n" + - "\n" + - " {0}\n" + - " {1}\n" + - " \n" + - " {2}\n" + - " \n" + - "\n" - ); - private static final MessageFormat TEMPLATE_RULE = new MessageFormat( - "\n" + - " {0}\n" + - " {1}\n" + - " {2}\n" + - " {3}\n" + - " \n" + - "\n" - ); - - private final ObjectMapper mapper; - private final URI jsonProfile; - - public ProfileBackup(URI jsonProfile) { - this.mapper = new ObjectMapper(); - // Ignore unknown properties - this.mapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false); - - this.jsonProfile = jsonProfile; - } - - private transient ProfileMetadata profileMetadata; - - private ProfileMetadata profileMetadata() { - if (profileMetadata == null) { - try (InputStream profilJsonFile = jsonProfile.toURL().openStream()) { - profileMetadata = mapper.readValue(profilJsonFile, ProfileMetadata.class); - } catch (IOException e) { - throw new RuntimeException("Unable to load JSON Profile: " + jsonProfile, e); - } - } - return profileMetadata; - } - - private RuleMetadata loadRule(String language, String ruleKey) { - try (InputStream ruleMetadataJsonFile = ClassLoader.getSystemResourceAsStream("org/green-code-initiative/rules/" + language + "/" + ruleKey + ".json")) { - RuleMetadata result = mapper.readValue(ruleMetadataJsonFile, RuleMetadata.class); - result.setKey(ruleKey); - return result; - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - private String xmlProfile() throws IOException { - ProfileMetadata profileMetadata = profileMetadata(); - String language = profileMetadata.getLanguage(); - List rules = profileMetadata.getRuleKeys().stream() - .map(ruleKey -> this.loadRule(language, ruleKey)) - .collect(Collectors.toList()); - StringBuilder output = new StringBuilder(); - String repositoryKey = "creedengo-" + profileMetadata.getLanguage(); - rules.forEach(rule -> output.append( - xmlRule( - repositoryKey, - rule.getKey(), - rule.getType(), - rule.getDefaultSeverity().toUpperCase() - )) - ); - return TEMPLATE_PROFIL.format(new Object[]{ - profileMetadata.getName(), - profileMetadata.getLanguage(), - output.toString() - }); - } - - private String xmlRule(String repositoryKey, String key, String type, String priority) { - return TEMPLATE_RULE.format(new Object[]{ - repositoryKey, - key, - type, - priority - }); - } - - /** - * Get the content of XML Profil in datauri format. - */ - public URL profileDataUri() { - try { - String xmlProfileContent = xmlProfile(); - String xmlProfileBase64encoded = Base64.getEncoder().encodeToString(xmlProfileContent.getBytes()); - return new URL("data:text/xml;base64," + xmlProfileBase64encoded); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public String language() { - return profileMetadata().getLanguage(); - } - - - public String name() { - return profileMetadata().getName(); - } -} diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/ProfileMetadata.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/ProfileMetadata.java deleted file mode 100644 index 80789148..00000000 --- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/ProfileMetadata.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.greencodeinitiative.creedengo.java.integration.tests.profile; - -import java.util.List; - -public class ProfileMetadata { - private String name; - private String language; - private List ruleKeys; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getLanguage() { - return language; - } - - public void setLanguage(String language) { - this.language = language; - } - - public List getRuleKeys() { - return ruleKeys; - } - - public void setRuleKeys(List ruleKeys) { - this.ruleKeys = ruleKeys; - } - - @Override - public String toString() { - return "ProfileMetadata{" + - "name='" + name + '\'' + - ", language='" + language + '\'' + - ", ruleKeys=" + ruleKeys + - '}'; - } -} diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/RuleMetadata.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/RuleMetadata.java deleted file mode 100644 index 8f6bc99f..00000000 --- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/profile/RuleMetadata.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.greencodeinitiative.creedengo.java.integration.tests.profile; - -public class RuleMetadata { - private String key; - private String type; - private String defaultSeverity; - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getDefaultSeverity() { - return defaultSeverity; - } - - public void setDefaultSeverity(String defaultSeverity) { - this.defaultSeverity = defaultSeverity; - } - - @Override - public String toString() { - return "RuleMetadata{" + - "key='" + key + '\'' + - ", type='" + type + '\'' + - ", defaultSeverity='" + defaultSeverity + '\'' + - '}'; - } -} From 95163709d7aba9facaa411b59d28f07a38a206e9 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Mon, 12 Jan 2026 22:43:36 +0100 Subject: [PATCH 170/233] correction of github action build - BIS --- pom.xml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 9c136942..e3e5cfef 100644 --- a/pom.xml +++ b/pom.xml @@ -46,9 +46,9 @@ ${java.version} - UTF-8 - ${encoding} - ${encoding} + + UTF-8 + UTF-8 green-code-initiative https://sonarcloud.io @@ -91,7 +91,8 @@ - 25.12.0.117093 + + 26.1.0.118079 ${sonarjava.version} From 254b1234ba888e20e43e68cb7e21520765d5519a Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Mon, 12 Jan 2026 23:36:17 +0100 Subject: [PATCH 171/233] correction warning console --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index e3e5cfef..19648835 100644 --- a/pom.xml +++ b/pom.xml @@ -246,6 +246,7 @@
report + verify report From 9646ab3d3b9ec8be3523c959b2f5e91408dd669b Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 13 Jan 2026 22:12:57 +0100 Subject: [PATCH 172/233] update component integration test --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 19648835..70d6844a 100644 --- a/pom.xml +++ b/pom.xml @@ -185,7 +185,7 @@ org.green-code-initiative creedengo-integration-test - main-SNAPSHOT + 0.2.1 test From 7eef89fdfbae82006ca2ab6bc1c95a40f457f880 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 13 Jan 2026 22:17:05 +0100 Subject: [PATCH 173/233] clean --- pom.xml | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/pom.xml b/pom.xml index 70d6844a..615dbca9 100644 --- a/pom.xml +++ b/pom.xml @@ -189,36 +189,6 @@ test
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 481741cc58464e879e4b64827e2022458a35e449 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 13 Jan 2026 22:19:15 +0100 Subject: [PATCH 174/233] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9449d30..cc01b8d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- update integration tests system to use the new component "creedengo-integration-test" + ### Deleted ## [2.1.2] - 2026-01-11 From 86b5bdc2964824ddfa0d233121fbcc9fd62a41d7 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 13 Jan 2026 22:44:19 +0100 Subject: [PATCH 175/233] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc01b8d6..49c9c918 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - update integration tests system to use the new component "creedengo-integration-test" +- compatibility updates for SonarQube 26.1.0 ### Deleted From f7f363808ab36a02f935ca50f56c1676f0a7fa89 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 13 Jan 2026 23:18:31 +0100 Subject: [PATCH 176/233] update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 615dbca9..17f89bfd 100644 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,7 @@ 2.6.7 - https://repo1.maven.org/maven2 + false From 57903930aa8b500e85eb08a5a3866e5a1bef7a34 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 13 Jan 2026 23:26:00 +0100 Subject: [PATCH 177/233] update pom.xml --- CHANGELOG.md | 1 - pom.xml | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49c9c918..cc01b8d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - update integration tests system to use the new component "creedengo-integration-test" -- compatibility updates for SonarQube 26.1.0 ### Deleted diff --git a/pom.xml b/pom.xml index 17f89bfd..5899b91c 100644 --- a/pom.xml +++ b/pom.xml @@ -91,8 +91,8 @@ - - 26.1.0.118079 + 25.12.0.117093 + ${sonarjava.version} From eb2ef32217e48651283c46cfa3b0c5856a0c3b7c Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Wed, 14 Jan 2026 11:41:39 +0100 Subject: [PATCH 178/233] update pom.xml / changelog --- CHANGELOG.md | 1 + pom.xml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc01b8d6..49c9c918 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - update integration tests system to use the new component "creedengo-integration-test" +- compatibility updates for SonarQube 26.1.0 ### Deleted diff --git a/pom.xml b/pom.xml index 5899b91c..f74adfdb 100644 --- a/pom.xml +++ b/pom.xml @@ -91,8 +91,8 @@ - 25.12.0.117093 - + + 26.1.0.118079 ${sonarjava.version} From e4938e4464f12097a3b3204e50b21fcd6e4cd4de Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 15 Jan 2026 00:10:28 +0100 Subject: [PATCH 179/233] correction of artifact download --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f74adfdb..1ac5f7b6 100644 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,7 @@ 2.6.7 - + https://repo1.maven.org/maven2 false @@ -99,6 +99,7 @@ +
From 82e3ed188e7e439046011dfe08ea88eefcb44a12 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 15 Jan 2026 00:12:48 +0100 Subject: [PATCH 180/233] revert to soanrqube 25.12 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 1ac5f7b6..e1e07426 100644 --- a/pom.xml +++ b/pom.xml @@ -91,8 +91,8 @@ - - 26.1.0.118079 + 25.12.0.117093 + ${sonarjava.version} From 60d13920b6f98744cbe96f563af4a4fd061559f0 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 15 Jan 2026 07:21:33 +0100 Subject: [PATCH 181/233] correction for sonar analysis on gthub action --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4052eda6..24419a56 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -46,4 +46,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: ./mvnw -e -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=green-code-initiative_creedengo-java + run: ./mvnw -e -B org.sonarsource.scanner.maven:sonar-maven-plugin:3.11.0.3922:sonar -Dsonar.projectKey=green-code-initiative_creedengo-java From 3e1d17141b192e8666876893446b136a79bfbf1c Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 15 Jan 2026 07:29:23 +0100 Subject: [PATCH 182/233] update build.yml --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 24419a56..b71528f2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,6 @@ on: - main paths-ignore: - "*.md" - - ".github/**/*.yml" tags: - "[0-9]+.[0-9]+.[0-9]+" pull_request: From cbc186e28f2113cd5a880c0d86563b4584a2416c Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 15 Jan 2026 07:39:07 +0100 Subject: [PATCH 183/233] update for sonar error on github action --- .github/workflows/build.yml | 7 +++++- pom.xml | 49 +++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b71528f2..00f858d6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,6 +30,11 @@ jobs: java-version: 17 cache: maven + - name: Configure Maven for Sonar + run: | + mkdir -p ~/.m2 + echo "org.sonarsource.scanner.maven" > ~/.m2/settings.xml + - name: Verify run: ./mvnw -e -B verify @@ -45,4 +50,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: ./mvnw -e -B org.sonarsource.scanner.maven:sonar-maven-plugin:3.11.0.3922:sonar -Dsonar.projectKey=green-code-initiative_creedengo-java + run: ./mvnw -e -B sonar:sonar -Dsonar.projectKey=green-code-initiative_creedengo-java diff --git a/pom.xml b/pom.xml index e1e07426..c89bbdfc 100644 --- a/pom.xml +++ b/pom.xml @@ -193,7 +193,21 @@ + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + 3.11.0.3922 + + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + 3.11.0.3922 + org.apache.maven.plugins maven-compiler-plugin @@ -491,6 +505,41 @@ keep-running true + + 33333 + + + + + + + sonar + + + env.SONAR_TOKEN + + + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + + + verify + + sonar + + + + + + + + + keep-running + + true 33333 From 27fcd9f6a98a8c2de56889d0f6dd56e079661612 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 15 Jan 2026 07:45:54 +0100 Subject: [PATCH 184/233] update for sonar error on github action - BIS --- pom.xml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/pom.xml b/pom.xml index c89bbdfc..86f2f51e 100644 --- a/pom.xml +++ b/pom.xml @@ -203,11 +203,6 @@ - - org.sonarsource.scanner.maven - sonar-maven-plugin - 3.11.0.3922 - org.apache.maven.plugins maven-compiler-plugin @@ -509,9 +504,6 @@ 33333
- - - sonar @@ -536,13 +528,5 @@
- - keep-running - - true - - 33333 - - From 61b2650d5dfc85e01873eef36dc208e2b9a42df2 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 15 Jan 2026 08:00:51 +0100 Subject: [PATCH 185/233] update for sonar error on github action - TER --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 00f858d6..0be9aad0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,4 +50,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: ./mvnw -e -B sonar:sonar -Dsonar.projectKey=green-code-initiative_creedengo-java + run: ./mvnw -e -B sonar:sonar -Dsonar.projectKey=green-code-initiative_creedengo-java -Dsonar.organization=green-code-initiative From ae0d5710eb45e1e10c826899fc6596f6e3ecf254 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 15 Jan 2026 22:05:43 +0100 Subject: [PATCH 186/233] github action build : add manual running --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0be9aad0..b567e879 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,7 @@ on: - "[0-9]+.[0-9]+.[0-9]+" pull_request: types: [opened, synchronize, reopened] + workflow_dispatch: jobs: build: From a6c43269dcbf7dd65f8a34008c6ce524731b0a96 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 15 Jan 2026 22:12:30 +0100 Subject: [PATCH 187/233] disable profile maven 'sonar' --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 86f2f51e..617039ff 100644 --- a/pom.xml +++ b/pom.xml @@ -504,7 +504,7 @@ 33333
- + From 3f524fb0e858a6132c86ee5d94f8a0199c738df9 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 15 Jan 2026 22:17:07 +0100 Subject: [PATCH 188/233] clean pom.xml --- pom.xml | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/pom.xml b/pom.xml index 617039ff..6a7946a7 100644 --- a/pom.xml +++ b/pom.xml @@ -504,29 +504,5 @@ 33333 - From 6bddbade4a6dd3a2597d28435aabf7d37b4ecb0d Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 15 Jan 2026 22:55:57 +0100 Subject: [PATCH 189/233] clean build.yml --- .github/workflows/build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b567e879..bbab13b8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,6 +31,8 @@ jobs: java-version: 17 cache: maven + # to be able to use "sonar:sonar" instead of "org.sonarsource.scanner.maven:sonar-maven-plugin:sonar" + # inside this build but also when the test project analysis is launched with sonar:sonar - name: Configure Maven for Sonar run: | mkdir -p ~/.m2 @@ -51,4 +53,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: ./mvnw -e -B sonar:sonar -Dsonar.projectKey=green-code-initiative_creedengo-java -Dsonar.organization=green-code-initiative + run: ./mvnw -e -B sonar:sonar -Dsonar.projectKey=green-code-initiative_creedengo-java From 2b65925d5a5cd700ec5c0c2e9f19f3b2d53436c1 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 15 Jan 2026 23:07:13 +0100 Subject: [PATCH 190/233] update changelog and pom.xml --- CHANGELOG.md | 1 - pom.xml | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49c9c918..cc01b8d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - update integration tests system to use the new component "creedengo-integration-test" -- compatibility updates for SonarQube 26.1.0 ### Deleted diff --git a/pom.xml b/pom.xml index 6a7946a7..cd6491b8 100644 --- a/pom.xml +++ b/pom.xml @@ -91,8 +91,10 @@ - 25.12.0.117093 - + + + + 26.1.0.118079 ${sonarjava.version} From d415aed286e2929052921126d56e303ffe222bc2 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 15 Jan 2026 23:07:34 +0100 Subject: [PATCH 191/233] update changelog and pom.xml - BIS --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cd6491b8..5c450e50 100644 --- a/pom.xml +++ b/pom.xml @@ -94,7 +94,7 @@ - 26.1.0.118079 + 26.1.0.118079 ${sonarjava.version} From 235bb583ab62fa80c2eb583f4d3d7e4c5557ab9c Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 15 Jan 2026 23:11:22 +0100 Subject: [PATCH 192/233] revert to sonarqube 25.12.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 5c450e50..ccbe96b5 100644 --- a/pom.xml +++ b/pom.xml @@ -91,10 +91,10 @@ - + 25.12.0.117093 - 26.1.0.118079 + ${sonarjava.version} From 092f247e6be4f0c88af13714ab81cf911a501eb0 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 20 Jan 2026 00:13:01 +0100 Subject: [PATCH 193/233] update tech --- .github/dependabot.yml | 2 -- .github/workflows/build.yml | 9 +++++---- pom.xml | 10 +++++----- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 5d53e306..7a77aa9c 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -10,8 +10,6 @@ updates: schedule: interval: "weekly" ignore: - # Ignore all versions : cf pom.xml comments - - dependency-name: "org.sonarsource.java:sonar-java-plugin" # Ignore all versions : cf pom.xml comments - dependency-name: "com.mycila:license-maven-plugin" - dependency-name: "org.springframework.data:spring-data-commons" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bbab13b8..bad37f2a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,7 +29,7 @@ jobs: with: distribution: "temurin" java-version: 17 - cache: maven + cache: maven # enable maven cache shared by all github actions build # to be able to use "sonar:sonar" instead of "org.sonarsource.scanner.maven:sonar-maven-plugin:sonar" # inside this build but also when the test project analysis is launched with sonar:sonar @@ -38,9 +38,7 @@ jobs: mkdir -p ~/.m2 echo "org.sonarsource.scanner.maven" > ~/.m2/settings.xml - - name: Verify - run: ./mvnw -e -B verify - + # enable sonarqube downloads cache shared by all github actions build - name: Cache SonarQube packages uses: actions/cache@v4 with: @@ -48,6 +46,9 @@ jobs: key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar + - name: Verify + run: ./mvnw -e -B verify + - name: SonarQube Scan if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository env: diff --git a/pom.xml b/pom.xml index ccbe96b5..9368778c 100644 --- a/pom.xml +++ b/pom.xml @@ -195,7 +195,7 @@ - + org.apache.maven.plugins @@ -213,7 +213,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.5.3 + 3.5.4 org.jacoco @@ -277,7 +277,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.6.0 + 3.6.1 package @@ -459,7 +459,7 @@ org.apache.maven.plugins maven-failsafe-plugin - 3.5.3 + 3.5.4 From 9d372eb0ce3111c821873a3a9480e59a94a6484d Mon Sep 17 00:00:00 2001 From: Renaud Rousset Date: Thu, 3 Oct 2024 09:44:40 +0000 Subject: [PATCH 194/233] [69] NullPointer exception in eco code java Sonar plugin --- CHANGELOG.md | 4 +- ...FreeResourcesOfAutoCloseableInterface.java | 3 ++ ...reeResourcesOfAutoCloseableInterface2.java | 45 +++++++++++++++++++ ...ResourcesOfAutoCloseableInterfaceTest.java | 7 +++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/test/files/FreeResourcesOfAutoCloseableInterface2.java diff --git a/CHANGELOG.md b/CHANGELOG.md index cc01b8d6..3676f22d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- update integration tests system to use the new component "creedengo-integration-test" +- [#49](https://github.com/green-code-initiative/ecoCode-java/pull/49) Add test to ensure all Rules are registered +- [#336](https://github.com/green-code-initiative/ecoCode/issues/336) [Adds Maven Wrapper](https://github.com/green-code-initiative/ecoCode-java/pull/67) +- [#69](https://github.com/green-code-initiative/ecoCode-java/pull/69) correction of NullPointer in EC79 rule ### Deleted diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java index 2b669145..db41c626 100644 --- a/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java +++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java @@ -74,6 +74,9 @@ public void visitNode(Tree tree) { @Override public void leaveNode(Tree tree) { if (tree.is(Tree.Kind.TRY_STATEMENT)) { + if(!withinTry.isEmpty()) { + withinTry.pop(); + } List secondaryTrees = toReport.pop(); if (!secondaryTrees.isEmpty()) { reportIssue(tree, MESSAGE_RULE); diff --git a/src/test/files/FreeResourcesOfAutoCloseableInterface2.java b/src/test/files/FreeResourcesOfAutoCloseableInterface2.java new file mode 100644 index 00000000..b72ba6a7 --- /dev/null +++ b/src/test/files/FreeResourcesOfAutoCloseableInterface2.java @@ -0,0 +1,45 @@ +package files; + +import java.io.FileWriter; +import java.io.IOException; + +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +public class FreeResourcesOfAutoCloseableInterface2 { + + /** + * The first methods adds a "try" in the stack used to follow if the code is in a try + */ + public void callingMethodWithTheTry() throws IOException { + try { + calledMethodWithoutTry(); + } finally { + // Empty block of code + } + } + + /** + * The "try" should have been poped from the stack before entering here + */ + private void calledMethodWithoutTry() throws IOException { + FileWriter myWriter = new FileWriter("somefilepath"); + myWriter.write("something"); + myWriter.flush(); + myWriter.close(); + } +} \ No newline at end of file diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java index aecce2d7..89d8c12c 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java @@ -38,4 +38,11 @@ void test_no_java_version() { .withCheck(new FreeResourcesOfAutoCloseableInterface()) .verifyIssues(); } + @Test + void test_when_try_before_auto_closeable_but_different_hierarchy_of_code() { + CheckVerifier.newVerifier() + .onFile("src/test/files/FreeResourcesOfAutoCloseableInterface2.java") + .withCheck(new FreeResourcesOfAutoCloseableInterface()) + .verifyNoIssues(); + } } From a10988128b8ea72ba03b9e0a458ce5c4c385432a Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Wed, 11 Feb 2026 23:26:11 +0100 Subject: [PATCH 195/233] refactoring GCI79 + NPE correction from PR 70 --- IA_description.md | 88 ++++++++++++ IA_rule.md | 33 +++++ ...FreeResourcesOfAutoCloseableInterface.java | 21 +++ ...FreeResourcesOfAutoCloseableInterface.java | 126 +++++++++++++----- ...FreeResourcesOfAutoCloseableInterface.java | 25 +++- ...reeResourcesOfAutoCloseableInterface2.java | 45 ------- ...ResourcesOfAutoCloseableInterfaceTest.java | 10 +- 7 files changed, 263 insertions(+), 85 deletions(-) create mode 100644 IA_description.md create mode 100644 IA_rule.md delete mode 100644 src/test/files/FreeResourcesOfAutoCloseableInterface2.java diff --git a/IA_description.md b/IA_description.md new file mode 100644 index 00000000..6c7bf66e --- /dev/null +++ b/IA_description.md @@ -0,0 +1,88 @@ +This file contains the technical description of the project + +Global description +--- +This project is a SonarQube plugin project and it is named "creedengo-java". +This plugin is for Java project analysis. +When this plugin is installed inside SonarQube, it adds some new rules for Java language analysis. +The new rules can be added to an existing Java quality profile or to a new Java quality profile. +A Sonarqube quality profile must be associated to only one programming language. +A quality profile can be the default quality profile for one language (here Java language), thus +all future Java project analysis will be done by default with this quality profile. +If a quality profile is not the default, a specific project (already analysed) can be associated with this +quality profile. + +Technical description +--- +Important elements of the plugin : +- the plugin contains a list of rule implementations +- each rule has a unique rule id +- each rule is implemented by one class +- there are several tests for each implementation rule class with several ressource files containing compliant code or / and non compliant code + +The implementation code is in src/main/java. + +Sonarqube analysis are based on the navigation inside the code to detect bad practices and to raise an issue when detected. +The code navigation is done through the AST principle. + +Implementation Structure +--- +- rule implementations : inside the package org.greencodeinitiative.creedengo.java.checks +- each implementation class has the same code template : + - "Rule" annotation : to give the rule id + - the rule id is previously defined in another maven component named "creedengo-rules-specifications" + - to enable a rule, the rule id must be added in the resources file named "creedengo_way_profile.json" + - extends a SonarQube API class "IssuableSubscriptionVisitor" + - "initialize" method (forom super-class) to declare for which AST node type, the analysis will deeply analyse the code. + - each "registerSyntaxNodeConsumer" method call implies that the node will be deeply analyzed. + - For each, a new private method is given to implement the deeply analysis and raise an issue if needed. +- to have a plugin working with activated rules, the Sonarqube plugin development guidelines is followed + - "JavaPlugin" : enable 2 following extensions + - "JavaRuleRepository" : extension containing the definition of the plugin and the list of implemented rule classes + - "JavaCreedengoWayProfile" : extension containing the definition a the quality profile (and rules activated inside) created with the plugin installation + +Unit Tests Implementation Structure +--- +Inside the "test/java" directory, there are unit tests for each class of the plugin. +The package "org.greencodeinitiative.creedengo.java.checks" contains one unit test class for each rule implementation class + +Each unit test class checking rule implementation class has the same template of code : +- at least one test method using the "CheckVerifier" class to check and simulate a SonarQube analysis + - usage of "CheckVerifier.verify" to check if there is some issues raised or not + - usage of "CheckVerifier.verifyNoIssues" to check there is no issues raised +- each call to "CheckVerifier" needs a test resource file : this one is the resource code file for the simulated analysis + +each test resource file is in the "test/resources/checks" directory (or sub-directories). +each test resource file contains compliuant code or / and non compliant code. +If there is no compliant code on which Sonarqube analysis should raise an issue, the line with the issue has a comment at the end of the line with the following template : +"# Noncompliant {{ERROR_MESSAGE_TO_DISPLAY}}" + - the "ERROR_MESSAGE_TO_DISPLAY" in the previous template is replaced by the real error message. + - this comment give the information to "CheckVerifier", the simulation tool, that an error is expected at this line + +Integration Tests Implementation Structure +--- +Inside the "it/java" directory, there are integration tests for each class of the plugin. +The package "org.greencodeinitiative.creedengo.java.integration.tests" contains one unit test class with one method for each rule. + +The integration test class extends the common class "GCIRulesBase" to use the system to initialize integration test. + +Integration test system process exists to check in a local and real environment that all implemented rules do the raises expected issues. + +The "src/it/test-projects" directory contains a real project to analyse. + +Here is the process +- build the plugin project +- download and launch a specific sonarqube version in local machine +- install the built plugin inside sonarqube +- create a specific default quality profile with all rules of the plugin installed +- launch the analysis of the test-project +- send analysis result to local sonarqube +- check the result of the analysis in front of expected results describe inside each test method + +Each test method describe different elements to check inside the result analysis : +- the relative path of each resource test file inside de test-project +- the complete rule id containing 2 parts : the plugin id ("creedengo-java") and the rule id (ex : "GCI2") +- the rule error message +- the lines where errors shoudl be raised : there are 2 arrays with the same size representing the start line and the end line of each issue raised + +Each test method ends with a call of a common method with all these parameters input. diff --git a/IA_rule.md b/IA_rule.md new file mode 100644 index 00000000..da6d5f55 --- /dev/null +++ b/IA_rule.md @@ -0,0 +1,33 @@ +Rule Implementation Plan +--- + +# Rule Implementation Methodology + +Use the TDD (Test-Driven Development) methodology to implement a rule in an efficient and structured way. + +# Rule Implementation Process + +## STEP 1: Define unit test resources + technical shell of the rule +- Define test resources for the rule to be implemented with all possible cases: + - Compliant code + - Non-compliant code + - Code with elements that should not be analyzed +- Location of test resource files: + - Files for unit tests: in "test/resources/checks" or subdirectories + - Files for integration tests: in "src/it/test-projects" or subdirectories +- Create the rule implementation class in the package "org.greencodeinitiative.creedengo.java.checks" + - Add the "Rule" annotation with the correct rule id (the rule is previously defined in another maven component named "creedengo-rules-specifications") + - Extend the "IssuableSubscriptionVisitor" class + - Implement the "initialize" method which will be used to declare the AST node types to analyze in depth but leave it empty for now +- Create the rule unit test class in the package "org.greencodeinitiative.creedengo.java.checks" +- Verify that unit tests fail with non-compliant test resources + +## STEP 2: Implement the rule + unit test validation +- Implement the rule in the implementation class created in step 1 +- Implement the "initialize" method to declare the AST node types to analyze in depth +- Implement private methods to analyze in depth the declared AST nodes and raise issues if needed +- Verify that unit tests pass with both compliant and non-compliant test resources + +## STEP 3: Implement integration tests +- Add a test method in the integration class "GCIRulesIT" for the implemented rule using the same pattern as other existing test methods +- Verify that integration tests pass with both compliant and non-compliant test resources diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java index 95ed3506..23274f6f 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java @@ -35,4 +35,25 @@ public void foo2() throws IOException { } } } + + /** + * The first methods adds a "try" in the stack used to follow if the code is in a try + */ + public void callingMethodWithTheTry() throws IOException { + try { // Compliant + calledMethodWithoutTry(); + } finally { + // Empty block of code + } + } + + /** + * The "try" should have been poped from the stack before entering here + */ + private void calledMethodWithoutTry() throws IOException { + FileWriter myWriter = new FileWriter("somefilepath"); + myWriter.write("something"); + myWriter.flush(); + myWriter.close(); + } } diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java index db41c626..0db0d94b 100644 --- a/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java +++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java @@ -17,30 +17,43 @@ */ package org.greencodeinitiative.creedengo.java.checks; +import java.util.ArrayDeque; import java.util.ArrayList; -import java.util.Arrays; import java.util.Deque; -import java.util.LinkedList; import java.util.List; +import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.JavaFileScannerContext; -import org.sonar.plugins.java.api.JavaVersion; import org.sonar.plugins.java.api.tree.NewClassTree; import org.sonar.plugins.java.api.tree.Tree; import org.sonar.plugins.java.api.tree.TryStatementTree; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; - +/** + * This rule checks that objects implementing AutoCloseable interface are properly managed + * using try-with-resources statement instead of try-finally blocks. + *

+ * Try-with-resources ensures proper resource management and reduces the risk of resource leaks. + * It also reduces boilerplate code and improves code readability. + *

+ * From an environmental perspective, proper resource management prevents resource leaks + * which can lead to increased memory consumption and unnecessary CPU cycles. + * + * @see Try-with-resources + */ @Rule(key = "GCI79") @DeprecatedRuleKey(repositoryKey = "ecocode-java", ruleKey = "EC79") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S79") public class FreeResourcesOfAutoCloseableInterface extends IssuableSubscriptionVisitor { - private final Deque withinTry = new LinkedList<>(); - private final Deque> toReport = new LinkedList<>(); + + /** + * Stack to track nested try statements while traversing the AST + */ + private final Deque tryStack = new ArrayDeque<>(); private static final String JAVA_LANG_AUTOCLOSEABLE = "java.lang.AutoCloseable"; protected static final String MESSAGE_RULE = "try-with-resources Statement needs to be implemented for any object that implements the AutoClosable interface."; @@ -48,49 +61,102 @@ public class FreeResourcesOfAutoCloseableInterface extends IssuableSubscriptionV @Override @ParametersAreNonnullByDefault public void leaveFile(JavaFileScannerContext context) { - withinTry.clear(); - toReport.clear(); + tryStack.clear(); } @Override + @Nonnull public List nodesToVisit() { - return Arrays.asList(Tree.Kind.TRY_STATEMENT, Tree.Kind.NEW_CLASS); + return List.of(Tree.Kind.TRY_STATEMENT, Tree.Kind.NEW_CLASS); } @Override - public void visitNode(Tree tree) { + public void visitNode(@Nonnull Tree tree) { if (tree.is(Tree.Kind.TRY_STATEMENT)) { - withinTry.push((TryStatementTree) tree); - if (withinTry.size() != toReport.size()) { - toReport.push(new ArrayList<>()); - } - } - if (tree.is(Tree.Kind.NEW_CLASS) && ((NewClassTree) tree).symbolType().isSubtypeOf(JAVA_LANG_AUTOCLOSEABLE) && withinStandardTryWithFinally()) { - assert toReport.peek() != null; - toReport.peek().add(tree); + handleTryStatement((TryStatementTree) tree); + } else if (tree.is(Tree.Kind.NEW_CLASS)) { + handleNewClass((NewClassTree) tree); } } @Override - public void leaveNode(Tree tree) { + public void leaveNode(@Nonnull Tree tree) { if (tree.is(Tree.Kind.TRY_STATEMENT)) { - if(!withinTry.isEmpty()) { - withinTry.pop(); + leaveTryStatement(); + } + } + + /** + * Handle entering a try statement by pushing it onto the stack + */ + private void handleTryStatement(@Nonnull TryStatementTree tryStatement) { + tryStack.push(new TryStatementContext(tryStatement)); + } + + /** + * Handle leaving a try statement by popping it from the stack and reporting issues if needed + */ + private void leaveTryStatement() { + if (!tryStack.isEmpty()) { + TryStatementContext context = tryStack.pop(); + if (!context.autoCloseableInstances.isEmpty()) { + reportIssue(context.tryStatement, MESSAGE_RULE); } - List secondaryTrees = toReport.pop(); - if (!secondaryTrees.isEmpty()) { - reportIssue(tree, MESSAGE_RULE); + } + } + + /** + * Handle new class instantiation to detect AutoCloseable objects + * that are created inside a try-finally block (without try-with-resources) + */ + private void handleNewClass(@Nonnull NewClassTree newClass) { + // Check if the new instance is an AutoCloseable + if (!newClass.symbolType().isSubtypeOf(JAVA_LANG_AUTOCLOSEABLE)) { + return; + } + + // Check if we are inside a non-compliant try statement + if (isInNonCompliantTry()) { + TryStatementContext context = tryStack.peek(); + if (context != null) { + context.autoCloseableInstances.add(newClass); } } } - private boolean withinStandardTryWithFinally() { - if (withinTry.isEmpty() || !withinTry.peek().resourceList().isEmpty()) return false; - assert withinTry.peek() != null; - return withinTry.peek().finallyBlock() != null; + /** + * Check if we are currently inside a try statement that: + * - Does NOT use try-with-resources (no resource list) + * - Has a finally block (indicating manual resource management) + * + * @return true if inside a non-compliant try statement + */ + private boolean isInNonCompliantTry() { + if (tryStack.isEmpty()) { + return false; + } + + TryStatementTree currentTry = tryStack.peek().tryStatement; + + // If try-with-resources is already used, it's compliant + if (!currentTry.resourceList().isEmpty()) { + return false; + } + + // If there's a finally block, it suggests manual resource management + return currentTry.finallyBlock() != null; } - public boolean isCompatibleWithJavaVersion(JavaVersion version) { - return version.isJava7Compatible(); + /** + * Context class to track information about a try statement during AST traversal + */ + private static class TryStatementContext { + final TryStatementTree tryStatement; + final List autoCloseableInstances; + + TryStatementContext(@Nonnull TryStatementTree tryStatement) { + this.tryStatement = tryStatement; + this.autoCloseableInstances = new ArrayList<>(); + } } } diff --git a/src/test/files/FreeResourcesOfAutoCloseableInterface.java b/src/test/files/FreeResourcesOfAutoCloseableInterface.java index 08ba1622..51274ecb 100644 --- a/src/test/files/FreeResourcesOfAutoCloseableInterface.java +++ b/src/test/files/FreeResourcesOfAutoCloseableInterface.java @@ -27,7 +27,7 @@ class FreeResourcesOfAutoCloseableInterface { public void foo1() { String fileName = "./FreeResourcesOfAutoCloseableInterface.java"; try (FileReader fr = new FileReader(fileName); - BufferedReader br = new BufferedReader(fr)) { + BufferedReader br = new BufferedReader(fr)) { // Compliant } catch (IOException e) { System.err.println(e.getMessage()); } @@ -35,7 +35,7 @@ public void foo1() { public void foo2() { String fileName = "./FreeResourcesOfAutoCloseableInterface.java"; - try { // Noncompliant + try { // Noncompliant {{try-with-resources Statement needs to be implemented for any object that implements the AutoClosable interface.}} FileReader fr = new FileReader(fileName); BufferedReader br = new BufferedReader(fr); System.out.printl(br.readLine()); @@ -50,4 +50,25 @@ public void foo2() { } } } + + /** + * The first methods adds a "try" in the stack used to follow if the code is in a try + */ + public void callingMethodWithTheTry() throws IOException { + try { // Compliant + calledMethodWithoutTry(); + } finally { + // Empty block of code + } + } + + /** + * The "try" should have been poped from the stack before entering here + */ + private void calledMethodWithoutTry() throws IOException { + FileWriter myWriter = new FileWriter("somefilepath"); + myWriter.write("something"); + myWriter.flush(); + myWriter.close(); + } } diff --git a/src/test/files/FreeResourcesOfAutoCloseableInterface2.java b/src/test/files/FreeResourcesOfAutoCloseableInterface2.java deleted file mode 100644 index b72ba6a7..00000000 --- a/src/test/files/FreeResourcesOfAutoCloseableInterface2.java +++ /dev/null @@ -1,45 +0,0 @@ -package files; - -import java.io.FileWriter; -import java.io.IOException; - -/* - * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -public class FreeResourcesOfAutoCloseableInterface2 { - - /** - * The first methods adds a "try" in the stack used to follow if the code is in a try - */ - public void callingMethodWithTheTry() throws IOException { - try { - calledMethodWithoutTry(); - } finally { - // Empty block of code - } - } - - /** - * The "try" should have been poped from the stack before entering here - */ - private void calledMethodWithoutTry() throws IOException { - FileWriter myWriter = new FileWriter("somefilepath"); - myWriter.write("something"); - myWriter.flush(); - myWriter.close(); - } -} \ No newline at end of file diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java index 89d8c12c..36ebb256 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java @@ -23,7 +23,7 @@ class FreeResourcesOfAutoCloseableInterfaceTest { @Test - void test() { + void test_with_java7() { CheckVerifier.newVerifier() .onFile("src/test/files/FreeResourcesOfAutoCloseableInterface.java") .withCheck(new FreeResourcesOfAutoCloseableInterface()) @@ -38,11 +38,5 @@ void test_no_java_version() { .withCheck(new FreeResourcesOfAutoCloseableInterface()) .verifyIssues(); } - @Test - void test_when_try_before_auto_closeable_but_different_hierarchy_of_code() { - CheckVerifier.newVerifier() - .onFile("src/test/files/FreeResourcesOfAutoCloseableInterface2.java") - .withCheck(new FreeResourcesOfAutoCloseableInterface()) - .verifyNoIssues(); - } + } From 91013169df8e07ba31adfa95c3e6de8d8f2e6dd8 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Wed, 11 Feb 2026 23:35:30 +0100 Subject: [PATCH 196/233] optim github action buildt --- .github/workflows/build.yml | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bad37f2a..0be9aad0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,6 @@ on: - "[0-9]+.[0-9]+.[0-9]+" pull_request: types: [opened, synchronize, reopened] - workflow_dispatch: jobs: build: @@ -29,16 +28,16 @@ jobs: with: distribution: "temurin" java-version: 17 - cache: maven # enable maven cache shared by all github actions build + cache: maven - # to be able to use "sonar:sonar" instead of "org.sonarsource.scanner.maven:sonar-maven-plugin:sonar" - # inside this build but also when the test project analysis is launched with sonar:sonar - name: Configure Maven for Sonar run: | mkdir -p ~/.m2 echo "org.sonarsource.scanner.maven" > ~/.m2/settings.xml - # enable sonarqube downloads cache shared by all github actions build + - name: Verify + run: ./mvnw -e -B verify + - name: Cache SonarQube packages uses: actions/cache@v4 with: @@ -46,12 +45,9 @@ jobs: key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar - - name: Verify - run: ./mvnw -e -B verify - - name: SonarQube Scan if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: ./mvnw -e -B sonar:sonar -Dsonar.projectKey=green-code-initiative_creedengo-java + run: ./mvnw -e -B sonar:sonar -Dsonar.projectKey=green-code-initiative_creedengo-java -Dsonar.organization=green-code-initiative From 898cfb6c19001ece4f42664da06f8beee0af39fb Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 12 Feb 2026 22:12:38 +0100 Subject: [PATCH 197/233] update changelog --- CHANGELOG.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3676f22d..6ec90385 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,9 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- [#49](https://github.com/green-code-initiative/ecoCode-java/pull/49) Add test to ensure all Rules are registered -- [#336](https://github.com/green-code-initiative/ecoCode/issues/336) [Adds Maven Wrapper](https://github.com/green-code-initiative/ecoCode-java/pull/67) -- [#69](https://github.com/green-code-initiative/ecoCode-java/pull/69) correction of NullPointer in EC79 rule +- [#69](https://github.com/green-code-initiative/creedengo-java/issues/69) correction of NullPointer in GCI79 rule + technical refactoring of GCI79 +- update integration tests system to use the new component "creedengo-integration-test" ### Deleted From ab589aebffe5b3d9552cc906b6edcdac491d83fe Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 12 Feb 2026 22:26:59 +0100 Subject: [PATCH 198/233] correction from copilot review --- IA_description.md | 8 ++++---- IA_rule.md | 8 ++++---- .../creedengo/java/integration/tests/GCIRulesIT.java | 2 +- .../checks/FreeResourcesOfAutoCloseableInterface.java | 4 ++-- .../checks/FreeResourcesOfAutoCloseableInterface.java | 2 +- src/test/files/FreeResourcesOfAutoCloseableInterface.java | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/IA_description.md b/IA_description.md index 6c7bf66e..cb25c3b7 100644 --- a/IA_description.md +++ b/IA_description.md @@ -52,12 +52,12 @@ Each unit test class checking rule implementation class has the same template of - usage of "CheckVerifier.verifyNoIssues" to check there is no issues raised - each call to "CheckVerifier" needs a test resource file : this one is the resource code file for the simulated analysis -each test resource file is in the "test/resources/checks" directory (or sub-directories). +each test resource file is in the "src/test/files" directory (or sub-directories). each test resource file contains compliuant code or / and non compliant code. -If there is no compliant code on which Sonarqube analysis should raise an issue, the line with the issue has a comment at the end of the line with the following template : -"# Noncompliant {{ERROR_MESSAGE_TO_DISPLAY}}" +If there is non compliant code on which Sonarqube analysis should raise an issue, the line with the issue has a comment at the end of the line with the following template : +"// Noncompliant {{ERROR_MESSAGE_TO_DISPLAY}}" - the "ERROR_MESSAGE_TO_DISPLAY" in the previous template is replaced by the real error message. - - this comment give the information to "CheckVerifier", the simulation tool, that an error is expected at this line + - this comment gives the information to "CheckVerifier", the simulation tool, that an error is expected at this line Integration Tests Implementation Structure --- diff --git a/IA_rule.md b/IA_rule.md index da6d5f55..22710167 100644 --- a/IA_rule.md +++ b/IA_rule.md @@ -13,20 +13,20 @@ Use the TDD (Test-Driven Development) methodology to implement a rule in an effi - Non-compliant code - Code with elements that should not be analyzed - Location of test resource files: - - Files for unit tests: in "test/resources/checks" or subdirectories + - Files for unit tests: in "src/test/files" or subdirectories - Files for integration tests: in "src/it/test-projects" or subdirectories - Create the rule implementation class in the package "org.greencodeinitiative.creedengo.java.checks" - Add the "Rule" annotation with the correct rule id (the rule is previously defined in another maven component named "creedengo-rules-specifications") - Extend the "IssuableSubscriptionVisitor" class - - Implement the "initialize" method which will be used to declare the AST node types to analyze in depth but leave it empty for now + - Override the "nodesToVisit", "visitNode" and (optionally) "leaveNode" methods, which will be used respectively to declare the AST node types to analyze in depth and to implement the analysis logic, but leave their bodies empty for now - Create the rule unit test class in the package "org.greencodeinitiative.creedengo.java.checks" - Verify that unit tests fail with non-compliant test resources ## STEP 2: Implement the rule + unit test validation - Implement the rule in the implementation class created in step 1 -- Implement the "initialize" method to declare the AST node types to analyze in depth +- Implement the "nodesToVisit" method to declare the AST node types to analyze in depth and implement the "visitNode" and, if needed, "leaveNode" methods to perform the analysis on those nodes - Implement private methods to analyze in depth the declared AST nodes and raise issues if needed -- Verify that unit tests pass with both compliant and non-compliant test resources +- Verify that unit tests pass with both compliant and non-compliant test resources, and call them from "visitNode"/"leaveNode" ## STEP 3: Implement integration tests - Add a test method in the integration class "GCIRulesIT" for the implemented rule using the same pattern as other existing test methods diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java index ff5bf687..bb8f6037 100644 --- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java +++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java @@ -408,7 +408,7 @@ void testGCI76_good() { void testGCI79() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java"; String ruleId = "creedengo-java:GCI79"; - String ruleMsg = "try-with-resources Statement needs to be implemented for any object that implements the AutoClosable interface."; + String ruleMsg = "try-with-resources Statement needs to be implemented for any object that implements the AutoCloseable interface."; int[] startLines = new int[]{23}; int[] endLines = new int[]{36}; diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java index 23274f6f..7632450d 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java @@ -37,7 +37,7 @@ public void foo2() throws IOException { } /** - * The first methods adds a "try" in the stack used to follow if the code is in a try + * The first method adds a "try" in the stack used to follow if the code is in a try */ public void callingMethodWithTheTry() throws IOException { try { // Compliant @@ -48,7 +48,7 @@ public void callingMethodWithTheTry() throws IOException { } /** - * The "try" should have been poped from the stack before entering here + * The "try" should have been popped from the stack before entering here */ private void calledMethodWithoutTry() throws IOException { FileWriter myWriter = new FileWriter("somefilepath"); diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java index 0db0d94b..2fc5c542 100644 --- a/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java +++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java @@ -56,7 +56,7 @@ public class FreeResourcesOfAutoCloseableInterface extends IssuableSubscriptionV private final Deque tryStack = new ArrayDeque<>(); private static final String JAVA_LANG_AUTOCLOSEABLE = "java.lang.AutoCloseable"; - protected static final String MESSAGE_RULE = "try-with-resources Statement needs to be implemented for any object that implements the AutoClosable interface."; + protected static final String MESSAGE_RULE = "try-with-resources Statement needs to be implemented for any object that implements the AutoCloseable interface."; @Override @ParametersAreNonnullByDefault diff --git a/src/test/files/FreeResourcesOfAutoCloseableInterface.java b/src/test/files/FreeResourcesOfAutoCloseableInterface.java index 51274ecb..776ba3c7 100644 --- a/src/test/files/FreeResourcesOfAutoCloseableInterface.java +++ b/src/test/files/FreeResourcesOfAutoCloseableInterface.java @@ -35,7 +35,7 @@ public void foo1() { public void foo2() { String fileName = "./FreeResourcesOfAutoCloseableInterface.java"; - try { // Noncompliant {{try-with-resources Statement needs to be implemented for any object that implements the AutoClosable interface.}} + try { // Noncompliant {{try-with-resources Statement needs to be implemented for any object that implements the AutoCloseable interface.}} FileReader fr = new FileReader(fileName); BufferedReader br = new BufferedReader(fr); System.out.printl(br.readLine()); @@ -52,7 +52,7 @@ public void foo2() { } /** - * The first methods adds a "try" in the stack used to follow if the code is in a try + * The first method adds a "try" in the stack used to follow if the code is in a try */ public void callingMethodWithTheTry() throws IOException { try { // Compliant @@ -63,7 +63,7 @@ public void callingMethodWithTheTry() throws IOException { } /** - * The "try" should have been poped from the stack before entering here + * The "try" should have been popped from the stack before entering here */ private void calledMethodWithoutTry() throws IOException { FileWriter myWriter = new FileWriter("somefilepath"); From 03df3164ad877b34171f3bbe036fa6e796964463 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 12 Feb 2026 23:24:37 +0100 Subject: [PATCH 199/233] update lib + exclusion in dependabot --- .github/dependabot.yml | 3 ++- pom.xml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 7a77aa9c..cde26d47 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -13,4 +13,5 @@ updates: # Ignore all versions : cf pom.xml comments - dependency-name: "com.mycila:license-maven-plugin" - dependency-name: "org.springframework.data:spring-data-commons" - update-types: ["version-update:semver-patch", "version-update:semver-minor"] + - dependency-name: "org.springframework:spring-context" + - dependency-name: "org.sonarsource.api.plugin:sonar-plugin-api" diff --git a/pom.xml b/pom.xml index 9368778c..21bc72ed 100644 --- a/pom.xml +++ b/pom.xml @@ -166,7 +166,7 @@ org.assertj assertj-core - 3.27.4 + 3.27.7 test From 2d23690e281de90ca004acffbf39f9bc2044e90a Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Sun, 15 Feb 2026 16:58:51 +0100 Subject: [PATCH 200/233] update lib integration-test --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 21bc72ed..12a091e3 100644 --- a/pom.xml +++ b/pom.xml @@ -188,7 +188,7 @@ org.green-code-initiative creedengo-integration-test - 0.2.1 + 0.2.4 test From 5facc2d8b14a6f2745be32357b006c55fa508182 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Sun, 15 Feb 2026 17:08:45 +0100 Subject: [PATCH 201/233] optim test dep --- pom.xml | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index 12a091e3..27dedcd1 100644 --- a/pom.xml +++ b/pom.xml @@ -149,6 +149,16 @@ + + + + + org.green-code-initiative + creedengo-integration-test + 0.2.4 + test + + org.sonarsource.java java-checks-testkit @@ -163,13 +173,6 @@ test - - org.assertj - assertj-core - 3.27.7 - test - - org.mockito mockito-junit-jupiter @@ -184,14 +187,6 @@ test - - - org.green-code-initiative - creedengo-integration-test - 0.2.4 - test - - From 14397ff5b169e3ddfeb466d2a5188239f33369bc Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Sun, 15 Feb 2026 19:06:16 +0100 Subject: [PATCH 202/233] update permissions on github actions --- .github/workflows/stale_tag.yml | 3 +++ .github/workflows/tag_release.yml | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/.github/workflows/stale_tag.yml b/.github/workflows/stale_tag.yml index 4c7a9ff9..dd3c35e1 100644 --- a/.github/workflows/stale_tag.yml +++ b/.github/workflows/stale_tag.yml @@ -7,6 +7,9 @@ on: jobs: stale: runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write steps: - uses: actions/stale@v8.0.0 with: diff --git a/.github/workflows/tag_release.yml b/.github/workflows/tag_release.yml index c91930cb..0e05dacb 100644 --- a/.github/workflows/tag_release.yml +++ b/.github/workflows/tag_release.yml @@ -9,6 +9,8 @@ jobs: checks: name: Requirements runs-on: ubuntu-latest + permissions: + contents: read steps: - name: Check user permissions uses: 74th/workflow-permission-action@1.0.0 @@ -20,6 +22,8 @@ jobs: needs: checks outputs: upload_url: ${{ steps.create_release.outputs.upload_url }} + permissions: + contents: write steps: - name: Checkout tag "${{ github.ref_name }}" uses: actions/checkout@v3 @@ -55,6 +59,8 @@ jobs: name: Upload Java Plugin runs-on: ubuntu-latest needs: build + permissions: + contents: write steps: - name: Import plugin JAR files id: import_jar_files From 839698af1b7ddcea9638d43edaf751eb7b22abed Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Sun, 15 Feb 2026 22:14:47 +0100 Subject: [PATCH 203/233] upgrade non-retrocomptibel + upgrade version from 2.1 to 2.2 --- CHANGELOG.md | 2 ++ README.md | 13 ++++++++----- pom.xml | 39 +++++++++++++++++++++++---------------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ec90385..02314f43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#69](https://github.com/green-code-initiative/creedengo-java/issues/69) correction of NullPointer in GCI79 rule + technical refactoring of GCI79 - update integration tests system to use the new component "creedengo-integration-test" +- compatibility updates for SonarQube up to 26.2.0 +- upgrade internal libraries versions - non retro-compatibility upgrades ### Deleted diff --git a/README.md b/README.md index cb0f6b88..e26322b9 100644 --- a/README.md +++ b/README.md @@ -57,11 +57,14 @@ 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 | -| 1.7.+ | 9.9.+ LTS to 10.6.0 | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) | -| 2.+ | 9.9.0 LTS to 25.12.0 | [17](https://docs.sonarsource.com/sonarqube/9.9/requirements/prerequisites-and-overview/#java) | +| Plugin version | SonarQube version | Java version | +|----------------|-----------------------|--------------| +| 1.6.+ | 9.4.+ LTS to 10.6.0 | 11 / 17 | +| 1.7.+ | 9.9.+ LTS to 10.6.0 | 17 | +| 2.0.+ / 2.1.+ | 9.9.0 LTS to 25.12.0 | 17 | +| 2.2.+ | 25.1.+ | 17 | +| 2.2.+ | 25.2.+ LTS to 25.12.+ | 17 / 21 | +| 2.2.+ | 26.1.+ LTS to 26.2.+ | 21 | > Compatibility table of versions lower than 1.4.+ are available from the > main [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-plugins-version-compatibility). diff --git a/pom.xml b/pom.xml index 27dedcd1..895f2324 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.green-code-initiative creedengo-java-plugin - 2.1.3-SNAPSHOT + 2.2.0-SNAPSHOT sonar-plugin @@ -60,24 +60,26 @@ 13.0.0.3026 - - 8.9.3.40165 - - + 8.23.0.42096 - 2.18.0.3393 + 2.21.0.4626 - 1.23.0.740 + 1.25.1.3002 - 2.6.7 + 2.7.1 https://repo1.maven.org/maven2 false + + + + + @@ -85,16 +87,21 @@ + + + + - 25.12.0.117093 + 25.12.0.117093 - + + ${sonarjava.version} @@ -169,14 +176,14 @@ org.junit.jupiter junit-jupiter - 5.13.4 + 5.14.3 test org.mockito mockito-junit-jupiter - 5.19.0 + 5.21.0 test @@ -203,7 +210,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.14.0 + 3.15.0 org.apache.maven.plugins @@ -213,7 +220,7 @@ org.jacoco jacoco-maven-plugin - 0.8.13 + 0.8.14 prepare-agent @@ -254,7 +261,7 @@ org.codehaus.mojo buildnumber-maven-plugin - 3.2.1 + 3.3.0 validate @@ -311,7 +318,7 @@ org.apache.maven.plugins maven-dependency-plugin - 3.8.1 + 3.10.0 copy From d0a5c189206a4647a47c04fa05e9bef58ae69310 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Sun, 15 Feb 2026 22:17:09 +0100 Subject: [PATCH 204/233] clean github action --- .github/workflows/_BACKUP_manual_release.yml | 91 -------------------- 1 file changed, 91 deletions(-) delete mode 100644 .github/workflows/_BACKUP_manual_release.yml diff --git a/.github/workflows/_BACKUP_manual_release.yml b/.github/workflows/_BACKUP_manual_release.yml deleted file mode 100644 index af210fe8..00000000 --- a/.github/workflows/_BACKUP_manual_release.yml +++ /dev/null @@ -1,91 +0,0 @@ -name: Manual Release -on: - workflow_dispatch: - inputs: - confirmeRelease: - description: 'Confirm manual release creation (by typing "true") ? ----- WARNING : check version (in pom.xml files) and release notes (in CHANGELOG.md file) before confirm' - default: 'false' -jobs: - checks: - name: Requirements - if: github.event.inputs.confirmeRelease == 'true' - runs-on: ubuntu-latest - steps: - - name: Check user permissions - uses: 74th/workflow-permission-action@1.0.0 - with: - users: dedece35,glalloue,jhertout,jules-delecour-dav,olegoaer,zippy1978 - build: - name: Build And Release - needs: checks - runs-on: ubuntu-latest - permissions: write-all - outputs: - last_tag: ${{ steps.export_last_tag.outputs.last_tag }} - upload_url: ${{ steps.export_upload_url.outputs.upload_url }} - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Change commiter - run: | - git config user.name 'github-actions[bot]' - git config user.email '' - - name: Maven release - run: ./mvnw release:prepare -B -ff -DtagNameFormat=@{project.version} - - name: Maven release clean - run: ./mvnw release:clean - - name: Get last TAG - run: echo "LAST_TAG=$(git tag --sort=-version:refname | head -n 1)" >> $GITHUB_ENV - - name: Extract release notes - id: extract-release-notes - uses: ffurrer2/extract-release-notes@v1 - - name: Checkout tag "${{ env.LAST_TAG }}" - uses: actions/checkout@v3 - with: - ref: ${{ env.LAST_TAG }} - - name: Build project - run: ./mvnw -e -B clean package -DskipTests - - name: Create release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ env.LAST_TAG }} - release_name: Release ${{ env.LAST_TAG }} - draft: false - prerelease: false - body: ${{ steps.extract-release-notes.outputs.release_notes }} - - name: Export plugin Jar files - id: export_jar_files - uses: actions/upload-artifact@v3 - with: - name: creedengo-plugins - path: lib - - name: Export LAST_TAG - id: export_last_tag - run: echo "last_tag=${{ env.LAST_TAG }}" >> $GITHUB_OUTPUT - - name: Export UPLOAD_URL - id: export_upload_url - run: echo "upload_url=${{ steps.create_release.outputs.upload_url }}" >> $GITHUB_OUTPUT - upload-java: - name: Upload Java Plugin - runs-on: ubuntu-latest - needs: build - steps: - - name: Import plugin JAR files - id: import_jar_files - uses: actions/download-artifact@v3 - with: - name: creedengo-plugins - path: lib - - name: Upload Release Asset - Java Plugin - id: upload-release-asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{needs.build.outputs.upload_url}} - asset_path: lib/creedengo-java-plugin-${{ needs.build.outputs.last_tag }}.jar - asset_name: creedengo-java-plugin-${{ needs.build.outputs.last_tag }}.jar - asset_content_type: application/zip From b48a064a35436136855ab39fcaf6e8c3286d6299 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 24 Feb 2026 01:06:39 +0000 Subject: [PATCH 205/233] Bump org.apache.maven.plugins:maven-surefire-plugin from 3.5.4 to 3.5.5 Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.5.4 to 3.5.5. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.5.4...surefire-3.5.5) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-version: 3.5.5 dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 895f2324..f040945d 100644 --- a/pom.xml +++ b/pom.xml @@ -215,7 +215,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.5.4 + 3.5.5 org.jacoco From 459653639f5a04d8be346ea4ce1665e83011d120 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 3 Mar 2026 22:43:14 +0100 Subject: [PATCH 206/233] correction for PR execution action --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0be9aad0..9965bd2e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -46,7 +46,7 @@ jobs: restore-keys: ${{ runner.os }}-sonar - name: SonarQube Scan - if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository + if: (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && secrets.SONAR_TOKEN != '' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From a0efde8fbcdfe6b5243ea06288601932d2bbba84 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Wed, 11 Mar 2026 23:10:01 +0100 Subject: [PATCH 207/233] update github actions --- .github/workflows/build.yml | 15 +++-- .github/workflows/tag_release.yml | 106 ++++++++++++++++-------------- 2 files changed, 67 insertions(+), 54 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9965bd2e..f0aa71d3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,9 +35,6 @@ jobs: mkdir -p ~/.m2 echo "org.sonarsource.scanner.maven" > ~/.m2/settings.xml - - name: Verify - run: ./mvnw -e -B verify - - name: Cache SonarQube packages uses: actions/cache@v4 with: @@ -45,9 +42,17 @@ jobs: key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar + - name: Verify + run: ./mvnw -e -B verify + - name: SonarQube Scan - if: (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && secrets.SONAR_TOKEN != '' + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: ./mvnw -e -B sonar:sonar -Dsonar.projectKey=green-code-initiative_creedengo-java -Dsonar.organization=green-code-initiative + run: | + if [ -z "$SONAR_TOKEN" ]; then + echo "⚠️ SONAR_TOKEN is not set (Dependabot PR or external fork). Skipping SonarQube scan." + else + ./mvnw -e -B sonar:sonar -Dsonar.projectKey=green-code-initiative_creedengo-java -Dsonar.organization=green-code-initiative + fi diff --git a/.github/workflows/tag_release.yml b/.github/workflows/tag_release.yml index 0e05dacb..3cbf005c 100644 --- a/.github/workflows/tag_release.yml +++ b/.github/workflows/tag_release.yml @@ -1,9 +1,15 @@ name: Tag Release on: - push: - tags: - - '[0-9]+.[0-9]+.[0-9]+' + #push: + # tags: + # - '[0-9]+.[0-9]+.[0-9]+' + workflow_dispatch: + inputs: + tag: + description: 'Release tag to deploy (e.g. 2.3.0). Leave empty to use the latest available tag.' + required: false + type: string jobs: checks: @@ -15,66 +21,68 @@ jobs: - name: Check user permissions uses: 74th/workflow-permission-action@1.0.0 with: - users: dedece35,glalloue,jhertout,jules-delecour-dav,olegoaer,zippy1978,utarwyn + users: dedece35,glalloue,jhertout,olegoaer,zippy1978,utarwyn build: name: Build And Release runs-on: ubuntu-latest needs: checks - outputs: - upload_url: ${{ steps.create_release.outputs.upload_url }} permissions: contents: write steps: - - name: Checkout tag "${{ github.ref_name }}" + - name: Checkout repository uses: actions/checkout@v3 with: - ref: ${{ github.ref_name }} + fetch-depth: 0 + + - name: Resolve release tag + id: resolve_tag + run: | + if [ -n "${{ inputs.tag }}" ]; then + RELEASE_TAG="${{ inputs.tag }}" + else + RELEASE_TAG=$(git tag --sort=-version:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1) + fi + if [ -z "$RELEASE_TAG" ]; then + echo "No tag found. Please specify one as input." + exit 1 + fi + echo "Tag used: $RELEASE_TAG" + echo "release_tag=$RELEASE_TAG" >> $GITHUB_ENV + + - name: Checkout tag "${{ env.release_tag }}" + uses: actions/checkout@v3 + with: + ref: ${{ env.release_tag }} + - name: Extract release notes id: extract-release-notes uses: ffurrer2/extract-release-notes@v1 + - name: Build project - run: ./mvnw -e -B clean package -DskipTests - - name: Create release - id: create_release - uses: actions/create-release@v1 env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # the plugin maven-release-plugin uses the environment variable VERSIONING_GIT_REF to determine the version to use when building the project. + # By setting this variable to refs/tags/${{ env.release_tag }}, we are telling the plugin to use the specified tag as the project version. + VERSIONING_GIT_REF: refs/tags/${{ env.release_tag }} + run: mvn -e -B clean package -DskipTests -Drevision=${{ env.release_tag }} + + - name: Resolve JAR filename + id: resolve_jar + run: | + JAR_FILE=$(ls target/creedengo-java-plugin-*.jar | grep -v original | head -n 1) + if [ -z "$JAR_FILE" ]; then + echo "No JAR found in target/" + exit 1 + fi + echo "JAR found: $JAR_FILE" + echo "jar_path=$JAR_FILE" >> $GITHUB_ENV + + - name: Create release and upload asset + uses: softprops/action-gh-release@v2 with: - tag_name: ${{ github.ref_name }} - release_name: Release ${{ github.ref_name }} + tag_name: ${{ env.release_tag }} + name: Release ${{ env.release_tag }} + body: ${{ steps.extract-release-notes.outputs.release_notes }} + generate_release_notes: true draft: false prerelease: false - body: ${{ steps.extract-release-notes.outputs.release_notes }} - - name: Export plugin Jar files - id: export_jar_files - uses: actions/upload-artifact@v4 - with: - name: creedengo-plugins - path: target - - name: Export UPLOAD_URL - id: export_upload_url - run: echo "upload_url=${{ steps.create_release.outputs.upload_url }}" >> $GITHUB_OUTPUT - - upload: - name: Upload Java Plugin - runs-on: ubuntu-latest - needs: build - permissions: - contents: write - steps: - - name: Import plugin JAR files - id: import_jar_files - uses: actions/download-artifact@v4 - with: - name: creedengo-plugins - path: target - - name: Upload Release Asset - Java Plugin - id: upload-release-asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{needs.build.outputs.upload_url}} - asset_path: target/creedengo-java-plugin-${{ github.ref_name }}.jar - asset_name: creedengo-java-plugin-${{ github.ref_name }}.jar - asset_content_type: application/zip + files: ${{ env.jar_path }} \ No newline at end of file From 7be5ca6f32b64428572378cc338e1985216effd4 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 1 May 2026 23:48:35 +0200 Subject: [PATCH 208/233] PR_109 from pataluc - report and rework --- CHANGELOG.md | 1 + pom.xml | 9 + .../java/integration/tests/GCIRulesIT.java | 169 ++- .../creedengo/java/checks/ArrayCopyCheck.java | 1000 +++++++++-------- .../java/checks/AvoidFullSQLRequestCheck.java | 19 + ...ingSizeCollectionInForEachLoopIgnored.java | 18 + ...voidGettingSizeCollectionInForLoopBad.java | 4 +- ...oidGettingSizeCollectionInForLoopGood.java | 19 +- ...GettingSizeCollectionInForLoopIgnored.java | 24 +- ...idGettingSizeCollectionInWhileLoopBad.java | 20 +- ...dGettingSizeCollectionInWhileLoopGood.java | 18 + ...ttingSizeCollectionInWhileLoopIgnored.java | 20 +- .../checks/AvoidMultipleIfElseStatement.java | 67 +- ...dMultipleIfElseStatementCompareMethod.java | 39 +- .../AvoidMultipleIfElseStatementNoIssue.java | 20 +- .../AvoidMultipleIfElseStatementNotBlock.java | 1 + .../checks/AvoidRegexPatternNotStatic.java | 17 + .../AvoidRegexPatternNotStaticValid1.java | 17 + .../AvoidRegexPatternNotStaticValid2.java | 17 + .../AvoidRegexPatternNotStaticValid3.java | 17 + .../checks/AvoidSQLRequestInLoopCheck.java | 17 + .../AvoidSetConstantInBatchUpdateCheck.java | 48 +- .../AvoidSpringRepositoryCallInLoopCheck.java | 2 +- ...voidSpringRepositoryCallInStreamCheck.java | 70 +- .../checks/AvoidStatementForDMLQueries.java | 23 +- .../checks/AvoidUsageOfStaticCollections.java | 23 +- .../AvoidUsageOfStaticCollectionsGoodWay.java | 17 + ...FreeResourcesOfAutoCloseableInterface.java | 25 +- .../creedengo/java/checks/IncrementCheck.java | 27 + .../InitializeBufferWithAppropriateSize.java | 22 + .../MakeNonReassignedVariablesConstants.java | 2 + .../NoFunctionCallWhenDeclaringForLoop.java | 9 +- .../OptimizeReadFileExceptionCheck.java | 35 +- .../OptimizeReadFileExceptionCheck2.java | 38 +- .../OptimizeReadFileExceptionCheck3.java | 35 +- .../OptimizeReadFileExceptionCheck4.java | 33 +- .../OptimizeReadFileExceptionCheck5.java | 33 +- .../checks/UseOptionalOrElseGetVsOrElse.java | 2 + ...DDCToCheckOptimizeSQLQueriesWithLimit.java | 32 - src/test/files/ArrayCopyCheck.java | 510 --------- src/test/files/AvoidFullSQLRequestCheck.java | 49 - ...ingSizeCollectionInForEachLoopIgnored.java | 39 - ...voidGettingSizeCollectionInForLoopBad.java | 17 - ...oidGettingSizeCollectionInForLoopGood.java | 40 - ...GettingSizeCollectionInForLoopIgnored.java | 39 - ...idGettingSizeCollectionInWhileLoopBad.java | 40 - ...dGettingSizeCollectionInWhileLoopGood.java | 42 - ...ttingSizeCollectionInWhileLoopIgnored.java | 41 - .../files/AvoidMultipleIfElseStatement.java | 283 ----- ...AvoidMultipleIfElseStatementInterface.java | 24 - .../AvoidMultipleIfElseStatementNoIssue.java | 274 ----- .../files/AvoidRegexPatternNotStatic.java | 28 - .../AvoidRegexPatternNotStaticValid1.java | 29 - .../AvoidRegexPatternNotStaticValid2.java | 29 - .../AvoidRegexPatternNotStaticValid3.java | 33 - .../files/AvoidSQLRequestInLoopCheck.java | 151 --- .../AvoidSetConstantInBatchUpdateCheck.java | 166 --- .../AvoidSpringRepositoryCallInLoopCheck.java | 57 - ...voidSpringRepositoryCallInStreamCheck.java | 139 --- .../files/AvoidStatementForDMLQueries.java | 34 - .../files/AvoidUsageOfStaticCollections.java | 36 - .../AvoidUsageOfStaticCollectionsGoodWay.java | 34 - ...FreeResourcesOfAutoCloseableInterface.java | 74 -- src/test/files/IncrementCheck.java | 106 -- .../InitializeBufferWithAppropriateSize.java | 48 - .../MakeNonReassignedVariablesConstants.java | 147 --- .../NoFunctionCallWhenDeclaringForLoop.java | 153 --- .../files/OptimizeReadFileExceptionCheck.java | 37 - .../OptimizeReadFileExceptionCheck2.java | 36 - .../OptimizeReadFileExceptionCheck3.java | 36 - .../OptimizeReadFileExceptionCheck4.java | 36 - .../OptimizeReadFileExceptionCheck5.java | 36 - .../files/UseOptionalOrElseGetVsOrElse.java | 35 - .../java/checks/ArrayCopyCheckTest.java | 2 +- .../checks/AvoidFullSQLRequestCheckTest.java | 2 +- .../AvoidGettingSizeCollectionInLoopTest.java | 14 +- .../AvoidMultipleIfElseStatementTest.java | 12 +- .../AvoidRegexPatternNotStaticTest.java | 8 +- .../AvoidSQLRequestInLoopCheckTest.java | 2 +- .../AvoidSetConstantInBatchInsertTest.java | 2 +- ...idSpringRepositoryCallInLoopCheckTest.java | 2 +- ...SpringRepositoryCallInStreamCheckTest.java | 2 +- .../AvoidStatementForDMLQueriesTest.java | 2 +- .../AvoidUsageOfStaticCollectionsTests.java | 4 +- ...ResourcesOfAutoCloseableInterfaceTest.java | 4 +- .../java/checks/IncrementCheckTest.java | 2 +- ...itializeBufferWithAppropriateSizeTest.java | 2 +- ...keNonReassignedVariablesConstantsTest.java | 2 +- ...oFunctionCallWhenDeclaringForLoopTest.java | 2 +- .../OptimizeReadFileExceptionCheckTest.java | 10 +- .../UseOptionalOrElseGetVsOrElseTest.java | 3 +- 91 files changed, 1270 insertions(+), 3694 deletions(-) rename src/{test/files => it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks}/AvoidMultipleIfElseStatementCompareMethod.java (61%) rename src/{test/files => it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks}/AvoidMultipleIfElseStatementNotBlock.java (97%) delete mode 100644 src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ZzzDDCToCheckOptimizeSQLQueriesWithLimit.java delete mode 100644 src/test/files/ArrayCopyCheck.java delete mode 100644 src/test/files/AvoidFullSQLRequestCheck.java delete mode 100644 src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java delete mode 100644 src/test/files/AvoidGettingSizeCollectionInForLoopBad.java delete mode 100644 src/test/files/AvoidGettingSizeCollectionInForLoopGood.java delete mode 100644 src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java delete mode 100644 src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java delete mode 100644 src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java delete mode 100644 src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java delete mode 100644 src/test/files/AvoidMultipleIfElseStatement.java delete mode 100644 src/test/files/AvoidMultipleIfElseStatementInterface.java delete mode 100644 src/test/files/AvoidMultipleIfElseStatementNoIssue.java delete mode 100644 src/test/files/AvoidRegexPatternNotStatic.java delete mode 100644 src/test/files/AvoidRegexPatternNotStaticValid1.java delete mode 100644 src/test/files/AvoidRegexPatternNotStaticValid2.java delete mode 100644 src/test/files/AvoidRegexPatternNotStaticValid3.java delete mode 100644 src/test/files/AvoidSQLRequestInLoopCheck.java delete mode 100644 src/test/files/AvoidSetConstantInBatchUpdateCheck.java delete mode 100644 src/test/files/AvoidSpringRepositoryCallInLoopCheck.java delete mode 100644 src/test/files/AvoidSpringRepositoryCallInStreamCheck.java delete mode 100644 src/test/files/AvoidStatementForDMLQueries.java delete mode 100644 src/test/files/AvoidUsageOfStaticCollections.java delete mode 100644 src/test/files/AvoidUsageOfStaticCollectionsGoodWay.java delete mode 100644 src/test/files/FreeResourcesOfAutoCloseableInterface.java delete mode 100644 src/test/files/IncrementCheck.java delete mode 100644 src/test/files/InitializeBufferWithAppropriateSize.java delete mode 100644 src/test/files/MakeNonReassignedVariablesConstants.java delete mode 100644 src/test/files/NoFunctionCallWhenDeclaringForLoop.java delete mode 100644 src/test/files/OptimizeReadFileExceptionCheck.java delete mode 100644 src/test/files/OptimizeReadFileExceptionCheck2.java delete mode 100644 src/test/files/OptimizeReadFileExceptionCheck3.java delete mode 100644 src/test/files/OptimizeReadFileExceptionCheck4.java delete mode 100644 src/test/files/OptimizeReadFileExceptionCheck5.java delete mode 100644 src/test/files/UseOptionalOrElseGetVsOrElse.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 02314f43..42e39e9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - update integration tests system to use the new component "creedengo-integration-test" - compatibility updates for SonarQube up to 26.2.0 - upgrade internal libraries versions - non retro-compatibility upgrades +- refacto to have all the test files in the same place (for UT and IT), to avoid maintaining 2 test directories ### Deleted diff --git a/pom.xml b/pom.xml index f040945d..68a2a9ae 100644 --- a/pom.xml +++ b/pom.xml @@ -50,6 +50,9 @@ UTF-8 UTF-8 + + false + green-code-initiative https://sonarcloud.io @@ -216,6 +219,12 @@ org.apache.maven.plugins maven-surefire-plugin 3.5.5 + + ${skip.unit.tests} + + src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks + + org.jacoco diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java index bb8f6037..5419880a 100644 --- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java +++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java @@ -25,7 +25,6 @@ void testMeasuresAndIssues() { List projectIssues = searchIssuesForComponent(projectKey, null).getIssuesList(); assertThat(projectIssues).isNotEmpty(); - } @Test @@ -35,37 +34,35 @@ void testGCI27() { String ruleId = "creedengo-java:GCI27"; String ruleMsg = "Use System.arraycopy to copy arrays"; int[] startLines = new int[]{ - 51, 56, 63, 72, 85, 94, - 105, 116, 139, 145, 153, 163, - 177, 187, 199, 211, 229, 236, - 245, 256, 271, 282, 295, 308, - 334, 341, 350, 361, 376, 389, - 415, 422, 431, 442, 457, 470 + 68, 73, 80, 89, 102, 111, + 122, 133, 156, 162, 170, 180, + 194, 204, 216, 228, 246, 253, + 262, 273, 288, 299, 312, 325, + 351, 358, 367, 378, 393, 406, + 432, 439, 448, 459, 474, 487 }; int[] endLines = new int[]{ - 53, 60, 69, 82, 91, 102, - 113, 124, 141, 149, 159, 173, - 183, 195, 207, 219, 232, 241, - 252, 267, 278, 291, 304, 317, - 337, 346, 357, 372, 385, 398, - 418, 427, 438, 453, 466, 479 + 70, 77, 86, 99, 108, 119, + 130, 141, 158, 166, 176, 190, + 200, 212, 224, 236, 249, 258, + 269, 284, 295, 308, 321, 334, + 354, 363, 374, 389, 402, 415, + 435, 444, 455, 470, 483, 496 }; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN); - } @Test void testGCI74() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheck.java"; - int[] startLines = new int[]{8, 12, 17, 23}; - int[] endLines = new int[]{8, 12, 17, 23}; + int[] startLines = new int[]{27, 31, 36, 42}; + int[] endLines = new int[]{27, 31, 36, 42}; String ruleId = "creedengo-java:GCI74"; String ruleMsg = "Don't use the query SELECT * FROM"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN); - } @Test @@ -78,7 +75,6 @@ void testGCI3_forEachLoopIgnored() { String ruleMsg = "Avoid getting the size of the collection in the loop"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); - } @Test @@ -91,7 +87,6 @@ void testGCI3_forLoopBad() { String ruleMsg = "Avoid getting the size of the collection in the loop"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); - } @Test @@ -104,7 +99,6 @@ void testGCI3_forEachLoopGood() { String ruleMsg = "Avoid getting the size of the collection in the loop"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); - } @Test @@ -117,20 +111,18 @@ void testGCI3_forLoopIgnored() { String ruleMsg = "Avoid getting the size of the collection in the loop"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); - } @Test void testGCI3_whileLoopBad() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java"; - int[] startLines = new int[]{17}; - int[] endLines = new int[]{17}; + int[] startLines = new int[]{35}; + int[] endLines = new int[]{35}; String ruleId = "creedengo-java:GCI3"; String ruleMsg = "Avoid getting the size of the collection in the loop"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); - } @Test @@ -143,7 +135,6 @@ void testGCI3_whileLoopGood() { String ruleMsg = "Avoid getting the size of the collection in the loop"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); - } @Test @@ -156,7 +147,6 @@ void testGCI3_whileLoopIgnored() { String ruleMsg = "Avoid getting the size of the collection in the loop"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); - } @Test @@ -165,24 +155,23 @@ void testGCI2() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java"; int[] startLines = new int[]{ - 24, 43, 45, 71, 88, 110, - 112, 131, 135, 137, 158, 164, - 190, 209, 212, 214, 211, 236, - 257, 259 + 41, 60, 62, 88, 105, 127, + 129, 148, 152, 154, 175, 181, + 207, 226, 228, 229, 231, 253, + 274, 276 }; int[] endLines = new int[]{ - 24, 43, 47, 71, 90, 110, - 114, 133, 135, 139, 160, 166, - 192, 209, 212, 216, 217, 238, - 257, 261 + 41, 60, 64, 88, 107, 127, + 131, 150, 152, 156, 177, 183, + 209, 226, 234, 229, 233, 255, + 274, 278 }; String ruleId = "creedengo-java:GCI2"; String ruleMsg = "Use a switch statement instead of multiple if-else if possible"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); - } @Test @@ -198,7 +187,6 @@ void testGCI2_compareMethodNoIssue() { String ruleMsg = "Use a switch statement instead of multiple if-else if possible"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); - } @Test @@ -214,7 +202,6 @@ void testGCI2_interfaceNoIssue() { String ruleMsg = "Use a switch statement instead of multiple if-else if possible"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); - } @Test @@ -230,7 +217,6 @@ void testGCI2_noBlockNoIssue() { String ruleMsg = "Use a switch statement instead of multiple if-else if possible"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); - } @Test @@ -246,20 +232,18 @@ void testGCI2_noIssue() { String ruleMsg = "Use a switch statement instead of multiple if-else if possible"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); - } @Test void testGCI77_invalid() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java"; - int[] startLines = new int[]{8}; - int[] endLines = new int[]{8}; + int[] startLines = new int[]{25}; + int[] endLines = new int[]{25}; String ruleId = "creedengo-java:GCI77"; String ruleMsg = "Avoid using Pattern.compile() in a non-static context."; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN); - } @Test @@ -272,7 +256,6 @@ void testGCI77_valid1() { String ruleMsg = "Avoid using Pattern.compile() in a non-static context."; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN); - } @Test @@ -285,7 +268,6 @@ void testGCI77_valid2() { String ruleMsg = "Avoid using Pattern.compile() in a non-static context."; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN); - } @Test @@ -298,7 +280,6 @@ void testGCI77_valid3() { String ruleMsg = "Avoid using Pattern.compile() in a non-static context."; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN); - } @Test @@ -306,26 +287,25 @@ void testGCI78() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java"; int[] startLines = new int[]{ - 34, 35, 36, 37, 38, 39, - 40, 41, 42, 43, 44, 45, - 46, 61, 63, 64, 65, 66, - 67, 70, 86, 88, 90, 91, - 92, 93, 94, 96, 114, 116, - 117, 118, 119, 120, 121, 123 + 53, 54, 55, 56, 57, 58, + 59, 60, 61, 62, 63, 64, + 80, 82, 83, 84, 85, 88, + 104, 106, 107, 108, 109, 110, + 111, 113, 131, 133, 134, 135, + 136, 137, 138, 140 }; int[] endLines = new int[]{ - 34, 35, 36, 37, 38, 39, - 40, 41, 42, 43, 44, 45, - 46, 61, 63, 64, 65, 66, - 67, 70, 86, 88, 90, 91, - 92, 93, 94, 96, 114, 116, - 117, 118, 119, 120, 121, 123 + 53, 54, 55, 56, 57, 58, + 59, 60, 61, 62, 63, 64, + 80, 82, 83, 84, 85, 88, + 104, 106, 107, 108, 109, 110, + 111, 113, 131, 133, 134, 135, + 136, 137, 138, 140 }; String ruleId = "creedengo-java:GCI78"; String ruleMsg = "Avoid setting constants in batch update"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_15MIN); - } @Test @@ -341,7 +321,6 @@ void testGCI1_loop() { String ruleMsg = "Avoid Spring repository call in loop or stream"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_50MIN); - } @Test @@ -349,15 +328,20 @@ void testGCI1_stream() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheck.java"; - int[] startLines = new int[]{36, 46, 56, 66, 76, 84, 96, 105}; + int[] startLines = new int[]{ + 37, 48, 59, 72, 87, 98, + 113, 123 + }; - int[] endLines = new int[]{36, 46, 56, 66, 76, 84, 96, 105}; + int[] endLines = new int[]{ + 37, 48, 59, 72, 87, 98, + 113, 123 + }; String ruleId = "creedengo-java:GCI1"; String ruleMsg = "Avoid Spring repository call in loop or stream"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_50MIN); - } @Test @@ -365,8 +349,8 @@ void testGCI72() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheck.java"; String ruleId = "creedengo-java:GCI72"; String ruleMsg = "Avoid SQL request in loop"; - int[] startLines = new int[]{57, 88, 119}; - int[] endLines = new int[]{57, 88, 119}; + int[] startLines = new int[]{74, 105, 136}; + int[] endLines = new int[]{74, 105, 136}; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_10MIN); } @@ -376,8 +360,8 @@ void testGCI5() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java"; String ruleId = "creedengo-java:GCI5"; String ruleMsg = "You must not use Statement for a DML query"; - int[] startLines = new int[]{18}; - int[] endLines = new int[]{18}; + int[] startLines = new int[]{33}; + int[] endLines = new int[]{33}; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_10MIN); } @@ -387,8 +371,8 @@ void testGCI76() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java"; String ruleId = "creedengo-java:GCI76"; String ruleMsg = "Avoid usage of static collections."; - int[] startLines = new int[]{10, 12, 14}; - int[] endLines = new int[]{10, 12, 14}; + int[] startLines = new int[]{27, 29, 31}; + int[] endLines = new int[]{27, 29, 31}; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN); } @@ -409,8 +393,8 @@ void testGCI79() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java"; String ruleId = "creedengo-java:GCI79"; String ruleMsg = "try-with-resources Statement needs to be implemented for any object that implements the AutoCloseable interface."; - int[] startLines = new int[]{23}; - int[] endLines = new int[]{36}; + int[] startLines = new int[]{40}; + int[] endLines = new int[]{53}; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_15MIN); } @@ -420,8 +404,8 @@ void testGCI32() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java"; String ruleId = "creedengo-java:GCI32"; String ruleMsg = "Initialize StringBuilder or StringBuffer with appropriate size"; - int[] startLines = new int[]{16, 24}; - int[] endLines = new int[]{16, 24}; + int[] startLines = new int[]{38, 46}; + int[] endLines = new int[]{38, 46}; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); } @@ -431,8 +415,8 @@ void testGCI67() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java"; String ruleId = "creedengo-java:GCI67"; String ruleMsg = "Use ++i instead of i++"; - int[] startLines = new int[]{9, 24, 47}; - int[] endLines = new int[]{9, 24, 47}; + int[] startLines = new int[]{31, 51, 74}; + int[] endLines = new int[]{31, 51, 74}; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); } @@ -442,8 +426,8 @@ void testGCI82() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java"; String ruleId = "creedengo-java:GCI82"; String ruleMsg = "The variable is never reassigned and can be 'final'"; - int[] startLines = new int[]{7, 12, 13, 18, 24, 27, 46, 73, 106, 119}; - int[] endLines = new int[]{7, 12, 13, 18, 24, 27, 46, 73, 106, 119}; + int[] startLines = new int[]{9, 14, 15, 20, 26, 29, 48, 75, 108, 121}; + int[] endLines = new int[]{9, 14, 15, 20, 26, 29, 48, 75, 108, 121}; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); } @@ -453,8 +437,8 @@ void testGCI69() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java"; String ruleId = "creedengo-java:GCI69"; String ruleMsg = "Do not call a function when declaring a for-type loop"; - int[] startLines = new int[]{62, 70, 78, 106, 127}; - int[] endLines = new int[]{62, 70, 78, 106, 127}; + int[] startLines = new int[]{65, 73, 81, 109, 130}; + int[] endLines = new int[]{65, 73, 81, 109, 130}; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); } @@ -464,15 +448,14 @@ void testGCI28() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java"; - int[] startLines = new int[]{23}; + int[] startLines = new int[]{34}; - int[] endLines = new int[]{23}; + int[] endLines = new int[]{34}; String ruleId = "creedengo-java:GCI28"; String ruleMsg = "Optimize Read File Exceptions"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); - } @Test @@ -480,15 +463,14 @@ void testGCI28_2() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java"; - int[] startLines = new int[]{20}; + int[] startLines = new int[]{32}; - int[] endLines = new int[]{20}; + int[] endLines = new int[]{32}; String ruleId = "creedengo-java:GCI28"; String ruleMsg = "Optimize Read File Exceptions"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); - } @Test @@ -496,15 +478,14 @@ void testGCI28_3() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java"; - int[] startLines = new int[]{19}; + int[] startLines = new int[]{32}; - int[] endLines = new int[]{19}; + int[] endLines = new int[]{32}; String ruleId = "creedengo-java:GCI28"; String ruleMsg = "Optimize Read File Exceptions"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); - } @Test @@ -512,15 +493,14 @@ void testGCI28_4() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java"; - int[] startLines = new int[]{18}; + int[] startLines = new int[]{31}; - int[] endLines = new int[]{18}; + int[] endLines = new int[]{31}; String ruleId = "creedengo-java:GCI28"; String ruleMsg = "Optimize Read File Exceptions"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); - } @Test @@ -528,15 +508,14 @@ void testGCI28_5() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java"; - int[] startLines = new int[]{18}; + int[] startLines = new int[]{31}; - int[] endLines = new int[]{18}; + int[] endLines = new int[]{31}; String ruleId = "creedengo-java:GCI28"; String ruleMsg = "Optimize Read File Exceptions"; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); - } @Test @@ -544,8 +523,8 @@ void testGCI94() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java"; String ruleId = "creedengo-java:GCI94"; String ruleMsg = "Use optional orElseGet instead of orElse."; - int[] startLines = new int[]{25}; - int[] endLines = new int[]{25}; + int[] startLines = new int[]{27}; + int[] endLines = new int[]{27}; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_1MIN); } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java index 4a7d153c..7d075c44 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java @@ -1,494 +1,510 @@ -package org.greencodeinitiative.creedengo.java.checks; - +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ import java.util.Arrays; - -class ArrayCopyCheck { - - public void copyArrayOK() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Copy with clone - dest = src.clone(); - - // Copy with System.arraycopy() - System.arraycopy(src, 0, dest, 0, src.length); - - // Copy with Arrays.copyOf() - dest = Arrays.copyOf(src, src.length); - } - - public void nonRegression() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple assignation - for (int i = 0; i < len; i++) { - dest[i] = true; - } - - // Edit same array - for (int i = 0; i < len - 1; i++) { - dest[i] = dest[i + 1]; - } - - // Objects assignations - String a = null; - String b = "Sample Value"; - for (int i = 0; i < len; i++) { - a = b; - } - } - - public void copyWithForLoop() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple copy - for (int i = 0; i < len; i++) { - dest[i] = src[i]; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with nested conditions - for (int i = 0; i < len; i++) { - if (i + 2 < len) { - dest[i] = src[i + 2]; - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with nested ELSE conditions - for (int i = 0; i < len; i++) { - if (i + 2 >= len) { - i++; - } else { - dest[i] = src[i + 2]; - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with more nested conditions - for (int i = 0; i < len; i++) { - if (i + 2 < len) { - if (dest != null) { - if (src != null) { - if (i > 1 && i + 2 < src.length) { - dest[i] = src[i + 2]; - } - } - } - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch - for (int i = 0; i < len; i++) { - try { - dest[i] = src[i]; - } catch (RuntimeException e) { - e.printStackTrace(); - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch and if - for (int i = 0; i < len; i++) { - try { - if (dest != null) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch in catch - for (int i = 0; i < len; i++) { - try { - dest.toString(); - } catch (RuntimeException e) { - if (dest != null) { - dest[i] = src[i]; - } - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch in finally - for (int i = 0; i < len; i++) { - try { - dest.toString(); - } catch (RuntimeException e) { - e.printStackTrace(); - } finally { - dest[i] = src[i]; - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Array transformation - for (int i = 0; i < len; i++) { - dest[i] = transform(src[i]); - } - } - - public void copyWithForEachLoop() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple copy by foreach - int i = -1; - for (boolean b : src) { - dest[++i] = b; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with nested conditions by foreach - i = -1; - for (boolean b : src) { - if (b) { - dest[++i] = b; - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with nested ELSE conditions by foreach - i = -1; - for (boolean b : src) { - if (i + 2 >= len) { - i++; - } else { - dest[++i] = b; - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with more nested conditions - i = -1; - for (boolean b : src) { - if (i + 2 < len) { - if (dest != null) { - if (src != null) { - if (i > 1 && i + 2 < src.length) { - dest[++i] = b; - } - } - } - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch - i = -1; - for (boolean b : src) { - try { - dest[++i] = b; - } catch (RuntimeException e) { - e.printStackTrace(); - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch and if - i = -1; - for (boolean b : src) { - try { - if (dest != null) { - dest[++i] = b; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch in catch - i = -1; - for (boolean b : src) { - try { - dest.toString(); - } catch (RuntimeException e) { - if (dest != null) { - dest[++i] = b; - } - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch in finally - i = -1; - for (boolean b : src) { - try { - dest.toString(); - } catch (RuntimeException e) { - e.printStackTrace(); - } finally { - dest[++i] = b; - } - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Array transformation - i = -1; - for (boolean b : src) { - dest[++i] = transform(b); - } - - // Simple copy - i = 0; - for (boolean b : src) { - dest[i] = src[i]; - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with nested conditions - i = 0; - for (boolean b : src) { - if (b) { - dest[i] = src[i]; - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with nested ELSE conditions - i = 0; - for (boolean b : src) { - if (i + 2 >= len) { - i++; - } else { - dest[i] = src[i + 2]; - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with more nested conditions - i = 0; - for (boolean b : src) { - if (i + 2 < len) { - if (dest != null) { - if (src != null) { - if (i > 1 && i + 2 < src.length) { - dest[i] = src[i + 2]; - } - } - } - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch - i = 0; - for (boolean b : src) { - try { - dest[i] = src[i]; - } catch (RuntimeException e) { - e.printStackTrace(); - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch and if - i = 0; - for (boolean b : src) { - try { - if (dest != null) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch in catch - i = 0; - for (boolean b : src) { - try { - dest.toString(); - } catch (RuntimeException e) { - if (dest != null) { - dest[i] = src[i]; - } - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch in finally - i = 0; - for (boolean b : src) { - try { - dest.toString(); - } catch (RuntimeException e) { - e.printStackTrace(); - } finally { - dest[i] = src[i]; - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Array transformation - i = 0; - for (boolean b : src) { - dest[i] = transform(src[i]); - i++; - } - } - - public void copyWithWhileLoop() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple copy - int i = 0; - while (i < len) { - dest[i] = src[i]; - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with nested conditions - i = 0; - while (i < len) { - if (i + 2 < len) { - dest[i] = src[i + 2]; - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with nested ELSE conditions - i = 0; - while (i < len) { - if (i + 2 >= len) { - i++; - } else { - dest[i] = src[i + 2]; - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with more nested conditions - i = 0; - while (i < len) { - if (i + 2 < len) { - if (dest != null) { - if (src != null) { - if (i > 1 && i + 2 < src.length) { - dest[i] = src[i + 2]; - } - } - } - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch and if - i = 0; - while (i < len) { - try { - if (dest != null) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch in catch - i = 0; - while (i < len) { - try { - dest.toString(); - } catch (RuntimeException e) { - if (dest != null) { - dest[i] = src[i]; - } - } - i++; - } // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Array transformation - i = 0; - while (i < len) { - dest[i] = transform(src[i]); - i++; - } - } - - public void copyWithDoWhileLoop() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple copy - int i = 0; - do { - dest[i] = src[i]; - i++; - } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with nested conditions - i = 0; - do { - if (i + 2 < len) { - dest[i] = src[i + 2]; - } - i++; - } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with nested ELSE conditions - i = 0; - do { - if (i + 2 >= len) { - i++; - } else { - dest[i] = src[i + 2]; - } - i++; - } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy with more nested conditions - i = 0; - do { - if (i + 2 < len) { - if (dest != null) { - if (src != null) { - if (i > 1 && i + 2 < src.length) { - dest[i] = src[i + 2]; - } - } - } - } - i++; - } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch and if - i = 0; - do { - try { - if (dest != null) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - i++; - } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Copy nested by try/catch in catch - i = 0; - do { - try { - dest.toString(); - } catch (RuntimeException e) { - if (dest != null) { - dest[i] = src[i]; - } - } - i++; - } while (i < len); // Noncompliant {{Use System.arraycopy to copy arrays}} - - // Array transformation - i = 0; - do { - dest[i] = transform(src[i]); - i++; - } while (i < len); - - } - - private boolean transform(boolean a) { - return !a; - } - +import java.util.Collection; +import java.util.Collections; + +class TestClass { + + public void copyArrayOK() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Copy with clone + dest = src.clone(); + + // Copy with System.arraycopy() + System.arraycopy(src, 0, dest, 0, src.length); + + // Copy with Arrays.copyOf() + dest = Arrays.copyOf(src, src.length); + } + + public void nonRegression() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple assignation + for (int i = 0; i < len; i++) { + dest[i] = true; + } + + // Edit same array + for (int i = 0; i < len-1; i++) { + dest[i] = dest[i+1]; + } + + // Objects assignations + String a = null; + String b = "Sample Value"; + for (int i = 0; i < len; i++) { + a = b; + } + } + + public void copyWithForLoop() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple copy + for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + dest[i] = src[i]; + } + + // Copy with nested conditions + for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 < len) { + dest[i] = src[i + 2]; + } + } + + // Copy with nested ELSE conditions + for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 >= len) { + i++; + } else { + dest[i] = src[i + 2]; + } + } + + // Copy with more nested conditions + for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 < len) { + if(dest != null) { + if(src != null) { + if(i > 1 && i + 2 < src.length) { + dest[i] = src[i + 2]; + } + } + } + } + } + + // Copy nested by try/catch + for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest[i] = src[i]; + } catch (RuntimeException e) { + e.printStackTrace(); + } + } + + // Copy nested by try/catch and if + for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + if(dest != null) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + } + + // Copy nested by try/catch in catch + for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest.toString(); + } catch (RuntimeException e) { + if(dest != null) { + dest[i] = src[i]; + } + } + } + + // Copy nested by try/catch in finally + for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest.toString(); + } catch (RuntimeException e) { + e.printStackTrace(); + } finally { + dest[i] = src[i]; + } + } + + // Array transformation + for (int i = 0; i < len; i++) { + dest[i] = transform(src[i]); + } + } + + public void copyWithForEachLoop() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple copy by foreach + int i = -1; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + dest[++i] = b; + } + + // Copy with nested conditions by foreach + i = -1; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(b) { + dest[++i] = b; + } + } + + // Copy with nested ELSE conditions by foreach + i = -1; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 >= len) { + i++; + } else { + dest[++i] = b; + } + } + + // Copy with more nested conditions + i = -1; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 < len) { + if(dest != null) { + if(src != null) { + if(i > 1 && i + 2 < src.length) { + dest[++i] = b; + } + } + } + } + } + + // Copy nested by try/catch + i = -1; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest[++i] = b; + } catch (RuntimeException e) { + e.printStackTrace(); + } + } + + // Copy nested by try/catch and if + i = -1; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + if(dest != null) { + dest[++i] = b; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + } + + // Copy nested by try/catch in catch + i = -1; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest.toString(); + } catch (RuntimeException e) { + if(dest != null) { + dest[++i] = b; + } + } + } + + // Copy nested by try/catch in finally + i = -1; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest.toString(); + } catch (RuntimeException e) { + e.printStackTrace(); + } finally { + dest[++i] = b; + } + } + + // Array transformation + i = -1; + for (boolean b : src) { + dest[++i] = transform(b); + } + + // Simple copy + i = 0; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + dest[i] = src[i]; + i++; + } + + // Copy with nested conditions + i = 0; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(b) { + dest[i] = src[i]; + } + i++; + } + + // Copy with nested ELSE conditions + i = 0; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 >= len) { + i++; + } else { + dest[i] = src[i + 2]; + } + i++; + } + + // Copy with more nested conditions + i = 0; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 < len) { + if(dest != null) { + if(src != null) { + if(i > 1 && i + 2 < src.length) { + dest[i] = src[i + 2]; + } + } + } + } + i++; + } + + // Copy nested by try/catch + i = 0; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest[i] = src[i]; + } catch (RuntimeException e) { + e.printStackTrace(); + } + i++; + } + + // Copy nested by try/catch and if + i = 0; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + if(dest != null) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + i++; + } + + // Copy nested by try/catch in catch + i = 0; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest.toString(); + } catch (RuntimeException e) { + if(dest != null) { + dest[i] = src[i]; + } + } + i++; + } + + // Copy nested by try/catch in finally + i = 0; + for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest.toString(); + } catch (RuntimeException e) { + e.printStackTrace(); + } finally { + dest[i] = src[i]; + } + i++; + } + + // Array transformation + i = 0; + for (boolean b : src) { + dest[i] = transform(src[i]); + i++; + } + } + + public void copyWithWhileLoop() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple copy + int i = 0; + while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} + dest[i] = src[i]; + i++; + } + + // Copy with nested conditions + i = 0; + while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 < len) { + dest[i] = src[i + 2]; + } + i++; + } + + // Copy with nested ELSE conditions + i = 0; + while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 >= len) { + i++; + } else { + dest[i] = src[i + 2]; + } + i++; + } + + // Copy with more nested conditions + i = 0; + while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 < len) { + if(dest != null) { + if(src != null) { + if(i > 1 && i + 2 < src.length) { + dest[i] = src[i + 2]; + } + } + } + } + i++; + } + + // Copy nested by try/catch and if + i = 0; + while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + if(dest != null) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + i++; + } + + // Copy nested by try/catch in catch + i = 0; + while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest.toString(); + } catch (RuntimeException e) { + if(dest != null) { + dest[i] = src[i]; + } + } + i++; + } + + // Array transformation + i = 0; + while (i < len) { + dest[i] = transform(src[i]); + i++; + } + } + + public void copyWithDoWhileLoop() { + final int len = 5; + final boolean[] src = new boolean[len]; + boolean[] dest = new boolean[len]; + + // Simple copy + int i = 0; + do { // Noncompliant {{Use System.arraycopy to copy arrays}} + dest[i] = src[i]; + i++; + } while (i < len); + + // Copy with nested conditions + i = 0; + do { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 < len) { + dest[i] = src[i + 2]; + } + i++; + } while (i < len); + + // Copy with nested ELSE conditions + i = 0; + do { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 >= len) { + i++; + } else { + dest[i] = src[i + 2]; + } + i++; + } while (i < len); + + // Copy with more nested conditions + i = 0; + do { // Noncompliant {{Use System.arraycopy to copy arrays}} + if(i + 2 < len) { + if(dest != null) { + if(src != null) { + if(i > 1 && i + 2 < src.length) { + dest[i] = src[i + 2]; + } + } + } + } + i++; + } while (i < len); + + // Copy nested by try/catch and if + i = 0; + do { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + if(dest != null) { + dest[i] = src[i]; + } + } catch (RuntimeException e) { + e.printStackTrace(); + } + i++; + } while (i < len); + + // Copy nested by try/catch in catch + i = 0; + do { // Noncompliant {{Use System.arraycopy to copy arrays}} + try { + dest.toString(); + } catch (RuntimeException e) { + if(dest != null) { + dest[i] = src[i]; + } + } + i++; + } while (i < len); + + // Array transformation + i = 0; + do { + dest[i] = transform(src[i]); + i++; + } while (i < len); + } + + private boolean transform(boolean a) { + return !a; + } + } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheck.java index a525a429..2d6b2e6a 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheck.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheck.java @@ -1,5 +1,24 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; +import java.util.regex.Pattern; + class AvoidFullSQLRequestCheck { AvoidFullSQLRequestCheck(AvoidFullSQLRequestCheck mc) { } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java index c24f9c92..ce4eeac9 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java @@ -1,5 +1,23 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; +import java.util.Collection; import java.util.ArrayList; import java.util.List; diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java index 03efe7c7..11254a13 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java @@ -6,11 +6,11 @@ class AvoidGettingSizeCollectionInForLoopBad { public void badForLoop() { - final List numberList = new ArrayList(); + final List numberList = new ArrayList<>(); numberList.add(10); numberList.add(20); - for (int i = 0; i < numberList.size(); ++i) { // Noncompliant + for (int i = 0; i < numberList.size(); ++i) { // Noncompliant {{Avoid getting the size of the collection in the loop}} System.out.println("numberList.size()"); } } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopGood.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopGood.java index 88d98861..169d8d56 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopGood.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopGood.java @@ -1,3 +1,20 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; import java.util.Collection; @@ -17,7 +34,7 @@ public void goodForLoop() { int size = numberList.size(); for (int i = 0; i < size; i++) { // Compliant System.out.println("numberList.size()"); - int size2 = numberList.size(); // Compliant with this rule + int innerSize = numberList.size(); // Compliant with this rule } } } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java index 3ef6359e..d837b7a7 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java @@ -1,11 +1,29 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; +import java.util.Collection; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -class AvoidGettingSizeCollectionInForLoopIgnored { - AvoidGettingSizeCollectionInForLoopIgnored() { +class GCI69AvoidGettingSizeCollectionInForLoopBad { + GCI69AvoidGettingSizeCollectionInForLoopBad() { } @@ -19,6 +37,4 @@ public void badForLoop() { System.out.println(it.next()); } } - - } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java index 7410af92..27d21981 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java @@ -1,5 +1,23 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; +import java.util.Collection; import java.util.ArrayList; import java.util.List; @@ -9,7 +27,7 @@ class AvoidGettingSizeCollectionInWhileLoopBad { } public void badWhileLoop() { - List numberList = new ArrayList(); + List numberList = new ArrayList<>(); numberList.add(10); numberList.add(20); diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java index a09e89e5..713998d5 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java @@ -1,5 +1,23 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; +import java.util.Collection; import java.util.ArrayList; import java.util.List; diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java index c22b216b..dbac3396 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java @@ -1,5 +1,23 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; +import java.util.Collection; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -14,7 +32,7 @@ public void badWhileLoop() { numberList.add(10); numberList.add(20); - Iterator it = numberList.iterator(); + Iterator it = numberList.iterator(); int i = 0; while (it.hasNext()) { // Ignored => compliant it.next(); diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java index 3e4ee746..52bc42ac 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java @@ -1,6 +1,23 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; -class AvoidMultipleIfElseStatement { +class AvoidMultipleIfElseStatementCheck { // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -42,9 +59,9 @@ public int shouldBeNotCompliantBecauseVariablesUsedMaximumTwiceAndDifferentsVari && nb3 == 2 && nb3 == 3) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} nb1 = 1; - } else { + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} nb2 = 2; - } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + } if (nb2 == 2) { nb1 = 3; @@ -85,9 +102,9 @@ public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInIfStatementsAtD if (nb1 == 1) { if (nb1 == 2) { nb1 = 1; - } else { + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} nb1 = 3; - } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + } } else { nb1 = 2; } @@ -109,9 +126,9 @@ public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseSta } else { if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} nb1 = 1; - } else { + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} nb1 = 3; - } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + } } return nb1; @@ -128,15 +145,15 @@ public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseSta if (nb1 == 1) { if (nb1 == 3) { nb1 = 4; - } else { + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} nb1 = 5; - } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + } } else { if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} nb1 = 1; - } else { + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} nb1 = 3; - } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + } } return nb1; @@ -155,15 +172,15 @@ public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseSta if (nb1 == 1) { if (nb1 == 3) { nb1 = 4; - } else { + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} nb1 = 5; - } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + } } else if (nb2 == 2) { if (nb1 == 4) { nb1 = 5; - } else { + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} nb1 = 6; - } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + } } return nb1; @@ -187,9 +204,9 @@ public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseSta } else if (nb2 == 2) { if (nb1 == 3) { nb1 = 4; - } else { + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} nb1 = 5; - } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + } } return nb1; @@ -208,13 +225,13 @@ public int shouldBeNotCompliantBecauseVariableUsedMaximumTwiceInComposedElseStat } else { if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} nb1 = 1; - } else { + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} if (nb1 == 3) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} nb1 = 4; - } else { + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} nb1 = 5; - } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + } + } } return nb1; @@ -233,9 +250,9 @@ public int shouldBeNotCompliantBecauseTheSameVariableIsUsedMoreThanTwice() // NO nb2 = 1; } else if (nb1 == nb2) { nb2 = 2; - } else { + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} nb2 = 4; - } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + } return nb2; } @@ -256,9 +273,9 @@ public int shouldBeNotCompliantBecauseTheSameVariableIsUsedManyTimes() // NOT Co nb2 = 2; } else if (nb3 == nb1) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} nb2 = 3; - } else { + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} nb2 = 4; - } // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + } return nb2; } diff --git a/src/test/files/AvoidMultipleIfElseStatementCompareMethod.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementCompareMethod.java similarity index 61% rename from src/test/files/AvoidMultipleIfElseStatementCompareMethod.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementCompareMethod.java index fdf00d60..9d20ea00 100644 --- a/src/test/files/AvoidMultipleIfElseStatementCompareMethod.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementCompareMethod.java @@ -19,36 +19,51 @@ class AvoidMultipleIfElseStatementCompareMethod { - public int compare(FieldVo o1, FieldVo o2) { + public int compare(DummyClass2 o1, DummyClass2 o2) { - if (o1.getIdBlock().equals(o2.getIdBlock())) { - if (o1.getIdField().equals(o2.getIdField())) { + if (o1.getField1().equals(o2.getField1())) { + if (o1.getField2().equals(o2.getField2())) { return 0; } // First original - if (o1.isOriginal() && !o2.isOriginal()) { + if (o1.getField3() && !o2.getField3()) { return -1; - } else if (!o1.isOriginal() && o2.isOriginal()) { + } else if (!o1.getField3() && o2.getField3()) { return 1; } // First min posgafld - Long result = o1.getColumnPos() - o2.getColumnPos(); + Long result = o1.getField4() - o2.getField4(); if (result != 0) { return result.intValue(); } - // First min ordgaflc - result = o1.getIndex() - o2.getIndex(); - return result.intValue(); } // First BQRY block - if (o1.getIdBlock().startsWith("BQRY") && !o2.getIdBlock().startsWith("BQRY")) { + if (o1.getField2().startsWith("BQRY") && !o2.getField2().startsWith("BQRY")) { return -1; - } else if (!o1.getIdBlock().startsWith("BQRY") && o2.getIdBlock().startsWith("BQRY")) { + } else if (!o1.getField2().startsWith("BQRY") && o2.getField2().startsWith("BQRY")) { return 1; } // If both block don't start with BQRY, sort alpha with String.compareTo method - return o1.getIdBlock().compareTo(o2.getIdBlock()); + return o1.getField2().compareTo(o2.getField2()); + } + + class DummyClass2 { + + public Object getField1() { + return 0; + } + + public String getField2() { + return ""; + } + + public boolean getField3() { + return true; + } + + public Long getField4() { + return 1000L; } } } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoIssue.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoIssue.java index f787785c..53e72dd1 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoIssue.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoIssue.java @@ -1,6 +1,23 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; -class AvoidMultipleIfElseStatementNoIssue { +class AvoidMultipleIfElseStatementCheckNoIssue { // inital RULES : please see HTML description file of this rule (resources directory) @@ -253,4 +270,5 @@ public int shouldBeCompliantBecauseVariableUsed4TimesWithInstanceOfKeys() return nb1; } + } diff --git a/src/test/files/AvoidMultipleIfElseStatementNotBlock.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNotBlock.java similarity index 97% rename from src/test/files/AvoidMultipleIfElseStatementNotBlock.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNotBlock.java index 46a5691f..9921ffd1 100644 --- a/src/test/files/AvoidMultipleIfElseStatementNotBlock.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNotBlock.java @@ -22,6 +22,7 @@ class AvoidMultipleIfElseStatementNotBlock { public boolean equals(Object obj) { if (this == obj) return true; + return false; } } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java index 20d9c24d..76387635 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java @@ -1,3 +1,20 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; import java.util.regex.Pattern; diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid1.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid1.java index 29ff6bbe..638ffd96 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid1.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid1.java @@ -1,3 +1,20 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; import java.util.regex.Pattern; diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid2.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid2.java index b238d4c2..0ef9517c 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid2.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid2.java @@ -1,3 +1,20 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; import java.util.regex.Pattern; diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid3.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid3.java index 0e748b13..f1378974 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid3.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid3.java @@ -1,3 +1,20 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; import java.util.regex.Pattern; diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheck.java index cb185891..f75e0c92 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheck.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheck.java @@ -1,3 +1,20 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; import java.sql.Connection; diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java index 342f6588..259f78a3 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java @@ -1,15 +1,34 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; import java.math.BigDecimal; -import java.sql.Connection; -import java.sql.DriverManager; import java.sql.PreparedStatement; -import java.sql.SQLException; +import java.util.regex.Pattern; import java.util.stream.IntStream; +import java.util.stream.Stream; +import java.sql.DriverManager; +import java.sql.Connection; +import java.sql.PreparedStatement; class AvoidSetConstantInBatchUpdateCheck { - void literalSQLrequest() throws SQLException { //dirty call + void literalSQLrequest() throws Exception { //dirty call int x = 0; Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle"); @@ -24,7 +43,7 @@ void literalSQLrequest() throws SQLException { //dirty call con.close(); } - void batchInsertInForLoop(int[] data) throws SQLException { + void batchInsertInForLoop(int[] data) throws Exception { Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle"); PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?,?,?,?,?,?,?,?)"); @@ -33,7 +52,6 @@ void batchInsertInForLoop(int[] data) throws SQLException { stmt.setBoolean(2, true); // Noncompliant {{Avoid setting constants in batch update}} stmt.setByte(3, (byte) 3); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setByte(4, (byte) 'v'); // Noncompliant {{Avoid setting constants in batch update}} stmt.setShort(5, (short) 5); // Noncompliant {{Avoid setting constants in batch update}} stmt.setInt(6, 6); // Noncompliant {{Avoid setting constants in batch update}} stmt.setLong(7, (long) 7); // Noncompliant {{Avoid setting constants in batch update}} @@ -47,12 +65,13 @@ void batchInsertInForLoop(int[] data) throws SQLException { stmt.addBatch(); } int[] nr = stmt.executeBatch(); - System.out.printf("{} rows updated", IntStream.of(nr).sum()); + String nbRows = IntStream.of(nr).sum() + ""; + System.out.println(nbRows + " rows updated"); con.close(); } - int[] batchInsertInForeachLoop(DummyClass[] data) throws SQLException { + int[] batchInsertInForeachLoop(DummyClass[] data) throws Exception { try (Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle")) { PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?,?,?,?,?,?,?,?,?,?)"); @@ -60,7 +79,6 @@ int[] batchInsertInForeachLoop(DummyClass[] data) throws SQLException { stmt.setInt(1, o.getField1()); stmt.setBoolean(2, Boolean.valueOf("false")); // Noncompliant {{Avoid setting constants in batch update}} stmt.setByte(3, o.getField3()); - stmt.setByte(4, (byte) 'v'); // Noncompliant {{Avoid setting constants in batch update}} stmt.setShort(5, (short) 5); // Noncompliant {{Avoid setting constants in batch update}} stmt.setInt(6, 6); // Noncompliant {{Avoid setting constants in batch update}} stmt.setLong(7, 7); // Noncompliant {{Avoid setting constants in batch update}} @@ -75,7 +93,7 @@ int[] batchInsertInForeachLoop(DummyClass[] data) throws SQLException { } - int[] batchInsertInWhileLoop2(DummyClass[] data) throws SQLException { + int[] batchInsertInWhileLoop(DummyClass[] data) throws Exception { try (Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle")) { PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?,?,?,?,?,?,?,?,?,?)"); @@ -86,7 +104,6 @@ int[] batchInsertInWhileLoop2(DummyClass[] data) throws SQLException { stmt.setBoolean(2, Boolean.TRUE); // Noncompliant {{Avoid setting constants in batch update}} stmt.setByte(3, o.getField3()); stmt.setByte(4, Byte.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}} -// stmt.setByte(4, Character.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}} stmt.setShort(5, Short.MIN_VALUE); // Noncompliant {{Avoid setting constants in batch update}} stmt.setInt(6, Integer.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}} stmt.setLong(7, Long.MIN_VALUE); // Noncompliant {{Avoid setting constants in batch update}} @@ -101,7 +118,7 @@ int[] batchInsertInWhileLoop2(DummyClass[] data) throws SQLException { } } - int[] batchInsertInWhileLoop(DummyClass[] data) throws SQLException { + int[] batchInsertInWhileLoop2(DummyClass[] data) throws Exception { if (data.length == 0) { return new int[]{}; } @@ -143,9 +160,8 @@ public byte getField3() { } public double getField4() { - return .1; - } - } - + return .1; } + } + } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheck.java index 6e1a2d89..3d386901 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheck.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheck.java @@ -53,5 +53,5 @@ public Employee(Integer id, String name) { public interface EmployeeRepository extends JpaRepository { } - + } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheck.java index 1716a3d7..5e89dc3f 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheck.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheck.java @@ -22,6 +22,7 @@ import java.util.*; import java.util.stream.Collectors; +import java.util.stream.IntStream; import java.util.stream.Stream; public class AvoidSpringRepositoryCallInStreamCheck { @@ -29,58 +30,71 @@ public class AvoidSpringRepositoryCallInStreamCheck { @Autowired private EmployeeRepository employeeRepository; - public List smellGetAllEmployeesByIdsForEach() { + public void smellGetAllEmployeesByIdsForEach() { List employees = new ArrayList<>(); Stream stream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); stream.forEach(id -> { Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop or stream}} - employee.ifPresent(employees::add); + if (employee.isPresent()) { + employees.add(employee.get()); + } }); - return employees; } - public List smellGetAllEmployeesByIdsForEachOrdered() { + public void smellGetAllEmployeesByIdsForEachOrdered() { List employees = new ArrayList<>(); Stream stream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); stream.forEachOrdered(id -> { Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop or stream}} - employee.ifPresent(employees::add); + if (employee.isPresent()) { + employees.add(employee.get()); + } }); - return employees; } - public List> smellGetAllEmployeesByIdsMap() { + public List smellGetAllEmployeesByIdsMap() { List employees = new ArrayList<>(); Stream stream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); return stream.map(id -> { - Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop or stream}} - employee.ifPresent(employees::add); - return employees; - }) - .collect(Collectors.toList()); + Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop or stream}} + if (employee.isPresent()) { + employees.add(employee.get()); + } + return id; // Return the id + }) + .collect(Collectors.toList()); } public List smellGetAllEmployeesByIdsPeek() { + List employees = new ArrayList<>(); Stream stream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); return stream.peek(id -> { - Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop or stream}} - }) - .collect(Collectors.toList()); + Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop or stream}} + if (employee.isPresent()) { + employees.add(employee.get()); + } + }) + .collect(Collectors.toList()); } public List smellGetAllEmployeesByIdsWithOptional(List ids) { + List employees = new ArrayList<>(); return ids .stream() .map(element -> { - Employee employ = new Employee(1, "name"); - return employeeRepository.findById(element).orElse(employ);// Noncompliant {{Avoid Spring repository call in loop or stream}} + Employee empl = new Employee(1, "nom"); + employees.add(empl); + return employeeRepository.findById(element).orElse(empl);// Noncompliant {{Avoid Spring repository call in loop or stream}} }) .collect(Collectors.toList()); } public List> smellGetAllEmployeesByIds(List ids) { + List employees = new ArrayList<>(); Stream stream = ids.stream(); return stream.map(element -> { + Employee empl = new Employee(1, "nom"); + employees.add(empl); return employeeRepository.findById(element);// Noncompliant {{Avoid Spring repository call in loop or stream}} }) .collect(Collectors.toList()); @@ -90,10 +104,14 @@ public List smellGetAllEmployeesByIdsWithoutStream(List ids) return employeeRepository.findAllById(ids); // Compliant } - public List> smellDeleteEmployeeById(List ids) { + public List smellDeleteEmployeeById(List ids) { + List employees = new ArrayList<>(); Stream stream = ids.stream(); - return stream.map(id -> { - return employeeRepository.findById(id);// Noncompliant {{Avoid Spring repository call in loop or stream}} + return stream.map(element -> { + Employee empl = new Employee(1, "nom"); + employees.add(empl); + employeeRepository.deleteById(element);// Noncompliant {{Avoid Spring repository call in loop or stream}} + return element; // Return the id since deleteById returns void }) .collect(Collectors.toList()); } @@ -101,15 +119,15 @@ public List> smellDeleteEmployeeById(List ids) { public List smellGetAllEmployeesByIdsWithSeveralMethods(List ids) { Stream stream = ids.stream(); return stream.map(element -> { - Employee empl = new Employee(1, "name"); - return employeeRepository.findById(element).orElse(empl);// Noncompliant {{Avoid Spring repository call in loop or stream}} + Employee empl = new Employee(1, "nom"); + return employeeRepository.findById(element).orElse(empl).anotherMethod().anotherOne();// Noncompliant {{Avoid Spring repository call in loop or stream}} }) .collect(Collectors.toList()); } - public static class Employee { - private final Integer id; - private final String name; + public class Employee { + private Integer id; + private String name; public Employee(Integer id, String name) { this.id = id; @@ -118,6 +136,8 @@ public Employee(Integer id, String name) { public Integer getId() { return id; } public String getName() { return name; } + public Employee anotherMethod() { return this; } + public Employee anotherOne() { return this; } } public interface EmployeeRepository extends JpaRepository { diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java index def8b5b8..a4965f1f 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java @@ -1,3 +1,20 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; import java.sql.Connection; @@ -5,15 +22,13 @@ import java.sql.*; import java.sql.PreparedStatement; -import javax.sql.DataSource; - class AvoidStatementForDMLQueries { AvoidStatementForDMLQueries(AvoidStatementForDMLQueries mc) { } - public void insert() throws SQLException { - Connection connection = DriverManager.getConnection("URL"); + public void insert() throws Exception { + Connection connection = DriverManager.getConnection("myurl", "toor", ""); Statement statement = connection.createStatement(); statement.executeUpdate("INSERT INTO persons(id, name) VALUES(2, 'Toto')"); // Noncompliant {{You must not use Statement for a DML query}} } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java index 476fbda8..43acc847 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java @@ -1,3 +1,20 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; import java.util.*; @@ -7,11 +24,11 @@ */ public class AvoidUsageOfStaticCollections { - public static final List LIST = new ArrayList(); // Noncompliant {{Avoid usage of static collections.}} + public static final List LIST = new ArrayList<>(); // Noncompliant {{Avoid usage of static collections.}} - public static final Set SET = new HashSet(); // Noncompliant {{Avoid usage of static collections.}} + public static final Set SET = new HashSet<>(); // Noncompliant {{Avoid usage of static collections.}} - public static final Map MAP = new HashMap(); // Noncompliant {{Avoid usage of static collections.}} + public static final Map MAP = new HashMap<>(); // Noncompliant {{Avoid usage of static collections.}} public AvoidUsageOfStaticCollections() { } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsGoodWay.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsGoodWay.java index bf6d3e06..e7a60938 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsGoodWay.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsGoodWay.java @@ -1,3 +1,20 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; import java.util.*; diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java index 7632450d..70403c64 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java @@ -1,3 +1,20 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; import java.io.*; @@ -7,20 +24,20 @@ class FreeResourcesOfAutoCloseableInterface { } - public void foo1() { + public void foo1() throws Exception { String fileName = "./FreeResourcesOfAutoCloseableInterface.java"; try (FileReader fr = new FileReader(fileName); - BufferedReader br = new BufferedReader(fr)) { + BufferedReader br = new BufferedReader(fr)) { // Compliant } catch (IOException e) { System.err.println(e.getMessage()); } } - public void foo2() throws IOException { + public void foo2() throws Exception { String fileName = "./FreeResourcesOfAutoCloseableInterface.java"; FileReader fr = null; BufferedReader br = null; - try { // Noncompliant + try { // Noncompliant {{try-with-resources Statement needs to be implemented for any object that implements the AutoCloseable interface.}} fr = new FileReader(fileName); br = new BufferedReader(fr); System.out.println(br.readLine()); diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java index b42caa96..c97ef08d 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java @@ -1,6 +1,28 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; class IncrementCheck { + + private class Foo { + public int i; //NOSONAR + } + IncrementCheck(IncrementCheck mc) { } @@ -19,6 +41,11 @@ int foo11() { return ++counter; } + int foo12() { + Foo f = new Foo(); + return f.i++; // Compliant because maybe the use case needs to return j AND increment it + } + int foo2() { int counter = 0; counter++; // Noncompliant {{Use ++i instead of i++}} diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java index 8cc73e29..a83c21e7 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java @@ -1,5 +1,27 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; + class InitializeBufferWithAppropriateSize { InitializeBufferWithAppropriateSize(InitializeBufferWithAppropriateSize mc) { } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java index 8e24b914..dc192cdd 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java @@ -1,3 +1,5 @@ +package org.greencodeinitiative.creedengo.java.checks; + import java.util.logging.Logger; public class MakeNonReassignedVariablesConstants { diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java index 1c225677..a7a62132 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java @@ -1,4 +1,4 @@ -package org.greencodeinitiative.creedengo.java.integration.tests;/* +/* * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) * @@ -15,6 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + +package org.greencodeinitiative.creedengo.java.checks; + import java.util.Iterator; import java.util.List; import java.util.ListIterator; @@ -133,8 +136,8 @@ public void test8() { } class OtherClassWrapper { - public Iterator iterator = null; - public Enumeration enumeration = null; + public Iterator iterator; + public Enumeration enumeration; public OtherClassWrapper(Iterator iterator){ this.iterator = iterator; diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java index 91520bd5..bd33a88f 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java @@ -1,19 +1,30 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStream; import java.util.Arrays; import java.util.List; -import java.util.logging.Logger; - -import static java.lang.System.Logger.Level.ERROR; - -class OptimizeReadFileExceptionCheck { - - Logger logger = Logger.getLogger(""); +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.FileNotFoundException; - OptimizeReadFileExceptionCheck(OptimizeReadFileExceptionCheck readFile) { +class ReadFile { + ReadFile(ReadFile readFile) { } public void readPreferences(String filename) { @@ -22,7 +33,7 @@ public void readPreferences(String filename) { try { in = new FileInputStream(filename); // Noncompliant {{Optimize Read File Exceptions}} } catch (FileNotFoundException e) { - logger.info(e.getMessage()); + System.out.println(e); } //... } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java index 205b814a..7ad10f63 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java @@ -1,26 +1,38 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; import java.util.Arrays; import java.util.List; -import java.util.logging.Logger; - -class OptimizeReadFileExceptionCheck2 { - - Logger logger = Logger.getLogger(""); +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.FileNotFoundException; - OptimizeReadFileExceptionCheck2(OptimizeReadFileExceptionCheck2 readFile) { +class ReadFile2 { + ReadFile2(ReadFile2 readFile) { } - public void readPreferences(String filename) throws IOException { + public void readPreferences(String filename) throws Exception { //... try (InputStream in = new FileInputStream(filename)) { // Noncompliant {{Optimize Read File Exceptions}} - logger.info("my log"); + System.out.println("my log"); } catch (FileNotFoundException e) { - logger.info(e.getMessage()); + System.out.println(e); } //... } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java index a26b6ea7..78e59393 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java @@ -1,25 +1,38 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; import java.util.Arrays; import java.util.List; -import java.util.logging.Logger; - -class OptimizeReadFileExceptionCheck3 { - - Logger logger = Logger.getLogger(""); +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.IOException; - OptimizeReadFileExceptionCheck3(OptimizeReadFileExceptionCheck3 readFile) { +class ReadFile3 { + ReadFile3(ReadFile3 readFile) { } public void readPreferences(String filename) { //... try (InputStream in = new FileInputStream(filename)) { // Noncompliant {{Optimize Read File Exceptions}} - logger.info("my log"); + System.out.println("my log"); } catch (IOException e) { - logger.info(e.getMessage()); + System.out.println(e); } //... } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java index 80a75d9d..001e0059 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java @@ -1,24 +1,37 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; -import java.io.FileInputStream; -import java.io.InputStream; import java.util.Arrays; import java.util.List; -import java.util.logging.Logger; - -class OptimizeReadFileExceptionCheck4 { - - Logger logger = Logger.getLogger(""); +import java.io.FileInputStream; +import java.io.InputStream; - OptimizeReadFileExceptionCheck4(OptimizeReadFileExceptionCheck4 readFile) { +class ReadFile4 { + ReadFile4(ReadFile4 readFile) { } public void readPreferences(String filename) { //... try (InputStream in = new FileInputStream(filename)) { // Noncompliant {{Optimize Read File Exceptions}} - logger.info("my log"); + System.out.println("my log"); } catch (Exception e) { - logger.info(e.getMessage()); + System.out.println(e); } //... } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java index 2115bef1..4b0ff359 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java @@ -1,24 +1,37 @@ +/* + * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.greencodeinitiative.creedengo.java.checks; -import java.io.FileInputStream; -import java.io.InputStream; import java.util.Arrays; import java.util.List; -import java.util.logging.Logger; - -class OptimizeReadFileExceptionCheck5 { - - Logger logger = Logger.getLogger(""); +import java.io.FileInputStream; +import java.io.InputStream; - OptimizeReadFileExceptionCheck5(OptimizeReadFileExceptionCheck5 readFile) { +class ReadFile5 { + ReadFile5(ReadFile5 readFile) { } public void readPreferences(String filename) { //... try (InputStream in = new FileInputStream(filename)) { // Noncompliant {{Optimize Read File Exceptions}} - logger.info("my log"); + System.out.println("my log"); } catch (Throwable e) { - logger.info(e.getMessage()); + System.out.println(e); } //... } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java index 20a0decc..6a93a0be 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java @@ -16,6 +16,8 @@ * along with this program. If not, see . */ +package org.greencodeinitiative.creedengo.java.checks; + import java.util.Optional; class UseOptionalOrElseGetVsOrElse { diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ZzzDDCToCheckOptimizeSQLQueriesWithLimit.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ZzzDDCToCheckOptimizeSQLQueriesWithLimit.java deleted file mode 100644 index f90c2cb4..00000000 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ZzzDDCToCheckOptimizeSQLQueriesWithLimit.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.greencodeinitiative.creedengo.java.checks; - -import org.springframework.data.jpa.repository.Query; - -import java.util.ArrayList; -import java.util.List; - -class ZzzDDCToCheckOptimizeSQLQueriesWithLimit { - - public void literalSQLrequest() { - dummyCall("SELECT user FROM myTable"); // Noncompliant {{Optimize Database SQL Queries (Clause LIMIT)}} - dummyCall("SELECT user FROM myTable LIMIT 50"); // Compliant - } - - @Query("select t from Todo t where t.status != 'COMPLETED'") // Noncompliant {{Optimize Database SQL Queries (Clause LIMIT)}} - public List findAllUsers() { - return new ArrayList<>(); - } - - @Query("select t from Todo t where t.status != 'COMPLETED' LIMIT 25") // Compliant - public List findFirstUsers() { - return new ArrayList<>(); - } - - private void callQuery() { - String sql1 = "SELECT user FROM myTable"; // Noncompliant {{Optimize Database SQL Queries (Clause LIMIT)}} - String sql2 = "SELECT user FROM myTable LIMIT 50"; // Compliant - } - - private void dummyCall(String request) { - } -} diff --git a/src/test/files/ArrayCopyCheck.java b/src/test/files/ArrayCopyCheck.java deleted file mode 100644 index 79d8353d..00000000 --- a/src/test/files/ArrayCopyCheck.java +++ /dev/null @@ -1,510 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -class TestClass { - - public void copyArrayOK() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Copy with clone - dest = src.clone(); - - // Copy with System.arraycopy() - System.arraycopy(src, 0, dest, 0, src.length); - - // Copy with Arrays.copyOf() - dest = Arrays.copyOf(src, src.length); - } - - public void nonRegression() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple assignation - for (int i = 0; i < len; i++) { - dest[i] = true; - } - - // Edit same array - for (int i = 0; i < len-1; i++) { - dest[i] = dest[i+1]; - } - - // Objects assignations - String a = null; - String b = "Sample Value"; - for (int i = 0; i < len; i++) { - a = b; - } - } - - public void copyWithForLoop() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple copy - for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} - dest[i] = src[i]; - } - - // Copy with nested conditions - for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} - if(i + 2 < len) { - dest[i] = src[i + 2]; - } - } - - // Copy with nested ELSE conditions - for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} - if(i + 2 >= len) { - i++; - } else { - dest[i] = src[i + 2]; - } - } - - // Copy with more nested conditions - for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} - if(i + 2 < len) { - if(dest != null) { - if(src != null) { - if(i > 1 && i + 2 < src.length) { - dest[i] = src[i + 2]; - } - } - } - } - } - - // Copy nested by try/catch - for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} - try { - dest[i] = src[i]; - } catch (RuntimeException e) { - e.printStackTrace(); - } - } - - // Copy nested by try/catch and if - for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} - try { - if(dest != null) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - } - - // Copy nested by try/catch in catch - for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} - try { - dest.toString(); - } catch (RuntimeException e) { - if(dest != null) { - dest[i] = src[i]; - } - } - } - - // Copy nested by try/catch in finally - for (int i = 0; i < len; i++) { // Noncompliant {{Use System.arraycopy to copy arrays}} - try { - dest.toString(); - } catch (RuntimeException e) { - e.printStackTrace(); - } finally { - dest[i] = src[i]; - } - } - - // Array transformation - for (int i = 0; i < len; i++) { - dest[i] = transform(src[i]); - } - } - - public void copyWithForEachLoop() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple copy by foreach - int i = -1; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} - dest[++i] = b; - } - - // Copy with nested conditions by foreach - i = -1; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} - if(b) { - dest[++i] = b; - } - } - - // Copy with nested ELSE conditions by foreach - i = -1; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} - if(i + 2 >= len) { - i++; - } else { - dest[++i] = b; - } - } - - // Copy with more nested conditions - i = -1; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} - if(i + 2 < len) { - if(dest != null) { - if(src != null) { - if(i > 1 && i + 2 < src.length) { - dest[++i] = b; - } - } - } - } - } - - // Copy nested by try/catch - i = -1; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} - try { - dest[++i] = b; - } catch (RuntimeException e) { - e.printStackTrace(); - } - } - - // Copy nested by try/catch and if - i = -1; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} - try { - if(dest != null) { - dest[++i] = b; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - } - - // Copy nested by try/catch in catch - i = -1; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} - try { - dest.toString(); - } catch (RuntimeException e) { - if(dest != null) { - dest[++i] = b; - } - } - } - - // Copy nested by try/catch in finally - i = -1; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} - try { - dest.toString(); - } catch (RuntimeException e) { - e.printStackTrace(); - } finally { - dest[++i] = b; - } - } - - // Array transformation - i = -1; - for (boolean b : src) { - dest[++i] = transform(b); - } - - // Simple copy - int i = 0; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} - dest[i] = src[i]; - i++; - } - - // Copy with nested conditions - i = 0; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} - if(b) { - dest[i] = src[i]; - } - i++; - } - - // Copy with nested ELSE conditions - i = 0; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} - if(i + 2 >= len) { - i++; - } else { - dest[i] = src[i + 2]; - } - i++; - } - - // Copy with more nested conditions - i = 0; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} - if(i + 2 < len) { - if(dest != null) { - if(src != null) { - if(i > 1 && i + 2 < src.length) { - dest[i] = src[i + 2]; - } - } - } - } - i++; - } - - // Copy nested by try/catch - i = 0; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} - try { - dest[i] = src[i]; - } catch (RuntimeException e) { - e.printStackTrace(); - } - i++; - } - - // Copy nested by try/catch and if - i = 0; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} - try { - if(dest != null) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - i++; - } - - // Copy nested by try/catch in catch - i = 0; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} - try { - dest.toString(); - } catch (RuntimeException e) { - if(dest != null) { - dest[i] = src[i]; - } - } - i++; - } - - // Copy nested by try/catch in finally - i = 0; - for (boolean b : src) { // Noncompliant {{Use System.arraycopy to copy arrays}} - try { - dest.toString(); - } catch (RuntimeException e) { - e.printStackTrace(); - } finally { - dest[i] = src[i]; - } - i++; - } - - // Array transformation - i = 0; - for (boolean b : src) { - dest[i] = transform(src[i]); - i++; - } - } - - public void copyWithWhileLoop() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple copy - int i = 0; - while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} - dest[i] = src[i]; - i++; - } - - // Copy with nested conditions - i = 0; - while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} - if(i + 2 < len) { - dest[i] = src[i + 2]; - } - i++; - } - - // Copy with nested ELSE conditions - i = 0; - while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} - if(i + 2 >= len) { - i++; - } else { - dest[i] = src[i + 2]; - } - i++; - } - - // Copy with more nested conditions - i = 0; - while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} - if(i + 2 < len) { - if(dest != null) { - if(src != null) { - if(i > 1 && i + 2 < src.length) { - dest[i] = src[i + 2]; - } - } - } - } - i++; - } - - // Copy nested by try/catch and if - i = 0; - while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} - try { - if(dest != null) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - i++; - } - - // Copy nested by try/catch in catch - i = 0; - while (i < len) { // Noncompliant {{Use System.arraycopy to copy arrays}} - try { - dest.toString(); - } catch (RuntimeException e) { - if(dest != null) { - dest[i] = src[i]; - } - } - i++; - } - - // Array transformation - i = 0; - while (i < len) { - dest[i] = transform(src[i]); - i++; - } - } - - public void copyWithDoWhileLoop() { - final int len = 5; - final boolean[] src = new boolean[len]; - boolean[] dest = new boolean[len]; - - // Simple copy - int i = 0; - do { // Noncompliant {{Use System.arraycopy to copy arrays}} - dest[i] = src[i]; - i++; - } while (i < len); - - // Copy with nested conditions - i = 0; - do { // Noncompliant {{Use System.arraycopy to copy arrays}} - if(i + 2 < len) { - dest[i] = src[i + 2]; - } - i++; - } while (i < len); - - // Copy with nested ELSE conditions - i = 0; - do { // Noncompliant {{Use System.arraycopy to copy arrays}} - if(i + 2 >= len) { - i++; - } else { - dest[i] = src[i + 2]; - } - i++; - } while (i < len); - - // Copy with more nested conditions - i = 0; - do { // Noncompliant {{Use System.arraycopy to copy arrays}} - if(i + 2 < len) { - if(dest != null) { - if(src != null) { - if(i > 1 && i + 2 < src.length) { - dest[i] = src[i + 2]; - } - } - } - } - i++; - } while (i < len); - - // Copy nested by try/catch and if - i = 0; - do { // Noncompliant {{Use System.arraycopy to copy arrays}} - try { - if(dest != null) { - dest[i] = src[i]; - } - } catch (RuntimeException e) { - e.printStackTrace(); - } - i++; - } while (i < len); - - // Copy nested by try/catch in catch - i = 0; - do { // Noncompliant {{Use System.arraycopy to copy arrays}} - try { - dest.toString(); - } catch (RuntimeException e) { - if(dest != null) { - dest[i] = src[i]; - } - } - i++; - } while (i < len); - - // Array transformation - i = 0; - do { - dest[i] = transform(src[i]); - i++; - } while (i < len); - } - - private boolean transform(boolean a) { - return !a; - } - -} diff --git a/src/test/files/AvoidFullSQLRequestCheck.java b/src/test/files/AvoidFullSQLRequestCheck.java deleted file mode 100644 index 2d6b2e6a..00000000 --- a/src/test/files/AvoidFullSQLRequestCheck.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.util.regex.Pattern; - -class AvoidFullSQLRequestCheck { - AvoidFullSQLRequestCheck(AvoidFullSQLRequestCheck mc) { - } - - public void literalSQLrequest() { - dummyCall(" sElEcT * fRoM myTable"); // Noncompliant {{Don't use the query SELECT * FROM}} - dummyCall(" sElEcT user fRoM myTable"); - - dummyCall("SELECTABLE 2*2 FROMAGE"); //not sql - dummyCall("SELECT *FROM table"); // Noncompliant {{Don't use the query SELECT * FROM}} - } - - - public void variableSQLrequest() { - String requestNonCompiliant = " SeLeCt * FrOm myTable"; // Noncompliant {{Don't use the query SELECT * FROM}} - String requestCompiliant = " SeLeCt user FrOm myTable"; - dummyCall(requestNonCompiliant); - dummyCall(requestCompiliant); - - String noSqlCompiliant = "SELECTABLE 2*2 FROMAGE"; //not sql - String requestNonCompiliant_nSpace = "SELECT *FROM table"; // Noncompliant {{Don't use the query SELECT * FROM}} - } - - private void dummyCall(String request) { - - } - -} diff --git a/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java b/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java deleted file mode 100644 index ce4eeac9..00000000 --- a/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.util.Collection; -import java.util.ArrayList; -import java.util.List; - -class AvoidGettingSizeCollectionInForEachLoopIgnored { - AvoidGettingSizeCollectionInForEachLoopIgnored(AvoidGettingSizeCollectionInForEachLoopIgnored obj) { - - } - - public void ignoredLoop() { - List numberList = new ArrayList(); - numberList.add(10); - numberList.add(20); - - for (Integer i : numberList) { // Ignored - int size = numberList.size(); // Compliant with this rule - System.out.println("numberList.size()"); - } - } -} diff --git a/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java b/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java deleted file mode 100644 index b437655d..00000000 --- a/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.greencodeinitiative.creedengo.java.checks; - -import java.util.ArrayList; -import java.util.List; - -class AvoidGettingSizeCollectionInForLoopBad { - - public void badForLoop() { - final List numberList = new ArrayList(); - numberList.add(10); - numberList.add(20); - - for (int i = 0; i < numberList.size(); ++i) { // Noncompliant {{Avoid getting the size of the collection in the loop}} - System.out.println("numberList.size()"); - } - } -} diff --git a/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java b/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java deleted file mode 100644 index 691bc334..00000000 --- a/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.util.Collection; -import java.util.ArrayList; -import java.util.List; - -class AvoidGettingSizeCollectionInForLoopGood { - AvoidGettingSizeCollectionInForLoopGood(AvoidGettingSizeCollectionInForLoopGood obj) { - - } - - public void goodForLoop() { - List numberList = new ArrayList(); - numberList.add(10); - numberList.add(20); - - int size = numberList.size(); - for (int i = 0; i < size; i++) { // Compliant - System.out.println("numberList.size()"); - int size = numberList.size(); // Compliant with this rule - } - } -} diff --git a/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java b/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java deleted file mode 100644 index c1fa56cb..00000000 --- a/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.util.Collection; -import java.util.ArrayList; -import java.util.List; - -class GCI69AvoidGettingSizeCollectionInForLoopBad { - AvoidGettingSizeCollectionInForLoopBad() { - - } - - public void badForLoop() { - final List numberList = new ArrayList(); - numberList.add(10); - numberList.add(20); - - final Iterator it = numberList.iterator(); - for (; it.hasNext(); ) { // Ignored => compliant - System.out.println(it.next()); - } - } -} diff --git a/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java b/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java deleted file mode 100644 index def86d2b..00000000 --- a/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.util.Collection; -import java.util.ArrayList; -import java.util.List; - -class AvoidGettingSizeCollectionInWhileLoopBad { - AvoidGettingSizeCollectionInWhileLoopBad() { - - } - - public void badWhileLoop() { - List numberList = new ArrayList(); - numberList.add(10); - numberList.add(20); - - int i = 0; - while (i < numberList.size()) { // Noncompliant {{Avoid getting the size of the collection in the loop}} - System.out.println("numberList.size()"); - i++; - } - } -} diff --git a/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java b/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java deleted file mode 100644 index 713998d5..00000000 --- a/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.util.Collection; -import java.util.ArrayList; -import java.util.List; - -class AvoidGettingSizeCollectionInWhileLoopGood { - AvoidGettingSizeCollectionInWhileLoopGood(AvoidGettingSizeCollectionInWhileLoopGood obj) { - - } - - public void goodWhileLoop() { - List numberList = new ArrayList(); - numberList.add(10); - numberList.add(20); - - int size = numberList.size(); - int i = 0; - while (i < size) { // Compliant - System.out.println("numberList.size()"); - int size2 = numberList.size(); // Compliant with this rule - i++; - } - } -} diff --git a/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java b/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java deleted file mode 100644 index 99009585..00000000 --- a/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.util.Collection; -import java.util.ArrayList; -import java.util.List; - -class AvoidGettingSizeCollectionInWhileLoopBad { - AvoidGettingSizeCollectionInWhileLoopBad() { - - } - - public void badWhileLoop() { - List numberList = new ArrayList(); - numberList.add(10); - numberList.add(20); - - Iterator it = numberList.iterator(); - int i = 0; - while (it.hasNext()) { // Ignored => compliant - it.next(); - System.out.println("numberList.size()"); - } - } -} diff --git a/src/test/files/AvoidMultipleIfElseStatement.java b/src/test/files/AvoidMultipleIfElseStatement.java deleted file mode 100644 index 52bc42ac..00000000 --- a/src/test/files/AvoidMultipleIfElseStatement.java +++ /dev/null @@ -1,283 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -class AvoidMultipleIfElseStatementCheck { - -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// // -// // NON COMPLIANT use cases -// // -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - // NON COMPLIANT - // USE CASE : Non compliant use case to check if following is NON OK : - // - two uses of the same variable - // - usage of the same variable on different levels of IF statements - public int shouldBeCompliantBecauseVariableUsedMaximumTwiceInComposedElseStatements() - { - int nb1 = 0; - - if (nb1 == 1) { - nb1 = 2; - } else { - if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - nb1 = 1; - } - } - - return nb1; - } - - // NON COMPLIANT - // USE CASE : non compliant use case to check if a variable is not used max twice on several IF / ELSE statements - // at the same level - public int shouldBeNotCompliantBecauseVariablesUsedMaximumTwiceAndDifferentsVariablesUsed() - { - int nb1 = 0; - int nb2 = 0; - int nb3 = 0; - - if (nb3 == 1 - && nb3 == 2 - && nb3 == 3) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - nb1 = 1; - } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - nb2 = 2; - } - - if (nb2 == 2) { - nb1 = 3; - } else { - nb1 = 4; - } - - return nb1; - } - - // NON COMPLIANT - // USE CASE : NON compliant use case to check if following is NOT COMPLIANT : - // one variable is used maximum in two IF / ELSE / ELSEIF statements - public int shouldBeNotCompliantBecauseVariablesIsUsedMoreThanTwice() - { - int nb1 = 0; - - if (nb1 == 1) { - nb1 = 2; - } else { - nb1 = 3; - } - - if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - nb1 = 4; - } - - return nb1; - } - - // NON COMPLIANT - // USE CASE : NON compliant use case to check if following is NOT OK : - // - same variable used maximum twice : no compliant because 2 IFs and 1 ELSE - public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInIfStatementsAtDifferentsLevels() - { - int nb1 = 0; - - if (nb1 == 1) { - if (nb1 == 2) { - nb1 = 1; - } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - nb1 = 3; - } - } else { - nb1 = 2; - } - - return nb1; - } - - - // NON COMPLIANT - // USE CASE : non compliant use case to check if following is NOT OK : - // - two uses of the same variable : use thre times with 2 IFs and 1 ELSE - // - usage of the same variable on different levels of IF statements - public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseStatements() - { - int nb1 = 0; - - if (nb1 == 1) { - nb1 = 2; - } else { - if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - nb1 = 1; - } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - nb1 = 3; - } - } - - return nb1; - } - - // NON COMPLIANT - // USE CASE : non compliant use case to check if following is NOT OK : - // - two uses of the same variable : use thre times with 2 IFs and 1 ELSE - // - usage of the same variable on different levels of IF statements - public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseStatementsScenario2() - { - int nb1 = 0; - - if (nb1 == 1) { - if (nb1 == 3) { - nb1 = 4; - } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - nb1 = 5; - } - } else { - if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - nb1 = 1; - } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - nb1 = 3; - } - } - - return nb1; - } - - - // NON COMPLIANT - // USE CASE : non compliant use case to check if following is NOT OK : - // - two uses of the same variable : use thre times with 2 IFs and 1 ELSE - // - usage of the same variable on different levels of IF statements - public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseStatementsScenario3() - { - int nb1 = 0; - int nb2 = 0; - - if (nb1 == 1) { - if (nb1 == 3) { - nb1 = 4; - } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - nb1 = 5; - } - } else if (nb2 == 2) { - if (nb1 == 4) { - nb1 = 5; - } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - nb1 = 6; - } - } - - return nb1; - } - - // NON COMPLIANT - // USE CASE : non compliant use case to check if following is NOT OK : - // - two uses of the same variable : use thre times with 2 IFs and 1 ELSE - // - usage of the same variable on different levels of IF statements - public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseStatementsScenario4() - { - int nb1 = 0; - int nb2 = 0; - - if (nb1 == 1) { - if (nb2 == 3) { - nb1 = 4; - } else { - nb1 = 5; - } - } else if (nb2 == 2) { - if (nb1 == 3) { - nb1 = 4; - } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - nb1 = 5; - } - } - - return nb1; - } - - // NON COMPLIANT - // USE CASE : NON compliant use case to check if following is NOT OK : - // - the same variable must used maximum twice - // - usage of the same variable on different levels of IF / ELSE statements - public int shouldBeNotCompliantBecauseVariableUsedMaximumTwiceInComposedElseStatements() - { - int nb1 = 0; - - if (nb1 == 1) { - nb1 = 2; - } else { - if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - nb1 = 1; - } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - if (nb1 == 3) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - nb1 = 4; - } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - nb1 = 5; - } - } - } - - return nb1; - } - - // NON COMPLIANT - // USE CASE : NON compliant use case to check if following is NOT OK : - // - more than twice uses of the same variable - // - usage of the same variable on different kind of test statements (IF and ELSEIF) - public int shouldBeNotCompliantBecauseTheSameVariableIsUsedMoreThanTwice() // NOT Compliant - { - int nb1 = 0; - int nb2 = 10; - - if (nb1 == 1) { - nb2 = 1; - } else if (nb1 == nb2) { - nb2 = 2; - } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - nb2 = 4; - } - - return nb2; - } - - // NON COMPLIANT - // USE CASE : NON compliant use case to check if following is NOT OK : - // - more than twice uses of the same variable - // - usage of the same variable on different kind of test statements (IF and ELSEIF) - public int shouldBeNotCompliantBecauseTheSameVariableIsUsedManyTimes() // NOT Compliant - { - int nb1 = 0; - int nb2 = 10; - int nb3 = 11; - - if (nb1 == 1) { - nb2 = 1; - } else if (nb1 == nb2) { - nb2 = 2; - } else if (nb3 == nb1) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - nb2 = 3; - } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} - nb2 = 4; - } - - return nb2; - } - -} diff --git a/src/test/files/AvoidMultipleIfElseStatementInterface.java b/src/test/files/AvoidMultipleIfElseStatementInterface.java deleted file mode 100644 index c9c76041..00000000 --- a/src/test/files/AvoidMultipleIfElseStatementInterface.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -interface AvoidMultipleIfElseStatementCheck { - - TransactionMetaData initMetaData(ITransactionFoundation transactionFoundation) throws ProgramException, MnemonicTemplateShellException; - -} diff --git a/src/test/files/AvoidMultipleIfElseStatementNoIssue.java b/src/test/files/AvoidMultipleIfElseStatementNoIssue.java deleted file mode 100644 index 53e72dd1..00000000 --- a/src/test/files/AvoidMultipleIfElseStatementNoIssue.java +++ /dev/null @@ -1,274 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -class AvoidMultipleIfElseStatementCheckNoIssue { - - // inital RULES : please see HTML description file of this rule (resources directory) - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // COMPLIANT use cases - // - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - // COMPLIANT - // USE CASE : compliant use case to check if a variable is used maximum twice on several IF / ELSE statements - // at the same level AND no problem with several IF staments at the same level using different variables - public int shouldBeCompliantBecauseVariablesUsedMaximumTwiceAndDifferentsVariablesUsed() - { - int nb1 = 0; - int nb2 = 0; - int nb3 = 0; - - if (nb3 != 1 && nb1 > 1) { - nb1 = 1; - } else { - nb2 = 2; - } - - if (nb2 == 2) { - nb1 = 3; - } else { - nb1 = 4; - } - - return nb1; - } - - // COMPLIANT - // USE CASE : compliant use case to check if a variable is used maximum twice on several IF / ELSE statements - // at the same level AND no problem with several IF staments at the same level using different variables - public int shouldBeCompliantBecauseVariablesUsedMaximumTwiceAndDifferentsVariablesUsedAtDiffLevels() - { - int nb1 = 0; - int nb2 = 0; - int nb3 = 0; - - if (nb1 < 1) { - if (nb2 == 2) { - nb3 = 3; - } else { - nb3 = 4; - } - } else { - nb2 = 2; - } - - if (nb3 >= 1) { - if (nb2 == 2) { - nb1 = 3; - } else { - nb1 = 4; - } - } else { - nb1 = 2; - } - - return nb1; - } - - // COMPLIANT - // USE CASE : compliant use case to check if a variable is used maximum twice on several IF / ELSE statements - // at the same level AND no problem with several IF staments at the same level using different variables - public int shouldBeCompliantBecauseVariablesUsedMaximumTwiceAndDiffVariablesUsedAtDiffLevelsScenario2() - { - int nb1 = 0; - int nb2 = 0; - int nb3 = 0; - - if (nb1 <= 1) { - if (nb2 == 2) { - if (nb3 == 2) { - nb3 = 3; - } else { - nb3 = 4; - } - } else { - nb3 = 4; - } - } else { - nb2 = 2; - } - - if (nb3 == 1) { - if (nb2 == 2) { - nb1 = 3; - } else { - nb1 = 4; - } - } else { - nb1 = 2; - } - - return nb1; - } - - // COMPLIANT - // USE CASE : compliant use case to check if one variable is used maximum twice in different IF statements - public int shouldBeCompliantBecauseVariableUsedMaximumTwiceInIfStatements() - { - int nb1 = 0; - - if (nb1 == 1) { - nb1 = 1; - } - - if (nb1 == 2) { - nb1 = 3; - } - - return nb1; - } - - // COMPLIANT - // USE CASE : compliant use case to check if following is OK : - // - two uses of the same variable - // - usage of the same variable on different levels of IF statements - public int shouldBeCompliantBecauseSereralVariablesUsedMaximumTwiceInComposedElseStatements() - { - int nb1 = 0; - int nb2 = 0; - int nb3 = 0; - - if (nb1 == 1) { - nb1 = 2; - } else { - if (nb2 == 2) { - nb1 = 1; - } else { - if (nb3 == 4) { - nb1 = 3; - } else { - nb1 = 6; - } - } - } - - return nb1; - } - - // COMPLIANT - // USE CASE : compliant use case to check if following is OK : - // - two uses of the same variable - // - usage of the same variable on different kind of test statements (IF and ELSEIF) - public int shouldBeCompliantBecauseVariableUsedMaximumTwiceInIfOrElseIfStatements() // Compliant - { - int nb1 = 0; - int nb2 = 10; - - if (nb1 == 1) { - nb2 = 1; - } else if (nb1 == nb2) { - nb2 = 2; - } - - return nb2; - } - - // COMPLIANT - // USE CASE : compliant use case to check if following is OK : - // - two uses of the same variable - // - usage of the same variable on different kind of test statements (IF and ELSEIF) - public int shouldBeCompliantBecauseSeveralVariablesUsedMaximumTwiceInIfOrElseIfStatements() // Compliant - { - int nb1 = 0; - int nb2 = 10; - int nb3 = 3; - int nb4 = 1; - int nb5 = 2; - - if (nb1 == 1) { - nb2 = 1; - } else if (nb3 == nb2) { - nb2 = 2; - } else if (nb4 == nb5) { - nb2 = 4; - } else { - nb2 = 3; - } - - return nb2; - } - - // COMPLIANT - // USE CASE : Compliant use case to check if following is OK : - // - usage of the same variable on different levels of IF statements but with incompatible type for a switch - public float shouldBeCompliantBecauseVariableHasNotCompatibleTypeFloatForSwitch() - { - float nb1 = 0.0f; - - if (nb1 > 1) { - nb1 = 2.1f; - } else { - if (nb1 > 2) { - nb1 = 1.1f; - } - } - - return nb1; - } - - // COMPLIANT - // USE CASE : Compliant use case to check if following is OK : - // - usage of the same variable on different levels of IF statements but with incompatible type for a switch - public double shouldBeCompliantBecauseVariableHasNotCompatibleTypeDoubleForSwitch() - { - double nb1 = 0.0; - - if (nb1 > 1) { - nb1 = 2.1; - } else { - if (nb1 > 2) { - nb1 = 1.1; - } - } - - return nb1; - } - - // COMPLIANT - // USE CASE : Compliant use case to check if following is OK : - // - usage of the same variable on different levels of IF statements but with instanceof keys - // - with a variable used 4 times - public int shouldBeCompliantBecauseVariableUsed4TimesWithInstanceOfKeys() - { - int nb1 = 0; - Object obj = new Object(); - - if (obj instanceof String) { - nb1 = 1; - } else { - if (obj instanceof Integer) { - nb1 = 2; - } else { - if (obj instanceof Double) { - nb1 = 3; - } else { - nb1 = 4; - } - } - } - - return nb1; - } - - -} diff --git a/src/test/files/AvoidRegexPatternNotStatic.java b/src/test/files/AvoidRegexPatternNotStatic.java deleted file mode 100644 index 76387635..00000000 --- a/src/test/files/AvoidRegexPatternNotStatic.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.util.regex.Pattern; - -public class AvoidRegexPatternNotStatic { - - public boolean foo() { - final Pattern pattern = Pattern.compile("foo"); // Noncompliant {{Avoid using Pattern.compile() in a non-static context.}} - return pattern.matcher("foo").find(); - } -} diff --git a/src/test/files/AvoidRegexPatternNotStaticValid1.java b/src/test/files/AvoidRegexPatternNotStaticValid1.java deleted file mode 100644 index 638ffd96..00000000 --- a/src/test/files/AvoidRegexPatternNotStaticValid1.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.util.regex.Pattern; - -public class AvoidRegexPatternNotStaticValid1 { - - private static final Pattern pattern = Pattern.compile("foo"); // Compliant - - public boolean foo() { - return pattern.matcher("foo").find(); - } -} diff --git a/src/test/files/AvoidRegexPatternNotStaticValid2.java b/src/test/files/AvoidRegexPatternNotStaticValid2.java deleted file mode 100644 index 0ef9517c..00000000 --- a/src/test/files/AvoidRegexPatternNotStaticValid2.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.util.regex.Pattern; - -public class AvoidRegexPatternNotStaticValid2 { - - private final Pattern pattern = Pattern.compile("foo"); // Compliant - - public boolean foo() { - return pattern.matcher("foo").find(); - } -} diff --git a/src/test/files/AvoidRegexPatternNotStaticValid3.java b/src/test/files/AvoidRegexPatternNotStaticValid3.java deleted file mode 100644 index f1378974..00000000 --- a/src/test/files/AvoidRegexPatternNotStaticValid3.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.util.regex.Pattern; - -public class AvoidRegexPatternNotStaticValid3 { - - private final Pattern pattern; - - public AvoidRegexPatternNotStaticValid3() { - pattern = Pattern.compile("foo"); // Compliant - } - - public boolean foo() { - return pattern.matcher("foo").find(); - } -} diff --git a/src/test/files/AvoidSQLRequestInLoopCheck.java b/src/test/files/AvoidSQLRequestInLoopCheck.java deleted file mode 100644 index f75e0c92..00000000 --- a/src/test/files/AvoidSQLRequestInLoopCheck.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.Statement; - -class AvoidSQLRequestInLoopCheck { - AvoidSQLRequestInLoopCheck(AvoidSQLRequestInLoopCheck mc) { - } - - public void testWithNoLoop() { - try { - // create our mysql database connection - String myDriver = "driver"; - String myUrl = "driver"; - Class.forName(myDriver); - Connection conn = DriverManager.getConnection(myUrl, "toor", ""); - - // our SQL SELECT query. - // if you only need a few columns, specify them by name instead of using "*" - String query = "SELECT * FROM users"; - - // create the java statement - Statement st = conn.createStatement(); - ResultSet rs = st.executeQuery(query); - - // iterate through the java resultset - while (rs.next()) { - int id = rs.getInt("id"); - System.out.println(id); - } - st.close(); - } catch (Exception e) { - System.err.println("Got an exception! "); - System.err.println(e.getMessage()); - } - } - - public void testWithForLoop() { - try { - // create our mysql database connection - String myDriver = "driver"; - String myUrl = "driver"; - Class.forName(myDriver); - Connection conn = DriverManager.getConnection(myUrl, "toor", ""); - - // our SQL SELECT query. - // if you only need a few columns, specify them by name instead of using "*" - String baseQuery = "SELECT name FROM users where id = "; - - for (int i = 0; i < 20; i++) { - - // create the java statement - String query = baseQuery.concat("" + i); - Statement st = conn.createStatement(); - ResultSet rs = st.executeQuery(query); // Noncompliant {{Avoid SQL request in loop}} - - // iterate through the java resultset - while (rs.next()) { - String name = rs.getString("name"); - System.out.println(name); - } - st.close(); - } - } catch (Exception e) { - System.err.println("Got an exception! "); - System.err.println(e.getMessage()); - } - } - - public void testWithForEachLoop() { - try { - // create our mysql database connection - String myDriver = "driver"; - String myUrl = "driver"; - Class.forName(myDriver); - Connection conn = DriverManager.getConnection(myUrl, "toor", ""); - - // our SQL SELECT query. - // if you only need a few columns, specify them by name instead of using "*" - String query = "SELECT * FROM users"; - int[] intArray = {10, 20, 30, 40, 50}; - for (int i : intArray) { - System.out.println(i); - // create the java statement - Statement st = conn.createStatement(); - ResultSet rs = st.executeQuery(query); // Noncompliant {{Avoid SQL request in loop}} - - // iterate through the java resultset - while (rs.next()) { - int id = rs.getInt("id"); - System.out.println(id); - } - st.close(); - } - } catch (Exception e) { - System.err.println("Got an exception! "); - System.err.println(e.getMessage()); - } - } - - public void testWithWhileLoop() { - try { - // create our mysql database connection - String myDriver = "driver"; - String myUrl = "driver"; - Class.forName(myDriver); - Connection conn = DriverManager.getConnection(myUrl, "toor", ""); - - // our SQL SELECT query. - // if you only need a few columns, specify them by name instead of using "*" - String query = "SELECT * FROM users"; - int i = 0; - while (i < -1) { - - // create the java statement - Statement st = conn.createStatement(); - ResultSet rs = st.executeQuery(query); // Noncompliant {{Avoid SQL request in loop}} - - // iterate through the java resultset - while (rs.next()) { - int id = rs.getInt("id"); - System.out.println(id); - } - st.close(); - } - } catch (Exception e) { - System.err.println("Got an exception! "); - System.err.println(e.getMessage()); - } - } - -} diff --git a/src/test/files/AvoidSetConstantInBatchUpdateCheck.java b/src/test/files/AvoidSetConstantInBatchUpdateCheck.java deleted file mode 100644 index d7b8013b..00000000 --- a/src/test/files/AvoidSetConstantInBatchUpdateCheck.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.util.regex.Pattern; -import java.util.stream.IntStream; -import java.util.stream.Stream; - -class AvoidSetConstantInBatchUpdateCheck { - - void literalSQLrequest() { //dirty call - - int x = 0; - Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle"); - PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?)"); - stmt.setInt(1, 101); - stmt.setString(2, "Ratan"); - stmt.setBigDecimal(3, Bigdecimal.ONE); - stmt.setBigDecimal(4, BigDecimal.valueOf(x)); - stmt.setBoolean(5, Boolean.valueOf("true")); - int i = stmt.executeUpdate(); - System.out.println(i + " records inserted"); - con.close(); - } - - void batchInsertInForLoop(int[] data) { - - Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle"); - PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?,?,?,?,?,?,?,?)"); - for (int i = 0; i < data.length; i++) { - stmt.setInt(1, data[i]); - - stmt.setBoolean(2, true); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setByte(3, (byte) 3); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setByte(4, 'v'); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setShort(5, (short) 5); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setInt(6, 6); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setLong(7, (long) 7); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setLong(7, 7l); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setFloat(8, (float) 8.); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setFloat(8, 8.f); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setDouble(9, 9.); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setDouble(9, 9.); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setString(10, "10"); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setBigDecimal(11, BigDecimal.valueOf(.77)); // Noncompliant {{Avoid setting constants in batch update}} - stmt.addBatch(); - } - int[] nr = stmt.executeBatch(); - logger.log("{} rows updated", IntStream.of(nr).sum()); - con.close(); - } - - - int[] batchInsertInForeachLoop(DummyClass[] data) { - - try (Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle")) { - PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?,?,?,?,?,?,?,?,?,?)"); - for (DummyClass o : data) { - stmt.setInt(1, o.getField1()); - stmt.setBoolean(2, Boolean.valueOf("false")); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setByte(3, o.getField3()); - stmt.setByte(4, 'v'); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setShort(5, (short) 5); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setInt(6, 6); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setLong(7, 7); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setFloat(8, (float) 8.); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setDouble(9, o.getField4()); - stmt.setString(10, o.getField2()); - stmt.setBigDecimal(11, BigDecimal.valueOf(11)); // Noncompliant {{Avoid setting constants in batch update}} - stmt.addBatch(); - } - return stmt.executeBatch(); - } - } - - - int[] batchInsertInWhileLoop(DummyClass[] data) { - - try (Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle")) { - PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?,?,?,?,?,?,?,?,?,?)"); - int i = 0; - while (i < data.length) { - DummyClass o = data[i]; - stmt.setInt(1, o.getField1()); - stmt.setBoolean(2, Boolean.TRUE); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setByte(3, o.getField3()); - stmt.setByte(4, Byte.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setShort(5, Short.MIN_VALUE); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setInt(6, Integer.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setLong(7, Long.MIN_VALUE); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setFloat(8, Float.MAX_VALUE); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setDouble(9, Double.MIN_VALUE); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setString(10, o.getField2()); - stmt.setBigDecimal(11, BigDecimal.TEN); // Noncompliant {{Avoid setting constants in batch update}} - stmt.addBatch(); - i++; - } - return stmt.executeBatch(); - } - } - - int[] batchInsertInWhileLoop(DummyClass[] data) { - if (data.length == 0) { - return new int[]{}; - } - try (Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle")) { - PreparedStatement stmt = con.prepareStatement("insert into Emp values(?,?,?,?,?,?,?,?,?,?,?,?,?)"); - int i = 0; - do { - DummyClass o = data[i]; - stmt.setInt(1, o.getField1()); - stmt.setBoolean(2, Boolean.valueOf(true)); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setByte(3, o.getField3()); - stmt.setByte(4, Byte.valueOf((byte) 3)); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setByte(4, Character.valueOf('1')); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setShort(5, Short.valueOf((short) 55)); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setInt(6, Integer.valueOf("222")); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setLong(7, Long.valueOf(0)); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setFloat(8, Float.valueOf(.33)); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setDouble(9, Double.valueOf(22)); // Noncompliant {{Avoid setting constants in batch update}} - stmt.setString(10, o.getField2()); - stmt.setBigDecimal(11, BigDecimal.valueOf(11)); // Noncompliant {{Avoid setting constants in batch update}} - stmt.addBatch(); - i++; - } while (i < data.length); - return stmt.executeBatch(); - } - } - - class DummyClass { - - public int getField1() { - return 0; - } - - public String getField2() { - return ""; - } - - public byte getField3() { - return 'A'; - } - - public double getField4() { - return .1; } - } - - -} diff --git a/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java b/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java deleted file mode 100644 index 3d386901..00000000 --- a/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.*; - -public class AvoidSpringRepositoryCallInLoopCheck { - @Autowired - private EmployeeRepository employeeRepository; - - public List smellGetAllEmployeesByIds(List ids) { - List employees = new ArrayList<>(); - for (Integer id : ids) { - Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop or stream}} - if (employee.isPresent()) { - employees.add(employee.get()); - } - } - return employees; - } - - public class Employee { - private Integer id; - private String name; - - public Employee(Integer id, String name) { - this.id = id; - this.name = name; - } - - public Integer getId() { return id; } - public String getName() { return name; } - } - - public interface EmployeeRepository extends JpaRepository { - - } - -} diff --git a/src/test/files/AvoidSpringRepositoryCallInStreamCheck.java b/src/test/files/AvoidSpringRepositoryCallInStreamCheck.java deleted file mode 100644 index 6acf592f..00000000 --- a/src/test/files/AvoidSpringRepositoryCallInStreamCheck.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.IntStream; -import java.util.stream.Stream; - -public class AvoidSpringRepositoryCallInStreamCheck { - - @Autowired - private EmployeeRepository employeeRepository; - - public void smellGetAllEmployeesByIdsForEach() { - List employees = new ArrayList<>(); - Stream stream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - stream.forEach(id -> { - Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop or stream}} - if (employee.isPresent()) { - employees.add(employee.get()); - } - }); - } - - public void smellGetAllEmployeesByIdsForEachOrdered() { - List employees = new ArrayList<>(); - Stream stream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - stream.forEachOrdered(id -> { - Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop or stream}} - if (employee.isPresent()) { - employees.add(employee.get()); - } - }); - } - - public List smellGetAllEmployeesByIdsMap() { - List employees = new ArrayList<>(); - Stream stream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - return stream.map(id -> { - Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop or stream}} - if (employee.isPresent()) { - employees.add(employee.get()); - } - }) - .collect(Collectors.toList()); - } - - public List smellGetAllEmployeesByIdsPeek() { - List employees = new ArrayList<>(); - Stream stream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - return stream.peek(id -> { - Optional employee = employeeRepository.findById(id); // Noncompliant {{Avoid Spring repository call in loop or stream}} - if (employee.isPresent()) { - employees.add(employee.get()); - } - }) - .collect(Collectors.toList()); - } - - public List smellGetAllEmployeesByIdsWithOptional(List ids) { - List employees = new ArrayList<>(); - return ids - .stream() - .map(element -> { - Employee empl = new Employee(); - employees.add(empl); - return employeeRepository.findById(element).orElse(empl);// Noncompliant {{Avoid Spring repository call in loop or stream}} - }) - .collect(Collectors.toList()); - } - - public List smellGetAllEmployeesByIds(List ids) { - Stream stream = ids.stream(); - return stream.map(element -> { - Employee empl = new Employee(); - employees.add(empl); - return employeeRepository.findById(element);// Noncompliant {{Avoid Spring repository call in loop or stream}} - }) - .collect(Collectors.toList()); - } - - public List smellGetAllEmployeesByIdsWithoutStream(List ids) { - return employeeRepository.findAllById(ids); // Compliant - } - - public List smellDeleteEmployeeById(List ids) { - Stream stream = ids.stream(); - return stream.map(element -> { - Employee empl = new Employee(); - employees.add(empl); - return employeeRepository.deleteById(element);// Noncompliant {{Avoid Spring repository call in loop or stream}} - }) - .collect(Collectors.toList()); - } - - public List smellGetAllEmployeesByIdsWithSeveralMethods(List ids) { - Stream stream = ids.stream(); - return stream.map(element -> { - Employee empl = new Employee(); - return employeeRepository.findById(element).orElse(empl).anotherMethod().anotherOne();// Noncompliant {{Avoid Spring repository call in loop or stream}} - }) - .collect(Collectors.toList()); - } - - public class Employee { - private Integer id; - private String name; - - public Employee(Integer id, String name) { - this.id = id; - this.name = name; - } - - public Integer getId() { return id; } - public String getName() { return name; } - } - - public interface EmployeeRepository extends JpaRepository { - } -} diff --git a/src/test/files/AvoidStatementForDMLQueries.java b/src/test/files/AvoidStatementForDMLQueries.java deleted file mode 100644 index a056dbbe..00000000 --- a/src/test/files/AvoidStatementForDMLQueries.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.*; -import java.sql.PreparedStatement; - - -class AvoidStatementForDMLQueries { - AvoidStatementForDMLQueries(AvoidStatementForDMLQueries mc) { - } - - public void insert() { - Statement statement = connection.createStatement(); - statement.executeUpdate("INSERT INTO persons(id, name) VALUES(2, 'Toto')"); // Noncompliant {{You must not use Statement for a DML query}} - } -} diff --git a/src/test/files/AvoidUsageOfStaticCollections.java b/src/test/files/AvoidUsageOfStaticCollections.java deleted file mode 100644 index f14de6aa..00000000 --- a/src/test/files/AvoidUsageOfStaticCollections.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.util.*; - -/** - * Not compliant - */ -public class AvoidUsageOfStaticCollections { - - public static final List LIST = new ArrayList(); // Noncompliant {{Avoid usage of static collections.}} - - public static final Set SET = new HashSet(); // Noncompliant {{Avoid usage of static collections.}} - - public static final Map MAP = new HashMap(); // Noncompliant {{Avoid usage of static collections.}} - - public AvoidUsageOfStaticCollections() { - } - -} diff --git a/src/test/files/AvoidUsageOfStaticCollectionsGoodWay.java b/src/test/files/AvoidUsageOfStaticCollectionsGoodWay.java deleted file mode 100644 index e7a60938..00000000 --- a/src/test/files/AvoidUsageOfStaticCollectionsGoodWay.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.util.*; - -/** - * Compliant - */ -public class AvoidUsageOfStaticCollectionsGoodWay { - public static volatile AvoidUsageOfStaticCollectionsGoodWay INSTANCE = new AvoidUsageOfStaticCollectionsGoodWay(); - - public final List LIST = new ArrayList(); // Compliant - public final Set SET = new HashSet(); // Compliant - public final Map MAP = new HashMap(); // Compliant - - private AvoidUsageOfStaticCollectionsGoodWay() { - } -} diff --git a/src/test/files/FreeResourcesOfAutoCloseableInterface.java b/src/test/files/FreeResourcesOfAutoCloseableInterface.java deleted file mode 100644 index 776ba3c7..00000000 --- a/src/test/files/FreeResourcesOfAutoCloseableInterface.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.io.*; - -class FreeResourcesOfAutoCloseableInterface { - FreeResourcesOfAutoCloseableInterface(FreeResourcesOfAutoCloseableInterface mc) { - - } - - public void foo1() { - String fileName = "./FreeResourcesOfAutoCloseableInterface.java"; - try (FileReader fr = new FileReader(fileName); - BufferedReader br = new BufferedReader(fr)) { // Compliant - } catch (IOException e) { - System.err.println(e.getMessage()); - } - } - - public void foo2() { - String fileName = "./FreeResourcesOfAutoCloseableInterface.java"; - try { // Noncompliant {{try-with-resources Statement needs to be implemented for any object that implements the AutoCloseable interface.}} - FileReader fr = new FileReader(fileName); - BufferedReader br = new BufferedReader(fr); - System.out.printl(br.readLine()); - } catch (IOException e) { - System.err.println(e.getMessage()); - } finally { - if (fr) { - org.close(); - } - if (br) { - br.close(); - } - } - } - - /** - * The first method adds a "try" in the stack used to follow if the code is in a try - */ - public void callingMethodWithTheTry() throws IOException { - try { // Compliant - calledMethodWithoutTry(); - } finally { - // Empty block of code - } - } - - /** - * The "try" should have been popped from the stack before entering here - */ - private void calledMethodWithoutTry() throws IOException { - FileWriter myWriter = new FileWriter("somefilepath"); - myWriter.write("something"); - myWriter.flush(); - myWriter.close(); - } -} diff --git a/src/test/files/IncrementCheck.java b/src/test/files/IncrementCheck.java deleted file mode 100644 index 86da5166..00000000 --- a/src/test/files/IncrementCheck.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -private class Foo { - public int i; //NOSONAR -} - -class IncrementCheck { - - IncrementCheck(IncrementCheck mc) { - } - - int foo1() { - int counter = 0; - return counter++; // Noncompliant {{Use ++i instead of i++}} - } - - private int j = 0; - int foo10() { - return this.j++; // Compliant because maybe the use case needs to return j AND increment it - } - - int foo11() { - int counter = 0; - return ++counter; - } - - int foo12() { - Foo f; - return f.i++; // Compliant because maybe the use case needs to return j AND increment it - } - - int foo2() { - int counter = 0; - counter++; // Noncompliant {{Use ++i instead of i++}} - return counter; - } - - int foo22() { - int counter = 0; - ++counter; - return counter; - } - - int foo3() { - int counter = 0; - counter = counter + 197845 ; - return counter; - } - - int foo4() { - int counter = 0; - counter = counter + 35 + 78 ; - return counter; - } - - void foo50() { - for (int i=0; i < 10; i++) { // Noncompliant {{Use ++i instead of i++}} - System.out.println(i); //NOSONAR - } - } - - void foo51() { - for (int i=0; i < 10; ++i) { - System.out.println(i); //NOSONAR - } - } - - void bar61(int value) { - // For test purpose - } - - int foo61() { - int i = 0; - bar61(i++); // Compliant because maybe bar61 needs the unincremented value - return i; - } - - int foo62() { - int i = 0; - bar61(2 + i++); // Compliant because maybe bar61 needs the unincremented value - return i; - } - - void foo71() { - int counter = 0; - int a = 2 + counter++; // Compliant because we probably want to increment counter - // then to add it to 2 to initialize a - } -} diff --git a/src/test/files/InitializeBufferWithAppropriateSize.java b/src/test/files/InitializeBufferWithAppropriateSize.java deleted file mode 100644 index a83c21e7..00000000 --- a/src/test/files/InitializeBufferWithAppropriateSize.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.Statement; - -class InitializeBufferWithAppropriateSize { - InitializeBufferWithAppropriateSize(InitializeBufferWithAppropriateSize mc) { - } - - public void testBufferCompliant() { - StringBuffer stringBuffer = new StringBuffer(16); - } - - public void testBufferCompliant2() { - StringBuffer stringBuffer = new StringBuffer(Integer.valueOf(16)); - } - - public void testBufferNonCompliant() { - StringBuffer stringBuffer = new StringBuffer(); // Noncompliant {{Initialize StringBuilder or StringBuffer with appropriate size}} - } - - public void testBuilderCompliant() { - StringBuilder stringBuilder = new StringBuilder(16); - } - - public void testBuilderNonCompliant() { - StringBuilder stringBuilder = new StringBuilder(); // Noncompliant {{Initialize StringBuilder or StringBuffer with appropriate size}} - } -} diff --git a/src/test/files/MakeNonReassignedVariablesConstants.java b/src/test/files/MakeNonReassignedVariablesConstants.java deleted file mode 100644 index 8e24b914..00000000 --- a/src/test/files/MakeNonReassignedVariablesConstants.java +++ /dev/null @@ -1,147 +0,0 @@ -import java.util.logging.Logger; - -public class MakeNonReassignedVariablesConstants { - - private final Logger logger = Logger.getLogger(""); // Compliant - - private Object myNonFinalAndNotReassignedObject = new Object(); // Noncompliant {{The variable is never reassigned and can be 'final'}} - private Object myNonFinalAndReassignedObject = new Object(); // Compliant - private final Object myFinalAndNotReassignedObject = new Object(); // Compliant - - private static final String CONSTANT = "toto"; // Compliant - private String varDefinedInClassNotReassigned = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}} - private String varDefinedInClassNotUsed = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}} - private String varDefinedInClassReassigned = "0"; // Compliant - private String varDefinedInConstructorReassigned = "1"; // Compliant - - // using "this" - private String varDefinedInClassNotReassignedByThis = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}} - private String varDefinedInClassReassignedByThis = "0"; // Compliant - private String varDefinedInConstructorReassignedByThis = "1"; // Compliant - - // passing through a method - private String varDefinedInClassReassignedInMethod = "0"; // Compliant - private String varDefinedInClassInFinalMethod = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}} - private String varDefinedInClassNotReassignedInMethod = "0"; // Compliant (the String was passed as a non-final parameter to the method) - private String varDefinedInClassReassignedInConstructor = "0"; // Compliant - private String varDefinedInClassInFinalConstructor = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}} - private String varDefinedInClassNotReassignedInConstructor = "0"; // Compliant (the String was passed as a non-final parameter to the constructor) - - public MakeNonReassignedVariablesConstants() { - varDefinedInConstructorReassigned = "3"; - this.varDefinedInConstructorReassignedByThis = "3"; - logger.info(varDefinedInConstructorReassigned); - logger.info(this.varDefinedInConstructorReassignedByThis); - } - - public void parameterReassigned(String reassigned) { - reassigned = "10"; - logger.info(reassigned); - } - - public void parameterNotReassigned(final String notReassigned) { - logger.info(notReassigned); - } - - public void parameterNotReassignedNotFinal(String notReassigned) { // Noncompliant {{The variable is never reassigned and can be 'final'}} - logger.info(notReassigned); - } - - void localVariableReassigned() { - String y1 = "10"; // Compliant - final String PI = "3.14159"; // Compliant - - y1 = "titi"; - - logger.info(y1); - logger.info(PI); - } - - void localVariableIncrement() { - String y2 = "10"; // Compliant - y2 += "titi"; - logger.info(y2); - } - - void localIntVariableIncrement() { - int y3 = 10; // Compliant - ++y3; - logger.info(y3+""); - } - - void localVariableNotReassigned() { - String y4 = "10"; // Noncompliant {{The variable is never reassigned and can be 'final'}} - final String PI2 = "3.14159"; // Compliant - - logger.info(y4); - logger.info(PI2); - } - - void classVariableReassigned() { - varDefinedInClassReassigned = "1"; - - logger.info(varDefinedInClassReassigned); - logger.info(varDefinedInClassNotReassigned); - logger.info(CONSTANT); - } - - void classVariableReassignedBis() { - varDefinedInClassReassigned = "2"; // method to avoid sonarqube error asking for moving class variable "varDefinedInClassReassigned" to local variable method - myNonFinalAndReassignedObject = new Object(); - - logger.info(varDefinedInClassReassigned); - logger.info(myNonFinalAndReassignedObject.toString()); - logger.info(myFinalAndNotReassignedObject.toString()); - } - - void classVariableReassignedByThis() { - this.varDefinedInClassReassignedByThis = "1"; - - logger.info(this.varDefinedInClassReassignedByThis); - logger.info(this.varDefinedInClassNotReassignedByThis); - } - - void reassignedInMethod() { - String varDefinedInMethodReassignedInMethod = "0"; // Compliant - String varDefinedInMethodInFinalMethod = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}} - String varDefinedInMethodNotReassignedInMethod = "0"; // Compliant (the String was passed as a non-final parameter to the method) - - this.parameterReassigned(varDefinedInMethodReassignedInMethod); - this.parameterReassigned(this.varDefinedInClassReassignedInMethod); - this.parameterNotReassigned(varDefinedInMethodInFinalMethod); - this.parameterNotReassigned(this.varDefinedInClassInFinalMethod); - this.parameterNotReassignedNotFinal(varDefinedInMethodNotReassignedInMethod); - this.parameterNotReassignedNotFinal(this.varDefinedInClassNotReassignedInMethod); - } - - void reassignedInConstructor(){ - String varDefinedInMethodReassignedInConstructor = "0"; // Compliant - String varDefinedInMethodInFinalConstructor = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}} - String varDefinedInMethodNotReassignedInConstructor = "0"; // Compliant (the String was passed as a non-final parameter to the constructor) - Object o = null; - o = new reassignedInConstructor(varDefinedInMethodReassignedInConstructor); - o = new reassignedInConstructor(this.varDefinedInClassReassignedInConstructor); - o = new notReassignedInConstructor(varDefinedInMethodInFinalConstructor); - o = new notReassignedInConstructor(this.varDefinedInClassInFinalConstructor); - o = new notReassignedInConstructorNotFinal(varDefinedInMethodNotReassignedInConstructor); - o = new notReassignedInConstructorNotFinal(this.varDefinedInClassNotReassignedInConstructor); - } - -} - -class reassignedInConstructor{ - reassignedInConstructor(String reassignedInConstructor) { - reassignedInConstructor = "10"; - System.out.println(reassignedInConstructor); - } -} -class notReassignedInConstructor{ - notReassignedInConstructor(final String notReassignedInConstructor) { - System.out.println(notReassignedInConstructor); - } -} -class notReassignedInConstructorNotFinal{ - notReassignedInConstructorNotFinal(String notReassignedInConstructorNotFinal) { // Noncompliant {{The variable is never reassigned and can be 'final'}} - System.out.println(notReassignedInConstructorNotFinal); - } -} \ No newline at end of file diff --git a/src/test/files/NoFunctionCallWhenDeclaringForLoop.java b/src/test/files/NoFunctionCallWhenDeclaringForLoop.java deleted file mode 100644 index 542cad39..00000000 --- a/src/test/files/NoFunctionCallWhenDeclaringForLoop.java +++ /dev/null @@ -1,153 +0,0 @@ -package org.greencodeinitiative.creedengo.java.integration.tests;/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.Collections; - - -class NoFunctionCallWhenDeclaringForLoop { - - public int getMyValue() { - return 6; - } - - public int incrementeMyValue(final int i) { - return i + 100; - } - - public void test1() { - for (int i = 0; i < 20; ++i) { - System.out.println(i); - final boolean b = getMyValue() > 6; - System.out.println(b); - } - } - - public void test2() { - final String[] cars = {"Volvo", "BMW", "Ford", "Mazda"}; - for (final String i : cars) { - System.out.println(i); - } - - } - - // compliant, the function is called only once in the initialization so it's not a performance issue - public void test3() { - for (int i = getMyValue(); i < 20; ++i) { - System.out.println(i); - final boolean b = getMyValue() > 6; - System.out.println(b); - } - } - - public void test4() { - for (int i = 0; i < getMyValue(); ++i) { // Noncompliant {{Do not call a function when declaring a for-type loop}} - System.out.println(i); - final boolean b = getMyValue() > 6; - System.out.println(b); - } - } - - public void test5() { - for (final int i = 0; i < getMyValue(); incrementeMyValue(i)) { // Noncompliant {{Do not call a function when declaring a for-type loop}} - System.out.println(i); - final boolean b = getMyValue() > 6; - System.out.println(b); - } - } - - public void test6() { - for (int i = getMyValue(); i < getMyValue(); ++i) { // Noncompliant {{Do not call a function when declaring a for-type loop}} - System.out.println(i); - final boolean b = getMyValue() > 6; - System.out.println(b); - } - } - - // compliant, iterators are allowed to be called in a for loop - public void test7() { - final List joursSemaine = Arrays.asList("Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"); - - String jour = null; - // iterator is allowed - for (final Iterator iterator = joursSemaine.iterator(); iterator.hasNext(); jour = iterator.next()) { - System.out.println(jour); - } - - // subclass of iterator is allowed - for (final ListIterator iterator = joursSemaine.listIterator(); iterator.hasNext(); jour = iterator.next()) { - System.out.println(jour); - } - - // iterator called in an indirect way is allowed - for (final OtherClassWrapper otherClass = new OtherClassWrapper(joursSemaine.iterator()); otherClass.iterator.hasNext(); jour = otherClass.iterator.next()) { - System.out.println(jour); - } - - // but using a method that returns an iterator causes an issue - for (final OtherClassWrapper otherClass = new OtherClassWrapper(joursSemaine.iterator()); otherClass.getIterator().hasNext(); jour = otherClass.getIterator().next()) { // Noncompliant {{Do not call a function when declaring a for-type loop}} - System.out.println(jour); - } - - } - - // compliant, enumeration is allowed - public void test8() { - final List joursSemaine = Arrays.asList("Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"); - - String jour = null; - for (final Enumeration enumeration = Collections.enumeration(joursSemaine); enumeration.hasMoreElements(); jour = enumeration.nextElement()) { - System.out.println(jour); - } - - // enumeration called in an indirect way is allowed - for(final OtherClassWrapper otherClass = new OtherClassWrapper(Collections.enumeration(joursSemaine)); otherClass.enumeration.hasMoreElements(); jour = otherClass.enumeration.nextElement()) { - System.out.println(jour); - } - - // but using a method that returns an enumeration causes an issue - for(final OtherClassWrapper otherClass = new OtherClassWrapper(Collections.enumeration(joursSemaine)); otherClass.getEnumeration().hasMoreElements(); jour = otherClass.getEnumeration().nextElement()) { // Noncompliant {{Do not call a function when declaring a for-type loop}} - System.out.println(jour); - } - - } - -} - -class OtherClassWrapper { - public final Iterator iterator; - public final Enumeration enumeration; - - public OtherClassWrapper(Iterator iterator){ - this.iterator = iterator; - } - public OtherClassWrapper(Enumeration enumeration){ - this.enumeration = enumeration; - } - - public Iterator getIterator(){ - return iterator; - } - - public Enumeration getEnumeration(){ - return enumeration; - } -} diff --git a/src/test/files/OptimizeReadFileExceptionCheck.java b/src/test/files/OptimizeReadFileExceptionCheck.java deleted file mode 100644 index 2bafe97a..00000000 --- a/src/test/files/OptimizeReadFileExceptionCheck.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.util.Arrays; -import java.util.List; - -class ReadFile { - ReadFile(ReadFile readFile) { - } - - public void readPreferences(String filename) { - //... - InputStream in = null; - try { - in = new FileInputStream(filename); // Noncompliant {{Optimize Read File Exceptions}} - } catch (FileNotFoundException e) { - logger.log(e); - } - //... - } -} diff --git a/src/test/files/OptimizeReadFileExceptionCheck2.java b/src/test/files/OptimizeReadFileExceptionCheck2.java deleted file mode 100644 index 4d1e7614..00000000 --- a/src/test/files/OptimizeReadFileExceptionCheck2.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.util.Arrays; -import java.util.List; - -class ReadFile { - ReadFile(ReadFile readFile) { - } - - public void readPreferences(String filename) { - //... - try (InputStream in = new FileInputStream(filename)) { // Noncompliant {{Optimize Read File Exceptions}} - logger.log("my log"); - } catch (FileNotFoundException e) { - logger.log(e); - } - //... - } -} diff --git a/src/test/files/OptimizeReadFileExceptionCheck3.java b/src/test/files/OptimizeReadFileExceptionCheck3.java deleted file mode 100644 index 7b9292f0..00000000 --- a/src/test/files/OptimizeReadFileExceptionCheck3.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.util.Arrays; -import java.util.List; - -class ReadFile { - ReadFile(ReadFile readFile) { - } - - public void readPreferences(String filename) { - //... - try (InputStream in = new FileInputStream(filename)) { // Noncompliant {{Optimize Read File Exceptions}} - logger.log("my log"); - } catch (IOException e) { - logger.log(e); - } - //... - } -} diff --git a/src/test/files/OptimizeReadFileExceptionCheck4.java b/src/test/files/OptimizeReadFileExceptionCheck4.java deleted file mode 100644 index 5096450f..00000000 --- a/src/test/files/OptimizeReadFileExceptionCheck4.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.util.Arrays; -import java.util.List; - -class ReadFile { - ReadFile(ReadFile readFile) { - } - - public void readPreferences(String filename) { - //... - try (InputStream in = new FileInputStream(filename)) { // Noncompliant {{Optimize Read File Exceptions}} - logger.log("my log"); - } catch (Exception e) { - logger.log(e); - } - //... - } -} diff --git a/src/test/files/OptimizeReadFileExceptionCheck5.java b/src/test/files/OptimizeReadFileExceptionCheck5.java deleted file mode 100644 index 8754e265..00000000 --- a/src/test/files/OptimizeReadFileExceptionCheck5.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.greencodeinitiative.creedengo.java.checks; - -import java.util.Arrays; -import java.util.List; - -class ReadFile { - ReadFile(ReadFile readFile) { - } - - public void readPreferences(String filename) { - //... - try (InputStream in = new FileInputStream(filename)) { // Noncompliant {{Optimize Read File Exceptions}} - logger.log("my log"); - } catch (Throwable e) { - logger.log(e); - } - //... - } -} diff --git a/src/test/files/UseOptionalOrElseGetVsOrElse.java b/src/test/files/UseOptionalOrElseGetVsOrElse.java deleted file mode 100644 index 20a0decc..00000000 --- a/src/test/files/UseOptionalOrElseGetVsOrElse.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * creedengo - Java language - Provides rules to reduce the environmental footprint of your Java programs - * Copyright © 2024 Green Code Initiative (https://green-code-initiative.org/) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -import java.util.Optional; - -class UseOptionalOrElseGetVsOrElse { - - private static Optional variable = Optional.empty(); - - public static final String NAME = Optional.of("creedengo").orElse(getUnpredictedMethod()); // Noncompliant {{Use optional orElseGet instead of orElse.}} - - public static final String NAME2 = Optional.of("creedengo").orElseGet(() -> getUnpredictedMethod()); // Compliant - - public static final String NAME3 = variable.orElse(getUnpredictedMethod()); // Compliant - - private static String getUnpredictedMethod() { - return "unpredicted"; - } - -} diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheckTest.java index 49deaa19..33800457 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheckTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheckTest.java @@ -28,7 +28,7 @@ class ArrayCopyCheckTest { @Test void test() { CheckVerifier.newVerifier() - .onFile("src/test/files/ArrayCopyCheck.java") + .onFile(System.getProperty("testfiles.path") + "/ArrayCopyCheck.java") .withCheck(new ArrayCopyCheck()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheckTest.java index 889721b1..d311b524 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheckTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheckTest.java @@ -25,7 +25,7 @@ class AvoidFullSQLRequestCheckTest { @Test void test() { CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidFullSQLRequestCheck.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidFullSQLRequestCheck.java") .withCheck(new AvoidFullSQLRequest()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInLoopTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInLoopTest.java index 4d4b3fd6..6a5752a9 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInLoopTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInLoopTest.java @@ -24,7 +24,7 @@ class AvoidGettingSizeCollectionInLoopTest { @Test void testBadForLoop() { CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidGettingSizeCollectionInForLoopBad.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidGettingSizeCollectionInForLoopBad.java") .withCheck(new AvoidGettingSizeCollectionInLoop()) .verifyIssues(); } @@ -32,7 +32,7 @@ void testBadForLoop() { @Test void testIgnoredForLoop() { CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidGettingSizeCollectionInForLoopIgnored.java") .withCheck(new AvoidGettingSizeCollectionInLoop()) .verifyNoIssues(); } @@ -40,7 +40,7 @@ void testIgnoredForLoop() { @Test void testGoodForLoop() { CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidGettingSizeCollectionInForLoopGood.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidGettingSizeCollectionInForLoopGood.java") .withCheck(new AvoidGettingSizeCollectionInLoop()) .verifyNoIssues(); } @@ -48,7 +48,7 @@ void testGoodForLoop() { @Test void testBadWhileFoop() { CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidGettingSizeCollectionInWhileLoopBad.java") .withCheck(new AvoidGettingSizeCollectionInLoop()) .verifyIssues(); } @@ -56,7 +56,7 @@ void testBadWhileFoop() { @Test void testIgnoredWhileFoop() { CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidGettingSizeCollectionInWhileLoopIgnored.java") .withCheck(new AvoidGettingSizeCollectionInLoop()) .verifyNoIssues(); } @@ -64,7 +64,7 @@ void testIgnoredWhileFoop() { @Test void testGoodWhileLoop() { CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidGettingSizeCollectionInWhileLoopGood.java") .withCheck(new AvoidGettingSizeCollectionInLoop()) .verifyNoIssues(); } @@ -72,7 +72,7 @@ void testGoodWhileLoop() { @Test void testIgnoredForEachLoop() { CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidGettingSizeCollectionInForEachLoopIgnored.java") .withCheck(new AvoidGettingSizeCollectionInLoop()) .verifyNoIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementTest.java index f63326e5..ee85d709 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementTest.java @@ -24,11 +24,11 @@ class AvoidMultipleIfElseStatementTest { @Test void test() { CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidMultipleIfElseStatement.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidMultipleIfElseStatement.java") .withCheck(new AvoidMultipleIfElseStatement()) .verifyIssues(); CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidMultipleIfElseStatementNoIssue.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidMultipleIfElseStatementNoIssue.java") .withCheck(new AvoidMultipleIfElseStatement()) .verifyNoIssues(); } @@ -36,15 +36,15 @@ void test() { @Test void testInterfaceMethodStatement() { CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidMultipleIfElseStatementInterface.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidMultipleIfElseStatementInterfaceNoIssue.java") .withCheck(new AvoidMultipleIfElseStatement()) .verifyNoIssues(); } @Test - void testNotBlockStatement() { + void testNoBlockStatement() { CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidMultipleIfElseStatementNotBlock.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidMultipleIfElseStatementNoBlockNoIssue.java") .withCheck(new AvoidMultipleIfElseStatement()) .verifyNoIssues(); } @@ -52,7 +52,7 @@ void testNotBlockStatement() { @Test void testCompareMethod() { CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidMultipleIfElseStatementCompareMethod.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidMultipleIfElseStatementCompareMethodNoIssue.java") .withCheck(new AvoidMultipleIfElseStatement()) .verifyNoIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticTest.java index c654160c..e1df2a68 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticTest.java @@ -25,7 +25,7 @@ class AvoidRegexPatternNotStaticTest { @Test void testHasIssues() { CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidRegexPatternNotStatic.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidRegexPatternNotStatic.java") .withCheck(new AvoidRegexPatternNotStatic()) .verifyIssues(); } @@ -34,9 +34,9 @@ void testHasIssues() { void testHasNoIssues() { CheckVerifier.newVerifier() .onFiles( - "src/test/files/AvoidRegexPatternNotStaticValid1.java", - "src/test/files/AvoidRegexPatternNotStaticValid2.java", - "src/test/files/AvoidRegexPatternNotStaticValid3.java" + System.getProperty("testfiles.path") + "/AvoidRegexPatternNotStaticValid1.java", + System.getProperty("testfiles.path") + "/AvoidRegexPatternNotStaticValid2.java", + System.getProperty("testfiles.path") + "/AvoidRegexPatternNotStaticValid3.java" ) .withCheck(new AvoidRegexPatternNotStatic()) .verifyNoIssues(); diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheckTest.java index bd64a6a7..e2804544 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheckTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheckTest.java @@ -25,7 +25,7 @@ class AvoidSQLRequestInLoopCheckTest { @Test void test() { CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidSQLRequestInLoopCheck.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidSQLRequestInLoopCheck.java") .withCheck(new AvoidSQLRequestInLoop()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchInsertTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchInsertTest.java index 9dffe6f9..07bdecd2 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchInsertTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchInsertTest.java @@ -25,7 +25,7 @@ class AvoidSetConstantInBatchInsertTest { @Test void test() { CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidSetConstantInBatchUpdateCheck.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidSetConstantInBatchUpdateCheck.java") .withCheck(new AvoidSetConstantInBatchUpdate()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java index 8041f0a7..c681e8b3 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java @@ -26,7 +26,7 @@ class AvoidSpringRepositoryCallInLoopCheckTest { @Test void test() { CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidSpringRepositoryCallInLoopCheck.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidSpringRepositoryCallInLoopCheck.java") .withCheck(new AvoidSpringRepositoryCallInLoopOrStreamCheck()) .withClassPath(FilesUtils.getClassPath("target/test-jars")) .verifyIssues(); diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java index 1be55d7e..825d36cc 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java @@ -26,7 +26,7 @@ class AvoidSpringRepositoryCallInStreamCheckTest { @Test void test() { CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidSpringRepositoryCallInStreamCheck.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidSpringRepositoryCallInStreamCheck.java") .withCheck(new AvoidSpringRepositoryCallInLoopOrStreamCheck()) .withClassPath(FilesUtils.getClassPath("target/test-jars")) .verifyIssues(); diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueriesTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueriesTest.java index 3caac84a..926e3045 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueriesTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueriesTest.java @@ -24,7 +24,7 @@ class AvoidStatementForDMLQueriesTest { @Test void test() { CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidStatementForDMLQueries.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidStatementForDMLQueries.java") .withCheck(new AvoidStatementForDMLQueries()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsTests.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsTests.java index 6512a044..ea3af849 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsTests.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsTests.java @@ -25,7 +25,7 @@ class AvoidUsageOfStaticCollectionsTests { @Test void testHasIssues() { CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidUsageOfStaticCollections.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidUsageOfStaticCollections.java") .withCheck(new AvoidUsageOfStaticCollections()) .verifyIssues(); } @@ -33,7 +33,7 @@ void testHasIssues() { @Test void testNoIssues() { CheckVerifier.newVerifier() - .onFile("src/test/files/AvoidUsageOfStaticCollectionsGoodWay.java") + .onFile(System.getProperty("testfiles.path") + "/AvoidUsageOfStaticCollectionsGoodWay.java") .withCheck(new AvoidUsageOfStaticCollections()) .verifyNoIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java index 36ebb256..5fe28519 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java @@ -25,7 +25,7 @@ class FreeResourcesOfAutoCloseableInterfaceTest { @Test void test_with_java7() { CheckVerifier.newVerifier() - .onFile("src/test/files/FreeResourcesOfAutoCloseableInterface.java") + .onFile(System.getProperty("testfiles.path") + "/FreeResourcesOfAutoCloseableInterface.java") .withCheck(new FreeResourcesOfAutoCloseableInterface()) .withJavaVersion(7) .verifyIssues(); @@ -34,7 +34,7 @@ void test_with_java7() { @Test void test_no_java_version() { CheckVerifier.newVerifier() - .onFile("src/test/files/FreeResourcesOfAutoCloseableInterface.java") + .onFile(System.getProperty("testfiles.path") + "/FreeResourcesOfAutoCloseableInterface.java") .withCheck(new FreeResourcesOfAutoCloseableInterface()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheckTest.java index d11de845..c985451b 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheckTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheckTest.java @@ -25,7 +25,7 @@ class IncrementCheckTest { @Test void test() { CheckVerifier.newVerifier() - .onFile("src/test/files/IncrementCheck.java") + .onFile(System.getProperty("testfiles.path") + "/IncrementCheck.java") .withCheck(new IncrementCheck()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSizeTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSizeTest.java index 0261b8f9..54dc10e8 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSizeTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSizeTest.java @@ -25,7 +25,7 @@ class InitializeBufferWithAppropriateSizeTest { @Test void test() { CheckVerifier.newVerifier() - .onFile("src/test/files/InitializeBufferWithAppropriateSize.java") + .onFile(System.getProperty("testfiles.path") + "/InitializeBufferWithAppropriateSize.java") .withCheck(new InitializeBufferWithAppropriateSize()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstantsTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstantsTest.java index 837a632e..2fe316fa 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstantsTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstantsTest.java @@ -25,7 +25,7 @@ class MakeNonReassignedVariablesConstantsTest { @Test void test() { CheckVerifier.newVerifier() - .onFile("src/test/files/MakeNonReassignedVariablesConstants.java") + .onFile(System.getProperty("testfiles.path") + "/MakeNonReassignedVariablesConstants.java") .withCheck(new MakeNonReassignedVariablesConstants()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java index e4dff73e..3473045a 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java @@ -24,7 +24,7 @@ class NoFunctionCallWhenDeclaringForLoopTest { @Test void test() { CheckVerifier.newVerifier() - .onFile("src/test/files/NoFunctionCallWhenDeclaringForLoop.java") + .onFile(System.getProperty("testfiles.path") + "/NoFunctionCallWhenDeclaringForLoop.java") .withCheck(new NoFunctionCallWhenDeclaringForLoop()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheckTest.java index d3f1def0..d37fe3aa 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheckTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheckTest.java @@ -25,7 +25,7 @@ class OptimizeReadFileExceptionCheckTest { @Test void test() { CheckVerifier.newVerifier() - .onFile("src/test/files/OptimizeReadFileExceptionCheck.java") + .onFile(System.getProperty("testfiles.path") + "/OptimizeReadFileExceptionCheck.java") .withCheck(new OptimizeReadFileExceptions()) .verifyIssues(); } @@ -33,7 +33,7 @@ void test() { @Test void test2() { CheckVerifier.newVerifier() - .onFile("src/test/files/OptimizeReadFileExceptionCheck2.java") + .onFile(System.getProperty("testfiles.path") + "/OptimizeReadFileExceptionCheck2.java") .withCheck(new OptimizeReadFileExceptions()) .verifyIssues(); } @@ -41,7 +41,7 @@ void test2() { @Test void test3() { CheckVerifier.newVerifier() - .onFile("src/test/files/OptimizeReadFileExceptionCheck3.java") + .onFile(System.getProperty("testfiles.path") + "/OptimizeReadFileExceptionCheck3.java") .withCheck(new OptimizeReadFileExceptions()) .verifyIssues(); } @@ -49,7 +49,7 @@ void test3() { @Test void test4() { CheckVerifier.newVerifier() - .onFile("src/test/files/OptimizeReadFileExceptionCheck4.java") + .onFile(System.getProperty("testfiles.path") + "/OptimizeReadFileExceptionCheck4.java") .withCheck(new OptimizeReadFileExceptions()) .verifyIssues(); } @@ -57,7 +57,7 @@ void test4() { @Test void test5() { CheckVerifier.newVerifier() - .onFile("src/test/files/OptimizeReadFileExceptionCheck5.java") + .onFile(System.getProperty("testfiles.path") + "/OptimizeReadFileExceptionCheck5.java") .withCheck(new OptimizeReadFileExceptions()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElseTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElseTest.java index 2edc2711..7a38f883 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElseTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElseTest.java @@ -21,10 +21,11 @@ import org.sonar.java.checks.verifier.CheckVerifier; class UseOptionalOrElseGetVsOrElseTest { + @Test void test() { CheckVerifier.newVerifier() - .onFile("src/test/files/UseOptionalOrElseGetVsOrElse.java") + .onFile(System.getProperty("testfiles.path") + "/UseOptionalOrElseGetVsOrElse.java") .withCheck(new UseOptionalOrElseGetVsOrElse()) .verifyIssues(); } From 010894a1fff22acb79d2214c0f072bd681137a40 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Sat, 2 May 2026 23:31:28 +0200 Subject: [PATCH 209/233] ISSUE 56 - refacto tests directories : add subdirectories for each rule (UT + IT) --- CHANGELOG.md | 1 + .../java/integration/tests/GCIRulesIT.java | 96 +++++++++---------- .../AvoidSpringRepositoryCallInLoopCheck.java | 0 ...voidSpringRepositoryCallInStreamCheck.java | 0 .../AvoidMultipleIfElseStatement.java | 0 ...dMultipleIfElseStatementCompareMethod.java | 0 ...leIfElseStatementCompareMethodNoIssue.java | 0 ...ltipleIfElseStatementInterfaceNoIssue.java | 0 ...MultipleIfElseStatementNoBlockNoIssue.java | 0 .../AvoidMultipleIfElseStatementNoIssue.java | 0 .../AvoidMultipleIfElseStatementNotBlock.java | 0 .../checks/{ => GCI27}/ArrayCopyCheck.java | 0 .../OptimizeReadFileExceptionCheck.java | 0 .../OptimizeReadFileExceptionCheck2.java | 0 .../OptimizeReadFileExceptionCheck3.java | 0 .../OptimizeReadFileExceptionCheck4.java | 0 .../OptimizeReadFileExceptionCheck5.java | 0 ...ingSizeCollectionInForEachLoopIgnored.java | 0 ...voidGettingSizeCollectionInForLoopBad.java | 0 ...oidGettingSizeCollectionInForLoopGood.java | 0 ...GettingSizeCollectionInForLoopIgnored.java | 0 ...idGettingSizeCollectionInWhileLoopBad.java | 0 ...dGettingSizeCollectionInWhileLoopGood.java | 0 ...ttingSizeCollectionInWhileLoopIgnored.java | 0 .../InitializeBufferWithAppropriateSize.java | 0 .../AvoidStatementForDMLQueries.java | 0 .../checks/{ => GCI67}/IncrementCheck.java | 0 .../NoFunctionCallWhenDeclaringForLoop.java | 0 .../AvoidSQLRequestInLoopCheck.java | 0 .../{ => GCI74}/AvoidFullSQLRequestCheck.java | 0 .../AvoidUsageOfStaticCollections.java | 0 .../AvoidUsageOfStaticCollectionsGoodWay.java | 0 .../AvoidRegexPatternNotStatic.java | 0 .../AvoidRegexPatternNotStaticValid1.java | 0 .../AvoidRegexPatternNotStaticValid2.java | 0 .../AvoidRegexPatternNotStaticValid3.java | 0 .../AvoidSetConstantInBatchUpdateCheck.java | 1 - ...FreeResourcesOfAutoCloseableInterface.java | 0 .../MakeNonReassignedVariablesConstants.java | 0 .../UseOptionalOrElseGetVsOrElse.java | 0 ...idSpringRepositoryCallInLoopCheckTest.java | 5 +- ...SpringRepositoryCallInStreamCheckTest.java | 5 +- .../AvoidMultipleIfElseStatementTest.java | 13 +-- .../{ => GCI27}/ArrayCopyCheckTest.java | 5 +- .../OptimizeReadFileExceptionCheckTest.java | 13 +-- .../AvoidGettingSizeCollectionInLoopTest.java | 17 ++-- ...itializeBufferWithAppropriateSizeTest.java | 5 +- .../AvoidStatementForDMLQueriesTest.java | 5 +- .../{ => GCI67}/IncrementCheckTest.java | 5 +- ...oFunctionCallWhenDeclaringForLoopTest.java | 5 +- .../AvoidSQLRequestInLoopCheckTest.java | 5 +- .../AvoidFullSQLRequestCheckTest.java | 5 +- .../AvoidUsageOfStaticCollectionsTests.java | 7 +- .../AvoidRegexPatternNotStaticTest.java | 11 ++- .../AvoidSetConstantInBatchInsertTest.java | 5 +- ...ResourcesOfAutoCloseableInterfaceTest.java | 7 +- ...keNonReassignedVariablesConstantsTest.java | 5 +- .../UseOptionalOrElseGetVsOrElseTest.java | 5 +- 58 files changed, 122 insertions(+), 104 deletions(-) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI1}/AvoidSpringRepositoryCallInLoopCheck.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI1}/AvoidSpringRepositoryCallInStreamCheck.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI2}/AvoidMultipleIfElseStatement.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI2}/AvoidMultipleIfElseStatementCompareMethod.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI2}/AvoidMultipleIfElseStatementCompareMethodNoIssue.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI2}/AvoidMultipleIfElseStatementInterfaceNoIssue.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI2}/AvoidMultipleIfElseStatementNoBlockNoIssue.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI2}/AvoidMultipleIfElseStatementNoIssue.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI2}/AvoidMultipleIfElseStatementNotBlock.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI27}/ArrayCopyCheck.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI28}/OptimizeReadFileExceptionCheck.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI28}/OptimizeReadFileExceptionCheck2.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI28}/OptimizeReadFileExceptionCheck3.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI28}/OptimizeReadFileExceptionCheck4.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI28}/OptimizeReadFileExceptionCheck5.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI3}/AvoidGettingSizeCollectionInForEachLoopIgnored.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI3}/AvoidGettingSizeCollectionInForLoopBad.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI3}/AvoidGettingSizeCollectionInForLoopGood.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI3}/AvoidGettingSizeCollectionInForLoopIgnored.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI3}/AvoidGettingSizeCollectionInWhileLoopBad.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI3}/AvoidGettingSizeCollectionInWhileLoopGood.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI3}/AvoidGettingSizeCollectionInWhileLoopIgnored.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI32}/InitializeBufferWithAppropriateSize.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI5}/AvoidStatementForDMLQueries.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI67}/IncrementCheck.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI69}/NoFunctionCallWhenDeclaringForLoop.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI72}/AvoidSQLRequestInLoopCheck.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI74}/AvoidFullSQLRequestCheck.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI76}/AvoidUsageOfStaticCollections.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI76}/AvoidUsageOfStaticCollectionsGoodWay.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI77}/AvoidRegexPatternNotStatic.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI77}/AvoidRegexPatternNotStaticValid1.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI77}/AvoidRegexPatternNotStaticValid2.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI77}/AvoidRegexPatternNotStaticValid3.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI78}/AvoidSetConstantInBatchUpdateCheck.java (99%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI79}/FreeResourcesOfAutoCloseableInterface.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI82}/MakeNonReassignedVariablesConstants.java (100%) rename src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI94}/UseOptionalOrElseGetVsOrElse.java (100%) rename src/test/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI1}/AvoidSpringRepositoryCallInLoopCheckTest.java (86%) rename src/test/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI1}/AvoidSpringRepositoryCallInStreamCheckTest.java (86%) rename src/test/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI2}/AvoidMultipleIfElseStatementTest.java (84%) rename src/test/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI27}/ArrayCopyCheckTest.java (88%) rename src/test/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI28}/OptimizeReadFileExceptionCheckTest.java (85%) rename src/test/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI3}/AvoidGettingSizeCollectionInLoopTest.java (83%) rename src/test/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI32}/InitializeBufferWithAppropriateSizeTest.java (85%) rename src/test/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI5}/AvoidStatementForDMLQueriesTest.java (86%) rename src/test/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI67}/IncrementCheckTest.java (88%) rename src/test/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI69}/NoFunctionCallWhenDeclaringForLoopTest.java (85%) rename src/test/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI72}/AvoidSQLRequestInLoopCheckTest.java (87%) rename src/test/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI74}/AvoidFullSQLRequestCheckTest.java (87%) rename src/test/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI76}/AvoidUsageOfStaticCollectionsTests.java (85%) rename src/test/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI77}/AvoidRegexPatternNotStaticTest.java (83%) rename src/test/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI78}/AvoidSetConstantInBatchInsertTest.java (86%) rename src/test/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI79}/FreeResourcesOfAutoCloseableInterfaceTest.java (85%) rename src/test/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI82}/MakeNonReassignedVariablesConstantsTest.java (85%) rename src/test/java/org/greencodeinitiative/creedengo/java/checks/{ => GCI94}/UseOptionalOrElseGetVsOrElseTest.java (86%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42e39e9f..a5c8c92c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - compatibility updates for SonarQube up to 26.2.0 - upgrade internal libraries versions - non retro-compatibility upgrades - refacto to have all the test files in the same place (for UT and IT), to avoid maintaining 2 test directories +- refacto all test files to add sub-directories for each rule, to be more clear and to be able to add more tests for each rule in the future ### Deleted diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java index 5419880a..477b8cde 100644 --- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java +++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java @@ -30,7 +30,7 @@ void testMeasuresAndIssues() { @Test void testGCI27() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI27/ArrayCopyCheck.java"; String ruleId = "creedengo-java:GCI27"; String ruleMsg = "Use System.arraycopy to copy arrays"; int[] startLines = new int[]{ @@ -56,7 +56,7 @@ void testGCI27() { @Test void testGCI74() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheck.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI74/AvoidFullSQLRequestCheck.java"; int[] startLines = new int[]{27, 31, 36, 42}; int[] endLines = new int[]{27, 31, 36, 42}; String ruleId = "creedengo-java:GCI74"; @@ -68,7 +68,7 @@ void testGCI74() { @Test void testGCI3_forEachLoopIgnored() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInForEachLoopIgnored.java"; int[] startLines = new int[]{}; int[] endLines = new int[]{}; String ruleId = "creedengo-java:GCI3"; @@ -80,7 +80,7 @@ void testGCI3_forEachLoopIgnored() { @Test void testGCI3_forLoopBad() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInForLoopBad.java"; int[] startLines = new int[]{13}; int[] endLines = new int[]{13}; String ruleId = "creedengo-java:GCI3"; @@ -92,7 +92,7 @@ void testGCI3_forLoopBad() { @Test void testGCI3_forEachLoopGood() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopGood.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInForLoopGood.java"; int[] startLines = new int[]{}; int[] endLines = new int[]{}; String ruleId = "creedengo-java:GCI3"; @@ -104,7 +104,7 @@ void testGCI3_forEachLoopGood() { @Test void testGCI3_forLoopIgnored() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInForLoopIgnored.java"; int[] startLines = new int[]{}; int[] endLines = new int[]{}; String ruleId = "creedengo-java:GCI3"; @@ -116,7 +116,7 @@ void testGCI3_forLoopIgnored() { @Test void testGCI3_whileLoopBad() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInWhileLoopBad.java"; int[] startLines = new int[]{35}; int[] endLines = new int[]{35}; String ruleId = "creedengo-java:GCI3"; @@ -128,7 +128,7 @@ void testGCI3_whileLoopBad() { @Test void testGCI3_whileLoopGood() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInWhileLoopGood.java"; int[] startLines = new int[]{}; int[] endLines = new int[]{}; String ruleId = "creedengo-java:GCI3"; @@ -140,7 +140,7 @@ void testGCI3_whileLoopGood() { @Test void testGCI3_whileLoopIgnored() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInWhileLoopIgnored.java"; int[] startLines = new int[]{}; int[] endLines = new int[]{}; String ruleId = "creedengo-java:GCI3"; @@ -152,7 +152,7 @@ void testGCI3_whileLoopIgnored() { @Test void testGCI2() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatement.java"; int[] startLines = new int[]{ 41, 60, 62, 88, 105, 127, @@ -177,7 +177,7 @@ void testGCI2() { @Test void testGCI2_compareMethodNoIssue() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatementCompareMethodNoIssue.java"; int[] startLines = new int[]{}; @@ -192,7 +192,7 @@ void testGCI2_compareMethodNoIssue() { @Test void testGCI2_interfaceNoIssue() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatementInterfaceNoIssue.java"; int[] startLines = new int[]{}; @@ -207,7 +207,7 @@ void testGCI2_interfaceNoIssue() { @Test void testGCI2_noBlockNoIssue() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatementNoBlockNoIssue.java"; int[] startLines = new int[]{}; @@ -222,7 +222,7 @@ void testGCI2_noBlockNoIssue() { @Test void testGCI2_noIssue() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoIssue.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatementNoIssue.java"; int[] startLines = new int[]{}; @@ -237,7 +237,7 @@ void testGCI2_noIssue() { @Test void testGCI77_invalid() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI77/AvoidRegexPatternNotStatic.java"; int[] startLines = new int[]{25}; int[] endLines = new int[]{25}; String ruleId = "creedengo-java:GCI77"; @@ -249,7 +249,7 @@ void testGCI77_invalid() { @Test void testGCI77_valid1() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid1.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI77/AvoidRegexPatternNotStaticValid1.java"; int[] startLines = new int[]{}; int[] endLines = new int[]{}; String ruleId = "creedengo-java:GCI77"; @@ -261,7 +261,7 @@ void testGCI77_valid1() { @Test void testGCI77_valid2() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid2.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI77/AvoidRegexPatternNotStaticValid2.java"; int[] startLines = new int[]{}; int[] endLines = new int[]{}; String ruleId = "creedengo-java:GCI77"; @@ -273,7 +273,7 @@ void testGCI77_valid2() { @Test void testGCI77_valid3() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid3.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI77/AvoidRegexPatternNotStaticValid3.java"; int[] startLines = new int[]{}; int[] endLines = new int[]{}; String ruleId = "creedengo-java:GCI77"; @@ -285,22 +285,22 @@ void testGCI77_valid3() { @Test void testGCI78() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI78/AvoidSetConstantInBatchUpdateCheck.java"; int[] startLines = new int[]{ - 53, 54, 55, 56, 57, 58, - 59, 60, 61, 62, 63, 64, - 80, 82, 83, 84, 85, 88, - 104, 106, 107, 108, 109, 110, - 111, 113, 131, 133, 134, 135, - 136, 137, 138, 140 + 52, 53, 54, 55, 56, 57, + 58, 59, 60, 61, 62, 63, + 79, 81, 82, 83, 84, 87, + 103, 105, 106, 107, 108, 109, + 110, 112, 130, 132, 133, 134, + 135, 136, 137, 139 }; int[] endLines = new int[]{ - 53, 54, 55, 56, 57, 58, - 59, 60, 61, 62, 63, 64, - 80, 82, 83, 84, 85, 88, - 104, 106, 107, 108, 109, 110, - 111, 113, 131, 133, 134, 135, - 136, 137, 138, 140 + 52, 53, 54, 55, 56, 57, + 58, 59, 60, 61, 62, 63, + 79, 81, 82, 83, 84, 87, + 103, 105, 106, 107, 108, 109, + 110, 112, 130, 132, 133, 134, + 135, 136, 137, 139 }; String ruleId = "creedengo-java:GCI78"; String ruleMsg = "Avoid setting constants in batch update"; @@ -311,7 +311,7 @@ void testGCI78() { @Test void testGCI1_loop() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheck.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI1/AvoidSpringRepositoryCallInLoopCheck.java"; int[] startLines = new int[]{32}; @@ -326,7 +326,7 @@ void testGCI1_loop() { @Test void testGCI1_stream() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheck.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI1/AvoidSpringRepositoryCallInStreamCheck.java"; int[] startLines = new int[]{ 37, 48, 59, 72, 87, 98, @@ -346,7 +346,7 @@ void testGCI1_stream() { @Test void testGCI72() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheck.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI72/AvoidSQLRequestInLoopCheck.java"; String ruleId = "creedengo-java:GCI72"; String ruleMsg = "Avoid SQL request in loop"; int[] startLines = new int[]{74, 105, 136}; @@ -357,7 +357,7 @@ void testGCI72() { @Test void testGCI5() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI5/AvoidStatementForDMLQueries.java"; String ruleId = "creedengo-java:GCI5"; String ruleMsg = "You must not use Statement for a DML query"; int[] startLines = new int[]{33}; @@ -368,7 +368,7 @@ void testGCI5() { @Test void testGCI76() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI76/AvoidUsageOfStaticCollections.java"; String ruleId = "creedengo-java:GCI76"; String ruleMsg = "Avoid usage of static collections."; int[] startLines = new int[]{27, 29, 31}; @@ -379,7 +379,7 @@ void testGCI76() { @Test void testGCI76_good() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsGoodWay.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI76/AvoidUsageOfStaticCollectionsGoodWay.java"; String ruleId = "creedengo-java:GCI76"; String ruleMsg = "Avoid usage of static collections."; int[] startLines = new int[]{}; @@ -390,7 +390,7 @@ void testGCI76_good() { @Test void testGCI79() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI79/FreeResourcesOfAutoCloseableInterface.java"; String ruleId = "creedengo-java:GCI79"; String ruleMsg = "try-with-resources Statement needs to be implemented for any object that implements the AutoCloseable interface."; int[] startLines = new int[]{40}; @@ -401,7 +401,7 @@ void testGCI79() { @Test void testGCI32() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI32/InitializeBufferWithAppropriateSize.java"; String ruleId = "creedengo-java:GCI32"; String ruleMsg = "Initialize StringBuilder or StringBuffer with appropriate size"; int[] startLines = new int[]{38, 46}; @@ -412,7 +412,7 @@ void testGCI32() { @Test void testGCI67() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI67/IncrementCheck.java"; String ruleId = "creedengo-java:GCI67"; String ruleMsg = "Use ++i instead of i++"; int[] startLines = new int[]{31, 51, 74}; @@ -423,7 +423,7 @@ void testGCI67() { @Test void testGCI82() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java"; String ruleId = "creedengo-java:GCI82"; String ruleMsg = "The variable is never reassigned and can be 'final'"; int[] startLines = new int[]{9, 14, 15, 20, 26, 29, 48, 75, 108, 121}; @@ -434,7 +434,7 @@ void testGCI82() { @Test void testGCI69() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI69/NoFunctionCallWhenDeclaringForLoop.java"; String ruleId = "creedengo-java:GCI69"; String ruleMsg = "Do not call a function when declaring a for-type loop"; int[] startLines = new int[]{65, 73, 81, 109, 130}; @@ -446,7 +446,7 @@ void testGCI69() { @Test void testGCI28() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI28/OptimizeReadFileExceptionCheck.java"; int[] startLines = new int[]{34}; @@ -461,7 +461,7 @@ void testGCI28() { @Test void testGCI28_2() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI28/OptimizeReadFileExceptionCheck2.java"; int[] startLines = new int[]{32}; @@ -476,7 +476,7 @@ void testGCI28_2() { @Test void testGCI28_3() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI28/OptimizeReadFileExceptionCheck3.java"; int[] startLines = new int[]{32}; @@ -491,7 +491,7 @@ void testGCI28_3() { @Test void testGCI28_4() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI28/OptimizeReadFileExceptionCheck4.java"; int[] startLines = new int[]{31}; @@ -506,7 +506,7 @@ void testGCI28_4() { @Test void testGCI28_5() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI28/OptimizeReadFileExceptionCheck5.java"; int[] startLines = new int[]{31}; @@ -520,7 +520,7 @@ void testGCI28_5() { @Test void testGCI94() { - String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java"; + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI94/UseOptionalOrElseGetVsOrElse.java"; String ruleId = "creedengo-java:GCI94"; String ruleMsg = "Use optional orElseGet instead of orElse."; int[] startLines = new int[]{27}; diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI1/AvoidSpringRepositoryCallInLoopCheck.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheck.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI1/AvoidSpringRepositoryCallInLoopCheck.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI1/AvoidSpringRepositoryCallInStreamCheck.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheck.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI1/AvoidSpringRepositoryCallInStreamCheck.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatement.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatement.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementCompareMethod.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatementCompareMethod.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementCompareMethod.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatementCompareMethod.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatementCompareMethodNoIssue.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatementCompareMethodNoIssue.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatementInterfaceNoIssue.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatementInterfaceNoIssue.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatementNoBlockNoIssue.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatementNoBlockNoIssue.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoIssue.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatementNoIssue.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoIssue.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatementNoIssue.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNotBlock.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatementNotBlock.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNotBlock.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatementNotBlock.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI27/ArrayCopyCheck.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheck.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI27/ArrayCopyCheck.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI28/OptimizeReadFileExceptionCheck.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI28/OptimizeReadFileExceptionCheck.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI28/OptimizeReadFileExceptionCheck2.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI28/OptimizeReadFileExceptionCheck2.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI28/OptimizeReadFileExceptionCheck3.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI28/OptimizeReadFileExceptionCheck3.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI28/OptimizeReadFileExceptionCheck4.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI28/OptimizeReadFileExceptionCheck4.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI28/OptimizeReadFileExceptionCheck5.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI28/OptimizeReadFileExceptionCheck5.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInForEachLoopIgnored.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInForEachLoopIgnored.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInForLoopBad.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInForLoopBad.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopGood.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInForLoopGood.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopGood.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInForLoopGood.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInForLoopIgnored.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInForLoopIgnored.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInWhileLoopBad.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInWhileLoopBad.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInWhileLoopGood.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInWhileLoopGood.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInWhileLoopIgnored.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInWhileLoopIgnored.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI32/InitializeBufferWithAppropriateSize.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI32/InitializeBufferWithAppropriateSize.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI5/AvoidStatementForDMLQueries.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI5/AvoidStatementForDMLQueries.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI67/IncrementCheck.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI67/IncrementCheck.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI69/NoFunctionCallWhenDeclaringForLoop.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI69/NoFunctionCallWhenDeclaringForLoop.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI72/AvoidSQLRequestInLoopCheck.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheck.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI72/AvoidSQLRequestInLoopCheck.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI74/AvoidFullSQLRequestCheck.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheck.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI74/AvoidFullSQLRequestCheck.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI76/AvoidUsageOfStaticCollections.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI76/AvoidUsageOfStaticCollections.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsGoodWay.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI76/AvoidUsageOfStaticCollectionsGoodWay.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsGoodWay.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI76/AvoidUsageOfStaticCollectionsGoodWay.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI77/AvoidRegexPatternNotStatic.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI77/AvoidRegexPatternNotStatic.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid1.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI77/AvoidRegexPatternNotStaticValid1.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid1.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI77/AvoidRegexPatternNotStaticValid1.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid2.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI77/AvoidRegexPatternNotStaticValid2.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid2.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI77/AvoidRegexPatternNotStaticValid2.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid3.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI77/AvoidRegexPatternNotStaticValid3.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticValid3.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI77/AvoidRegexPatternNotStaticValid3.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI78/AvoidSetConstantInBatchUpdateCheck.java similarity index 99% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI78/AvoidSetConstantInBatchUpdateCheck.java index 259f78a3..8e20630a 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI78/AvoidSetConstantInBatchUpdateCheck.java @@ -24,7 +24,6 @@ import java.util.stream.Stream; import java.sql.DriverManager; import java.sql.Connection; -import java.sql.PreparedStatement; class AvoidSetConstantInBatchUpdateCheck { diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI79/FreeResourcesOfAutoCloseableInterface.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI79/FreeResourcesOfAutoCloseableInterface.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI94/UseOptionalOrElseGetVsOrElse.java similarity index 100% rename from src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java rename to src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI94/UseOptionalOrElseGetVsOrElse.java diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI1/AvoidSpringRepositoryCallInLoopCheckTest.java similarity index 86% rename from src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI1/AvoidSpringRepositoryCallInLoopCheckTest.java index c681e8b3..f3db2b53 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI1/AvoidSpringRepositoryCallInLoopCheckTest.java @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.greencodeinitiative.creedengo.java.checks; +package org.greencodeinitiative.creedengo.java.checks.GCI1; +import org.greencodeinitiative.creedengo.java.checks.AvoidSpringRepositoryCallInLoopOrStreamCheck; import org.greencodeinitiative.creedengo.java.utils.FilesUtils; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -26,7 +27,7 @@ class AvoidSpringRepositoryCallInLoopCheckTest { @Test void test() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidSpringRepositoryCallInLoopCheck.java") + .onFile(System.getProperty("testfiles.path") + "/GCI1/AvoidSpringRepositoryCallInLoopCheck.java") .withCheck(new AvoidSpringRepositoryCallInLoopOrStreamCheck()) .withClassPath(FilesUtils.getClassPath("target/test-jars")) .verifyIssues(); diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI1/AvoidSpringRepositoryCallInStreamCheckTest.java similarity index 86% rename from src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI1/AvoidSpringRepositoryCallInStreamCheckTest.java index 825d36cc..222c90f8 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheckTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI1/AvoidSpringRepositoryCallInStreamCheckTest.java @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.greencodeinitiative.creedengo.java.checks; +package org.greencodeinitiative.creedengo.java.checks.GCI1; +import org.greencodeinitiative.creedengo.java.checks.AvoidSpringRepositoryCallInLoopOrStreamCheck; import org.greencodeinitiative.creedengo.java.utils.FilesUtils; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -26,7 +27,7 @@ class AvoidSpringRepositoryCallInStreamCheckTest { @Test void test() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidSpringRepositoryCallInStreamCheck.java") + .onFile(System.getProperty("testfiles.path") + "/GCI1/AvoidSpringRepositoryCallInStreamCheck.java") .withCheck(new AvoidSpringRepositoryCallInLoopOrStreamCheck()) .withClassPath(FilesUtils.getClassPath("target/test-jars")) .verifyIssues(); diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatementTest.java similarity index 84% rename from src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementTest.java rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatementTest.java index ee85d709..4eb1e99c 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI2/AvoidMultipleIfElseStatementTest.java @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.greencodeinitiative.creedengo.java.checks; +package org.greencodeinitiative.creedengo.java.checks.GCI2; +import org.greencodeinitiative.creedengo.java.checks.AvoidMultipleIfElseStatement; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -24,11 +25,11 @@ class AvoidMultipleIfElseStatementTest { @Test void test() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidMultipleIfElseStatement.java") + .onFile(System.getProperty("testfiles.path") + "/GCI2/AvoidMultipleIfElseStatement.java") .withCheck(new AvoidMultipleIfElseStatement()) .verifyIssues(); CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidMultipleIfElseStatementNoIssue.java") + .onFile(System.getProperty("testfiles.path") + "/GCI2/AvoidMultipleIfElseStatementNoIssue.java") .withCheck(new AvoidMultipleIfElseStatement()) .verifyNoIssues(); } @@ -36,7 +37,7 @@ void test() { @Test void testInterfaceMethodStatement() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidMultipleIfElseStatementInterfaceNoIssue.java") + .onFile(System.getProperty("testfiles.path") + "/GCI2/AvoidMultipleIfElseStatementInterfaceNoIssue.java") .withCheck(new AvoidMultipleIfElseStatement()) .verifyNoIssues(); } @@ -44,7 +45,7 @@ void testInterfaceMethodStatement() { @Test void testNoBlockStatement() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidMultipleIfElseStatementNoBlockNoIssue.java") + .onFile(System.getProperty("testfiles.path") + "/GCI2/AvoidMultipleIfElseStatementNoBlockNoIssue.java") .withCheck(new AvoidMultipleIfElseStatement()) .verifyNoIssues(); } @@ -52,7 +53,7 @@ void testNoBlockStatement() { @Test void testCompareMethod() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidMultipleIfElseStatementCompareMethodNoIssue.java") + .onFile(System.getProperty("testfiles.path") + "/GCI2/AvoidMultipleIfElseStatementCompareMethodNoIssue.java") .withCheck(new AvoidMultipleIfElseStatement()) .verifyNoIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI27/ArrayCopyCheckTest.java similarity index 88% rename from src/test/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheckTest.java rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI27/ArrayCopyCheckTest.java index 33800457..1ab0c890 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/ArrayCopyCheckTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI27/ArrayCopyCheckTest.java @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.greencodeinitiative.creedengo.java.checks; +package org.greencodeinitiative.creedengo.java.checks.GCI27; +import org.greencodeinitiative.creedengo.java.checks.ArrayCopyCheck; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -28,7 +29,7 @@ class ArrayCopyCheckTest { @Test void test() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/ArrayCopyCheck.java") + .onFile(System.getProperty("testfiles.path") + "/GCI27/ArrayCopyCheck.java") .withCheck(new ArrayCopyCheck()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI28/OptimizeReadFileExceptionCheckTest.java similarity index 85% rename from src/test/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheckTest.java rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI28/OptimizeReadFileExceptionCheckTest.java index d37fe3aa..4491fe3b 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheckTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI28/OptimizeReadFileExceptionCheckTest.java @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.greencodeinitiative.creedengo.java.checks; +package org.greencodeinitiative.creedengo.java.checks.GCI28; +import org.greencodeinitiative.creedengo.java.checks.OptimizeReadFileExceptions; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -25,7 +26,7 @@ class OptimizeReadFileExceptionCheckTest { @Test void test() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/OptimizeReadFileExceptionCheck.java") + .onFile(System.getProperty("testfiles.path") + "/GCI28/OptimizeReadFileExceptionCheck.java") .withCheck(new OptimizeReadFileExceptions()) .verifyIssues(); } @@ -33,7 +34,7 @@ void test() { @Test void test2() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/OptimizeReadFileExceptionCheck2.java") + .onFile(System.getProperty("testfiles.path") + "/GCI28/OptimizeReadFileExceptionCheck2.java") .withCheck(new OptimizeReadFileExceptions()) .verifyIssues(); } @@ -41,7 +42,7 @@ void test2() { @Test void test3() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/OptimizeReadFileExceptionCheck3.java") + .onFile(System.getProperty("testfiles.path") + "/GCI28/OptimizeReadFileExceptionCheck3.java") .withCheck(new OptimizeReadFileExceptions()) .verifyIssues(); } @@ -49,7 +50,7 @@ void test3() { @Test void test4() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/OptimizeReadFileExceptionCheck4.java") + .onFile(System.getProperty("testfiles.path") + "/GCI28/OptimizeReadFileExceptionCheck4.java") .withCheck(new OptimizeReadFileExceptions()) .verifyIssues(); } @@ -57,7 +58,7 @@ void test4() { @Test void test5() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/OptimizeReadFileExceptionCheck5.java") + .onFile(System.getProperty("testfiles.path") + "/GCI28/OptimizeReadFileExceptionCheck5.java") .withCheck(new OptimizeReadFileExceptions()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInLoopTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInLoopTest.java similarity index 83% rename from src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInLoopTest.java rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInLoopTest.java index 6a5752a9..adfad5ab 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInLoopTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI3/AvoidGettingSizeCollectionInLoopTest.java @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.greencodeinitiative.creedengo.java.checks; +package org.greencodeinitiative.creedengo.java.checks.GCI3; +import org.greencodeinitiative.creedengo.java.checks.AvoidGettingSizeCollectionInLoop; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -24,7 +25,7 @@ class AvoidGettingSizeCollectionInLoopTest { @Test void testBadForLoop() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidGettingSizeCollectionInForLoopBad.java") + .onFile(System.getProperty("testfiles.path") + "/GCI3/AvoidGettingSizeCollectionInForLoopBad.java") .withCheck(new AvoidGettingSizeCollectionInLoop()) .verifyIssues(); } @@ -32,7 +33,7 @@ void testBadForLoop() { @Test void testIgnoredForLoop() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidGettingSizeCollectionInForLoopIgnored.java") + .onFile(System.getProperty("testfiles.path") + "/GCI3/AvoidGettingSizeCollectionInForLoopIgnored.java") .withCheck(new AvoidGettingSizeCollectionInLoop()) .verifyNoIssues(); } @@ -40,7 +41,7 @@ void testIgnoredForLoop() { @Test void testGoodForLoop() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidGettingSizeCollectionInForLoopGood.java") + .onFile(System.getProperty("testfiles.path") + "/GCI3/AvoidGettingSizeCollectionInForLoopGood.java") .withCheck(new AvoidGettingSizeCollectionInLoop()) .verifyNoIssues(); } @@ -48,7 +49,7 @@ void testGoodForLoop() { @Test void testBadWhileFoop() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidGettingSizeCollectionInWhileLoopBad.java") + .onFile(System.getProperty("testfiles.path") + "/GCI3/AvoidGettingSizeCollectionInWhileLoopBad.java") .withCheck(new AvoidGettingSizeCollectionInLoop()) .verifyIssues(); } @@ -56,7 +57,7 @@ void testBadWhileFoop() { @Test void testIgnoredWhileFoop() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidGettingSizeCollectionInWhileLoopIgnored.java") + .onFile(System.getProperty("testfiles.path") + "/GCI3/AvoidGettingSizeCollectionInWhileLoopIgnored.java") .withCheck(new AvoidGettingSizeCollectionInLoop()) .verifyNoIssues(); } @@ -64,7 +65,7 @@ void testIgnoredWhileFoop() { @Test void testGoodWhileLoop() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidGettingSizeCollectionInWhileLoopGood.java") + .onFile(System.getProperty("testfiles.path") + "/GCI3/AvoidGettingSizeCollectionInWhileLoopGood.java") .withCheck(new AvoidGettingSizeCollectionInLoop()) .verifyNoIssues(); } @@ -72,7 +73,7 @@ void testGoodWhileLoop() { @Test void testIgnoredForEachLoop() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidGettingSizeCollectionInForEachLoopIgnored.java") + .onFile(System.getProperty("testfiles.path") + "/GCI3/AvoidGettingSizeCollectionInForEachLoopIgnored.java") .withCheck(new AvoidGettingSizeCollectionInLoop()) .verifyNoIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSizeTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI32/InitializeBufferWithAppropriateSizeTest.java similarity index 85% rename from src/test/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSizeTest.java rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI32/InitializeBufferWithAppropriateSizeTest.java index 54dc10e8..9c92dae3 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSizeTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI32/InitializeBufferWithAppropriateSizeTest.java @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.greencodeinitiative.creedengo.java.checks; +package org.greencodeinitiative.creedengo.java.checks.GCI32; +import org.greencodeinitiative.creedengo.java.checks.InitializeBufferWithAppropriateSize; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -25,7 +26,7 @@ class InitializeBufferWithAppropriateSizeTest { @Test void test() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/InitializeBufferWithAppropriateSize.java") + .onFile(System.getProperty("testfiles.path") + "/GCI32/InitializeBufferWithAppropriateSize.java") .withCheck(new InitializeBufferWithAppropriateSize()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueriesTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI5/AvoidStatementForDMLQueriesTest.java similarity index 86% rename from src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueriesTest.java rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI5/AvoidStatementForDMLQueriesTest.java index 926e3045..e593914c 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueriesTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI5/AvoidStatementForDMLQueriesTest.java @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.greencodeinitiative.creedengo.java.checks; +package org.greencodeinitiative.creedengo.java.checks.GCI5; +import org.greencodeinitiative.creedengo.java.checks.AvoidStatementForDMLQueries; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -24,7 +25,7 @@ class AvoidStatementForDMLQueriesTest { @Test void test() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidStatementForDMLQueries.java") + .onFile(System.getProperty("testfiles.path") + "/GCI5/AvoidStatementForDMLQueries.java") .withCheck(new AvoidStatementForDMLQueries()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI67/IncrementCheckTest.java similarity index 88% rename from src/test/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheckTest.java rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI67/IncrementCheckTest.java index c985451b..1a5171f8 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheckTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI67/IncrementCheckTest.java @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.greencodeinitiative.creedengo.java.checks; +package org.greencodeinitiative.creedengo.java.checks.GCI67; +import org.greencodeinitiative.creedengo.java.checks.IncrementCheck; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -25,7 +26,7 @@ class IncrementCheckTest { @Test void test() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/IncrementCheck.java") + .onFile(System.getProperty("testfiles.path") + "/GCI67/IncrementCheck.java") .withCheck(new IncrementCheck()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI69/NoFunctionCallWhenDeclaringForLoopTest.java similarity index 85% rename from src/test/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI69/NoFunctionCallWhenDeclaringForLoopTest.java index 3473045a..d9d83fdf 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI69/NoFunctionCallWhenDeclaringForLoopTest.java @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.greencodeinitiative.creedengo.java.checks; +package org.greencodeinitiative.creedengo.java.checks.GCI69; +import org.greencodeinitiative.creedengo.java.checks.NoFunctionCallWhenDeclaringForLoop; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -24,7 +25,7 @@ class NoFunctionCallWhenDeclaringForLoopTest { @Test void test() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/NoFunctionCallWhenDeclaringForLoop.java") + .onFile(System.getProperty("testfiles.path") + "/GCI69/NoFunctionCallWhenDeclaringForLoop.java") .withCheck(new NoFunctionCallWhenDeclaringForLoop()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI72/AvoidSQLRequestInLoopCheckTest.java similarity index 87% rename from src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheckTest.java rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI72/AvoidSQLRequestInLoopCheckTest.java index e2804544..7e99d797 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheckTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI72/AvoidSQLRequestInLoopCheckTest.java @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.greencodeinitiative.creedengo.java.checks; +package org.greencodeinitiative.creedengo.java.checks.GCI72; +import org.greencodeinitiative.creedengo.java.checks.AvoidSQLRequestInLoop; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -25,7 +26,7 @@ class AvoidSQLRequestInLoopCheckTest { @Test void test() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidSQLRequestInLoopCheck.java") + .onFile(System.getProperty("testfiles.path") + "/GCI72/AvoidSQLRequestInLoopCheck.java") .withCheck(new AvoidSQLRequestInLoop()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheckTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI74/AvoidFullSQLRequestCheckTest.java similarity index 87% rename from src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheckTest.java rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI74/AvoidFullSQLRequestCheckTest.java index d311b524..28f27390 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheckTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI74/AvoidFullSQLRequestCheckTest.java @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.greencodeinitiative.creedengo.java.checks; +package org.greencodeinitiative.creedengo.java.checks.GCI74; +import org.greencodeinitiative.creedengo.java.checks.AvoidFullSQLRequest; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -25,7 +26,7 @@ class AvoidFullSQLRequestCheckTest { @Test void test() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidFullSQLRequestCheck.java") + .onFile(System.getProperty("testfiles.path") + "/GCI74/AvoidFullSQLRequestCheck.java") .withCheck(new AvoidFullSQLRequest()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsTests.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI76/AvoidUsageOfStaticCollectionsTests.java similarity index 85% rename from src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsTests.java rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI76/AvoidUsageOfStaticCollectionsTests.java index ea3af849..b777f820 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollectionsTests.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI76/AvoidUsageOfStaticCollectionsTests.java @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.greencodeinitiative.creedengo.java.checks; +package org.greencodeinitiative.creedengo.java.checks.GCI76; +import org.greencodeinitiative.creedengo.java.checks.AvoidUsageOfStaticCollections; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -25,7 +26,7 @@ class AvoidUsageOfStaticCollectionsTests { @Test void testHasIssues() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidUsageOfStaticCollections.java") + .onFile(System.getProperty("testfiles.path") + "/GCI76/AvoidUsageOfStaticCollections.java") .withCheck(new AvoidUsageOfStaticCollections()) .verifyIssues(); } @@ -33,7 +34,7 @@ void testHasIssues() { @Test void testNoIssues() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidUsageOfStaticCollectionsGoodWay.java") + .onFile(System.getProperty("testfiles.path") + "/GCI76/AvoidUsageOfStaticCollectionsGoodWay.java") .withCheck(new AvoidUsageOfStaticCollections()) .verifyNoIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI77/AvoidRegexPatternNotStaticTest.java similarity index 83% rename from src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticTest.java rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI77/AvoidRegexPatternNotStaticTest.java index e1df2a68..470658bc 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStaticTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI77/AvoidRegexPatternNotStaticTest.java @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.greencodeinitiative.creedengo.java.checks; +package org.greencodeinitiative.creedengo.java.checks.GCI77; +import org.greencodeinitiative.creedengo.java.checks.AvoidRegexPatternNotStatic; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -25,7 +26,7 @@ class AvoidRegexPatternNotStaticTest { @Test void testHasIssues() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidRegexPatternNotStatic.java") + .onFile(System.getProperty("testfiles.path") + "/GCI77/AvoidRegexPatternNotStatic.java") .withCheck(new AvoidRegexPatternNotStatic()) .verifyIssues(); } @@ -34,9 +35,9 @@ void testHasIssues() { void testHasNoIssues() { CheckVerifier.newVerifier() .onFiles( - System.getProperty("testfiles.path") + "/AvoidRegexPatternNotStaticValid1.java", - System.getProperty("testfiles.path") + "/AvoidRegexPatternNotStaticValid2.java", - System.getProperty("testfiles.path") + "/AvoidRegexPatternNotStaticValid3.java" + System.getProperty("testfiles.path") + "/GCI77/AvoidRegexPatternNotStaticValid1.java", + System.getProperty("testfiles.path") + "/GCI77/AvoidRegexPatternNotStaticValid2.java", + System.getProperty("testfiles.path") + "/GCI77/AvoidRegexPatternNotStaticValid3.java" ) .withCheck(new AvoidRegexPatternNotStatic()) .verifyNoIssues(); diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchInsertTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI78/AvoidSetConstantInBatchInsertTest.java similarity index 86% rename from src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchInsertTest.java rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI78/AvoidSetConstantInBatchInsertTest.java index 07bdecd2..8c6464a9 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchInsertTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI78/AvoidSetConstantInBatchInsertTest.java @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.greencodeinitiative.creedengo.java.checks; +package org.greencodeinitiative.creedengo.java.checks.GCI78; +import org.greencodeinitiative.creedengo.java.checks.AvoidSetConstantInBatchUpdate; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -25,7 +26,7 @@ class AvoidSetConstantInBatchInsertTest { @Test void test() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/AvoidSetConstantInBatchUpdateCheck.java") + .onFile(System.getProperty("testfiles.path") + "/GCI78/AvoidSetConstantInBatchUpdateCheck.java") .withCheck(new AvoidSetConstantInBatchUpdate()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI79/FreeResourcesOfAutoCloseableInterfaceTest.java similarity index 85% rename from src/test/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI79/FreeResourcesOfAutoCloseableInterfaceTest.java index 5fe28519..d0836297 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI79/FreeResourcesOfAutoCloseableInterfaceTest.java @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.greencodeinitiative.creedengo.java.checks; +package org.greencodeinitiative.creedengo.java.checks.GCI79; +import org.greencodeinitiative.creedengo.java.checks.FreeResourcesOfAutoCloseableInterface; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -25,7 +26,7 @@ class FreeResourcesOfAutoCloseableInterfaceTest { @Test void test_with_java7() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/FreeResourcesOfAutoCloseableInterface.java") + .onFile(System.getProperty("testfiles.path") + "/GCI79/FreeResourcesOfAutoCloseableInterface.java") .withCheck(new FreeResourcesOfAutoCloseableInterface()) .withJavaVersion(7) .verifyIssues(); @@ -34,7 +35,7 @@ void test_with_java7() { @Test void test_no_java_version() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/FreeResourcesOfAutoCloseableInterface.java") + .onFile(System.getProperty("testfiles.path") + "/GCI79/FreeResourcesOfAutoCloseableInterface.java") .withCheck(new FreeResourcesOfAutoCloseableInterface()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstantsTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsTest.java similarity index 85% rename from src/test/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstantsTest.java rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsTest.java index 2fe316fa..dfd09887 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstantsTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsTest.java @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.greencodeinitiative.creedengo.java.checks; +package org.greencodeinitiative.creedengo.java.checks.GCI82; +import org.greencodeinitiative.creedengo.java.checks.MakeNonReassignedVariablesConstants; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -25,7 +26,7 @@ class MakeNonReassignedVariablesConstantsTest { @Test void test() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/MakeNonReassignedVariablesConstants.java") + .onFile(System.getProperty("testfiles.path") + "/GCI82/MakeNonReassignedVariablesConstants.java") .withCheck(new MakeNonReassignedVariablesConstants()) .verifyIssues(); } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElseTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI94/UseOptionalOrElseGetVsOrElseTest.java similarity index 86% rename from src/test/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElseTest.java rename to src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI94/UseOptionalOrElseGetVsOrElseTest.java index 7a38f883..5818615e 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElseTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI94/UseOptionalOrElseGetVsOrElseTest.java @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.greencodeinitiative.creedengo.java.checks; +package org.greencodeinitiative.creedengo.java.checks.GCI94; +import org.greencodeinitiative.creedengo.java.checks.UseOptionalOrElseGetVsOrElse; import org.junit.jupiter.api.Test; import org.sonar.java.checks.verifier.CheckVerifier; @@ -25,7 +26,7 @@ class UseOptionalOrElseGetVsOrElseTest { @Test void test() { CheckVerifier.newVerifier() - .onFile(System.getProperty("testfiles.path") + "/UseOptionalOrElseGetVsOrElse.java") + .onFile(System.getProperty("testfiles.path") + "/GCI94/UseOptionalOrElseGetVsOrElse.java") .withCheck(new UseOptionalOrElseGetVsOrElse()) .verifyIssues(); } From 7ec566de90e3006995b4a00fa07886f3b8cfeade Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Wed, 20 May 2026 00:55:47 +0200 Subject: [PATCH 210/233] fix IT system run + IT GCI82 --- CHANGELOG.md | 1 + pom.xml | 2 +- .../creedengo/java/integration/tests/GCIRulesIT.java | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5c8c92c..a429d0a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - upgrade internal libraries versions - non retro-compatibility upgrades - refacto to have all the test files in the same place (for UT and IT), to avoid maintaining 2 test directories - refacto all test files to add sub-directories for each rule, to be more clear and to be able to add more tests for each rule in the future +- fix integration test system run + fix TI GCI82 ### Deleted diff --git a/pom.xml b/pom.xml index 68a2a9ae..d1bbdaaf 100644 --- a/pom.xml +++ b/pom.xml @@ -165,7 +165,7 @@ org.green-code-initiative creedengo-integration-test - 0.2.4 + 0.4.0 test diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java index 477b8cde..ec6730ca 100644 --- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java +++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java @@ -426,8 +426,8 @@ void testGCI82() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java"; String ruleId = "creedengo-java:GCI82"; String ruleMsg = "The variable is never reassigned and can be 'final'"; - int[] startLines = new int[]{9, 14, 15, 20, 26, 29, 48, 75, 108, 121}; - int[] endLines = new int[]{9, 14, 15, 20, 26, 29, 48, 75, 108, 121}; + int[] startLines = new int[]{9, 14, 15, 20, 26, 29, 48, 75, 108, 121, 146}; + int[] endLines = new int[]{9, 14, 15, 20, 26, 29, 48, 75, 108, 121, 146}; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); } From c2bd721282282a9b5037b4b9d78ddbb432ac407a Mon Sep 17 00:00:00 2001 From: "Bo.sy" <37907425+rroot47@users.noreply.github.com> Date: Wed, 20 May 2026 14:10:53 +0200 Subject: [PATCH 211/233] GCI94 systematically suggests orElseGet, but could be further optimized (#190) --- CHANGELOG.md | 1 + .../java/integration/tests/GCIRulesIT.java | 4 +- .../GCI94/UseOptionalOrElseGetVsOrElse.java | 27 ++++++++++- .../checks/UseOptionalOrElseGetVsOrElse.java | 45 +++++++++++++++---- 4 files changed, 66 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a429d0a6..d83178ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- [#119](https://github.com/green-code-initiative/creedengo-java/issues/119) GCI94 - reduce false positives: rule no longer flags `orElse()` when argument is a constant, literal, static field or null; detection extended to Optional variables (semantic type check) and to computed arguments nested inside concatenation, ternary or object instantiation - [#69](https://github.com/green-code-initiative/creedengo-java/issues/69) correction of NullPointer in GCI79 rule + technical refactoring of GCI79 - update integration tests system to use the new component "creedengo-integration-test" - compatibility updates for SonarQube up to 26.2.0 diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java index ec6730ca..86c5f5fc 100644 --- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java +++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java @@ -523,8 +523,8 @@ void testGCI94() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI94/UseOptionalOrElseGetVsOrElse.java"; String ruleId = "creedengo-java:GCI94"; String ruleMsg = "Use optional orElseGet instead of orElse."; - int[] startLines = new int[]{27}; - int[] endLines = new int[]{27}; + int[] startLines = new int[]{29, 31, 33, 35, 55, 56, 57, 58}; + int[] endLines = new int[]{29, 31, 33, 35, 55, 56, 57, 58}; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_1MIN); } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI94/UseOptionalOrElseGetVsOrElse.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI94/UseOptionalOrElseGetVsOrElse.java index 6a93a0be..8d918a43 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI94/UseOptionalOrElseGetVsOrElse.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI94/UseOptionalOrElseGetVsOrElse.java @@ -22,16 +22,41 @@ class UseOptionalOrElseGetVsOrElse { + private static final String DEFAULT_NAME = "default"; + private static Optional variable = Optional.empty(); public static final String NAME = Optional.of("creedengo").orElse(getUnpredictedMethod()); // Noncompliant {{Use optional orElseGet instead of orElse.}} + public static final String NAME_CONCAT = Optional.of("creedengo").orElse("prefix_" + getUnpredictedMethod()); // Noncompliant {{Use optional orElseGet instead of orElse.}} + + public static final String NAME_NEW = Optional.of("creedengo").orElse(new StringBuilder().toString()); // Noncompliant {{Use optional orElseGet instead of orElse.}} + + public static final String NAME7 = variable.orElse(getUnpredictedMethod()); // Noncompliant {{Use optional orElseGet instead of orElse.}} + public static final String NAME2 = Optional.of("creedengo").orElseGet(() -> getUnpredictedMethod()); // Compliant - public static final String NAME3 = variable.orElse(getUnpredictedMethod()); // Compliant + public static final String NAME3 = Optional.of("creedengo").orElseGet(UseOptionalOrElseGetVsOrElse::getUnpredictedMethod); // Compliant + + public static final String NAME4 = Optional.of("creedengo").orElse(DEFAULT_NAME); // Compliant - constant + + public static final String NAME5 = Optional.of("creedengo").orElse("fallback"); // Compliant - string literal + + public static final String NAME6 = Optional.of("creedengo").orElse(null); // Compliant - null literal + + public static final Boolean FLAG = Optional.of(Boolean.TRUE).orElse(Boolean.FALSE); // Compliant - static field reference private static String getUnpredictedMethod() { return "unpredicted"; } + static void testVariableCases() { + Optional opt = Optional.of("creedengo"); + String r1 = opt.orElse(getUnpredictedMethod()); // Noncompliant {{Use optional orElseGet instead of orElse.}} + String r2 = opt.orElse("a" + getUnpredictedMethod()); // Noncompliant {{Use optional orElseGet instead of orElse.}} + String r3 = opt.orElse(Boolean.TRUE ? getUnpredictedMethod() : DEFAULT_NAME); // Noncompliant {{Use optional orElseGet instead of orElse.}} + String r4 = opt.orElse(new String("default")); // Noncompliant {{Use optional orElseGet instead of orElse.}} + String r5 = opt.orElse(DEFAULT_NAME); // Compliant - constant + } + } diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java index ec971a6c..28f1ea50 100644 --- a/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java +++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java @@ -22,11 +22,12 @@ import org.sonar.plugins.java.api.tree.BaseTreeVisitor; import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree; import org.sonar.plugins.java.api.tree.MethodInvocationTree; +import org.sonar.plugins.java.api.tree.NewArrayTree; +import org.sonar.plugins.java.api.tree.NewClassTree; import org.sonar.plugins.java.api.tree.Tree; import javax.annotation.Nonnull; import java.util.Collections; import java.util.List; -import java.util.Objects; @Rule(key = "GCI94") public class UseOptionalOrElseGetVsOrElse extends IssuableSubscriptionVisitor { @@ -47,13 +48,41 @@ public void visitNode(@Nonnull Tree tree) { private class UseOptionalOrElseGetVsOrElseVisitor extends BaseTreeVisitor { @Override public void visitMethodInvocation(MethodInvocationTree tree) { - if (tree.methodSelect().is(Tree.Kind.MEMBER_SELECT) && - Objects.requireNonNull(tree.methodSelect().firstToken()).text().equals("Optional")) { - MemberSelectExpressionTree memberSelect = (MemberSelectExpressionTree) tree.methodSelect(); - if (memberSelect.identifier().name().equals("orElse")) { - reportIssue(memberSelect, MESSAGE_RULE); - } + if (!tree.methodSelect().is(Tree.Kind.MEMBER_SELECT)) { + return; } + MemberSelectExpressionTree memberSelect = (MemberSelectExpressionTree) tree.methodSelect(); + if (memberSelect.identifier().name().equals("orElse") && + memberSelect.expression().symbolType().is("java.util.Optional") && + !tree.arguments().isEmpty() && + containsComputation(tree.arguments().get(0))) { + reportIssue(memberSelect, MESSAGE_RULE); + } + } + } + + private static boolean containsComputation(Tree argument) { + ComputationDetector detector = new ComputationDetector(); + argument.accept(detector); + return detector.found; + } + + private static class ComputationDetector extends BaseTreeVisitor { + boolean found = false; + + @Override + public void visitMethodInvocation(@Nonnull MethodInvocationTree tree) { + found = true; + } + + @Override + public void visitNewClass(@Nonnull NewClassTree tree) { + found = true; + } + + @Override + public void visitNewArray(@Nonnull NewArrayTree tree) { + found = true; } } -} +} \ No newline at end of file From 4488bbc42814f5bf588fccb027974b98088fd368 Mon Sep 17 00:00:00 2001 From: Maxime Malgorn <9255967+utarwyn@users.noreply.github.com> Date: Wed, 20 May 2026 14:29:15 +0200 Subject: [PATCH 212/233] Bump GitHub workflow actions --- .github/workflows/build.yml | 6 +++--- .github/workflows/build_container.yml | 12 ++++++------ .github/workflows/stale_tag.yml | 2 +- .github/workflows/tag_release.yml | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f0aa71d3..6885ed65 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,12 +19,12 @@ jobs: pull-requests: read # allows SonarCloud to decorate PRs with analysis results steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - name: Set up JDK 17 - uses: actions/setup-java@v4 + uses: actions/setup-java@v5 with: distribution: "temurin" java-version: 17 @@ -36,7 +36,7 @@ jobs: echo "org.sonarsource.scanner.maven" > ~/.m2/settings.xml - name: Cache SonarQube packages - uses: actions/cache@v4 + uses: actions/cache@v5 with: path: ~/.sonar/cache key: ${{ runner.os }}-sonar diff --git a/.github/workflows/build_container.yml b/.github/workflows/build_container.yml index 08fb38b2..2ba91fcf 100644 --- a/.github/workflows/build_container.yml +++ b/.github/workflows/build_container.yml @@ -34,26 +34,26 @@ jobs: steps: - name: Login to GitHub Container Registry - uses: docker/login-action@v2 + uses: docker/login-action@v4 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v6 with: fetch-depth: 0 - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v4 - name: Docker metadata id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} images: ${{ env.IMAGES }} @@ -70,7 +70,7 @@ jobs: - name: Publish image id: push - uses: docker/build-push-action@v4 + uses: docker/build-push-action@v7 with: push: true tags: ${{ steps.meta.outputs.tags }} diff --git a/.github/workflows/stale_tag.yml b/.github/workflows/stale_tag.yml index dd3c35e1..75db955f 100644 --- a/.github/workflows/stale_tag.yml +++ b/.github/workflows/stale_tag.yml @@ -11,7 +11,7 @@ jobs: contents: read pull-requests: write steps: - - uses: actions/stale@v8.0.0 + - uses: actions/stale@v10 with: repo-token: ${{ secrets.GITHUB_TOKEN }} days-before-issue-stale: -1 # We don't want to address issues diff --git a/.github/workflows/tag_release.yml b/.github/workflows/tag_release.yml index 3cbf005c..775d20c1 100644 --- a/.github/workflows/tag_release.yml +++ b/.github/workflows/tag_release.yml @@ -19,7 +19,7 @@ jobs: contents: read steps: - name: Check user permissions - uses: 74th/workflow-permission-action@1.0.0 + uses: 74th/workflow-permission-action@61b695d54d72c612459668d29fca41281a0f49d4 # v1.0.0 with: users: dedece35,glalloue,jhertout,olegoaer,zippy1978,utarwyn build: @@ -30,7 +30,7 @@ jobs: contents: write steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v6 with: fetch-depth: 0 @@ -50,13 +50,13 @@ jobs: echo "release_tag=$RELEASE_TAG" >> $GITHUB_ENV - name: Checkout tag "${{ env.release_tag }}" - uses: actions/checkout@v3 + uses: actions/checkout@v6 with: ref: ${{ env.release_tag }} - name: Extract release notes id: extract-release-notes - uses: ffurrer2/extract-release-notes@v1 + uses: ffurrer2/extract-release-notes@273da39a24fb7db106a35526c8162815faffd31d # v3.1.0 - name: Build project env: @@ -77,7 +77,7 @@ jobs: echo "jar_path=$JAR_FILE" >> $GITHUB_ENV - name: Create release and upload asset - uses: softprops/action-gh-release@v2 + uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3.0.0 with: tag_name: ${{ env.release_tag }} name: Release ${{ env.release_tag }} From 6e6589203af0c3a4f8191929297511d3ba6443b4 Mon Sep 17 00:00:00 2001 From: Maxime Malgorn <9255967+utarwyn@users.noreply.github.com> Date: Wed, 20 May 2026 14:34:39 +0200 Subject: [PATCH 213/233] Fix potential script injection in release action --- .github/workflows/tag_release.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tag_release.yml b/.github/workflows/tag_release.yml index 775d20c1..572af966 100644 --- a/.github/workflows/tag_release.yml +++ b/.github/workflows/tag_release.yml @@ -36,9 +36,11 @@ jobs: - name: Resolve release tag id: resolve_tag + env: + INPUT_TAG: ${{ inputs.tag }} run: | - if [ -n "${{ inputs.tag }}" ]; then - RELEASE_TAG="${{ inputs.tag }}" + if [ -n "$INPUT_TAG" ]; then + RELEASE_TAG="$INPUT_TAG" else RELEASE_TAG=$(git tag --sort=-version:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1) fi From 6f3c8280bc808a43c7baecb50d8c92f4974acb6b Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 16 Jun 2026 22:32:38 +0200 Subject: [PATCH 214/233] update lib / compat 26.6 --- CHANGELOG.md | 2 +- README.md | 2 +- pom.xml | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d83178ed..fd3e6a31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#119](https://github.com/green-code-initiative/creedengo-java/issues/119) GCI94 - reduce false positives: rule no longer flags `orElse()` when argument is a constant, literal, static field or null; detection extended to Optional variables (semantic type check) and to computed arguments nested inside concatenation, ternary or object instantiation - [#69](https://github.com/green-code-initiative/creedengo-java/issues/69) correction of NullPointer in GCI79 rule + technical refactoring of GCI79 - update integration tests system to use the new component "creedengo-integration-test" -- compatibility updates for SonarQube up to 26.2.0 +- compatibility updates for SonarQube up to 26.6.0 - upgrade internal libraries versions - non retro-compatibility upgrades - refacto to have all the test files in the same place (for UT and IT), to avoid maintaining 2 test directories - refacto all test files to add sub-directories for each rule, to be more clear and to be able to add more tests for each rule in the future diff --git a/README.md b/README.md index e26322b9..5519515a 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ Ready to use binaries are available [from GitHub](https://github.com/green-code- | 2.0.+ / 2.1.+ | 9.9.0 LTS to 25.12.0 | 17 | | 2.2.+ | 25.1.+ | 17 | | 2.2.+ | 25.2.+ LTS to 25.12.+ | 17 / 21 | -| 2.2.+ | 26.1.+ LTS to 26.2.+ | 21 | +| 2.2.+ | 26.1.+ LTS to 26.6.+ | 21 | > Compatibility table of versions lower than 1.4.+ are available from the > main [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-plugins-version-compatibility). diff --git a/pom.xml b/pom.xml index d1bbdaaf..31d83a10 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,7 @@ 1.25.1.3002 - 2.7.1 + 3.1.0 https://repo1.maven.org/maven2 @@ -83,7 +83,7 @@ - + @@ -92,7 +92,7 @@ - + @@ -104,7 +104,8 @@ - + + ${sonarjava.version} From 4468a22a6310c81d7507cff8c616b68d321bea4d Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 16 Jun 2026 22:43:41 +0200 Subject: [PATCH 215/233] prepare 2.2.0 version : update CHANGELOG.md --- CHANGELOG.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd3e6a31..9994185e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +### Deleted + +## [2.2.0] - 2026-06-16 + +### Changed + - [#119](https://github.com/green-code-initiative/creedengo-java/issues/119) GCI94 - reduce false positives: rule no longer flags `orElse()` when argument is a constant, literal, static field or null; detection extended to Optional variables (semantic type check) and to computed arguments nested inside concatenation, ternary or object instantiation - [#69](https://github.com/green-code-initiative/creedengo-java/issues/69) correction of NullPointer in GCI79 rule + technical refactoring of GCI79 - update integration tests system to use the new component "creedengo-integration-test" @@ -20,8 +26,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - refacto all test files to add sub-directories for each rule, to be more clear and to be able to add more tests for each rule in the future - fix integration test system run + fix TI GCI82 -### Deleted - ## [2.1.2] - 2026-01-11 ### Changed @@ -118,7 +122,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Update ecocode-rules-specifications to 1.4.6 -[unreleased](https://github.com/green-code-initiative/creedengo-java/compare/2.1.2...HEAD) +[unreleased](https://github.com/green-code-initiative/creedengo-java/compare/2.2.0...HEAD) +[2.2.0](https://github.com/green-code-initiative/creedengo-java/compare/2.1.2...2.2.0) [2.1.2](https://github.com/green-code-initiative/creedengo-java/compare/2.1.1...2.1.2) [2.1.1](https://github.com/green-code-initiative/creedengo-java/compare/2.1.0...2.1.1) [2.1.0](https://github.com/green-code-initiative/creedengo-java/compare/2.0.0...2.1.0) From c2c00595c4f5a2077c36db51e53da4fcf1725251 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 16 Jun 2026 23:15:00 +0200 Subject: [PATCH 216/233] upgrade to dynamic version --- pom.xml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 31d83a10..d9fd9e1a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,8 @@ org.green-code-initiative creedengo-java-plugin - 2.2.0-SNAPSHOT + + ${revision} sonar-plugin @@ -40,6 +41,16 @@ + + current-SNAPSHOT + + + + ${git.commit.timestamp.datetime} + 17 ${java.version} ${java.version} From 2b0664f187025ba2ec467d1dbf9f460f5df32917 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 16 Jun 2026 23:28:54 +0200 Subject: [PATCH 217/233] upgrade to dynamic version - bis --- .mvn/extensions.xml | 7 +++++++ .mvn/maven-git-versioning-extension.xml | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 .mvn/extensions.xml create mode 100644 .mvn/maven-git-versioning-extension.xml diff --git a/.mvn/extensions.xml b/.mvn/extensions.xml new file mode 100644 index 00000000..094fe108 --- /dev/null +++ b/.mvn/extensions.xml @@ -0,0 +1,7 @@ + + + me.qoomon + maven-git-versioning-extension + 9.11.0 + + diff --git a/.mvn/maven-git-versioning-extension.xml b/.mvn/maven-git-versioning-extension.xml new file mode 100644 index 00000000..071e3ab1 --- /dev/null +++ b/.mvn/maven-git-versioning-extension.xml @@ -0,0 +1,18 @@ + + + + .+ + ${ref}-SNAPSHOT + + + + \d+\.\d+\.\d+.*)$]]> + ${ref.version} + + + + + + ${commit} + + From 436329370c4174d332d39b77def5dd429e2dbff5 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 16 Jun 2026 23:38:13 +0200 Subject: [PATCH 218/233] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9994185e..94994f09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - refacto to have all the test files in the same place (for UT and IT), to avoid maintaining 2 test directories - refacto all test files to add sub-directories for each rule, to be more clear and to be able to add more tests for each rule in the future - fix integration test system run + fix TI GCI82 +- upgrade delivery process to be dynamic ## [2.1.2] - 2026-01-11 From 197f3cb1b534f07cfa0deba2269fa57b9d8f1cc9 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 4 Aug 2026 19:47:20 +0200 Subject: [PATCH 219/233] sonarqube 26.7.0 compatibility --- CHANGELOG.md | 2 ++ README.md | 2 +- pom.xml | 47 ++++++++++++++++++++++++----------------------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94994f09..1f533de4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- compatibility updates for SonarQube up to 26.7.0 + ### Deleted ## [2.2.0] - 2026-06-16 diff --git a/README.md b/README.md index 5519515a..0902e6d7 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ Ready to use binaries are available [from GitHub](https://github.com/green-code- | 2.0.+ / 2.1.+ | 9.9.0 LTS to 25.12.0 | 17 | | 2.2.+ | 25.1.+ | 17 | | 2.2.+ | 25.2.+ LTS to 25.12.+ | 17 / 21 | -| 2.2.+ | 26.1.+ LTS to 26.6.+ | 21 | +| 2.2.+ | 26.1.+ LTS to 26.7.+ | 21 | > Compatibility table of versions lower than 1.4.+ are available from the > main [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-plugins-version-compatibility). diff --git a/pom.xml b/pom.xml index d9fd9e1a..0055d25c 100644 --- a/pom.xml +++ b/pom.xml @@ -89,34 +89,35 @@ false - + - - - - - - - - - - - - - - - - - - - 25.12.0.117093 + + + + + + + + + + + + + + + + + + + - - - + + + + 26.7.0.124771 ${sonarjava.version} From 5d0f022b8b9a677264ca1c432f5122198ff0eeea Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 4 Aug 2026 20:00:41 +0200 Subject: [PATCH 220/233] update CI build from jdk17 to jdk21 --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6885ed65..d9aba89e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,11 +23,11 @@ jobs: with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v5 with: distribution: "temurin" - java-version: 17 + java-version: 21 cache: maven - name: Configure Maven for Sonar From 4e40ffcab59dbac46266c652c18627abbc5495b1 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Tue, 4 Aug 2026 20:02:29 +0200 Subject: [PATCH 221/233] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f533de4..5c8826c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - compatibility updates for SonarQube up to 26.7.0 +- update default CI JDK from 17 to 21 ### Deleted From d53678974e907de159c363dbed5b73fbb5f68d24 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 7 Aug 2026 12:59:59 +0200 Subject: [PATCH 222/233] upgrade lib + clean readme --- CHANGELOG.md | 1 + README.md | 15 +++++++-------- pom.xml | 11 +++++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c8826c8..5c8bb50e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - compatibility updates for SonarQube up to 26.7.0 - update default CI JDK from 17 to 21 +- upgrade internal librairies versions ### Deleted diff --git a/README.md b/README.md index 0902e6d7..11ebf2bd 100644 --- a/README.md +++ b/README.md @@ -57,14 +57,13 @@ 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 | -| 1.7.+ | 9.9.+ LTS to 10.6.0 | 17 | -| 2.0.+ / 2.1.+ | 9.9.0 LTS to 25.12.0 | 17 | -| 2.2.+ | 25.1.+ | 17 | -| 2.2.+ | 25.2.+ LTS to 25.12.+ | 17 / 21 | -| 2.2.+ | 26.1.+ LTS to 26.7.+ | 21 | +| Plugin version | SonarQube version | Java version | +|----------------|--------------------|--------------| +| 1.6.+ | 9.4.+ to 10.6.+ | 11 / 17 | +| 1.7.+ | 9.9.+ to 10.6.+ | 17 | +| 2.0.+ / 2.1.+ | 9.9.+ to 25.12.+ | 17 | +| 2.2.+ | 24.12.+ to 25.12.+ | 17 | +| 2.2.+ | 25.2.+ to 26.7.+ | 21 | > Compatibility table of versions lower than 1.4.+ are available from the > main [creedengo repository](https://github.com/green-code-initiative/creedengo-rules-specifications#-plugins-version-compatibility). diff --git a/pom.xml b/pom.xml index 0055d25c..856fee8b 100644 --- a/pom.xml +++ b/pom.xml @@ -81,7 +81,10 @@ 1.25.1.3002 - 3.1.0 + 3.2.0 + + + 0.5.0 https://repo1.maven.org/maven2 @@ -102,11 +105,11 @@ - + - + @@ -178,7 +181,7 @@ org.green-code-initiative creedengo-integration-test - 0.4.0 + ${creedengo-integration-test.version} test From 929cda18c28840f287f20faaaf7638a340988220 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 7 Aug 2026 23:42:08 +0200 Subject: [PATCH 223/233] update lib creedengo-integration-test --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 856fee8b..20aead58 100644 --- a/pom.xml +++ b/pom.xml @@ -84,7 +84,7 @@ 3.2.0 - 0.5.0 + 0.6.0 https://repo1.maven.org/maven2 @@ -105,11 +105,11 @@ - + - + From 86602e84edd16d06e4e13024a68d09cb1d7c23b7 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Thu, 27 Aug 2026 17:10:38 +0200 Subject: [PATCH 224/233] update lib and CI check --- .github/workflows/build-jdk17.yml | 34 +++++++++++++++++++++++++++ .github/workflows/build.yml | 2 +- .github/workflows/build_container.yml | 18 +++++++------- CHANGELOG.md | 1 + pom.xml | 2 +- 5 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/build-jdk17.yml diff --git a/.github/workflows/build-jdk17.yml b/.github/workflows/build-jdk17.yml new file mode 100644 index 00000000..ac698016 --- /dev/null +++ b/.github/workflows/build-jdk17.yml @@ -0,0 +1,34 @@ +name: Build and Tests for JDK 17 + +on: + push: + branches: + - main + paths-ignore: + - "*.md" + tags: + - "[0-9]+.[0-9]+.[0-9]+" + pull_request: + types: [opened, synchronize, reopened] + +jobs: + build: + name: Build + runs-on: ubuntu-latest + permissions: + pull-requests: read # allows SonarCloud to decorate PRs with analysis results + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Set up JDK 17 + uses: actions/setup-java@v5 + with: + distribution: "temurin" + java-version: 17 + cache: maven + + - name: Verify + run: ./mvnw -e -B verify -Dtest-it.sonarqube.version=24.12.0.100206 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d9aba89e..63d9e84b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Build and Tests +name: Build, Tests and check SonarQube on: push: diff --git a/.github/workflows/build_container.yml b/.github/workflows/build_container.yml index 2ba91fcf..d5bb22c4 100644 --- a/.github/workflows/build_container.yml +++ b/.github/workflows/build_container.yml @@ -2,15 +2,15 @@ # template source: https://github.com/bretfisher/docker-build-workflow/blob/main/templates/call-docker-build.yaml name: Docker Build -on: - push: - branches: - - main - tags: - - '*' - # pull_request: - # branches: - # - main +#on: +# push: +# branches: +# - main +# tags: +# - '*' +# # pull_request: +# # branches: +# # - main env: # github.repository as / diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c8bb50e..6827115f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - compatibility updates for SonarQube up to 26.7.0 - update default CI JDK from 17 to 21 - upgrade internal librairies versions +- add CI check for JDK17 and JDK21 ### Deleted diff --git a/pom.xml b/pom.xml index 20aead58..90c2f5bb 100644 --- a/pom.xml +++ b/pom.xml @@ -84,7 +84,7 @@ 3.2.0 - 0.6.0 + 0.7.0 https://repo1.maven.org/maven2 From 7ce324f86a648e32a3f555d09f8f653af930bf46 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 28 Aug 2026 14:56:39 +0200 Subject: [PATCH 225/233] GCI82 : fix record false positive --- CHANGELOG.md | 1 + .../creedengo/java/integration/tests/GCIRulesIT.java | 4 ++-- .../GCI82/MakeNonReassignedVariablesConstants.java | 7 ++++++- .../checks/MakeNonReassignedVariablesConstants.java | 11 ++++++++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6827115f..bbedac87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - update default CI JDK from 17 to 21 - upgrade internal librairies versions - add CI check for JDK17 and JDK21 +- [#105](https://github.com/green-code-initiative/creedengo-java/pull/105) GCI82 : fix rule to handle record types and adjust test cases ### Deleted diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java index 86c5f5fc..4f4c0343 100644 --- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java +++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java @@ -426,8 +426,8 @@ void testGCI82() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java"; String ruleId = "creedengo-java:GCI82"; String ruleMsg = "The variable is never reassigned and can be 'final'"; - int[] startLines = new int[]{9, 14, 15, 20, 26, 29, 48, 75, 108, 121, 146}; - int[] endLines = new int[]{9, 14, 15, 20, 26, 29, 48, 75, 108, 121, 146}; + int[] startLines = new int[]{9, 14, 15, 20, 26, 29, 53, 80, 113, 126, 151}; + int[] endLines = new int[]{9, 14, 15, 20, 26, 29, 53, 80, 113, 126, 151}; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java index dc192cdd..e1cc029d 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java @@ -29,6 +29,11 @@ public class MakeNonReassignedVariablesConstants { private String varDefinedInClassInFinalConstructor = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}} private String varDefinedInClassNotReassignedInConstructor = "0"; // Compliant (the String was passed as a non-final parameter to the constructor) + private record myRecord( + String myImplicitlyFinalStringField, // Compliant + Integer myImplicitlyFinalIntField) // Compliant + { } + public MakeNonReassignedVariablesConstants() { varDefinedInConstructorReassigned = "3"; this.varDefinedInConstructorReassignedByThis = "3"; @@ -146,4 +151,4 @@ class notReassignedInConstructorNotFinal{ notReassignedInConstructorNotFinal(String notReassignedInConstructorNotFinal) { // Noncompliant {{The variable is never reassigned and can be 'final'}} System.out.println(notReassignedInConstructorNotFinal); } -} \ No newline at end of file +} diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java index 495bc4e2..884c3e40 100644 --- a/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java +++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java @@ -32,13 +32,22 @@ public void visitNode(@Nonnull Tree tree) { LOGGER.debug(" => isNotReassigned = {}", isNotReassigned(variableTree)); LOGGER.debug(" => isPassedAsNonFinalParameter = {}", isPassedAsNonFinalParameter(variableTree)); } - if (isNotFinalAndNotStatic(variableTree) && isNotReassigned(variableTree)) { + if (isNotFromRecord(variableTree) && + isNotFinalAndNotStatic(variableTree) && + isNotReassigned(variableTree)) { reportIssue(tree, MESSAGE_RULE); } else { super.visitNode(tree); } } + private static boolean isNotFromRecord(VariableTree variableTree) { + Tree parent = variableTree.parent(); + if (parent == null) return false; + + return !parent.is(Kind.RECORD); + } + private static boolean isNotReassigned(VariableTree variableTree) { return variableTree.symbol() .usages() From 6dc016aeec135ff12274fa701a64e5786f96ef45 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 28 Aug 2026 15:01:37 +0200 Subject: [PATCH 226/233] correction on CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbedac87..deae5510 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - update default CI JDK from 17 to 21 - upgrade internal librairies versions - add CI check for JDK17 and JDK21 -- [#105](https://github.com/green-code-initiative/creedengo-java/pull/105) GCI82 : fix rule to handle record types and adjust test cases +- [#198](https://github.com/green-code-initiative/creedengo-java/pull/198) GCI82 : fix rule to handle record types and adjust test cases ### Deleted From 5655c3051f08acbb835f5e80581d8b05666f26cd Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 28 Aug 2026 15:59:29 +0200 Subject: [PATCH 227/233] GCI82 : fix lombok false positive --- CHANGELOG.md | 1 + .../java/integration/tests/GCIRulesIT.java | 4 +- .../pom.xml | 8 +- .../MakeNonReassignedVariablesConstants.java | 24 ++++++ .../MakeNonReassignedVariablesConstants.java | 79 +++++++++++++++++++ 5 files changed, 113 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index deae5510..494d031b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - upgrade internal librairies versions - add CI check for JDK17 and JDK21 - [#198](https://github.com/green-code-initiative/creedengo-java/pull/198) GCI82 : fix rule to handle record types and adjust test cases +- [#113](https://github.com/green-code-initiative/creedengo-java/pull/113) GCI82 : fix rule to handle Lombok generated setters ### Deleted diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java index 4f4c0343..b42a77d2 100644 --- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java +++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java @@ -426,8 +426,8 @@ void testGCI82() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java"; String ruleId = "creedengo-java:GCI82"; String ruleMsg = "The variable is never reassigned and can be 'final'"; - int[] startLines = new int[]{9, 14, 15, 20, 26, 29, 53, 80, 113, 126, 151}; - int[] endLines = new int[]{9, 14, 15, 20, 26, 29, 53, 80, 113, 126, 151}; + int[] startLines = new int[]{15, 20, 21, 26, 32, 35, 59, 86, 119, 132, 157, 167, 176}; + int[] endLines = new int[]{15, 20, 21, 26, 32, 35, 59, 86, 119, 132, 157, 168, 177}; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/pom.xml b/src/it/test-projects/creedengo-java-plugin-test-project/pom.xml index cfb7ba4f..839969c9 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/pom.xml +++ b/src/it/test-projects/creedengo-java-plugin-test-project/pom.xml @@ -32,6 +32,12 @@ spring-beans 5.3.25 + + org.projectlombok + lombok + 1.18.46 + provided + - \ No newline at end of file + diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java index e1cc029d..7e5983a7 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java @@ -1,9 +1,15 @@ package org.greencodeinitiative.creedengo.java.checks; import java.util.logging.Logger; +import lombok.Setter; +import lombok.Data; +import lombok.AccessLevel; public class MakeNonReassignedVariablesConstants { + @Setter + private String myLombokManagedString = "initialValue"; // Compliant + private final Logger logger = Logger.getLogger(""); // Compliant private Object myNonFinalAndNotReassignedObject = new Object(); // Noncompliant {{The variable is never reassigned and can be 'final'}} @@ -152,3 +158,21 @@ class notReassignedInConstructorNotFinal{ System.out.println(notReassignedInConstructorNotFinal); } } + +@Setter +class myExtraClassWithLombokSetter { + private String myExtraClassString = "initialValue"; // Compliant + private final String myExtraClassFinalString = "initialValue"; // Compliant + + @Setter(AccessLevel.NONE) // Noncompliant {{The variable is never reassigned and can be 'final'}} + private String myExtraClassSetterNoneString = "initialValue"; +} + +@Data +class myExtraClassWithLombokData { + private String myExtraClassString = "initialValue"; // Compliant + private final String myExtraClassFinalString = "initialValue"; // Compliant + + @Setter(AccessLevel.NONE) // Noncompliant {{The variable is never reassigned and can be 'final'}} + private String myExtraClassSetterNoneString = "initialValue"; +} diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java index 884c3e40..99e73df4 100644 --- a/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java +++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java @@ -17,6 +17,13 @@ public class MakeNonReassignedVariablesConstants extends IssuableSubscriptionVis private static final Logger LOGGER = Loggers.get(MakeNonReassignedVariablesConstants.class); + private final String LOMBOK_SETTER = "Setter"; + private final String LOMBOK_DATA = "Data"; + + private boolean hasParsedImports = false; + private boolean hasLombokSetterImport = false; + private boolean hasLombokDataImport = false; + @Override public List nodesToVisit() { return List.of(Kind.VARIABLE); @@ -33,6 +40,7 @@ public void visitNode(@Nonnull Tree tree) { LOGGER.debug(" => isPassedAsNonFinalParameter = {}", isPassedAsNonFinalParameter(variableTree)); } if (isNotFromRecord(variableTree) && + hasNoLombokSetter(variableTree) && isNotFinalAndNotStatic(variableTree) && isNotReassigned(variableTree)) { reportIssue(tree, MESSAGE_RULE); @@ -168,4 +176,75 @@ private String getVariableNameForLogger(VariableTree variableTree) { } + private boolean hasNoLombokSetter(VariableTree variableTree) { + // Check if the variable is annotated with @Setter + + for (AnnotationTree annotation : variableTree.modifiers().annotations()) { + if (annotation.annotationType().toString().equals(LOMBOK_SETTER)) { + if (hasLombokImport(variableTree, LOMBOK_SETTER)) { + + // Ignore if the annotation has AccessLevel.NONE + if (!annotation.arguments().isEmpty()) { + for (ExpressionTree argument : annotation.arguments()) { + if (argument.is(Kind.MEMBER_SELECT)) { + MemberSelectExpressionTree memberSelectExpressionTree = (MemberSelectExpressionTree) argument; + if (memberSelectExpressionTree.expression().toString().equals("AccessLevel") + && memberSelectExpressionTree.identifier().name().equals("NONE")) { + return true; + } + } + } + } + return false; + } + } + } + // Check if the variable is in a class with @Setter or with @Data + if( variableTree.parent() != null && !variableTree.parent().is(Kind.CLASS)){ + return true; + } + if (variableTree.parent() != null && variableTree.parent().is(Kind.CLASS)) { + ClassTree classTree = (ClassTree) variableTree.parent(); + for (AnnotationTree annotation : classTree.modifiers().annotations()) { + if (annotation.annotationType().toString().equals(LOMBOK_SETTER) && hasLombokImport(variableTree, LOMBOK_SETTER)) { + return false; + } + if (annotation.annotationType().toString().equals(LOMBOK_DATA) && hasLombokImport(variableTree, LOMBOK_DATA)) { + return false; + } + } + } + + return true; + } + + private boolean hasLombokImport(VariableTree variableTree, String lombokImport) { + if (!hasParsedImports) { + Tree currentTree = variableTree; + while (currentTree.parent() != null && !currentTree.parent().is(Kind.COMPILATION_UNIT)) { + currentTree = currentTree.parent(); + } + if (currentTree != null) { + CompilationUnitTree rootNode = (CompilationUnitTree) currentTree.parent(); + for (var importClauseTree : rootNode.imports()) { + ImportTree importTree = (ImportTree) importClauseTree; + MemberSelectExpressionTree identifier = (MemberSelectExpressionTree) importTree.qualifiedIdentifier(); + + if ("lombok".equals(identifier.expression().toString())) { + if ("*".equals(identifier.identifier().name())) { + hasLombokSetterImport = true; + hasLombokDataImport = true; + } else if (LOMBOK_SETTER.equals(identifier.identifier().name())) { + hasLombokSetterImport = true; + } else if (LOMBOK_DATA.equals(identifier.identifier().name())) { + hasLombokDataImport = true; + } + } + } + } + hasParsedImports = true; + } + return LOMBOK_SETTER.equals(lombokImport) ? hasLombokSetterImport : hasLombokDataImport; + } + } From a314346730af5e04ded72e64d00d1a05747c9278 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 28 Aug 2026 16:01:56 +0200 Subject: [PATCH 228/233] correctionon CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 494d031b..9c56c9be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - upgrade internal librairies versions - add CI check for JDK17 and JDK21 - [#198](https://github.com/green-code-initiative/creedengo-java/pull/198) GCI82 : fix rule to handle record types and adjust test cases -- [#113](https://github.com/green-code-initiative/creedengo-java/pull/113) GCI82 : fix rule to handle Lombok generated setters +- [#199](https://github.com/green-code-initiative/creedengo-java/pull/199) GCI82 : fix rule to handle Lombok generated setters ### Deleted From e20cb66716681c794df6fa0e8c701c3d5ed8616c Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 28 Aug 2026 17:15:53 +0200 Subject: [PATCH 229/233] GCI82 : refactor --- CHANGELOG.md | 2 +- .../java/integration/tests/GCIRulesIT.java | 15 +- .../MakeNonReassignedVariablesConstants.java | 24 +++ ...VariablesConstantsWithoutLombokImport.java | 35 ++++ .../MakeNonReassignedVariablesConstants.java | 165 ++++++++++-------- ...keNonReassignedVariablesConstantsTest.java | 11 ++ 6 files changed, 179 insertions(+), 73 deletions(-) create mode 100644 src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsWithoutLombokImport.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c56c9be..7a31c9c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - upgrade internal librairies versions - add CI check for JDK17 and JDK21 - [#198](https://github.com/green-code-initiative/creedengo-java/pull/198) GCI82 : fix rule to handle record types and adjust test cases -- [#199](https://github.com/green-code-initiative/creedengo-java/pull/199) GCI82 : fix rule to handle Lombok generated setters +- [#199](https://github.com/green-code-initiative/creedengo-java/pull/199) GCI82 : fix rule to handle Lombok generated setters (`@Setter`, `@Data`, `@Setter(AccessLevel.NONE)`), including fully qualified annotations used without any `lombok` import ### Deleted diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java index b42a77d2..3bf374d7 100644 --- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java +++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java @@ -426,8 +426,19 @@ void testGCI82() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java"; String ruleId = "creedengo-java:GCI82"; String ruleMsg = "The variable is never reassigned and can be 'final'"; - int[] startLines = new int[]{15, 20, 21, 26, 32, 35, 59, 86, 119, 132, 157, 167, 176}; - int[] endLines = new int[]{15, 20, 21, 26, 32, 35, 59, 86, 119, 132, 157, 168, 177}; + int[] startLines = new int[]{15, 20, 21, 26, 32, 35, 59, 86, 119, 132, 157, 167, 176, 185, 188, 201}; + int[] endLines = new int[]{15, 20, 21, 26, 32, 35, 59, 86, 119, 132, 157, 168, 177, 186, 189, 201}; + + checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); + } + + @Test + void testGCI82_lombokWithoutImport() { + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsWithoutLombokImport.java"; + String ruleId = "creedengo-java:GCI82"; + String ruleMsg = "The variable is never reassigned and can be 'final'"; + int[] startLines = new int[]{11, 13, 34}; + int[] endLines = new int[]{11, 14, 34}; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java index 7e5983a7..16771634 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java @@ -176,3 +176,27 @@ class myExtraClassWithLombokData { @Setter(AccessLevel.NONE) // Noncompliant {{The variable is never reassigned and can be 'final'}} private String myExtraClassSetterNoneString = "initialValue"; } + +// fully qualified annotations : valid Java, and the only available form when there is no lombok import +@Setter +class myExtraClassWithFullyQualifiedLombokSetter { + private String myExtraClassString = "initialValue"; // Compliant + + @Setter(value = AccessLevel.NONE) // Noncompliant {{The variable is never reassigned and can be 'final'}} + private String myNamedArgumentSetterNoneString = "initialValue"; + + @Setter(lombok.AccessLevel.NONE) // Noncompliant {{The variable is never reassigned and can be 'final'}} + private String myFullyQualifiedSetterNoneString = "initialValue"; +} + +@Data +class myExtraClassWithFullyQualifiedLombokData { + private String myExtraClassString = "initialValue"; // Compliant +} + +class myExtraClassWithFullyQualifiedFieldSetter { + @Setter + private String myFullyQualifiedSetterString = "initialValue"; // Compliant + + private String myPlainNotReassignedString = "initialValue"; // Noncompliant {{The variable is never reassigned and can be 'final'}} +} diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsWithoutLombokImport.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsWithoutLombokImport.java new file mode 100644 index 00000000..8a05b275 --- /dev/null +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsWithoutLombokImport.java @@ -0,0 +1,35 @@ +package org.greencodeinitiative.creedengo.java.checks; + +// No "import lombok.*" here on purpose : Lombok annotations are only used in their fully qualified form, +// which is valid Java and used to be a false positive (the rule required an explicit import to be found). + +class MakeNonReassignedVariablesConstantsWithoutLombokImport { + + @lombok.Setter + private String myLombokManagedString = "initialValue"; // Compliant + + private String myPlainNotReassignedString = "initialValue"; // Noncompliant {{The variable is never reassigned and can be 'final'}} + + @lombok.Setter(lombok.AccessLevel.NONE) // Noncompliant {{The variable is never reassigned and can be 'final'}} + private String mySetterNoneString = "initialValue"; + +} + +@lombok.Setter +class myClassWithFullyQualifiedLombokSetterAndNoImport { + private String myClassString = "initialValue"; // Compliant + private final String myClassFinalString = "initialValue"; // Compliant +} + +@lombok.Data +class myClassWithFullyQualifiedLombokDataAndNoImport { + private String myClassString = "initialValue"; // Compliant + private final String myClassFinalString = "initialValue"; // Compliant +} + +class myExtraClassWithFullyQualifiedFieldSetterAndNoImport { + @lombok.Setter + private String myFullyQualifiedSetterString = "initialValue"; // Compliant + + private String myPlainNotReassignedString = "initialValue"; // Noncompliant {{The variable is never reassigned and can be 'final'}} +} diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java index 99e73df4..f7089eaf 100644 --- a/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java +++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java @@ -4,11 +4,14 @@ import org.sonar.api.utils.log.Loggers; import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; +import org.sonar.plugins.java.api.semantic.Type; import org.sonar.plugins.java.api.tree.*; import org.sonar.plugins.java.api.tree.Tree.Kind; +import javax.annotation.CheckForNull; import javax.annotation.Nonnull; import java.util.List; +import java.util.Objects; @Rule(key = "GCI82") public class MakeNonReassignedVariablesConstants extends IssuableSubscriptionVisitor { @@ -17,12 +20,11 @@ public class MakeNonReassignedVariablesConstants extends IssuableSubscriptionVis private static final Logger LOGGER = Loggers.get(MakeNonReassignedVariablesConstants.class); - private final String LOMBOK_SETTER = "Setter"; - private final String LOMBOK_DATA = "Data"; - - private boolean hasParsedImports = false; - private boolean hasLombokSetterImport = false; - private boolean hasLombokDataImport = false; + private static final String LOMBOK_PACKAGE = "lombok"; + private static final String SETTER = "Setter"; + private static final String DATA = "Data"; + private static final String ACCESS_LEVEL_NONE = "AccessLevel.NONE"; + private static final String NONE = "NONE"; @Override public List nodesToVisit() { @@ -39,10 +41,11 @@ public void visitNode(@Nonnull Tree tree) { LOGGER.debug(" => isNotReassigned = {}", isNotReassigned(variableTree)); LOGGER.debug(" => isPassedAsNonFinalParameter = {}", isPassedAsNonFinalParameter(variableTree)); } + // the Lombok check is the most expensive predicate : it is evaluated last, on actual candidates only if (isNotFromRecord(variableTree) && - hasNoLombokSetter(variableTree) && isNotFinalAndNotStatic(variableTree) && - isNotReassigned(variableTree)) { + isNotReassigned(variableTree) && + !isLombokManaged(variableTree)) { reportIssue(tree, MESSAGE_RULE); } else { super.visitNode(tree); @@ -176,75 +179,97 @@ private String getVariableNameForLogger(VariableTree variableTree) { } - private boolean hasNoLombokSetter(VariableTree variableTree) { - // Check if the variable is annotated with @Setter - - for (AnnotationTree annotation : variableTree.modifiers().annotations()) { - if (annotation.annotationType().toString().equals(LOMBOK_SETTER)) { - if (hasLombokImport(variableTree, LOMBOK_SETTER)) { - - // Ignore if the annotation has AccessLevel.NONE - if (!annotation.arguments().isEmpty()) { - for (ExpressionTree argument : annotation.arguments()) { - if (argument.is(Kind.MEMBER_SELECT)) { - MemberSelectExpressionTree memberSelectExpressionTree = (MemberSelectExpressionTree) argument; - if (memberSelectExpressionTree.expression().toString().equals("AccessLevel") - && memberSelectExpressionTree.identifier().name().equals("NONE")) { - return true; - } - } - } - } - return false; - } - } + /** + * A variable is "Lombok managed" when Lombok generates a setter for it : making it {@code final} + * would not compile, so the rule must stay silent. + *

+ * This happens when the field itself is annotated with {@code @Setter}, or when its owner class is + * annotated with {@code @Setter} or {@code @Data}. A field level {@code @Setter(AccessLevel.NONE)} + * explicitly disables the generation and therefore wins over the class level annotation. + */ + private static boolean isLombokManaged(VariableTree variableTree) { + AnnotationTree fieldSetter = findLombokAnnotation(variableTree.modifiers(), SETTER); + if (fieldSetter != null) { + return !isSetterDisabled(fieldSetter); } - // Check if the variable is in a class with @Setter or with @Data - if( variableTree.parent() != null && !variableTree.parent().is(Kind.CLASS)){ - return true; - } - if (variableTree.parent() != null && variableTree.parent().is(Kind.CLASS)) { - ClassTree classTree = (ClassTree) variableTree.parent(); - for (AnnotationTree annotation : classTree.modifiers().annotations()) { - if (annotation.annotationType().toString().equals(LOMBOK_SETTER) && hasLombokImport(variableTree, LOMBOK_SETTER)) { - return false; - } - if (annotation.annotationType().toString().equals(LOMBOK_DATA) && hasLombokImport(variableTree, LOMBOK_DATA)) { - return false; - } - } + + // covers CLASS, but also ENUM and INTERFACE owners, which Kind.CLASS alone would miss + if (variableTree.parent() instanceof ClassTree classTree) { + ModifiersTree classModifiers = classTree.modifiers(); + return findLombokAnnotation(classModifiers, SETTER) != null + || findLombokAnnotation(classModifiers, DATA) != null; } - return true; + return false; } - private boolean hasLombokImport(VariableTree variableTree, String lombokImport) { - if (!hasParsedImports) { - Tree currentTree = variableTree; - while (currentTree.parent() != null && !currentTree.parent().is(Kind.COMPILATION_UNIT)) { - currentTree = currentTree.parent(); + @CheckForNull + private static AnnotationTree findLombokAnnotation(ModifiersTree modifiers, String simpleName) { + for (AnnotationTree annotation : modifiers.annotations()) { + if (isLombokAnnotation(annotation, simpleName)) { + return annotation; } - if (currentTree != null) { - CompilationUnitTree rootNode = (CompilationUnitTree) currentTree.parent(); - for (var importClauseTree : rootNode.imports()) { - ImportTree importTree = (ImportTree) importClauseTree; - MemberSelectExpressionTree identifier = (MemberSelectExpressionTree) importTree.qualifiedIdentifier(); - - if ("lombok".equals(identifier.expression().toString())) { - if ("*".equals(identifier.identifier().name())) { - hasLombokSetterImport = true; - hasLombokDataImport = true; - } else if (LOMBOK_SETTER.equals(identifier.identifier().name())) { - hasLombokSetterImport = true; - } else if (LOMBOK_DATA.equals(identifier.identifier().name())) { - hasLombokDataImport = true; - } - } - } - } - hasParsedImports = true; } - return LOMBOK_SETTER.equals(lombokImport) ? hasLombokSetterImport : hasLombokDataImport; + return null; + } + + /** + * Relies on the semantic model when it is available : the resolved type handles the regular import, + * the wildcard import ({@code import lombok.*}) and the fully qualified usage ({@code @lombok.Setter}) + * indifferently, and rules out a same named annotation coming from another library. + *

+ * When Lombok is missing from the analysis classpath the type cannot be resolved, so we fall back on the + * written form and accept both {@code @Setter} and {@code @lombok.Setter}. + */ + private static boolean isLombokAnnotation(AnnotationTree annotation, String simpleName) { + String fullyQualifiedName = LOMBOK_PACKAGE + "." + simpleName; + + Type annotationType = annotation.symbolType(); + if (!annotationType.isUnknown()) { + return annotationType.is(fullyQualifiedName); + } + + String writtenName = writtenNameOf(annotation.annotationType()); + return simpleName.equals(writtenName) || fullyQualifiedName.equals(writtenName); + } + + /** + * Detects {@code AccessLevel.NONE}, whatever the way it is written : positional or named argument + * ({@code value = ...}), simple, fully qualified or statically imported constant. + */ + private static boolean isSetterDisabled(AnnotationTree annotation) { + return annotation.arguments() + .stream() + .map(MakeNonReassignedVariablesConstants::annotationArgumentValue) + .map(MakeNonReassignedVariablesConstants::writtenNameOf) + .filter(Objects::nonNull) + .anyMatch(value -> value.endsWith(ACCESS_LEVEL_NONE) || NONE.equals(value)); + } + + private static ExpressionTree annotationArgumentValue(ExpressionTree argument) { + return argument.is(Kind.ASSIGNMENT) + ? ((AssignmentExpressionTree) argument).expression() + : argument; + } + + /** + * Rebuilds the name as written in the source ({@code Setter}, {@code lombok.Setter}, + * {@code lombok.AccessLevel.NONE}) by walking the tree : {@code toString()} only returns the source + * text for identifiers, not for member selects. + * + * @return {@code null} when the tree is neither an identifier nor a member select + */ + @CheckForNull + private static String writtenNameOf(Tree tree) { + if (tree.is(Kind.IDENTIFIER)) { + return ((IdentifierTree) tree).name(); + } + if (tree.is(Kind.MEMBER_SELECT)) { + MemberSelectExpressionTree memberSelect = (MemberSelectExpressionTree) tree; + String qualifier = writtenNameOf(memberSelect.expression()); + return qualifier == null ? null : qualifier + "." + memberSelect.identifier().name(); + } + return null; } } diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsTest.java index dfd09887..88b75683 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsTest.java @@ -31,4 +31,15 @@ void test() { .verifyIssues(); } + /** + * Lombok annotations used in their fully qualified form, without any {@code import lombok.*} statement. + */ + @Test + void testWithoutLombokImport() { + CheckVerifier.newVerifier() + .onFile(System.getProperty("testfiles.path") + "/GCI82/MakeNonReassignedVariablesConstantsWithoutLombokImport.java") + .withCheck(new MakeNonReassignedVariablesConstants()) + .verifyIssues(); + } + } From 0808d262722d7883a516059df717c74a1198214e Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 28 Aug 2026 18:21:31 +0200 Subject: [PATCH 230/233] GCI82 instanceof : refactor --- CHANGELOG.md | 1 + .../java/integration/tests/GCIRulesIT.java | 4 +-- .../MakeNonReassignedVariablesConstants.java | 26 ++++++++++++++ .../MakeNonReassignedVariablesConstants.java | 36 +++++++++++++++++-- 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a31c9c8..1814f7a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - add CI check for JDK17 and JDK21 - [#198](https://github.com/green-code-initiative/creedengo-java/pull/198) GCI82 : fix rule to handle record types and adjust test cases - [#199](https://github.com/green-code-initiative/creedengo-java/pull/199) GCI82 : fix rule to handle Lombok generated setters (`@Setter`, `@Data`, `@Setter(AccessLevel.NONE)`), including fully qualified annotations used without any `lombok` import +- [#198](https://github.com/green-code-initiative/creedengo-java/pull/198) GCI82 : fix rule to accept instanceof pattern ### Deleted diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java index 3bf374d7..95073d60 100644 --- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java +++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java @@ -426,8 +426,8 @@ void testGCI82() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java"; String ruleId = "creedengo-java:GCI82"; String ruleMsg = "The variable is never reassigned and can be 'final'"; - int[] startLines = new int[]{15, 20, 21, 26, 32, 35, 59, 86, 119, 132, 157, 167, 176, 185, 188, 201}; - int[] endLines = new int[]{15, 20, 21, 26, 32, 35, 59, 86, 119, 132, 157, 168, 177, 186, 189, 201}; + int[] startLines = new int[]{15, 20, 21, 26, 32, 35, 59, 86, 119, 132, 145, 183, 193, 202, 211, 214, 227}; + int[] endLines = new int[]{15, 20, 21, 26, 32, 35, 59, 86, 119, 132, 145, 183, 194, 203, 212, 215, 227}; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); } diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java index 16771634..f1e97fd2 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java @@ -140,6 +140,32 @@ void reassignedInConstructor(){ o = new notReassignedInConstructorNotFinal(this.varDefinedInClassNotReassignedInConstructor); } + public String nonReasignedVariableWithPatternInstanceOfShouldBeNonCompliant() { + final Object o = "NON-COMPLIANT"; + if (o instanceof String var) { // Noncompliant {{The variable is never reassigned and can be 'final'}} + return var; + } + return ""; + } + + + public String nonReasignedVariableWithPatternInstanceOfWithFinalShouldBeCompliant() { + final Object o = "COMPLIANT"; + if (o instanceof final String var) { // Compliant : here final keyword should be recognized and not trigger the rule + return var; + } + return ""; + } + + public String reasignedVariableWithPatternInstanceOfShouldBeCompliant() { + final Object o = "COMPLIANT"; + if (o instanceof String var) { // Compliant : Variable is reassigned + var = "REASSIGN"; + return var; + } + return ""; + } + } class reassignedInConstructor{ diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java index f7089eaf..cd77e7cd 100644 --- a/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java +++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java @@ -4,6 +4,7 @@ import org.sonar.api.utils.log.Loggers; import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; +import org.sonar.plugins.java.api.location.Position; import org.sonar.plugins.java.api.semantic.Type; import org.sonar.plugins.java.api.tree.*; import org.sonar.plugins.java.api.tree.Tree.Kind; @@ -131,8 +132,39 @@ private static boolean parentIsKind(Tree tree, Kind... orKind) { return false; } - private static boolean isNotFinalAndNotStatic(VariableTree variableTree) { - return hasNoneOf(variableTree.modifiers(), Modifier.FINAL, Modifier.STATIC); + private boolean isNotFinalAndNotStatic(VariableTree variableTree) { + return hasNoneOf(variableTree.modifiers(), Modifier.FINAL, Modifier.STATIC) && !isFinalPatternVariable(variableTree); + } + + /** + * For a pattern variable ({@code instanceof final Type var}), the parser does not attach the + * {@code final} keyword to {@link VariableTree#modifiers()} : the keyword sits between the + * {@code instanceof} keyword and the pattern type, outside of any tree node's token range. + * It is recovered here by reading the raw source in that gap. + */ + private boolean isFinalPatternVariable(VariableTree variableTree) { + Tree parent = variableTree.parent(); + if (parent == null || !parent.is(Kind.TYPE_PATTERN) || !(parent.parent() instanceof PatternInstanceOfTree patternInstanceOf)) { + return false; + } + String textBeforeType = textBetween( + patternInstanceOf.instanceofKeyword().range().end(), + variableTree.type().firstToken().range().start() + ); + return "final".equals(textBeforeType.trim()); + } + + private String textBetween(Position start, Position end) { + List lines = context.getFileLines(); + if (start.line() == end.line()) { + return lines.get(start.line() - 1).substring(start.columnOffset(), end.columnOffset()); + } + StringBuilder result = new StringBuilder(lines.get(start.line() - 1).substring(start.columnOffset())); + for (int line = start.line() + 1; line < end.line(); line++) { + result.append(lines.get(line - 1)); + } + result.append(lines.get(end.line() - 1), 0, end.columnOffset()); + return result.toString(); } private static boolean hasNoneOf(ModifiersTree modifiersTree, Modifier... unexpectedModifiers) { From 61ab1cf3fc7f6b7ded7ae3cbdf7796b9b852a47b Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 28 Aug 2026 18:49:17 +0200 Subject: [PATCH 231/233] GCI82 abstract method fix --- CHANGELOG.md | 3 ++- .../java/integration/tests/GCIRulesIT.java | 11 +++++++++ ...edVariablesConstantsForAbstractMethod.java | 23 +++++++++++++++++++ .../MakeNonReassignedVariablesConstants.java | 9 ++++++++ ...keNonReassignedVariablesConstantsTest.java | 8 +++++++ 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForAbstractMethod.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 1814f7a1..d2d963cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - add CI check for JDK17 and JDK21 - [#198](https://github.com/green-code-initiative/creedengo-java/pull/198) GCI82 : fix rule to handle record types and adjust test cases - [#199](https://github.com/green-code-initiative/creedengo-java/pull/199) GCI82 : fix rule to handle Lombok generated setters (`@Setter`, `@Data`, `@Setter(AccessLevel.NONE)`), including fully qualified annotations used without any `lombok` import -- [#198](https://github.com/green-code-initiative/creedengo-java/pull/198) GCI82 : fix rule to accept instanceof pattern +- [#200](https://github.com/green-code-initiative/creedengo-java/pull/200) GCI82 : fix rule to accept instanceof pattern +- [#198](https://github.com/green-code-initiative/creedengo-java/pull/198) GCI82 : fix rule on abstarct methods ### Deleted diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java index 95073d60..189f983a 100644 --- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java +++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java @@ -443,6 +443,17 @@ void testGCI82_lombokWithoutImport() { checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); } + @Test + void testGCI82_abstractMethods() { + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForAbstractMethod.java"; + String ruleId = "creedengo-java:GCI82"; + String ruleMsg = "The variable is never reassigned and can be 'final'"; + int[] startLines = new int[]{16, 20}; + int[] endLines = new int[]{16, 20}; + + checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); + } + @Test void testGCI69() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI69/NoFunctionCallWhenDeclaringForLoop.java"; diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForAbstractMethod.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForAbstractMethod.java new file mode 100644 index 00000000..e5d075a7 --- /dev/null +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForAbstractMethod.java @@ -0,0 +1,23 @@ +package org.greencodeinitiative.creedengo.java.checks; + +@FunctionalInterface +interface EventListenerSample { + /** + * Callback method when an event occurs + * @param value Event data + * @return False if this event must stop at this treatment. + */ + boolean onEvent(T value); // Compliant +} + +interface InterfaceWithMultipleMethods { + void abstractMethod(String param); // Compliant + + default void defaultMethod(String param) { // Noncompliant {{The variable is never reassigned and can be 'final'}} + System.out.println(param); + } + + static void staticMethod(String param) { // Noncompliant {{The variable is never reassigned and can be 'final'}} + System.out.println(param); + } +} diff --git a/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java b/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java index cd77e7cd..64fbe177 100644 --- a/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java +++ b/src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java @@ -42,6 +42,10 @@ public void visitNode(@Nonnull Tree tree) { LOGGER.debug(" => isNotReassigned = {}", isNotReassigned(variableTree)); LOGGER.debug(" => isPassedAsNonFinalParameter = {}", isPassedAsNonFinalParameter(variableTree)); } + + if (isParameterOfAbstractMethod(variableTree)) + return; + // the Lombok check is the most expensive predicate : it is evaluated last, on actual candidates only if (isNotFromRecord(variableTree) && isNotFinalAndNotStatic(variableTree) && @@ -53,6 +57,11 @@ public void visitNode(@Nonnull Tree tree) { } } + private static boolean isParameterOfAbstractMethod(VariableTree variableTree) { + Tree parent = variableTree.parent(); + return parent != null && parent.is(Kind.METHOD) && ((MethodTree) parent).block() == null; + } + private static boolean isNotFromRecord(VariableTree variableTree) { Tree parent = variableTree.parent(); if (parent == null) return false; diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsTest.java index 88b75683..8854c7ac 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsTest.java @@ -42,4 +42,12 @@ void testWithoutLombokImport() { .verifyIssues(); } + @Test + void testAbstractMethods() { + CheckVerifier.newVerifier() + .onFile(System.getProperty("testfiles.path") + "/GCI82/MakeNonReassignedVariablesConstantsForAbstractMethod.java") + .withCheck(new MakeNonReassignedVariablesConstants()) + .verifyIssues(); + } + } From aea626985da0353858071628e5ccef565880a415 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 28 Aug 2026 18:51:31 +0200 Subject: [PATCH 232/233] CHANGELOG fix --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2d963cf..107e0292 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#198](https://github.com/green-code-initiative/creedengo-java/pull/198) GCI82 : fix rule to handle record types and adjust test cases - [#199](https://github.com/green-code-initiative/creedengo-java/pull/199) GCI82 : fix rule to handle Lombok generated setters (`@Setter`, `@Data`, `@Setter(AccessLevel.NONE)`), including fully qualified annotations used without any `lombok` import - [#200](https://github.com/green-code-initiative/creedengo-java/pull/200) GCI82 : fix rule to accept instanceof pattern -- [#198](https://github.com/green-code-initiative/creedengo-java/pull/198) GCI82 : fix rule on abstarct methods +- [#201](https://github.com/green-code-initiative/creedengo-java/pull/201) GCI82 : fix rule on abstract methods ### Deleted From bd9eea8481405285719ac19c156034f7716f7cdc Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 28 Aug 2026 19:54:41 +0200 Subject: [PATCH 233/233] GCI82 : refacto UT and IT --- .../java/integration/tests/GCIRulesIT.java | 37 ++++++++- .../MakeNonReassignedVariablesConstants.java | 79 ------------------- ...signedVariablesConstantsForInstanceOf.java | 30 +++++++ ...ReassignedVariablesConstantsForLombok.java | 55 +++++++++++++ ...ReassignedVariablesConstantsForRecord.java | 9 +++ ...keNonReassignedVariablesConstantsTest.java | 27 ++++++- 6 files changed, 153 insertions(+), 84 deletions(-) create mode 100644 src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForInstanceOf.java create mode 100644 src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForLombok.java create mode 100644 src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForRecord.java diff --git a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java index 189f983a..2ab7df8c 100644 --- a/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java +++ b/src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java @@ -426,8 +426,19 @@ void testGCI82() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java"; String ruleId = "creedengo-java:GCI82"; String ruleMsg = "The variable is never reassigned and can be 'final'"; - int[] startLines = new int[]{15, 20, 21, 26, 32, 35, 59, 86, 119, 132, 145, 183, 193, 202, 211, 214, 227}; - int[] endLines = new int[]{15, 20, 21, 26, 32, 35, 59, 86, 119, 132, 145, 183, 194, 203, 212, 215, 227}; + int[] startLines = new int[]{9, 14, 15, 20, 26, 29, 48, 75, 108, 121, 146}; + int[] endLines = new int[]{9, 14, 15, 20, 26, 29, 48, 75, 108, 121, 146}; + + checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); + } + + @Test + void testGCI82_lombok() { + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForLombok.java"; + String ruleId = "creedengo-java:GCI82"; + String ruleMsg = "The variable is never reassigned and can be 'final'"; + int[] startLines = new int[]{20, 29, 38, 41, 54}; + int[] endLines = new int[]{21, 30, 39, 42, 54}; checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); } @@ -443,6 +454,28 @@ void testGCI82_lombokWithoutImport() { checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); } + @Test + void testGCI82_record() { + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForRecord.java"; + String ruleId = "creedengo-java:GCI82"; + String ruleMsg = "The variable is never reassigned and can be 'final'"; + int[] startLines = new int[]{}; + int[] endLines = new int[]{}; + + checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); + } + + @Test + void testGCI82_instanceOf() { + String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForInstanceOf.java"; + String ruleId = "creedengo-java:GCI82"; + String ruleMsg = "The variable is never reassigned and can be 'final'"; + int[] startLines = new int[]{7}; + int[] endLines = new int[]{7}; + + checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines); + } + @Test void testGCI82_abstractMethods() { String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForAbstractMethod.java"; diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java index f1e97fd2..ce5c3caf 100644 --- a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java @@ -1,15 +1,9 @@ package org.greencodeinitiative.creedengo.java.checks; import java.util.logging.Logger; -import lombok.Setter; -import lombok.Data; -import lombok.AccessLevel; public class MakeNonReassignedVariablesConstants { - @Setter - private String myLombokManagedString = "initialValue"; // Compliant - private final Logger logger = Logger.getLogger(""); // Compliant private Object myNonFinalAndNotReassignedObject = new Object(); // Noncompliant {{The variable is never reassigned and can be 'final'}} @@ -35,11 +29,6 @@ public class MakeNonReassignedVariablesConstants { private String varDefinedInClassInFinalConstructor = "0"; // Noncompliant {{The variable is never reassigned and can be 'final'}} private String varDefinedInClassNotReassignedInConstructor = "0"; // Compliant (the String was passed as a non-final parameter to the constructor) - private record myRecord( - String myImplicitlyFinalStringField, // Compliant - Integer myImplicitlyFinalIntField) // Compliant - { } - public MakeNonReassignedVariablesConstants() { varDefinedInConstructorReassigned = "3"; this.varDefinedInConstructorReassignedByThis = "3"; @@ -140,32 +129,6 @@ void reassignedInConstructor(){ o = new notReassignedInConstructorNotFinal(this.varDefinedInClassNotReassignedInConstructor); } - public String nonReasignedVariableWithPatternInstanceOfShouldBeNonCompliant() { - final Object o = "NON-COMPLIANT"; - if (o instanceof String var) { // Noncompliant {{The variable is never reassigned and can be 'final'}} - return var; - } - return ""; - } - - - public String nonReasignedVariableWithPatternInstanceOfWithFinalShouldBeCompliant() { - final Object o = "COMPLIANT"; - if (o instanceof final String var) { // Compliant : here final keyword should be recognized and not trigger the rule - return var; - } - return ""; - } - - public String reasignedVariableWithPatternInstanceOfShouldBeCompliant() { - final Object o = "COMPLIANT"; - if (o instanceof String var) { // Compliant : Variable is reassigned - var = "REASSIGN"; - return var; - } - return ""; - } - } class reassignedInConstructor{ @@ -184,45 +147,3 @@ class notReassignedInConstructorNotFinal{ System.out.println(notReassignedInConstructorNotFinal); } } - -@Setter -class myExtraClassWithLombokSetter { - private String myExtraClassString = "initialValue"; // Compliant - private final String myExtraClassFinalString = "initialValue"; // Compliant - - @Setter(AccessLevel.NONE) // Noncompliant {{The variable is never reassigned and can be 'final'}} - private String myExtraClassSetterNoneString = "initialValue"; -} - -@Data -class myExtraClassWithLombokData { - private String myExtraClassString = "initialValue"; // Compliant - private final String myExtraClassFinalString = "initialValue"; // Compliant - - @Setter(AccessLevel.NONE) // Noncompliant {{The variable is never reassigned and can be 'final'}} - private String myExtraClassSetterNoneString = "initialValue"; -} - -// fully qualified annotations : valid Java, and the only available form when there is no lombok import -@Setter -class myExtraClassWithFullyQualifiedLombokSetter { - private String myExtraClassString = "initialValue"; // Compliant - - @Setter(value = AccessLevel.NONE) // Noncompliant {{The variable is never reassigned and can be 'final'}} - private String myNamedArgumentSetterNoneString = "initialValue"; - - @Setter(lombok.AccessLevel.NONE) // Noncompliant {{The variable is never reassigned and can be 'final'}} - private String myFullyQualifiedSetterNoneString = "initialValue"; -} - -@Data -class myExtraClassWithFullyQualifiedLombokData { - private String myExtraClassString = "initialValue"; // Compliant -} - -class myExtraClassWithFullyQualifiedFieldSetter { - @Setter - private String myFullyQualifiedSetterString = "initialValue"; // Compliant - - private String myPlainNotReassignedString = "initialValue"; // Noncompliant {{The variable is never reassigned and can be 'final'}} -} diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForInstanceOf.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForInstanceOf.java new file mode 100644 index 00000000..5ab7abd4 --- /dev/null +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForInstanceOf.java @@ -0,0 +1,30 @@ +package org.greencodeinitiative.creedengo.java.checks; + +public class MakeNonReassignedVariablesConstantsForInstanceOf { + + public String nonReasignedVariableWithPatternInstanceOfShouldBeNonCompliant() { + final Object o = "NON-COMPLIANT"; + if (o instanceof String var) { // Noncompliant {{The variable is never reassigned and can be 'final'}} + return var; + } + return ""; + } + + public String nonReasignedVariableWithPatternInstanceOfWithFinalShouldBeCompliant() { + final Object o = "COMPLIANT"; + if (o instanceof final String var) { // Compliant : here final keyword should be recognized and not trigger the rule + return var; + } + return ""; + } + + public String reasignedVariableWithPatternInstanceOfShouldBeCompliant() { + final Object o = "COMPLIANT"; + if (o instanceof String var) { // Compliant : Variable is reassigned + var = "REASSIGN"; + return var; + } + return ""; + } + +} diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForLombok.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForLombok.java new file mode 100644 index 00000000..12c5880c --- /dev/null +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForLombok.java @@ -0,0 +1,55 @@ +package org.greencodeinitiative.creedengo.java.checks; + +import lombok.Setter; +import lombok.Data; +import lombok.AccessLevel; + +class myExtraClassWithLombokAttributeSetter { + + @Setter + private String myLombokManagedString = "initialValue"; // Compliant + +} + +@Setter +class myExtraClassWithLombokSetter { + + private String myExtraClassString = "initialValue"; // Compliant + private final String myExtraClassFinalString = "initialValue"; // Compliant + + @Setter(AccessLevel.NONE) // Noncompliant {{The variable is never reassigned and can be 'final'}} + private String myExtraClassSetterNoneString = "initialValue"; +} + +@Data +class myExtraClassWithLombokData { + private String myExtraClassString = "initialValue"; // Compliant + private final String myExtraClassFinalString = "initialValue"; // Compliant + + @Setter(AccessLevel.NONE) // Noncompliant {{The variable is never reassigned and can be 'final'}} + private String myExtraClassSetterNoneString = "initialValue"; +} + +// fully qualified annotations : valid Java, and the only available form when there is no lombok import +@Setter +class myExtraClassWithFullyQualifiedLombokSetter { + private String myExtraClassString = "initialValue"; // Compliant + + @Setter(value = AccessLevel.NONE) // Noncompliant {{The variable is never reassigned and can be 'final'}} + private String myNamedArgumentSetterNoneString = "initialValue"; + + @Setter(lombok.AccessLevel.NONE) // Noncompliant {{The variable is never reassigned and can be 'final'}} + private String myFullyQualifiedSetterNoneString = "initialValue"; +} + +@Data +class myExtraClassWithFullyQualifiedLombokData { + private String myExtraClassString = "initialValue"; // Compliant +} + +class myExtraClassWithFullyQualifiedFieldSetter { + @Setter + private String myFullyQualifiedSetterString = "initialValue"; // Compliant + + private String myPlainNotReassignedString = "initialValue"; // Noncompliant {{The variable is never reassigned and can be 'final'}} +} diff --git a/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForRecord.java b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForRecord.java new file mode 100644 index 00000000..c02d0b8d --- /dev/null +++ b/src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsForRecord.java @@ -0,0 +1,9 @@ +package org.greencodeinitiative.creedengo.java.checks; + +public class MakeNonReassignedVariablesConstantsForRecord { + + private record myRecord( + String myImplicitlyFinalStringField, // Compliant + Integer myImplicitlyFinalIntField) // Compliant + { } +} diff --git a/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsTest.java b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsTest.java index 8854c7ac..313bd5cb 100644 --- a/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsTest.java +++ b/src/test/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstantsTest.java @@ -31,9 +31,14 @@ void test() { .verifyIssues(); } - /** - * Lombok annotations used in their fully qualified form, without any {@code import lombok.*} statement. - */ + @Test + void testLombok() { + CheckVerifier.newVerifier() + .onFile(System.getProperty("testfiles.path") + "/GCI82/MakeNonReassignedVariablesConstantsForLombok.java") + .withCheck(new MakeNonReassignedVariablesConstants()) + .verifyIssues(); + } + @Test void testWithoutLombokImport() { CheckVerifier.newVerifier() @@ -42,6 +47,22 @@ void testWithoutLombokImport() { .verifyIssues(); } + @Test + void testRecord() { + CheckVerifier.newVerifier() + .onFile(System.getProperty("testfiles.path") + "/GCI82/MakeNonReassignedVariablesConstantsForRecord.java") + .withCheck(new MakeNonReassignedVariablesConstants()) + .verifyNoIssues(); + } + + @Test + void testInstanceOf() { + CheckVerifier.newVerifier() + .onFile(System.getProperty("testfiles.path") + "/GCI82/MakeNonReassignedVariablesConstantsForInstanceOf.java") + .withCheck(new MakeNonReassignedVariablesConstants()) + .verifyIssues(); + } + @Test void testAbstractMethods() { CheckVerifier.newVerifier()