]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2594 FindBugs plugin should support localized violations
authorEvgeny Mandrikov <mandrikov@gmail.com>
Wed, 19 Oct 2011 11:42:35 +0000 (15:42 +0400)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Wed, 19 Oct 2011 14:37:48 +0000 (18:37 +0400)
plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java
plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsExecutor.java

index 21057ea46631c3a1f87e96072b6a299914baad1c..9526f7975c20513b7d1c16dd0494f57efde9b37b 100644 (file)
@@ -35,6 +35,7 @@ import org.sonar.plugins.findbugs.xml.Match;
 import java.io.*;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Locale;
 
 /**
  * @since 2.4
@@ -121,6 +122,10 @@ public class FindbugsConfiguration implements BatchExtension {
     return project.getConfiguration().getLong(CoreProperties.FINDBUGS_TIMEOUT_PROPERTY, CoreProperties.FINDBUGS_TIMEOUT_DEFAULT_VALUE);
   }
 
+  public Locale getLocale() {
+    return new Locale(project.getConfiguration().getString(CoreProperties.CORE_VIOLATION_LOCALE_PROPERTY, CoreProperties.CORE_VIOLATION_LOCALE_DEFAULT_VALUE));
+  }
+
   private File jsr305Lib;
   private File annotationsLib;
 
index 6beceb7badcc0e24104a8da4adc7238e787320f3..cd0d1fb175a9804741e314a14d05731c48d7d10e 100644 (file)
@@ -41,6 +41,7 @@ import java.lang.reflect.Field;
 import java.net.URL;
 import java.util.Enumeration;
 import java.util.List;
+import java.util.Locale;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -64,6 +65,10 @@ public class FindbugsExecutor implements BatchExtension {
     ClassLoader initialClassLoader = Thread.currentThread().getContextClassLoader();
     Thread.currentThread().setContextClassLoader(FindBugs2.class.getClassLoader());
 
+    // This is a dirty workaround, but unfortunately there is no other way to specify locale for FindBugs - see SONAR-2594
+    Locale initialLocale = Locale.getDefault();
+    Locale.setDefault(configuration.getLocale());
+
     OutputStream xmlOutput = null;
     ExecutorService executorService = Executors.newSingleThreadExecutor();
     try {
@@ -122,6 +127,7 @@ public class FindbugsExecutor implements BatchExtension {
       executorService.shutdown();
       IOUtils.closeQuietly(xmlOutput);
       Thread.currentThread().setContextClassLoader(initialClassLoader);
+      Locale.setDefault(initialLocale);
     }
   }