Package org.sonar.api.rules

Examples of org.sonar.api.rules.ActiveRule


    String dsmJson = serializeDsm(files, feedbackEdges);
    context.saveMeasure(dir, new Measure(CoreMetrics.DEPENDENCY_MATRIX, dsmJson));
  }

  private void saveViolations(Set<Edge> feedbackEdges, DirectedGraph<Directory, DirectoryEdge> packagesGraph) {
    ActiveRule cycleBetweenPackagesRule = CycleBetweenPackagesCheck.getActiveRule(checkFactory);
    if (cycleBetweenPackagesRule != null) {
      for (Edge feedbackEdge : feedbackEdges) {
        Directory fromPackage = (Directory) feedbackEdge.getFrom();
        Directory toPackage = (Directory) feedbackEdge.getTo();
        DirectoryEdge edge = packagesGraph.getEdge(fromPackage, toPackage);
        for (FileEdge subEdge : edge.getRootEdges()) {
          Resource fromFile = subEdge.getFrom();
          Resource toFile = subEdge.getTo();
          Issuable issuable = perspectives.as(Issuable.class, fromFile);
          // If resource cannot be obtained, then silently ignore, because anyway warning will be printed by method addFile
          if ((issuable != null) && (fromFile != null) && (toFile != null)) {
            Issue issue = issuable.newIssueBuilder()
                .ruleKey(cycleBetweenPackagesRule.getRule().ruleKey())
                .line(subEdge.getLine())
                .message("Remove the dependency from file \"" + fromFile.getLongName()
                    + "\" to file \"" + toFile.getLongName() + "\" to break a package cycle.")
                .effortToFix((double) subEdge.getWeight())
                .build();
View Full Code Here


  private void saveIssues(File sonarFile, SourceFile squidFile) {
    Collection<CheckMessage> messages = squidFile.getCheckMessages();
    if (messages != null) {

      for (CheckMessage message : messages) {
        ActiveRule rule = annotationCheckFactory.getActiveRule(message.getCheck());
        Issuable issuable = resourcePerspectives.as(Issuable.class, sonarFile);

        if (issuable != null) {
          Issue issue = issuable.newIssueBuilder()
            .ruleKey(RuleKey.of(rule.getRepositoryKey(), rule.getRuleKey()))
            .line(message.getLine())
            .message(message.getText(Locale.ENGLISH))
            .build();
          issuable.addIssue(issue);
        }
View Full Code Here

        boolean createEmptyConceptIssue = isCreateEmptyConceptIssue();
        for (GroupType groupType : report.getGroup()) {
            LOGGER.info("Processing group '{}'", groupType.getId());
            for (RuleType ruleType : groupType.getConceptOrConstraint()) {
                String id = ruleType.getId();
                ActiveRule activeRule = rules.get(id);
                if (activeRule == null) {
                    LOGGER.warn("Cannot resolve activeRule for id '{}'.", id);
                } else {
                    ResultType result = ruleType.getResult();
                    boolean hasRows = result != null && result.getRows().getCount() > 0;
View Full Code Here

      // Manual rules are not declared in Quality profiles, so no need to check ActiveRule
      boolean isRemovedRule = rule == null || Rule.STATUS_REMOVED.equals(rule.getStatus());
      issue.setEndOfLife(forceEndOfLife || isRemovedRule);
      issue.setOnDisabledRule(isRemovedRule);
    } else {
      ActiveRule activeRule = rulesProfile.getActiveRule(issue.ruleKey().repository(), issue.ruleKey().rule());
      issue.setEndOfLife(true);
      issue.setOnDisabledRule(activeRule == null || rule == null || Rule.STATUS_REMOVED.equals(rule.getStatus()));
    }
  }
View Full Code Here

  }

  @Override
  public ActiveRule getActiveRule(String repositoryKey, String ruleKey) {
    for (RulesProfile profile : profiles) {
      ActiveRule activeRule = profile.getActiveRule(repositoryKey, ruleKey);
      if (activeRule != null) {
        return activeRule;
      }
    }
    return null;
View Full Code Here

  }

  @Override
  public ActiveRule getActiveRule(Rule rule) {
    for (RulesProfile profile : profiles) {
      ActiveRule activeRule = profile.getActiveRule(rule);
      if (activeRule != null) {
        return activeRule;
      }
    }
    return null;
View Full Code Here

    // 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

  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

    Rule rule = Rule.create("checkstyle", "IllegalRegexp", "illegal regexp");
    rule.createParameter("format");
    rule.createParameter("message");
    rule.createParameter("tokens");

    ActiveRule activeRule = profile.activateRule(rule, RulePriority.BLOCKER);
    activeRule.setParameter("format", "foo");
    activeRule.setParameter("message", "with special characters < > &");
    // the tokens parameter is not set
    new XMLProfileSerializer().write(profile, writer);

    assertSimilarXml("exportRuleParameters.xml", writer.toString());
  }
View Full Code Here

    })) {
      throw MessageException.of(String.format(
        "The definition of the profile '%s' (language '%s') contains multiple occurrences of the '%s:%s' rule. The plugin which declares this profile should fix this.",
        getName(), getLanguage(), rule.getRepositoryKey(), rule.getKey()));
    }
    ActiveRule activeRule = new ActiveRule();
    activeRule.setRule(rule);
    activeRule.setRulesProfile(this);
    activeRule.setSeverity(optionalSeverity == null ? rule.getSeverity() : optionalSeverity);
    activeRules.add(activeRule);
    return activeRule;
  }
View Full Code Here

TOP

Related Classes of org.sonar.api.rules.ActiveRule

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.