diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-05-19 11:04:39 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-05-19 11:04:39 +0200 |
commit | 11ef0dc4eacb45f3caad754ea5d190b77b033a3a (patch) | |
tree | 743e6015cc3595653c26c6159e7343152556918d /sonar-ws-client/src/main/java | |
parent | b278651d81fe6302181da3a19bff7d9673c72bd0 (diff) | |
download | sonarqube-11ef0dc4eacb45f3caad754ea5d190b77b033a3a.tar.gz sonarqube-11ef0dc4eacb45f3caad754ea5d190b77b033a3a.zip |
Improve Java WS Client of /api/sources/show and /api/source/show
Diffstat (limited to 'sonar-ws-client/src/main/java')
8 files changed, 184 insertions, 22 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/source/Scm.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/source/Scm.java index cf420820659..27a2bb6b2d8 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/source/Scm.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/source/Scm.java @@ -26,7 +26,8 @@ import java.util.Date; public interface Scm { - long index(); + @CheckForNull + Integer lineIndex(); @CheckForNull String author(); diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/source/Source.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/source/Source.java index f1d1cf7b032..2d5b807fce1 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/source/Source.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/source/Source.java @@ -20,13 +20,17 @@ package org.sonar.wsclient.source; +import javax.annotation.CheckForNull; + /** * @since 4.4 */ public interface Source { - long index(); + @CheckForNull + Integer lineIndex(); - String line(); + @CheckForNull + String lineAsHtml(); } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/source/SourceClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/source/SourceClient.java index 36b65251bd4..6f5bb490def 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/source/SourceClient.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/source/SourceClient.java @@ -20,18 +20,17 @@ package org.sonar.wsclient.source; -import javax.annotation.Nullable; - import java.util.List; /** * Display sources information + * * @since 4.4 */ public interface SourceClient { - List<Source> show(String key, @Nullable String from, @Nullable String to); + List<Source> show(SourceShowQuery query); - List<Scm> scm(String key, @Nullable String from, @Nullable String to, @Nullable Boolean groupCommits); + List<Scm> scm(SourceScmQuery query); } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/source/SourceScmQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/source/SourceScmQuery.java new file mode 100644 index 00000000000..70d5124206c --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/source/SourceScmQuery.java @@ -0,0 +1,79 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 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.wsclient.source; + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + +public class SourceScmQuery { + + private String key; + private String from; + private String to; + private Boolean groupCommits; + + private SourceScmQuery() { + // Nothing here + } + + public String key() { + return key; + } + + public SourceScmQuery setKey(String key) { + this.key = key; + return this; + } + + @CheckForNull + public String from() { + return from; + } + + public SourceScmQuery setFrom(@Nullable String from) { + this.from = from; + return this; + } + + @CheckForNull + public String to() { + return to; + } + + public SourceScmQuery setTo(@Nullable String to) { + this.to = to; + return this; + } + + @CheckForNull + public Boolean groupCommits() { + return groupCommits; + } + + public SourceScmQuery setGroupCommits(@Nullable Boolean groupCommits) { + this.groupCommits = groupCommits; + return this; + } + + public static SourceScmQuery create(){ + return new SourceScmQuery(); + } +} diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/source/SourceShowQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/source/SourceShowQuery.java new file mode 100644 index 00000000000..d56241ace18 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/source/SourceShowQuery.java @@ -0,0 +1,69 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 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.wsclient.source; + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + +public class SourceShowQuery { + + private String key; + private String from; + private String to; + + private SourceShowQuery() { + // Nothing here + } + + public String key() { + return key; + } + + public SourceShowQuery setKey(String key) { + this.key = key; + return this; + } + + @CheckForNull + public String from() { + return from; + } + + public SourceShowQuery setFrom(@Nullable String from) { + this.from = from; + return this; + } + + @CheckForNull + public String to() { + return to; + } + + public SourceShowQuery setTo(@Nullable String to) { + this.to = to; + return this; + } + + public static SourceShowQuery create(){ + return new SourceShowQuery(); + } + +} diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/source/internal/DefaultScm.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/source/internal/DefaultScm.java index b563f5ec39a..e6cfc870a95 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/source/internal/DefaultScm.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/source/internal/DefaultScm.java @@ -37,10 +37,16 @@ public class DefaultScm implements Scm { } @Override - public long index() { - return (Long) json.get(0); + @CheckForNull + public Integer lineIndex() { + Object value = json.get(0); + if (value != null) { + return ((Long) value).intValue(); + } + return null; } + @Override @CheckForNull public String author() { diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/source/internal/DefaultSource.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/source/internal/DefaultSource.java index 8794a5f8bff..37a4f7db646 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/source/internal/DefaultSource.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/source/internal/DefaultSource.java @@ -22,6 +22,8 @@ package org.sonar.wsclient.source.internal; import org.sonar.wsclient.source.Source; +import javax.annotation.CheckForNull; + import java.util.List; public class DefaultSource implements Source { @@ -33,12 +35,18 @@ public class DefaultSource implements Source { } @Override - public long index() { - return (Long) json.get(0); + @CheckForNull + public Integer lineIndex() { + Object value = json.get(0); + if (value != null) { + return ((Long) value).intValue(); + } + return null; } @Override - public String line() { + @CheckForNull + public String lineAsHtml() { return (String) json.get(1); } } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/source/internal/DefaultSourceClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/source/internal/DefaultSourceClient.java index d5e0acffe26..db20901c1b1 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/source/internal/DefaultSourceClient.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/source/internal/DefaultSourceClient.java @@ -23,11 +23,7 @@ package org.sonar.wsclient.source.internal; import org.json.simple.JSONValue; import org.sonar.wsclient.internal.EncodingUtils; import org.sonar.wsclient.internal.HttpRequestFactory; -import org.sonar.wsclient.source.Scm; -import org.sonar.wsclient.source.Source; -import org.sonar.wsclient.source.SourceClient; - -import javax.annotation.Nullable; +import org.sonar.wsclient.source.*; import java.util.ArrayList; import java.util.List; @@ -42,8 +38,8 @@ public class DefaultSourceClient implements SourceClient { } @Override - public List<Source> show(String key, @Nullable String from, @Nullable String to) { - Map<String, Object> params = EncodingUtils.toMap("key", key, "from", from, "to", to); + public List<Source> show(SourceShowQuery query) { + Map<String, Object> params = EncodingUtils.toMap("key", query.key(), "from", query.from(), "to", query.to()); String json = requestFactory.get("/api/sources/show", params); List<Source> sources = new ArrayList<Source>(); @@ -58,9 +54,9 @@ public class DefaultSourceClient implements SourceClient { } @Override - public List<Scm> scm(String key, @Nullable String from, @Nullable String to, @Nullable Boolean groupCommits) { - Map<String, Object> params = EncodingUtils.toMap("key", key, "from", from, "to", to); - params.put("group_commits", groupCommits); + public List<Scm> scm(SourceScmQuery query) { + Map<String, Object> params = EncodingUtils.toMap("key", query.key(), "from", query.from(), "to", query.to()); + params.put("group_commits", query.groupCommits()); String json = requestFactory.get("/api/sources/scm", params); List<Scm> result = new ArrayList<Scm>(); |