]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7319 WS api/ce/task_types list CE task types
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Mon, 15 Feb 2016 09:16:39 +0000 (10:16 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Mon, 15 Feb 2016 13:24:41 +0000 (14:24 +0100)
server/sonar-server/src/main/java/org/sonar/server/computation/ws/CeWsModule.java
server/sonar-server/src/main/java/org/sonar/server/computation/ws/TaskTypesAction.java [new file with mode: 0644]
server/sonar-server/src/main/resources/org/sonar/server/computation/ws/task_types-example.json [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/computation/ws/CeWsModuleTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/ws/TaskTypesActionTest.java [new file with mode: 0644]
sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java
sonar-ws/src/main/protobuf/ws-ce.proto
sonar-ws/src/test/java/org/sonarqube/ws/client/ce/CeServiceTest.java

index edc04a1202e45c8121cfbd1035351fb3a4d09849..76e06f1ce7af70c2fda1e7014d8ccdc9395f904b 100644 (file)
@@ -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 (file)
index 0000000..392c844
--- /dev/null
@@ -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 (file)
index 0000000..6dd3019
--- /dev/null
@@ -0,0 +1,8 @@
+{
+  "taskTypes": [
+    "REPORT",
+    "DEV_REFRESH",
+    "DEV_PURGE",
+    "VIEW_REFRESH"
+  ]
+}
index 5186c1a4f41c4fed97cabc202e635e65be5a4ba6..d4878ad772d01d5b785e6f117a9be2970e384e80 100644 (file)
@@ -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 (file)
index 0000000..1706293
--- /dev/null
@@ -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();
+    }
+  }
+
+}
index b11cfdfb60ecf3b1649a6648c122ec66e698271a..66aa65812ed8c276d1c8b78e7afbd08a1c37fc23 100644 (file)
@@ -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());
+  }
+
 }
index 9c27b02f4c9d7ca8a4f4dc0718aced6f5a74c4c5..8a8a3f8503695fc3bc43f849a7e4df23cb530383 100644 (file)
@@ -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;
index d7094f7549504864c5aecc7d8b3a4fce02c119fe..f93004ffcbc21bc9d003d51900ae3f5c0bee812a 100644 (file)
@@ -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());
+  }
 }