From: Simon Brandhof Date: Wed, 5 Feb 2014 09:09:22 +0000 (+0100) Subject: SONAR-926 fix support of Java as long as release version is used X-Git-Tag: 4.2~256 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f65a7c9ef91a50813b663adc7c4c64da72fb0515;p=sonarqube.git SONAR-926 fix support of Java as long as release version is used --- diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java index d9ecbb18b17..249a492a19a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java @@ -50,9 +50,10 @@ public class SensorsExecutor implements BatchComponent { private BatchExtensionDictionnary selector; private final DatabaseSession session; private final SensorMatcher sensorMatcher; + private final DefaultModuleLanguages moduleLanguages; public SensorsExecutor(BatchExtensionDictionnary selector, Project project, DefaultModuleFileSystem fs, MavenPluginExecutor mavenExecutor, EventBus eventBus, - DatabaseSession session, SensorMatcher sensorMatcher) { + DatabaseSession session, SensorMatcher sensorMatcher, DefaultModuleLanguages moduleLanguages) { this.selector = selector; this.mavenExecutor = mavenExecutor; this.eventBus = eventBus; @@ -60,6 +61,7 @@ public class SensorsExecutor implements BatchComponent { this.fs = fs; this.session = session; this.sensorMatcher = sensorMatcher; + this.moduleLanguages = moduleLanguages; } public void execute(SensorContext context) { @@ -72,6 +74,22 @@ public class SensorsExecutor implements BatchComponent { if (sensor.shouldExecuteOnProject(module)) { executeSensor(context, sensor); + } else { + // For backward compatibility try to execute Sensor for each language until it is executed once (or never) + String oldLanguageKey = module.getLanguageKey(); + Language oldLanguage = module.getLanguage(); + for (Language language : moduleLanguages.languages()) { + module.setLanguage(language); + module.getConfiguration().setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, language.getKey()); + if (sensor.shouldExecuteOnProject(module)) { + LOG.warn("Sensor {} should be updated to not depends on deprecated Project::getLanguage or Project::getLanguageKey", sensor); + executeSensor(context, sensor); + break; + } + } + // Restore module language + module.setLanguage(oldLanguage); + module.getConfiguration().setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, oldLanguageKey); } }