diff options
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ActiveRulesProvider.java')
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ActiveRulesProvider.java | 51 |
1 files changed, 10 insertions, 41 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ActiveRulesProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ActiveRulesProvider.java index eb703522dc3..a6d7f7666aa 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ActiveRulesProvider.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ActiveRulesProvider.java @@ -19,21 +19,16 @@ */ package org.sonar.scanner.rule; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; import java.util.Map; -import java.util.Set; import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; import org.sonar.api.batch.rule.internal.DefaultActiveRules; import org.sonar.api.batch.rule.internal.NewActiveRule; import org.sonar.api.issue.impact.Severity; import org.sonar.api.issue.impact.SoftwareQuality; -import org.sonar.api.rule.RuleKey; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.api.utils.log.Profiler; +import org.sonar.scanner.bootstrap.ScannerProperties; import org.springframework.context.annotation.Bean; /** @@ -45,34 +40,22 @@ public class ActiveRulesProvider { private static final String LOG_MSG = "Load active rules"; @Bean("ActiveRules") - public DefaultActiveRules provide(ActiveRulesLoader loader, QualityProfiles qProfiles) { + public DefaultActiveRules provide(ActiveRulesLoader loader, ScannerProperties props) { Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); - DefaultActiveRules activeRules = load(loader, qProfiles); + DefaultActiveRules activeRules = load(loader, props.getProjectKey()); profiler.stopInfo(); return activeRules; } - private static DefaultActiveRules load(ActiveRulesLoader loader, QualityProfiles qProfiles) { - - Collection<String> qProfileKeys = getKeys(qProfiles); - Set<RuleKey> loadedRulesKey = new HashSet<>(); + private static DefaultActiveRules load(ActiveRulesLoader loader, String projectKey) { ActiveRulesBuilder builder = new ActiveRulesBuilder(); - - for (String qProfileKey : qProfileKeys) { - Collection<LoadedActiveRule> qProfileRules = load(loader, qProfileKey); - - for (LoadedActiveRule r : qProfileRules) { - if (!loadedRulesKey.contains(r.getRuleKey())) { - loadedRulesKey.add(r.getRuleKey()); - builder.addRule(transform(r, qProfileKey, r.getDeprecatedKeys())); - } - } - } - + loader.load(projectKey).stream() + .map(ActiveRulesProvider::transform) + .forEach(builder::addRule); return builder.build(); } - private static NewActiveRule transform(LoadedActiveRule activeRule, String qProfileKey, Set<RuleKey> deprecatedKeys) { + private static NewActiveRule transform(LoadedActiveRule activeRule) { NewActiveRule.Builder builder = new NewActiveRule.Builder(); builder .setRuleKey(activeRule.getRuleKey()) @@ -83,8 +66,8 @@ public class ActiveRulesProvider { .setLanguage(activeRule.getLanguage()) .setInternalKey(activeRule.getInternalKey()) .setTemplateRuleKey(activeRule.getTemplateRuleKey()) - .setQProfileKey(qProfileKey) - .setDeprecatedKeys(deprecatedKeys); + .setQProfileKey(activeRule.getQProfileKey()) + .setDeprecatedKeys(activeRule.getDeprecatedKeys()); // load parameters if (activeRule.getParams() != null) { for (Map.Entry<String, String> params : activeRule.getParams().entrySet()) { @@ -100,18 +83,4 @@ public class ActiveRulesProvider { return builder.build(); } - - private static List<LoadedActiveRule> load(ActiveRulesLoader loader, String qProfileKey) { - return loader.load(qProfileKey); - } - - private static Collection<String> getKeys(QualityProfiles qProfiles) { - List<String> keys = new ArrayList<>(qProfiles.findAll().size()); - - for (QProfile qp : qProfiles.findAll()) { - keys.add(qp.getKey()); - } - - return keys; - } } |