aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueFinder.java8
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java10
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/WebIssues.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/issue/JRubyIssues.java)2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/Paging.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/issue/Paging.java)30
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/issue/PagingTest.java54
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/PagingTest.java85
6 files changed, 119 insertions, 70 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueFinder.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueFinder.java
index 7ba13797017..735225e461e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueFinder.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueFinder.java
@@ -23,10 +23,10 @@ package org.sonar.api.issue;
import org.sonar.api.ServerComponent;
import org.sonar.api.component.Component;
import org.sonar.api.rules.Rule;
+import org.sonar.api.utils.Paging;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-
import java.util.Collection;
import java.util.List;
@@ -62,10 +62,4 @@ public interface IssueFinder extends ServerComponent {
@CheckForNull
Issue findByKey(String key /* TODO @Nullable Integer currentUserId */);
-
- /*
- Map<RuleKey, Rule> rules(Collection<Issue> issues);
-
- Map<String, Component> components(Collection<Issue> issues);
-*/
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java
index 796a6d42df7..d3fedd09ac7 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java
@@ -157,7 +157,7 @@ public class IssueQuery {
public static class Builder {
private enum Sort {
- created, updated, closed, assignee;
+ created, updated, closed, assignee
}
private static final int DEFAULT_PAGE_SIZE = 100;
@@ -265,15 +265,15 @@ public class IssueQuery {
}
public Builder pageSize(@Nullable Integer i) {
- Preconditions.checkArgument(i == null || i.intValue() > 0, "Page size must be greater than 0 (got " + i + ")");
- Preconditions.checkArgument(i == null || i.intValue() < MAX_PAGE_SIZE, "Page size must be less than " + MAX_PAGE_SIZE + " (got " + i + ")");
+ Preconditions.checkArgument(i == null || i > 0, "Page size must be greater than 0 (got " + i + ")");
+ Preconditions.checkArgument(i == null || i < MAX_PAGE_SIZE, "Page size must be less than " + MAX_PAGE_SIZE + " (got " + i + ")");
this.pageSize = (i == null ? DEFAULT_PAGE_SIZE : i.intValue());
return this;
}
public Builder pageIndex(@Nullable Integer i) {
- Preconditions.checkArgument(i == null || i.intValue() > 0, "Page index must be greater than 0 (got " + i + ")");
- this.pageIndex = (i == null ? DEFAULT_PAGE_INDEX : i.intValue());
+ Preconditions.checkArgument(i == null || i > 0, "Page index must be greater than 0 (got " + i + ")");
+ this.pageIndex = (i == null ? DEFAULT_PAGE_INDEX : i);
return this;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/JRubyIssues.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/WebIssues.java
index a56d44340e4..67932f0fe59 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/JRubyIssues.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/WebIssues.java
@@ -31,7 +31,7 @@ import java.util.Map;
*
* @since 3.6
*/
-public interface JRubyIssues extends ServerComponent {
+public interface WebIssues extends ServerComponent {
/**
* Search for issues.
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Paging.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/Paging.java
index 867cec866ca..0fc31c4b18a 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Paging.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/Paging.java
@@ -18,10 +18,9 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.api.issue;
+package org.sonar.api.utils;
/**
- * TODO move outside this package
* @since 3.6
*/
public class Paging {
@@ -30,20 +29,29 @@ public class Paging {
private final int pageIndex;
private final int total;
- public Paging(int pageSize, int pageIndex, int total) {
+ private Paging(int pageSize, int pageIndex, int total) {
this.pageSize = pageSize;
this.pageIndex = pageIndex;
this.total = total;
}
+ /**
+ * Page index, starting with 1.
+ */
public int pageIndex() {
return pageIndex;
}
+ /**
+ * Maximum number of items per page. It is greater than 0.
+ */
public int pageSize() {
return pageSize;
}
+ /**
+ * Total number of items. It is greater than or equal 0.
+ */
public int total() {
return total;
}
@@ -52,6 +60,9 @@ public class Paging {
return (pageIndex - 1) * pageSize;
}
+ /**
+ * Number of pages. It is greater than or equal 0.
+ */
public int pages() {
int p = (total / pageSize);
if ((total % pageSize) > 0) {
@@ -59,4 +70,17 @@ public class Paging {
}
return p;
}
+
+ public static Paging create(int pageSize, int pageIndex, int totalItems) {
+ if (pageSize<1) {
+ throw new IllegalArgumentException("Page size must be strictly positive. Got " + pageSize);
+ }
+ if (pageIndex<1) {
+ throw new IllegalArgumentException("Page index must be strictly positive. Got " + pageIndex);
+ }
+ if (totalItems<0) {
+ throw new IllegalArgumentException("Total items must be positive. Got " + totalItems);
+ }
+ return new Paging(pageSize, pageIndex, totalItems);
+ }
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/issue/PagingTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/issue/PagingTest.java
deleted file mode 100644
index ca9dbf25df2..00000000000
--- a/sonar-plugin-api/src/test/java/org/sonar/api/issue/PagingTest.java
+++ /dev/null
@@ -1,54 +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.api.issue;
-
-import org.junit.Test;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class PagingTest {
-
- @Test
- public void test_pagination(){
- Paging paging = new Paging(5, 1, 20);
-
- assertThat(paging.pageSize()).isEqualTo(5);
- assertThat(paging.pageIndex()).isEqualTo(1);
- assertThat(paging.total()).isEqualTo(20);
-
- assertThat(paging.offset()).isEqualTo(0);
- assertThat(paging.pages()).isEqualTo(4);
- }
-
- @Test
- public void test_offset(){
- assertThat(new Paging(5, 1, 20).offset()).isEqualTo(0);
- assertThat(new Paging(5, 2, 20).offset()).isEqualTo(5);
- }
-
- @Test
- public void test_number_of_pages(){
- assertThat(new Paging(5, 2, 20).pages()).isEqualTo(4);
- assertThat(new Paging(5, 2, 21).pages()).isEqualTo(5);
- assertThat(new Paging(5, 2, 25).pages()).isEqualTo(5);
- assertThat(new Paging(5, 2, 26).pages()).isEqualTo(6);
- }
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/PagingTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/PagingTest.java
new file mode 100644
index 00000000000..0d28a7b5ccc
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/PagingTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.api.utils;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
+
+public class PagingTest {
+
+ @Test
+ public void test_pagination() {
+ Paging paging = Paging.create(5, 1, 20);
+
+ assertThat(paging.pageSize()).isEqualTo(5);
+ assertThat(paging.pageIndex()).isEqualTo(1);
+ assertThat(paging.total()).isEqualTo(20);
+
+ assertThat(paging.offset()).isEqualTo(0);
+ assertThat(paging.pages()).isEqualTo(4);
+ }
+
+ @Test
+ public void test_offset() {
+ assertThat(Paging.create(5, 1, 20).offset()).isEqualTo(0);
+ assertThat(Paging.create(5, 2, 20).offset()).isEqualTo(5);
+ }
+
+ @Test
+ public void test_number_of_pages() {
+ assertThat(Paging.create(5, 2, 20).pages()).isEqualTo(4);
+ assertThat(Paging.create(5, 2, 21).pages()).isEqualTo(5);
+ assertThat(Paging.create(5, 2, 25).pages()).isEqualTo(5);
+ assertThat(Paging.create(5, 2, 26).pages()).isEqualTo(6);
+ }
+
+ @Test
+ public void page_size_should_be_strictly_positive() throws Exception {
+ try {
+ Paging.create(0, 5, 5);
+ fail();
+ } catch (IllegalArgumentException e) {
+ assertThat(e).hasMessage("Page size must be strictly positive. Got 0");
+ }
+ }
+
+ @Test
+ public void page_index_should_be_strictly_positive() throws Exception {
+ try {
+ Paging.create(5, 0, 5);
+ fail();
+ } catch (IllegalArgumentException e) {
+ assertThat(e).hasMessage("Page index must be strictly positive. Got 0");
+ }
+ }
+
+ @Test
+ public void total_items_should_be_positive() throws Exception {
+ try {
+ Paging.create(5, 5, -1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ assertThat(e).hasMessage("Total items must be positive. Got -1");
+ }
+ }
+}