diff --git a/java-jsp/src/main/java/org/sonar/java/jsp/Jasper.java b/java-jsp/src/main/java/org/sonar/java/jsp/Jasper.java index 6107ba90934..edada309723 100644 --- a/java-jsp/src/main/java/org/sonar/java/jsp/Jasper.java +++ b/java-jsp/src/main/java/org/sonar/java/jsp/Jasper.java @@ -63,6 +63,8 @@ @ScannerSide public class Jasper { + public static final String JSP_LANGUAGE_KEY = "jsp"; + private static final String SONAR_EXCLUSIONS_PROPERTY = "sonar.exclusions"; private static final Logger LOG = LoggerFactory.getLogger(Jasper.class); @@ -188,7 +190,7 @@ private static Optional findWebInfParentDirectory(FileSystem fs) { } private static List jspFiles(FileSystem fs) { - Iterable inputFiles = fs.inputFiles(fs.predicates().hasLanguage("jsp")); + Iterable inputFiles = fs.inputFiles(fs.predicates().hasLanguage(JSP_LANGUAGE_KEY)); return StreamSupport.stream(inputFiles.spliterator(), false) .toList(); } diff --git a/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaSensor.java b/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaSensor.java index 355e8b5a5eb..aae5aaafedc 100644 --- a/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaSensor.java +++ b/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaSensor.java @@ -96,7 +96,7 @@ public JavaSensor(SonarComponents sonarComponents, FileSystem fs, JavaResourceLo @Override public void describe(SensorDescriptor descriptor) { - descriptor.onlyOnLanguage(Java.KEY).name("JavaSensor"); + descriptor.onlyOnLanguages(Java.KEY, Jasper.JSP_LANGUAGE_KEY).name("JavaSensor"); } @Override diff --git a/sonar-java-plugin/src/test/java/org/sonar/plugins/java/JavaSensorTest.java b/sonar-java-plugin/src/test/java/org/sonar/plugins/java/JavaSensorTest.java index 44267068c36..e9a4b7bb149 100644 --- a/sonar-java-plugin/src/test/java/org/sonar/plugins/java/JavaSensorTest.java +++ b/sonar-java-plugin/src/test/java/org/sonar/plugins/java/JavaSensorTest.java @@ -45,6 +45,7 @@ import org.sonar.api.batch.rule.Checks; import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; import org.sonar.api.batch.rule.internal.NewActiveRule; +import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; import org.sonar.api.batch.sensor.internal.SensorContextTester; import org.sonar.api.config.Configuration; import org.sonar.api.config.internal.MapSettings; @@ -112,8 +113,8 @@ void test_toString() throws IOException { @Test void test_issues_creation_on_main_file() throws IOException { - // Expected issues : the number of methods violating BadMethodName rule. Currently, 17 tests. - testIssueCreation(InputFile.Type.MAIN, 17); + // Expected issues : the number of methods violating BadMethodName rule. Currently, 18 tests. + testIssueCreation(InputFile.Type.MAIN, 18); } @Test @@ -132,8 +133,8 @@ private void testIssueCreation(InputFile.Type onType, int expectedIssues) throws JavaSensor jss = new JavaSensor(sonarComponents, fs, javaResourceLocator, settings.asConfig(), noSonarFilter, null); jss.execute(context); - // argument 120 refers to the comment on line #120 in this file - verify(noSonarFilter, times(1)).noSonarInFile(fs.inputFiles().iterator().next(), Collections.singleton(120)); + // argument 121 refers to the comment on line #121 in this file, each time this file changes, this argument should be updated + verify(noSonarFilter, times(1)).noSonarInFile(fs.inputFiles().iterator().next(), Collections.singleton(121)); verify(sonarComponents, times(expectedIssues)).reportIssue(any(AnalyzerMessage.class)); settings.setProperty(JavaVersion.SOURCE_VERSION, "wrongFormat"); @@ -434,6 +435,16 @@ void filter_checks_when_autoscan_true() throws IOException { ); } + @Test + void test_describe_sensor() throws IOException { + DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor(); + SonarComponents sonarComponents = createSonarComponentsMock(createContext(InputFile.Type.MAIN)); + var sensor = new JavaSensor(sonarComponents, null, null, null, null, null); + sensor.describe(descriptor); + assertThat(descriptor.name()).isEqualTo("JavaSensor"); + assertThat(descriptor.languages()).containsExactly("java", "jsp"); + } + private SensorContextTester analyzeTwoFilesWithIssues(MapSettings settings) throws IOException { SensorContextTester context = SensorContextTester.create(new File("src/test/files").getAbsoluteFile()) .setSettings(settings)