Skip to content

Commit

Permalink
turning off CXX analysis
Browse files Browse the repository at this point in the history
- to turn off the CXX language, set the value to 'sonar.cxx.file.suffixes=-' (in the user interface set the first entry to '-')
- close #1807
  • Loading branch information
guwirth committed Apr 5, 2020
1 parent 541adfe commit 71d8bd0
Show file tree
Hide file tree
Showing 81 changed files with 30,461 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static CxxFileTester CreateCxxFileTester(String fileName, String basePath
public static CxxLanguage mockCxxLanguage() {
CxxLanguage language = Mockito.mock(CxxLanguage.class);
when(language.getKey()).thenReturn("c++");
when(language.getName()).thenReturn("c++");
when(language.getName()).thenReturn("CXX");
when(language.getFileSuffixes())
.thenReturn(new String[]{".cpp", ".hpp", ".h", ".cxx", ".c", ".cc", ".hxx", ".hh"});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static NSObject require(@Nullable NSObject object, String errorMsg) {
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
.name("import Clang Static Analyzer report(s)")
.name("CXX Clang Static Analyzer report import")
.onlyOnLanguage("c++")
.createIssuesForRuleRepository(getRuleRepositoryKey())
.onlyWhenConfiguration(conf -> conf.hasKey(getReportPathKey()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static List<PropertyDefinition> properties() {
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
.name("import Clang-Tidy report(s)")
.name("CXX Clang-Tidy report import")
.onlyOnLanguage("c++")
.createIssuesForRuleRepository(getRuleRepositoryKey())
.onlyWhenConfiguration(conf -> conf.hasKey(getReportPathKey()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static List<PropertyDefinition> properties() {
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
.name("import GCC compiler report(s)")
.name("CXX GCC compiler report import")
.onlyOnLanguage("c++")
.createIssuesForRuleRepositories(getRuleRepositoryKey())
.onlyWhenConfiguration(conf -> conf.hasKey(getReportPathKey()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static List<PropertyDefinition> properties() {
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
.name("import Visual Studio compiler report(s)")
.name("CXX Visual Studio compiler report import")
.onlyOnLanguage("c++")
.createIssuesForRuleRepositories(getRuleRepositoryKey())
.onlyWhenConfiguration(conf -> conf.hasKey(getReportPathKey()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static List<PropertyDefinition> properties() {
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
.name("import coverage report(s)")
.name("CXX coverage report import")
.onlyOnLanguage("c++")
.onlyWhenConfiguration(conf -> conf.hasKey(REPORT_PATH_KEY));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static List<PropertyDefinition> properties() {
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
.name("import Cppcheck report(s)")
.name("CXX Cppcheck report import")
.onlyOnLanguage("c++")
.createIssuesForRuleRepository(getRuleRepositoryKey())
.onlyWhenConfiguration(conf -> conf.hasKey(getReportPathKey()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static List<PropertyDefinition> properties() {
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
.name("import Dr. Memory report(s)")
.name("CXX Dr. Memory report import")
.onlyOnLanguage("c++")
.createIssuesForRuleRepository(getRuleRepositoryKey())
.onlyWhenConfiguration(conf -> conf.hasKey(getReportPathKey()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static List<PropertyDefinition> properties() {
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
.name("import external analyser report(s)")
.name("CXX external analyser report import")
.onlyOnLanguage("c++")
.createIssuesForRuleRepository(getRuleRepositoryKey())
.onlyWhenConfiguration(conf -> conf.hasKey(getReportPathKey()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static List<PropertyDefinition> properties() {
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
.name("import PC-lint report(s)")
.name("CXX PC-lint report import")
.onlyOnLanguage("c++")
.createIssuesForRuleRepository(getRuleRepositoryKey())
.onlyWhenConfiguration(conf -> conf.hasKey(getReportPathKey()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static List<PropertyDefinition> properties() {
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
.name("import RATS report(s)")
.name("CXX RATS report import")
.onlyOnLanguage("c++")
.createIssuesForRuleRepository(getRuleRepositoryKey())
.onlyWhenConfiguration(conf -> conf.hasKey(getReportPathKey()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public static List<PropertyDefinition> properties() {
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
.name("source code analyzer")
.name("CXX")
.onlyOnLanguage("c++")
.onlyOnFileType(InputFile.Type.MAIN);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static List<PropertyDefinition> properties() {
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
.name("import VSTest/xUnit/NUnit Test report(s)")
.name("CXX VSTest/xUnit/NUnit Test report import")
.onlyWhenConfiguration(conf -> new UnitTestConfiguration(language, conf).hasUnitTestResultsProperty())
.onlyOnLanguage("c++");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static List<PropertyDefinition> properties() {
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
.name("import xUnit Test report(s)")
.name("CXX xUnit Test report import")
//.onlyOnLanguage(getLanguage().getKey())
.onlyWhenConfiguration(conf -> conf.hasKey(REPORT_PATH_KEY));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static List<PropertyDefinition> properties() {
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
.name("import Valgrind report(s)")
.name("CXX Valgrind report import")
.onlyOnLanguage("c++")
.createIssuesForRuleRepository(getRuleRepositoryKey())
.onlyWhenConfiguration(conf -> conf.hasKey(REPORT_PATH_KEY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static List<PropertyDefinition> properties() {
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
.name("import Vera++ report(s)")
.name("CXX Vera++ report import")
.onlyOnLanguage("c++")
.createIssuesForRuleRepository(getRuleRepositoryKey())
.onlyWhenConfiguration(conf -> conf.hasKey(getReportPathKey()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void sensorDescriptor() {
sensor.describe(descriptor);

var softly = new SoftAssertions();
softly.assertThat(descriptor.name()).isEqualTo("import Clang Static Analyzer report(s)");
softly.assertThat(descriptor.name()).isEqualTo("CXX Clang Static Analyzer report import");
softly.assertThat(descriptor.languages()).containsOnly("c++");
softly.assertThat(descriptor.ruleRepositories()).containsOnly(CxxClangSARuleRepository.KEY);
softly.assertAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void sensorDescriptor() {
sensor.describe(descriptor);

var softly = new SoftAssertions();
softly.assertThat(descriptor.name()).isEqualTo("import Clang-Tidy report(s)");
softly.assertThat(descriptor.name()).isEqualTo("CXX Clang-Tidy report import");
softly.assertThat(descriptor.languages()).containsOnly("c++");
softly.assertThat(descriptor.ruleRepositories()).containsOnly(CxxClangTidyRuleRepository.KEY);
softly.assertAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void sensorDescriptorGcc() {
var sensor = new CxxCompilerGccSensor();
sensor.describe(descriptor);
var softly = new SoftAssertions();
softly.assertThat(descriptor.name()).isEqualTo("import GCC compiler report(s)");
softly.assertThat(descriptor.name()).isEqualTo("CXX GCC compiler report import");
softly.assertThat(descriptor.languages()).containsOnly("c++");
softly.assertThat(descriptor.ruleRepositories())
.containsOnly(CxxCompilerGccRuleRepository.KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void sensorDescriptorVc() {
var sensor = new CxxCompilerVcSensor();
sensor.describe(descriptor);
var softly = new SoftAssertions();
softly.assertThat(descriptor.name()).isEqualTo("import Visual Studio compiler report(s)");
softly.assertThat(descriptor.name()).isEqualTo("CXX Visual Studio compiler report import");
softly.assertThat(descriptor.languages()).containsOnly("c++");
softly.assertThat(descriptor.ruleRepositories())
.containsOnly(CxxCompilerVcRuleRepository.KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void sensorDescriptor() {
sensor.describe(descriptor);

var softly = new SoftAssertions();
softly.assertThat(descriptor.name()).isEqualTo("import coverage report(s)");
softly.assertThat(descriptor.name()).isEqualTo("CXX coverage report import");
softly.assertThat(descriptor.languages()).containsOnly("c++");
softly.assertAll();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void sensorDescriptor() {
sensor.describe(descriptor);

var softly = new SoftAssertions();
softly.assertThat(descriptor.name()).isEqualTo("import Cppcheck report(s)");
softly.assertThat(descriptor.name()).isEqualTo("CXX Cppcheck report import");
softly.assertThat(descriptor.languages()).containsOnly("c++");
softly.assertThat(descriptor.ruleRepositories()).containsOnly(CxxCppCheckRuleRepository.KEY);
softly.assertAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void sensorDescriptor() {
sensor.describe(descriptor);

var softly = new SoftAssertions();
softly.assertThat(descriptor.name()).isEqualTo("import Dr. Memory report(s)");
softly.assertThat(descriptor.name()).isEqualTo("CXX Dr. Memory report import");
softly.assertThat(descriptor.languages()).containsOnly("c++");
softly.assertThat(descriptor.ruleRepositories()).containsOnly(CxxDrMemoryRuleRepository.KEY);
softly.assertAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void sensorDescriptor() {
sensor.describe(descriptor);

var softly = new SoftAssertions();
softly.assertThat(descriptor.name()).isEqualTo("import external analyser report(s)");
softly.assertThat(descriptor.name()).isEqualTo("CXX external analyser report import");
softly.assertThat(descriptor.languages()).containsOnly("c++");
softly.assertThat(descriptor.ruleRepositories()).containsOnly(CxxOtherRepository.KEY);
softly.assertAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void sensorDescriptor() {
sensor.describe(descriptor);

var softly = new SoftAssertions();
softly.assertThat(descriptor.name()).isEqualTo("import PC-lint report(s)");
softly.assertThat(descriptor.name()).isEqualTo("CXX PC-lint report import");
softly.assertThat(descriptor.languages()).containsOnly("c++");
softly.assertThat(descriptor.ruleRepositories()).containsOnly(CxxPCLintRuleRepository.KEY);
softly.assertAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void sensorDescriptor() {
sensor.describe(descriptor);

var softly = new SoftAssertions();
softly.assertThat(descriptor.name()).isEqualTo("import RATS report(s)");
softly.assertThat(descriptor.name()).isEqualTo("CXX RATS report import");
softly.assertThat(descriptor.languages()).containsOnly("c++");
softly.assertThat(descriptor.ruleRepositories()).containsOnly(CxxRatsRuleRepository.KEY);
softly.assertAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void sensorDescriptor() {
sensor.describe(descriptor);

var softly = new SoftAssertions();
softly.assertThat(descriptor.name()).isEqualTo("import VSTest/xUnit/NUnit Test report(s)");
softly.assertThat(descriptor.name()).isEqualTo("CXX VSTest/xUnit/NUnit Test report import");
softly.assertThat(descriptor.languages()).containsOnly("c++");
softly.assertAll();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void sensorDescriptor() {
var sensor = new CxxXunitSensor(settings.asConfig());
sensor.describe(descriptor);

assertThat(descriptor.name()).isEqualTo("import xUnit Test report(s)");
assertThat(descriptor.name()).isEqualTo("CXX xUnit Test report import");
}

File cppunitReport() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static DefaultFileSystem mockFileSystem(File baseDir,
public static CxxLanguage mockCxxLanguage() {
CxxLanguage language = Mockito.mock(CxxLanguage.class);
when(language.getKey()).thenReturn("c++");
when(language.getName()).thenReturn("c++");
when(language.getName()).thenReturn("CXX");
when(language.getFileSuffixes())
.thenReturn(new String[]{".cpp", ".hpp", ".h", ".cxx", ".c", ".cc", ".hxx", ".hh"});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void sensorDescriptor() {
sensor.describe(descriptor);

var softly = new SoftAssertions();
softly.assertThat(descriptor.name()).isEqualTo("import Valgrind report(s)");
softly.assertThat(descriptor.name()).isEqualTo("CXX Valgrind report import");
softly.assertThat(descriptor.languages()).containsOnly("c++");
softly.assertThat(descriptor.ruleRepositories()).containsOnly(CxxValgrindRuleRepository.KEY);
softly.assertAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void sensorDescriptor() {
sensor.describe(descriptor);

var softly = new SoftAssertions();
softly.assertThat(descriptor.name()).isEqualTo("import Vera++ report(s)");
softly.assertThat(descriptor.name()).isEqualTo("CXX Vera++ report import");
softly.assertThat(descriptor.languages()).containsOnly("c++");
softly.assertThat(descriptor.ruleRepositories()).containsOnly(CxxVeraxxRuleRepository.KEY);
softly.assertAll();
Expand Down
6 changes: 5 additions & 1 deletion cxx-squid/src/main/java/org/sonar/cxx/CxxLanguage.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public static List<PropertyDefinition> properties() {
.defaultValue(DEFAULT_FILE_SUFFIXES)
.name("File suffixes")
.multiValues(true)
.description("Comma-separated list of suffixes for files to analyze. To not filter, leave the list empty.")
.description("Comma-separated list of suffixes for files to analyze. To turn off the CXX language,"
+ " set the value to 'sonar.cxx.file.suffixes=-'"
+ " (in the user interface set the first entry to '-').")
.category("CXX")
.subCategory("(1) General")
.onQualifiers(Qualifiers.PROJECT)
Expand All @@ -89,6 +91,8 @@ public String[] getFileSuffixes() {
.filter(s -> s != null && !s.trim().isEmpty()).toArray(String[]::new);
if (suffixes.length == 0) {
suffixes = Iterables.toArray(Splitter.on(',').split(DEFAULT_FILE_SUFFIXES), String.class);
} else if ("-".equals(suffixes[0])) {
suffixes = new String[]{"disabled"};
}
return suffixes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static CxxFileTester AddFileToContext(CxxFileTester tester, String fileNa
public static CxxLanguage mockCxxLanguage() {
CxxLanguage language = Mockito.mock(CxxLanguage.class);
when(language.getKey()).thenReturn("c++");
when(language.getName()).thenReturn("c++");
when(language.getName()).thenReturn("CXX");
when(language.getFileSuffixes())
.thenReturn(new String[]{".cpp", ".hpp", ".h", ".cxx", ".c", ".cc", ".hxx", ".hh"});

Expand Down
22 changes: 19 additions & 3 deletions cxx-squid/src/test/java/org/sonar/cxx/CxxLanguageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,26 @@ public void shouldReturnConfiguredFileSuffixes() {
}

@Test
public void shouldReturnDefaultFileSuffixes() {
public void shouldReturnDefaultFileSuffixes1() {
var cxx = new CxxLanguage(settings.asConfig());
String[] expectedAll = {".cxx", ".cpp", ".cc", ".c", ".hxx", ".hpp", ".hh", ".h"};
assertThat(cxx.getFileSuffixes(), is(expectedAll));
String[] expected = {".cxx", ".cpp", ".cc", ".c", ".hxx", ".hpp", ".hh", ".h"};
assertThat(cxx.getFileSuffixes(), is(expected));
}

@Test
public void shouldReturnDefaultFileSuffixes2() {
settings.setProperty(CxxLanguage.FILE_SUFFIXES_KEY, "");
var cxx = new CxxLanguage(settings.asConfig());
String[] expected = {".cxx", ".cpp", ".cc", ".c", ".hxx", ".hpp", ".hh", ".h"};
assertThat(cxx.getFileSuffixes(), is(expected));
}

@Test
public void shouldBeEmpty() {
settings.setProperty(CxxLanguage.FILE_SUFFIXES_KEY, "-");
var cxx = new CxxLanguage(settings.asConfig());
String[] expected = {"disabled"};
assertThat(cxx.getFileSuffixes(), is(expected));
}

}
22 changes: 22 additions & 0 deletions integration-tests/features/indexing.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@SqApi79
Feature: Indexing files

Test indexing of files depending on language and file extension settings

Scenario: CXX file suffixes
Given the project "indexing_project"
When I run "sonar-scanner -X -Dsonar.cxx.file.suffixes=.cc"
Then the analysis finishes successfully
And the analysis in server has completed
And the following metrics have following values:
| metric | value |
| files | 9 |

Scenario: Turn CXX language off
Given the project "indexing_project"
When I run "sonar-scanner -X -Dsonar.cxx.file.suffixes=-"
Then the analysis finishes successfully
And the analysis in server has completed
And the following metrics have following values:
| metric | value |
| files | 0 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int very_useful_function(int a, int b){
return a * b;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int very_useful_function(int a, int b);
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# required metadata
sonar.projectKey=indexing_project
sonar.projectName=indexing_project
sonar.projectVersion=1

# disable xml
sonar.xml.file.suffixes=.disable-xml

# disable SCM support
sonar.scm.disabled=true

# path to source directories (required)
sonar.sources=src
sonar.tests=tests/unittests

sonar.cxx.includeDirectories=src,3rdparty
11 changes: 11 additions & 0 deletions integration-tests/testdata/indexing_project/src/cli/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <iostream>
#include <lib/component1.hh>
#include <extlib.hh>
#include <lib/component1.hh>
#include <extlib.hh>

int main(int argc, char* argv[])
{
std::cout << "Here is main" << std::endl;
return Bar().foo();
}
Loading

0 comments on commit 71d8bd0

Please sign in to comment.