From d715d5a98dec5cc34f6f642d5d1a3a7dcec1724b Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Wed, 18 Nov 2015 14:50:59 +0100 Subject: Move views task back into views --- .../org/sonar/batch/bootstrap/BatchComponents.java | 5 +- .../main/java/org/sonar/batch/task/ViewsTask.java | 85 ---------------------- .../batch/mediumtest/tasks/TasksMediumTest.java | 15 ---- 3 files changed, 1 insertion(+), 104 deletions(-) delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/task/ViewsTask.java diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java index 526d2aada6c..9c3cfaf78f4 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java @@ -38,7 +38,6 @@ import org.sonar.batch.source.LinesSensor; import org.sonar.batch.task.ListTask; import org.sonar.batch.task.ScanTask; import org.sonar.batch.task.Tasks; -import org.sonar.batch.task.ViewsTask; import org.sonar.core.component.DefaultResourceTypes; import org.sonar.core.config.CorePropertyDefinitions; import org.sonar.core.issue.tracking.Tracker; @@ -74,9 +73,7 @@ public class BatchComponents { ListTask.DEFINITION, ListTask.class, ScanTask.DEFINITION, - ScanTask.class, - ViewsTask.DEFINITION, - ViewsTask.class); + ScanTask.class); components.addAll(CorePropertyDefinitions.all()); // CPD components.addAll(CpdComponents.all()); diff --git a/sonar-batch/src/main/java/org/sonar/batch/task/ViewsTask.java b/sonar-batch/src/main/java/org/sonar/batch/task/ViewsTask.java deleted file mode 100644 index c9d8bd173a2..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/task/ViewsTask.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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.batch.task; - -import com.github.kevinsawicki.http.HttpRequest; -import java.net.MalformedURLException; -import java.net.URL; -import org.sonar.api.CoreProperties; -import org.sonar.api.platform.Server; -import org.sonar.api.task.Task; -import org.sonar.api.task.TaskDefinition; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.batch.bootstrap.ServerClient; - -import static java.lang.String.format; - -public class ViewsTask implements Task { - - private static final Logger LOG = Loggers.get(ViewsTask.class); - - public static final String KEY = "views"; - - public static final TaskDefinition DEFINITION = TaskDefinition.builder() - .key(KEY) - .description("Trigger Views update") - .taskClass(ViewsTask.class) - .build(); - - private final ServerClient serverClient; - private final Server server; - - public ViewsTask(ServerClient serverClient, Server server) { - this.serverClient = serverClient; - this.server = server; - } - - @Override - public void execute() { - LOG.info("Trigger Views update"); - URL url; - try { - url = new URL(serverClient.getURL() + "/api/views/run"); - } catch (MalformedURLException e) { - throw new IllegalArgumentException("Invalid URL", e); - } - HttpRequest request = HttpRequest.post(url); - request.trustAllCerts(); - request.trustAllHosts(); - request.header("User-Agent", format("SonarQube %s", server.getVersion())); - request.basic(serverClient.getLogin(), serverClient.getPassword()); - if (!request.ok()) { - int responseCode = request.code(); - if (responseCode == 401) { - throw new IllegalStateException(format(serverClient.getMessageWhenNotAuthorized(), CoreProperties.LOGIN, CoreProperties.PASSWORD)); - } - if (responseCode == 409) { - throw new IllegalStateException("A full refresh of Views is already queued or running"); - } - if (responseCode == 403) { - // SONAR-4397 Details are in response content - throw new IllegalStateException(request.body()); - } - throw new IllegalStateException(format("Fail to execute request [code=%s, url=%s]: %s", responseCode, url, request.body())); - } - } - -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/tasks/TasksMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/tasks/TasksMediumTest.java index 0195a075fcd..ec151f29874 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/tasks/TasksMediumTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/tasks/TasksMediumTest.java @@ -95,21 +95,6 @@ public class TasksMediumTest { .start(); } - @Test - public void triggerViews() throws Exception { - startServer(200, "OK"); - tester = BatchMediumTester.builder() - .bootstrapProperties(ImmutableMap.of("sonar.host.url", "http://localhost:" + server.getPort())) - .build(); - tester.start(); - tester.newTask() - .properties(ImmutableMap.builder() - .put("sonar.task", "views").build()) - .start(); - - assertThat(logTester.logs()).contains("Trigger Views update"); - } - @Test(expected = MessageException.class) public void unsupportedTask() throws Exception { tester = BatchMediumTester.builder() -- cgit v1.2.3