import java.io.*;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
/**
* @since 2.4
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;
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;
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();
executorService.shutdown();
IOUtils.closeQuietly(xmlOutput);
Thread.currentThread().setContextClassLoader(initialClassLoader);
+ Locale.setDefault(initialLocale);
}
}
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;
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();
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;
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();
}
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;
}