aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-04-19 13:47:26 +0400
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-04-19 17:51:53 +0400
commit5cc143c7351b3a5d8334a59b42720407232f4153 (patch)
treeef9ca60d11c7146a89db27a9ff09362539530760 /plugins
parent9936a0250bfa0d484f403a1776e0dfc7a61acdf2 (diff)
downloadsonarqube-5cc143c7351b3a5d8334a59b42720407232f4153.tar.gz
sonarqube-5cc143c7351b3a5d8334a59b42720407232f4153.zip
SONAR-2358 Don't use org.codehaus.plexus.util.StringInputStream to calculate checksums for violations
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecorator.java23
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest.java2
2 files changed, 9 insertions, 16 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecorator.java
index 832a4be13b0..8360475d550 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecorator.java
@@ -23,10 +23,8 @@ import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
-import org.codehaus.plexus.util.StringInputStream;
import org.sonar.api.batch.*;
import org.sonar.api.database.model.RuleFailureModel;
import org.sonar.api.database.model.SnapshotSource;
@@ -35,11 +33,9 @@ import org.sonar.api.resources.Resource;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
import org.sonar.api.rules.Violation;
-import org.sonar.api.utils.SonarException;
import org.sonar.batch.components.PastViolationsLoader;
import org.sonar.batch.index.ViolationPersister;
-import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -108,19 +104,14 @@ public class ViolationPersisterDecorator implements Decorator {
return source == null || source.getData() == null ? Collections.<String>emptyList() : getChecksums(source.getData());
}
+ /**
+ * @param data can't be null
+ */
static List<String> getChecksums(String data) {
+ String[] lines = data.split("\r?\n|\r", -1);
List<String> result = Lists.newArrayList();
- StringInputStream stream = new StringInputStream(data);
- try {
- List<String> lines = IOUtils.readLines(stream);
- for (String line : lines) {
- result.add(getChecksum(line));
- }
- } catch (IOException e) {
- throw new SonarException("Unable to calculate checksums", e);
-
- } finally {
- IOUtils.closeQuietly(stream);
+ for (String line : lines) {
+ result.add(getChecksum(line));
}
return result;
}
@@ -145,7 +136,7 @@ public class ViolationPersisterDecorator implements Decorator {
*/
RuleFailureModel selectPastViolation(Violation violation, Multimap<Rule, RuleFailureModel> pastViolationsByRule) {
Collection<RuleFailureModel> pastViolations = pastViolationsByRule.get(violation.getRule());
- if (pastViolations==null || pastViolations.isEmpty()) {
+ if (pastViolations == null || pastViolations.isEmpty()) {
// skip violation, if there is no past violations with same rule
return null;
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest.java
index daf343330c6..0c715997b39 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest.java
@@ -48,9 +48,11 @@ public class ViolationPersisterDecoratorTest {
public void shouldGenerateCorrectChecksums() {
List<String> crlf = ViolationPersisterDecorator.getChecksums("Hello\r\nWorld");
List<String> lf = ViolationPersisterDecorator.getChecksums("Hello\nWorld");
+ List<String> cr = ViolationPersisterDecorator.getChecksums("Hello\rWorld");
assertThat(crlf.size(), is(2));
assertThat(crlf.get(0), not(equalTo(crlf.get(1))));
assertThat(lf, equalTo(crlf));
+ assertThat(cr, equalTo(crlf));
assertThat(ViolationPersisterDecorator.getChecksum("\tvoid method() {\n"),
equalTo(ViolationPersisterDecorator.getChecksum(" void method() {")));