diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-05-22 15:23:39 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-05-22 15:23:46 +0200 |
commit | 0d5c741914e8a4e1df63d231f55b472750e1098b (patch) | |
tree | d46ebc1b461f5d9f378f9ed83fbab17c2a6c7c37 /sonar-ws-client/src/main/java | |
parent | 51efc27c57f0943d247835189e882e31130a4f56 (diff) | |
download | sonarqube-0d5c741914e8a4e1df63d231f55b472750e1098b.tar.gz sonarqube-0d5c741914e8a4e1df63d231f55b472750e1098b.zip |
Add Java WS client for /api/coverage/show and /api/duplications/show
Diffstat (limited to 'sonar-ws-client/src/main/java')
17 files changed, 769 insertions, 0 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/SonarClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/SonarClient.java index beabf3d0735..51b594321dd 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/SonarClient.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/SonarClient.java @@ -19,6 +19,8 @@ */ package org.sonar.wsclient; +import org.sonar.wsclient.duplication.DuplicationClient; +import org.sonar.wsclient.duplication.internal.DefaultDuplicationClient; import org.sonar.wsclient.internal.HttpRequestFactory; import org.sonar.wsclient.issue.ActionPlanClient; import org.sonar.wsclient.issue.IssueClient; @@ -34,8 +36,12 @@ import org.sonar.wsclient.qualitygate.QualityGateClient; import org.sonar.wsclient.qualitygate.internal.DefaultQualityGateClient; import org.sonar.wsclient.rule.RuleClient; import org.sonar.wsclient.rule.internal.DefaultRuleClient; +import org.sonar.wsclient.source.SourceClient; +import org.sonar.wsclient.source.internal.DefaultSourceClient; import org.sonar.wsclient.system.SystemClient; import org.sonar.wsclient.system.internal.DefaultSystemClient; +import org.sonar.wsclient.test.CoverageClient; +import org.sonar.wsclient.test.internal.DefaultCoverageClient; import org.sonar.wsclient.user.UserClient; import org.sonar.wsclient.user.internal.DefaultUserClient; @@ -130,6 +136,26 @@ public class SonarClient { return new DefaultQProfileClient(requestFactory); } + /** + * New client to interact with web services related to source + */ + public SourceClient sourceClient() { + return new DefaultSourceClient(requestFactory); + } + + /** + * New client to interact with web services related to coverage + */ + public CoverageClient coverageClient() { + return new DefaultCoverageClient(requestFactory); + } + + /** + * New client to interact with web services related to duplication + */ + public DuplicationClient duplicationClient() { + return new DefaultDuplicationClient(requestFactory); + } public SystemClient systemClient() { return new DefaultSystemClient(requestFactory); diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/Block.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/Block.java new file mode 100644 index 00000000000..ef2e7250329 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/Block.java @@ -0,0 +1,39 @@ +/* + * 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.duplication; + +import javax.annotation.CheckForNull; + +/** + * @since 4.4 + */ +public interface Block { + + @CheckForNull + String fileRef(); + + @CheckForNull + Integer from(); + + @CheckForNull + Integer size(); + +} diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/Duplication.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/Duplication.java new file mode 100644 index 00000000000..9008afe835d --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/Duplication.java @@ -0,0 +1,32 @@ +/* + * 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.duplication; + +import java.util.List; + +/** + * @since 4.4 + */ +public interface Duplication { + + List<Block> blocks(); + +} diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/DuplicationClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/DuplicationClient.java new file mode 100644 index 00000000000..27f624b2ff4 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/DuplicationClient.java @@ -0,0 +1,32 @@ +/* + * 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.duplication; + +/** + * Display duplication information + * + * @since 4.4 + */ +public interface DuplicationClient { + + Duplications show(String componentKey); + +} diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/Duplications.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/Duplications.java new file mode 100644 index 00000000000..c7e927873af --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/Duplications.java @@ -0,0 +1,39 @@ +/* + * 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.duplication; + +import javax.annotation.CheckForNull; + +import java.util.List; + +/** + * @since 4.4 + */ +public interface Duplications { + + List<Duplication> duplications(); + + List<File> files(); + + @CheckForNull + File fileByRef(String ref); + +} diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/File.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/File.java new file mode 100644 index 00000000000..976f9a7ab90 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/File.java @@ -0,0 +1,39 @@ +/* + * 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.duplication; + +import javax.annotation.CheckForNull; + +/** + * @since 4.4 + */ +public interface File { + + @CheckForNull + String key(); + + @CheckForNull + String name(); + + @CheckForNull + String projectName(); + +} diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/internal/DefaultDuplicationClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/internal/DefaultDuplicationClient.java new file mode 100644 index 00000000000..b9dfe736c4e --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/internal/DefaultDuplicationClient.java @@ -0,0 +1,123 @@ +/* + * 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.duplication.internal; + +import org.json.simple.JSONValue; +import org.sonar.wsclient.duplication.*; +import org.sonar.wsclient.internal.EncodingUtils; +import org.sonar.wsclient.internal.HttpRequestFactory; +import org.sonar.wsclient.unmarshallers.JsonUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class DefaultDuplicationClient implements DuplicationClient { + + private final HttpRequestFactory requestFactory; + + public DefaultDuplicationClient(HttpRequestFactory requestFactory) { + this.requestFactory = requestFactory; + } + + @Override + public Duplications show(String componentKey) { + Map<String, Object> params = EncodingUtils.toMap("key", componentKey); + String jsonResult = requestFactory.get("/api/duplications/show", params); + + DefaultDuplications duplications = new DefaultDuplications(); + Map jRoot = (Map) JSONValue.parse(jsonResult); + parseDuplications(duplications, jRoot); + parseFiles(duplications, jRoot); + return duplications; + } + + private void parseDuplications(DefaultDuplications duplications, Map jRoot) { + List<Map> jsonDuplications = (List<Map>) jRoot.get("duplications"); + if (jsonDuplications != null) { + for (Map jsonDuplication : jsonDuplications) { + final List<Block> blockList = new ArrayList<Block>(); + + List<Map> blocks = (List<Map>) jsonDuplication.get("blocks"); + if (blocks != null) { + for (final Map block : blocks) { + + blockList.add((new Block() { + @Override + public String fileRef() { + return JsonUtils.getString(block, "_ref"); + } + + @Override + public Integer from() { + return JsonUtils.getInteger(block, "from"); + } + + @Override + public Integer size() { + return JsonUtils.getInteger(block, "size"); + } + })); + } + } + + Duplication duplication = new Duplication() { + @Override + public List<Block> blocks() { + return blockList; + } + }; + + duplications.addDuplication(duplication); + } + } + } + + private void parseFiles(DefaultDuplications duplications, Map jRoot) { + Map<String, Map> jsonFiles = (Map) jRoot.get("files"); + if (jsonFiles != null) { + for (Map.Entry<String, Map> entry : jsonFiles.entrySet()) { + String ref = entry.getKey(); + final Map file = entry.getValue(); + if (ref != null && file != null) { + + duplications.addFile(ref, new File() { + @Override + public String key () { + return JsonUtils.getString(file, "key"); + } + + @Override + public String name () { + return JsonUtils.getString(file, "name"); + } + + @Override + public String projectName () { + return JsonUtils.getString(file, "projectName"); + } + }); + + } + } + } + } +} diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/internal/DefaultDuplications.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/internal/DefaultDuplications.java new file mode 100644 index 00000000000..fefc8596825 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/internal/DefaultDuplications.java @@ -0,0 +1,62 @@ +/* + * 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.duplication.internal; + +import org.sonar.wsclient.duplication.Duplication; +import org.sonar.wsclient.duplication.Duplications; +import org.sonar.wsclient.duplication.File; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class DefaultDuplications implements Duplications { + + private final List<Duplication> duplications = new ArrayList<Duplication>(); + private final Map<String, File> files = new HashMap<String, File>(); + + @Override + public List<Duplication> duplications() { + return duplications; + } + + @Override + public List<File> files() { + return new ArrayList<File>(files.values()); + } + + @Override + public File fileByRef(String ref) { + return files.get(ref); + } + + DefaultDuplications addDuplication(Duplication duplication) { + duplications.add(duplication); + return this; + } + + DefaultDuplications addFile(String ref, File file) { + files.put(ref, file); + return this; + } + +} diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/internal/package-info.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/internal/package-info.java new file mode 100644 index 00000000000..9488f801b80 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/internal/package-info.java @@ -0,0 +1,24 @@ +/* + * 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. + */ + +@ParametersAreNonnullByDefault +package org.sonar.wsclient.duplication.internal; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/package-info.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/package-info.java new file mode 100644 index 00000000000..d703cacae42 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/duplication/package-info.java @@ -0,0 +1,24 @@ +/* + * 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. + */ + +@ParametersAreNonnullByDefault +package org.sonar.wsclient.duplication; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/test/Coverage.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/test/Coverage.java new file mode 100644 index 00000000000..b18c7edcd76 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/test/Coverage.java @@ -0,0 +1,45 @@ +/* + * 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.test; + +import javax.annotation.CheckForNull; + +/** + * @since 4.4 + */ +public interface Coverage { + + @CheckForNull + Integer lineIndex(); + + @CheckForNull + Boolean isCovered(); + + @CheckForNull + Integer tests(); + + @CheckForNull + Integer branches(); + + @CheckForNull + Integer coveredBranches(); + +} diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/test/CoverageClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/test/CoverageClient.java new file mode 100644 index 00000000000..97a28d7eb16 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/test/CoverageClient.java @@ -0,0 +1,34 @@ +/* + * 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.test; + +import java.util.List; + +/** + * Display coverage information + * + * @since 4.4 + */ +public interface CoverageClient { + + List<Coverage> show(CoverageShowQuery query); + +} diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/test/CoverageShowQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/test/CoverageShowQuery.java new file mode 100644 index 00000000000..092cfd51d92 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/test/CoverageShowQuery.java @@ -0,0 +1,80 @@ +/* + * 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.test; + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + +public class CoverageShowQuery { + + private String key; + private String from; + private String to; + private String type; + + private CoverageShowQuery() { + // Nothing here + } + + public String key() { + return key; + } + + public CoverageShowQuery setKey(String key) { + this.key = key; + return this; + } + + @CheckForNull + public String from() { + return from; + } + + public CoverageShowQuery setFrom(@Nullable String from) { + this.from = from; + return this; + } + + @CheckForNull + public String to() { + return to; + } + + public CoverageShowQuery setTo(@Nullable String to) { + this.to = to; + return this; + } + + @CheckForNull + public String type() { + return type; + } + + public CoverageShowQuery setType(@Nullable String type) { + this.type = type; + return this; + } + + public static CoverageShowQuery create(){ + return new CoverageShowQuery(); + } + +} diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/test/internal/DefaultCoverage.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/test/internal/DefaultCoverage.java new file mode 100644 index 00000000000..4c9e73d7a42 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/test/internal/DefaultCoverage.java @@ -0,0 +1,64 @@ +/* + * 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.test.internal; + +import org.sonar.wsclient.test.Coverage; + +import java.util.List; + +public class DefaultCoverage implements Coverage { + + private final List json; + + public DefaultCoverage(List json) { + this.json = json; + } + + @Override + public Integer lineIndex() { + Object value = json.get(0); + return value != null ? ((Long) value).intValue() : null; + } + + @Override + public Boolean isCovered() { + Object value = json.get(1); + return value != null ? (Boolean) value : null; + } + + @Override + public Integer tests() { + Object value = json.get(2); + return value != null ? ((Long) value).intValue() : null; + } + + @Override + public Integer branches() { + Object value = json.get(3); + return value != null ? ((Long) value).intValue() : null; + } + + @Override + public Integer coveredBranches() { + Object value = json.get(4); + return value != null ? ((Long) value).intValue() : null; + } +} diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/test/internal/DefaultCoverageClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/test/internal/DefaultCoverageClient.java new file mode 100644 index 00000000000..d5666045f21 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/test/internal/DefaultCoverageClient.java @@ -0,0 +1,58 @@ +/* + * 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.test.internal; + +import org.json.simple.JSONValue; +import org.sonar.wsclient.internal.EncodingUtils; +import org.sonar.wsclient.internal.HttpRequestFactory; +import org.sonar.wsclient.test.Coverage; +import org.sonar.wsclient.test.CoverageClient; +import org.sonar.wsclient.test.CoverageShowQuery; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class DefaultCoverageClient implements CoverageClient { + + private final HttpRequestFactory requestFactory; + + public DefaultCoverageClient(HttpRequestFactory requestFactory) { + this.requestFactory = requestFactory; + } + + @Override + public List<Coverage> show(CoverageShowQuery query) { + Map<String, Object> params = EncodingUtils.toMap("key", query.key(), "from", query.from(), "to", query.to(), "type", query.type()); + String jsonResult = requestFactory.get("/api/coverage/show", params); + + List<Coverage> coverages = new ArrayList<Coverage>(); + Map jRoot = (Map) JSONValue.parse(jsonResult); + List<List> jsonList = (List) jRoot.get("coverage"); + if (jsonList != null) { + for (List json : jsonList) { + coverages.add(new DefaultCoverage(json)); + } + } + return coverages; + } + +} diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/test/internal/package-info.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/test/internal/package-info.java new file mode 100644 index 00000000000..e7ae755dea6 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/test/internal/package-info.java @@ -0,0 +1,24 @@ +/* + * 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. + */ + +@ParametersAreNonnullByDefault +package org.sonar.wsclient.test.internal; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/test/package-info.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/test/package-info.java new file mode 100644 index 00000000000..578e47ce73b --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/test/package-info.java @@ -0,0 +1,24 @@ +/* + * 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. + */ + +@ParametersAreNonnullByDefault +package org.sonar.wsclient.test; + +import javax.annotation.ParametersAreNonnullByDefault; |