Skip to content

Commit

Permalink
Introduce parameter to disable CxxSquidSensor
Browse files Browse the repository at this point in the history
Fix for SonarOpenCommunity#2228

SquidSensor can take significant amount of time on big projects.
Skip execution if sonar.cxx.squidDisabled parameter is set to true.
  • Loading branch information
andreydanin committed Oct 7, 2021
1 parent b4fd14e commit 2421d1c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -144,6 +145,18 @@ public static List<PropertyDefinition> 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(
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -521,5 +535,4 @@ private <T extends Serializable> void saveMetric(InputFile file, Metric<T> metri
.on(file)
.save();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

0 comments on commit 2421d1c

Please sign in to comment.