From 862403f430006757c19c0c7b3fe7f8de44c44c14 Mon Sep 17 00:00:00 2001 From: Ivan Galkin Date: Tue, 7 Aug 2018 23:23:51 +0200 Subject: [PATCH] Fix SensorDescriptors for CxxCompiler{Gcc|Vc}Sensor * Issue introduced in #1522 --- .../compiler/CxxCompilerGccSensor.java | 7 +++-- .../sensors/compiler/CxxCompilerVcSensor.java | 7 +++-- .../compiler/CxxCompilerSensorTest.java | 31 +++++++++++++++++++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/cxx-sensors/src/main/java/org/sonar/cxx/sensors/compiler/CxxCompilerGccSensor.java b/cxx-sensors/src/main/java/org/sonar/cxx/sensors/compiler/CxxCompilerGccSensor.java index 8315dcaf9e..55fd3b3342 100644 --- a/cxx-sensors/src/main/java/org/sonar/cxx/sensors/compiler/CxxCompilerGccSensor.java +++ b/cxx-sensors/src/main/java/org/sonar/cxx/sensors/compiler/CxxCompilerGccSensor.java @@ -46,7 +46,10 @@ public CxxCompilerGccSensor(CxxLanguage language) { @Override public void describe(SensorDescriptor descriptor) { - descriptor.name(getLanguage().getName() + " CxxCompilerGccSensor").onlyOnLanguage(getLanguage().getKey()) - .createIssuesForRuleRepositories(getReportPathKey()).onlyWhenConfiguration(new IsGccParserConfigured()); + descriptor + .name(getLanguage().getName() + " CxxCompilerGccSensor") + .onlyOnLanguage(getLanguage().getKey()) + .createIssuesForRuleRepository(getRuleRepositoryKey()) + .onlyWhenConfiguration(new IsGccParserConfigured()); } } diff --git a/cxx-sensors/src/main/java/org/sonar/cxx/sensors/compiler/CxxCompilerVcSensor.java b/cxx-sensors/src/main/java/org/sonar/cxx/sensors/compiler/CxxCompilerVcSensor.java index a5ff1615da..9c65ad6978 100644 --- a/cxx-sensors/src/main/java/org/sonar/cxx/sensors/compiler/CxxCompilerVcSensor.java +++ b/cxx-sensors/src/main/java/org/sonar/cxx/sensors/compiler/CxxCompilerVcSensor.java @@ -49,7 +49,10 @@ public CxxCompilerVcSensor(CxxLanguage language) { @Override public void describe(SensorDescriptor descriptor) { - descriptor.name(getLanguage().getName() + " CxxCompilerVcSensor").onlyOnLanguage(getLanguage().getKey()) - .createIssuesForRuleRepositories(getReportPathKey()).onlyWhenConfiguration(new IsVcParserConfigured()); + descriptor + .name(getLanguage().getName() + " CxxCompilerVcSensor") + .onlyOnLanguage(getLanguage().getKey()) + .createIssuesForRuleRepository(getRuleRepositoryKey()) + .onlyWhenConfiguration(new IsVcParserConfigured()); } } diff --git a/cxx-sensors/src/test/java/org/sonar/cxx/sensors/compiler/CxxCompilerSensorTest.java b/cxx-sensors/src/test/java/org/sonar/cxx/sensors/compiler/CxxCompilerSensorTest.java index a046b6b4bf..f106d82125 100644 --- a/cxx-sensors/src/test/java/org/sonar/cxx/sensors/compiler/CxxCompilerSensorTest.java +++ b/cxx-sensors/src/test/java/org/sonar/cxx/sensors/compiler/CxxCompilerSensorTest.java @@ -24,6 +24,8 @@ import java.util.Optional; import javax.xml.stream.XMLStreamException; import static org.assertj.core.api.Assertions.assertThat; + +import org.assertj.core.api.SoftAssertions; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -31,6 +33,7 @@ import static org.mockito.Mockito.when; import org.sonar.api.batch.fs.internal.DefaultFileSystem; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; +import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; import org.sonar.api.batch.sensor.internal.SensorContextTester; import org.sonar.api.config.internal.MapSettings; import org.sonar.api.profiles.RulesProfile; @@ -140,4 +143,32 @@ public void shouldReportWarningsWithoutFileAndLineInformation() throws XMLStream Assert.assertTrue(warnings.containsAll(sensor.savedWarnings)); } + + @Test + public void sensorDescriptorGcc() { + DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor(); + CxxCompilerGccSensor sensor = new CxxCompilerGccSensor(language); + sensor.describe(descriptor); + + SoftAssertions softly = new SoftAssertions(); + softly.assertThat(descriptor.name()).isEqualTo(language.getName() + " CxxCompilerGccSensor"); + softly.assertThat(descriptor.languages()).containsOnly(language.getKey()); + softly.assertThat(descriptor.ruleRepositories()) + .containsOnly(CxxCompilerGccRuleRepository.getRepositoryKey(language)); + softly.assertAll(); + } + + @Test + public void sensorDescriptorVc() { + DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor(); + CxxCompilerVcSensor sensor = new CxxCompilerVcSensor(language); + sensor.describe(descriptor); + + SoftAssertions softly = new SoftAssertions(); + softly.assertThat(descriptor.name()).isEqualTo(language.getName() + " CxxCompilerVcSensor"); + softly.assertThat(descriptor.languages()).containsOnly(language.getKey()); + softly.assertThat(descriptor.ruleRepositories()) + .containsOnly(CxxCompilerVcRuleRepository.getRepositoryKey(language)); + softly.assertAll(); + } }