]> source.dussan.org Git - sonarqube.git/commitdiff
Drop WS api/sources/index
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 31 Aug 2015 13:16:46 +0000 (15:16 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 4 Sep 2015 13:14:36 +0000 (15:14 +0200)
This WS is not used and is marked as internal, so it can be dropped

server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
server/sonar-server/src/main/java/org/sonar/server/source/ws/IndexAction.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/source/ws/IndexActionTest.java [deleted file]

index 62a58ce92a4ce4a400e7832e1decd5aa231bbf06..74deea4d98d8344411c2fb020c71d32ccd9894ec 100644 (file)
@@ -272,7 +272,6 @@ import org.sonar.server.rule.ws.TagsAction;
 import org.sonar.server.source.HtmlSourceDecorator;
 import org.sonar.server.source.SourceService;
 import org.sonar.server.source.ws.HashAction;
-import org.sonar.server.source.ws.IndexAction;
 import org.sonar.server.source.ws.LinesAction;
 import org.sonar.server.source.ws.RawAction;
 import org.sonar.server.source.ws.ScmAction;
@@ -645,7 +644,6 @@ public class PlatformLevel4 extends PlatformLevel {
       LinesAction.class,
       HashAction.class,
       RawAction.class,
-      IndexAction.class,
       ScmAction.class,
 
     // Duplications
diff --git a/server/sonar-server/src/main/java/org/sonar/server/source/ws/IndexAction.java b/server/sonar-server/src/main/java/org/sonar/server/source/ws/IndexAction.java
deleted file mode 100644 (file)
index 8a5612b..0000000
+++ /dev/null
@@ -1,94 +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.server.source.ws;
-
-import com.google.common.io.Resources;
-import java.util.List;
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.Response;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.api.web.UserRole;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.server.component.ComponentFinder;
-import org.sonar.server.source.SourceService;
-import org.sonar.server.user.UserSession;
-
-public class IndexAction implements SourcesWsAction {
-
-  private final DbClient dbClient;
-  private final SourceService sourceService;
-  private final UserSession userSession;
-  private final ComponentFinder componentFinder;
-
-  public IndexAction(DbClient dbClient, SourceService sourceService, UserSession userSession, ComponentFinder componentFinder) {
-    this.dbClient = dbClient;
-    this.sourceService = sourceService;
-    this.userSession = userSession;
-    this.componentFinder = componentFinder;
-  }
-
-  @Override
-  public void define(WebService.NewController controller) {
-    WebService.NewAction action = controller.createAction("index")
-      .setDescription("Get source code as line number / text pairs. Require See Source Code permission on file")
-      .setSince("5.0")
-      .setResponseExample(Resources.getResource(getClass(), "example-index.json"))
-      .setInternal(true)
-      .setHandler(this);
-
-    action
-      .createParam("resource")
-      .setRequired(true)
-      .setDescription("File key")
-      .setExampleValue("my_project:/src/foo/Bar.php");
-
-    action
-      .createParam("from")
-      .setDefaultValue(1)
-      .setDescription("First line");
-
-    action
-      .createParam("to")
-      .setDescription("Last line (excluded). If not specified, all lines are returned until end of file");
-  }
-
-  @Override
-  public void handle(Request request, Response response) {
-    String fileKey = request.mandatoryParam("resource");
-    userSession.checkComponentPermission(UserRole.CODEVIEWER, fileKey);
-    Integer from = request.mandatoryParamAsInt("from");
-    Integer to = request.paramAsInt("to");
-    try (DbSession session = dbClient.openSession(false)) {
-      ComponentDto componentDto = componentFinder.getByKey(session, fileKey);
-      List<String> lines = sourceService.getLinesAsTxt(componentDto.uuid(), from, to == null ? null : to - 1);
-      JsonWriter json = response.newJsonWriter().beginArray().beginObject();
-      Integer lineCounter = from;
-      for (String line : lines) {
-        json.prop(lineCounter.toString(), line);
-        lineCounter++;
-      }
-      json.endObject().endArray().close();
-    }
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/ws/IndexActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/ws/IndexActionTest.java
deleted file mode 100644 (file)
index 7a18f0e..0000000
+++ /dev/null
@@ -1,126 +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.server.source.ws;
-
-import com.google.common.base.Optional;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.web.UserRole;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.component.ComponentDao;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.server.component.ComponentFinder;
-import org.sonar.db.component.ComponentTesting;
-import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.source.SourceService;
-import org.sonar.server.tester.UserSessionRule;
-import org.sonar.server.ws.WsTester;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class IndexActionTest {
-
-  @Rule
-  public UserSessionRule userSessionRule = UserSessionRule.standalone();
-
-  @Mock
-  DbClient dbClient;
-
-  @Mock
-  DbSession session;
-
-  @Mock
-  ComponentDao componentDao;
-
-  @Mock
-  SourceService sourceService;
-
-  WsTester tester;
-
-  ComponentDto project = ComponentTesting.newProjectDto();
-  ComponentDto file = ComponentTesting.newFileDto(project);
-
-  @Before
-  public void setUp() {
-    when(dbClient.componentDao()).thenReturn(componentDao);
-    when(dbClient.openSession(false)).thenReturn(session);
-    tester = new WsTester(new SourcesWs(new IndexAction(dbClient, sourceService, userSessionRule, new ComponentFinder(dbClient))));
-  }
-
-  @Test
-  public void get_json() throws Exception {
-    String fileKey = "src/Foo.java";
-    userSessionRule.addComponentPermission(UserRole.CODEVIEWER, "polop", fileKey);
-    when(componentDao.selectByKey(session, fileKey)).thenReturn(Optional.of(file));
-
-    when(sourceService.getLinesAsTxt(file.uuid(), 1, null)).thenReturn(newArrayList(
-      "public class HelloWorld {",
-      "}"
-    ));
-
-    WsTester.TestRequest request = tester.newGetRequest("api/sources", "index").setParam("resource", fileKey);
-    request.execute().assertJson(this.getClass(), "index-result.json");
-  }
-
-  @Test
-  public void limit_range() throws Exception {
-    String fileKey = "src/Foo.java";
-    userSessionRule.addComponentPermission(UserRole.CODEVIEWER, "polop", fileKey);
-    when(componentDao.selectByKey(session, fileKey)).thenReturn(Optional.of(file));
-
-    when(sourceService.getLinesAsTxt(file.uuid(), 1, 2)).thenReturn(newArrayList(
-      "public class HelloWorld {",
-      "}"
-    ));
-
-    WsTester.TestRequest request = tester.newGetRequest("api/sources", "index")
-      .setParam("resource", fileKey).setParam("from", "1").setParam("to", "3");
-    request.execute().assertJson(this.getClass(), "index-result.json");
-  }
-
-  @Test(expected = ForbiddenException.class)
-  public void requires_code_viewer_permission() throws Exception {
-    tester.newGetRequest("api/sources", "index").setParam("resource", "any").execute();
-  }
-
-  @Test
-  public void close_db_session() throws Exception {
-    String fileKey = "src/Foo.java";
-    userSessionRule.addComponentPermission(UserRole.CODEVIEWER, "polop", fileKey);
-    when(componentDao.selectByKey(session, fileKey)).thenReturn(Optional.<ComponentDto>absent());
-
-    WsTester.TestRequest request = tester.newGetRequest("api/sources", "index").setParam("resource", fileKey);
-    try {
-      request.execute();
-    } catch (NotFoundException nfe) {
-      verify(session).close();
-    }
-  }
-}