diff options
author | Jenkins CI <ci@sonarsource.com> | 2014-10-09 15:16:17 +0200 |
---|---|---|
committer | Jenkins CI <ci@sonarsource.com> | 2014-10-09 15:16:17 +0200 |
commit | 15b326bf6c8a77591a15f4b2705309c3cc68b186 (patch) | |
tree | 1d3cf10f6bc3117e6176af65d147307298775622 /sonar-batch | |
parent | 393f9888e69e209b2755aebaed3709a167399b29 (diff) | |
parent | 6aeb90e78f84b5cd6060ea1a8843be8b9eabe2f1 (diff) | |
download | sonarqube-15b326bf6c8a77591a15f4b2705309c3cc68b186.tar.gz sonarqube-15b326bf6c8a77591a15f4b2705309c3cc68b186.zip |
Automatic merge from branch-4.5
* origin/branch-4.5:
Fix line count when file starts with a new line
SONAR-5030 Remove log about deregistered driver
Diffstat (limited to 'sonar-batch')
3 files changed, 22 insertions, 11 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java index 46720c4e224..87eca7394bc 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java @@ -32,7 +32,6 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -import java.util.List; /** * Contains and provides class loader extended with the JDBC Driver hosted on the server-side. @@ -177,11 +176,7 @@ public class JdbcDriverHolder { Class<?> lpClass = defineClass("org.sonar.batch.bootstrap.JdbcLeakPrevention", classBytes, 0, offset, this.getClass().getProtectionDomain()); Object obj = lpClass.newInstance(); - List<String> driverNames = (List<String>) obj.getClass().getMethod("unregisterDrivers").invoke(obj); - - for (String name : driverNames) { - LOG.debug("To prevent a memory leak, the JDBC Driver [{}] has been forcibly deregistered", name); - } + obj.getClass().getMethod("unregisterDrivers").invoke(obj); } catch (Exception e) { LOG.warn("JDBC driver deregistration failed", e); } finally { diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileMetadata.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileMetadata.java index 95c6ed4cc3b..4759db79b68 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileMetadata.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileMetadata.java @@ -23,7 +23,12 @@ import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.IOUtils; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; import java.nio.charset.Charset; import java.security.MessageDigest; @@ -50,13 +55,13 @@ class FileMetadata { Metadata read(File file, Charset encoding) { Reader reader = null; int lines = 0; - char c = (char)-1; + char c = (char) -1; try { MessageDigest md5Digest = DigestUtils.getMd5Digest(); md5Digest.reset(); reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding)); int i = reader.read(); - boolean afterCR = true; + boolean afterCR = false; while (i != -1) { c = (char) i; if (afterCR) { @@ -77,7 +82,7 @@ class FileMetadata { md5Digest.update(charToBytesUTF(c)); i = reader.read(); } - if (c != (char)-1) { + if (c != (char) -1) { lines++; } String hash = Hex.encodeHexString(md5Digest.digest()); @@ -91,7 +96,7 @@ class FileMetadata { } private byte[] charToBytesUTF(char c) { - char[] buffer = new char[]{c}; + char[] buffer = new char[] {c}; byte[] b = new byte[buffer.length << 1]; for (int i = 0; i < buffer.length; i++) { int bpos = i << 1; diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileMetadataTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileMetadataTest.java index 749a87408d3..2b4c64df8a0 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileMetadataTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileMetadataTest.java @@ -33,6 +33,7 @@ import static org.fest.assertions.Assertions.assertThat; public class FileMetadataTest { private static final String EXPECTED_HASH_WITHOUT_LATEST_EOL = "c80cc50d65ace6c4eb63f189d274dbeb"; + private static final String EXPECTED_HASH_NEW_LINE_FIRST = "cf2d41454b5b451eeb5122f0848c1d2a"; private static final String EXPECTED_HASH_WITH_LATEST_EOL = "bf77e51d219e7d7d643faac86f1b5d15"; @Rule @@ -112,6 +113,16 @@ public class FileMetadataTest { } @Test + public void start_with_newline() throws Exception { + File tempFile = temp.newFile(); + FileUtils.write(tempFile, "\nfoo\nbar\r\nbaz", Charsets.UTF_8, true); + + FileMetadata.Metadata metadata = FileMetadata.INSTANCE.read(tempFile, Charsets.UTF_8); + assertThat(metadata.lines).isEqualTo(4); + assertThat(metadata.hash).isEqualTo(EXPECTED_HASH_NEW_LINE_FIRST); + } + + @Test public void should_throw_if_file_does_not_exist() throws Exception { File tempFolder = temp.newFolder(); File file = new File(tempFolder, "doesNotExist.txt"); |