]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3387 Rename Violation to Issue
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 17 Sep 2013 08:35:38 +0000 (10:35 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 18 Sep 2013 10:37:30 +0000 (12:37 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTracking.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/tracking/IssueTrackingBlocksRecognizer.java [new file with mode: 0644]
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/tracking/ViolationTrackingBlocksRecognizer.java [deleted file]
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/tracking/IssueTrackingBlocksRecognizerTest.java [new file with mode: 0644]
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/tracking/ViolationTrackingBlocksRecognizerTest.java [deleted file]

index b433614c6300ccff32b77beb818969278e77ed38..871239ef6d6b1442d2aa736be2dea086e12a36d8 100644 (file)
@@ -114,7 +114,7 @@ public class IssueTracking implements BatchExtension {
     HashedSequence<StringText> hashedSource = HashedSequence.wrap(new StringText(source), StringTextComparator.IGNORE_WHITESPACE);
     HashedSequenceComparator<StringText> hashedComparator = new HashedSequenceComparator<StringText>(StringTextComparator.IGNORE_WHITESPACE);
 
-    ViolationTrackingBlocksRecognizer rec = new ViolationTrackingBlocksRecognizer(hashedReference, hashedSource, hashedComparator);
+    IssueTrackingBlocksRecognizer rec = new IssueTrackingBlocksRecognizer(hashedReference, hashedSource, hashedComparator);
 
     Multimap<Integer, DefaultIssue> newIssuesByLines = newIssuesByLines(newIssues, rec, result);
     Multimap<Integer, IssueDto> lastIssuesByLines = lastIssuesByLines(result.unmatched(), rec);
@@ -220,7 +220,7 @@ public class IssueTracking implements BatchExtension {
     }
   }
 
-  private Multimap<Integer, DefaultIssue> newIssuesByLines(Collection<DefaultIssue> newIssues, ViolationTrackingBlocksRecognizer rec, IssueTrackingResult result) {
+  private Multimap<Integer, DefaultIssue> newIssuesByLines(Collection<DefaultIssue> newIssues, IssueTrackingBlocksRecognizer rec, IssueTrackingResult result) {
     Multimap<Integer, DefaultIssue> newIssuesByLines = LinkedHashMultimap.create();
     for (DefaultIssue newIssue : newIssues) {
       if (isNotAlreadyMapped(newIssue, result) && rec.isValidLineInSource(newIssue.line())) {
@@ -230,7 +230,7 @@ public class IssueTracking implements BatchExtension {
     return newIssuesByLines;
   }
 
-  private Multimap<Integer, IssueDto> lastIssuesByLines(Collection<IssueDto> lastIssues, ViolationTrackingBlocksRecognizer rec) {
+  private Multimap<Integer, IssueDto> lastIssuesByLines(Collection<IssueDto> lastIssues, IssueTrackingBlocksRecognizer rec) {
     Multimap<Integer, IssueDto> lastIssuesByLines = LinkedHashMultimap.create();
     for (IssueDto pastIssue : lastIssues) {
       if (rec.isValidLineInReference(pastIssue.getLine())) {
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/tracking/IssueTrackingBlocksRecognizer.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/tracking/IssueTrackingBlocksRecognizer.java
new file mode 100644 (file)
index 0000000..666bd98
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.plugins.core.issue.tracking;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.sonar.plugins.core.issue.tracking.HashedSequence;
+import org.sonar.plugins.core.issue.tracking.HashedSequenceComparator;
+import org.sonar.plugins.core.issue.tracking.StringText;
+import org.sonar.plugins.core.issue.tracking.StringTextComparator;
+
+import javax.annotation.Nullable;
+
+public class IssueTrackingBlocksRecognizer {
+
+  private final HashedSequence<StringText> a;
+  private final HashedSequence<StringText> b;
+  private final HashedSequenceComparator<StringText> cmp;
+
+  @VisibleForTesting
+  public IssueTrackingBlocksRecognizer(String referenceSource, String source) {
+    this.a = HashedSequence.wrap(new StringText(referenceSource), StringTextComparator.IGNORE_WHITESPACE);
+    this.b = HashedSequence.wrap(new StringText(source), StringTextComparator.IGNORE_WHITESPACE);
+    this.cmp = new HashedSequenceComparator<StringText>(StringTextComparator.IGNORE_WHITESPACE);
+  }
+
+  public IssueTrackingBlocksRecognizer(HashedSequence<StringText> a, HashedSequence<StringText> b, HashedSequenceComparator<StringText> cmp) {
+    this.a = a;
+    this.b = b;
+    this.cmp = cmp;
+  }
+
+  public boolean isValidLineInReference(@Nullable Integer line) {
+    return (line != null) && (0 <= line - 1) && (line - 1 < a.length());
+  }
+
+  public boolean isValidLineInSource(@Nullable Integer line) {
+    return (line != null) && (0 <= line - 1) && (line - 1 < b.length());
+  }
+
+  /**
+   * @param startA number of line from first version of text (numbering starts from 0)
+   * @param startB number of line from second version of text (numbering starts from 0)
+   */
+  public int computeLengthOfMaximalBlock(int startA, int startB) {
+    if (!cmp.equals(a, startA, b, startB)) {
+      return 0;
+    }
+    int length = 0;
+    int ai = startA;
+    int bi = startB;
+    while (ai < a.length() && bi < b.length() && cmp.equals(a, ai, b, bi)) {
+      ai++;
+      bi++;
+      length++;
+    }
+    ai = startA;
+    bi = startB;
+    while (ai >= 0 && bi >= 0 && cmp.equals(a, ai, b, bi)) {
+      ai--;
+      bi--;
+      length++;
+    }
+    // Note that position (startA, startB) was counted twice
+    return length - 1;
+  }
+
+}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/tracking/ViolationTrackingBlocksRecognizer.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/tracking/ViolationTrackingBlocksRecognizer.java
deleted file mode 100644 (file)
index 2a191e3..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.plugins.core.issue.tracking;
-
-import com.google.common.annotations.VisibleForTesting;
-import org.sonar.plugins.core.issue.tracking.HashedSequence;
-import org.sonar.plugins.core.issue.tracking.HashedSequenceComparator;
-import org.sonar.plugins.core.issue.tracking.StringText;
-import org.sonar.plugins.core.issue.tracking.StringTextComparator;
-
-import javax.annotation.Nullable;
-
-public class ViolationTrackingBlocksRecognizer {
-
-  private final HashedSequence<StringText> a;
-  private final HashedSequence<StringText> b;
-  private final HashedSequenceComparator<StringText> cmp;
-
-  @VisibleForTesting
-  public ViolationTrackingBlocksRecognizer(String referenceSource, String source) {
-    this.a = HashedSequence.wrap(new StringText(referenceSource), StringTextComparator.IGNORE_WHITESPACE);
-    this.b = HashedSequence.wrap(new StringText(source), StringTextComparator.IGNORE_WHITESPACE);
-    this.cmp = new HashedSequenceComparator<StringText>(StringTextComparator.IGNORE_WHITESPACE);
-  }
-
-  public ViolationTrackingBlocksRecognizer(HashedSequence<StringText> a, HashedSequence<StringText> b, HashedSequenceComparator<StringText> cmp) {
-    this.a = a;
-    this.b = b;
-    this.cmp = cmp;
-  }
-
-  public boolean isValidLineInReference(@Nullable Integer line) {
-    return (line != null) && (0 <= line - 1) && (line - 1 < a.length());
-  }
-
-  public boolean isValidLineInSource(@Nullable Integer line) {
-    return (line != null) && (0 <= line - 1) && (line - 1 < b.length());
-  }
-
-  /**
-   * @param startA number of line from first version of text (numbering starts from 0)
-   * @param startB number of line from second version of text (numbering starts from 0)
-   */
-  public int computeLengthOfMaximalBlock(int startA, int startB) {
-    if (!cmp.equals(a, startA, b, startB)) {
-      return 0;
-    }
-    int length = 0;
-    int ai = startA;
-    int bi = startB;
-    while (ai < a.length() && bi < b.length() && cmp.equals(a, ai, b, bi)) {
-      ai++;
-      bi++;
-      length++;
-    }
-    ai = startA;
-    bi = startB;
-    while (ai >= 0 && bi >= 0 && cmp.equals(a, ai, b, bi)) {
-      ai--;
-      bi--;
-      length++;
-    }
-    // Note that position (startA, startB) was counted twice
-    return length - 1;
-  }
-
-}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/tracking/IssueTrackingBlocksRecognizerTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/tracking/IssueTrackingBlocksRecognizerTest.java
new file mode 100644 (file)
index 0000000..77b4293
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.plugins.core.issue.tracking;
+
+import org.junit.Test;
+import org.sonar.plugins.core.issue.tracking.IssueTrackingBlocksRecognizer;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class IssueTrackingBlocksRecognizerTest {
+
+  @Test
+  public void test() {
+    assertThat(compute(t("abcde"), t("abcde"), 3, 3)).isEqualTo(5);
+    assertThat(compute(t("abcde"), t("abcd"), 3, 3)).isEqualTo(4);
+    assertThat(compute(t("bcde"), t("abcde"), 3, 3)).isEqualTo(0);
+    assertThat(compute(t("bcde"), t("abcde"), 2, 3)).isEqualTo(4);
+  }
+
+  private static int compute(String a, String b, int ai, int bi) {
+    IssueTrackingBlocksRecognizer rec = new IssueTrackingBlocksRecognizer(a, b);
+    return rec.computeLengthOfMaximalBlock(ai, bi);
+  }
+
+  private static String t(String text) {
+    StringBuilder sb = new StringBuilder();
+    for (int i = 0; i < text.length(); i++) {
+      sb.append(text.charAt(i)).append('\n');
+    }
+    return sb.toString();
+  }
+
+}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/tracking/ViolationTrackingBlocksRecognizerTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/tracking/ViolationTrackingBlocksRecognizerTest.java
deleted file mode 100644 (file)
index 194ee7d..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.plugins.core.issue.tracking;
-
-import org.junit.Test;
-import org.sonar.plugins.core.issue.tracking.ViolationTrackingBlocksRecognizer;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class ViolationTrackingBlocksRecognizerTest {
-
-  @Test
-  public void test() {
-    assertThat(compute(t("abcde"), t("abcde"), 3, 3)).isEqualTo(5);
-    assertThat(compute(t("abcde"), t("abcd"), 3, 3)).isEqualTo(4);
-    assertThat(compute(t("bcde"), t("abcde"), 3, 3)).isEqualTo(0);
-    assertThat(compute(t("bcde"), t("abcde"), 2, 3)).isEqualTo(4);
-  }
-
-  private static int compute(String a, String b, int ai, int bi) {
-    ViolationTrackingBlocksRecognizer rec = new ViolationTrackingBlocksRecognizer(a, b);
-    return rec.computeLengthOfMaximalBlock(ai, bi);
-  }
-
-  private static String t(String text) {
-    StringBuilder sb = new StringBuilder();
-    for (int i = 0; i < text.length(); i++) {
-      sb.append(text.charAt(i)).append('\n');
-    }
-    return sb.toString();
-  }
-
-}