Package org.sonar.api.profiles

Examples of org.sonar.api.profiles.RulesProfile


    this.xmlProfileParser = xmlProfileParser;
  }

  @Override
  public RulesProfile createProfile(ValidationMessages messages) {
    RulesProfile profile = xmlProfileParser.parseResource(getClass().getClassLoader(),
                                                          "default-profile.xml", messages);
    RulesProfile sonarRules = annotationProfileParser.parse(CheckList.REPOSITORY_KEY, NAME,
                                                            CxxLanguage.KEY, CheckList.getChecks(), messages);
    for (ActiveRule activeRule: sonarRules.getActiveRules()) {
      profile.addActiveRule(activeRule);
    }

    profile.setDefaultProfile(true);
    return profile;
View Full Code Here


  public void shouldCreateDefaultProfile() {
    ValidationMessages validation = ValidationMessages.create();

    RuleFinder ruleFinder = ruleFinder();
    CxxDefaultProfile definition = new CxxDefaultProfile(new XMLProfileParser(ruleFinder), new AnnotationProfileParser(ruleFinder));
    RulesProfile profile = definition.createProfile(validation);

    assertThat(profile.getLanguage()).isEqualTo(CxxLanguage.KEY);
    assertThat(profile.getActiveRulesByRepository("valgrind")).hasSize(15);
    assertThat(validation.hasErrors()).isFalse();
  }
View Full Code Here

  public void should_create_sonar_way_profile() {
    ValidationMessages validation = ValidationMessages.create();

    RuleFinder ruleFinder = ruleFinder();
    JavaScriptProfile definition = new JavaScriptProfile(new AnnotationProfileParser(ruleFinder));
    RulesProfile profile = definition.createProfile(validation);

    assertThat(profile.getLanguage()).isEqualTo(JavaScript.KEY);
    assertThat(profile.getName()).isEqualTo(RulesProfile.SONAR_WAY_NAME);
    assertThat(profile.getActiveRulesByRepository(CheckList.REPOSITORY_KEY))
        .hasSize(61);
    assertThat(validation.hasErrors()).isFalse();
  }
View Full Code Here

    }
    return new RulesProfileWrapper(dtos);
  }

  private RulesProfile select(QProfile qProfile, ActiveRules activeRules, RuleFinder ruleFinder) {
    RulesProfile deprecatedProfile = new RulesProfile();
    // TODO deprecatedProfile.setVersion(qProfile.version());
    deprecatedProfile.setName(qProfile.getName());
    deprecatedProfile.setLanguage(qProfile.getLanguage());
    for (org.sonar.api.batch.rule.ActiveRule activeRule : ((DefaultActiveRules) activeRules).findByLanguage(qProfile.getLanguage())) {
      Rule rule = ruleFinder.findByKey(activeRule.ruleKey());
      ActiveRule deprecatedActiveRule = deprecatedProfile.activateRule(rule, RulePriority.valueOf(activeRule.severity()));
      for (Map.Entry<String, String> param : activeRule.params().entrySet()) {
        deprecatedActiveRule.setParameter(param.getKey(), param.getValue());
      }
    }
    return deprecatedProfile;
View Full Code Here

    export(profileKey, tool, writer);
    return writer.toString();
  }

  private RulesProfile wrap(QualityProfileDto profile) {
    RulesProfile target = new RulesProfile(profile.getName(), profile.getLanguage());
    for (ActiveRule activeRule : loader.findActiveRulesByProfile(profile.getKey())) {
      Rule rule = ruleFinder.findByKey(activeRule.key().ruleKey());
      org.sonar.api.rules.ActiveRule wrappedActiveRule = target.activateRule(rule, RulePriority.valueOf(activeRule.severity()));
      for (Map.Entry<String, String> entry : activeRule.params().entrySet()) {
        wrappedActiveRule.setParameter(entry.getKey(), entry.getValue());
      }
    }
    return target;
View Full Code Here

  public QProfileResult importXml(QualityProfileDto profileDto, String importerKey, String xml, DbSession dbSession) {
    QProfileResult result = new QProfileResult();
    ValidationMessages messages = ValidationMessages.create();
    ProfileImporter importer = getProfileImporter(importerKey);
    RulesProfile rulesProfile = importer.importProfile(new StringReader(xml), messages);
    importProfile(profileDto, rulesProfile, dbSession);
    processValidationMessages(messages, result);
    return result;
  }
View Full Code Here

   */
  private ListMultimap<String, RulesProfile> profilesByLanguage() {
    ListMultimap<String, RulesProfile> byLang = ArrayListMultimap.create();
    for (ProfileDefinition definition : definitions) {
      ValidationMessages validation = ValidationMessages.create();
      RulesProfile profile = definition.createProfile(validation);
      validation.log(LOGGER);
      if (profile != null && !validation.hasErrors()) {
        byLang.put(StringUtils.lowerCase(profile.getLanguage()), profile);
      }
    }
    return byLang;
  }
View Full Code Here

public class XooQualityProfile extends ProfileDefinition {

  @Override
  public RulesProfile createProfile(ValidationMessages validation) {
    final RulesProfile profile = RulesProfile.create("Basic", Xoo.KEY);

    profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, "x1"), RulePriority.MAJOR);

    return profile;
  }
View Full Code Here

    return new String[] {Xoo.KEY};
  }

  @Override
  public RulesProfile importProfile(Reader reader, ValidationMessages messages) {
    RulesProfile rulesProfile = RulesProfile.create();
    rulesProfile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, "x1"), RulePriority.CRITICAL);
    return rulesProfile;
  }
View Full Code Here

  }

  public static class XooProfileDefinition extends ProfileDefinition {
    @Override
    public RulesProfile createProfile(ValidationMessages validation) {
      final RulesProfile profile = RulesProfile.create("Basic", ServerTester.Xoo.KEY);
      ActiveRule activeRule1 = profile.activateRule(
        org.sonar.api.rules.Rule.create("xoo", "x1").setParams(newArrayList(new RuleParam().setKey("acceptWhitespace"))),
        RulePriority.CRITICAL);
      activeRule1.setParameter("acceptWhitespace", "true");

      profile.activateRule(org.sonar.api.rules.Rule.create("xoo", "x2"), RulePriority.INFO);
      return profile;
    }
View Full Code Here

TOP

Related Classes of org.sonar.api.profiles.RulesProfile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.