From 2fd26556387c6614e6fb0e2e66469505a321fd81 Mon Sep 17 00:00:00 2001 From: Diego Rodriguez <63045276+diegorodriguez31@users.noreply.github.com> Date: Wed, 26 Apr 2023 13:12:48 +0200 Subject: [PATCH 01/17] Remove LEQUAL email --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 43438d2..7db5257 100644 --- a/README.md +++ b/README.md @@ -82,8 +82,6 @@ If you want to do a PR, please put inside of it the reason of this pull request. All details are available in [CONTRIBUTING](https://github.com/cnescatlab/sonar-icode-cnes-plugin/blob/master/CONTRIBUTING.md). ### Feedback and Support -Contact : L-lequal@cnes.fr - Bugs and Feature requests: https://github.com/cnescatlab/sonar-icode-cnes-plugin/issues ### License From 49994e8d35943657d97be4df6458a725cbc840d8 Mon Sep 17 00:00:00 2001 From: Diego Rodriguez <63045276+diegorodriguez31@users.noreply.github.com> Date: Wed, 26 Apr 2023 13:13:03 +0200 Subject: [PATCH 02/17] Remove LEQUAL email --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 643c5ae..33ec036 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,7 +11,7 @@ The following is a set of guidelines for contributing to i-Code CNES plugin for * [Git Commit Messages](#git-commit-messages) ## Code of Conduct -This project and everyone participating in it is governed by the [Lequal Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to [L-lequal@cnes.fr](mailto:L-lequal@cnes.fr). +This project and everyone participating in it is governed by the [Lequal Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. ## How Can I Contribute? From 826da0b79de8e59f6a5ff08391fca2b302a59a91 Mon Sep 17 00:00:00 2001 From: Diego Rodriguez <63045276+diegorodriguez31@users.noreply.github.com> Date: Wed, 26 Apr 2023 13:13:23 +0200 Subject: [PATCH 03/17] Remove LEQUAL email --- CODE_OF_CONDUCT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 7d537b1..7e77a3a 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -34,7 +34,7 @@ This Code of Conduct applies both within project spaces and in public spaces whe ## Enforcement -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at L-lequal@cnes.fr. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. From 91c860850e1caf57f26523fd9819984ed546db1b Mon Sep 17 00:00:00 2001 From: Diego Rodriguez Date: Mon, 1 May 2023 20:26:58 +0200 Subject: [PATCH 04/17] Update sonar api and sonar api impl (old from 3 LTS) --- pom.xml | 37 +++++++++++++------ .../sonar/plugins/icode/ICodePluginTest.java | 5 ++- .../plugins/icode/check/ICodeSensorTest.java | 4 +- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 0c86a25..eff37bd 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ fr.cnes.sonar.plugins sonar-icode-cnes-plugin sonar-plugin - 3.0.1 + 3.1.0 Sonar i-Code CNES plugin @@ -46,6 +46,12 @@ https://github.com/WaldoFR WaldoFR + + Diego Rodriguez + CNES + https://github.com/WaldoFR + WaldoFR + @@ -55,9 +61,10 @@ 11 1.8 1.8 - 6.7.7 + 9.8.0.203 + 9.5.0.56709 2.6.1 - 1.17 + 1.21.0.505 3.7 2.8.2 1.7.25 @@ -81,7 +88,7 @@ - org.sonarsource.sonarqube + org.sonarsource.api.plugin sonar-plugin-api ${sonar.apiVersion} provided @@ -100,12 +107,18 @@ org.sonarsource.sonarqube sonar-testing-harness - ${sonar.apiVersion} + ${sonar.testingHarnessVersion} test + + org.sonarsource.sonarqube + sonar-plugin-api-impl + 9.9.1.69595 + junit junit + 4.11 test @@ -134,7 +147,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.5.1 + 3.10.1 ${jdk.min.version} ${jdk.min.version} @@ -145,13 +158,13 @@ org.codehaus.mojo native2ascii-maven-plugin - 1.0-beta-1 + 2.0.1 - - - native2ascii - - + + + resources + + diff --git a/src/test/java/fr/cnes/sonar/plugins/icode/ICodePluginTest.java b/src/test/java/fr/cnes/sonar/plugins/icode/ICodePluginTest.java index f019c83..d26afce 100644 --- a/src/test/java/fr/cnes/sonar/plugins/icode/ICodePluginTest.java +++ b/src/test/java/fr/cnes/sonar/plugins/icode/ICodePluginTest.java @@ -23,16 +23,17 @@ import org.sonar.api.SonarRuntime; import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.utils.Version; +import org.sonar.api.SonarEdition; public class ICodePluginTest { - private static final Version VERSION_6_7 = Version.create(6, 7); + private static final Version VERSION_8_9 = Version.create(8, 9); @Test public void test_extensions_are_all_set() { ICodePlugin iCodePlugin = new ICodePlugin(); - SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(VERSION_6_7, SonarQubeSide.SERVER); + SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(VERSION_8_9, SonarQubeSide.SERVER, SonarEdition.COMMUNITY); Plugin.Context context = new Plugin.Context(runtime); iCodePlugin.define(context); Assert.assertEquals(12, context.getExtensions().size()); diff --git a/src/test/java/fr/cnes/sonar/plugins/icode/check/ICodeSensorTest.java b/src/test/java/fr/cnes/sonar/plugins/icode/check/ICodeSensorTest.java index d83e958..246b970 100644 --- a/src/test/java/fr/cnes/sonar/plugins/icode/check/ICodeSensorTest.java +++ b/src/test/java/fr/cnes/sonar/plugins/icode/check/ICodeSensorTest.java @@ -65,7 +65,7 @@ public void prepare() throws URISyntaxException { .setLanguage("icode") .setType(InputFile.Type.MAIN) .setLines(10) - .setOriginalLineOffsets(new int[]{0,0,0,0,0,0,0,0,0,0}) + .setOriginalLineStartOffsets(new int[]{0,0,0,0,0,0,0,0,0,0}) .setLastValidOffset(100) .build(); fs.add(clanhb_f); @@ -76,7 +76,7 @@ public void prepare() throws URISyntaxException { .setLanguage("icode") .setType(InputFile.Type.MAIN) .setLines(10) - .setOriginalLineOffsets(new int[]{0,0,0,0,0,0,0,0,0,0}) + .setOriginalLineStartOffsets(new int[]{0,0,0,0,0,0,0,0,0,0}) .setLastValidOffset(100) .build(); fs.add(clanhb_f90); From f92a968fc13f25979249fab951bd28834a720677 Mon Sep 17 00:00:00 2001 From: Diego Rodriguez Date: Thu, 4 May 2023 12:41:11 +0000 Subject: [PATCH 05/17] Try to implement one rule with new method --- .../icode/rules/ICodeRulesDefinition.java | 77 +++++++++++-------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java b/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java index 528dd17..0709995 100644 --- a/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java +++ b/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java @@ -16,11 +16,15 @@ */ package fr.cnes.sonar.plugins.icode.rules; +import org.sonar.api.rule.RuleKey; +import org.sonar.api.rule.RuleStatus; +import org.sonar.api.rule.Severity; +import org.sonar.api.rules.RuleType; +import org.sonar.api.server.rule.RulesDefinition; + import fr.cnes.sonar.plugins.icode.languages.Fortran77Language; import fr.cnes.sonar.plugins.icode.languages.Fortran90Language; import fr.cnes.sonar.plugins.icode.settings.ICodePluginProperties; -import org.sonar.api.server.rule.RulesDefinition; -import org.sonar.api.server.rule.RulesDefinitionXmlLoader; import java.io.InputStream; import java.nio.charset.StandardCharsets; @@ -30,6 +34,10 @@ */ public class ICodeRulesDefinition implements RulesDefinition { + public static final String REPOSITORY = "f77-rules"; + public static final String FORTRAN_LANGUAGE = "f77"; + public static final RuleKey F77_DATA_ARRAY = RuleKey.of(REPOSITORY, "F77.DATA.Array"); + /** Partial key for repository. **/ private static final String REPO_KEY_SUFFIX = "-rules"; @@ -47,32 +55,44 @@ public class ICodeRulesDefinition implements RulesDefinition { */ @Override public void define(final Context context) { - createRepository(context, Fortran77Language.KEY); - createRepository(context, Fortran90Language.KEY); - } + // createRepository(context, Fortran77Language.KEY); + //createRepository(context, Fortran90Language.KEY); + NewRepository repository = context.createRepository(REPOSITORY, FORTRAN_LANGUAGE).setName(ICodePluginProperties.ICODE_NAME) + + NewRule f77DataArray = repository.createRule(F77_DATA_ARRAY.rule()) + .setName("F77.DATA.Array") + .setInternalKey("*") + .setHtmlDescription("Arrays dimension should be declared explicitly. The use of * is tolerated for the last one if justified with a comment.") + .setSeverity(Severity.MAJOR) + .setStatus(RuleStatus.READY) + .setType(RuleType.CODE_SMELL) + .setDebtRemediationFunction(framaErrorRule.debtRemediationFunctions().constantPerIssue("30min")); - /** - * Create repositories for each language. - * - * @param context SonarQube context. - * @param language Key of the language. - */ - protected void createRepository(final Context context, final String language) { - // Create a repository to put rules inside. - final NewRepository repository = context - .createRepository(getRepositoryKeyForLanguage(language), language) - .setName(getRepositoryName()); - - // Get XML file describing rules for language. - final InputStream rulesXml = this.getClass().getResourceAsStream(rulesDefinitionFilePath(language)); - // Add rules in repository. - if (rulesXml != null) { - final RulesDefinitionXmlLoader rulesLoader = new RulesDefinitionXmlLoader(); - rulesLoader.load(repository, rulesXml, StandardCharsets.UTF_8.name()); - } repository.done(); } + // /** + // * Create repositories for each language. + // * + // * @param context SonarQube context. + // * @param language Key of the language. + // */ + // protected void createRepository(final Context context, final String language) { + // // Create a repository to put rules inside. + // final NewRepository repository = context + // .createRepository(getRepositoryKeyForLanguage(language), language) + // .setName(getRepositoryName()); + + // // Get XML file describing rules for language. + // final InputStream rulesXml = this.getClass().getResourceAsStream(rulesDefinitionFilePath(language)); + // // Add rules in repository. + // if (rulesXml != null) { + // final RulesDefinitionXmlLoader rulesLoader = new RulesDefinitionXmlLoader(); + // rulesLoader.load(repository, rulesXml, StandardCharsets.UTF_8.name()); + // } + // repository.done(); + // } + /** * Getter for repository key. * @@ -83,15 +103,6 @@ public static String getRepositoryKeyForLanguage(final String language) { return language + REPO_KEY_SUFFIX; } - /** - * Getter for repository name. - * - * @return A string. - */ - public static String getRepositoryName() { - return ICodePluginProperties.ICODE_NAME; - } - /** * Getter for the path to rules file. * From d0b8cdae6db37165da330967b273a28185ed93c7 Mon Sep 17 00:00:00 2001 From: Diego Date: Thu, 4 May 2023 15:03:58 +0200 Subject: [PATCH 06/17] It's working for one rule !!! --- .../icode/languages/ICodeQualityProfiles.java | 13 ++++++++-- .../icode/rules/ICodeRulesDefinition.java | 7 ++--- .../icode/rules/ICodeRulesDefinitionTest.java | 26 +++++++++---------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java b/src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java index dc70e70..b010e36 100644 --- a/src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java +++ b/src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java @@ -44,8 +44,17 @@ public final class ICodeQualityProfiles implements BuiltInQualityProfilesDefinit */ @Override public void define(final Context context) { - createBuiltInProfile(context, Fortran77Language.KEY, ICodeRulesDefinition.PATH_TO_F77_RULES_XML); - createBuiltInProfile(context, Fortran90Language.KEY, ICodeRulesDefinition.PATH_TO_F90_RULES_XML); + NewBuiltInQualityProfile profile = context.createBuiltInQualityProfile("F 77", "f77"); + profile.setDefault(true); + + NewBuiltInActiveRule data_array = profile.activateRule("f77-rules", "F77.DATA.Array"); + profile.done(); + + NewBuiltInQualityProfile profile2 = context.createBuiltInQualityProfile("F 90", "f90"); + profile2.setDefault(true); + profile2.done(); + //createBuiltInProfile(context, Fortran77Language.KEY, ICodeRulesDefinition.PATH_TO_F77_RULES_XML); + //reateBuiltInProfile(context, Fortran90Language.KEY, ICodeRulesDefinition.PATH_TO_F90_RULES_XML); } /** diff --git a/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java b/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java index 0709995..539b963 100644 --- a/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java +++ b/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java @@ -57,7 +57,7 @@ public class ICodeRulesDefinition implements RulesDefinition { public void define(final Context context) { // createRepository(context, Fortran77Language.KEY); //createRepository(context, Fortran90Language.KEY); - NewRepository repository = context.createRepository(REPOSITORY, FORTRAN_LANGUAGE).setName(ICodePluginProperties.ICODE_NAME) + NewRepository repository = context.createRepository(REPOSITORY, FORTRAN_LANGUAGE).setName(ICodePluginProperties.ICODE_NAME); NewRule f77DataArray = repository.createRule(F77_DATA_ARRAY.rule()) .setName("F77.DATA.Array") @@ -65,8 +65,9 @@ public void define(final Context context) { .setHtmlDescription("Arrays dimension should be declared explicitly. The use of * is tolerated for the last one if justified with a comment.") .setSeverity(Severity.MAJOR) .setStatus(RuleStatus.READY) - .setType(RuleType.CODE_SMELL) - .setDebtRemediationFunction(framaErrorRule.debtRemediationFunctions().constantPerIssue("30min")); + .setType(RuleType.CODE_SMELL); + + f77DataArray.setDebtRemediationFunction(f77DataArray.debtRemediationFunctions().constantPerIssue("30min")); repository.done(); } diff --git a/src/test/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinitionTest.java b/src/test/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinitionTest.java index 0720151..fd260f5 100644 --- a/src/test/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinitionTest.java +++ b/src/test/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinitionTest.java @@ -32,18 +32,18 @@ public void test_creation_of_repositories_and_rules() { Assert.assertEquals(64, context.repository("f90-rules").rules().size()); } - @Test - public void test_creation_of_repositories_and_rules_for_bad_language() { - RulesDefinition.Context context = new RulesDefinition.Context(); - Assert.assertEquals(0, context.repositories().size()); - new ICodeRulesDefinition(){ - @Override - public void define(Context context) { - createRepository(context, "bad"); - } - }.define(context); - Assert.assertEquals(1, context.repositories().size()); - Assert.assertEquals(0, context.repository("bad-rules").rules().size()); - } + // @Test + // public void test_creation_of_repositories_and_rules_for_bad_language() { + // RulesDefinition.Context context = new RulesDefinition.Context(); + // Assert.assertEquals(0, context.repositories().size()); + // new ICodeRulesDefinition(){ + // @Override + // public void define(Context context) { + // createRepository(context, "bad"); + // } + // }.define(context); + // Assert.assertEquals(1, context.repositories().size()); + // Assert.assertEquals(0, context.repository("bad-rules").rules().size()); + // } } From 38995df4b6de267b218e87fa6198f89687f25800 Mon Sep 17 00:00:00 2001 From: Diego Rodriguez Date: Tue, 18 Jul 2023 13:29:03 +0200 Subject: [PATCH 07/17] Handling new way of creating repositories and rules for SQ9 --- .../icode/languages/ICodeQualityProfiles.java | 46 ++---- .../icode/rules/ICodeRulesDefinition.java | 147 ++++++++++-------- src/main/resources/rules/icode-f77-rules.xml | 117 +------------- src/main/resources/rules/icode-f90-rules.xml | 128 --------------- 4 files changed, 103 insertions(+), 335 deletions(-) diff --git a/src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java b/src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java index b010e36..5c4a719 100644 --- a/src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java +++ b/src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java @@ -23,11 +23,15 @@ import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; +import org.sonar.api.server.rule.RulesDefinition.NewRule; + +import java.util.ArrayList; +import java.util.List; import java.io.InputStream; /** - * Built-in quality profile format since SonarQube 6.6. + * Built-in quality profile format since SonarQube 9.9 */ public final class ICodeQualityProfiles implements BuiltInQualityProfilesDefinition { @@ -44,45 +48,29 @@ public final class ICodeQualityProfiles implements BuiltInQualityProfilesDefinit */ @Override public void define(final Context context) { - NewBuiltInQualityProfile profile = context.createBuiltInQualityProfile("F 77", "f77"); - profile.setDefault(true); - - NewBuiltInActiveRule data_array = profile.activateRule("f77-rules", "F77.DATA.Array"); - profile.done(); - - NewBuiltInQualityProfile profile2 = context.createBuiltInQualityProfile("F 90", "f90"); - profile2.setDefault(true); - profile2.done(); - //createBuiltInProfile(context, Fortran77Language.KEY, ICodeRulesDefinition.PATH_TO_F77_RULES_XML); - //reateBuiltInProfile(context, Fortran90Language.KEY, ICodeRulesDefinition.PATH_TO_F90_RULES_XML); + createBuiltInProfile(context, ICodeRulesDefinition.FORTRAN77_REPOSITORY, Fortran77Language.KEY, ICodeRulesDefinition.f77Rules); + createBuiltInProfile(context, ICodeRulesDefinition.FORTRAN90_REPOSITORY, Fortran90Language.KEY, ICodeRulesDefinition.f90Rules); } /** * Create a built in quality profile for a specific language. * * @param context SonarQube context in which create the profile. + * @param repository Rules' repository. * @param language Language key of the associated profile. - * @param path Path to the xml definition of all rules. + * @param rules Rules to activate. */ - private void createBuiltInProfile(final Context context, final String language, final String path) { + private void createBuiltInProfile(final Context context, final String repository, final String languageKey, final List rules) { // Create a builder for the rules' repository. - final NewBuiltInQualityProfile defaultProfile = - context.createBuiltInQualityProfile(I_CODE_RULES_PROFILE_NAME, language); - - // Retrieve all defined rules. - final InputStream stream = getClass().getResourceAsStream(path); - final RulesDefinition rules = (RulesDefinition) XmlHandler.unmarshal(stream, RulesDefinition.class); - final String repositoryKey = ICodeRulesDefinition.getRepositoryKeyForLanguage(language); + NewBuiltInQualityProfile profile = context.createBuiltInQualityProfile(I_CODE_RULES_PROFILE_NAME, languageKey); // Activate all i-Code CNES rules. - for(final Rule rule : rules.getRules()) { - defaultProfile.activateRule(repositoryKey, rule.getKey()); - LOGGER.debug(String.format("Rule %s added to repository %s.", rule.getKey(), repositoryKey)); + for (NewRule rule : rules) { + profile.activateRule(repository, rule.key()); + LOGGER.info(String.format("Rule %s added to repository %s.", rule.key(), repository)); } - LOGGER.debug(String.format("%s rules are activated.", defaultProfile.activeRules().size())); - - // Save the default profile. - defaultProfile.setDefault(true); - defaultProfile.done(); + profile.setDefault(true); + profile.done(); + LOGGER.info(String.format("%s rules are activated for the repository %s.", profile.activeRules().size(), repository)); } } \ No newline at end of file diff --git a/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java b/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java index 539b963..048c9f3 100644 --- a/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java +++ b/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java @@ -22,25 +22,42 @@ import org.sonar.api.rules.RuleType; import org.sonar.api.server.rule.RulesDefinition; +import org.sonar.api.utils.log.Logger; +import org.sonar.api.utils.log.Loggers; + import fr.cnes.sonar.plugins.icode.languages.Fortran77Language; import fr.cnes.sonar.plugins.icode.languages.Fortran90Language; import fr.cnes.sonar.plugins.icode.settings.ICodePluginProperties; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; + +import java.io.File; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.DocumentBuilder; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; +import org.w3c.dom.Node; +import org.w3c.dom.Element; /** * Specific i-Code rules definition provided by resource file. */ public class ICodeRulesDefinition implements RulesDefinition { - public static final String REPOSITORY = "f77-rules"; - public static final String FORTRAN_LANGUAGE = "f77"; - public static final RuleKey F77_DATA_ARRAY = RuleKey.of(REPOSITORY, "F77.DATA.Array"); + /** Logger for this class. **/ + private static final Logger LOGGER = Loggers.get(ICodeRulesDefinition.class); /** Partial key for repository. **/ private static final String REPO_KEY_SUFFIX = "-rules"; + public static final String FORTRAN77_LANGUAGE = Fortran77Language.KEY; + public static final String FORTRAN90_LANGUAGE = Fortran90Language.KEY; + + public static final String FORTRAN77_REPOSITORY = FORTRAN77_LANGUAGE + REPO_KEY_SUFFIX; + public static final String FORTRAN90_REPOSITORY = FORTRAN90_LANGUAGE + REPO_KEY_SUFFIX; /** Path to xml file in resources tree (fortran 77 rules). **/ public static final String PATH_TO_F77_RULES_XML = "/rules/icode-f77-rules.xml"; @@ -48,6 +65,9 @@ public class ICodeRulesDefinition implements RulesDefinition { /** Path to xml file in resources tree (fortran 90 rules). **/ public static final String PATH_TO_F90_RULES_XML = "/rules/icode-f90-rules.xml"; + public static List f77Rules; + public static List f90Rules; + /** * Define i-Code rules in SonarQube thanks to xml configuration files. * @@ -55,44 +75,69 @@ public class ICodeRulesDefinition implements RulesDefinition { */ @Override public void define(final Context context) { - // createRepository(context, Fortran77Language.KEY); - //createRepository(context, Fortran90Language.KEY); - NewRepository repository = context.createRepository(REPOSITORY, FORTRAN_LANGUAGE).setName(ICodePluginProperties.ICODE_NAME); - - NewRule f77DataArray = repository.createRule(F77_DATA_ARRAY.rule()) - .setName("F77.DATA.Array") - .setInternalKey("*") - .setHtmlDescription("Arrays dimension should be declared explicitly. The use of * is tolerated for the last one if justified with a comment.") - .setSeverity(Severity.MAJOR) - .setStatus(RuleStatus.READY) - .setType(RuleType.CODE_SMELL); - - f77DataArray.setDebtRemediationFunction(f77DataArray.debtRemediationFunctions().constantPerIssue("30min")); - - repository.done(); + this.f77Rules = createFortranRepository(context, FORTRAN77_LANGUAGE, FORTRAN77_REPOSITORY, PATH_TO_F77_RULES_XML); + this.f90Rules = createFortranRepository(context, FORTRAN90_LANGUAGE, FORTRAN90_REPOSITORY, PATH_TO_F90_RULES_XML); } - // /** - // * Create repositories for each language. - // * - // * @param context SonarQube context. - // * @param language Key of the language. - // */ - // protected void createRepository(final Context context, final String language) { - // // Create a repository to put rules inside. - // final NewRepository repository = context - // .createRepository(getRepositoryKeyForLanguage(language), language) - // .setName(getRepositoryName()); - - // // Get XML file describing rules for language. - // final InputStream rulesXml = this.getClass().getResourceAsStream(rulesDefinitionFilePath(language)); - // // Add rules in repository. - // if (rulesXml != null) { - // final RulesDefinitionXmlLoader rulesLoader = new RulesDefinitionXmlLoader(); - // rulesLoader.load(repository, rulesXml, StandardCharsets.UTF_8.name()); - // } - // repository.done(); - // } + /** + * Create repositories for each language f77 and f90 + * + * @param context SonarQube context. + * @param language Key of the language. + * @param repositoryName Key of the repository. + * @param pathToRulesXml Path to the xml file containing the rules. + */ + protected List createFortranRepository(final Context context, final String language, final String repositoryName, final String pathToRulesXml) { + // Create the repository + NewRepository repository = context.createRepository(repositoryName, language) + .setName(ICodePluginProperties.ICODE_NAME); + + List rules = new ArrayList<>(); + + try { + InputStream inputFile = this.getClass().getResourceAsStream(pathToRulesXml); + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + Document doc = dbFactory.newDocumentBuilder().parse(inputFile); + doc.getDocumentElement().normalize(); + + NodeList nodeList = doc.getElementsByTagName("rule"); + + for (int i = 0; i < nodeList.getLength(); i++) { + Node node = nodeList.item(i); + + if (node.getNodeType() == Node.ELEMENT_NODE) { + Element element = (Element) node; + + String key = element.getElementsByTagName("key").item(0).getTextContent(); + String name = element.getElementsByTagName("name").item(0).getTextContent(); + String internalKey = element.getElementsByTagName("internalKey").item(0).getTextContent(); + String description = element.getElementsByTagName("description").item(0).getTextContent(); + String severity = element.getElementsByTagName("severity").item(0).getTextContent(); + RuleStatus status = RuleStatus.valueOf(element.getElementsByTagName("status").item(0).getTextContent()); + RuleType type = RuleType.valueOf(element.getElementsByTagName("type").item(0).getTextContent()); + String remediationFunctionBaseEffort = element.getElementsByTagName("remediationFunctionBaseEffort").item(0).getTextContent(); + + RuleKey ruleKey = RuleKey.of(repositoryName, key); + + NewRule rule = repository.createRule(ruleKey.rule()) + .setName(name) + .setInternalKey(internalKey) + .setHtmlDescription(description) + .setSeverity(severity) + .setStatus(status) + .setType(type); + + rule.setDebtRemediationFunction(rule.debtRemediationFunctions().constantPerIssue(remediationFunctionBaseEffort)); + rules.add(rule); + LOGGER.info(String.format("Rule %s created.", rule.toString())); + } + } + repository.done(); + } catch (Exception e) { + e.printStackTrace(); + } + return rules; + } /** * Getter for repository key. @@ -103,26 +148,4 @@ public void define(final Context context) { public static String getRepositoryKeyForLanguage(final String language) { return language + REPO_KEY_SUFFIX; } - - /** - * Getter for the path to rules file. - * - * @param language Key of the language. - * @return A path in String format. - */ - public String rulesDefinitionFilePath(final String language) { - String path = "bad_file"; - switch (language) { - case Fortran77Language.KEY: - path = PATH_TO_F77_RULES_XML; - break; - case Fortran90Language.KEY: - path = PATH_TO_F90_RULES_XML; - break; - default: - break; - } - return path; - } -} - +} \ No newline at end of file diff --git a/src/main/resources/rules/icode-f77-rules.xml b/src/main/resources/rules/icode-f77-rules.xml index 321d6b8..f969fe4 100644 --- a/src/main/resources/rules/icode-f77-rules.xml +++ b/src/main/resources/rules/icode-f77-rules.xml @@ -14,10 +14,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: BLOCKER - SINGLE READY BUG - CONSTANT_ISSUE 30min @@ -26,10 +24,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Equality and non equality (.EQ., ==, .NE., /=) are forbidden on reals (REAL, DOUBLE PRECISION, COMPLEX). MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -38,10 +34,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Variables have to be initialized before being used. When a variable is used, the algorithm should checked if it is initialized and if not throw an error. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -50,10 +44,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Data declared into subroutine, function, ... and which are never modified then should be declared as constant. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -62,10 +54,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * It is forbidden to modify loop condition inside the loop. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -74,10 +64,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Every declared variable should be used. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -86,10 +74,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Allocation and desallocation of ressources should be in the same level. For each “DEALLOCATE” keyword found, i-Code CNES checks that the keyword “ALLOCATE” is also found and checks that they are relative to the same resource. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -98,10 +84,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * In a loop, SLEEP, WAIT and PAUSE instructions are forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -110,10 +94,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Keyword STOP is forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -122,10 +104,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * In a condition (IF,DO), maximum number of operands is 5 (AND, OR, NEQV, XOR, EQV, NOT, LT, <, LE, <=, GT, >, GE, >=, EQ, ==, NE, /=). MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -134,10 +114,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Function return values should be checked. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -146,10 +124,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * The identity of the user running the program should be checked. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -158,10 +134,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Function, procedure and method should have a unique exit point. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -170,10 +144,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Function, procedure and method should have a unique exit point. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -182,10 +154,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * File opening (OPEN, READ, WRITE) should be done after using INQUIRE and EXIST instruction of this file. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -194,10 +164,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * In the OPEN instruction, it is forbidden to use directly the file name (file.txt). Path should be defined through a variable. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -208,10 +176,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: ( a ) .NOT. ( a .AND. .NOT. b) -> .NOT. a .OR. b MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -220,10 +186,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Every expression should be braced. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -232,10 +196,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Commented code is forbidden. i-Code CNES checks all keywords in comments, except in the header. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -244,10 +206,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * "GO TO" is forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -256,10 +216,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * In a loop instruction, comparison using (.EQ., ==, .NE., \=) are forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -268,10 +226,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Variable name should be unique. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -280,10 +236,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Headers are mandatory for each module and function. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -300,10 +254,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -312,10 +264,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * A line of source code should contain 100 characters maximum. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -324,10 +274,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * In a expression (defined by operator like +, -, /, *, **) all variables should have the same type : REAL, INTEGER, … MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -336,10 +284,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * White COMMON are forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -348,10 +294,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * In an instruction IF, the last ELSE IF should be follow by ELSE. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -360,10 +304,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Parameter’s braces should be used when defining a FUNCTION whenever there is no parameter. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -372,10 +314,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Nested DO loop should have different end instructions (one for each). MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -384,10 +324,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Arrays dimension should be declared explicitly. The use of * is tolerated for the last one if justified with a comment. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -396,10 +334,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * INCLUDE must be used to declare COMMON in program units referencing it. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -408,10 +344,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * In a constant initialisation or in an expression evaluation, the use of (D) (as double precision is mandatory. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -420,10 +354,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Variable initialisation should be done using DATA or BLOCKDATA. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -432,10 +364,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Implicit logical units defined by * are forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -444,10 +374,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * DO loop condition parameter should use INTEGER. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -456,10 +384,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * The use of constants, computed values or function calls as function parameters is forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -468,10 +394,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * The check of return status for instructions OPEN and READ is mandatory. It is recommended to use “IOSTAT = “ to do it. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -480,10 +404,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * ASSIGN instruction is forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -492,10 +414,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * DIMENSION instruction is forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -504,10 +424,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * EQUIVALENCE instruction is forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -516,10 +434,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * FUNCTION instruction should be used with an explicite type declaration, at function definition. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -528,10 +444,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Arithmetic IF is forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -540,10 +454,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * If instruction INCLUDE is used, the included file should not contain executable instructions. (ASSIGN, GOTO, IF, ELSE, CONTINUE, STOP, PAUSE ; DO, READ, WRITE, PRINT, REWIND ; BACKSPACE, ENDFILE, OPEN, CLOSE, INQUIER, CALL, RETURN, END). MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -552,10 +464,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * PAUSE instruction is forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -564,10 +474,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * RETURN(i) instruction is forbidden in subprogram. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -576,10 +484,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * SAVE instruction is forbidden except for local variables with justification in a comment. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -588,10 +494,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Each line should contain less than 72 characters. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -600,10 +504,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * The use of generic names for intrinseque functions is mandatory. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -612,10 +514,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Intrinsic function names reuse is forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -624,10 +524,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Fortran 77 keywords should not be reused for variable names. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -636,10 +534,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Label usage is restricted to instruction FORMAT and CONTINUE. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -648,10 +544,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * External functions should be declared with EXTERNAL keyword. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -660,10 +554,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Logical unit should be identified with symbolic name. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -672,10 +564,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * OPEN parameters FILE, STATUS and POSITION should be defined. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -684,10 +574,9 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * It is forbidden to set as subroutine parameter variables which are already in a COMMON bloc accessible from the subroutine and the program which calls it. MAJOR - SINGLE + READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -696,10 +585,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Only standard types (INTEGER, REAL, DOUBLE PRECISION, COMPLEX, LOGICAL, CHARACTER) are allowed. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -708,10 +595,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Data and constant of type Hollerith are forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min \ No newline at end of file diff --git a/src/main/resources/rules/icode-f90-rules.xml b/src/main/resources/rules/icode-f90-rules.xml index 47da947..d7fee78 100644 --- a/src/main/resources/rules/icode-f90-rules.xml +++ b/src/main/resources/rules/icode-f90-rules.xml @@ -14,10 +14,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: BLOCKER - SINGLE READY BUG - CONSTANT_ISSUE 30min @@ -26,10 +24,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Equality and non equality (.EQ., ==, .NE., /=) are forbidden on reals (REAL, DOUBLE PRECISION, COMPLEX). MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -38,10 +34,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Variables have to be initialized before being used. When a variable is used, the algorithm should checked if it is initialized and if not throw an error. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -50,10 +44,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Data declared into subroutine, function, ... and which are never modified then should be declared as constant. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -62,10 +54,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * It is forbidden to modify loop condition inside the loop. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -74,10 +64,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Every declared variable should be used. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -86,10 +74,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Allocation and deallocation of ressources should be in the same level. For each “DEALLOCATE” keyword found, i-Code CNES checks that the keyword “ALLOCATE” is also found and checks that they are relative to the same resource. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -98,10 +84,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * In a loop, SLEEP, WAIT and PAUSE instructions are forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -110,10 +94,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Keyword STOP is forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -122,10 +104,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * In a condition (IF,DO), maximum number of operands is 5 (AND, OR, NEQV, XOR, EQV, NOT, LT, <, LE, <=, GT, >, GE, >=, EQ, ==, NE, /=). MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -134,10 +114,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Function return values should be checked. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -146,10 +124,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * The identity of the user running the program should be checked. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -158,10 +134,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Function, procedure and method should have a unique exit point. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -170,10 +144,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Function, procedure and method should have a unique exit point. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -182,10 +154,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * File opening (OPEN, READ, WRITE) should be done after using INQUIRE and EXIST instruction of this file. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -194,10 +164,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * In the OPEN instruction, it is forbidden to use directly the file name (file.txt). Path should be defined through a variable. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -208,10 +176,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: ( a ) .NOT. ( a .AND. .NOT. b) -> .NOT. a .OR. b MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -220,10 +186,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Every expression should be braced. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -232,10 +196,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Commented code is forbidden. i-Code CNES checks all keywords in comments, except in the header. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -244,10 +206,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * "GO TO" is forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -256,10 +216,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * In a loop instruction, comparison using (.EQ., ==, .NE., \=) are forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -268,10 +226,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Variable name should be unique. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -280,10 +236,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Headers are mandatory for each module and function. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -300,10 +254,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -312,10 +264,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * A line of source code should contain 100 characters maximum. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -324,10 +274,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * In a expression (defined by operator like +, -, /, *, **) all variables should have the same type : REAL, INTEGER, … MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -336,10 +284,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * SWITCH instruction should define the DEFAULT case as last one. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -348,10 +294,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Each line should be limited to only one expression. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -360,10 +304,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Recursion is forbidden. In Fortran, i-Code CNES checks that "RECURSIVE FUNCTION(params)" is not found. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -372,10 +314,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Every open file should be closed. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -384,10 +324,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Array dimensions should be respected. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -396,10 +334,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * In an array of indirections, it is not possible to define the same item several times. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -408,10 +344,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Constants which appear in several subprograms should be defined into a module. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -420,10 +354,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Numerical constants (see above) should be followed by subtype parameter. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -433,10 +365,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: The use of IMPLICIT NONE instruction is mandatory for each method header. Limitations : this rule is not checked for function and array. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -445,10 +375,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * It is forbidden to use * output format (WRITE instruction) for REAL. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -457,10 +385,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Functions SELECTED_REAL_KIND and SELECTED_INT_KIND should be grouped in the same module. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -469,10 +395,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Allocated memory should be free in the same conceptual level. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -481,10 +405,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * File inclusion is forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -493,10 +415,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Modules should only contains USE, PRIVATE and PUBLIC clauses. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -505,10 +425,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * In an OPEN function, units number should depend on another function or array. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -527,10 +445,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -539,10 +455,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Allocation and deallocation should contain “STAT” parameter. Then, « STAT » value should be tested. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -551,10 +465,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * OPEN and READ instructions, which work on files, should contain IOSTAT parameter and check this variable value. To check this, OPEN instruction should contain FILE attribute. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -563,10 +475,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Between declaration and ASSOCIATED instruction, it is mandatory to call NULLIFY. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -575,10 +485,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * ENTRY instruction is forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -587,10 +495,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * EQUIVALENCE instruction is forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -599,10 +505,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * IF followed by one of these instructions : EXIT, GOTO, CYCLE, RETURN is forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -611,10 +515,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Each subprogram parameter should be declared with INTENT keyword. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -623,10 +525,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * After deallocate, the use of NULLIFY into the same logical unit is mandatory. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -635,10 +535,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * The use of keyword ONLY without comment is forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -647,10 +545,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Do not use old notation. Replace .EQ., .NE., .LT., .LE., .GT., .GE. by ==, /=, <, <=, >, >=. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -662,10 +558,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -676,10 +570,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -688,10 +580,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Fortran keywords should not be used as variable names. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -700,10 +590,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Overriding operators is forbidden. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -712,10 +600,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * The use of a whole array should be represented using the notation (:). MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -724,10 +610,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Called subprogram should be visible. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -736,10 +620,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * END keyword should be followed by the type (function, subroutine…) and the name. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -748,10 +630,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Every OPEN instruction should have parameters FILE, STATUS, IOSTAT and POSITION. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -760,10 +640,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * A variable should be referenced with the same name in subprogram. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -772,10 +650,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * Every type declaration should be placed into a module. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -784,10 +660,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * INTEGER parameters should be followed by SELECTED_INT_KIND expression. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min @@ -796,10 +670,8 @@ Please, report this error to i-Code CNES maintainers to improve the tool: * REAL parameters should be followed by SELECTED_REAL_KIND. MAJOR - SINGLE READY CODE_SMELL - CONSTANT_ISSUE 30min \ No newline at end of file From abddcfb4925a0132a2b6f13923e469ceeea0ca2d Mon Sep 17 00:00:00 2001 From: Diego Rodriguez Date: Tue, 18 Jul 2023 19:05:46 +0200 Subject: [PATCH 08/17] Update jacoco version for handling the tests that are run with latest Java version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index eff37bd..4b8106f 100644 --- a/pom.xml +++ b/pom.xml @@ -69,7 +69,7 @@ 2.8.2 1.7.25 4.13.2 - 0.8.4 + 0.8.10 icode fr.cnes.sonar.plugins.icode.ICodePlugin https://github.com/cnescatlab/sonar-icode-cnes-plugin From a4da7f4c0940f8d29f87ef2f00f0eab447b88b22 Mon Sep 17 00:00:00 2001 From: Diego Rodriguez Date: Wed, 19 Jul 2023 11:41:33 +0200 Subject: [PATCH 09/17] Change tests implementation to fit with SQ 9 and adapt some new rules names and remove some shell treatments --- pom.xml | 5 ++ .../plugins/icode/check/ICodeSensor.java | 2 +- .../icode/measures/ICodeMetricsProcessor.java | 6 +- .../icode/rules/ICodeRulesDefinition.java | 6 ++ .../plugins/icode/check/ICodeSensorTest.java | 11 +-- .../languages/ICodeQualityProfilesTest.java | 7 +- .../measures/ICodeMetricsProcessorTest.java | 88 ++++++------------- .../icode/rules/ICodeRulesDefinitionTest.java | 26 +++--- 8 files changed, 63 insertions(+), 88 deletions(-) diff --git a/pom.xml b/pom.xml index 4b8106f..8379ae8 100644 --- a/pom.xml +++ b/pom.xml @@ -132,6 +132,11 @@ xstream 1.4.18 + + org.sonarsource.sonarqube + sonar-plugin-api-impl + 9.9.1.69595 + diff --git a/src/main/java/fr/cnes/sonar/plugins/icode/check/ICodeSensor.java b/src/main/java/fr/cnes/sonar/plugins/icode/check/ICodeSensor.java index d414e04..42fb7a1 100644 --- a/src/main/java/fr/cnes/sonar/plugins/icode/check/ICodeSensor.java +++ b/src/main/java/fr/cnes/sonar/plugins/icode/check/ICodeSensor.java @@ -338,7 +338,7 @@ protected Map getScannedFiles(final FileSystem fileSystem, fi for(final AnalysisFile file : files) { // Checks if the file system contains a file with corresponding path (relative or absolute). final String fileToFind = new File(fileSystem.baseDir(), file.getFileName()).getPath(); - final FilePredicate predicate = fileSystem.predicates().hasRelativePath(fileToFind); + final FilePredicate predicate = fileSystem.predicates().hasPath(fileToFind); final InputFile inputFile = fileSystem.inputFile(predicate); if(inputFile!=null) { result.put(file.getFileName(), inputFile); diff --git a/src/main/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessor.java b/src/main/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessor.java index 6851bfe..52f8f59 100644 --- a/src/main/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessor.java +++ b/src/main/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessor.java @@ -79,11 +79,11 @@ public static void saveMeasure(final SensorContext context, final Map { - if(x.contains(".MET.LineOfCode")) { + if(x.contains(".MET.Line")) { rawMeasures.addAll(y); } }); diff --git a/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java b/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java index 048c9f3..0b32e9e 100644 --- a/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java +++ b/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java @@ -96,6 +96,12 @@ protected List createFortranRepository(final Context context, final Str try { InputStream inputFile = this.getClass().getResourceAsStream(pathToRulesXml); + + if (inputFile == null) { + repository.done(); + return rules; + } + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); Document doc = dbFactory.newDocumentBuilder().parse(inputFile); doc.getDocumentElement().normalize(); diff --git a/src/test/java/fr/cnes/sonar/plugins/icode/check/ICodeSensorTest.java b/src/test/java/fr/cnes/sonar/plugins/icode/check/ICodeSensorTest.java index 246b970..8bb0357 100644 --- a/src/test/java/fr/cnes/sonar/plugins/icode/check/ICodeSensorTest.java +++ b/src/test/java/fr/cnes/sonar/plugins/icode/check/ICodeSensorTest.java @@ -29,6 +29,7 @@ import org.mockito.Mockito; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultFileSystem; +import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.sensor.SensorDescriptor; @@ -58,10 +59,8 @@ public class ICodeSensorTest { public void prepare() throws URISyntaxException { fs = new DefaultFileSystem(new File(getClass().getResource("/project").toURI())); fs.setEncoding(StandardCharsets.UTF_8); - - clanhb_f = TestInputFileBuilder.create( - "ProjectKey", - fs.resolvePath("clanhb.f").getPath()) + + clanhb_f = TestInputFileBuilder.create("ProjectKey", fs.baseDir(), new File(getClass().getResource("/project/clanhb.f").toURI())) .setLanguage("icode") .setType(InputFile.Type.MAIN) .setLines(10) @@ -70,9 +69,7 @@ public void prepare() throws URISyntaxException { .build(); fs.add(clanhb_f); - clanhb_f90 = TestInputFileBuilder.create( - "ProjectKey", - fs.resolvePath("clanhb.f90").getPath()) + clanhb_f90 = TestInputFileBuilder.create("ProjectKey", fs.baseDir(), new File(getClass().getResource("/project/clanhb.f90").toURI())) .setLanguage("icode") .setType(InputFile.Type.MAIN) .setLines(10) diff --git a/src/test/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfilesTest.java b/src/test/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfilesTest.java index a1464fa..c7e9bab 100644 --- a/src/test/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfilesTest.java +++ b/src/test/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfilesTest.java @@ -19,16 +19,21 @@ import org.junit.Assert; import org.junit.Test; import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; +import org.sonar.api.server.rule.RulesDefinition; +import fr.cnes.sonar.plugins.icode.rules.ICodeRulesDefinition; public class ICodeQualityProfilesTest { @Test public void test_should_create_sonar_way_profile() { ICodeQualityProfiles profileDef = new ICodeQualityProfiles(); + + RulesDefinition.Context contextRules = new RulesDefinition.Context(); + new ICodeRulesDefinition().define(contextRules); + BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); profileDef.define(context); Assert.assertNotNull(profileDef); Assert.assertEquals(2, context.profilesByLanguageAndName().keySet().size()); } - } diff --git a/src/test/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessorTest.java b/src/test/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessorTest.java index 128af63..8b49b82 100644 --- a/src/test/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessorTest.java +++ b/src/test/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessorTest.java @@ -45,36 +45,36 @@ public class ICodeMetricsProcessorTest { private Map files; private AnalysisRule rule; - private DefaultInputFile bash_sh; private DefaultInputFile clanhb_f; + private DefaultInputFile clanhb_f90; @Before public void prepare() throws URISyntaxException { - final URI projectPath = ICodeMetricsProcessor.class.getResource("/project/").toURI(); + final URI projectPath = ICodeMetricsProcessor.class.getResource("/project").toURI(); fs = new DefaultFileSystem(new File(projectPath)); fs.setEncoding(Charset.forName("UTF-8")); - bash_sh = TestInputFileBuilder.create( + clanhb_f = TestInputFileBuilder.create( "ProjectKey", - fs.resolvePath(projectPath.getRawPath()+"bash.sh").getPath()) + fs.baseDir(), new File(getClass().getResource("/project/clanhb.f").toURI())) .setLanguage("icode") .setType(InputFile.Type.MAIN) .build(); - fs.add(bash_sh); - clanhb_f = TestInputFileBuilder.create( - "ProjectKey", - fs.resolvePath(projectPath.getRawPath()+"clanhb.f").getPath()) + fs.add(clanhb_f); + + clanhb_f90 = TestInputFileBuilder.create("ProjectKey", fs.baseDir(), new File(getClass().getResource("/project/clanhb.f90").toURI())) .setLanguage("icode") .setType(InputFile.Type.MAIN) .build(); - fs.add(clanhb_f); + fs.add(clanhb_f90); + context = SensorContextTester.create(fs.baseDir()); files = new HashMap<>(); rule = new AnalysisRule(); - files.put("bash.sh", bash_sh); files.put("clanhb.f", clanhb_f); + files.put("clanhb.f90", clanhb_f90); } @Test @@ -89,23 +89,18 @@ public void test_is_metric_false() { @Test public void test_save_nominal_measures() { - String[] analysisRulesIds = {"SH.MET.LineOfCode","SH.MET.LineOfComment","F90.MET.Nesting","F90.MET.LineOfCode"}; - String[] fileNames = {"bash.sh", "bash.sh", "bash.sh", "zoulou.sh"}; - int[] expectedResults = {1,2,2,2}; // Size is incremented as context.measure(key) is not resetted after each iteration - - for(int i=0;i Date: Fri, 21 Jul 2023 10:04:48 +0200 Subject: [PATCH 10/17] Fix bugs and code smells --- .../icode/languages/ICodeQualityProfiles.java | 10 +- .../icode/measures/ICodeMetricsProcessor.java | 5 +- .../icode/rules/ICodeRulesDefinition.java | 33 +++--- .../measures/ICodeMetricsProcessorTest.java | 108 +++++++++--------- 4 files changed, 76 insertions(+), 80 deletions(-) diff --git a/src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java b/src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java index 5c4a719..1a38c0e 100644 --- a/src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java +++ b/src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java @@ -16,20 +16,14 @@ */ package fr.cnes.sonar.plugins.icode.languages; -import fr.cnes.sonar.plugins.icode.model.Rule; -import fr.cnes.sonar.plugins.icode.model.RulesDefinition; -import fr.cnes.sonar.plugins.icode.model.XmlHandler; import fr.cnes.sonar.plugins.icode.rules.ICodeRulesDefinition; import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.api.server.rule.RulesDefinition.NewRule; -import java.util.ArrayList; import java.util.List; -import java.io.InputStream; - /** * Built-in quality profile format since SonarQube 9.9 */ @@ -48,8 +42,8 @@ public final class ICodeQualityProfiles implements BuiltInQualityProfilesDefinit */ @Override public void define(final Context context) { - createBuiltInProfile(context, ICodeRulesDefinition.FORTRAN77_REPOSITORY, Fortran77Language.KEY, ICodeRulesDefinition.f77Rules); - createBuiltInProfile(context, ICodeRulesDefinition.FORTRAN90_REPOSITORY, Fortran90Language.KEY, ICodeRulesDefinition.f90Rules); + createBuiltInProfile(context, ICodeRulesDefinition.FORTRAN77_REPOSITORY, Fortran77Language.KEY, ICodeRulesDefinition.getF77Rules()); + createBuiltInProfile(context, ICodeRulesDefinition.FORTRAN90_REPOSITORY, Fortran90Language.KEY, ICodeRulesDefinition.getF90Rules()); } /** diff --git a/src/main/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessor.java b/src/main/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessor.java index 52f8f59..23383d5 100644 --- a/src/main/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessor.java +++ b/src/main/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessor.java @@ -78,12 +78,9 @@ public static void saveMeasure(final SensorContext context, final Map f77Rules; - public static List f90Rules; + private static List f77Rules; + private static List f90Rules; /** * Define i-Code rules in SonarQube thanks to xml configuration files. @@ -103,6 +99,7 @@ protected List createFortranRepository(final Context context, final Str } DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + dbFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); Document doc = dbFactory.newDocumentBuilder().parse(inputFile); doc.getDocumentElement().normalize(); @@ -115,15 +112,15 @@ protected List createFortranRepository(final Context context, final Str Element element = (Element) node; String key = element.getElementsByTagName("key").item(0).getTextContent(); - String name = element.getElementsByTagName("name").item(0).getTextContent(); - String internalKey = element.getElementsByTagName("internalKey").item(0).getTextContent(); - String description = element.getElementsByTagName("description").item(0).getTextContent(); - String severity = element.getElementsByTagName("severity").item(0).getTextContent(); - RuleStatus status = RuleStatus.valueOf(element.getElementsByTagName("status").item(0).getTextContent()); - RuleType type = RuleType.valueOf(element.getElementsByTagName("type").item(0).getTextContent()); + String name = element.getElementsByTagName("name").item(0).getTextContent(); + String internalKey = element.getElementsByTagName("internalKey").item(0).getTextContent(); + String description = element.getElementsByTagName("description").item(0).getTextContent(); + String severity = element.getElementsByTagName("severity").item(0).getTextContent(); + RuleStatus status = RuleStatus.valueOf(element.getElementsByTagName("status").item(0).getTextContent()); + RuleType type = RuleType.valueOf(element.getElementsByTagName("type").item(0).getTextContent()); String remediationFunctionBaseEffort = element.getElementsByTagName("remediationFunctionBaseEffort").item(0).getTextContent(); - RuleKey ruleKey = RuleKey.of(repositoryName, key); + RuleKey ruleKey = RuleKey.of(repositoryName, key); NewRule rule = repository.createRule(ruleKey.rule()) .setName(name) @@ -140,7 +137,7 @@ protected List createFortranRepository(final Context context, final Str } repository.done(); } catch (Exception e) { - e.printStackTrace(); + LOGGER.error("Error while creating rules.", e); } return rules; } @@ -154,4 +151,12 @@ protected List createFortranRepository(final Context context, final Str public static String getRepositoryKeyForLanguage(final String language) { return language + REPO_KEY_SUFFIX; } + + public static List getF77Rules() { + return f77Rules; + } + + public static List getF90Rules() { + return f90Rules; + } } \ No newline at end of file diff --git a/src/test/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessorTest.java b/src/test/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessorTest.java index 8b49b82..0a77ae0 100644 --- a/src/test/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessorTest.java +++ b/src/test/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessorTest.java @@ -22,7 +22,12 @@ import fr.cnes.sonar.plugins.icode.model.Result; import org.junit.Assert; import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.Arguments; + +import java.util.stream.Stream; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultFileSystem; import org.sonar.api.batch.fs.internal.DefaultInputFile; @@ -77,52 +82,45 @@ public void prepare() throws URISyntaxException { files.put("clanhb.f90", clanhb_f90); } - @Test - public void test_is_metric_true() { - Assert.assertTrue(ICodeMetricsProcessor.isMetric("SH.MET.COCO")); - } - - @Test - public void test_is_metric_false() { - Assert.assertFalse(ICodeMetricsProcessor.isMetric("COCO")); + private static Stream testData() { + return Stream.of( + Arguments.of(new AnalysisRuleTestData("F77.MET.ComplexitySimplified", "clanhb.f", "3")), + Arguments.of(new AnalysisRuleTestData("F77.MET.Nesting", "clanhb.f", "3")), + Arguments.of(new AnalysisRuleTestData("F77.MET.Line", "clanhb.f", "3")) + ); } - @Test - public void test_save_nominal_measures() { - - final String key = clanhb_f.key(); - rule.setResult(new Result()); - rule.setAnalysisRuleId("F77.MET.Line"); - rule.getResult().setFileName("clanhb.f"); - rule.getResult().setResultValue("3"); - rule.getResult().setResultLine("3"); - rule.getResult().setResultTypePlace("class"); - rule.getResult().setResultMessage("Small file"); - - ICodeMetricsProcessor.saveMeasure(context, files, rule); - Assert.assertEquals(1, context.measures(key).size()); - } - - @Test - public void test_compute_complexity() { - + @ParameterizedTest + @MethodSource("testData") + public void test_compute_metrics(AnalysisRuleTestData testData) { final AnalysisProject project = new AnalysisProject(); final String key = clanhb_f.key(); rule.setResult(new Result()); - rule.setAnalysisRuleId("F77.MET.ComplexitySimplified"); - rule.getResult().setFileName("clanhb.f"); - rule.getResult().setResultValue("3"); - rule.getResult().setResultLine("3"); + rule.setAnalysisRuleId(testData.getAnalysisRuleId()); + rule.getResult().setFileName(testData.getFileName()); + rule.getResult().setResultValue(testData.getResultValue()); + rule.getResult().setResultLine("3"); // Assuming the result line is always "3" rule.getResult().setResultTypePlace("method"); rule.getResult().setResultMessage("Small file"); project.setAnalysisRule(new AnalysisRule[]{rule}); ICodeMetricsProcessor.saveExtraMeasures(context, files, project); + Assert.assertEquals(1, context.measures(key).size()); } + @Test + public void test_is_metric_true() { + Assert.assertTrue(ICodeMetricsProcessor.isMetric("SH.MET.COCO")); + } + + @Test + public void test_is_metric_false() { + Assert.assertFalse(ICodeMetricsProcessor.isMetric("COCO")); + } + @Test public void test_save_extra_measure_with_null_location() { // If we upgrade to Junit5, we may check @ParametrizedTest annotation @@ -145,42 +143,44 @@ public void test_save_extra_measure_with_null_location() { } @Test - public void test_compute_nesting() { + public void test_save_nominal_measures() { - final AnalysisProject project = new AnalysisProject(); final String key = clanhb_f.key(); - rule.setResult(new Result()); - rule.setAnalysisRuleId("F77.MET.Nesting"); + rule.setAnalysisRuleId("F77.MET.Line"); rule.getResult().setFileName("clanhb.f"); rule.getResult().setResultValue("3"); rule.getResult().setResultLine("3"); - rule.getResult().setResultTypePlace("method"); + rule.getResult().setResultTypePlace("class"); rule.getResult().setResultMessage("Small file"); - project.setAnalysisRule(new AnalysisRule[]{rule}); - - ICodeMetricsProcessor.saveExtraMeasures(context, files, project); + ICodeMetricsProcessor.saveMeasure(context, files, rule); Assert.assertEquals(1, context.measures(key).size()); } + +} - @Test - public void test_compute_functions() { +class AnalysisRuleTestData { + private String analysisRuleId; + private String fileName; + private String resultValue; - final AnalysisProject project = new AnalysisProject(); - final String key = clanhb_f.key(); + public AnalysisRuleTestData(String analysisRuleId, String fileName, String resultValue) { + this.analysisRuleId = analysisRuleId; + this.fileName = fileName; + this.resultValue = resultValue; + } - rule.setResult(new Result()); - rule.setAnalysisRuleId("F77.MET.Line"); - rule.getResult().setFileName("clanhb.f"); - rule.getResult().setResultValue("3"); - rule.getResult().setResultLine("3"); - rule.getResult().setResultTypePlace("method"); - rule.getResult().setResultMessage("Small file"); + public String getAnalysisRuleId() { + return analysisRuleId; + } - project.setAnalysisRule(new AnalysisRule[]{rule}); + public String getFileName() { + return fileName; + } - ICodeMetricsProcessor.saveExtraMeasures(context, files, project); - Assert.assertEquals(1, context.measures(key).size()); + public String getResultValue() { + return resultValue; } + } From 728ca1ecd22d32c34630e8b6614a32cdb282d461 Mon Sep 17 00:00:00 2001 From: Diego Rodriguez Date: Fri, 21 Jul 2023 10:16:50 +0200 Subject: [PATCH 11/17] Fix bugs and code smells --- .../icode/languages/ICodeQualityProfiles.java | 4 ++-- .../icode/rules/ICodeRulesDefinition.java | 12 ++---------- .../measures/ICodeMetricsProcessorTest.java | 16 ++++++++-------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java b/src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java index 1a38c0e..1580e75 100644 --- a/src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java +++ b/src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java @@ -42,8 +42,8 @@ public final class ICodeQualityProfiles implements BuiltInQualityProfilesDefinit */ @Override public void define(final Context context) { - createBuiltInProfile(context, ICodeRulesDefinition.FORTRAN77_REPOSITORY, Fortran77Language.KEY, ICodeRulesDefinition.getF77Rules()); - createBuiltInProfile(context, ICodeRulesDefinition.FORTRAN90_REPOSITORY, Fortran90Language.KEY, ICodeRulesDefinition.getF90Rules()); + createBuiltInProfile(context, ICodeRulesDefinition.FORTRAN77_REPOSITORY, Fortran77Language.KEY, ICodeRulesDefinition.f77Rules); + createBuiltInProfile(context, ICodeRulesDefinition.FORTRAN90_REPOSITORY, Fortran90Language.KEY, ICodeRulesDefinition.f90Rules); } /** diff --git a/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java b/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java index a5deaec..632c3ae 100644 --- a/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java +++ b/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java @@ -61,8 +61,8 @@ public class ICodeRulesDefinition implements RulesDefinition { /** Path to xml file in resources tree (fortran 90 rules). **/ public static final String PATH_TO_F90_RULES_XML = "/rules/icode-f90-rules.xml"; - private static List f77Rules; - private static List f90Rules; + public static List f77Rules; + public static List f90Rules; /** * Define i-Code rules in SonarQube thanks to xml configuration files. @@ -151,12 +151,4 @@ protected List createFortranRepository(final Context context, final Str public static String getRepositoryKeyForLanguage(final String language) { return language + REPO_KEY_SUFFIX; } - - public static List getF77Rules() { - return f77Rules; - } - - public static List getF90Rules() { - return f90Rules; - } } \ No newline at end of file diff --git a/src/test/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessorTest.java b/src/test/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessorTest.java index 0a77ae0..91aef77 100644 --- a/src/test/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessorTest.java +++ b/src/test/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessorTest.java @@ -21,7 +21,7 @@ import fr.cnes.sonar.plugins.icode.model.AnalysisRule; import fr.cnes.sonar.plugins.icode.model.Result; import org.junit.Assert; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -43,7 +43,7 @@ import java.util.List; import java.util.Map; -public class ICodeMetricsProcessorTest { +class ICodeMetricsProcessorTest { private DefaultFileSystem fs; private SensorContextTester context; @@ -53,7 +53,7 @@ public class ICodeMetricsProcessorTest { private DefaultInputFile clanhb_f; private DefaultInputFile clanhb_f90; - @Before + @BeforeEach public void prepare() throws URISyntaxException { final URI projectPath = ICodeMetricsProcessor.class.getResource("/project").toURI(); fs = new DefaultFileSystem(new File(projectPath)); @@ -92,7 +92,7 @@ private static Stream testData() { @ParameterizedTest @MethodSource("testData") - public void test_compute_metrics(AnalysisRuleTestData testData) { + void test_compute_metrics(AnalysisRuleTestData testData) { final AnalysisProject project = new AnalysisProject(); final String key = clanhb_f.key(); @@ -112,17 +112,17 @@ public void test_compute_metrics(AnalysisRuleTestData testData) { } @Test - public void test_is_metric_true() { + void test_is_metric_true() { Assert.assertTrue(ICodeMetricsProcessor.isMetric("SH.MET.COCO")); } @Test - public void test_is_metric_false() { + void test_is_metric_false() { Assert.assertFalse(ICodeMetricsProcessor.isMetric("COCO")); } @Test - public void test_save_extra_measure_with_null_location() { + void test_save_extra_measure_with_null_location() { // If we upgrade to Junit5, we may check @ParametrizedTest annotation String[] locations = {null, "", "method"}; int[] expectedResults = {0, 0, 1}; @@ -143,7 +143,7 @@ public void test_save_extra_measure_with_null_location() { } @Test - public void test_save_nominal_measures() { + void test_save_nominal_measures() { final String key = clanhb_f.key(); rule.setResult(new Result()); From 12952f092af7d05baa12622e79b6817719a70f70 Mon Sep 17 00:00:00 2001 From: Diego Rodriguez Date: Fri, 21 Jul 2023 10:30:39 +0200 Subject: [PATCH 12/17] Fix static issues with list of fortran rules --- .../icode/rules/ICodeRulesDefinition.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java b/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java index 632c3ae..3a08908 100644 --- a/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java +++ b/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java @@ -71,8 +71,8 @@ public class ICodeRulesDefinition implements RulesDefinition { */ @Override public void define(final Context context) { - this.f77Rules = createFortranRepository(context, FORTRAN77_LANGUAGE, FORTRAN77_REPOSITORY, PATH_TO_F77_RULES_XML); - this.f90Rules = createFortranRepository(context, FORTRAN90_LANGUAGE, FORTRAN90_REPOSITORY, PATH_TO_F90_RULES_XML); + createFortranRepository(context, FORTRAN77_LANGUAGE, FORTRAN77_REPOSITORY, PATH_TO_F77_RULES_XML); + createFortranRepository(context, FORTRAN90_LANGUAGE, FORTRAN90_REPOSITORY, PATH_TO_F90_RULES_XML); } /** @@ -83,7 +83,7 @@ public void define(final Context context) { * @param repositoryName Key of the repository. * @param pathToRulesXml Path to the xml file containing the rules. */ - protected List createFortranRepository(final Context context, final String language, final String repositoryName, final String pathToRulesXml) { + protected void createFortranRepository(final Context context, final String language, final String repositoryName, final String pathToRulesXml) { // Create the repository NewRepository repository = context.createRepository(repositoryName, language) .setName(ICodePluginProperties.ICODE_NAME); @@ -95,7 +95,11 @@ protected List createFortranRepository(final Context context, final Str if (inputFile == null) { repository.done(); - return rules; + if (language == FORTRAN77_LANGUAGE) { + ICodeRulesDefinition.f77Rules = rules; + } else { + ICodeRulesDefinition.f90Rules = rules; + } } DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); @@ -139,7 +143,11 @@ protected List createFortranRepository(final Context context, final Str } catch (Exception e) { LOGGER.error("Error while creating rules.", e); } - return rules; + if (language == FORTRAN77_LANGUAGE) { + ICodeRulesDefinition.f77Rules = rules; + } else { + ICodeRulesDefinition.f90Rules = rules; + } } /** From e7fa8a2507225bdc969b3368ff29d145cbcfed0e Mon Sep 17 00:00:00 2001 From: Diego Rodriguez Date: Fri, 21 Jul 2023 12:26:05 +0200 Subject: [PATCH 13/17] Refactoring of the rules storing --- .../icode/languages/ICodeQualityProfiles.java | 9 ++++- .../icode/rules/ICodeRulesDefinition.java | 19 +++++---- .../plugins/icode/rules/RulesRepository.java | 40 +++++++++++++++++++ 3 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 src/main/java/fr/cnes/sonar/plugins/icode/rules/RulesRepository.java diff --git a/src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java b/src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java index 1580e75..bb68283 100644 --- a/src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java +++ b/src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java @@ -17,6 +17,8 @@ package fr.cnes.sonar.plugins.icode.languages; import fr.cnes.sonar.plugins.icode.rules.ICodeRulesDefinition; +import fr.cnes.sonar.plugins.icode.rules.RulesRepository; + import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; @@ -35,6 +37,9 @@ public final class ICodeQualityProfiles implements BuiltInQualityProfilesDefinit /** Display name for the built-in quality profile. **/ private static final String I_CODE_RULES_PROFILE_NAME = "Sonar way"; + private List f77Rules = RulesRepository.getInstance().getF77Rules(); + private List f90Rules = RulesRepository.getInstance().getF90Rules(); + /** * Allow to create a plugin. * @@ -42,8 +47,8 @@ public final class ICodeQualityProfiles implements BuiltInQualityProfilesDefinit */ @Override public void define(final Context context) { - createBuiltInProfile(context, ICodeRulesDefinition.FORTRAN77_REPOSITORY, Fortran77Language.KEY, ICodeRulesDefinition.f77Rules); - createBuiltInProfile(context, ICodeRulesDefinition.FORTRAN90_REPOSITORY, Fortran90Language.KEY, ICodeRulesDefinition.f90Rules); + createBuiltInProfile(context, ICodeRulesDefinition.FORTRAN77_REPOSITORY, Fortran77Language.KEY, f77Rules); + createBuiltInProfile(context, ICodeRulesDefinition.FORTRAN90_REPOSITORY, Fortran90Language.KEY, f90Rules); } /** diff --git a/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java b/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java index 3a08908..cd8d5b4 100644 --- a/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java +++ b/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java @@ -27,6 +27,7 @@ import fr.cnes.sonar.plugins.icode.languages.Fortran77Language; import fr.cnes.sonar.plugins.icode.languages.Fortran90Language; import fr.cnes.sonar.plugins.icode.settings.ICodePluginProperties; +import fr.cnes.sonar.plugins.icode.rules.RulesRepository; import java.io.InputStream; import java.util.ArrayList; @@ -61,9 +62,6 @@ public class ICodeRulesDefinition implements RulesDefinition { /** Path to xml file in resources tree (fortran 90 rules). **/ public static final String PATH_TO_F90_RULES_XML = "/rules/icode-f90-rules.xml"; - public static List f77Rules; - public static List f90Rules; - /** * Define i-Code rules in SonarQube thanks to xml configuration files. * @@ -95,11 +93,12 @@ protected void createFortranRepository(final Context context, final String langu if (inputFile == null) { repository.done(); - if (language == FORTRAN77_LANGUAGE) { - ICodeRulesDefinition.f77Rules = rules; + if (language.equals(FORTRAN77_LANGUAGE)) { + RulesRepository.getInstance().setF77Rules(rules); } else { - ICodeRulesDefinition.f90Rules = rules; + RulesRepository.getInstance().setF90Rules(rules); } + } DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); @@ -143,11 +142,11 @@ protected void createFortranRepository(final Context context, final String langu } catch (Exception e) { LOGGER.error("Error while creating rules.", e); } - if (language == FORTRAN77_LANGUAGE) { - ICodeRulesDefinition.f77Rules = rules; + if (language.equals(FORTRAN77_LANGUAGE)) { + RulesRepository.getInstance().setF77Rules(rules); } else { - ICodeRulesDefinition.f90Rules = rules; - } + RulesRepository.getInstance().setF90Rules(rules); + } } /** diff --git a/src/main/java/fr/cnes/sonar/plugins/icode/rules/RulesRepository.java b/src/main/java/fr/cnes/sonar/plugins/icode/rules/RulesRepository.java new file mode 100644 index 0000000..fef38f0 --- /dev/null +++ b/src/main/java/fr/cnes/sonar/plugins/icode/rules/RulesRepository.java @@ -0,0 +1,40 @@ +package fr.cnes.sonar.plugins.icode.rules; + +import java.util.List; +import java.util.ArrayList; +import org.sonar.api.server.rule.RulesDefinition.NewRule; + +public class RulesRepository { + private static RulesRepository instance = null; + + private List f77Rules; + private List f90Rules; + + private RulesRepository() { + this.f77Rules = new ArrayList<>(); + this.f90Rules = new ArrayList<>(); + } + + public static RulesRepository getInstance() { + if (instance == null) { + instance = new RulesRepository(); + } + return instance; + } + + public List getF77Rules() { + return f77Rules; + } + + public List getF90Rules() { + return f90Rules; + } + + public void setF77Rules(List f77Rules) { + this.f77Rules = f77Rules; + } + + public void setF90Rules(List f90Rules) { + this.f90Rules = f90Rules; + } +} From 89c25b839d665586d5ec18accce776bc8a724fb2 Mon Sep 17 00:00:00 2001 From: Diego Rodriguez Date: Fri, 21 Jul 2023 12:29:19 +0200 Subject: [PATCH 14/17] Remove useless import --- .../fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java b/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java index cd8d5b4..217ab7c 100644 --- a/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java +++ b/src/main/java/fr/cnes/sonar/plugins/icode/rules/ICodeRulesDefinition.java @@ -27,7 +27,6 @@ import fr.cnes.sonar.plugins.icode.languages.Fortran77Language; import fr.cnes.sonar.plugins.icode.languages.Fortran90Language; import fr.cnes.sonar.plugins.icode.settings.ICodePluginProperties; -import fr.cnes.sonar.plugins.icode.rules.RulesRepository; import java.io.InputStream; import java.util.ArrayList; From eabf1827bca1bb1d749116981d1bcc71c5785eee Mon Sep 17 00:00:00 2001 From: Diego Rodriguez Date: Tue, 25 Jul 2023 06:25:34 +0000 Subject: [PATCH 15/17] Change readme and remove a duplicated dependency --- README.md | 1 + pom.xml | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index 7db5257..f0c4ddc 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Here is the compatibility matrix of the plugin: | 2.0.3 | 4.1.2 | 7.9 -> 8.2 | Fortran / Shell | | 3.0.0 | 4.1.0 | 7.9 -> 8.2 | Fortran | | 3.0.1 | 4.1.2 | 7.9 -> 8.2 | Fortran | +| 3.1.0 | 4.1.2 | 7.9 -> 9.9 | Fortran | #### Run i-Code manually If you need help to run i-Code please refer to the [official user manual](https://github.com/cnescatlab/i-CodeCNES/wiki/User-Manual) or [i-Code issue tracker](https://github.com/cnescatlab/i-CodeCNES/issues). diff --git a/pom.xml b/pom.xml index 8379ae8..4b8106f 100644 --- a/pom.xml +++ b/pom.xml @@ -132,11 +132,6 @@ xstream 1.4.18 - - org.sonarsource.sonarqube - sonar-plugin-api-impl - 9.9.1.69595 - From 42bbb08b811064c5ce1e4b575a12c376248b075e Mon Sep 17 00:00:00 2001 From: Diego Rodriguez Date: Tue, 25 Jul 2023 06:28:11 +0000 Subject: [PATCH 16/17] Add version in properties --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4b8106f..25ec22f 100644 --- a/pom.xml +++ b/pom.xml @@ -63,6 +63,7 @@ 1.8 9.8.0.203 9.5.0.56709 + 9.9.1.69595 2.6.1 1.21.0.505 3.7 @@ -113,7 +114,7 @@ org.sonarsource.sonarqube sonar-plugin-api-impl - 9.9.1.69595 + ${sonar.apiImplVersion} junit From a28d74b4b83d70273009257f10553d14645a6a30 Mon Sep 17 00:00:00 2001 From: Diego Rodriguez <63045276+diegorodriguez31@users.noreply.github.com> Date: Sat, 29 Jul 2023 16:15:54 +0200 Subject: [PATCH 17/17] Update pom.xml Fix typo --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 25ec22f..c885d2e 100644 --- a/pom.xml +++ b/pom.xml @@ -49,8 +49,8 @@ Diego Rodriguez CNES - https://github.com/WaldoFR - WaldoFR + https://github.com/diegorodriguez31 + diegorodriguez31