protected void configureModule() {
add(
CeWs.class,
+ ActivityAction.class,
CancelAction.class,
CancelAllAction.class,
QueueAction.class,
SubmitAction.class,
TaskFormatter.class,
TaskAction.class,
- ActivityAction.class);
+ TaskTypesAction.class);
}
}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+{
+ "taskTypes": [
+ "REPORT",
+ "DEV_REFRESH",
+ "DEV_PURGE",
+ "VIEW_REFRESH"
+ ]
+}
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 */);
}
}
--- /dev/null
+/*
+ * 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();
+ }
+ }
+
+}
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;
ActivityResponse.parser());
}
+ public TaskTypesWsResponse taskTypes() {
+ return call(new GetRequest(path("task_types")), TaskTypesWsResponse.parser());
+ }
+
}
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;
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;
CeService underTest = serviceTester.getInstanceUnderTest();
@Test
- public void search() {
+ public void activity() {
ActivityWsRequest request = new ActivityWsRequest()
.setComponentId(VALUE_COMPONENT_ID)
.setComponentQuery(VALUE_COMPONENT_QUERY)
.hasParam("ps", 1)
.andNoOtherParam();
}
+
+ @Test
+ public void task_types() {
+ underTest.taskTypes();
+
+ assertThat(serviceTester.getGetParser()).isSameAs(WsCe.TaskTypesWsResponse.parser());
+ }
}