From 2421d1c81b17c23c744a4089eb6122bb9f72a1fb Mon Sep 17 00:00:00 2001 From: Andrey Danin Date: Fri, 12 Mar 2021 22:42:22 +0300 Subject: [PATCH] Introduce parameter to disable CxxSquidSensor Fix for #2228 SquidSensor can take significant amount of time on big projects. Skip execution if sonar.cxx.squidDisabled parameter is set to true. --- .../org/sonar/plugins/cxx/CxxSquidSensor.java | 17 +++++++++++++++-- .../org/sonar/plugins/cxx/CxxPluginTest.java | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/CxxSquidSensor.java b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/CxxSquidSensor.java index d5e2fe881d..d1739cf158 100644 --- a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/CxxSquidSensor.java +++ b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/CxxSquidSensor.java @@ -72,6 +72,7 @@ */ public class CxxSquidSensor implements ProjectSensor { + public static final String SQUID_DISABLED_KEY = "sonar.cxx.squid.disabled"; public static final String DEFINES_KEY = "sonar.cxx.defines"; public static final String INCLUDE_DIRECTORIES_KEY = "sonar.cxx.includeDirectories"; public static final String ERROR_RECOVERY_KEY = "sonar.cxx.errorRecoveryEnabled"; @@ -144,6 +145,18 @@ public static List properties() { ) .onQualifiers(Qualifiers.PROJECT) .build(), + PropertyDefinition.builder(SQUID_DISABLED_KEY) + .defaultValue(Boolean.FALSE.toString()) + .name("Disable code quality and metrics checks") + .description( + "Disable preprocessor, metrics, duplications detection. It could be time consuming on" + + " big projects." + ) + .category("CXX") + .subCategory("(1) General") + .onQualifiers(Qualifiers.PROJECT) + .type(PropertyType.BOOLEAN) + .build(), PropertyDefinition.builder(DEFINES_KEY) .name("(2.1) Macros") .description( @@ -270,7 +283,8 @@ public void describe(SensorDescriptor descriptor) { descriptor .name("CXX") .onlyOnLanguage("cxx") - .onlyOnFileType(InputFile.Type.MAIN); + .onlyOnFileType(InputFile.Type.MAIN) + .onlyWhenConfiguration(conf -> !conf.getBoolean(SQUID_DISABLED_KEY).orElse(false)); } /** @@ -521,5 +535,4 @@ private void saveMetric(InputFile file, Metric metri .on(file) .save(); } - } diff --git a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/CxxPluginTest.java b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/CxxPluginTest.java index e9cdadcaae..f6feccda99 100644 --- a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/CxxPluginTest.java +++ b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/CxxPluginTest.java @@ -40,7 +40,7 @@ public void testGetExtensions() throws Exception { var context = new Plugin.Context(runtime); var plugin = new CxxPlugin(); plugin.define(context); - assertThat(context.getExtensions()).hasSize(80); + assertThat(context.getExtensions()).hasSize(81); } }