Search in sources :

Example 1 with MessageException

use of org.sonarsource.sonarlint.core.client.api.exceptions.MessageException in project sonarlint-core by SonarSource.

the class SonarQubeActiveRulesProvider method createNewActiveRule.

private static void createNewActiveRule(ActiveRulesBuilder builder, ActiveRule activeRule, Sonarlint.Rules storageRules, String language, Rules rules) {
    RuleKey ruleKey = RuleKey.of(activeRule.getRepo(), activeRule.getKey());
    Rule rule = rules.find(ruleKey);
    Sonarlint.Rules.Rule storageRule;
    try {
        storageRule = storageRules.getRulesByKeyOrThrow(ruleKey.toString());
    } catch (IllegalArgumentException e) {
        throw new MessageException("Unknown active rule in the quality profile of the project. Please update the SonarQube server binding.");
    }
    NewActiveRule newActiveRule = builder.create(ruleKey).setLanguage(language).setName(rule.name()).setInternalKey(rule.internalKey()).setSeverity(activeRule.getSeverity());
    if (!StringUtils.isEmpty(storageRule.getTemplateKey())) {
        RuleKey templateRuleKey = RuleKey.parse(storageRule.getTemplateKey());
        newActiveRule.setTemplateRuleKey(templateRuleKey.rule());
    }
    for (Map.Entry<String, String> param : activeRule.getParamsMap().entrySet()) {
        newActiveRule.setParam(param.getKey(), param.getValue());
    }
    newActiveRule.activate();
}
Also used : NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) RuleKey(org.sonar.api.rule.RuleKey) MessageException(org.sonarsource.sonarlint.core.client.api.exceptions.MessageException) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) Rule(org.sonar.api.batch.rule.Rule) ActiveRule(org.sonarsource.sonarlint.core.proto.Sonarlint.ActiveRules.ActiveRule) ActiveRules(org.sonar.api.batch.rule.ActiveRules) Rules(org.sonar.api.batch.rule.Rules) Map(java.util.Map)

Example 2 with MessageException

use of org.sonarsource.sonarlint.core.client.api.exceptions.MessageException in project sonarlint-core by SonarSource.

the class SonarLintWrappedExceptionTest method extractMessageException.

@Test
public void extractMessageException() {
    MessageException e = new MessageException("a");
    Exception a = new IllegalStateException("a", new IllegalStateException("b", e));
    assertThat(SonarLintWrappedException.wrap(a)).isEqualTo(e);
}
Also used : MessageException(org.sonarsource.sonarlint.core.client.api.exceptions.MessageException) SonarLintWrappedException(org.sonarsource.sonarlint.core.client.api.exceptions.SonarLintWrappedException) MessageException(org.sonarsource.sonarlint.core.client.api.exceptions.MessageException) Test(org.junit.Test)

Aggregations

MessageException (org.sonarsource.sonarlint.core.client.api.exceptions.MessageException)2 Map (java.util.Map)1 Test (org.junit.Test)1 ActiveRules (org.sonar.api.batch.rule.ActiveRules)1 Rule (org.sonar.api.batch.rule.Rule)1 Rules (org.sonar.api.batch.rule.Rules)1 NewActiveRule (org.sonar.api.batch.rule.internal.NewActiveRule)1 RuleKey (org.sonar.api.rule.RuleKey)1 SonarLintWrappedException (org.sonarsource.sonarlint.core.client.api.exceptions.SonarLintWrappedException)1 ActiveRule (org.sonarsource.sonarlint.core.proto.Sonarlint.ActiveRules.ActiveRule)1