aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-10-19 15:42:35 +0400
committerEvgeny Mandrikov <mandrikov@gmail.com>2012-07-09 15:47:02 +0600
commit86e442b7124f1513d8beeb2f84860cb05502d3fb (patch)
treed08c2293bfde941cd29ac72ffd8077ebdcf1b1c7 /plugins
parent4773c7b53a45ea1b54a89b60f8d3fbb5901c00da (diff)
downloadsonarqube-86e442b7124f1513d8beeb2f84860cb05502d3fb.tar.gz
sonarqube-86e442b7124f1513d8beeb2f84860cb05502d3fb.zip
SONAR-2594 FindBugs plugin should support localized violations
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java5
-rw-r--r--plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsExecutor.java6
-rw-r--r--plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java7
-rw-r--r--plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsExecutorTest.java7
4 files changed, 24 insertions, 1 deletions
diff --git a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java
index 10de177c4d9..8e127a8ccd2 100644
--- a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java
+++ b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java
@@ -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;
diff --git a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsExecutor.java b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsExecutor.java
index ea5f8844467..6e6d73e3e9f 100644
--- a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsExecutor.java
+++ b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsExecutor.java
@@ -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);
}
}
diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java
index 10073c87003..28662ceb8f9 100644
--- a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java
+++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java
@@ -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;
@@ -102,6 +103,12 @@ public class FindbugsConfigurationTest {
}
@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();
settings.setProperty(FindbugsConstants.EXCLUDES_FILTERS_PROPERTY, " foo.xml , bar.xml,");
diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsExecutorTest.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsExecutorTest.java
index afdf5797d96..c8bb43d02b1 100644
--- a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsExecutorTest.java
+++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsExecutorTest.java
@@ -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;
}