aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-02-15 10:16:39 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-02-15 14:24:41 +0100
commite1700f3dc7d4b52d62d0ac707eeeaace0f5ad772 (patch)
tree6f6aaa39dbb34115e09d99dcbcbcecc034917873
parent2679df38cca5c450b163ebaad139c435fddc14ca (diff)
downloadsonarqube-e1700f3dc7d4b52d62d0ac707eeeaace0f5ad772.tar.gz
sonarqube-e1700f3dc7d4b52d62d0ac707eeeaace0f5ad772.zip
SONAR-7319 WS api/ce/task_types list CE task types
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/ws/CeWsModule.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/ws/TaskTypesAction.java62
-rw-r--r--server/sonar-server/src/main/resources/org/sonar/server/computation/ws/task_types-example.json8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/ws/CeWsModuleTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/ws/TaskTypesActionTest.java66
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java5
-rw-r--r--sonar-ws/src/main/protobuf/ws-ce.proto5
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/ce/CeServiceTest.java10
8 files changed, 158 insertions, 3 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ws/CeWsModule.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ws/CeWsModule.java
index edc04a1202e..76e06f1ce7a 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/ws/CeWsModule.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ws/CeWsModule.java
@@ -26,6 +26,7 @@ public class CeWsModule extends Module {
protected void configureModule() {
add(
CeWs.class,
+ ActivityAction.class,
CancelAction.class,
CancelAllAction.class,
QueueAction.class,
@@ -35,6 +36,6 @@ public class CeWsModule extends Module {
SubmitAction.class,
TaskFormatter.class,
TaskAction.class,
- ActivityAction.class);
+ TaskTypesAction.class);
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ws/TaskTypesAction.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ws/TaskTypesAction.java
new file mode 100644
index 00000000000..392c84448e0
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ws/TaskTypesAction.java
@@ -0,0 +1,62 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.server.computation.ws;
+
+import com.google.common.collect.ImmutableSet;
+import java.util.Set;
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.server.computation.taskprocessor.CeTaskProcessor;
+import org.sonarqube.ws.WsCe;
+
+import static org.sonar.server.ws.WsUtils.writeProtobuf;
+
+public class TaskTypesAction implements CeWsAction {
+ private final Set<String> taskTypes;
+
+ public TaskTypesAction(CeTaskProcessor[] taskProcessors) {
+ ImmutableSet.Builder<String> taskTypesBuilder = ImmutableSet.builder();
+ for (CeTaskProcessor taskProcessor : taskProcessors) {
+ taskTypesBuilder.addAll(taskProcessor.getHandledCeTaskTypes());
+ }
+ this.taskTypes = taskTypesBuilder.build();
+ }
+
+ @Override
+ public void define(WebService.NewController controller) {
+ controller.createAction("task_types")
+ .setDescription("List available task types")
+ .setResponseExample(getClass().getResource("task_types-example.json"))
+ .setSince("5.5")
+ .setInternal(true)
+ .setHandler(this);
+ }
+
+ @Override
+ public void handle(Request request, Response response) throws Exception {
+ WsCe.TaskTypesWsResponse taskTypesWsResponse = WsCe.TaskTypesWsResponse.newBuilder()
+ .addAllTaskTypes(taskTypes)
+ .build();
+
+ writeProtobuf(taskTypesWsResponse, request, response);
+ }
+}
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/computation/ws/task_types-example.json b/server/sonar-server/src/main/resources/org/sonar/server/computation/ws/task_types-example.json
new file mode 100644
index 00000000000..6dd30192bea
--- /dev/null
+++ b/server/sonar-server/src/main/resources/org/sonar/server/computation/ws/task_types-example.json
@@ -0,0 +1,8 @@
+{
+ "taskTypes": [
+ "REPORT",
+ "DEV_REFRESH",
+ "DEV_PURGE",
+ "VIEW_REFRESH"
+ ]
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ws/CeWsModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ws/CeWsModuleTest.java
index 5186c1a4f41..d4878ad772d 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/ws/CeWsModuleTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/ws/CeWsModuleTest.java
@@ -30,6 +30,6 @@ public class CeWsModuleTest {
public void verify_count_of_added_components() {
ComponentContainer container = new ComponentContainer();
new CeWsModule().configure(container);
- assertThat(container.size()).isEqualTo(11 + 2 /* injected by ComponentContainer */);
+ assertThat(container.size()).isEqualTo(12 + 2 /* injected by ComponentContainer */);
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ws/TaskTypesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ws/TaskTypesActionTest.java
new file mode 100644
index 00000000000..17062932b49
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/ws/TaskTypesActionTest.java
@@ -0,0 +1,66 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.server.computation.ws;
+
+import com.google.common.collect.ImmutableSet;
+import java.util.Set;
+import org.junit.Test;
+import org.sonar.server.computation.queue.CeTask;
+import org.sonar.server.computation.queue.CeTaskResult;
+import org.sonar.server.computation.taskprocessor.CeTaskProcessor;
+import org.sonar.server.ws.WsActionTester;
+
+import static org.sonar.test.JsonAssert.assertJson;
+
+public class TaskTypesActionTest {
+
+ WsActionTester ws = new WsActionTester(new TaskTypesAction(new CeTaskProcessor[] {
+ new FakeCeTaskProcessor("REPORT"),
+ new FakeCeTaskProcessor("DEV_REFRESH", "DEV_PURGE"),
+ new FakeCeTaskProcessor("VIEW_REFRESH")
+ }));
+
+ @Test
+ public void json_example() {
+ String response = ws.newRequest().execute().getInput();
+
+ assertJson(response).isSimilarTo(getClass().getResource("task_types-example.json"));
+ }
+
+ private static class FakeCeTaskProcessor implements CeTaskProcessor {
+ private final Set<String> taskTypes;
+
+ private FakeCeTaskProcessor(String... taskTypes) {
+ this.taskTypes = ImmutableSet.copyOf(taskTypes);
+ }
+
+ @Override
+ public Set<String> getHandledCeTaskTypes() {
+ return taskTypes;
+ }
+
+ @Override
+ public CeTaskResult process(CeTask task) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java
index b11cfdfb60e..66aa65812ed 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java
@@ -21,6 +21,7 @@
package org.sonarqube.ws.client.ce;
import org.sonarqube.ws.WsCe.ActivityResponse;
+import org.sonarqube.ws.WsCe.TaskTypesWsResponse;
import org.sonarqube.ws.client.BaseService;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.WsConnector;
@@ -54,4 +55,8 @@ public class CeService extends BaseService {
ActivityResponse.parser());
}
+ public TaskTypesWsResponse taskTypes() {
+ return call(new GetRequest(path("task_types")), TaskTypesWsResponse.parser());
+ }
+
}
diff --git a/sonar-ws/src/main/protobuf/ws-ce.proto b/sonar-ws/src/main/protobuf/ws-ce.proto
index 9c27b02f4c9..8a8a3f85036 100644
--- a/sonar-ws/src/main/protobuf/ws-ce.proto
+++ b/sonar-ws/src/main/protobuf/ws-ce.proto
@@ -54,6 +54,11 @@ message ProjectResponse {
optional Task current = 2;
}
+// GET api/ce/task_types
+message TaskTypesWsResponse {
+ repeated string taskTypes = 1;
+}
+
message Task {
optional string id = 1;
optional string type = 2;
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/ce/CeServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/ce/CeServiceTest.java
index d7094f75495..f93004ffcbc 100644
--- a/sonar-ws/src/test/java/org/sonarqube/ws/client/ce/CeServiceTest.java
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/ce/CeServiceTest.java
@@ -23,6 +23,7 @@ package org.sonarqube.ws.client.ce;
import com.google.common.collect.ImmutableList;
import org.junit.Rule;
import org.junit.Test;
+import org.sonarqube.ws.WsCe;
import org.sonarqube.ws.WsCe.ActivityResponse;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.ServiceTester;
@@ -56,7 +57,7 @@ public class CeServiceTest {
CeService underTest = serviceTester.getInstanceUnderTest();
@Test
- public void search() {
+ public void activity() {
ActivityWsRequest request = new ActivityWsRequest()
.setComponentId(VALUE_COMPONENT_ID)
.setComponentQuery(VALUE_COMPONENT_QUERY)
@@ -87,4 +88,11 @@ public class CeServiceTest {
.hasParam("ps", 1)
.andNoOtherParam();
}
+
+ @Test
+ public void task_types() {
+ underTest.taskTypes();
+
+ assertThat(serviceTester.getGetParser()).isSameAs(WsCe.TaskTypesWsResponse.parser());
+ }
}