From 22bbe67fec48024db6388d3af6966b3f7b25aa50 Mon Sep 17 00:00:00 2001 From: jycr Date: Wed, 12 Apr 2023 03:28:58 +0200 Subject: [PATCH] green-code-initiative/ecoCode#92 refactor(rule/java): moves Java rules into `ecocode-rules-specifications` module --- ecocode-rules-specifications/pom.xml | 29 +++++ .../src/main/assembly/java.xml | 22 ++++ .../rules/java/JavaRulesRepository.java | 8 ++ .../src/main/rules/EC1}/EC1.json | 0 .../src/main/rules/EC1/java/EC1.asciidoc | 0 .../src/main/rules/EC2}/EC2.json | 0 .../src/main/rules/EC2/java/EC2.asciidoc | 0 .../src/main/rules/EC27}/EC27.json | 0 .../src/main/rules/EC27/java/EC27.asciidoc | 0 .../src/main/rules/EC28}/EC28.json | 0 .../src/main/rules/EC28/java/EC28.asciidoc | 0 .../src/main/rules/EC3}/EC3.json | 0 .../src/main/rules/EC3/java/EC3.asciidoc | 0 .../src/main/rules/EC32}/EC32.json | 0 .../src/main/rules/EC32/java/EC32.asciidoc | 0 .../src/main/rules/EC4}/EC4.json | 0 .../src/main/rules/EC4/java/EC4.asciidoc | 0 .../src/main/rules/EC5}/EC5.json | 0 .../src/main/rules/EC5/java/EC5.asciidoc | 0 .../src/main/rules/EC53}/EC53.json | 0 .../src/main/rules/EC53/java/EC53.asciidoc | 0 .../src/main/rules/EC63}/EC63.json | 0 .../src/main/rules/EC63/java/EC63.asciidoc | 0 .../src/main/rules/EC67}/EC67.json | 0 .../src/main/rules/EC67/java/EC67.asciidoc | 0 .../src/main/rules/EC69}/EC69.json | 0 .../src/main/rules/EC69/java/EC69.asciidoc | 0 .../src/main/rules/EC72}/EC72.json | 0 .../src/main/rules/EC72/java/EC72.asciidoc | 0 .../src/main/rules/EC74}/EC74.json | 0 .../src/main/rules/EC74/java/EC74.asciidoc | 0 .../src/main/rules/EC75}/EC75.json | 0 .../src/main/rules/EC75/java/EC75.asciidoc | 0 .../src/main/rules/EC76}/EC76.json | 0 .../src/main/rules/EC76/java/EC76.asciidoc | 0 .../src/main/rules/EC77}/EC77.json | 0 .../src/main/rules/EC77/java/EC77.asciidoc | 0 .../src/main/rules/EC78}/EC78.json | 0 .../src/main/rules/EC78/java/EC78.asciidoc | 0 .../src/main/rules/EC79}/EC79.json | 0 .../src/main/rules/EC79/java/EC79.asciidoc | 0 java-plugin/pom.xml | 20 +++- .../java/JavaCheckRegistrar.java | 10 +- .../java/JavaRulesDefinition.java | 107 +++++++++++++----- .../greencodeinitiative/java/RulesList.java | 87 -------------- .../java/JavaRulesDefinitionTest.java | 11 +- 46 files changed, 164 insertions(+), 130 deletions(-) create mode 100644 ecocode-rules-specifications/src/main/assembly/java.xml create mode 100644 ecocode-rules-specifications/src/main/java/io/ecocode/rules/java/JavaRulesRepository.java rename {java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java => ecocode-rules-specifications/src/main/rules/EC1}/EC1.json (100%) rename java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC1.html => ecocode-rules-specifications/src/main/rules/EC1/java/EC1.asciidoc (100%) rename {java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java => ecocode-rules-specifications/src/main/rules/EC2}/EC2.json (100%) rename java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC2.html => ecocode-rules-specifications/src/main/rules/EC2/java/EC2.asciidoc (100%) rename {java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java => ecocode-rules-specifications/src/main/rules/EC27}/EC27.json (100%) rename java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC27.html => ecocode-rules-specifications/src/main/rules/EC27/java/EC27.asciidoc (100%) rename {java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java => ecocode-rules-specifications/src/main/rules/EC28}/EC28.json (100%) rename java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC28.html => ecocode-rules-specifications/src/main/rules/EC28/java/EC28.asciidoc (100%) rename {java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java => ecocode-rules-specifications/src/main/rules/EC3}/EC3.json (100%) rename java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC3.html => ecocode-rules-specifications/src/main/rules/EC3/java/EC3.asciidoc (100%) rename {java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java => ecocode-rules-specifications/src/main/rules/EC32}/EC32.json (100%) rename java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC32.html => ecocode-rules-specifications/src/main/rules/EC32/java/EC32.asciidoc (100%) rename {java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java => ecocode-rules-specifications/src/main/rules/EC4}/EC4.json (100%) rename java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC4.html => ecocode-rules-specifications/src/main/rules/EC4/java/EC4.asciidoc (100%) rename {java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java => ecocode-rules-specifications/src/main/rules/EC5}/EC5.json (100%) rename java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC5.html => ecocode-rules-specifications/src/main/rules/EC5/java/EC5.asciidoc (100%) rename {java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java => ecocode-rules-specifications/src/main/rules/EC53}/EC53.json (100%) rename java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC53.html => ecocode-rules-specifications/src/main/rules/EC53/java/EC53.asciidoc (100%) rename {java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java => ecocode-rules-specifications/src/main/rules/EC63}/EC63.json (100%) rename java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC63.html => ecocode-rules-specifications/src/main/rules/EC63/java/EC63.asciidoc (100%) rename {java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java => ecocode-rules-specifications/src/main/rules/EC67}/EC67.json (100%) rename java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC67.html => ecocode-rules-specifications/src/main/rules/EC67/java/EC67.asciidoc (100%) rename {java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java => ecocode-rules-specifications/src/main/rules/EC69}/EC69.json (100%) rename java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC69.html => ecocode-rules-specifications/src/main/rules/EC69/java/EC69.asciidoc (100%) rename {java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java => ecocode-rules-specifications/src/main/rules/EC72}/EC72.json (100%) rename java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC72.html => ecocode-rules-specifications/src/main/rules/EC72/java/EC72.asciidoc (100%) rename {java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java => ecocode-rules-specifications/src/main/rules/EC74}/EC74.json (100%) rename java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC74.html => ecocode-rules-specifications/src/main/rules/EC74/java/EC74.asciidoc (100%) rename {java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java => ecocode-rules-specifications/src/main/rules/EC75}/EC75.json (100%) rename java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC75.html => ecocode-rules-specifications/src/main/rules/EC75/java/EC75.asciidoc (100%) rename {java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java => ecocode-rules-specifications/src/main/rules/EC76}/EC76.json (100%) rename java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC76.html => ecocode-rules-specifications/src/main/rules/EC76/java/EC76.asciidoc (100%) rename {java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java => ecocode-rules-specifications/src/main/rules/EC77}/EC77.json (100%) rename java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC77.html => ecocode-rules-specifications/src/main/rules/EC77/java/EC77.asciidoc (100%) rename {java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java => ecocode-rules-specifications/src/main/rules/EC78}/EC78.json (100%) rename java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC78.html => ecocode-rules-specifications/src/main/rules/EC78/java/EC78.asciidoc (100%) rename {java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java => ecocode-rules-specifications/src/main/rules/EC79}/EC79.json (100%) rename java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC79.html => ecocode-rules-specifications/src/main/rules/EC79/java/EC79.asciidoc (100%) delete mode 100644 java-plugin/src/main/java/fr/greencodeinitiative/java/RulesList.java diff --git a/ecocode-rules-specifications/pom.xml b/ecocode-rules-specifications/pom.xml index 73b970ab9..f8f8fdd09 100644 --- a/ecocode-rules-specifications/pom.xml +++ b/ecocode-rules-specifications/pom.xml @@ -63,6 +63,23 @@ maven-antrun-plugin 3.1.0 + + process-resources + + + + + + + + + + + + + run + + @@ -70,6 +87,18 @@ maven-assembly-plugin 3.5.0 + + assembly-java + prepare-package + + single + + + + ${project.basedir}/src/main/assembly/java.xml + + + true diff --git a/ecocode-rules-specifications/src/main/assembly/java.xml b/ecocode-rules-specifications/src/main/assembly/java.xml new file mode 100644 index 000000000..560df7337 --- /dev/null +++ b/ecocode-rules-specifications/src/main/assembly/java.xml @@ -0,0 +1,22 @@ + + java + + jar + + false + + + ${project.build.outputDirectory} + + io/ecocode/rules/java/*.class + + + + + ${project.build.directory}/java + io/ecocode/rules/java/specifications + + + diff --git a/ecocode-rules-specifications/src/main/java/io/ecocode/rules/java/JavaRulesRepository.java b/ecocode-rules-specifications/src/main/java/io/ecocode/rules/java/JavaRulesRepository.java new file mode 100644 index 000000000..3fd7a0dd3 --- /dev/null +++ b/ecocode-rules-specifications/src/main/java/io/ecocode/rules/java/JavaRulesRepository.java @@ -0,0 +1,8 @@ +package io.ecocode.rules.java; + +public class JavaRulesRepository { + public static final String REPOSITORY_KEY = "ecocode-java"; + public static final String NAME = "ecoCode"; + public static final String LANGUAGE = "java"; + public static final String RESOURCE_BASE_PATH = JavaRulesRepository.class.getPackageName().replace('.', '/') + "/specifications"; +} diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC1.json b/ecocode-rules-specifications/src/main/rules/EC1/EC1.json similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC1.json rename to ecocode-rules-specifications/src/main/rules/EC1/EC1.json diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC1.html b/ecocode-rules-specifications/src/main/rules/EC1/java/EC1.asciidoc similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC1.html rename to ecocode-rules-specifications/src/main/rules/EC1/java/EC1.asciidoc diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC2.json b/ecocode-rules-specifications/src/main/rules/EC2/EC2.json similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC2.json rename to ecocode-rules-specifications/src/main/rules/EC2/EC2.json diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC2.html b/ecocode-rules-specifications/src/main/rules/EC2/java/EC2.asciidoc similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC2.html rename to ecocode-rules-specifications/src/main/rules/EC2/java/EC2.asciidoc diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC27.json b/ecocode-rules-specifications/src/main/rules/EC27/EC27.json similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC27.json rename to ecocode-rules-specifications/src/main/rules/EC27/EC27.json diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC27.html b/ecocode-rules-specifications/src/main/rules/EC27/java/EC27.asciidoc similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC27.html rename to ecocode-rules-specifications/src/main/rules/EC27/java/EC27.asciidoc diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC28.json b/ecocode-rules-specifications/src/main/rules/EC28/EC28.json similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC28.json rename to ecocode-rules-specifications/src/main/rules/EC28/EC28.json diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC28.html b/ecocode-rules-specifications/src/main/rules/EC28/java/EC28.asciidoc similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC28.html rename to ecocode-rules-specifications/src/main/rules/EC28/java/EC28.asciidoc diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC3.json b/ecocode-rules-specifications/src/main/rules/EC3/EC3.json similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC3.json rename to ecocode-rules-specifications/src/main/rules/EC3/EC3.json diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC3.html b/ecocode-rules-specifications/src/main/rules/EC3/java/EC3.asciidoc similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC3.html rename to ecocode-rules-specifications/src/main/rules/EC3/java/EC3.asciidoc diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC32.json b/ecocode-rules-specifications/src/main/rules/EC32/EC32.json similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC32.json rename to ecocode-rules-specifications/src/main/rules/EC32/EC32.json diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC32.html b/ecocode-rules-specifications/src/main/rules/EC32/java/EC32.asciidoc similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC32.html rename to ecocode-rules-specifications/src/main/rules/EC32/java/EC32.asciidoc diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC4.json b/ecocode-rules-specifications/src/main/rules/EC4/EC4.json similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC4.json rename to ecocode-rules-specifications/src/main/rules/EC4/EC4.json diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC4.html b/ecocode-rules-specifications/src/main/rules/EC4/java/EC4.asciidoc similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC4.html rename to ecocode-rules-specifications/src/main/rules/EC4/java/EC4.asciidoc diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC5.json b/ecocode-rules-specifications/src/main/rules/EC5/EC5.json similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC5.json rename to ecocode-rules-specifications/src/main/rules/EC5/EC5.json diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC5.html b/ecocode-rules-specifications/src/main/rules/EC5/java/EC5.asciidoc similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC5.html rename to ecocode-rules-specifications/src/main/rules/EC5/java/EC5.asciidoc diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC53.json b/ecocode-rules-specifications/src/main/rules/EC53/EC53.json similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC53.json rename to ecocode-rules-specifications/src/main/rules/EC53/EC53.json diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC53.html b/ecocode-rules-specifications/src/main/rules/EC53/java/EC53.asciidoc similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC53.html rename to ecocode-rules-specifications/src/main/rules/EC53/java/EC53.asciidoc diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC63.json b/ecocode-rules-specifications/src/main/rules/EC63/EC63.json similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC63.json rename to ecocode-rules-specifications/src/main/rules/EC63/EC63.json diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC63.html b/ecocode-rules-specifications/src/main/rules/EC63/java/EC63.asciidoc similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC63.html rename to ecocode-rules-specifications/src/main/rules/EC63/java/EC63.asciidoc diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC67.json b/ecocode-rules-specifications/src/main/rules/EC67/EC67.json similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC67.json rename to ecocode-rules-specifications/src/main/rules/EC67/EC67.json diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC67.html b/ecocode-rules-specifications/src/main/rules/EC67/java/EC67.asciidoc similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC67.html rename to ecocode-rules-specifications/src/main/rules/EC67/java/EC67.asciidoc diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC69.json b/ecocode-rules-specifications/src/main/rules/EC69/EC69.json similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC69.json rename to ecocode-rules-specifications/src/main/rules/EC69/EC69.json diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC69.html b/ecocode-rules-specifications/src/main/rules/EC69/java/EC69.asciidoc similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC69.html rename to ecocode-rules-specifications/src/main/rules/EC69/java/EC69.asciidoc diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC72.json b/ecocode-rules-specifications/src/main/rules/EC72/EC72.json similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC72.json rename to ecocode-rules-specifications/src/main/rules/EC72/EC72.json diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC72.html b/ecocode-rules-specifications/src/main/rules/EC72/java/EC72.asciidoc similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC72.html rename to ecocode-rules-specifications/src/main/rules/EC72/java/EC72.asciidoc diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC74.json b/ecocode-rules-specifications/src/main/rules/EC74/EC74.json similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC74.json rename to ecocode-rules-specifications/src/main/rules/EC74/EC74.json diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC74.html b/ecocode-rules-specifications/src/main/rules/EC74/java/EC74.asciidoc similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC74.html rename to ecocode-rules-specifications/src/main/rules/EC74/java/EC74.asciidoc diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC75.json b/ecocode-rules-specifications/src/main/rules/EC75/EC75.json similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC75.json rename to ecocode-rules-specifications/src/main/rules/EC75/EC75.json diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC75.html b/ecocode-rules-specifications/src/main/rules/EC75/java/EC75.asciidoc similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC75.html rename to ecocode-rules-specifications/src/main/rules/EC75/java/EC75.asciidoc diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC76.json b/ecocode-rules-specifications/src/main/rules/EC76/EC76.json similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC76.json rename to ecocode-rules-specifications/src/main/rules/EC76/EC76.json diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC76.html b/ecocode-rules-specifications/src/main/rules/EC76/java/EC76.asciidoc similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC76.html rename to ecocode-rules-specifications/src/main/rules/EC76/java/EC76.asciidoc diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC77.json b/ecocode-rules-specifications/src/main/rules/EC77/EC77.json similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC77.json rename to ecocode-rules-specifications/src/main/rules/EC77/EC77.json diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC77.html b/ecocode-rules-specifications/src/main/rules/EC77/java/EC77.asciidoc similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC77.html rename to ecocode-rules-specifications/src/main/rules/EC77/java/EC77.asciidoc diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC78.json b/ecocode-rules-specifications/src/main/rules/EC78/EC78.json similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC78.json rename to ecocode-rules-specifications/src/main/rules/EC78/EC78.json diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC78.html b/ecocode-rules-specifications/src/main/rules/EC78/java/EC78.asciidoc similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC78.html rename to ecocode-rules-specifications/src/main/rules/EC78/java/EC78.asciidoc diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC79.json b/ecocode-rules-specifications/src/main/rules/EC79/EC79.json similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC79.json rename to ecocode-rules-specifications/src/main/rules/EC79/EC79.json diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC79.html b/ecocode-rules-specifications/src/main/rules/EC79/java/EC79.asciidoc similarity index 100% rename from java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/EC79.html rename to ecocode-rules-specifications/src/main/rules/EC79/java/EC79.asciidoc diff --git a/java-plugin/pom.xml b/java-plugin/pom.xml index 88ba0c619..37673412b 100644 --- a/java-plugin/pom.xml +++ b/java-plugin/pom.xml @@ -16,26 +16,30 @@ https://github.com/green-code-initiative/ecoCode/tree/main/java-plugin + + ${project.groupId} + ecocode-rules-specifications + ${project.version} + java + org.sonarsource.java sonar-java-plugin sonar-plugin + provided org.sonarsource.sonarqube sonar-plugin-api - - - - org.sonarsource.sonarqube - sonar-plugin-api-impl + provided org.sonarsource.analyzer-commons sonar-analyzer-commons + provided @@ -127,6 +131,12 @@ META-INF/** + + *:ecocode-rules-specifications + + META-INF/** + + diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java index 1d92303b1..1a94f3a03 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java @@ -21,10 +21,14 @@ import java.util.List; +import io.ecocode.rules.java.JavaRulesRepository; import org.sonar.plugins.java.api.CheckRegistrar; import org.sonar.plugins.java.api.JavaCheck; import org.sonarsource.api.sonarlint.SonarLintSide; +import static fr.greencodeinitiative.java.JavaRulesDefinition.ANNOTATED_RULE_CLASSES; +import static fr.greencodeinitiative.java.JavaRulesDefinition.ANNOTATED_RULE_TEST_CLASSES; + /** * Provide the "checks" (implementations of rules) classes that are going be executed during * source code analysis. @@ -40,20 +44,20 @@ public class JavaCheckRegistrar implements CheckRegistrar { @Override public void register(RegistrarContext registrarContext) { // Call to registerClassesForRepository to associate the classes with the correct repository key - registrarContext.registerClassesForRepository(JavaRulesDefinition.REPOSITORY_KEY, checkClasses(), testCheckClasses()); + registrarContext.registerClassesForRepository(JavaRulesRepository.REPOSITORY_KEY, checkClasses(), testCheckClasses()); } /** * Lists all the main checks provided by the plugin */ public static List> checkClasses() { - return RulesList.getJavaChecks(); + return ANNOTATED_RULE_CLASSES; } /** * Lists all the test checks provided by the plugin */ public static List> testCheckClasses() { - return RulesList.getJavaTestChecks(); + return ANNOTATED_RULE_TEST_CLASSES; } } diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java index 9b6d698d5..38740d39b 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java @@ -19,54 +19,99 @@ */ package fr.greencodeinitiative.java; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Objects; -import java.util.Set; - +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; +import fr.greencodeinitiative.java.checks.AvoidRegexPatternNotStatic; +import fr.greencodeinitiative.java.checks.AvoidSQLRequestInLoop; +import fr.greencodeinitiative.java.checks.AvoidSetConstantInBatchUpdate; +import fr.greencodeinitiative.java.checks.AvoidSpringRepositoryCallInLoopCheck; +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.api.SonarEdition; +import org.sonar.api.SonarProduct; import org.sonar.api.SonarQubeSide; import org.sonar.api.SonarRuntime; -import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.server.rule.RulesDefinition; import org.sonar.api.utils.Version; +import org.sonar.plugins.java.api.JavaCheck; import org.sonarsource.analyzer.commons.RuleMetadataLoader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static io.ecocode.rules.java.JavaRulesRepository.LANGUAGE; +import static io.ecocode.rules.java.JavaRulesRepository.NAME; +import static io.ecocode.rules.java.JavaRulesRepository.REPOSITORY_KEY; +import static io.ecocode.rules.java.JavaRulesRepository.RESOURCE_BASE_PATH; + /** * Declare rule metadata in server repository of rules. * That allows to list the rules in the page "Rules". */ public class JavaRulesDefinition implements RulesDefinition { + static final List> ANNOTATED_RULE_CLASSES = List.of( + ArrayCopyCheck.class, + IncrementCheck.class, + AvoidConcatenateStringsInLoop.class, + AvoidUsageOfStaticCollections.class, + AvoidGettingSizeCollectionInLoop.class, + AvoidRegexPatternNotStatic.class, + NoFunctionCallWhenDeclaringForLoop.class, + AvoidStatementForDMLQueries.class, + AvoidSpringRepositoryCallInLoopCheck.class, + AvoidSQLRequestInLoop.class, + AvoidFullSQLRequest.class, + UseCorrectForLoop.class, + UnnecessarilyAssignValuesToVariables.class, + OptimizeReadFileExceptions.class, + InitializeBufferWithAppropriateSize.class, + AvoidUsingGlobalVariablesCheck.class, + AvoidSetConstantInBatchUpdate.class, + FreeResourcesOfAutoCloseableInterface.class, + AvoidMultipleIfElseStatement.class + ); - // don't change that because the path is hard coded in CheckVerifier - private static final String RESOURCE_BASE_PATH = "fr/greencodeinitiative/l10n/java/rules/java"; - - - // Add the rule keys of the rules which need to be considered as template-rules - private static final Set RULE_TEMPLATES_KEY = Collections.emptySet(); - public static final String NAME = "ecoCode"; - public static final String LANGUAGE = "java"; - public static final String REPOSITORY_KEY = "ecocode-java"; - + static final List> ANNOTATED_RULE_TEST_CLASSES = Collections.emptyList(); + private static final Version SONARQUBE_RUNTIME_VERSION = Version.create(9, 8); + private static final SonarRuntime SONARQUBE_RUNTIME = new SonarRuntime() { @Override - public void define(Context context) { - NewRepository repository = context.createRepository(REPOSITORY_KEY, LANGUAGE).setName(NAME); - - SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(9, 8), SonarQubeSide.SCANNER, SonarEdition.DEVELOPER); - - RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_BASE_PATH, sonarRuntime); - - ruleMetadataLoader.addRulesByAnnotatedClass(repository, new ArrayList<>(RulesList.getChecks())); + public Version getApiVersion() { + return SONARQUBE_RUNTIME_VERSION; + } - setTemplates(repository); + @Override + public SonarProduct getProduct() { + return SonarProduct.SONARQUBE; + } - repository.done(); + @Override + public SonarQubeSide getSonarQubeSide() { + return SonarQubeSide.SCANNER; } - private static void setTemplates(NewRepository repository) { - RULE_TEMPLATES_KEY.stream() - .map(repository::rule) - .filter(Objects::nonNull) - .forEach(rule -> rule.setTemplate(true)); + @Override + public SonarEdition getEdition() { + return SonarEdition.COMMUNITY; } + }; + + @Override + public void define(Context context) { + NewRepository repository = context.createRepository(REPOSITORY_KEY, LANGUAGE).setName(NAME); + RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_BASE_PATH, SONARQUBE_RUNTIME); + ruleMetadataLoader.addRulesByAnnotatedClass(repository, new ArrayList<>(ANNOTATED_RULE_CLASSES)); + repository.done(); + } } diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/RulesList.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/RulesList.java deleted file mode 100644 index d6a5cdbf4..000000000 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/RulesList.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * SonarQube Java - * Copyright (C) 2012-2021 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package fr.greencodeinitiative.java; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -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; -import fr.greencodeinitiative.java.checks.AvoidRegexPatternNotStatic; -import fr.greencodeinitiative.java.checks.AvoidSQLRequestInLoop; -import fr.greencodeinitiative.java.checks.AvoidSetConstantInBatchUpdate; -import fr.greencodeinitiative.java.checks.AvoidSpringRepositoryCallInLoopCheck; -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.JavaCheck; - -public final class RulesList { - - private RulesList() { - } - - public static List> getChecks() { - List> checks = new ArrayList<>(); - checks.addAll(getJavaChecks()); - checks.addAll(getJavaTestChecks()); - return Collections.unmodifiableList(checks); - } - - public static List> getJavaChecks() { - return Collections.unmodifiableList(Arrays.asList( - ArrayCopyCheck.class, - IncrementCheck.class, - AvoidConcatenateStringsInLoop.class, - AvoidUsageOfStaticCollections.class, - AvoidGettingSizeCollectionInLoop.class, - AvoidRegexPatternNotStatic.class, - NoFunctionCallWhenDeclaringForLoop.class, - AvoidStatementForDMLQueries.class, - AvoidSpringRepositoryCallInLoopCheck.class, - AvoidSQLRequestInLoop.class, - AvoidFullSQLRequest.class, - UseCorrectForLoop.class, - UnnecessarilyAssignValuesToVariables.class, - OptimizeReadFileExceptions.class, - InitializeBufferWithAppropriateSize.class, - AvoidUsingGlobalVariablesCheck.class, - AvoidSetConstantInBatchUpdate.class, - FreeResourcesOfAutoCloseableInterface.class, - AvoidMultipleIfElseStatement.class - )); - } - - public static List> getJavaTestChecks() { - return Collections.emptyList(); - } -} diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java index 45bd537e2..e8df94368 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java @@ -19,6 +19,7 @@ */ package fr.greencodeinitiative.java; +import io.ecocode.rules.java.JavaRulesRepository; import org.assertj.core.api.SoftAssertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -30,6 +31,8 @@ import org.sonar.api.server.rule.RulesDefinition.Repository; import org.sonar.api.server.rule.RulesDefinition.Rule; +import static fr.greencodeinitiative.java.JavaRulesDefinition.ANNOTATED_RULE_CLASSES; +import static fr.greencodeinitiative.java.JavaRulesDefinition.ANNOTATED_RULE_TEST_CLASSES; import static org.assertj.core.api.Assertions.assertThat; class JavaRulesDefinitionTest { @@ -41,14 +44,14 @@ void init() { final JavaRulesDefinition rulesDefinition = new JavaRulesDefinition(); final RulesDefinition.Context context = new RulesDefinition.Context(); rulesDefinition.define(context); - repository = context.repository(JavaRulesDefinition.REPOSITORY_KEY); + repository = context.repository(JavaRulesRepository.REPOSITORY_KEY); } @Test void test() { - assertThat(repository.name()).isEqualTo(JavaRulesDefinition.NAME); - assertThat(repository.language()).isEqualTo(JavaRulesDefinition.LANGUAGE); - assertThat(repository.rules()).hasSize(RulesList.getChecks().size()); + assertThat(repository.name()).isEqualTo(JavaRulesRepository.NAME); + assertThat(repository.language()).isEqualTo(JavaRulesRepository.LANGUAGE); + assertThat(repository.rules()).hasSize(ANNOTATED_RULE_CLASSES.size() + ANNOTATED_RULE_TEST_CLASSES.size()); assertThat(repository.rules().stream().filter(Rule::template)).isEmpty(); assertRuleProperties(repository);