]> 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>
Mon, 9 Jul 2012 09:47:02 +0000 (15:47 +0600)
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
plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java
plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsExecutorTest.java

index 10de177c4d908783b80501e2449567a618a54ddf..8e127a8ccd267cc42de7acbc7684ba7e69f79f98 100644 (file)
@@ -37,6 +37,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
@@ -124,6 +125,10 @@ public class FindbugsConfiguration implements BatchExtension {
     return settings.getLong(CoreProperties.FINDBUGS_TIMEOUT_PROPERTY);
   }
 
+  public Locale getLocale() {
+    return new Locale(settings.getString(CoreProperties.CORE_VIOLATION_LOCALE_PROPERTY));
+  }
+
   private File jsr305Lib;
   private File annotationsLib;
 
index ea5f8844467c7f044eb775d22c4f61dfe9a5da37..6e6d73e3e9fbb3e832cb10fda5c0bfdb5441ab84 100644 (file)
@@ -40,6 +40,7 @@ import java.net.URL;
 import java.util.Collection;
 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;
@@ -68,6 +69,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;
     Collection<Plugin> customPlugins = null;
     ExecutorService executorService = Executors.newSingleThreadExecutor();
@@ -126,6 +131,7 @@ public class FindbugsExecutor implements BatchExtension {
       executorService.shutdown();
       IOUtils.closeQuietly(xmlOutput);
       Thread.currentThread().setContextClassLoader(initialClassLoader);
+      Locale.setDefault(initialLocale);
     }
   }
 
index 10073c87003f050f93f17c05e53ed511b18d2e91..28662ceb8f95dcc04a2b8d193668ef290ee1508a 100644 (file)
@@ -32,6 +32,7 @@ import org.sonar.api.resources.Project;
 import org.sonar.api.test.SimpleProjectFileSystem;
 
 import java.io.File;
+import java.util.Locale;
 
 import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
@@ -101,6 +102,12 @@ public class FindbugsConfigurationTest {
     assertThat(conf.getTimeout()).isEqualTo(1);
   }
 
+  @Test
+  public void should_return_locale() {
+    settings.setProperty(CoreProperties.CORE_VIOLATION_LOCALE_PROPERTY, "fr");
+    assertThat(conf.getLocale()).isEqualTo(Locale.FRENCH);
+  }
+
   @Test
   public void should_return_excludes_filters() {
     assertThat(conf.getExcludesFilters()).isEmpty();
index afdf5797d96b6b64d8bf6284be063966175eebf8..c8bb43d02b12bc6a09e0062fd39accf015df7186 100644 (file)
@@ -23,11 +23,13 @@ import com.google.common.collect.Lists;
 import org.apache.commons.io.FileUtils;
 import org.junit.Test;
 import org.sonar.api.CoreProperties;
+import org.sonar.api.config.Settings;
 import org.sonar.api.resources.Project;
 import org.sonar.api.resources.ProjectFileSystem;
 import org.sonar.api.utils.SonarException;
 
 import java.io.File;
+import java.util.Locale;
 
 import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
@@ -63,7 +65,9 @@ public class FindbugsExecutorTest {
     Project project = mock(Project.class);
     ProjectFileSystem fs = mock(ProjectFileSystem.class);
     when(project.getFileSystem()).thenReturn(fs);
-    FindbugsConfiguration conf = new FindbugsConfiguration(project, null, null, null, null);
+    Settings settings = new Settings();
+    settings.setProperty(CoreProperties.CORE_VIOLATION_LOCALE_PROPERTY, CoreProperties.CORE_VIOLATION_LOCALE_DEFAULT_VALUE);
+    FindbugsConfiguration conf = new FindbugsConfiguration(project, settings, null, null, null);
 
     new FindbugsExecutor(conf).execute();
   }
@@ -80,6 +84,7 @@ public class FindbugsExecutorTest {
     when(conf.getExcludesFilters()).thenReturn(Lists.newArrayList(new File("test-resources/findbugs-exclude.xml"), new File("test-resources/fake-file.xml")));
     when(conf.getEffort()).thenReturn("default");
     when(conf.getTimeout()).thenReturn(CoreProperties.FINDBUGS_TIMEOUT_DEFAULT_VALUE);
+    when(conf.getLocale()).thenReturn(Locale.ENGLISH);
     return conf;
   }