diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-01-18 18:02:33 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-01-18 20:47:59 +0100 |
commit | e0aaf832d06c079f2cd9d643e9ac857d65d1d262 (patch) | |
tree | 486a9510bac1f06c7089a0803306c4a688084e02 /server | |
parent | 29b386604e338b8ec560b5615cbdb5346dccf09e (diff) | |
download | sonarqube-e0aaf832d06c079f2cd9d643e9ac857d65d1d262.tar.gz sonarqube-e0aaf832d06c079f2cd9d643e9ac857d65d1d262.zip |
Remove unused RubyRuleService
and the associated deprecated ES utilities
Diffstat (limited to 'server')
7 files changed, 0 insertions, 507 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/paging/PagedResult.java b/server/sonar-server/src/main/java/org/sonar/server/paging/PagedResult.java deleted file mode 100644 index d89d9cb9fd7..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/paging/PagedResult.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.paging; - -import java.util.Collection; - -/** - * @deprecated use {@link org.sonar.server.search.Result} - */ -@Deprecated -public class PagedResult<T> { - - private Collection<T> results; - - private PagingResult paging; - - public PagedResult(Collection<T> results, PagingResult paging) { - this.results = results; - this.paging = paging; - } - - public Collection<T> results() { - return this.results; - } - - public PagingResult paging() { - return this.paging; - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/paging/Paging.java b/server/sonar-server/src/main/java/org/sonar/server/paging/Paging.java deleted file mode 100644 index be1ac2e9a53..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/paging/Paging.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.paging; - -/** - * Heavily inspired by {@link org.sonar.api.utils.Paging} - * @since 4.2 - * @deprecated use {@link org.sonar.server.search.Result} - */ -@Deprecated -public class Paging { - - private final int pageSize; - private final int pageIndex; - - protected Paging(int pageSize, int pageIndex) { - this.pageSize = pageSize; - this.pageIndex = pageIndex; - } - - /** - * Page index, starting with 1. - */ - public int pageIndex() { - return pageIndex; - } - - /** - * Maximum number of items per page. It is greater than 0. - */ - public int pageSize() { - return pageSize; - } - - public int offset(){ - return (pageIndex - 1) * pageSize; - } - - public static Paging create(int pageSize, int pageIndex) { - checkPageSize(pageSize); - checkPageIndex(pageIndex); - return new Paging(pageSize, pageIndex); - } - - protected static void checkPageIndex(int pageIndex) { - if (pageIndex<1) { - throw new IllegalArgumentException("Page index must be strictly positive. Got " + pageIndex); - } - } - - protected static void checkPageSize(int pageSize) { - if (pageSize<1) { - throw new IllegalArgumentException("Page size must be strictly positive. Got " + pageSize); - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/paging/PagingResult.java b/server/sonar-server/src/main/java/org/sonar/server/paging/PagingResult.java deleted file mode 100644 index 1955a02f038..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/paging/PagingResult.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.paging; - -/** - * Heavily inspired by {@link org.sonar.api.utils.Paging} - * - * @since 4.2 - * @deprecated use {@link org.sonar.server.search.Result} - */ -@Deprecated -public class PagingResult extends Paging { - - private final long total; - - private PagingResult(int pageSize, int pageIndex, long total) { - super(pageSize, pageIndex); - this.total = total; - } - - /** - * Number of pages. It is greater than or equal 0. - */ - public long pages() { - long p = total / pageSize(); - if (total % pageSize() > 0) { - p++; - } - return p; - } - - public boolean hasNextPage() { - return pageIndex() < pages(); - } - - /** - * Total number of items. It is greater than or equal 0. - */ - public long total() { - return total; - } - - public static PagingResult create(int pageSize, int pageIndex, long totalItems) { - checkPageSize(pageSize); - checkPageIndex(pageIndex); - checkTotalItems(totalItems); - - return new PagingResult(pageSize, pageIndex, totalItems); - } - - protected static void checkTotalItems(long totalItems) { - if (totalItems < 0) { - throw new IllegalArgumentException("Total items must be positive. Got " + totalItems); - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index 63d1b8e5d30..2630320711e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -160,7 +160,6 @@ import org.sonar.server.root.ws.RootWsModule; import org.sonar.server.rule.CommonRuleDefinitionsImpl; import org.sonar.server.rule.DefaultRuleFinder; import org.sonar.server.rule.DeprecatedRulesDefinitionLoader; -import org.sonar.server.rule.RubyRuleService; import org.sonar.server.rule.RuleCreator; import org.sonar.server.rule.RuleDefinitionsLoader; import org.sonar.server.rule.RuleDeleter; @@ -285,7 +284,6 @@ public class PlatformLevel4 extends PlatformLevel { XMLRuleParser.class, DefaultRuleFinder.class, RuleOperations.class, - RubyRuleService.class, DeprecatedRulesDefinitionLoader.class, RuleDefinitionsLoader.class, CommonRuleDefinitionsImpl.class, diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java b/server/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java deleted file mode 100644 index cc51cfc1dd0..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * 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.rule; - -import com.google.common.base.Strings; -import java.util.List; -import java.util.Map; -import javax.annotation.CheckForNull; -import org.picocontainer.Startable; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.rule.RuleStatus; -import org.sonar.api.server.ServerSide; -import org.sonar.api.server.debt.DebtRemediationFunction; -import org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction; -import org.sonar.db.DbClient; -import org.sonar.db.DbSession; -import org.sonar.db.rule.RuleDto; -import org.sonar.server.es.SearchIdResult; -import org.sonar.server.es.SearchOptions; -import org.sonar.server.paging.PagedResult; -import org.sonar.server.paging.PagingResult; -import org.sonar.server.rule.index.RuleIndexDefinition; -import org.sonar.server.rule.index.RuleQuery; -import org.sonar.server.user.UserSession; -import org.sonar.server.util.RubyUtils; - -/** - * Used through ruby code <pre>Internal.rules</pre> - * - * @deprecated in 4.4 because Ruby on Rails is deprecated too ! - */ -@Deprecated -@ServerSide -public class RubyRuleService implements Startable { - - private final DbClient dbClient; - private final RuleService service; - private final RuleUpdater updater; - private final UserSession userSession; - - public RubyRuleService(DbClient dbClient, RuleService service, RuleUpdater updater, UserSession userSession) { - this.dbClient = dbClient; - this.service = service; - this.updater = updater; - this.userSession = userSession; - } - - /** - * Used in issues_controller.rb and in manual_rules_controller.rb and in SQALE - */ - @CheckForNull - public RuleDto findByKey(String ruleKey) { - DbSession dbSession = dbClient.openSession(false); - try { - return dbClient.ruleDao().selectByKey(dbSession, RuleKey.parse(ruleKey)).orNull(); - } finally { - dbClient.closeSession(dbSession); - } - } - - /** - * Used in SQALE - */ - public PagedResult<RuleDto> find(Map<String, Object> params) { - RuleQuery query = new RuleQuery(); - query.setQueryText(Strings.emptyToNull((String) params.get("searchQuery"))); - query.setKey(Strings.emptyToNull((String) params.get("key"))); - query.setLanguages(RubyUtils.toStrings(params.get("languages"))); - query.setRepositories(RubyUtils.toStrings(params.get("repositories"))); - query.setSeverities(RubyUtils.toStrings(params.get("severities"))); - query.setStatuses(RubyUtils.toEnums(params.get("statuses"), RuleStatus.class)); - query.setTags(RubyUtils.toStrings(params.get("tags"))); - query.setSortField(RuleIndexDefinition.FIELD_RULE_NAME); - String profile = Strings.emptyToNull((String) params.get("profile")); - if (profile != null) { - query.setQProfileKey(profile); - query.setActivation(true); - } - - SearchOptions options = new SearchOptions(); - Integer pageSize = RubyUtils.toInteger(params.get("pageSize")); - int size = pageSize != null ? pageSize : 50; - Integer page = RubyUtils.toInteger(params.get("p")); - int pageIndex = page != null ? page : 1; - options.setPage(pageIndex, size); - SearchIdResult<RuleKey> result = service.search(query, options); - List<RuleDto> ruleDtos = loadDtos(result.getIds()); - return new PagedResult<>(ruleDtos, PagingResult.create(options.getLimit(), pageIndex, result.getTotal())); - } - - // sqale - public void updateRule(Map<String, Object> params) { - RuleUpdate update = RuleUpdate.createForPluginRule(RuleKey.parse((String) params.get("ruleKey"))); - String fn = (String) params.get("debtRemediationFunction"); - if (fn == null) { - update.setDebtRemediationFunction(null); - } else { - update.setDebtRemediationFunction(new DefaultDebtRemediationFunction( - DebtRemediationFunction.Type.valueOf(fn), - Strings.emptyToNull((String) params.get("debtRemediationCoefficient")), - Strings.emptyToNull((String) params.get("debtRemediationOffset")))); - } - updater.update(update, userSession); - } - - private List<RuleDto> loadDtos(List<RuleKey> ruleKeys) { - DbSession dbSession = dbClient.openSession(false); - try { - return dbClient.ruleDao().selectByKeys(dbSession, ruleKeys); - } finally { - dbClient.closeSession(dbSession); - } - } - - @Override - public void start() { - // used to force pico to instantiate the singleton at startup - } - - @Override - public void stop() { - // implement startable - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java deleted file mode 100644 index 5e6163923a3..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * 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.rule; - -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableMap; -import java.util.HashMap; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.rule.RuleStatus; -import org.sonar.api.server.ws.WebService.Param; -import org.sonar.db.DbClient; -import org.sonar.db.DbSession; -import org.sonar.db.rule.RuleDao; -import org.sonar.db.rule.RuleDto; -import org.sonar.db.rule.RuleTesting; -import org.sonar.server.es.SearchIdResult; -import org.sonar.server.es.SearchOptions; -import org.sonar.server.rule.index.RuleQuery; -import org.sonar.server.tester.UserSessionRule; -import org.sonar.server.user.ThreadLocalUserSession; - -import static com.google.common.collect.Maps.newHashMap; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -@RunWith(MockitoJUnitRunner.class) -public class RubyRuleServiceTest { - - @org.junit.Rule - public UserSessionRule userSessionRule = UserSessionRule.standalone(); - - @Mock - RuleService ruleService; - - @Mock - DbClient dbClient; - - @Mock - DbSession dbSession; - - @Mock - RuleDao ruleDao; - - @Mock - RuleUpdater updater; - - @Captor - ArgumentCaptor<SearchOptions> optionsCaptor; - - @Captor - ArgumentCaptor<RuleQuery> ruleQueryCaptor; - - RubyRuleService service; - - @Before - public void setUp() { - when(dbClient.openSession(false)).thenReturn(dbSession); - when(dbClient.ruleDao()).thenReturn(ruleDao); - service = new RubyRuleService(dbClient, ruleService, updater, userSessionRule); - } - - @Test - public void find_by_key() { - RuleKey ruleKey = RuleKey.of("squid", "S001"); - RuleDto ruleDto = RuleTesting.newXooX1(); - - when(ruleDao.selectByKey(dbSession, ruleKey)).thenReturn(Optional.of(ruleDto)); - - assertThat(service.findByKey("squid:S001")).isEqualTo(ruleDto); - } - - @Test - public void search_rules() { - when(ruleService.search(any(RuleQuery.class), any(SearchOptions.class))).thenReturn(mock(SearchIdResult.class)); - - HashMap<String, Object> params = newHashMap(); - params.put("searchQuery", "Exception"); - params.put("key", "S001"); - params.put("languages", "xoo,js"); - params.put("repositories", "checkstyle,pmd"); - params.put("severities", "MAJOR,MINOR"); - params.put("statuses", "BETA,READY"); - params.put("tags", "tag1,tag2"); - params.put(Param.PAGE, "1"); - params.put("pageSize", "40"); - service.find(params); - - verify(ruleService).search(ruleQueryCaptor.capture(), optionsCaptor.capture()); - - assertThat(ruleQueryCaptor.getValue().getQueryText()).isEqualTo("Exception"); - assertThat(ruleQueryCaptor.getValue().getKey()).isEqualTo("S001"); - assertThat(ruleQueryCaptor.getValue().getLanguages()).containsOnly("xoo", "js"); - assertThat(ruleQueryCaptor.getValue().getRepositories()).containsOnly("checkstyle", "pmd"); - assertThat(ruleQueryCaptor.getValue().getRepositories()).containsOnly("checkstyle", "pmd"); - assertThat(ruleQueryCaptor.getValue().getSeverities()).containsOnly("MAJOR", "MINOR"); - assertThat(ruleQueryCaptor.getValue().getStatuses()).containsOnly(RuleStatus.BETA, RuleStatus.READY); - assertThat(ruleQueryCaptor.getValue().getTags()).containsOnly("tag1", "tag2"); - assertThat(ruleQueryCaptor.getValue().getQProfileKey()).isNull(); - assertThat(ruleQueryCaptor.getValue().getActivation()).isNull(); - - assertThat(optionsCaptor.getValue().getLimit()).isEqualTo(40); - assertThat(optionsCaptor.getValue().getOffset()).isEqualTo(0); - } - - @Test - public void search_rules_activated_on_a_profile() { - when(ruleService.search(any(RuleQuery.class), any(SearchOptions.class))).thenReturn(mock(SearchIdResult.class)); - - HashMap<String, Object> params = newHashMap(); - params.put("profile", "xoo-profile"); - service.find(params); - - verify(ruleService).search(ruleQueryCaptor.capture(), optionsCaptor.capture()); - - assertThat(ruleQueryCaptor.getValue().getQProfileKey()).isEqualTo("xoo-profile"); - assertThat(ruleQueryCaptor.getValue().getActivation()).isTrue(); - } - - @Test - public void search_rules_without_page_size_param() { - when(ruleService.search(any(RuleQuery.class), any(SearchOptions.class))).thenReturn(mock(SearchIdResult.class)); - - HashMap<String, Object> params = newHashMap(); - params.put(Param.PAGE, "1"); - service.find(params); - - verify(ruleService).search(ruleQueryCaptor.capture(), optionsCaptor.capture()); - - assertThat(optionsCaptor.getValue().getLimit()).isEqualTo(50); - assertThat(optionsCaptor.getValue().getOffset()).isEqualTo(0); - } - - @Test - public void update_rule() { - when(ruleService.search(any(RuleQuery.class), any(SearchOptions.class))).thenReturn(mock(SearchIdResult.class)); - - service.updateRule(ImmutableMap.<String, Object>of("ruleKey", "squid:S001")); - - verify(updater).update(any(RuleUpdate.class), any(ThreadLocalUserSession.class)); - } -} diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/internal.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/internal.rb index 845152751e6..8bbf4897aaa 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/internal.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/internal.rb @@ -62,10 +62,6 @@ class Internal component(Java::OrgSonarServerQualitygate::QualityGates.java_class) end - def self.rules - component(Java::OrgSonarServerRule::RubyRuleService.java_class) - end - def self.durations component(Java::OrgSonarApiUtils::Durations.java_class) end |