aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-05-15 14:52:25 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-05-15 14:52:35 +0200
commitdcc95840ae5f64cfc50d8bb27ffd3ffdb20496b9 (patch)
treec03bda9923dc3f02990c79548addea8ba3416a01
parent3d333b6bfd8a75bdb03e72ef761d451500315247 (diff)
downloadsonarqube-dcc95840ae5f64cfc50d8bb27ffd3ffdb20496b9.tar.gz
sonarqube-dcc95840ae5f64cfc50d8bb27ffd3ffdb20496b9.zip
SONAR-5007 drop tables RULE_TAGS and RULES_RULE_TAGS
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java7
-rw-r--r--sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java57
-rw-r--r--sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java10
-rw-r--r--sonar-core/src/main/java/org/sonar/core/rule/RuleRuleTagDto.java85
-rw-r--r--sonar-core/src/main/java/org/sonar/core/rule/RuleTagDao.java106
-rw-r--r--sonar-core/src/main/java/org/sonar/core/rule/RuleTagDto.java50
-rw-r--r--sonar-core/src/main/java/org/sonar/core/rule/RuleTagMapper.java35
-rw-r--r--sonar-core/src/main/java/org/sonar/core/rule/RuleTagType.java25
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql1
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl13
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml35
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/rule/RuleTagMapper.xml31
-rw-r--r--sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java14
-rw-r--r--sonar-core/src/test/java/org/sonar/core/rule/RuleTagDaoTest.java75
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_tags_by_rule_id.xml11
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_tags_by_rule_ids.xml11
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/delete-result.xml7
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/insert-result.xml9
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/select-unused.xml15
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/shared.xml8
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java9
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/ESRuleTags.java102
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java597
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java4
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/RuleOperations.java98
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/RuleRegistry.java36
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/RuleTagDocument.java33
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/RuleTagLookup.java41
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/RuleTagOperations.java88
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/RuleTags.java49
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/Rules.java9
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/ws/AbstractUpdateTagsWsHandler.java63
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/ws/AddTagsWsHandler.java41
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/ws/RemoveTagsWsHandler.java41
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/ws/RuleTagsWs.java92
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/ws/RulesWs.java23
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule2/RegisterRules.java14
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule2/index/RuleIndexDefinition.java7
-rw-r--r--sonar-server/src/main/java/org/sonar/server/search/Result.java4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/internal.rb4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/537_drop_rule_tags_tables.rb77
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule/ESRuleTagsTest.java149
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java6
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule/RuleOperationsTest.java96
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule/RuleRegistryTest.java12
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule/RuleTagLookupTest.java42
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule/RuleTagOperationsTest.java117
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule/RuleTagsTest.java72
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule/RulesTest.java21
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule/ws/AddTagsWsHandlerTest.java90
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule/ws/RemoveTagsWsHandlerTest.java84
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule/ws/RuleSearchWsHandlerTest.java2
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule/ws/RuleShowWsHandlerTest.java2
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule/ws/RuleTagsWsTest.java104
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsTest.java26
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule2/RegisterRulesMediumTest.java117
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule2/RegisterRulesTest.java15
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule2/persistence/RuleDaoTest.java12
-rw-r--r--sonar-server/src/test/java/org/sonar/server/tester/DataStoreCleanup.java10
-rw-r--r--sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java7
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_repositories-result.xml3
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_rules-result.xml8
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_rules.xml6
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/insert_new_rules-result.xml8
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/update_rule_fields-result.xml10
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/update_rule_fields.xml10
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/ws/RuleTagsWsTest/create_ok.json1
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/ws/RuleTagsWsTest/list.json1
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule2/RegisterRulesTest/disable_deprecated_repositories-result.xml3
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule2/persistence/RuleDaoTest/select_tags_by_rule_id.xml13
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule2/persistence/RuleDaoTest/select_tags_by_rule_ids.xml11
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/SonarClient.java9
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/rule/RuleTagClient.java39
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/rule/internal/DefaultRuleTagClient.java59
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/SonarClientTest.java2
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/rule/internal/DefaultRuleTagClientTest.java67
78 files changed, 253 insertions, 3024 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java b/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java
index bcccf44a798..5c3e7b9ab73 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java
@@ -38,7 +38,6 @@ import org.sonar.core.resource.ResourceDao;
import org.sonar.core.resource.ResourceIndexerDao;
import org.sonar.core.resource.ResourceKeyUpdaterDao;
import org.sonar.core.rule.RuleDao;
-import org.sonar.core.rule.RuleTagDao;
import org.sonar.core.source.db.SnapshotDataDao;
import org.sonar.core.source.db.SnapshotSourceDao;
import org.sonar.core.technicaldebt.db.CharacteristicDao;
@@ -87,7 +86,6 @@ public final class DaoUtils {
ResourceKeyUpdaterDao.class,
RoleDao.class,
RuleDao.class,
- RuleTagDao.class,
SemaphoreDao.class,
SnapshotDataDao.class,
SnapshotSourceDao.class,
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
index 2b125c1ff7a..d18002ce859 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
@@ -33,7 +33,7 @@ import java.util.List;
*/
public class DatabaseVersion implements BatchComponent, ServerComponent {
- public static final int LAST_VERSION = 536;
+ public static final int LAST_VERSION = 537;
public static enum Status {
UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL
@@ -84,8 +84,6 @@ public class DatabaseVersion implements BatchComponent, ServerComponent {
"rules",
"rules_parameters",
"rules_profiles",
- "rule_tags",
- "rules_rule_tags",
"semaphores",
"schema_migrations",
"snapshots",
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
index e113adbe9ab..8998f8da543 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
@@ -105,9 +105,6 @@ import org.sonar.core.resource.SnapshotDto;
import org.sonar.core.rule.RuleDto;
import org.sonar.core.rule.RuleMapper;
import org.sonar.core.rule.RuleParamDto;
-import org.sonar.core.rule.RuleRuleTagDto;
-import org.sonar.core.rule.RuleTagDto;
-import org.sonar.core.rule.RuleTagMapper;
import org.sonar.core.source.db.SnapshotDataDto;
import org.sonar.core.source.db.SnapshotDataMapper;
import org.sonar.core.source.db.SnapshotSourceMapper;
@@ -178,8 +175,6 @@ public class MyBatis implements BatchComponent, ServerComponent {
loadAlias(conf, "ResourceSnapshot", ResourceSnapshotDto.class);
loadAlias(conf, "Rule", RuleDto.class);
loadAlias(conf, "RuleParam", RuleParamDto.class);
- loadAlias(conf, "RuleTag", RuleTagDto.class);
- loadAlias(conf, "RuleRuleTag", RuleRuleTagDto.class);
loadAlias(conf, "Snapshot", SnapshotDto.class);
loadAlias(conf, "Semaphore", SemaphoreDto.class);
loadAlias(conf, "SchemaMigration", SchemaMigrationDto.class);
@@ -220,7 +215,7 @@ public class MyBatis implements BatchComponent, ServerComponent {
ResourceKeyUpdaterMapper.class, ResourceIndexerMapper.class, ResourceSnapshotMapper.class, RoleMapper.class, RuleMapper.class,
SchemaMigrationMapper.class, SemaphoreMapper.class, UserMapper.class, WidgetMapper.class, WidgetPropertyMapper.class,
MeasureMapper.class, SnapshotDataMapper.class, SnapshotSourceMapper.class, ActionPlanMapper.class, ActionPlanStatsMapper.class,
- NotificationQueueMapper.class, CharacteristicMapper.class, RuleTagMapper.class,
+ NotificationQueueMapper.class, CharacteristicMapper.class,
GroupMembershipMapper.class, QualityProfileMapper.class, ActiveRuleMapper.class,
MeasureDataMapper.class, QualityGateMapper.class, QualityGateConditionMapper.class, ComponentMapper.class, ProjectQgateAssociationMapper.class,
RequirementMapper.class
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java
index 3b5677fc9b9..b46bde45fe3 100644
--- a/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java
@@ -27,7 +27,6 @@ import org.sonar.api.rule.RuleKey;
import org.sonar.core.persistence.MyBatis;
import javax.annotation.CheckForNull;
-
import java.util.Collection;
import java.util.List;
@@ -251,60 +250,4 @@ public class RuleDao implements BatchComponent, ServerComponent {
private RuleMapper getMapper(SqlSession session) {
return session.getMapper(RuleMapper.class);
}
-
- //***************************
- // Methods for Rule Tags
- //***************************
-
-
- public void insert(RuleRuleTagDto newTag, SqlSession session) {
- getMapper(session).insertTag(newTag);
- }
-
- public void deleteParam(RuleParamDto persistedParam, SqlSession sqlSession) {
- getMapper(sqlSession).deleteParameter(persistedParam.getId());
- }
-
- public void deleteTag(RuleRuleTagDto tagToDelete, SqlSession session) {
- getMapper(session).deleteTag(tagToDelete.getId().intValue());
- }
-
- public void update(RuleRuleTagDto existingTag, SqlSession session) {
- getMapper(session).updateTag(existingTag);
- }
-
- public List<RuleRuleTagDto> selectTags(SqlSession session) {
- return getMapper(session).selectAllTags();
- }
-
- public List<RuleRuleTagDto> selectTagsByRuleId(Integer ruleId) {
- SqlSession session = mybatis.openSession();
- try {
- return selectTagsByRuleIds(ruleId, session);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public List<RuleRuleTagDto> selectTagsByRuleIds(Integer ruleId, SqlSession session) {
- return selectTagsByRuleIds(newArrayList(ruleId), session);
- }
-
- public List<RuleRuleTagDto> selectTagsByRuleIds(List<Integer> ruleIds) {
- SqlSession session = mybatis.openSession();
- try {
- return selectTagsByRuleIds(ruleIds, session);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public List<RuleRuleTagDto> selectTagsByRuleIds(List<Integer> ruleIds, SqlSession session) {
- List<RuleRuleTagDto> dtos = newArrayList();
- List<List<Integer>> partitionList = Lists.partition(newArrayList(ruleIds), 1000);
- for (List<Integer> partition : partitionList) {
- dtos.addAll(getMapper(session).selectTagsByRuleIds(partition));
- }
- return dtos;
- }
}
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java
index 9ee3d44e23c..5aeb9fbfaa7 100644
--- a/sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java
@@ -60,14 +60,4 @@ public interface RuleMapper {
void deleteParameter(Integer paramId);
- List<RuleRuleTagDto> selectAllTags();
-
- void insertTag(RuleRuleTagDto newTag);
-
- void deleteTag(Integer tagId);
-
- void updateTag(RuleRuleTagDto existingTag);
-
- List<RuleRuleTagDto> selectTagsByRuleIds(@Param("ruleIds") List<Integer> ruleIds);
-
}
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleRuleTagDto.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleRuleTagDto.java
deleted file mode 100644
index b2058b3650c..00000000000
--- a/sonar-core/src/main/java/org/sonar/core/rule/RuleRuleTagDto.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.core.rule;
-
-
-public class RuleRuleTagDto {
-
- private Long id;
- private Integer ruleId;
- private Long tagId;
- private String tag;
- private String type;
-
- public Long getId() {
- return id;
- }
-
- public RuleRuleTagDto setId(Long id) {
- this.id = id;
- return this;
- }
-
- public Integer getRuleId() {
- return ruleId;
- }
-
- public RuleRuleTagDto setRuleId(Integer ruleId) {
- this.ruleId = ruleId;
- return this;
- }
-
- public Long getTagId() {
- return tagId;
- }
-
- public RuleRuleTagDto setTagId(Long tagId) {
- this.tagId = tagId;
- return this;
- }
-
- public String getTag() {
- return tag;
- }
-
- public RuleRuleTagDto setTag(String tag) {
- this.tag = tag;
- return this;
- }
-
- public RuleTagType getType() {
- return RuleTagType.valueOf(type);
- }
-
- public RuleRuleTagDto setType(RuleTagType type) {
- this.type = type.name();
- return this;
- }
-
- @Override
- public String toString() {
- return String.format("RuleRuleTag[id=%d, ruleId=%d, tagId=%d, tag=%s, type=%s]",
- id, ruleId, tagId, tag, type);
- }
-
- public boolean isSystemTag(){
- return this.getType().equals(RuleTagType.SYSTEM);
- }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleTagDao.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleTagDao.java
deleted file mode 100644
index ab227644610..00000000000
--- a/sonar-core/src/main/java/org/sonar/core/rule/RuleTagDao.java
+++ /dev/null
@@ -1,106 +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.core.rule;
-
-import org.apache.ibatis.session.SqlSession;
-import org.sonar.api.ServerExtension;
-import org.sonar.core.persistence.MyBatis;
-
-import java.util.List;
-
-public class RuleTagDao implements ServerExtension {
-
- private final MyBatis myBatis;
-
- public RuleTagDao(MyBatis myBatis) {
- this.myBatis = myBatis;
- }
-
- public List<RuleTagDto> selectAll() {
- SqlSession session = myBatis.openSession(false);
- try {
- return selectAll(session);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public List<RuleTagDto> selectAll(SqlSession session) {
- return getMapper(session).selectAll();
- }
-
- public void insert(RuleTagDto newRuleTag) {
- SqlSession session = myBatis.openSession(false);
- try {
- insert(newRuleTag, session);
- session.commit();
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public void insert(RuleTagDto newRuleTag, SqlSession session) {
- getMapper(session).insert(newRuleTag);
- }
-
- public void delete(Long tagId) {
- SqlSession session = myBatis.openSession(false);
- try {
- delete(tagId, session);
- session.commit();
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public void delete(long tagId, SqlSession session) {
- getMapper(session).delete(tagId);
- }
-
- public Long selectId(String tag) {
- SqlSession session = myBatis.openSession(false);
- try {
- return selectId(tag, session);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public Long selectId(String tag, SqlSession session) {
- return getMapper(session).selectId(tag);
- }
-
- public List<RuleTagDto> selectUnused() {
- SqlSession session = myBatis.openSession(false);
- try {
- return selectUnused(session);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public List<RuleTagDto> selectUnused(SqlSession session) {
- return getMapper(session).selectUnused();
- }
-
- private RuleTagMapper getMapper(SqlSession session) {
- return session.getMapper(RuleTagMapper.class);
- }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleTagDto.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleTagDto.java
deleted file mode 100644
index 39da820c2e1..00000000000
--- a/sonar-core/src/main/java/org/sonar/core/rule/RuleTagDto.java
+++ /dev/null
@@ -1,50 +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.core.rule;
-
-
-public class RuleTagDto {
-
- private Long id;
- private String tag;
-
- public Long getId() {
- return id;
- }
-
- public RuleTagDto setId(Long id) {
- this.id = id;
- return this;
- }
-
- public String getTag() {
- return tag;
- }
-
- public RuleTagDto setTag(String tag) {
- this.tag = tag;
- return this;
- }
-
- @Override
- public String toString() {
- return String.format("RuleTag[id=%d, tag=%s]", id, tag);
- }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleTagMapper.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleTagMapper.java
deleted file mode 100644
index 7eb52ec1adf..00000000000
--- a/sonar-core/src/main/java/org/sonar/core/rule/RuleTagMapper.java
+++ /dev/null
@@ -1,35 +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.core.rule;
-
-import java.util.List;
-
-public interface RuleTagMapper {
-
- List<RuleTagDto> selectAll();
-
- void insert(RuleTagDto newTag);
-
- void delete(Long tagId);
-
- Long selectId(String tag);
-
- List<RuleTagDto> selectUnused();
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleTagType.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleTagType.java
deleted file mode 100644
index 8c94549ed0f..00000000000
--- a/sonar-core/src/main/java/org/sonar/core/rule/RuleTagType.java
+++ /dev/null
@@ -1,25 +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.core.rule;
-
-public enum RuleTagType {
-
- SYSTEM, ADMIN;
-}
diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
index e6e974e9d54..acf291ae4ce 100644
--- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
+++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
@@ -232,6 +232,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('533');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('534');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('535');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('536');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('537');
INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null);
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
index 7871f4f5e6b..962392da0ed 100644
--- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
+++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
@@ -163,17 +163,6 @@ CREATE TABLE "RULES" (
"UPDATED_AT" TIMESTAMP
);
-CREATE TABLE "RULE_TAGS" (
- "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
- "TAG" VARCHAR(100) NOT NULL
-);
-
-CREATE TABLE "RULES_RULE_TAGS" (
- "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
- "RULE_ID" INTEGER NOT NULL,
- "RULE_TAG_ID" INTEGER NOT NULL,
- "TAG_TYPE" VARCHAR (20) NOT NULL
-);
CREATE TABLE "WIDGET_PROPERTIES" (
"ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
@@ -692,8 +681,6 @@ CREATE INDEX "GROUP_ROLES_ROLE" ON "GROUP_ROLES" ("ROLE");
CREATE UNIQUE INDEX "RULES_PLUGIN_KEY_AND_NAME" ON "RULES" ("PLUGIN_RULE_KEY", "PLUGIN_NAME");
-CREATE UNIQUE INDEX "RULE_TAGS_UNIQUE" ON "RULES_RULE_TAGS" ("RULE_ID", "RULE_TAG_ID");
-
CREATE INDEX "CHARACTERISTICS_ENABLED" ON "CHARACTERISTICS" ("ENABLED");
CREATE UNIQUE INDEX "QUALITY_GATES_UNIQUE" ON "QUALITY_GATES" ("NAME");
diff --git a/sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml b/sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml
index 66a330b03b6..643d7b5c712 100644
--- a/sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml
@@ -185,41 +185,6 @@
WHERE id=#{id}
</update>
- <sql id="tagColumns">
- rrt.id, rrt.rule_id as "ruleId", rrt.rule_tag_id as "tagId", rrt.tag_type as "type", rt.tag
- </sql>
-
- <select id="selectAllTags" resultType="RuleRuleTag">
- SELECT <include refid="tagColumns"/>
- FROM rules_rule_tags rrt
- JOIN rule_tags rt ON rrt.rule_tag_id = rt.id
- </select>
-
- <select id="selectTagsByRuleIds" resultType="RuleRuleTag">
- SELECT <include refid="tagColumns"/>
- FROM rules_rule_tags rrt
- JOIN rule_tags rt ON rrt.rule_tag_id = rt.id
- <where>
- AND (<foreach item="id" index="index" collection="ruleIds" open="(" separator=" or " close=")">rrt.rule_id=#{id}</foreach>)
- </where>
- </select>
-
- <insert id="insertTag" parameterType="RuleRuleTag" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
- INSERT INTO rules_rule_tags (rule_id, rule_tag_id, tag_type)
- VALUES (#{ruleId}, #{tagId}, #{type})
- </insert>
-
- <update id="updateTag" parameterType="RuleRuleTag">
- UPDATE rules_rule_tags
- SET tag_type=#{type}
- WHERE id=#{id}
- </update>
-
- <update id="deleteTag" parameterType="Integer">
- DELETE FROM rules_rule_tags WHERE id=#{tagId}
- </update>
-
-
<select id="selectKeysOfRulesUpdatedSince" resultType="map">
SELECT r.plugin_name as "repo", r.plugin_rule_key as "rule"
FROM rules r
diff --git a/sonar-core/src/main/resources/org/sonar/core/rule/RuleTagMapper.xml b/sonar-core/src/main/resources/org/sonar/core/rule/RuleTagMapper.xml
deleted file mode 100644
index 5fb61f62a50..00000000000
--- a/sonar-core/src/main/resources/org/sonar/core/rule/RuleTagMapper.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.core.rule.RuleTagMapper">
-
- <select id="selectAll" resultType="RuleTag">
- SELECT id, tag
- FROM rule_tags
- </select>
-
- <insert id="insert" parameterType="RuleTag" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
- INSERT INTO rule_tags (tag)
- VALUES (#{tag})
- </insert>
-
- <update id="delete" parameterType="Integer">
- DELETE FROM rule_tags WHERE id=#{tagId}
- </update>
-
- <select id="selectId" resultType="Long" parameterType="String">
- SELECT id
- FROM rule_tags
- WHERE tag=#{tag}
- </select>
-
- <select id="selectUnused" resultType="RuleTag">
- SELECT r.id, r.tag FROM rule_tags r LEFT JOIN rules_rule_tags rr ON rr.rule_tag_id = r.id WHERE rr.rule_id IS NULL
- </select>
-
-</mapper>
-
diff --git a/sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java b/sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java
index 9cd518afedb..8b0c63095db 100644
--- a/sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java
@@ -357,20 +357,6 @@ public class RuleDaoTest extends AbstractDaoTestCase {
checkTables("update_parameter", "rules_parameters");
}
- @Test
- public void select_tags_by_rule_id() throws Exception {
- setupData("select_tags_by_rule_id");
-
- assertThat(dao.selectTagsByRuleId(3)).hasSize(2);
- }
-
- @Test
- public void select_tags_by_rule_ids() throws Exception {
- setupData("select_tags_by_rule_ids");
-
- assertThat(dao.selectTagsByRuleIds(newArrayList(3, 4))).hasSize(3);
- }
-
private List<Integer> idsFromRuleDtos(List<RuleDto> ruleDtos){
return newArrayList(Iterables.transform(ruleDtos, new Function<RuleDto, Integer>() {
@Override
diff --git a/sonar-core/src/test/java/org/sonar/core/rule/RuleTagDaoTest.java b/sonar-core/src/test/java/org/sonar/core/rule/RuleTagDaoTest.java
deleted file mode 100644
index d7aab3a002f..00000000000
--- a/sonar-core/src/test/java/org/sonar/core/rule/RuleTagDaoTest.java
+++ /dev/null
@@ -1,75 +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.core.rule;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.core.persistence.AbstractDaoTestCase;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class RuleTagDaoTest extends AbstractDaoTestCase {
-
- RuleTagDao dao;
-
- @Before
- public void createDao() {
- dao = new RuleTagDao(getMyBatis());
- }
-
- @Test
- public void should_select_all_tags() {
- setupData("shared");
-
- assertThat(dao.selectAll()).hasSize(3);
- }
-
- @Test
- public void should_select_id() {
- setupData("shared");
-
- assertThat(dao.selectId("tag1")).isEqualTo(1L);
- assertThat(dao.selectId("unknown")).isNull();
- }
-
- @Test
- public void should_insert_tag() {
- setupData("shared");
-
- dao.insert(new RuleTagDto().setTag("tag4"));
- checkTable("insert", "rule_tags");
- }
-
- @Test
- public void should_delete_tag() {
- setupData("shared");
-
- dao.delete(1L);
- checkTable("delete", "rule_tags");
- }
-
- @Test
- public void should_select_unused_tags() {
- setupData("select-unused");
-
- assertThat(dao.selectUnused()).hasSize(2);
- }
-
-}
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_tags_by_rule_id.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_tags_by_rule_id.xml
deleted file mode 100644
index 8d252e540b4..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_tags_by_rule_id.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<dataset>
-
- <rule_tags id="3" tag="tag1"/>
- <rule_tags id="4" tag="tag3"/>
- <rule_tags id="5" tag="tag5"/>
-
- <rules_rule_tags id="3" rule_id="3" rule_tag_id="3" tag_type="SYSTEM"/>
- <rules_rule_tags id="4" rule_id="3" rule_tag_id="4" tag_type="SYSTEM"/>
- <rules_rule_tags id="5" rule_id="4" rule_tag_id="5" tag_type="SYSTEM"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_tags_by_rule_ids.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_tags_by_rule_ids.xml
deleted file mode 100644
index 8d252e540b4..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_tags_by_rule_ids.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<dataset>
-
- <rule_tags id="3" tag="tag1"/>
- <rule_tags id="4" tag="tag3"/>
- <rule_tags id="5" tag="tag5"/>
-
- <rules_rule_tags id="3" rule_id="3" rule_tag_id="3" tag_type="SYSTEM"/>
- <rules_rule_tags id="4" rule_id="3" rule_tag_id="4" tag_type="SYSTEM"/>
- <rules_rule_tags id="5" rule_id="4" rule_tag_id="5" tag_type="SYSTEM"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/delete-result.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/delete-result.xml
deleted file mode 100644
index 8c9c2d034f9..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/delete-result.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<dataset>
-
- <rule_tags id="2" tag="tag2"/>
- <rule_tags id="3" tag="tag3"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/insert-result.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/insert-result.xml
deleted file mode 100644
index 3b805137bdd..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/insert-result.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<dataset>
-
- <rule_tags id="1" tag="tag1"/>
- <rule_tags id="2" tag="tag2"/>
- <rule_tags id="3" tag="tag3"/>
- <rule_tags id="4" tag="tag4"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/select-unused.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/select-unused.xml
deleted file mode 100644
index dcae0d0f74e..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/select-unused.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<dataset>
-
- <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="rule1" plugin_name="fake" plugin_config_key="old_config_key" name="old name" description="old description"
- status="READY" priority="2" cardinality="SINGLE" parent_id="[null]" />
-
- <rule_tags id="1" tag="tag1"/>
- <rule_tags id="2" tag="tag2"/>
- <rule_tags id="3" tag="tag3"/>
- <rule_tags id="4" tag="tag4"/>
-
- <rules_rule_tags id="1" rule_id="1" rule_tag_id="1" tag_type="ADMIN"/>
- <rules_rule_tags id="2" rule_id="1" rule_tag_id="2" tag_type="SYSTEM"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/shared.xml
deleted file mode 100644
index e7085790921..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/shared.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<dataset>
-
- <rule_tags id="1" tag="tag1"/>
- <rule_tags id="2" tag="tag2"/>
- <rule_tags id="3" tag="tag3"/>
-
-</dataset>
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java b/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
index 9bfaf3e41c0..335dbabe63a 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
@@ -326,8 +326,6 @@ class ServerComponents {
pico.addSingleton(RulesWs.class);
pico.addSingleton(RuleShowWsHandler.class);
pico.addSingleton(RuleSearchWsHandler.class);
- pico.addSingleton(AddTagsWsHandler.class);
- pico.addSingleton(RemoveTagsWsHandler.class);
pico.addSingleton(RulesDefinitionXmlLoader.class);
// experimental rules
@@ -339,13 +337,6 @@ class ServerComponents {
pico.addSingleton(SetTagsAction.class);
pico.addSingleton(org.sonar.server.rule2.ws.AppAction.class);
- // rule tags
- pico.addSingleton(ESRuleTags.class);
- pico.addSingleton(RuleTagLookup.class);
- pico.addSingleton(RuleTagOperations.class);
- pico.addSingleton(RuleTags.class);
- pico.addSingleton(RuleTagsWs.class);
-
// measure
pico.addComponent(MeasuresDao.class, false);
pico.addSingleton(MeasureFilterFactory.class);
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/ESRuleTags.java b/sonar-server/src/main/java/org/sonar/server/rule/ESRuleTags.java
deleted file mode 100644
index 2c08117aea8..00000000000
--- a/sonar-server/src/main/java/org/sonar/server/rule/ESRuleTags.java
+++ /dev/null
@@ -1,102 +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.rule;
-
-import org.elasticsearch.common.io.BytesStream;
-import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentFactory;
-import org.elasticsearch.index.query.FilterBuilders;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.elasticsearch.search.sort.SortOrder;
-import org.sonar.core.rule.RuleTagDto;
-import org.sonar.server.es.ESIndex;
-
-import java.io.IOException;
-import java.util.Collection;
-
-/**
- * @deprecated to be dropped in 4.4
- */
-@Deprecated
-public class ESRuleTags {
-
- public static final String TYPE_TAG = "tag";
-
- private final ESIndex index;
-
- public ESRuleTags(ESIndex index) {
- this.index = index;
- }
-
- public void start() {
- index.addMappingFromClasspath(RuleRegistry.INDEX_RULES, TYPE_TAG, "/org/sonar/server/es/config/mappings/tag_mapping.json");
- }
-
- public void putAllTags(Collection<RuleTagDto> tags) {
- String[] ids = new String[tags.size()];
- try {
- if (!tags.isEmpty()) {
- BytesStream[] sources = new BytesStream[tags.size()];
- int tagCounter = 0;
- for (RuleTagDto tag: tags) {
- ids[tagCounter] = tag.getTag();
- sources[tagCounter] = ruleTagDocument(tag);
- tagCounter ++;
- }
- index.bulkIndex(RuleRegistry.INDEX_RULES, TYPE_TAG, ids, sources);
- }
- index.client().prepareDeleteByQuery(RuleRegistry.INDEX_RULES).setTypes(TYPE_TAG)
- .setQuery(
- QueryBuilders.filteredQuery(
- QueryBuilders.matchAllQuery(),
- FilterBuilders.notFilter(
- FilterBuilders.termsFilter(RuleTagDocument.FIELD_VALUE, ids))))
- .execute().actionGet();
- } catch(IOException ioException) {
- throw new IllegalStateException("Unable to index tags", ioException);
- }
- }
-
- public void put(RuleTagDto tag) {
- try {
- index.putSynchronous(RuleRegistry.INDEX_RULES, TYPE_TAG, tag.getTag(), ruleTagDocument(tag));
- } catch (IOException ioException) {
- throw new IllegalStateException("Unable to index tag "+tag.getTag(), ioException);
- }
- }
-
- public Collection<String> searchAllTags() {
- final int scrollSize = 50;
- return index.findDocumentIds(index.client().prepareSearch(RuleRegistry.INDEX_RULES)
- .setTypes(TYPE_TAG)
- .addSort(RuleTagDocument.FIELD_VALUE, SortOrder.ASC), scrollSize);
- }
-
- private XContentBuilder ruleTagDocument(RuleTagDto tag) throws IOException {
- return XContentFactory.jsonBuilder()
- .startObject()
- .field(RuleTagDocument.FIELD_VALUE, tag.getTag())
- .endObject();
- }
-
- public void delete(String... deleted) {
- index.bulkDelete(RuleRegistry.INDEX_RULES, TYPE_TAG, deleted);
- }
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java b/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
deleted file mode 100644
index 84c9c48ce83..00000000000
--- a/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
+++ /dev/null
@@ -1,597 +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.rule;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.Sets;
-import org.apache.commons.lang.ObjectUtils;
-import org.apache.commons.lang.StringUtils;
-import org.picocontainer.Startable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.server.debt.DebtRemediationFunction;
-import org.sonar.api.server.rule.RulesDefinition;
-import org.sonar.api.utils.MessageException;
-import org.sonar.api.utils.System2;
-import org.sonar.api.utils.TimeProfiler;
-import org.sonar.check.Cardinality;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
-import org.sonar.core.qualityprofile.db.ActiveRuleDao;
-import org.sonar.core.rule.RuleDao;
-import org.sonar.core.rule.RuleDto;
-import org.sonar.core.rule.RuleParamDto;
-import org.sonar.core.rule.RuleRuleTagDto;
-import org.sonar.core.rule.RuleTagDao;
-import org.sonar.core.rule.RuleTagDto;
-import org.sonar.core.rule.RuleTagType;
-import org.sonar.core.technicaldebt.db.CharacteristicDao;
-import org.sonar.core.technicaldebt.db.CharacteristicDto;
-import org.sonar.server.qualityprofile.ProfilesManager;
-import org.sonar.server.startup.RegisterDebtModel;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import static com.google.common.collect.Lists.newArrayList;
-
-/**
- * @deprecated to be dropped in 4.4
- */
-@Deprecated
-public class RegisterRules implements Startable {
-
- private static final Logger LOG = LoggerFactory.getLogger(RegisterRules.class);
-
- private final RuleDefinitionsLoader defLoader;
- private final ProfilesManager profilesManager;
- private final RuleRegistry ruleRegistry;
- private final ESRuleTags esRuleTags;
- private final MyBatis myBatis;
- private final RuleDao ruleDao;
- private final RuleTagDao ruleTagDao;
- private final RuleTagOperations ruleTagOperations;
- private final ActiveRuleDao activeRuleDao;
- private final CharacteristicDao characteristicDao;
- private final System2 system;
-
- /**
- * @param registerDebtModel used only to be started after init of the technical debt model
- */
- public RegisterRules(RuleDefinitionsLoader defLoader, ProfilesManager profilesManager,
- RuleRegistry ruleRegistry, ESRuleTags esRuleTags, RuleTagOperations ruleTagOperations,
- MyBatis myBatis, RuleDao ruleDao, RuleTagDao ruleTagDao, ActiveRuleDao activeRuleDao, CharacteristicDao characteristicDao,
- RegisterDebtModel registerDebtModel) {
- this(defLoader, profilesManager, ruleRegistry, esRuleTags, ruleTagOperations, myBatis, ruleDao, ruleTagDao, activeRuleDao, characteristicDao, System2.INSTANCE);
- }
-
- @VisibleForTesting
- RegisterRules(RuleDefinitionsLoader defLoader, ProfilesManager profilesManager,
- RuleRegistry ruleRegistry, ESRuleTags esRuleTags, RuleTagOperations ruleTagOperations,
- MyBatis myBatis, RuleDao ruleDao, RuleTagDao ruleTagDao, ActiveRuleDao activeRuleDao, CharacteristicDao characteristicDao, System2 system) {
- this.defLoader = defLoader;
- this.profilesManager = profilesManager;
- this.ruleRegistry = ruleRegistry;
- this.esRuleTags = esRuleTags;
- this.ruleTagOperations = ruleTagOperations;
- this.myBatis = myBatis;
- this.ruleDao = ruleDao;
- this.ruleTagDao = ruleTagDao;
- this.activeRuleDao = activeRuleDao;
- this.characteristicDao = characteristicDao;
- this.system = system;
- }
-
- @Override
- public void start() {
- TimeProfiler profiler = new TimeProfiler().start("Register rules");
- DbSession sqlSession = myBatis.openSession(false);
- try {
- RulesDefinition.Context context = defLoader.load();
- Buffer buffer = new Buffer(system.now());
- selectRulesFromDb(buffer, sqlSession);
- enableRuleDefinitions(context, buffer, sqlSession);
- List<RuleDto> removedRules = processRemainingDbRules(buffer, sqlSession);
- removeActiveRulesOnStillExistingRepositories(removedRules, context);
- index(buffer, sqlSession);
- ruleTagOperations.deleteUnusedTags(sqlSession);
- sqlSession.commit();
-
- } finally {
- sqlSession.close();
- profiler.stop();
- }
- }
-
- @Override
- public void stop() {
- // nothing
- }
-
- private void selectRulesFromDb(Buffer buffer, DbSession sqlSession) {
- for (RuleDto ruleDto : ruleDao.selectNonManual(sqlSession)) {
- buffer.add(ruleDto);
- buffer.markUnprocessed(ruleDto);
- }
- for (RuleParamDto paramDto : ruleDao.selectParameters(sqlSession)) {
- buffer.add(paramDto);
- }
- for (RuleTagDto tagDto : ruleTagDao.selectAll(sqlSession)) {
- buffer.add(tagDto);
- }
- for (RuleRuleTagDto tagDto : ruleDao.selectTags(sqlSession)) {
- buffer.add(tagDto);
- }
- for (CharacteristicDto characteristicDto : characteristicDao.selectEnabledCharacteristics(sqlSession)) {
- buffer.add(characteristicDto);
- }
- }
-
- private void enableRuleDefinitions(RulesDefinition.Context context, Buffer buffer, DbSession sqlSession) {
- for (RulesDefinition.Repository repoDef : context.repositories()) {
- enableRepository(buffer, sqlSession, repoDef);
- }
- for (RulesDefinition.ExtendedRepository extendedRepoDef : context.extendedRepositories()) {
- if (context.repository(extendedRepoDef.key()) == null) {
- LOG.warn(String.format("Extension is ignored, repository %s does not exist", extendedRepoDef.key()));
- } else {
- enableRepository(buffer, sqlSession, extendedRepoDef);
- }
- }
- }
-
- private void enableRepository(Buffer buffer, DbSession sqlSession, RulesDefinition.ExtendedRepository repoDef) {
- int count = 0;
- for (RulesDefinition.Rule ruleDef : repoDef.rules()) {
- RuleDto dto = buffer.rule(RuleKey.of(ruleDef.repository().key(), ruleDef.key()));
- if (dto == null) {
- dto = enableAndInsert(buffer, sqlSession, ruleDef);
- } else {
- enableAndUpdate(buffer, sqlSession, ruleDef, dto);
- }
- buffer.markProcessed(dto);
- count++;
- if (count % 100 == 0) {
- sqlSession.commit();
- }
- }
- sqlSession.commit();
- }
-
- private RuleDto enableAndInsert(Buffer buffer, DbSession sqlSession, RulesDefinition.Rule ruleDef) {
- RuleDto ruleDto = new RuleDto()
- .setCardinality(ruleDef.template() ? Cardinality.MULTIPLE : Cardinality.SINGLE)
- .setConfigKey(ruleDef.internalKey())
- .setDescription(ruleDef.htmlDescription())
- .setLanguage(ruleDef.repository().language())
- .setName(ruleDef.name())
- .setRepositoryKey(ruleDef.repository().key())
- .setRuleKey(ruleDef.key())
- .setSeverity(ruleDef.severity())
- .setStatus(ruleDef.status().name());
-
- CharacteristicDto characteristic = buffer.characteristic(ruleDef.debtSubCharacteristic(), ruleDef.repository().key(), ruleDef.key(), null);
- DebtRemediationFunction remediationFunction = ruleDef.debtRemediationFunction();
- if (characteristic != null && remediationFunction != null) {
- ruleDto.setDefaultSubCharacteristicId(characteristic.getId())
- .setDefaultRemediationFunction(remediationFunction.type().name())
- .setDefaultRemediationCoefficient(remediationFunction.coefficient())
- .setDefaultRemediationOffset(remediationFunction.offset())
- .setEffortToFixDescription(ruleDef.effortToFixDescription());
- }
-
- ruleDao.insert(ruleDto, sqlSession);
- buffer.add(ruleDto);
-
- for (RulesDefinition.Param param : ruleDef.params()) {
- RuleParamDto paramDto = new RuleParamDto()
- .setRuleId(ruleDto.getId())
- .setDefaultValue(param.defaultValue())
- .setDescription(param.description())
- .setName(param.name())
- .setType(param.type().toString());
- ruleDao.insert(paramDto, sqlSession);
- buffer.add(paramDto);
- }
- mergeTags(buffer, sqlSession, ruleDef, ruleDto);
- return ruleDto;
- }
-
- private void enableAndUpdate(Buffer buffer, DbSession sqlSession, RulesDefinition.Rule ruleDef, RuleDto dto) {
- if (mergeRule(buffer, ruleDef, dto)) {
- ruleDao.update(dto, sqlSession);
- }
- mergeParams(buffer, sqlSession, ruleDef, dto);
- mergeTags(buffer, sqlSession, ruleDef, dto);
- buffer.markProcessed(dto);
- }
-
- private boolean mergeRule(Buffer buffer, RulesDefinition.Rule def, RuleDto dto) {
- boolean changed = false;
- if (!StringUtils.equals(dto.getName(), def.name())) {
- dto.setName(def.name());
- changed = true;
- }
- if (!StringUtils.equals(dto.getDescription(), def.htmlDescription())) {
- dto.setDescription(def.htmlDescription());
- changed = true;
- }
- if (!StringUtils.equals(dto.getConfigKey(), def.internalKey())) {
- dto.setConfigKey(def.internalKey());
- changed = true;
- }
- String severity = def.severity();
- if (!ObjectUtils.equals(dto.getSeverityString(), severity)) {
- dto.setSeverity(severity);
- changed = true;
- }
- Cardinality cardinality = def.template() ? Cardinality.MULTIPLE : Cardinality.SINGLE;
- if (!cardinality.equals(dto.getCardinality())) {
- dto.setCardinality(cardinality);
- changed = true;
- }
- String status = def.status().name();
- if (!StringUtils.equals(dto.getStatus(), status)) {
- dto.setStatus(status);
- changed = true;
- }
- if (!StringUtils.equals(dto.getLanguage(), def.repository().language())) {
- dto.setLanguage(def.repository().language());
- changed = true;
- }
- CharacteristicDto subCharacteristic = buffer.characteristic(def.debtSubCharacteristic(), def.repository().key(), def.key(), dto.getSubCharacteristicId());
- changed = mergeDebtDefinitions(def, dto, subCharacteristic) || changed;
- if (changed) {
- dto.setUpdatedAt(buffer.now());
- }
- return changed;
- }
-
- private boolean mergeDebtDefinitions(RulesDefinition.Rule def, RuleDto dto, @Nullable CharacteristicDto subCharacteristic) {
- // Debt definitions are set to null if the sub-characteristic and the remediation function are null
- DebtRemediationFunction debtRemediationFunction = subCharacteristic != null ? def.debtRemediationFunction() : null;
- boolean hasDebt = subCharacteristic != null && debtRemediationFunction != null;
- return mergeDebtDefinitions(def, dto,
- hasDebt ? subCharacteristic.getId() : null,
- debtRemediationFunction != null ? debtRemediationFunction.type().name() : null,
- hasDebt ? debtRemediationFunction.coefficient() : null,
- hasDebt ? debtRemediationFunction.offset() : null,
- hasDebt ? def.effortToFixDescription() : null);
- }
-
- private boolean mergeDebtDefinitions(RulesDefinition.Rule def, RuleDto dto, @Nullable Integer characteristicId, @Nullable String remediationFunction,
- @Nullable String remediationCoefficient, @Nullable String remediationOffset, @Nullable String effortToFixDescription) {
- boolean changed = false;
-
- if (!ObjectUtils.equals(dto.getDefaultSubCharacteristicId(), characteristicId)) {
- dto.setDefaultSubCharacteristicId(characteristicId);
- changed = true;
- }
- if (!StringUtils.equals(dto.getDefaultRemediationFunction(), remediationFunction)) {
- dto.setDefaultRemediationFunction(remediationFunction);
- changed = true;
- }
- if (!StringUtils.equals(dto.getDefaultRemediationCoefficient(), remediationCoefficient)) {
- dto.setDefaultRemediationCoefficient(remediationCoefficient);
- changed = true;
- }
- if (!StringUtils.equals(dto.getDefaultRemediationOffset(), remediationOffset)) {
- dto.setDefaultRemediationOffset(remediationOffset);
- changed = true;
- }
- if (!StringUtils.equals(dto.getEffortToFixDescription(), effortToFixDescription)) {
- dto.setEffortToFixDescription(effortToFixDescription);
- changed = true;
- }
- return changed;
- }
-
- private void mergeParams(Buffer buffer, DbSession sqlSession, RulesDefinition.Rule ruleDef, RuleDto dto) {
- Collection<RuleParamDto> paramDtos = buffer.paramsForRuleId(dto.getId());
- Set<String> persistedParamKeys = Sets.newHashSet();
- for (RuleParamDto paramDto : paramDtos) {
- RulesDefinition.Param paramDef = ruleDef.param(paramDto.getName());
- if (paramDef == null) {
- activeRuleDao.deleteParametersWithParamId(paramDto.getId(), sqlSession);
- ruleDao.deleteParam(paramDto, sqlSession);
- } else {
- // TODO validate that existing active rules still match constraints
- // TODO store param name
- if (mergeParam(paramDto, paramDef)) {
- ruleDao.update(paramDto, sqlSession);
- }
- persistedParamKeys.add(paramDto.getName());
- }
- }
- for (RulesDefinition.Param param : ruleDef.params()) {
- if (!persistedParamKeys.contains(param.key())) {
- RuleParamDto paramDto = new RuleParamDto()
- .setRuleId(dto.getId())
- .setName(param.key())
- .setDescription(param.description())
- .setDefaultValue(param.defaultValue())
- .setType(param.type().toString());
- ruleDao.insert(paramDto, sqlSession);
- buffer.add(paramDto);
- }
- }
- }
-
- private boolean mergeParam(RuleParamDto paramDto, RulesDefinition.Param paramDef) {
- boolean changed = false;
- if (!StringUtils.equals(paramDto.getType(), paramDef.type().toString())) {
- paramDto.setType(paramDef.type().toString());
- changed = true;
- }
- if (!StringUtils.equals(paramDto.getDefaultValue(), paramDef.defaultValue())) {
- paramDto.setDefaultValue(paramDef.defaultValue());
- changed = true;
- }
- if (!StringUtils.equals(paramDto.getDescription(), paramDef.description())) {
- paramDto.setDescription(paramDef.description());
- changed = true;
- }
- return changed;
- }
-
- private void mergeTags(Buffer buffer, DbSession sqlSession, RulesDefinition.Rule ruleDef, RuleDto dto) {
- Set<String> existingSystemTags = Sets.newHashSet();
-
- Collection<RuleRuleTagDto> tagDtos = ImmutableList.copyOf(buffer.tagsForRuleId(dto.getId()));
- for (RuleRuleTagDto tagDto : tagDtos) {
- String tag = tagDto.getTag();
-
- if (tagDto.getType() == RuleTagType.SYSTEM) {
- // tag previously declared by plugin
- if (!ruleDef.tags().contains(tag)) {
- // not declared anymore
- ruleDao.deleteTag(tagDto, sqlSession);
- buffer.remove(tagDto);
- } else {
- existingSystemTags.add(tagDto.getTag());
- }
- } else {
- // tags created by end-users
- if (ruleDef.tags().contains(tag)) {
- long tagId = getOrCreateReferenceTagId(buffer, tag, sqlSession);
- tagDto.setId(tagId);
- tagDto.setType(RuleTagType.SYSTEM);
- ruleDao.update(tagDto, sqlSession);
- existingSystemTags.add(tag);
- }
- }
- }
-
- for (String tag : ruleDef.tags()) {
- if (!existingSystemTags.contains(tag)) {
- long tagId = getOrCreateReferenceTagId(buffer, tag, sqlSession);
- RuleRuleTagDto newTagDto = new RuleRuleTagDto()
- .setRuleId(dto.getId())
- .setTagId(tagId)
- .setTag(tag)
- .setType(RuleTagType.SYSTEM);
- ruleDao.insert(newTagDto, sqlSession);
- buffer.add(newTagDto);
- }
- }
- }
-
- private long getOrCreateReferenceTagId(Buffer buffer, String tag, DbSession sqlSession) {
- // End-user tag is converted to system tag
- long tagId = 0L;
- if (buffer.referenceTagExists(tag)) {
- tagId = buffer.referenceTagIdForValue(tag);
- } else {
- RuleTagDto newRuleTag = new RuleTagDto().setTag(tag);
- ruleTagDao.insert(newRuleTag, sqlSession);
- buffer.add(newRuleTag);
- tagId = newRuleTag.getId();
- }
- return tagId;
- }
-
- private List<RuleDto> processRemainingDbRules(Buffer buffer, DbSession sqlSession) {
- List<RuleDto> removedRules = newArrayList();
- for (Integer unprocessedRuleId : buffer.unprocessedRuleIds) {
- RuleDto ruleDto = buffer.rulesById.get(unprocessedRuleId);
- boolean toBeRemoved = true;
- // Update custom rules from template
- if (ruleDto.getParentId() != null) {
- RuleDto parent = buffer.rulesById.get(ruleDto.getParentId());
- if (parent != null && !Rule.STATUS_REMOVED.equals(parent.getStatus())) {
- ruleDto.setLanguage(parent.getLanguage());
- ruleDto.setStatus(parent.getStatus());
- ruleDto.setDefaultSubCharacteristicId(parent.getDefaultSubCharacteristicId());
- ruleDto.setDefaultRemediationFunction(parent.getDefaultRemediationFunction());
- ruleDto.setDefaultRemediationCoefficient(parent.getDefaultRemediationCoefficient());
- ruleDto.setDefaultRemediationOffset(parent.getDefaultRemediationOffset());
- ruleDto.setEffortToFixDescription(parent.getEffortToFixDescription());
- ruleDto.setUpdatedAt(buffer.now());
- ruleDao.update(ruleDto, sqlSession);
- toBeRemoved = false;
- }
- }
- if (toBeRemoved && !Rule.STATUS_REMOVED.equals(ruleDto.getStatus())) {
- LOG.info(String.format("Disable rule %s:%s", ruleDto.getRepositoryKey(), ruleDto.getRuleKey()));
- ruleDto.setStatus(Rule.STATUS_REMOVED);
- ruleDto.setUpdatedAt(buffer.now());
- for (RuleRuleTagDto removed : buffer.tagsByRuleId.removeAll(ruleDto.getId())) {
- ruleDao.deleteTag(removed, sqlSession);
- }
- ruleDao.update(ruleDto, sqlSession);
- removedRules.add(ruleDto);
- if (removedRules.size() % 100 == 0) {
- sqlSession.commit();
- }
- }
- }
- sqlSession.commit();
-
- return removedRules;
- }
-
- /**
- * SONAR-4642
- * <p/>
- * Remove active rules on repositories that still exists.
- * <p/>
- * For instance, if the javascript repository do not provide anymore some rules, active rules related to this rules will be removed.
- * But if the javascript repository do not exists anymore, then related active rules will not be removed.
- * <p/>
- * The side effect of this approach is that extended repositories will not be managed the same way.
- * If an extended repository do not exists anymore, then related active rules will be removed.
- */
- private void removeActiveRulesOnStillExistingRepositories(List<RuleDto> removedRules, RulesDefinition.Context context) {
- List<String> repositoryKeys = newArrayList(Iterables.transform(context.repositories(), new Function<RulesDefinition.Repository, String>() {
- @Override
- public String apply(RulesDefinition.Repository input) {
- return input.key();
- }
- }
- ));
-
- for (RuleDto rule : removedRules) {
- // SONAR-4642 Remove active rules only when repository still exists
- if (repositoryKeys.contains(rule.getRepositoryKey())) {
- profilesManager.removeActivatedRules(rule.getId());
- }
- }
- }
-
- private void index(Buffer buffer, DbSession sqlSession) {
- String[] ids = ruleRegistry.reindex(buffer.rulesById.values(), sqlSession);
- ruleRegistry.removeDeletedRules(ids);
- esRuleTags.putAllTags(buffer.referenceTagsByTagValue.values());
- }
-
- static class Buffer {
- private Date now;
- private List<Integer> unprocessedRuleIds = newArrayList();
- private Map<RuleKey, RuleDto> rulesByKey = Maps.newHashMap();
- private Map<Integer, RuleDto> rulesById = Maps.newHashMap();
- private Multimap<Integer, RuleParamDto> paramsByRuleId = ArrayListMultimap.create();
- private Multimap<Integer, RuleRuleTagDto> tagsByRuleId = ArrayListMultimap.create();
- private Map<String, RuleTagDto> referenceTagsByTagValue = Maps.newHashMap();
- private Map<Integer, CharacteristicDto> characteristicsById = Maps.newHashMap();
-
- Buffer(long now) {
- this.now = new Date(now);
- }
-
- Date now() {
- return now;
- }
-
- void add(RuleDto rule) {
- rulesById.put(rule.getId(), rule);
- rulesByKey.put(RuleKey.of(rule.getRepositoryKey(), rule.getRuleKey()), rule);
- }
-
- void add(CharacteristicDto characteristicDto) {
- characteristicsById.put(characteristicDto.getId(), characteristicDto);
- }
-
- void add(RuleTagDto tag) {
- referenceTagsByTagValue.put(tag.getTag(), tag);
- }
-
- void add(RuleParamDto param) {
- paramsByRuleId.put(param.getRuleId(), param);
- }
-
- void add(RuleRuleTagDto tag) {
- tagsByRuleId.put(tag.getRuleId(), tag);
- }
-
- void remove(RuleRuleTagDto tag) {
- tagsByRuleId.remove(tag.getRuleId(), tag);
- }
-
- @CheckForNull
- RuleDto rule(RuleKey key) {
- return rulesByKey.get(key);
- }
-
- Collection<RuleParamDto> paramsForRuleId(Integer ruleId) {
- return paramsByRuleId.get(ruleId);
- }
-
- Collection<RuleRuleTagDto> tagsForRuleId(Integer ruleId) {
- return tagsByRuleId.get(ruleId);
- }
-
- boolean referenceTagExists(String tagValue) {
- return referenceTagsByTagValue.containsKey(tagValue);
- }
-
- Long referenceTagIdForValue(String tagValue) {
- return referenceTagsByTagValue.get(tagValue).getId();
- }
-
- void markUnprocessed(RuleDto ruleDto) {
- unprocessedRuleIds.add(ruleDto.getId());
- }
-
- void markProcessed(RuleDto ruleDto) {
- unprocessedRuleIds.remove(ruleDto.getId());
- }
-
- CharacteristicDto characteristic(@Nullable String subCharacteristic, String repo, String ruleKey, @Nullable Integer overridingCharacteristicId) {
- // Rule is not linked to a default characteristic or characteristic has been disabled by user
- if (subCharacteristic == null) {
- return null;
- }
- CharacteristicDto characteristicDto = findCharacteristic(subCharacteristic);
- if (characteristicDto == null) {
- // Log a warning only if rule has not been overridden by user
- if (overridingCharacteristicId == null) {
- LOG.warn(String.format("Characteristic '%s' has not been found on rule '%s:%s'", subCharacteristic, repo, ruleKey));
- }
- } else if (characteristicDto.getParentId() == null) {
- throw MessageException.of(String.format("Rule '%s:%s' cannot be linked on the root characteristic '%s'", repo, ruleKey, subCharacteristic));
- }
- return characteristicDto;
- }
-
- @CheckForNull
- private CharacteristicDto findCharacteristic(final String key) {
- return Iterables.find(characteristicsById.values(), new Predicate<CharacteristicDto>() {
- @Override
- public boolean apply(@Nullable CharacteristicDto input) {
- return input != null && key.equals(input.getKey());
- }
- }, null);
- }
- }
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java b/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java
index 6d4d445fc9f..e33c061605e 100644
--- a/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java
+++ b/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java
@@ -109,10 +109,6 @@ public class RubyRuleService implements ServerComponent, Startable {
rules.deleteCustomRule(ruleId);
}
- public void updateRuleTags(int ruleId, Object tags) {
- rules.updateRuleTags(ruleId, tags);
- }
-
@Override
public void start() {
// used to force pico to instantiate the singleton at startup
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RuleOperations.java b/sonar-server/src/main/java/org/sonar/server/rule/RuleOperations.java
index 83a4804e68a..62ada1b5427 100644
--- a/sonar-server/src/main/java/org/sonar/server/rule/RuleOperations.java
+++ b/sonar-server/src/main/java/org/sonar/server/rule/RuleOperations.java
@@ -24,9 +24,6 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Strings;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.ibatis.session.SqlSession;
import org.sonar.api.ServerComponent;
@@ -44,9 +41,6 @@ import org.sonar.core.qualityprofile.db.ActiveRuleDto;
import org.sonar.core.rule.RuleDao;
import org.sonar.core.rule.RuleDto;
import org.sonar.core.rule.RuleParamDto;
-import org.sonar.core.rule.RuleRuleTagDto;
-import org.sonar.core.rule.RuleTagDao;
-import org.sonar.core.rule.RuleTagType;
import org.sonar.core.technicaldebt.db.CharacteristicDao;
import org.sonar.core.technicaldebt.db.CharacteristicDto;
import org.sonar.server.exceptions.BadRequestException;
@@ -56,11 +50,9 @@ import org.sonar.server.user.UserSession;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-
import java.util.Date;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import static com.google.common.collect.Lists.newArrayList;
@@ -73,28 +65,24 @@ public class RuleOperations implements ServerComponent {
private final MyBatis myBatis;
private final ActiveRuleDao activeRuleDao;
private final RuleDao ruleDao;
- private final RuleTagDao ruleTagDao;
private final CharacteristicDao characteristicDao;
- private final RuleTagOperations ruleTagOperations;
private final ESActiveRule esActiveRule;
private final RuleRegistry ruleRegistry;
private final System2 system;
- public RuleOperations(MyBatis myBatis, ActiveRuleDao activeRuleDao, RuleDao ruleDao, RuleTagDao ruleTagDao, CharacteristicDao characteristicDao,
- RuleTagOperations ruleTagOperations, ESActiveRule esActiveRule, RuleRegistry ruleRegistry) {
- this(myBatis, activeRuleDao, ruleDao, ruleTagDao, characteristicDao, ruleTagOperations, esActiveRule, ruleRegistry, System2.INSTANCE);
+ public RuleOperations(MyBatis myBatis, ActiveRuleDao activeRuleDao, RuleDao ruleDao, CharacteristicDao characteristicDao,
+ ESActiveRule esActiveRule, RuleRegistry ruleRegistry) {
+ this(myBatis, activeRuleDao, ruleDao, characteristicDao, esActiveRule, ruleRegistry, System2.INSTANCE);
}
@VisibleForTesting
- RuleOperations(MyBatis myBatis, ActiveRuleDao activeRuleDao, RuleDao ruleDao, RuleTagDao ruleTagDao, CharacteristicDao characteristicDao, RuleTagOperations ruleTagOperations,
+ RuleOperations(MyBatis myBatis, ActiveRuleDao activeRuleDao, RuleDao ruleDao, CharacteristicDao characteristicDao,
ESActiveRule esActiveRule, RuleRegistry ruleRegistry, System2 system) {
this.myBatis = myBatis;
this.activeRuleDao = activeRuleDao;
this.ruleDao = ruleDao;
- this.ruleTagDao = ruleTagDao;
this.characteristicDao = characteristicDao;
- this.ruleTagOperations = ruleTagOperations;
this.esActiveRule = esActiveRule;
this.ruleRegistry = ruleRegistry;
this.system = system;
@@ -175,16 +163,6 @@ public class RuleOperations implements ServerComponent {
ruleDao.insert(param, session);
}
- List<RuleRuleTagDto> templateRuleTags = ruleDao.selectTagsByRuleIds(templateRule.getId(), session);
- for (RuleRuleTagDto tag : templateRuleTags) {
- RuleRuleTagDto newTag = new RuleRuleTagDto()
- .setRuleId(rule.getId())
- .setTagId(tag.getTagId())
- .setTag(tag.getTag())
- .setType(tag.getType());
- ruleDao.insert(newTag, session);
- }
-
session.commit();
reindexRule(rule, session);
return rule;
@@ -246,26 +224,6 @@ public class RuleOperations implements ServerComponent {
}
}
- public void updateRuleTags(RuleDto rule, List<String> newTags, UserSession userSession) {
- checkPermission(userSession);
- DbSession session = myBatis.openSession(false);
- try {
- Map<String, Long> neededTagIds = validateAndGetTagIds(newTags, session);
-
- final Integer ruleId = rule.getId();
-
- boolean ruleChanged = synchronizeTags(ruleId, newTags, neededTagIds, session);
- if (ruleChanged) {
- rule.setUpdatedAt(new Date(system.now()));
- ruleDao.update(rule, session);
- session.commit();
- reindexRule(rule, session);
- }
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
public void updateRule(RuleChange ruleChange, UserSession userSession) {
checkPermission(userSession);
DbSession session = myBatis.openSession(false);
@@ -344,14 +302,14 @@ public class RuleOperations implements ServerComponent {
}
private static boolean isRuleDebtSameAsDefaultValues(RuleDto ruleDto, CharacteristicDto newSubCharacteristic, @Nullable String newFunction,
- @Nullable String newCoefficient, @Nullable String newOffset) {
+ @Nullable String newCoefficient, @Nullable String newOffset) {
return newSubCharacteristic.getId().equals(ruleDto.getDefaultSubCharacteristicId()) &&
isSameRemediationFunction(newFunction, newCoefficient, newOffset, ruleDto.getDefaultRemediationFunction(), ruleDto.getDefaultRemediationCoefficient(),
ruleDto.getDefaultRemediationOffset());
}
private static boolean isRuleDebtSameAsOverriddenValues(RuleDto ruleDto, CharacteristicDto newSubCharacteristic, @Nullable String newFunction,
- @Nullable String newCoefficient, @Nullable String newOffset) {
+ @Nullable String newCoefficient, @Nullable String newOffset) {
return newSubCharacteristic.getId().equals(ruleDto.getSubCharacteristicId())
&& isSameRemediationFunction(newFunction, newCoefficient, newOffset, ruleDto.getRemediationFunction(), ruleDto.getRemediationCoefficient(), ruleDto.getRemediationOffset());
}
@@ -365,50 +323,6 @@ public class RuleOperations implements ServerComponent {
.isEquals();
}
- private Map<String, Long> validateAndGetTagIds(List<String> newTags, SqlSession session) {
- Map<String, Long> neededTagIds = Maps.newHashMap();
- Set<String> unknownTags = Sets.newHashSet();
- for (String tag : newTags) {
- Long tagId = ruleTagDao.selectId(tag, session);
- if (tagId == null) {
- unknownTags.add(tag);
- } else {
- neededTagIds.put(tag, tagId);
- }
- }
- if (!unknownTags.isEmpty()) {
- throw new NotFoundException("The following tags are unknown and must be created before association: "
- + StringUtils.join(unknownTags, ", "));
- }
- return neededTagIds;
- }
-
- private boolean synchronizeTags(final Integer ruleId, List<String> newTags, Map<String, Long> neededTagIds, SqlSession session) {
- boolean ruleChanged = false;
-
- Set<String> tagsToKeep = Sets.newHashSet();
- List<RuleRuleTagDto> currentTags = ruleDao.selectTagsByRuleIds(ruleId, session);
- for (RuleRuleTagDto existingTag : currentTags) {
- if (existingTag.getType() == RuleTagType.ADMIN && !newTags.contains(existingTag.getTag())) {
- ruleDao.deleteTag(existingTag, session);
- ruleChanged = true;
- } else {
- tagsToKeep.add(existingTag.getTag());
- }
- }
-
- for (String tag : newTags) {
- if (!tagsToKeep.contains(tag)) {
- ruleDao.insert(new RuleRuleTagDto().setRuleId(ruleId).setTagId(neededTagIds.get(tag)).setType(RuleTagType.ADMIN), session);
- ruleChanged = true;
- }
- }
-
- ruleTagOperations.deleteUnusedTags(session);
-
- return ruleChanged;
- }
-
private void reindexRule(RuleDto rule, SqlSession session) {
ruleRegistry.reindex(rule, session);
}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RuleRegistry.java b/sonar-server/src/main/java/org/sonar/server/rule/RuleRegistry.java
index 24ee11f0614..b80114ca374 100644
--- a/sonar-server/src/main/java/org/sonar/server/rule/RuleRegistry.java
+++ b/sonar-server/src/main/java/org/sonar/server/rule/RuleRegistry.java
@@ -30,7 +30,6 @@ import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
-import org.elasticsearch.common.collect.Lists;
import org.elasticsearch.common.collect.Maps;
import org.elasticsearch.common.io.BytesStream;
import org.elasticsearch.common.unit.TimeValue;
@@ -123,7 +122,6 @@ public class RuleRegistry {
*/
public String[] reindex(Collection<RuleDto> rules, SqlSession session) {
Multimap<Integer, RuleParamDto> paramsByRuleId = ArrayListMultimap.create();
- Multimap<Integer, RuleRuleTagDto> tagsByRuleId = ArrayListMultimap.create();
Map<Integer, CharacteristicDto> characteristicsById = newHashMap();
List<Integer> ruleIds = newArrayList();
@@ -148,13 +146,10 @@ public class RuleRegistry {
for (RuleParamDto paramDto : ruleDao.selectParametersByRuleIds(ruleIds, session)) {
paramsByRuleId.put(paramDto.getRuleId(), paramDto);
}
- for (RuleRuleTagDto tagDto : ruleDao.selectTagsByRuleIds(ruleIds, session)) {
- tagsByRuleId.put(tagDto.getRuleId(), tagDto);
- }
for (CharacteristicDto characteristicDto : allCharacteristicDtos) {
characteristicsById.put(characteristicDto.getId(), characteristicDto);
}
- return bulkIndexRules(rules, characteristicsById, paramsByRuleId, tagsByRuleId);
+ return bulkIndexRules(rules, characteristicsById, paramsByRuleId);
}
/**
@@ -180,15 +175,13 @@ public class RuleRegistry {
characteristicDao.selectById(parentId, session) : null;
searchIndex.putSynchronous(INDEX_RULES, TYPE_RULE, Long.toString(ruleId), ruleDocument(rule,
characteristic, subCharacteristic,
- ruleDao.selectParametersByRuleIds(newArrayList(ruleId), session),
- ruleDao.selectTagsByRuleIds(newArrayList(ruleId), session)));
+ ruleDao.selectParametersByRuleIds(newArrayList(ruleId), session)));
} catch (IOException ioexception) {
throw new IllegalStateException("Unable to index rule with id=" + rule.getId(), ioexception);
}
}
- private String[] bulkIndexRules(Collection<RuleDto> rules, Map<Integer, CharacteristicDto> characteristicsById, Multimap<Integer, RuleParamDto> paramsByRule,
- Multimap<Integer, RuleRuleTagDto> tagsByRule) {
+ private String[] bulkIndexRules(Collection<RuleDto> rules, Map<Integer, CharacteristicDto> characteristicsById, Multimap<Integer, RuleParamDto> paramsByRule) {
try {
String[] ids = new String[rules.size()];
BytesStream[] docs = new BytesStream[rules.size()];
@@ -199,7 +192,7 @@ public class RuleRegistry {
CharacteristicDto effectiveSubCharacteristic =
characteristicsById.get(rule.getSubCharacteristicId() != null ? rule.getSubCharacteristicId() : rule.getDefaultSubCharacteristicId());
CharacteristicDto effectiveCharacteristic = effectiveSubCharacteristic != null ? characteristicsById.get(effectiveSubCharacteristic.getParentId()) : null;
- docs[index] = ruleDocument(rule, effectiveCharacteristic, effectiveSubCharacteristic, paramsByRule.get(rule.getId()), tagsByRule.get(rule.getId()));
+ docs[index] = ruleDocument(rule, effectiveCharacteristic, effectiveSubCharacteristic, paramsByRule.get(rule.getId()));
index++;
}
TIME_PROFILER.stop();
@@ -226,7 +219,7 @@ public class RuleRegistry {
}
private XContentBuilder ruleDocument(RuleDto rule, @Nullable CharacteristicDto characteristicDto, @Nullable CharacteristicDto subCharacteristicDto,
- Collection<RuleParamDto> params, Collection<RuleRuleTagDto> tags) throws IOException {
+ Collection<RuleParamDto> params) throws IOException {
XContentBuilder document = XContentFactory.jsonBuilder()
.startObject()
.field(RuleDocument.FIELD_ID, rule.getId())
@@ -244,7 +237,6 @@ public class RuleRegistry {
addRuleDebt(document, rule, characteristicDto, subCharacteristicDto);
addRuleNote(document, rule);
addRuleParams(document, rule, params);
- addRuleTags(document, rule, tags);
document.endObject();
return document;
}
@@ -290,24 +282,6 @@ public class RuleRegistry {
}
}
- private void addRuleTags(XContentBuilder document, RuleDto rule, Collection<RuleRuleTagDto> tags) throws IOException {
- List<String> systemTags = Lists.newArrayList();
- List<String> adminTags = Lists.newArrayList();
- for (RuleRuleTagDto tag : tags) {
- if (tag.getType() == RuleTagType.SYSTEM) {
- systemTags.add(tag.getTag());
- } else {
- adminTags.add(tag.getTag());
- }
- }
- if (!systemTags.isEmpty()) {
- document.array(RuleDocument.FIELD_SYSTEM_TAGS, systemTags.toArray());
- }
- if (!adminTags.isEmpty()) {
- document.array(RuleDocument.FIELD_ADMIN_TAGS, adminTags.toArray());
- }
- }
-
/**
* <p>Find rule IDs matching the given criteria.</p>
*
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RuleTagDocument.java b/sonar-server/src/main/java/org/sonar/server/rule/RuleTagDocument.java
deleted file mode 100644
index 2c35de519eb..00000000000
--- a/sonar-server/src/main/java/org/sonar/server/rule/RuleTagDocument.java
+++ /dev/null
@@ -1,33 +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.rule;
-
-/**
- * @deprecated to be dropped in 4.4
- */
-@Deprecated
-public class RuleTagDocument {
-
- public static final String FIELD_VALUE = "value";
-
- private RuleTagDocument() {
- // Only constants
- }
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RuleTagLookup.java b/sonar-server/src/main/java/org/sonar/server/rule/RuleTagLookup.java
deleted file mode 100644
index 475407b56d7..00000000000
--- a/sonar-server/src/main/java/org/sonar/server/rule/RuleTagLookup.java
+++ /dev/null
@@ -1,41 +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.rule;
-
-import org.sonar.api.ServerComponent;
-
-import java.util.Collection;
-
-/**
- * @deprecated to be dropped in 4.4
- */
-@Deprecated
-public class RuleTagLookup implements ServerComponent {
-
- private final ESRuleTags esRuleTags;
-
- public RuleTagLookup(ESRuleTags esRuleTags) {
- this.esRuleTags = esRuleTags;
- }
-
- public Collection<String> listAllTags() {
- return esRuleTags.searchAllTags();
- }
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RuleTagOperations.java b/sonar-server/src/main/java/org/sonar/server/rule/RuleTagOperations.java
deleted file mode 100644
index 8b50e6bb7e1..00000000000
--- a/sonar-server/src/main/java/org/sonar/server/rule/RuleTagOperations.java
+++ /dev/null
@@ -1,88 +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.rule;
-
-import org.apache.ibatis.session.SqlSession;
-import org.elasticsearch.common.collect.Sets;
-import org.sonar.api.ServerExtension;
-import org.sonar.api.server.rule.RuleTagFormat;
-import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.core.rule.RuleTagDao;
-import org.sonar.core.rule.RuleTagDto;
-import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.user.UserSession;
-
-import java.util.Set;
-
-/**
- * @deprecated to be dropped in 4.4
- */
-@Deprecated
-public class RuleTagOperations implements ServerExtension {
-
- private final RuleTagDao ruleTagDao;
- private final ESRuleTags esRuleTags;
-
- public RuleTagOperations(RuleTagDao ruleTagDao, ESRuleTags esRuleTags) {
- this.ruleTagDao = ruleTagDao;
- this.esRuleTags = esRuleTags;
- }
-
- public RuleTagDto create(String tag, UserSession userSession) {
- checkPermission(userSession);
- validateTagFormat(tag);
- checkDuplicateTag(tag);
-
- RuleTagDto newTag = new RuleTagDto().setTag(tag);
- ruleTagDao.insert(newTag);
- esRuleTags.put(newTag);
- return newTag;
- }
-
- private void checkDuplicateTag(String tag) {
- if (ruleTagDao.selectId(tag) != null) {
- throw new BadRequestException(String.format("Tag %s already exists", tag));
- }
- }
-
- private void validateTagFormat(String tag) {
- try {
- RuleTagFormat.validate(tag);
- } catch(IllegalArgumentException iae) {
- throw new BadRequestException(iae.getMessage());
- }
- }
-
- private void checkPermission(UserSession userSession) {
- userSession.checkLoggedIn();
- userSession.checkGlobalPermission(GlobalPermissions.QUALITY_PROFILE_ADMIN);
- }
-
- public void deleteUnusedTags(SqlSession session) {
- Set<String> deleted = Sets.newHashSet();
- for (RuleTagDto unused: ruleTagDao.selectUnused(session)) {
- deleted.add(unused.getTag());
- ruleTagDao.delete(unused.getId(), session);
- }
- if (!deleted.isEmpty()) {
- esRuleTags.delete(deleted.toArray(new String[0]));
- }
- }
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RuleTags.java b/sonar-server/src/main/java/org/sonar/server/rule/RuleTags.java
deleted file mode 100644
index d87df4c6073..00000000000
--- a/sonar-server/src/main/java/org/sonar/server/rule/RuleTags.java
+++ /dev/null
@@ -1,49 +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.rule;
-
-import org.sonar.api.ServerExtension;
-import org.sonar.core.rule.RuleTagDto;
-import org.sonar.server.user.UserSession;
-
-import java.util.Collection;
-
-/**
- * @deprecated to be dropped in 4.4
- */
-@Deprecated
-public class RuleTags implements ServerExtension {
-
- private final RuleTagLookup ruleTagLookup;
- private final RuleTagOperations ruleTagOperations;
-
- public RuleTags(RuleTagLookup ruleTagLookup, RuleTagOperations ruleTagOperations) {
- this.ruleTagLookup = ruleTagLookup;
- this.ruleTagOperations = ruleTagOperations;
- }
-
- public Collection<String> listAllTags() {
- return ruleTagLookup.listAllTags();
- }
-
- public RuleTagDto create(String tag) {
- return ruleTagOperations.create(tag, UserSession.get());
- }
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/Rules.java b/sonar-server/src/main/java/org/sonar/server/rule/Rules.java
index 625a62870a2..7d909603deb 100644
--- a/sonar-server/src/main/java/org/sonar/server/rule/Rules.java
+++ b/sonar-server/src/main/java/org/sonar/server/rule/Rules.java
@@ -106,15 +106,6 @@ public class Rules implements ServerExtension {
ruleOperations.deleteCustomRule(rule, UserSession.get());
}
- public void updateRuleTags(int ruleId, Object tags) {
- RuleDto rule = findRuleNotNull(ruleId);
- List<String> newTags = RubyUtils.toStrings(tags);
- if (newTags == null) {
- newTags = ImmutableList.of();
- }
- ruleOperations.updateRuleTags(rule, newTags, UserSession.get());
- }
-
@CheckForNull
public Rule findByKey(RuleKey key) {
return ruleRegistry.findByKey(key);
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/ws/AbstractUpdateTagsWsHandler.java b/sonar-server/src/main/java/org/sonar/server/rule/ws/AbstractUpdateTagsWsHandler.java
deleted file mode 100644
index 7c64895f12e..00000000000
--- a/sonar-server/src/main/java/org/sonar/server/rule/ws/AbstractUpdateTagsWsHandler.java
+++ /dev/null
@@ -1,63 +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.rule.ws;
-
-import org.sonar.server.exceptions.NotFoundException;
-
-import com.google.common.collect.Sets;
-import org.elasticsearch.common.collect.Lists;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.RequestHandler;
-import org.sonar.api.server.ws.Response;
-import org.sonar.server.rule.Rule;
-import org.sonar.server.rule.Rules;
-
-import java.util.Set;
-
-/**
- * @deprecated to be dropped in 4.4
- */
-@Deprecated
-public abstract class AbstractUpdateTagsWsHandler implements RequestHandler {
-
- private final Rules rules;
-
- protected AbstractUpdateTagsWsHandler(Rules rules) {
- this.rules = rules;
- }
-
- @Override
- public void handle(Request request, Response response) {
- RuleKey ruleKey = RuleKey.parse(request.mandatoryParam("key"));
- Rule rule = rules.findByKey(ruleKey);
- if (rule == null) {
- throw new NotFoundException("No rule found for key " + ruleKey);
- }
- Set<String> allAdminTags = Sets.newHashSet(rule.adminTags());
- String[] tagsFromRequest = request.mandatoryParam("tags").split(",");
- updateTags(allAdminTags, tagsFromRequest);
- rules.updateRuleTags(rule.id(), Lists.newArrayList(allAdminTags));
-
- response.noContent();
- }
-
- protected abstract void updateTags(Set<String> currentTags, String[] tagsFromRequest);
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/ws/AddTagsWsHandler.java b/sonar-server/src/main/java/org/sonar/server/rule/ws/AddTagsWsHandler.java
deleted file mode 100644
index 38d2d267441..00000000000
--- a/sonar-server/src/main/java/org/sonar/server/rule/ws/AddTagsWsHandler.java
+++ /dev/null
@@ -1,41 +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.rule.ws;
-
-import org.sonar.server.rule.Rules;
-
-import java.util.Arrays;
-import java.util.Set;
-
-/**
- * @deprecated to be dropped in 4.4
- */
-@Deprecated
-public class AddTagsWsHandler extends AbstractUpdateTagsWsHandler {
-
- public AddTagsWsHandler(Rules rules) {
- super(rules);
- }
-
- @Override
- protected void updateTags(Set<String> currentTags, String[] tagsFromRequest) {
- currentTags.addAll(Arrays.asList(tagsFromRequest));
- }
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/ws/RemoveTagsWsHandler.java b/sonar-server/src/main/java/org/sonar/server/rule/ws/RemoveTagsWsHandler.java
deleted file mode 100644
index 9fe9c5ad77d..00000000000
--- a/sonar-server/src/main/java/org/sonar/server/rule/ws/RemoveTagsWsHandler.java
+++ /dev/null
@@ -1,41 +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.rule.ws;
-
-import org.sonar.server.rule.Rules;
-
-import java.util.Arrays;
-import java.util.Set;
-
-/**
- * @deprecated to be dropped in 4.4
- */
-@Deprecated
-public class RemoveTagsWsHandler extends AbstractUpdateTagsWsHandler {
-
- public RemoveTagsWsHandler(Rules rules) {
- super(rules);
- }
-
- @Override
- protected void updateTags(Set<String> currentTags, String[] tagsFromRequest) {
- currentTags.removeAll(Arrays.asList(tagsFromRequest));
- }
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleTagsWs.java b/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleTagsWs.java
deleted file mode 100644
index 2628ee3653e..00000000000
--- a/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleTagsWs.java
+++ /dev/null
@@ -1,92 +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.rule.ws;
-
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.RequestHandler;
-import org.sonar.api.server.ws.Response;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.core.rule.RuleTagDto;
-import org.sonar.server.rule.RuleTags;
-
-/**
- * @deprecated to be dropped in 4.4
- */
-@Deprecated
-public class RuleTagsWs implements WebService {
-
- private final RuleTags ruleTags;
-
- public RuleTagsWs(RuleTags ruleTags) {
- this.ruleTags = ruleTags;
- }
-
- @Override
- public void define(Context context) {
- NewController controller = context.createController("api/rule_tags")
- .setDescription("Rule tags management");
-
- controller.createAction("list")
- .setDescription("List all available rule tags")
- .setSince("4.2")
- .setHandler(new RequestHandler() {
- @Override
- public void handle(Request request, Response response) {
- list(response);
- }
- });
-
- controller.createAction("create")
- .setPost(true)
- .setDescription("Create a new rule tag")
- .setSince("4.2")
- .setHandler(new RequestHandler() {
- @Override
- public void handle(Request request, Response response) {
- create(request, response);
- }
- })
- .createParam("tag")
- .setDescription("Value of the new rule tag")
- .setExampleValue("java8");
-
- controller.done();
- }
-
- private void list(Response response) {
- JsonWriter writer = response.newJsonWriter();
- writer.beginArray();
- for (String tag : ruleTags.listAllTags()) {
- writer.value(tag);
- }
- writer.endArray().close();
- }
-
- private void create(Request request, Response response) {
- RuleTagDto newTag = ruleTags.create(request.mandatoryParam("tag"));
- response.newJsonWriter()
- .beginObject()
- .prop("id", newTag.getId())
- .prop("tag", newTag.getTag())
- .endObject()
- .close();
- }
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/ws/RulesWs.java b/sonar-server/src/main/java/org/sonar/server/rule/ws/RulesWs.java
index 75a4e13b64e..74c52e969a7 100644
--- a/sonar-server/src/main/java/org/sonar/server/rule/ws/RulesWs.java
+++ b/sonar-server/src/main/java/org/sonar/server/rule/ws/RulesWs.java
@@ -29,14 +29,10 @@ public class RulesWs implements WebService {
private final RuleSearchWsHandler searchHandler;
private final RuleShowWsHandler showHandler;
- private final AddTagsWsHandler addTagsWsHandler;
- private final RemoveTagsWsHandler removeTagsWsHandler;
- public RulesWs(RuleSearchWsHandler searchHandler, RuleShowWsHandler showHandler, AddTagsWsHandler addTagsWsHandler, RemoveTagsWsHandler removeTagsWsHandler) {
+ public RulesWs(RuleSearchWsHandler searchHandler, RuleShowWsHandler showHandler) {
this.searchHandler = searchHandler;
this.showHandler = showHandler;
- this.addTagsWsHandler = addTagsWsHandler;
- this.removeTagsWsHandler = removeTagsWsHandler;
}
@Override
@@ -67,23 +63,6 @@ public class RulesWs implements WebService {
.setHandler(showHandler)
.createParam("key", "Mandatory key of rule");
- addTagParams(controller.createAction("add_tags")
- .setDescription("Add tags to a rule")
- .setSince("4.2")
- .setPost(true)
- .setHandler(addTagsWsHandler));
-
- addTagParams(controller.createAction("remove_tags")
- .setDescription("Remove tags from a rule")
- .setSince("4.2")
- .setPost(true)
- .setHandler(removeTagsWsHandler));
-
controller.done();
}
-
- private void addTagParams(final NewAction action) {
- action.createParam("key", "Full key of the rule");
- action.createParam("tags", "Comma separated list of tags");
- }
}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/RegisterRules.java b/sonar-server/src/main/java/org/sonar/server/rule2/RegisterRules.java
index 9b6c1121d19..55eb6660214 100644
--- a/sonar-server/src/main/java/org/sonar/server/rule2/RegisterRules.java
+++ b/sonar-server/src/main/java/org/sonar/server/rule2/RegisterRules.java
@@ -44,6 +44,10 @@ import org.sonar.core.technicaldebt.db.CharacteristicDto;
import org.sonar.server.db.DbClient;
import org.sonar.server.qualityprofile.ProfilesManager;
import org.sonar.server.rule.RuleDefinitionsLoader;
+import org.sonar.server.rule2.index.RuleIndexDefinition;
+import org.sonar.server.search.action.EmbeddedIndexAction;
+import org.sonar.server.search.action.IndexAction;
+import org.sonar.server.search.action.KeyIndexAction;
import javax.annotation.Nullable;
import java.util.ArrayList;
@@ -95,7 +99,6 @@ public class RegisterRules implements Startable {
RulesDefinition.Context context = defLoader.load();
for (RulesDefinition.ExtendedRepository repoDef : getRepositories(context)) {
for (RulesDefinition.Rule ruleDef : repoDef.rules()) {
-
RuleKey ruleKey = RuleKey.of(ruleDef.repository().key(), ruleDef.key());
RuleDto rule = allRules.containsKey(ruleKey) ? allRules.remove(ruleKey) : createRuleDto(ruleDef, session);
@@ -118,6 +121,9 @@ public class RegisterRules implements Startable {
if (executeUpdate) {
dbClient.ruleDao().update(rule, session);
+ } else {
+ // TODO replace this hack by index synchronizer
+ session.enqueue(new KeyIndexAction<RuleKey>(RuleIndexDefinition.INDEX_TYPE, IndexAction.Method.UPDATE, rule.getKey()));
}
mergeParams(ruleDef, rule, session);
@@ -276,6 +282,9 @@ public class RegisterRules implements Startable {
// TODO store param name
if (mergeParam(paramDto, paramDef)) {
dbClient.ruleDao().updateRuleParam(rule, paramDto, session);
+ } else {
+ // TODO to be replaced by synchronizer
+ session.enqueue(new EmbeddedIndexAction<RuleKey>(RuleIndexDefinition.INDEX_TYPE, IndexAction.Method.UPDATE, paramDto, rule.getKey()));
}
existingParamDtoNames.add(paramDto.getName());
}
@@ -312,9 +321,8 @@ public class RegisterRules implements Startable {
private boolean mergeTags(RulesDefinition.Rule ruleDef, RuleDto dto) {
boolean changed = false;
- if (Rule.STATUS_REMOVED.equals(ruleDef.status())) {
+ if (RuleStatus.REMOVED == ruleDef.status()) {
dto.setSystemTags(Collections.EMPTY_SET);
- dto.setTags(Collections.EMPTY_SET);
changed = true;
} else if (!dto.getSystemTags().containsAll(ruleDef.tags())) {
dto.setSystemTags(ruleDef.tags());
diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/index/RuleIndexDefinition.java b/sonar-server/src/main/java/org/sonar/server/rule2/index/RuleIndexDefinition.java
index 8482e333347..9519da264c8 100644
--- a/sonar-server/src/main/java/org/sonar/server/rule2/index/RuleIndexDefinition.java
+++ b/sonar-server/src/main/java/org/sonar/server/rule2/index/RuleIndexDefinition.java
@@ -23,9 +23,8 @@ import org.sonar.server.search.IndexDefinition;
public final class RuleIndexDefinition implements IndexDefinition {
- private static final String INDEX_NAME = "rules2";
- private static final String INDEX_DOMAIN = "rules";
- private static final String INDEX_TYPE = "rule2";
+ public static final String INDEX_NAME = "rules2";
+ public static final String INDEX_TYPE = "rule2";
@Override
public String getIndexName() {
@@ -36,4 +35,4 @@ public final class RuleIndexDefinition implements IndexDefinition {
public String getIndexType() {
return RuleIndexDefinition.INDEX_TYPE;
}
-} \ No newline at end of file
+}
diff --git a/sonar-server/src/main/java/org/sonar/server/search/Result.java b/sonar-server/src/main/java/org/sonar/server/search/Result.java
index 1ab0cfd1208..a6aaa09dc92 100644
--- a/sonar-server/src/main/java/org/sonar/server/search/Result.java
+++ b/sonar-server/src/main/java/org/sonar/server/search/Result.java
@@ -36,7 +36,7 @@ import java.util.Map;
public abstract class Result<K> {
- private final Collection<K> hits;
+ private final List<K> hits;
private final Map<String, Collection<FacetValue>> facets;
private final long total;
private final long timeInMillis;
@@ -79,7 +79,7 @@ public abstract class Result<K> {
return this.getSearchResult(fields);
}
- public Collection<K> getHits() {
+ public List<K> getHits() {
return hits;
}
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/internal.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/internal.rb
index b5a114bb17c..c4091a7798b 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/internal.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/internal.rb
@@ -82,10 +82,6 @@ class Internal
component(Java::OrgSonarServerRule::RubyRuleService.java_class)
end
- def self.rule_tags
- component(Java::OrgSonarServerRule::RuleTags.java_class)
- end
-
def self.durations
component(Java::OrgSonarApiUtils::Durations.java_class)
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/537_drop_rule_tags_tables.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/537_drop_rule_tags_tables.rb
new file mode 100644
index 00000000000..6019912e646
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/537_drop_rule_tags_tables.rb
@@ -0,0 +1,77 @@
+#
+# 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.
+#
+
+#
+# SonarQube 4.4
+# SONAR-5007
+#
+class DropRuleTagsTables < ActiveRecord::Migration
+
+ class Rule < ActiveRecord::Base
+ end
+
+ class Tag < ActiveRecord::Base
+ set_table_name 'rule_tags'
+ end
+
+ class RuleTag < ActiveRecord::Base
+ set_table_name 'rules_rule_tags'
+ end
+
+ def self.up
+ # load tags
+ tags_by_id={}
+ Tag.find(:all).inject(tags_by_id) do |h, tag|
+ h[tag.id]=tag.tag
+ h
+ end
+
+ # load associations between rules and tags
+ rule_tags_by_rule_id={}
+ RuleTag.find(:all).inject(rule_tags_by_rule_id) do |h, rule_tag|
+ h[rule_tag.rule_id]||=[]
+ h[rule_tag.rule_id]<<rule_tag
+ h
+ end
+
+ # move tags to RULES.TAGS and RULES.SYSTEM_TAGS (see migration 533)
+ rule_tags_by_rule_id.each do |rule_id, rule_tags|
+ rule=Rule.find(rule_id)
+ if rule
+ system_tags=[]
+ user_tags=[]
+ rule_tags.each do |rule_tag|
+ if rule_tag.tag_type=='SYSTEM'
+ system_tags<<tags_by_id[rule_tag.rule_tag_id]
+ else
+ user_tags<<tags_by_id[rule_tag.rule_tag_id]
+ end
+ end
+ rule.tags=user_tags.join(',')
+ rule.system_tags=system_tags.join(',')
+ rule.save!
+ end
+ end
+
+ drop_table(:rules_rule_tags)
+ drop_table(:rule_tags)
+ end
+
+end
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/ESRuleTagsTest.java b/sonar-server/src/test/java/org/sonar/server/rule/ESRuleTagsTest.java
deleted file mode 100644
index c040bb52dfc..00000000000
--- a/sonar-server/src/test/java/org/sonar/server/rule/ESRuleTagsTest.java
+++ /dev/null
@@ -1,149 +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.rule;
-
-import com.github.tlrx.elasticsearch.test.EsSetup;
-import com.github.tlrx.elasticsearch.test.request.Index;
-import com.google.common.collect.ImmutableList;
-import org.elasticsearch.common.settings.ImmutableSettings;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.config.Settings;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.rule.RuleTagDto;
-import org.sonar.server.es.ESIndex;
-import org.sonar.server.es.ESNode;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class ESRuleTagsTest {
-
- EsSetup esSetup;
-
- ESIndex searchIndex;
-
- ESRuleTags ruleTags;
-
- @Before
- public void setUp() throws Exception {
- esSetup = new EsSetup(ImmutableSettings.builder().loadFromUrl(ESNode.class.getResource("config/elasticsearch.json")).build());
- esSetup.execute(EsSetup.deleteAll());
-
- ESNode node = mock(ESNode.class);
- when(node.client()).thenReturn(esSetup.client());
-
- Settings settings = new Settings();
- settings.setProperty("sonar.log.profilingLevel", "FULL");
- Profiling profiling = new Profiling(settings);
- searchIndex = new ESIndex(node, profiling);
- searchIndex.start();
-
- ruleTags = new ESRuleTags(searchIndex);
- ruleTags.start();
- }
-
- @After
- public void tearDown() {
- searchIndex.stop();
- esSetup.terminate();
- }
-
- @Test
- public void should_register_mapping_at_startup() {
- assertThat(esSetup.exists("rules")).isTrue();
- assertThat(esSetup.client().admin().indices().prepareTypesExists("rules").setTypes("tag").execute().actionGet().isExists()).isTrue();
- }
-
- @Test
- public void should_skip_bulk_if_no_tag() {
- esSetup.execute(
- indexTagDocument("tag5"),
- indexTagDocument("tag6"),
- indexTagDocument("tag7"));
- ruleTags.putAllTags(ImmutableList.<RuleTagDto>of());
- checkTagCount(0L);
- }
-
- @Test
- public void should_register_new_tags() throws Exception {
- ruleTags.putAllTags(ImmutableList.of(
- newRuleTagDto("tag1"),
- newRuleTagDto("tag2"),
- newRuleTagDto("tag3"),
- newRuleTagDto("tag4"),
- newRuleTagDto("tag5")
- ));
-
- checkTagCount(5L);
- }
-
-
- @Test
- public void should_remove_unused_tags() throws Exception {
-
- esSetup.execute(
- indexTagDocument("tag4"),
- indexTagDocument("tag5"),
- indexTagDocument("tag6"),
- indexTagDocument("tag7"));
-
- ruleTags.putAllTags(ImmutableList.of(
- newRuleTagDto("tag1"),
- newRuleTagDto("tag2"),
- newRuleTagDto("tag3"),
- newRuleTagDto("tag4"),
- newRuleTagDto("tag5")
- ));
-
- checkTagCount(5L);
- }
-
- @Test
- public void should_delete_tags() throws Exception {
-
- esSetup.execute(
- indexTagDocument("tag1"),
- indexTagDocument("tag2"),
- indexTagDocument("tag3"),
- indexTagDocument("tag4"));
-
- ruleTags.delete("tag1", "tag2");
-
- checkTagCount(2L);
- }
-
- private void checkTagCount(long count) {
- assertThat(ruleTags.searchAllTags()).hasSize((int) count);
- }
-
- private RuleTagDto newRuleTagDto(String tagValue) {
- return new RuleTagDto().setTag(tagValue);
- }
-
- private Index indexTagDocument(String tagValue) {
- return EsSetup.index(RuleRegistry.INDEX_RULES, ESRuleTags.TYPE_TAG).withSource(String.format("{\"value\":\"%s\"}", tagValue));
- }
-}
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java
index 59c1cdcc04e..23ec6119db4 100644
--- a/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java
@@ -124,12 +124,6 @@ public class RubyRuleServiceTest {
}
@Test
- public void update_rule_tags() {
- facade.updateRuleTags(10, ImmutableList.of("tag1", "tag2"));
- verify(rules).updateRuleTags(10, ImmutableList.of("tag1", "tag2"));
- }
-
- @Test
public void find_by_key() {
facade.findByKey("repo:key");
verify(rules).findByKey(RuleKey.of("repo", "key"));
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RuleOperationsTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RuleOperationsTest.java
index bc4abd91090..ac8c9b3181f 100644
--- a/sonar-server/src/test/java/org/sonar/server/rule/RuleOperationsTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/rule/RuleOperationsTest.java
@@ -46,9 +46,6 @@ import org.sonar.core.qualityprofile.db.ActiveRuleDto;
import org.sonar.core.rule.RuleDao;
import org.sonar.core.rule.RuleDto;
import org.sonar.core.rule.RuleParamDto;
-import org.sonar.core.rule.RuleRuleTagDto;
-import org.sonar.core.rule.RuleTagDao;
-import org.sonar.core.rule.RuleTagType;
import org.sonar.core.technicaldebt.db.CharacteristicDao;
import org.sonar.core.technicaldebt.db.CharacteristicDto;
import org.sonar.server.exceptions.BadRequestException;
@@ -59,7 +56,6 @@ import org.sonar.server.rule.RuleOperations.RuleChange;
import org.sonar.server.user.MockUserSession;
import org.sonar.server.user.UserSession;
-import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -94,15 +90,9 @@ public class RuleOperationsTest {
RuleDao ruleDao;
@Mock
- RuleTagDao ruleTagDao;
-
- @Mock
CharacteristicDao characteristicDao;
@Mock
- RuleTagOperations ruleTagOperations;
-
- @Mock
ESActiveRule esActiveRule;
@Mock
@@ -139,7 +129,7 @@ public class RuleOperationsTest {
}
}).when(activeRuleDao).insert(any(ActiveRuleDto.class), any(SqlSession.class));
- operations = new RuleOperations(myBatis, activeRuleDao, ruleDao, ruleTagDao, characteristicDao, ruleTagOperations, esActiveRule, ruleRegistry, system);
+ operations = new RuleOperations(myBatis, activeRuleDao, ruleDao, characteristicDao, esActiveRule, ruleRegistry, system);
}
@Test
@@ -148,8 +138,6 @@ public class RuleOperationsTest {
List<RuleParamDto> ruleParams = newArrayList(new RuleParamDto().setId(20).setName("max").setDefaultValue("10"));
when(ruleDao.selectParametersByRuleId(eq(10), eq(session))).thenReturn(ruleParams);
- List<RuleRuleTagDto> ruleTags = newArrayList(new RuleRuleTagDto().setId(30L).setTag("style").setType(RuleTagType.SYSTEM));
- when(ruleDao.selectTagsByRuleIds(eq(10), eq(session))).thenReturn(ruleTags);
operations.updateRuleNote(rule, "My note", authorizedUserSession);
@@ -185,8 +173,6 @@ public class RuleOperationsTest {
List<RuleParamDto> ruleParams = newArrayList(new RuleParamDto().setId(20).setName("max").setDefaultValue("10"));
when(ruleDao.selectParametersByRuleId(eq(10), eq(session))).thenReturn(ruleParams);
- List<RuleRuleTagDto> ruleTags = newArrayList(new RuleRuleTagDto().setId(30L).setTag("style").setType(RuleTagType.SYSTEM));
- when(ruleDao.selectTagsByRuleIds(eq(10), eq(session))).thenReturn(ruleTags);
operations.updateRuleNote(rule, "My new note", MockUserSession.create().setLogin("guy").setName("Guy").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN));
@@ -208,8 +194,6 @@ public class RuleOperationsTest {
List<RuleParamDto> ruleParams = newArrayList(new RuleParamDto().setId(20).setName("max").setDefaultValue("10"));
when(ruleDao.selectParametersByRuleId(eq(10), eq(session))).thenReturn(ruleParams);
- List<RuleRuleTagDto> ruleTags = newArrayList(new RuleRuleTagDto().setId(30L).setTag("style").setType(RuleTagType.SYSTEM));
- when(ruleDao.selectTagsByRuleIds(eq(10), eq(session))).thenReturn(ruleTags);
long now = System.currentTimeMillis();
doReturn(now).when(system).now();
@@ -232,7 +216,6 @@ public class RuleOperationsTest {
RuleDto templateRule = new RuleDto().setId(10).setRepositoryKey("squid").setRuleKey("AvoidCycle").setConfigKey("Xpath")
.setDefaultSubCharacteristicId(2).setDefaultRemediationFunction("LINEAR_OFFSET").setDefaultRemediationCoefficient("2h").setDefaultRemediationOffset("15min");
when(ruleDao.selectParametersByRuleId(eq(10), eq(session))).thenReturn(newArrayList(new RuleParamDto().setId(20).setName("max").setDefaultValue("10")));
- when(ruleDao.selectTagsByRuleIds(eq(10), eq(session))).thenReturn(newArrayList(new RuleRuleTagDto().setId(30L).setTag("style").setType(RuleTagType.SYSTEM)));
Map<String, String> paramsByKey = ImmutableMap.of("max", "20");
RuleDto result = operations.createCustomRule(templateRule, "My New Rule", Severity.BLOCKER, "Rule Description", paramsByKey, authorizedUserSession);
@@ -259,11 +242,6 @@ public class RuleOperationsTest {
assertThat(ruleParamArgument.getValue().getName()).isEqualTo("max");
assertThat(ruleParamArgument.getValue().getDefaultValue()).isEqualTo("20");
- ArgumentCaptor<RuleRuleTagDto> ruleTagArgument = ArgumentCaptor.forClass(RuleRuleTagDto.class);
- verify(ruleDao).insert(ruleTagArgument.capture(), eq(session));
- assertThat(ruleTagArgument.getValue().getTag()).isEqualTo("style");
- assertThat(ruleTagArgument.getValue().getType()).isEqualTo(RuleTagType.SYSTEM);
-
verify(session).commit();
verify(ruleRegistry).reindex(eq(ruleArgument.getValue()), eq(session));
}
@@ -272,8 +250,6 @@ public class RuleOperationsTest {
public void update_custom_rule() throws Exception {
RuleDto rule = new RuleDto().setId(11).setRepositoryKey("squid").setRuleKey("XPath_1387869254").setConfigKey("Xpath");
when(ruleDao.selectParametersByRuleId(eq(11), eq(session))).thenReturn(newArrayList(new RuleParamDto().setId(21).setName("max").setDefaultValue("20")));
- ArrayList<RuleRuleTagDto> ruleTags = newArrayList(new RuleRuleTagDto().setId(30L).setTag("style").setType(RuleTagType.SYSTEM));
- when(ruleDao.selectTagsByRuleIds(eq(11), eq(session))).thenReturn(ruleTags);
Map<String, String> paramsByKey = ImmutableMap.of("max", "21");
operations.updateCustomRule(rule, "Updated Rule", Severity.MAJOR, "Updated Description", paramsByKey, authorizedUserSession);
@@ -298,8 +274,6 @@ public class RuleOperationsTest {
RuleDto rule = new RuleDto().setId(ruleId).setRepositoryKey("squid").setRuleKey("XPath_1387869254").setConfigKey("Xpath");//.setUpdatedAt(DateUtils.parseDate("2013-12-23"));
RuleParamDto param = new RuleParamDto().setId(21).setName("max").setDefaultValue("20");
when(ruleDao.selectParametersByRuleId(eq(ruleId), eq(session))).thenReturn(newArrayList(param));
- ArrayList<RuleRuleTagDto> ruleTags = newArrayList(new RuleRuleTagDto().setId(30L).setTag("style").setType(RuleTagType.SYSTEM));
- when(ruleDao.selectTagsByRuleIds(eq(ruleId), eq(session))).thenReturn(ruleTags);
final int activeRuleId = 5;
ActiveRuleDto activeRule = new ActiveRuleDto().setId(activeRuleId).setProfileId(1).setRuleId(ruleId).setSeverity(Severity.MINOR);
@@ -318,74 +292,6 @@ public class RuleOperationsTest {
verify(esActiveRule).deleteActiveRules(newArrayList(activeRuleId));
}
- @Test(expected = ForbiddenException.class)
- public void fail_to_update_tags_on_unauthorized_user() {
- operations.updateRuleTags(new RuleDto(), ImmutableList.of("polop"), unauthorizedUserSession);
- }
-
- @Test(expected = NotFoundException.class)
- public void fail_to_update_tags_on_unknown_tag() {
- final String tag = "polop";
- when(ruleTagDao.selectId(tag, session)).thenReturn(null);
- operations.updateRuleTags(new RuleDto(), ImmutableList.of(tag), authorizedUserSession);
- }
-
- @Test
- public void add_new_tags() {
- final int ruleId = 24;
- final RuleDto rule = new RuleDto().setId(ruleId);
- final String tag = "polop";
- final long tagId = 42L;
- when(ruleTagDao.selectId(tag, session)).thenReturn(tagId);
-
- operations.updateRuleTags(rule, ImmutableList.of(tag), authorizedUserSession);
-
- verify(ruleTagDao).selectId(tag, session);
- ArgumentCaptor<RuleRuleTagDto> capture = ArgumentCaptor.forClass(RuleRuleTagDto.class);
- verify(ruleDao).insert(capture.capture(), eq(session));
- final RuleRuleTagDto newTag = capture.getValue();
- assertThat(newTag.getRuleId()).isEqualTo(ruleId);
- assertThat(newTag.getTagId()).isEqualTo(tagId);
- assertThat(newTag.getType()).isEqualTo(RuleTagType.ADMIN);
- verify(ruleDao).update(rule, session);
- verify(session).commit();
- }
-
- @Test
- public void delete_removed_tags() {
- final int ruleId = 24;
- final RuleDto rule = new RuleDto().setId(ruleId);
- final String tag = "polop";
- RuleRuleTagDto existingTag = new RuleRuleTagDto().setTag(tag).setType(RuleTagType.ADMIN);
- when(ruleDao.selectTagsByRuleIds(ruleId, session)).thenReturn(ImmutableList.of(existingTag));
-
- operations.updateRuleTags(rule, ImmutableList.<String>of(), authorizedUserSession);
-
- verify(ruleDao, atLeast(1)).selectTagsByRuleIds(ruleId, session);
- verify(ruleDao).deleteTag(existingTag, session);
- verify(ruleDao).update(rule, session);
- verify(ruleTagOperations).deleteUnusedTags(session);
- verify(session).commit();
- }
-
- @Test
- public void not_update_rule_tags_if_tags_unchanged() {
- final int ruleId = 24;
- final RuleDto rule = new RuleDto().setId(ruleId);
- final String tag = "polop";
- final long tagId = 42L;
- when(ruleTagDao.selectId(tag, session)).thenReturn(tagId);
- RuleRuleTagDto existingTag = new RuleRuleTagDto().setTag(tag).setType(RuleTagType.ADMIN);
- when(ruleDao.selectTagsByRuleIds(ruleId, session)).thenReturn(ImmutableList.of(existingTag));
-
- operations.updateRuleTags(rule, ImmutableList.of(tag), authorizedUserSession);
-
- verify(ruleTagDao).selectId(tag, session);
- verify(ruleDao).selectTagsByRuleIds(ruleId, session);
- verify(ruleTagOperations).deleteUnusedTags(session);
- verify(ruleDao, never()).update(rule);
- }
-
@Test
public void update_rule() throws Exception {
RuleDto dto = new RuleDto().setId(1).setRepositoryKey("squid").setRuleKey("UselessImportCheck")
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RuleRegistryTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RuleRegistryTest.java
index 89fc2dcdbda..32929d7b31e 100644
--- a/sonar-server/src/test/java/org/sonar/server/rule/RuleRegistryTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/rule/RuleRegistryTest.java
@@ -41,8 +41,6 @@ import org.sonar.core.profiling.Profiling;
import org.sonar.core.rule.RuleDao;
import org.sonar.core.rule.RuleDto;
import org.sonar.core.rule.RuleParamDto;
-import org.sonar.core.rule.RuleRuleTagDto;
-import org.sonar.core.rule.RuleTagType;
import org.sonar.core.technicaldebt.db.CharacteristicDao;
import org.sonar.core.technicaldebt.db.CharacteristicDto;
import org.sonar.server.es.ESIndex;
@@ -132,11 +130,6 @@ public class RuleRegistryTest {
new RuleParamDto().setRuleId(3).setName("name")
));
- when(ruleDao.selectTagsByRuleIds(newArrayList(3), session)).thenReturn(newArrayList(
- new RuleRuleTagDto().setRuleId(3).setTag("tag1").setType(RuleTagType.SYSTEM),
- new RuleRuleTagDto().setRuleId(3).setTag("tag2").setType(RuleTagType.SYSTEM),
- new RuleRuleTagDto().setRuleId(3).setTag("tag").setType(RuleTagType.ADMIN)));
-
when(characteristicDao.selectCharacteristicsByIds(newHashSet(11), session)).thenReturn(newArrayList(
new CharacteristicDto().setId(11).setKey("MODULARITY").setName("Modularity").setParentId(10)));
when(characteristicDao.selectCharacteristicsByIds(newHashSet(10), session)).thenReturn(newArrayList(
@@ -254,11 +247,6 @@ public class RuleRegistryTest {
new RuleParamDto().setRuleId(3).setName("name")
));
- when(ruleDao.selectTagsByRuleIds(newArrayList(3), session)).thenReturn(newArrayList(
- new RuleRuleTagDto().setRuleId(3).setTag("tag1").setType(RuleTagType.SYSTEM),
- new RuleRuleTagDto().setRuleId(3).setTag("tag2").setType(RuleTagType.SYSTEM),
- new RuleRuleTagDto().setRuleId(3).setTag("tag").setType(RuleTagType.ADMIN)));
-
when(characteristicDao.selectById(11, session)).thenReturn(new CharacteristicDto().setId(11).setKey("MODULARITY").setName("Modularity").setParentId(10));
when(characteristicDao.selectById(10, session)).thenReturn(new CharacteristicDto().setId(10).setKey("REUSABILITY").setName("Reusability"));
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RuleTagLookupTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RuleTagLookupTest.java
deleted file mode 100644
index 4c0f494e93b..00000000000
--- a/sonar-server/src/test/java/org/sonar/server/rule/RuleTagLookupTest.java
+++ /dev/null
@@ -1,42 +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.rule;
-
-import com.google.common.collect.ImmutableList;
-import org.junit.Test;
-
-import java.util.Collection;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class RuleTagLookupTest {
-
- @Test
- public void should_pass_to_es_impl() {
- ESRuleTags esRuleTags = mock(ESRuleTags.class);
- Collection<String> tags = ImmutableList.of("tag1", "tag2");
- when(esRuleTags.searchAllTags()).thenReturn(tags);
- assertThat(new RuleTagLookup(esRuleTags).listAllTags()).isEqualTo(tags);
- verify(esRuleTags).searchAllTags();
- }
-}
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RuleTagOperationsTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RuleTagOperationsTest.java
deleted file mode 100644
index 471177b9069..00000000000
--- a/sonar-server/src/test/java/org/sonar/server/rule/RuleTagOperationsTest.java
+++ /dev/null
@@ -1,117 +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.rule;
-
-import com.google.common.collect.ImmutableList;
-import org.apache.ibatis.session.SqlSession;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.core.rule.RuleTagDao;
-import org.sonar.core.rule.RuleTagDto;
-import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.user.MockUserSession;
-import org.sonar.server.user.UserSession;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class RuleTagOperationsTest {
-
- @Mock
- private RuleTagDao ruleTagDao;
-
- @Mock
- private ESRuleTags esRuleTags;
-
- UserSession authorizedUserSession = MockUserSession.create().setLogin("nicolas").setName("Nicolas").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
- UserSession unauthorizedUserSession = MockUserSession.create().setLogin("nicolas").setName("Nicolas");
-
- private RuleTagOperations operations;
-
- @Before
- public void setUp() {
- operations = new RuleTagOperations(ruleTagDao, esRuleTags);
- }
-
- @Test(expected = ForbiddenException.class)
- public void should_fail_on_unallowed_user() {
- operations.create("polop", unauthorizedUserSession);
- }
-
- @Test(expected = BadRequestException.class)
- public void should_fail_on_bad_tag() {
- operations.create("! ! !", authorizedUserSession);
- }
-
- @Test(expected = BadRequestException.class)
- public void should_fail_on_duplicate_tag() {
- String newTag = "polop";
- when(ruleTagDao.selectId(newTag)).thenReturn(42L);
-
- operations.create(newTag, authorizedUserSession);
- }
-
- @Test
- public void should_create_and_index_tag() {
- String newTag = "polop";
- when(ruleTagDao.selectId(newTag)).thenReturn(null);
-
- operations.create(newTag, authorizedUserSession);
-
- verify(ruleTagDao).selectId(newTag);
- ArgumentCaptor<RuleTagDto> newTagDto = ArgumentCaptor.forClass(RuleTagDto.class);
- verify(ruleTagDao).insert(newTagDto.capture());
- assertThat(newTagDto.getValue().getTag()).isEqualTo(newTag);
- verify(esRuleTags).put(newTagDto.getValue());
- }
-
- @Test
- public void should_delete_unused_tags() {
- long tagId = 42L;
- String tagValue = "answerlifeanevrythng";
- RuleTagDto unusedTag = new RuleTagDto().setId(tagId).setTag(tagValue);
- SqlSession session = mock(SqlSession.class);
- when(ruleTagDao.selectUnused(session)).thenReturn(ImmutableList.of(unusedTag));
- operations.deleteUnusedTags(session);
-
- verify(ruleTagDao).selectUnused(session);
- verify(ruleTagDao).delete(tagId, session);
- verify(esRuleTags).delete(tagValue);
- }
-
- @Test
- public void should_do_nothing_if_no_unused_tags() {
- SqlSession session = mock(SqlSession.class);
- operations.deleteUnusedTags(session);
-
- verify(ruleTagDao).selectUnused(session);
- verifyNoMoreInteractions(ruleTagDao, esRuleTags);
- }
-}
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RuleTagsTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RuleTagsTest.java
deleted file mode 100644
index f906ac5b476..00000000000
--- a/sonar-server/src/test/java/org/sonar/server/rule/RuleTagsTest.java
+++ /dev/null
@@ -1,72 +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.rule;
-
-import com.google.common.collect.ImmutableList;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.core.rule.RuleTagDto;
-import org.sonar.server.user.UserSession;
-
-import java.util.Collection;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class RuleTagsTest {
-
- @Mock
- private RuleTagLookup ruleTagLookup;
-
- @Mock
- private RuleTagOperations ruleTagOperations;
-
- private RuleTags ruleTags;
-
- @Before
- public void setUp() {
- ruleTags = new RuleTags(ruleTagLookup, ruleTagOperations);
- }
-
- @Test
- public void should_find_all_tags() {
- Collection<String> tags = ImmutableList.of("tag1", "tag2");
- when(ruleTagLookup.listAllTags()).thenReturn(tags);
- assertThat(ruleTags.listAllTags()).isEqualTo(tags);
- verify(ruleTagLookup).listAllTags();
- }
-
- @Test
- public void should_create_tag() {
- String tag = "polop";
- RuleTagDto newTag = mock(RuleTagDto.class);
- when(ruleTagOperations.create(eq(tag), any(UserSession.class))).thenReturn(newTag);
- assertThat(ruleTags.create(tag)).isEqualTo(newTag);
- verify(ruleTagOperations).create(eq(tag), any(UserSession.class));
- }
-}
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RulesTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RulesTest.java
index d507fd008a9..54684962be9 100644
--- a/sonar-server/src/test/java/org/sonar/server/rule/RulesTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/rule/RulesTest.java
@@ -201,27 +201,6 @@ public class RulesTest {
}
@Test
- public void pass_tags_to_update() {
- final int ruleId = 11;
- RuleDto rule = new RuleDto().setId(ruleId).setRepositoryKey("squid").setRuleKey("XPath_1387869254").setParentId(10);
- when(ruleDao.selectById(ruleId)).thenReturn(rule);
-
- rules.updateRuleTags(ruleId, null);
- verify(ruleOperations).updateRuleTags(eq(rule), isA(List.class), any(UserSession.class));
- }
-
- @Test
- public void prepare_empty_tag_list() {
- final int ruleId = 11;
- RuleDto rule = new RuleDto().setId(ruleId).setRepositoryKey("squid").setRuleKey("XPath_1387869254").setParentId(10);
- when(ruleDao.selectById(ruleId)).thenReturn(rule);
-
- List<String> tags = ImmutableList.of("tag1", "tag2");
- rules.updateRuleTags(ruleId, tags);
- verify(ruleOperations).updateRuleTags(eq(rule), eq(tags), any(UserSession.class));
- }
-
- @Test
public void find_by_key() {
RuleKey key = RuleKey.of("polop", "palap");
Rule rule = mock(Rule.class);
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/ws/AddTagsWsHandlerTest.java b/sonar-server/src/test/java/org/sonar/server/rule/ws/AddTagsWsHandlerTest.java
deleted file mode 100644
index 3476eb15ef6..00000000000
--- a/sonar-server/src/test/java/org/sonar/server/rule/ws/AddTagsWsHandlerTest.java
+++ /dev/null
@@ -1,90 +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.rule.ws;
-
-import com.google.common.collect.ImmutableList;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.rule.Rule;
-import org.sonar.server.rule.Rules;
-import org.sonar.server.user.MockUserSession;
-import org.sonar.server.ws.WsTester;
-
-import java.util.List;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.isA;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class AddTagsWsHandlerTest {
-
- @Mock
- Rules rules;
-
- WsTester tester;
-
- @Before
- public void setUp() throws Exception {
- tester = new WsTester(new RulesWs(mock(RuleSearchWsHandler.class), mock(RuleShowWsHandler.class), new AddTagsWsHandler(rules), mock(RemoveTagsWsHandler.class)));
- }
-
- @Test
- public void add_tags() throws Exception {
- String ruleKey = "squid:AvoidCycle";
- Rule rule = createStandardRule();
- when(rules.findByKey(RuleKey.of("squid", "AvoidCycle"))).thenReturn(rule);
-
- MockUserSession.set().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
- WsTester.TestRequest request = tester.newPostRequest("api/rules", "add_tags").setParam("key", ruleKey).setParam("tags", "tag1,tag2");
- request.execute().assertNoContent();
-
- ArgumentCaptor<Object> newTagsCaptor = ArgumentCaptor.forClass(Object.class);
- verify(rules).updateRuleTags(isA(Integer.class), newTagsCaptor.capture());
- Object newTags = newTagsCaptor.getValue();
- assertThat(newTags).isInstanceOf(List.class);
- assertThat((List<String>) newTags).hasSize(4).containsOnly("admin1", "admin2", "tag1", "tag2");
- }
-
- @Test(expected = NotFoundException.class)
- public void add_tags_key_not_found() throws Exception {
- tester.newPostRequest("api/rules", "add_tags").setParam("key", "polop:palap").setParam("tags", "tag1,tag2").execute();
- }
-
- private Rule create(String repoKey, String key, String name, String description) {
- Rule mockRule = mock(Rule.class);
- when(mockRule.adminTags()).thenReturn(ImmutableList.of("admin1", "admin2"));
- return mockRule;
- }
-
- private Rule createStandardRule() {
- return create("xoo", "RuleWithTags", "Rule with tags", "This rule has tags set");
- }
-}
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/ws/RemoveTagsWsHandlerTest.java b/sonar-server/src/test/java/org/sonar/server/rule/ws/RemoveTagsWsHandlerTest.java
deleted file mode 100644
index 37b5c1a8434..00000000000
--- a/sonar-server/src/test/java/org/sonar/server/rule/ws/RemoveTagsWsHandlerTest.java
+++ /dev/null
@@ -1,84 +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.rule.ws;
-
-import com.google.common.collect.ImmutableList;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.server.rule.Rule;
-import org.sonar.server.rule.Rules;
-import org.sonar.server.user.MockUserSession;
-import org.sonar.server.ws.WsTester;
-
-import java.util.List;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.isA;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class RemoveTagsWsHandlerTest {
-
- @Mock
- Rules rules;
-
- WsTester tester;
-
- @Before
- public void setUp() throws Exception {
- tester = new WsTester(new RulesWs(mock(RuleSearchWsHandler.class), mock(RuleShowWsHandler.class), mock(AddTagsWsHandler.class), new RemoveTagsWsHandler(rules)));
- }
-
- @Test
- public void add_tags() throws Exception {
- String ruleKey = "squid:AvoidCycle";
- Rule rule = createStandardRule();
- when(rules.findByKey(RuleKey.of("squid", "AvoidCycle"))).thenReturn(rule);
-
- MockUserSession.set().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
- WsTester.TestRequest request = tester.newPostRequest("api/rules", "remove_tags").setParam("key", ruleKey).setParam("tags", "admin2,admin3,polop");
- request.execute().assertNoContent();
-
- ArgumentCaptor<Object> newTagsCaptor = ArgumentCaptor.forClass(Object.class);
- verify(rules).updateRuleTags(isA(Integer.class), newTagsCaptor.capture());
- Object newTags = newTagsCaptor.getValue();
- assertThat(newTags).isInstanceOf(List.class);
- assertThat((List<String>) newTags).hasSize(2).containsOnly("admin1", "admin4");
- }
-
- private Rule create(String repoKey, String key, String name, String description) {
- Rule mockRule = mock(Rule.class);
- when(mockRule.adminTags()).thenReturn(ImmutableList.of("admin1", "admin2", "admin3", "admin4"));
- return mockRule;
- }
-
- private Rule createStandardRule() {
- return create("xoo", "RuleWithTags", "Rule with tags", "This rule has tags set");
- }
-}
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleSearchWsHandlerTest.java b/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleSearchWsHandlerTest.java
index fb896e371ed..f9022f54271 100644
--- a/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleSearchWsHandlerTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleSearchWsHandlerTest.java
@@ -68,7 +68,7 @@ public class RuleSearchWsHandlerTest {
@Before
public void setUp() throws Exception {
- tester = new WsTester(new RulesWs(new RuleSearchWsHandler(rules, languages), mock(RuleShowWsHandler.class), mock(AddTagsWsHandler.class), mock(RemoveTagsWsHandler.class)));
+ tester = new WsTester(new RulesWs(new RuleSearchWsHandler(rules, languages), mock(RuleShowWsHandler.class)));
}
@Test
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleShowWsHandlerTest.java b/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleShowWsHandlerTest.java
index 62817bd59ab..e426dd95bf8 100644
--- a/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleShowWsHandlerTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleShowWsHandlerTest.java
@@ -75,7 +75,7 @@ public class RuleShowWsHandlerTest {
@Before
public void setUp() throws Exception {
- tester = new WsTester(new RulesWs(mock(RuleSearchWsHandler.class), new RuleShowWsHandler(rules, ruleFinder, i18n, languages), mock(AddTagsWsHandler.class), mock(RemoveTagsWsHandler.class)));
+ tester = new WsTester(new RulesWs(mock(RuleSearchWsHandler.class), new RuleShowWsHandler(rules, ruleFinder, i18n, languages)));
}
@Test
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleTagsWsTest.java b/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleTagsWsTest.java
deleted file mode 100644
index 2981115d70c..00000000000
--- a/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleTagsWsTest.java
+++ /dev/null
@@ -1,104 +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.rule.ws;
-
-import com.google.common.collect.ImmutableList;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.core.rule.RuleTagDto;
-import org.sonar.server.rule.RuleTags;
-import org.sonar.server.ws.WsTester;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-import static org.mockito.Mockito.*;
-
-@RunWith(MockitoJUnitRunner.class)
-public class RuleTagsWsTest {
-
- @Mock
- RuleTags ruleTags;
-
- WsTester tester;
-
- @Before
- public void setUp() {
- tester = new WsTester(new RuleTagsWs(ruleTags));
- }
-
- @Test
- public void define_ws() throws Exception {
- WebService.Controller controller = tester.controller("api/rule_tags");
- assertThat(controller).isNotNull();
- assertThat(controller.path()).isEqualTo("api/rule_tags");
- assertThat(controller.description()).isNotEmpty();
- assertThat(controller.actions()).hasSize(2);
-
- WebService.Action search = controller.action("list");
- assertThat(search).isNotNull();
- assertThat(search.key()).isEqualTo("list");
- assertThat(search.handler()).isNotNull();
- assertThat(search.since()).isEqualTo("4.2");
- assertThat(search.isPost()).isFalse();
-
- WebService.Action create = controller.action("create");
- assertThat(create).isNotNull();
- assertThat(create.key()).isEqualTo("create");
- assertThat(create.handler()).isNotNull();
- assertThat(create.since()).isEqualTo("4.2");
- assertThat(create.isPost()).isTrue();
- assertThat(create.params()).hasSize(1);
- assertThat(create.param("tag")).isNotNull();
- }
-
- @Test
- public void list_tags() throws Exception {
- when(ruleTags.listAllTags()).thenReturn(ImmutableList.of("tag1", "tag2", "tag3"));
- tester.newGetRequest("api/rule_tags", "list").execute().assertJson(getClass(), "list.json");
- verify(ruleTags).listAllTags();
- }
-
- @Test
- public void create_ok() throws Exception {
- String tag = "newtag";
- Long tagId = 42L;
- RuleTagDto newTag = new RuleTagDto().setId(tagId).setTag(tag);
- when(ruleTags.create("newtag")).thenReturn(newTag);
-
- WsTester.TestRequest request = tester.newPostRequest("api/rule_tags", "create").setParam("tag", tag);
- request.execute().assertJson(getClass(), "create_ok.json");
- verify(ruleTags).create(tag);
- }
-
- @Test
- public void create_missing_parameter() throws Exception {
- WsTester.TestRequest request = tester.newPostRequest("api/rule_tags", "create");
- try {
- request.execute();
- fail();
- } catch (IllegalArgumentException e) {
- verifyZeroInteractions(ruleTags);
- }
- }
-}
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsTest.java b/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsTest.java
index a513d509ff4..45cbb6b365e 100644
--- a/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsTest.java
@@ -38,17 +38,11 @@ public class RulesWsTest {
@Mock
RuleShowWsHandler showHandler;
- @Mock
- AddTagsWsHandler addTagsWsHandler;
-
- @Mock
- RemoveTagsWsHandler removeTagsWsHandler;
-
WsTester tester;
@Before
public void setUp() {
- tester = new WsTester(new RulesWs(searchHandler, showHandler, addTagsWsHandler, removeTagsWsHandler));
+ tester = new WsTester(new RulesWs(searchHandler, showHandler));
}
@Test
@@ -57,7 +51,7 @@ public class RulesWsTest {
assertThat(controller).isNotNull();
assertThat(controller.path()).isEqualTo("api/rules");
assertThat(controller.description()).isNotEmpty();
- assertThat(controller.actions()).hasSize(4);
+ assertThat(controller.actions()).hasSize(2);
WebService.Action list = controller.action("list");
assertThat(list).isNotNull();
@@ -73,21 +67,5 @@ public class RulesWsTest {
assertThat(show.since()).isEqualTo("4.2");
assertThat(show.isPost()).isFalse();
assertThat(show.isInternal()).isFalse();
-
- WebService.Action addTags = controller.action("add_tags");
- assertThat(addTags).isNotNull();
- assertThat(addTags.handler()).isNotNull();
- assertThat(addTags.since()).isEqualTo("4.2");
- assertThat(addTags.isPost()).isTrue();
- assertThat(addTags.isInternal()).isFalse();
- assertThat(addTags.params()).hasSize(2);
-
- WebService.Action removeTags = controller.action("remove_tags");
- assertThat(removeTags).isNotNull();
- assertThat(removeTags.handler()).isNotNull();
- assertThat(removeTags.since()).isEqualTo("4.2");
- assertThat(removeTags.isPost()).isTrue();
- assertThat(removeTags.isInternal()).isFalse();
- assertThat(removeTags.params()).hasSize(2);
}
}
diff --git a/sonar-server/src/test/java/org/sonar/server/rule2/RegisterRulesMediumTest.java b/sonar-server/src/test/java/org/sonar/server/rule2/RegisterRulesMediumTest.java
new file mode 100644
index 00000000000..aaa75d55226
--- /dev/null
+++ b/sonar-server/src/test/java/org/sonar/server/rule2/RegisterRulesMediumTest.java
@@ -0,0 +1,117 @@
+/*
+ * 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.rule2;
+
+import org.junit.Test;
+import org.sonar.api.rule.Severity;
+import org.sonar.api.server.rule.RuleParamType;
+import org.sonar.api.server.rule.RulesDefinition;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.rule.RuleDto;
+import org.sonar.core.rule.RuleParamDto;
+import org.sonar.server.db.DbClient;
+import org.sonar.server.platform.Platform;
+import org.sonar.server.rule2.index.RuleIndex;
+import org.sonar.server.rule2.index.RuleQuery;
+import org.sonar.server.rule2.index.RuleResult;
+import org.sonar.server.rule2.persistence.RuleDao;
+import org.sonar.server.search.QueryOptions;
+import org.sonar.server.tester.ServerTester;
+
+import java.util.List;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class RegisterRulesMediumTest {
+
+ @org.junit.Rule
+ public ServerTester tester = new ServerTester().addComponents(XooRulesDefinition.class);
+
+ @Test
+ public void register_rules_at_startup() throws Exception {
+ verifyRulesInDb();
+
+ RuleIndex index = tester.get(RuleIndex.class);
+ index.refresh();
+
+ RuleResult searchResult = index.search(new RuleQuery(), new QueryOptions());
+ assertThat(searchResult.getTotal()).isEqualTo(2);
+ assertThat(searchResult.getHits()).hasSize(2);
+ }
+
+ @Test
+ public void index_even_if_no_changes() throws Exception {
+ RuleIndex index = tester.get(RuleIndex.class);
+
+ verifyRulesInDb();
+
+ // clear ES but keep db
+ tester.clearIndexes();
+ verifyRulesInDb();
+ RuleResult searchResult = index.search(new RuleQuery(), new QueryOptions());
+ assertThat(searchResult.getTotal()).isEqualTo(0);
+ assertThat(searchResult.getHits()).hasSize(0);
+
+ // db is not updated (same rules) but es must be reindexed
+ tester.get(Platform.class).restart();
+
+ index = tester.get(RuleIndex.class);
+ index.refresh();
+ verifyRulesInDb();
+ searchResult = index.search(new RuleQuery().setKey("xoo:x1"), new QueryOptions());
+ assertThat(searchResult.getTotal()).isEqualTo(1);
+ assertThat(searchResult.getHits()).hasSize(1);
+ assertThat(searchResult.getHits().get(0).params()).hasSize(1);
+ }
+
+ private void verifyRulesInDb() {
+ RuleDao dao = tester.get(RuleDao.class);
+ DbClient dbClient = tester.get(DbClient.class);
+ DbSession session = dbClient.openSession(false);
+ List<RuleDto> rules = dao.findAll(session);
+ assertThat(rules).hasSize(2);
+ List<RuleParamDto> ruleParams = dao.findAllRuleParams(session);
+ assertThat(ruleParams).hasSize(1);
+ }
+
+ public static class XooRulesDefinition implements RulesDefinition {
+ @Override
+ public void define(Context context) {
+ NewRepository repository = context.createRepository("xoo", "xoo").setName("Xoo Repo");
+ repository.createRule("x1")
+ .setName("x1 name")
+ .setHtmlDescription("x1 desc")
+ .setSeverity(Severity.MINOR)
+ .createParam("acceptWhitespace")
+ .setDefaultValue("false")
+ .setType(RuleParamType.BOOLEAN)
+ .setDescription("Accept whitespaces on the line");
+
+
+
+ repository.createRule("x2")
+ .setName("x2 name")
+ .setHtmlDescription("x2 desc")
+ .setSeverity(Severity.MAJOR);
+ repository.done();
+ }
+ }
+}
diff --git a/sonar-server/src/test/java/org/sonar/server/rule2/RegisterRulesTest.java b/sonar-server/src/test/java/org/sonar/server/rule2/RegisterRulesTest.java
index 2c7e8890be1..a5865a143f5 100644
--- a/sonar-server/src/test/java/org/sonar/server/rule2/RegisterRulesTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/rule2/RegisterRulesTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.server.rule2;
+import com.google.common.collect.Sets;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -80,6 +81,7 @@ public class RegisterRulesTest extends AbstractDaoTestCase {
public void insert_new_rules() {
execute(new FakeRepositoryV1());
+ // verify db
assertThat(dbClient.ruleDao().findAll(dbSession)).hasSize(2);
RuleKey ruleKey1 = RuleKey.of("fake", "rule1");
RuleDto rule1 = dbClient.ruleDao().getByKey(ruleKey1, dbSession);
@@ -121,16 +123,22 @@ public class RegisterRulesTest extends AbstractDaoTestCase {
execute(new FakeRepositoryV1());
assertThat(dbClient.ruleDao().findAll(dbSession)).hasSize(2);
+ // user adds tags
+ RuleKey ruleKey1 = RuleKey.of("fake", "rule1");
+ RuleDto rule1 = dbClient.ruleDao().getByKey(ruleKey1, dbSession);
+ rule1.setTags(Sets.newHashSet("usertag1", "usertag2"));
+ dbClient.ruleDao().update(rule1, dbSession);
+ dbSession.commit();
+
when(system.now()).thenReturn(DATE2.getTime());
execute(new FakeRepositoryV2());
// rule1 has been updated
- RuleKey ruleKey1 = RuleKey.of("fake", "rule1");
- RuleDto rule1 = dbClient.ruleDao().getByKey(ruleKey1, dbSession);
+ rule1 = dbClient.ruleDao().getByKey(ruleKey1, dbSession);
assertThat(rule1.getName()).isEqualTo("One v2");
assertThat(rule1.getDescription()).isEqualTo("Description of One v2");
assertThat(rule1.getSeverityString()).isEqualTo(Severity.INFO);
- assertThat(rule1.getTags()).isEmpty();
+ assertThat(rule1.getTags()).containsOnly("usertag1", "usertag2");
assertThat(rule1.getSystemTags()).containsOnly("tag1", "tag4");
assertThat(rule1.getConfigKey()).isEqualTo("config1 v2");
assertThat(rule1.getStatus()).isEqualTo(RuleStatus.READY.toString());
@@ -152,6 +160,7 @@ public class RegisterRulesTest extends AbstractDaoTestCase {
// rule3 has been created
RuleDto rule3 = dbClient.ruleDao().getByKey(RuleKey.of("fake", "rule3"), dbSession);
assertThat(rule3).isNotNull();
+ assertThat(rule3.getStatus()).isEqualTo(RuleStatus.READY.toString());
}
@Test
diff --git a/sonar-server/src/test/java/org/sonar/server/rule2/persistence/RuleDaoTest.java b/sonar-server/src/test/java/org/sonar/server/rule2/persistence/RuleDaoTest.java
index 86a2f90a317..37bd788237c 100644
--- a/sonar-server/src/test/java/org/sonar/server/rule2/persistence/RuleDaoTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/rule2/persistence/RuleDaoTest.java
@@ -386,16 +386,4 @@ public class RuleDaoTest extends AbstractDaoTestCase {
checkTables("update_parameter", "rules_parameters");
}
-
- @Test
- public void select_tags_by_rule() throws Exception {
- setupData("select_tags_by_rule_id");
-
- RuleDto rule = dao.getById(1, session);
- assertThat(rule.getSystemTags()).hasSize(2);
- assertThat(rule.getTags()).hasSize(3);
- assertThat(rule.getTags()).containsOnly("tag1", "tag2","tag3");
- assertThat(rule.getSystemTags()).containsOnly("systag1", "systag2");
-
- }
}
diff --git a/sonar-server/src/test/java/org/sonar/server/tester/DataStoreCleanup.java b/sonar-server/src/test/java/org/sonar/server/tester/DataStoreCleanup.java
index 0e1da622753..2437b39df89 100644
--- a/sonar-server/src/test/java/org/sonar/server/tester/DataStoreCleanup.java
+++ b/sonar-server/src/test/java/org/sonar/server/tester/DataStoreCleanup.java
@@ -43,12 +43,12 @@ public class DataStoreCleanup implements ServerComponent {
this.myBatis = myBatis;
}
- public void clear() {
- truncateDb();
- truncateEs();
+ public void clearAll() {
+ clearDb();
+ clearIndexes();
}
- private void truncateDb() {
+ public void clearDb() {
DbSession dbSession = myBatis.openSession(false);
Connection connection = dbSession.getConnection();
try {
@@ -68,7 +68,7 @@ public class DataStoreCleanup implements ServerComponent {
}
}
- private void truncateEs() {
+ public void clearIndexes() {
LOG.info("Truncate es indices");
Client client = esNode.client();
client.prepareDeleteByQuery(
diff --git a/sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java b/sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java
index 783cff96a7c..5e5c1d4dc28 100644
--- a/sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java
+++ b/sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java
@@ -159,7 +159,12 @@ public class ServerTester extends ExternalResource {
*/
public void clearDataStores() {
checkStarted();
- get(DataStoreCleanup.class).clear();
+ get(DataStoreCleanup.class).clearAll();
+ }
+
+ public void clearIndexes() {
+ checkStarted();
+ get(DataStoreCleanup.class).clearIndexes();
}
/**
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_repositories-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_repositories-result.xml
index f350c52f77b..0c0534a73ab 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_repositories-result.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_repositories-result.xml
@@ -7,9 +7,6 @@
status="READY" priority="4" cardinality="SINGLE" parent_id="[null]" language="java"/>
<rules_parameters id="1" rule_id="2" default_value="default value one" description="parameter one" name="param1" param_type="STRING"/>
<rules_parameters id="2" rule_id="2" default_value="default value two" description="parameter two" name="param2" param_type="STRING"/>
- <rule_tags id="1" rule_id="2" tag="tag1" tag_type="SYSTEM"/>
- <rule_tags id="2" rule_id="2" tag="tag3" tag_type="SYSTEM"/>
- <rule_tags id="3" rule_id="2" tag="tag5" tag_type="SYSTEM"/>
<rules tags="[null]" system_tags="[null]" id="3" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="rule2" name="Two" description="Description of Two"
status="DEPRECATED" priority="0" cardinality="SINGLE" parent_id="[null]" language="java"/>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_rules-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_rules-result.xml
index fdf0c45f489..2b80f2f4466 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_rules-result.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_rules-result.xml
@@ -17,12 +17,4 @@
<rules tags="[null]" system_tags="[null]" id="4" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="[null]" name="Two" description="Description of Two"
status="DEPRECATED" priority="0" cardinality="SINGLE" parent_id="[null]" language="java"/>
- <rule_tags id="3" tag="tag1"/>
- <rule_tags id="4" tag="tag3"/>
- <rule_tags id="5" tag="tag5"/>
-
- <rules_rule_tags id="3" rule_id="3" rule_tag_id="3" tag_type="SYSTEM"/>
- <rules_rule_tags id="4" rule_id="3" rule_tag_id="4" tag_type="SYSTEM"/>
- <rules_rule_tags id="5" rule_id="3" rule_tag_id="5" tag_type="SYSTEM"/>
-
</dataset>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_rules.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_rules.xml
index 2c47ca23004..c894e0097fd 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_rules.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_rules.xml
@@ -8,10 +8,4 @@
<rules_parameters id="1" rule_id="1" name="deprecated-prop" description="[null]" param_type="STRING"/>
- <rule_tags id="1" tag="formertag1"/>
- <rule_tags id="2" tag="formertag2"/>
-
- <rules_rule_tags id="1" rule_id="1" rule_tag_id="1" tag_type="SYSTEM"/>
- <rules_rule_tags id="2" rule_id="1" rule_tag_id="2" tag_type="ADMIN"/>
-
</dataset>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/insert_new_rules-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/insert_new_rules-result.xml
index 0578a3d9262..24c65625e65 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/insert_new_rules-result.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/insert_new_rules-result.xml
@@ -19,14 +19,6 @@
<rules_parameters id="1" rule_id="2" default_value="default value one" description="parameter one" name="param1" param_type="STRING"/>
<rules_parameters id="2" rule_id="2" default_value="default value two" description="parameter two" name="param2" param_type="STRING"/>
- <rule_tags id="1" tag="tag1"/>
- <rule_tags id="2" tag="tag3"/>
- <rule_tags id="3" tag="tag5"/>
-
- <rules_rule_tags id="1" rule_id="2" rule_tag_id="1" tag_type="SYSTEM"/>
- <rules_rule_tags id="2" rule_id="2" rule_tag_id="2" tag_type="SYSTEM"/>
- <rules_rule_tags id="3" rule_id="2" rule_tag_id="3" tag_type="SYSTEM"/>
-
<rules tags="[null]" system_tags="[null]" id="3" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="[null]" name="Two" description="Description of Two"
status="DEPRECATED" priority="0" cardinality="SINGLE" parent_id="[null]" language="java"
characteristic_id="[null]" default_characteristic_id="[null]"
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/update_rule_fields-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/update_rule_fields-result.xml
index 7ac88187557..733251902b6 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/update_rule_fields-result.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/update_rule_fields-result.xml
@@ -11,16 +11,6 @@
<rules_parameters id="1" rule_id="1" default_value="default value one" description="parameter one" name="param1" param_type="STRING"/>
<rules_parameters id="2" rule_id="1" default_value="default value two" description="parameter two" name="param2" param_type="STRING"/>
- <rule_tags id="1" tag="tag1"/>
- <rule_tags id="3" tag="tag3"/>
- <rule_tags id="4" tag="tag4"/>
- <rule_tags id="5" tag="tag5"/>
-
- <rules_rule_tags id="1" rule_id="1" rule_tag_id="1" tag_type="SYSTEM"/>
- <rules_rule_tags id="3" rule_id="1" rule_tag_id="3" tag_type="SYSTEM"/>
- <rules_rule_tags id="4" rule_id="1" rule_tag_id="4" tag_type="ADMIN"/>
- <rules_rule_tags id="5" rule_id="1" rule_tag_id="5" tag_type="SYSTEM"/>
-
<rules tags="[null]" system_tags="[null]" id="2" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="[null]" name="Two" description="Description of Two"
status="DEPRECATED" priority="0" cardinality="SINGLE" parent_id="[null]" language="java"
characteristic_id="[null]" default_characteristic_id="[null]"
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/update_rule_fields.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/update_rule_fields.xml
index dddc193f1d8..7f35c78b072 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/update_rule_fields.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/update_rule_fields.xml
@@ -12,16 +12,6 @@
<rules_parameters id="1" rule_id="1" name="param1" description="[null]" param_type="STRING"/>
- <rule_tags id="1" tag="tag1"/>
- <rule_tags id="2" tag="tag2"/>
- <rule_tags id="3" tag="tag3"/>
- <rule_tags id="4" tag="tag4"/>
-
- <rules_rule_tags id="1" rule_id="1" rule_tag_id="1" tag_type="SYSTEM"/>
- <rules_rule_tags id="2" rule_id="1" rule_tag_id="2" tag_type="SYSTEM"/>
- <rules_rule_tags id="3" rule_id="1" rule_tag_id="3" tag_type="ADMIN"/>
- <rules_rule_tags id="4" rule_id="1" rule_tag_id="4" tag_type="ADMIN"/>
-
<rules tags="[null]" system_tags="[null]" id="2" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="old_config_key2" name="old name2" description="old description2"
status="READY" priority="1" cardinality="SINGLE" parent_id="[null]"/>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/ws/RuleTagsWsTest/create_ok.json b/sonar-server/src/test/resources/org/sonar/server/rule/ws/RuleTagsWsTest/create_ok.json
deleted file mode 100644
index 708d9ffb525..00000000000
--- a/sonar-server/src/test/resources/org/sonar/server/rule/ws/RuleTagsWsTest/create_ok.json
+++ /dev/null
@@ -1 +0,0 @@
-{"id":42,"tag":"newtag"}
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/ws/RuleTagsWsTest/list.json b/sonar-server/src/test/resources/org/sonar/server/rule/ws/RuleTagsWsTest/list.json
deleted file mode 100644
index eeeb09cb836..00000000000
--- a/sonar-server/src/test/resources/org/sonar/server/rule/ws/RuleTagsWsTest/list.json
+++ /dev/null
@@ -1 +0,0 @@
-["tag1","tag2","tag3"]
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/RegisterRulesTest/disable_deprecated_repositories-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule2/RegisterRulesTest/disable_deprecated_repositories-result.xml
index f350c52f77b..0c0534a73ab 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule2/RegisterRulesTest/disable_deprecated_repositories-result.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule2/RegisterRulesTest/disable_deprecated_repositories-result.xml
@@ -7,9 +7,6 @@
status="READY" priority="4" cardinality="SINGLE" parent_id="[null]" language="java"/>
<rules_parameters id="1" rule_id="2" default_value="default value one" description="parameter one" name="param1" param_type="STRING"/>
<rules_parameters id="2" rule_id="2" default_value="default value two" description="parameter two" name="param2" param_type="STRING"/>
- <rule_tags id="1" rule_id="2" tag="tag1" tag_type="SYSTEM"/>
- <rule_tags id="2" rule_id="2" tag="tag3" tag_type="SYSTEM"/>
- <rule_tags id="3" rule_id="2" tag="tag5" tag_type="SYSTEM"/>
<rules tags="[null]" system_tags="[null]" id="3" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="rule2" name="Two" description="Description of Two"
status="DEPRECATED" priority="0" cardinality="SINGLE" parent_id="[null]" language="java"/>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/persistence/RuleDaoTest/select_tags_by_rule_id.xml b/sonar-server/src/test/resources/org/sonar/server/rule2/persistence/RuleDaoTest/select_tags_by_rule_id.xml
deleted file mode 100644
index 3feba4d4b8e..00000000000
--- a/sonar-server/src/test/resources/org/sonar/server/rule2/persistence/RuleDaoTest/select_tags_by_rule_id.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-<dataset>
-
- <rules tags="tag1,tag2,tag3" system_tags="systag1,systag2" id="1" plugin_rule_key="NewRuleKey" plugin_name="plugin" name="new name" description="new description" status="DEPRECATED"
- plugin_config_key="NewConfigKey" priority="0" cardinality="MULTIPLE" language="dart" created_at="2013-12-16" updated_at="2013-12-17" parent_id="3"
- note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]"
- characteristic_id="100" default_characteristic_id="101"
- remediation_function="linear" default_remediation_function="linear_offset"
- remediation_coeff="1h" default_remediation_coeff="5d"
- remediation_offset="5min" default_remediation_offset="10h"
- effort_to_fix_description="squid.S115.effortToFix"
- />
-
-</dataset>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/persistence/RuleDaoTest/select_tags_by_rule_ids.xml b/sonar-server/src/test/resources/org/sonar/server/rule2/persistence/RuleDaoTest/select_tags_by_rule_ids.xml
deleted file mode 100644
index 8d252e540b4..00000000000
--- a/sonar-server/src/test/resources/org/sonar/server/rule2/persistence/RuleDaoTest/select_tags_by_rule_ids.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<dataset>
-
- <rule_tags id="3" tag="tag1"/>
- <rule_tags id="4" tag="tag3"/>
- <rule_tags id="5" tag="tag5"/>
-
- <rules_rule_tags id="3" rule_id="3" rule_tag_id="3" tag_type="SYSTEM"/>
- <rules_rule_tags id="4" rule_id="3" rule_tag_id="4" tag_type="SYSTEM"/>
- <rules_rule_tags id="5" rule_id="4" rule_tag_id="5" tag_type="SYSTEM"/>
-
-</dataset>
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/SonarClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/SonarClient.java
index 7e06483dcd5..beabf3d0735 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/SonarClient.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/SonarClient.java
@@ -33,9 +33,7 @@ import org.sonar.wsclient.qprofile.internal.DefaultQProfileClient;
import org.sonar.wsclient.qualitygate.QualityGateClient;
import org.sonar.wsclient.qualitygate.internal.DefaultQualityGateClient;
import org.sonar.wsclient.rule.RuleClient;
-import org.sonar.wsclient.rule.RuleTagClient;
import org.sonar.wsclient.rule.internal.DefaultRuleClient;
-import org.sonar.wsclient.rule.internal.DefaultRuleTagClient;
import org.sonar.wsclient.system.SystemClient;
import org.sonar.wsclient.system.internal.DefaultSystemClient;
import org.sonar.wsclient.user.UserClient;
@@ -112,13 +110,6 @@ public class SonarClient {
}
/**
- * New client to interact with web services related to rule tags
- */
- public RuleTagClient ruleTagClient() {
- return new DefaultRuleTagClient(requestFactory);
- }
-
- /**
* New client to interact with web services related to rules
*/
public RuleClient ruleClient() {
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/rule/RuleTagClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/rule/RuleTagClient.java
deleted file mode 100644
index b1d8e93ec3c..00000000000
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/rule/RuleTagClient.java
+++ /dev/null
@@ -1,39 +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.wsclient.rule;
-
-import java.util.Collection;
-
-/**
- * Allows management of rule tags
- * @since 4.2
- */
-public interface RuleTagClient {
-
- /**
- * List all tags
- */
- Collection<String> list();
-
- /**
- * Create a new tag
- */
- void create(String tag);
-}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/rule/internal/DefaultRuleTagClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/rule/internal/DefaultRuleTagClient.java
deleted file mode 100644
index 62f15a11e05..00000000000
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/rule/internal/DefaultRuleTagClient.java
+++ /dev/null
@@ -1,59 +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.wsclient.rule.internal;
-
-import org.json.simple.JSONValue;
-import org.sonar.wsclient.internal.HttpRequestFactory;
-import org.sonar.wsclient.rule.RuleTagClient;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Do not instantiate this class, but use {@link org.sonar.wsclient.SonarClient#ruleTagClient()}.
- */
-public class DefaultRuleTagClient implements RuleTagClient {
-
- private static final String ROOT_URL = "/api/rule_tags";
- private static final String LIST_URL = ROOT_URL + "/list";
- private static final String CREATE_URL = ROOT_URL + "/create";
-
- private final HttpRequestFactory requestFactory;
-
- public DefaultRuleTagClient(HttpRequestFactory requestFactory) {
- this.requestFactory = requestFactory;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public Collection<String> list() {
- String json = requestFactory.get(LIST_URL, Collections.<String, Object> emptyMap());
- return (Collection<String>) JSONValue.parse(json);
- }
-
- @Override
- public void create(String tag) {
- Map<String, Object> params = new HashMap<String, Object>();
- params.put("tag", tag);
- requestFactory.post(CREATE_URL, params);
- }
-}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/SonarClientTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/SonarClientTest.java
index 1ca87ea7322..3f3c6e53050 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/SonarClientTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/SonarClientTest.java
@@ -27,7 +27,6 @@ import org.sonar.wsclient.project.internal.DefaultProjectClient;
import org.sonar.wsclient.qprofile.internal.DefaultQProfileClient;
import org.sonar.wsclient.qualitygate.internal.DefaultQualityGateClient;
import org.sonar.wsclient.rule.internal.DefaultRuleClient;
-import org.sonar.wsclient.rule.internal.DefaultRuleTagClient;
import org.sonar.wsclient.system.internal.DefaultSystemClient;
import org.sonar.wsclient.user.internal.DefaultUserClient;
@@ -43,7 +42,6 @@ public class SonarClientTest {
assertThat(client.userClient()).isNotNull().isInstanceOf(DefaultUserClient.class);
assertThat(client.permissionClient()).isNotNull().isInstanceOf(DefaultPermissionClient.class);
assertThat(client.projectClient()).isNotNull().isInstanceOf(DefaultProjectClient.class);
- assertThat(client.ruleTagClient()).isNotNull().isInstanceOf(DefaultRuleTagClient.class);
assertThat(client.ruleClient()).isNotNull().isInstanceOf(DefaultRuleClient.class);
assertThat(client.qualityGateClient()).isNotNull().isInstanceOf(DefaultQualityGateClient.class);
assertThat(client.qProfileClient()).isNotNull().isInstanceOf(DefaultQProfileClient.class);
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/rule/internal/DefaultRuleTagClientTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/rule/internal/DefaultRuleTagClientTest.java
deleted file mode 100644
index ae85b5b229b..00000000000
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/rule/internal/DefaultRuleTagClientTest.java
+++ /dev/null
@@ -1,67 +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.wsclient.rule.internal;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.wsclient.MockHttpServerInterceptor;
-import org.sonar.wsclient.internal.HttpRequestFactory;
-
-import java.util.Collection;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.MapAssert.entry;
-
-public class DefaultRuleTagClientTest {
-
- @Rule
- public MockHttpServerInterceptor httpServer = new MockHttpServerInterceptor();
-
- private DefaultRuleTagClient client;
-
- @Before
- public void initClient() {
- HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url());
- this.client = new DefaultRuleTagClient(requestFactory);
- }
-
- @Test
- public void should_list_tags() {
- httpServer.stubResponseBody("[\"tag1\",\"tag2\",\"tag3\"]");
-
- Collection<String> result = client.list();
-
- assertThat(httpServer.requestedPath()).isEqualTo("/api/rule_tags/list");
- assertThat(result).containsOnly("tag1", "tag2", "tag3");
- }
-
- @Test
- public void should_create_rule_tag() {
- httpServer.stubStatusCode(200);
-
- final String newTag = "polop";
- client.create(newTag);
-
- assertThat(httpServer.requestedPath()).isEqualTo("/api/rule_tags/create");
- assertThat(httpServer.requestParams()).includes(entry("tag", newTag));
- }
-
-}