]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws in BatchUtils
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 30 Nov 2015 08:15:38 +0000 (09:15 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 30 Nov 2015 08:15:38 +0000 (09:15 +0100)
sonar-batch/src/main/java/org/sonar/batch/util/BatchUtils.java

index aa5fbc35ae0ea0876deb4d1a44d78fac65660743..1315cd1d4fbdea8fa69af40ca265bdb471cce810 100644 (file)
@@ -27,7 +27,9 @@ import java.io.InputStreamReader;
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
+import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -68,13 +70,14 @@ public class BatchUtils {
     return o.getClass().getName();
   }
 
+  @CheckForNull
   public static String getServerVersion() {
-    InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("sq-version.txt");
+    InputStream is = BatchUtils.class.getResourceAsStream("/sq-version.txt");
     if (is == null) {
       LOG.warn("Failed to get SQ version");
       return null;
     }
-    try (BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
+    try (BufferedReader br = IOUtils.toBufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
       return br.readLine();
     } catch (IOException e) {
       LOG.warn("Failed to get SQ version", e);