diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2018-09-06 18:02:56 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-09-24 20:20:58 +0200 |
commit | 1cacbb1d2ed72d720058580746d678ba8da1b453 (patch) | |
tree | 3d08e44365ae38fb975239385d301fc64973f541 /server/sonar-server-common | |
parent | cfba7fcb6500d8217bd81ecfcb8f47ec48ad55f2 (diff) | |
download | sonarqube-1cacbb1d2ed72d720058580746d678ba8da1b453.tar.gz sonarqube-1cacbb1d2ed72d720058580746d678ba8da1b453.zip |
SONAR-11209 Store ad hoc rules coming from scanner in rules_metadata
Diffstat (limited to 'server/sonar-server-common')
3 files changed, 0 insertions, 211 deletions
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/AddHocRuleCreator.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/AddHocRuleCreator.java deleted file mode 100644 index a2f938f9e7a..00000000000 --- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/AddHocRuleCreator.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.rule; - -import org.sonar.api.utils.System2; -import org.sonar.db.DbClient; -import org.sonar.db.DbSession; -import org.sonar.db.rule.RuleDao; -import org.sonar.db.rule.RuleDefinitionDto; -import org.sonar.db.rule.RuleDto; -import org.sonar.server.rule.index.RuleIndexer; - -import static org.sonar.api.rule.RuleStatus.READY; -import static org.sonar.db.rule.RuleDto.Scope.ALL; - -public class AddHocRuleCreator { - - private final DbClient dbClient; - private final System2 system2; - private final RuleIndexer ruleIndexer; - - public AddHocRuleCreator(DbClient dbClient, System2 system2, RuleIndexer ruleIndexer) { - this.dbClient = dbClient; - this.system2 = system2; - this.ruleIndexer = ruleIndexer; - } - - /** - * Persists a new add hoc rule in the DB and indexes it. - * @return the rule that was inserted in the DB, which <b>includes the generated ID</b>. - */ - public RuleDto persistAndIndex(DbSession dbSession, NewAddHocRule adHoc) { - RuleDao dao = dbClient.ruleDao(); - dao.insert(dbSession, new RuleDefinitionDto() - .setRuleKey(adHoc.getKey()) - .setPluginKey(adHoc.getPluginKey()) - .setIsExternal(true) - .setName(adHoc.getName()) - .setIsAdHoc(true) - .setScope(ALL) - .setStatus(READY) - .setCreatedAt(system2.now()) - .setUpdatedAt(system2.now())); - - RuleDto ruleDto = dao.selectOrFailByKey(dbSession, adHoc.getKey()); - ruleIndexer.commitAndIndex(dbSession, ruleDto.getId()); - return ruleDto; - } - -} diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/NewAddHocRule.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/NewAddHocRule.java deleted file mode 100644 index c84896b7791..00000000000 --- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/NewAddHocRule.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.rule; - -import java.util.Objects; -import javax.annotation.concurrent.Immutable; -import org.sonar.api.rule.RuleKey; - -@Immutable -public class NewAddHocRule { - private final RuleKey key; - private final String name; - private final String pluginKey; - - private NewAddHocRule(Builder builder) { - Objects.requireNonNull(builder.key, "'key' not expected to be null for an external rule"); - this.key = builder.key; - this.pluginKey = builder.pluginKey; - this.name = builder.name; - } - - public RuleKey getKey() { - return key; - } - - public String getName() { - return name; - } - - public String getPluginKey() { - return pluginKey; - } - - public static class Builder { - private RuleKey key; - private String pluginKey; - private String name; - - public Builder setKey(RuleKey key) { - this.key = key; - return this; - } - - public Builder setName(String name) { - this.name = name; - return this; - } - - public String name() { - return name; - } - - public NewAddHocRule build() { - return new NewAddHocRule(this); - } - - public Builder setPluginKey(String pluginKey) { - this.pluginKey = pluginKey; - return this; - } - } -} diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/AddHocRuleCreatorTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/AddHocRuleCreatorTest.java deleted file mode 100644 index db5269e1b4b..00000000000 --- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/AddHocRuleCreatorTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.rule; - -import org.junit.Test; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.utils.System2; -import org.sonar.db.DbSession; -import org.sonar.db.DbTester; -import org.sonar.db.rule.RuleDto; -import org.sonar.server.es.EsTester; -import org.sonar.server.rule.index.RuleIndexer; - -import static org.assertj.core.api.Assertions.assertThat; - -public class AddHocRuleCreatorTest { - - @org.junit.Rule - public DbTester dbTester = DbTester.create(System2.INSTANCE); - @org.junit.Rule - public EsTester es = EsTester.create(); - - private RuleIndexer indexer = new RuleIndexer(es.client(), dbTester.getDbClient()); - private AddHocRuleCreator underTest = new AddHocRuleCreator(dbTester.getDbClient(), System2.INSTANCE, indexer); - private DbSession dbSession = dbTester.getSession(); - - @Test - public void create_external_rule() { - RuleKey ruleKey = RuleKey.of("eslint", "no-cond-assign"); - NewAddHocRule externalRule = new NewAddHocRule.Builder() - .setKey(ruleKey) - .setPluginKey("eslint") - .setName("name") - .build(); - - RuleDto rule1 = underTest.persistAndIndex(dbSession, externalRule); - - assertThat(rule1).isNotNull(); - assertThat(rule1.isExternal()).isTrue(); - assertThat(rule1.isAdHoc()).isTrue(); - assertThat(rule1.getId()).isGreaterThan(0); - assertThat(rule1.getKey()).isEqualTo(ruleKey); - assertThat(rule1.getPluginKey()).isEqualTo("eslint"); - assertThat(rule1.getName()).isEqualTo("name"); - assertThat(rule1.getType()).isEqualTo(0); - } - -} |