]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3755 Move Issuable implementaiton to sonar-core
authorJulien Lancelot <julien.lancelot@gmail.com>
Mon, 8 Apr 2013 11:08:37 +0000 (13:08 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Mon, 8 Apr 2013 11:08:37 +0000 (13:08 +0200)
sonar-core/src/main/java/org/sonar/core/issue/DefaultIssuable.java [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/issue/DefaultIssuableTest.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/issue/Issuable.java
sonar-plugin-api/src/test/java/org/sonar/api/issue/IssuableTest.java [deleted file]

diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssuable.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssuable.java
new file mode 100644 (file)
index 0000000..ff8fa76
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+
+package org.sonar.core.issue;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Predicate;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.ListMultimap;
+import org.sonar.api.component.Component;
+import org.sonar.api.issue.Issuable;
+import org.sonar.api.issue.Issue;
+import org.sonar.api.issue.IssueChangelog;
+
+import java.util.List;
+
+/**
+ * @since 3.6
+ */
+public class DefaultIssuable implements Issuable {
+
+  private List<Issue> issues;
+  private ListMultimap<Issue, IssueChangelog> issuesWithChangelogs;
+
+  public DefaultIssuable(List<Issue> issues) {
+    this.issues = issues;
+    this.issuesWithChangelogs = ArrayListMultimap.create();
+  }
+
+  public Issue apply(Issue issue, IssueChangelog issueChangelog) {
+    Issue existingIssue = findIssue(issue);
+    Issue.Builder builder = new Issue.Builder(existingIssue);
+
+    if (!Objects.equal(existingIssue.severity(), issueChangelog.severity())) {
+      builder.severity(issueChangelog.severity());
+    }
+    if (!Objects.equal(existingIssue.status(), issueChangelog.status())) {
+      builder.status(issueChangelog.status());
+    }
+    if (!Objects.equal(existingIssue.resolution(), issueChangelog.resolution())) {
+      builder.resolution(issueChangelog.resolution());
+    }
+    if (!Objects.equal(existingIssue.line(), issueChangelog.line())) {
+      builder.line(issueChangelog.line());
+      // Do not add changelog if only line has changed
+    }
+
+    issuesWithChangelogs.get(issue).add(issueChangelog);
+    return builder.build();
+  }
+
+  private Issue findIssue(final Issue issue) {
+    return Iterables.find(issues, new Predicate<Issue>() {
+      public boolean apply(Issue currentIssue) {
+        return currentIssue.uuid().equals(issue.uuid());
+      }
+    });
+  }
+
+  public List<Issue> issues() {
+    return issues;
+  }
+
+  @Override
+  public Component component() {
+    return null;
+  }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssuableTest.java b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssuableTest.java
new file mode 100644 (file)
index 0000000..3e3fc39
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+
+package org.sonar.core.issue;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.issue.Issue;
+import org.sonar.api.issue.IssueChangelog;
+
+import java.util.List;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DefaultIssuableTest {
+
+  private org.sonar.api.issue.Issuable issuable;
+  private List<Issue> issueList;
+
+  @Before
+  public void before(){
+    issueList = newArrayList();
+    issuable = new DefaultIssuable(issueList);
+  }
+
+  @Test
+  public void should_apply_issue() throws Exception {
+    Issue issue = new Issue.Builder()
+        .ruleKey("ruleKey")
+        .ruleRepositoryKey("ruleRepositoryKey")
+        .severity(Issue.SEVERITY_BLOCKER)
+        .status(Issue.STATUS_REOPENED)
+        .resolution(Issue.RESOLUTION_FALSE_POSITIVE)
+        .line(10)
+        .componentKey("componentKey")
+        .cost(10.0)
+        .message("issue message")
+        .build();
+    issueList.add(issue);
+
+    IssueChangelog issueChangelog = new IssueChangelog.Builder()
+        .severity(Issue.SEVERITY_MAJOR)
+        .status(Issue.STATUS_CLOSED)
+        .resolution(Issue.RESOLUTION_FIXED)
+        .message("changelog message")
+        .line(1)
+        .build();
+
+    Issue resultIssue = issuable.apply(issue, issueChangelog);
+    assertThat(resultIssue).isNotNull();
+    assertThat(resultIssue.uuid()).isNotEmpty();
+    assertThat(resultIssue.severity()).isEqualTo(Issue.SEVERITY_MAJOR);
+    assertThat(resultIssue.status()).isEqualTo(Issue.STATUS_CLOSED);
+    assertThat(resultIssue.resolution()).isEqualTo(Issue.RESOLUTION_FIXED);
+    assertThat(resultIssue.line()).isEqualTo(1);
+  }
+}
index fea96cceba26a185ef03624c05d44cffa02156e9..2351dc454ecfd4dff0cef89526a87be9d62c0860 100644 (file)
 
 package org.sonar.api.issue;
 
-import com.google.common.base.Objects;
-import com.google.common.base.Predicate;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.ListMultimap;
 import org.sonar.api.component.Component;
+import org.sonar.api.component.Perspective;
 
 import java.util.List;
 
 /**
  * @since 3.6
  */
-public class Issuable {
+public interface Issuable extends Perspective {
 
-  private List<Issue> issues;
-  private ListMultimap<Issue, IssueChangelog> issuesWithChangelogs;
+  Issue apply(Issue issue, IssueChangelog issueChangelog);
 
-  public Issuable(List<Issue> issues) {
-    this.issues = issues;
-    this.issuesWithChangelogs = ArrayListMultimap.create();
-  }
+  List<Issue> issues();
 
-  public Issue apply(Issue issue, IssueChangelog issueChangelog) {
-    Issue existingIssue = findIssue(issue);
-    Issue.Builder builder = new Issue.Builder(existingIssue);
+  @Override
+  Component component();
 
-    if (!Objects.equal(existingIssue.severity(), issueChangelog.severity())) {
-      builder.severity(issueChangelog.severity());
-    }
-    if (!Objects.equal(existingIssue.status(), issueChangelog.status())) {
-      builder.status(issueChangelog.status());
-    }
-    if (!Objects.equal(existingIssue.resolution(), issueChangelog.resolution())) {
-      builder.resolution(issueChangelog.resolution());
-    }
-    if (!Objects.equal(existingIssue.line(), issueChangelog.line())) {
-      builder.line(issueChangelog.line());
-      // Do not add changelog if only line has changed
-    }
-
-    issuesWithChangelogs.get(issue).add(issueChangelog);
-    return builder.build();
-  }
-
-  private Issue findIssue(final Issue issue) {
-    return Iterables.find(issues, new Predicate<Issue>() {
-      public boolean apply(Issue currentIssue) {
-        return currentIssue.uuid().equals(issue.uuid());
-      }
-    });
-  }
-
-  public List<Issue> issues() {
-    return issues;
-  }
-
-  public Component component() {
-    return null;
-  }
 }
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssuableTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssuableTest.java
deleted file mode 100644 (file)
index de68aa7..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-
-package org.sonar.api.issue;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.List;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static org.fest.assertions.Assertions.assertThat;
-
-public class IssuableTest {
-
-  private Issuable issuable;
-  private List<Issue> issueList;
-
-  @Before
-  public void before(){
-    issueList = newArrayList();
-    issuable = new Issuable(issueList);
-  }
-
-  @Test
-  public void should_apply_issue() throws Exception {
-    Issue issue = new Issue.Builder()
-        .ruleKey("ruleKey")
-        .ruleRepositoryKey("ruleRepositoryKey")
-        .severity(Issue.SEVERITY_BLOCKER)
-        .status(Issue.STATUS_REOPENED)
-        .resolution(Issue.RESOLUTION_FALSE_POSITIVE)
-        .line(10)
-        .componentKey("componentKey")
-        .cost(10.0)
-        .message("issue message")
-        .build();
-    issueList.add(issue);
-
-    IssueChangelog issueChangelog = new IssueChangelog.Builder()
-        .severity(Issue.SEVERITY_MAJOR)
-        .status(Issue.STATUS_CLOSED)
-        .resolution(Issue.RESOLUTION_FIXED)
-        .message("changelog message")
-        .line(1)
-        .build();
-
-    Issue resultIssue = issuable.apply(issue, issueChangelog);
-    assertThat(resultIssue).isNotNull();
-    assertThat(resultIssue.uuid()).isNotEmpty();
-    assertThat(resultIssue.severity()).isEqualTo(Issue.SEVERITY_MAJOR);
-    assertThat(resultIssue.status()).isEqualTo(Issue.STATUS_CLOSED);
-    assertThat(resultIssue.resolution()).isEqualTo(Issue.RESOLUTION_FIXED);
-    assertThat(resultIssue.line()).isEqualTo(1);
-  }
-}