public interface Scm {
- long index();
+ @CheckForNull
+ Integer lineIndex();
@CheckForNull
String author();
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();
}
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);
}
--- /dev/null
+/*
+ * 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();
+ }
+}
--- /dev/null
+/*
+ * 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();
+ }
+
+}
}
@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() {
import org.sonar.wsclient.source.Source;
+import javax.annotation.CheckForNull;
+
import java.util.List;
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);
}
}
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;
}
@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>();
}
@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>();
import org.junit.Test;
import org.sonar.wsclient.MockHttpServerInterceptor;
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 org.sonar.wsclient.source.*;
import java.io.IOException;
import java.util.List;
httpServer.stubResponseBody(Resources.toString(Resources.getResource(this.getClass(), "DefaultSourceClientTest/show_source.json"), Charsets.UTF_8));
SourceClient client = new DefaultSourceClient(requestFactory);
- List<Source> sources = client.show("MyFile", "20", "25");
+ List<Source> sources = client.show(SourceShowQuery.create().setKey("MyFile").setFrom("20").setTo("25"));
assertThat(httpServer.requestedPath()).isEqualTo("/api/sources/show?key=MyFile&from=20&to=25");
assertThat(sources).hasSize(6);
- assertThat(sources.get(0).index()).isEqualTo(20);
- assertThat(sources.get(0).line()).isEqualTo("<span class=\"k\">package </span>org.sonar.check;");
+ assertThat(sources.get(0).lineIndex()).isEqualTo(20);
+ assertThat(sources.get(0).lineAsHtml()).isEqualTo("<span class=\"k\">package </span>org.sonar.check;");
}
@Test
httpServer.stubResponseBody(Resources.toString(Resources.getResource(this.getClass(), "DefaultSourceClientTest/return_scm.json"), Charsets.UTF_8));
SourceClient client = new DefaultSourceClient(requestFactory);
- List<Scm> result = client.scm("MyFile", "1", "3", true);
+ List<Scm> result = client.scm(SourceScmQuery.create().setKey("MyFile").setFrom("1").setTo("3").setGroupCommits(true));
assertThat(httpServer.requestedPath()).isEqualTo("/api/sources/scm?key=MyFile&from=1&to=3&group_commits=true");
assertThat(result).hasSize(3);
- assertThat(result.get(0).index()).isEqualTo(1);
+ assertThat(result.get(0).lineIndex()).isEqualTo(1);
assertThat(result.get(0).author()).isEqualTo("julien");
assertThat(result.get(0).date().getTime()).isEqualTo(1363129200000L);
}