diff options
author | Fabrice Bellingard <fabrice.bellingard@sonarsource.com> | 2012-09-14 09:46:00 +0200 |
---|---|---|
committer | Fabrice Bellingard <fabrice.bellingard@sonarsource.com> | 2012-09-14 09:46:00 +0200 |
commit | 7215a16cecd2b30eff25ae9742669ce630612d44 (patch) | |
tree | e152e5d43ccb7c8c82108fce1f19fa3f935309f9 /src/main/java | |
parent | fd146e021cc68228933abc9027021e0fea08843f (diff) | |
download | sonar-scanner-cli-7215a16cecd2b30eff25ae9742669ce630612d44.tar.gz sonar-scanner-cli-7215a16cecd2b30eff25ae9742669ce630612d44.zip |
SONARPLUGINS-2256 Do not force UTF-8 as the default charset
=> By default sonar-runner should not use UTF-8 to read source code
files but the default encoding of the JVM.
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/sonar/runner/Main.java | 2 | ||||
-rw-r--r-- | src/main/java/org/sonar/runner/Runner.java | 20 |
2 files changed, 19 insertions, 3 deletions
diff --git a/src/main/java/org/sonar/runner/Main.java b/src/main/java/org/sonar/runner/Main.java index 09a4c01..ee3449b 100644 --- a/src/main/java/org/sonar/runner/Main.java +++ b/src/main/java/org/sonar/runner/Main.java @@ -25,6 +25,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.Locale; import java.util.Properties; /** @@ -68,6 +69,7 @@ public final class Main { Logs.info("Java version: " + System.getProperty("java.version", "<unknown>") + ", vendor: " + System.getProperty("java.vendor", "<unknown>")); Logs.info("OS name: \"" + System.getProperty("os.name") + "\", version: \"" + System.getProperty("os.version") + "\", arch: \"" + System.getProperty("os.arch") + "\""); + Logs.info("Default locale: \"" + Locale.getDefault() + "\", source code encoding: \"" + runner.getSourceCodeEncoding() + "\""); if (debugMode) { Logs.info("Other system properties:"); Logs.info(" - sun.arch.data.model: \"" + System.getProperty("sun.arch.data.model") + "\""); diff --git a/src/main/java/org/sonar/runner/Runner.java b/src/main/java/org/sonar/runner/Runner.java index 6c4e6df..e17face 100644 --- a/src/main/java/org/sonar/runner/Runner.java +++ b/src/main/java/org/sonar/runner/Runner.java @@ -25,6 +25,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import java.util.Properties; @@ -102,6 +103,8 @@ public final class Runner { */ private static final String[] UNSUPPORTED_VERSIONS = {"1", "2.0", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7", "2.8", "2.9", "2.10"}; + private static final String PROPERTY_SOURCE_ENCODING = "sonar.sourceEncoding"; + private File projectDir; private File workDir; private String[] unmaskedPackages; @@ -114,6 +117,10 @@ public final class Runner { // set the default values for the Sonar Runner - they can be overriden with #setEnvironmentInformation this.properties.put(PROPERTY_ENVIRONMENT_INFORMATION_KEY, "Runner"); this.properties.put(PROPERTY_ENVIRONMENT_INFORMATION_VERSION, Version.getVersion()); + // sets the encoding if not forced + if (!properties.containsKey(PROPERTY_SOURCE_ENCODING)) { + properties.setProperty(PROPERTY_SOURCE_ENCODING, Charset.defaultCharset().name()); + } // and init the directories initDirs(); } @@ -187,6 +194,13 @@ public final class Runner { } /** + * @return the source code encoding that will be used by Sonar + */ + public String getSourceCodeEncoding() { + return properties.getProperty(PROPERTY_SOURCE_ENCODING); + } + + /** * @return global properties, project properties and command-line properties */ protected Properties getProperties() { @@ -204,9 +218,9 @@ public final class Runner { private BootstrapClassLoader createClassLoader(Bootstrapper bootstrapper) { URL url = getJarPath(); return bootstrapper.createClassLoader( - new URL[]{url}, // Add JAR with Sonar Runner - it's a Jar which contains this class - getClass().getClassLoader(), - unmaskedPackages); + new URL[] {url}, // Add JAR with Sonar Runner - it's a Jar which contains this class + getClass().getClassLoader(), + unmaskedPackages); } /** |