]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-926 fix support of Java as long as release version is used
authorSimon Brandhof <simon.brandhof@gmail.com>
Wed, 5 Feb 2014 09:09:22 +0000 (10:09 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Wed, 5 Feb 2014 09:09:22 +0000 (10:09 +0100)
sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java

index d9ecbb18b17e5ca38499bcb193bf27b9b7695bc8..249a492a19a82c114b7526a390c3565cfcb62f74 100644 (file)
@@ -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);
       }
     }