diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2018-10-11 11:35:06 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-10-11 20:20:54 +0200 |
commit | 5666430ddc9fb043313be01045fd93208033acbd (patch) | |
tree | 3335d52643fb073605e963153c4ac2be4f4664f4 /sonar-scanner-engine | |
parent | e581d9bf12be654518a355e2a6cc4e360a4f231e (diff) | |
download | sonarqube-5666430ddc9fb043313be01045fd93208033acbd.tar.gz sonarqube-5666430ddc9fb043313be01045fd93208033acbd.zip |
SONAR-11218 Drop RuleFinder implementation on scanner side and remove deprecation
Also deprecate Rules, that should be ultimately removed.
Diffstat (limited to 'sonar-scanner-engine')
3 files changed, 0 insertions, 215 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RuleFinderCompatibility.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RuleFinderCompatibility.java deleted file mode 100644 index d5937928674..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RuleFinderCompatibility.java +++ /dev/null @@ -1,112 +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.scanner.rule; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.stream.Collectors; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import javax.annotation.concurrent.Immutable; - -import org.apache.commons.lang.builder.ReflectionToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; -import org.sonar.api.batch.rule.Rules; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.rules.Rule; -import org.sonar.api.rules.RuleFinder; -import org.sonar.api.rules.RuleQuery; - -@Immutable -public class RuleFinderCompatibility implements RuleFinder { - - private final Rules rules; - - public RuleFinderCompatibility(Rules rules) { - this.rules = rules; - } - - @Override - public Rule findById(int ruleId) { - throw new UnsupportedOperationException("Unable to find rule by id"); - } - - @Override - public Rule findByKey(String repositoryKey, String key) { - return findByKey(RuleKey.of(repositoryKey, key)); - } - - @Override - public Rule findByKey(RuleKey key) { - return toRule(rules.find(key)); - } - - @Override - public Rule find(RuleQuery query) { - Collection<Rule> all = findAll(query); - if (all.size() > 1) { - throw new IllegalArgumentException("Non unique result for rule query: " + ReflectionToStringBuilder.toString(query, ToStringStyle.SHORT_PREFIX_STYLE)); - } else if (all.isEmpty()) { - return null; - } else { - return all.iterator().next(); - } - } - - @Override - public Collection<Rule> findAll(RuleQuery query) { - if (query.getConfigKey() != null) { - if (query.getRepositoryKey() != null && query.getKey() == null) { - return byInternalKey(query); - } - } else if (query.getRepositoryKey() != null) { - if (query.getKey() != null) { - return byKey(query); - } else { - return byRepository(query); - } - } - throw new UnsupportedOperationException("Unable to find rule by query"); - } - - private Collection<Rule> byRepository(RuleQuery query) { - return rules.findByRepository(query.getRepositoryKey()).stream() - .map(RuleFinderCompatibility::toRule) - .collect(Collectors.toList()); - } - - private Collection<Rule> byKey(RuleQuery query) { - Rule rule = toRule(rules.find(RuleKey.of(query.getRepositoryKey(), query.getKey()))); - return rule != null ? Arrays.asList(rule) : Collections.<Rule>emptyList(); - } - - private Collection<Rule> byInternalKey(RuleQuery query) { - return rules.findByInternalKey(query.getRepositoryKey(), query.getConfigKey()).stream() - .map(RuleFinderCompatibility::toRule) - .collect(Collectors.toList()); - } - - @CheckForNull - private static Rule toRule(@Nullable org.sonar.api.batch.rule.Rule ar) { - return ar == null ? null : Rule.create(ar.key().repository(), ar.key().rule()).setName(ar.name()).setConfigKey(ar.internalKey()); - } - -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java index 128e1fe30bc..9de9eb074a7 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java @@ -50,7 +50,6 @@ import org.sonar.scanner.phases.SensorsExecutor; import org.sonar.scanner.postjob.DefaultPostJobContext; import org.sonar.scanner.postjob.PostJobOptimizer; import org.sonar.scanner.rule.QProfileVerifier; -import org.sonar.scanner.rule.RuleFinderCompatibility; import org.sonar.scanner.rule.RulesProfileProvider; import org.sonar.scanner.scan.filesystem.DefaultModuleFileSystem; import org.sonar.scanner.scan.filesystem.ExclusionFilters; @@ -105,7 +104,6 @@ public class ModuleScanContainer extends ComponentContainer { } add( - RuleFinderCompatibility.class, PostJobsExecutor.class, SensorsExecutor.class, diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RuleFinderCompatibilityTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RuleFinderCompatibilityTest.java deleted file mode 100644 index e63803ed934..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RuleFinderCompatibilityTest.java +++ /dev/null @@ -1,101 +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.scanner.rule; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.batch.rule.Rules; -import org.sonar.api.batch.rule.internal.RulesBuilder; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.rules.RuleQuery; - -import static org.assertj.core.api.Assertions.assertThat; - -public class RuleFinderCompatibilityTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private Rules rules; - private RuleFinderCompatibility ruleFinder; - - @Before - public void prepare() { - RulesBuilder builder = new RulesBuilder(); - builder.add(RuleKey.of("repo1", "rule1")); - builder.add(RuleKey.of("repo1", "rule2")).setInternalKey("rule2_internal"); - builder.add(RuleKey.of("repo2", "rule1")); - rules = builder.build(); - - ruleFinder = new RuleFinderCompatibility(rules); - } - - @Test - public void testByInternalKey() { - assertThat(ruleFinder.find(RuleQuery.create().withRepositoryKey("repo1").withConfigKey("rule2_internal")).getKey()).isEqualTo("rule2"); - assertThat(ruleFinder.find(RuleQuery.create().withRepositoryKey("repo1").withConfigKey("rule2_internal2"))).isNull(); - } - - @Test - public void testByKey() { - assertThat(ruleFinder.find(RuleQuery.create().withRepositoryKey("repo1").withKey("rule2")).getKey()).isEqualTo("rule2"); - assertThat(ruleFinder.find(RuleQuery.create().withRepositoryKey("repo1").withKey("rule3"))).isNull(); - assertThat(ruleFinder.findByKey("repo1", "rule2").getKey()).isEqualTo("rule2"); - } - - @Test - public void duplicateResult() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Non unique result for rule query: RuleQuery[repositoryKey=repo1,key=<null>,configKey=<null>]"); - ruleFinder.find(RuleQuery.create().withRepositoryKey("repo1")); - } - - @Test - public void unsupportedById() { - thrown.expect(UnsupportedOperationException.class); - ruleFinder.findById(1); - } - - @Test - public void unsupportedByInternalKeyWithoutRepo() { - thrown.expect(UnsupportedOperationException.class); - ruleFinder.find(RuleQuery.create().withConfigKey("config")); - } - - @Test - public void unsupportedByKeyWithoutRepo() { - thrown.expect(UnsupportedOperationException.class); - ruleFinder.find(RuleQuery.create().withKey("key")); - } - - @Test - public void unsupportedByKeyAndInternalKey() { - thrown.expect(UnsupportedOperationException.class); - ruleFinder.find(RuleQuery.create().withRepositoryKey("repo").withKey("key").withConfigKey("config")); - } - - @Test - public void unsupportedByKeyAndInternalKeyWithoutRepo() { - thrown.expect(UnsupportedOperationException.class); - ruleFinder.find(RuleQuery.create().withKey("key").withConfigKey("config")); - } -} |