diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-11-18 14:50:59 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-11-18 16:53:43 +0100 |
commit | d715d5a98dec5cc34f6f642d5d1a3a7dcec1724b (patch) | |
tree | 617cef38b66b1bd148df937dea36dad2c65c67ae /sonar-batch | |
parent | d544f09c60de180096db0965a0deefe63937976d (diff) | |
download | sonarqube-d715d5a98dec5cc34f6f642d5d1a3a7dcec1724b.tar.gz sonarqube-d715d5a98dec5cc34f6f642d5d1a3a7dcec1724b.zip |
Move views task back into views
Diffstat (limited to 'sonar-batch')
3 files changed, 1 insertions, 104 deletions
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.<String, String>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() |