Package org.sonar.api.issue

Examples of org.sonar.api.issue.Issuable


    Issuable.IssueBuilder issueBuilder = mock(Issuable.IssueBuilder.class);
    when(issueBuilder.build()).thenReturn(issue);
    when(issueBuilder.ruleKey((RuleKey)anyObject())).thenReturn(issueBuilder);
    when(issueBuilder.line((Integer)anyObject())).thenReturn(issueBuilder);
    when(issueBuilder.message((String)anyObject())).thenReturn(issueBuilder);
    Issuable issuable = mock(Issuable.class);
    when(issuable.newIssueBuilder()).thenReturn(issueBuilder);
    return issuable;
  }
View Full Code Here


  private int saveViolations(org.sonar.api.resources.File sonarFile, SourceFile squidFile) {
    Collection<CheckMessage> messages = squidFile.getCheckMessages();
    int violationsCount = 0;
    if (messages != null) {
      Issuable issuable = perspectives.as(Issuable.class, sonarFile);
      if (issuable != null) {
        for (CheckMessage message : messages) {
          Issue issue = issuable.newIssueBuilder()
              .ruleKey(annotationCheckFactory.getActiveRule(message.getCheck()).getRule().ruleKey())
              .line(message.getLine())
              .message(message.getText(Locale.ENGLISH))
              .build();
          if (issuable.addIssue(issue))
            violationsCount++;
        }
      }
      return violationsCount;
    }
View Full Code Here

    return add;
  }

  private boolean contextSaveViolation(Resource resource, int lineNr, RuleKey rule, String msg) {
    Issuable issuable = perspectives.as(Issuable.class, resource);
    boolean result = false;
    if (issuable != null) {
      Issuable.IssueBuilder issueBuilder = issuable.newIssueBuilder()
          .ruleKey(rule)
          .message(msg);
      if (lineNr > 0) {
        issueBuilder = issueBuilder.line(lineNr);
      }
      Issue issue = issueBuilder.build();
      result = issuable.addIssue(issue);
      if (result)
        violationsCount++;
    }
    return result;
  }
View Full Code Here

      if (includedFile == null) {
        CxxUtils.LOG.warn("Unable to find resource '" + include.getPath() + "' to create a dependency with '" + sonarFile.getKey() + "'");
      }
      else if (filesGraph.hasEdge(sonarFile, includedFile)) {
        FileEdge fileEdge = filesGraph.getEdge(sonarFile, includedFile);
        Issuable issuable = perspectives.as(Issuable.class, sonarFile);
        if ((issuable != null) && (duplicateIncludeRule != null)) {
          Issue issue = issuable.newIssueBuilder()
              .ruleKey(duplicateIncludeRule.getRule().ruleKey())
              .line(include.getLine())
              .message("Remove duplicated include, \"" + includedFile.getLongName() + "\" is already included at line " + fileEdge.getLine() + ".")
              .build();
          if (issuable.addIssue(issue))
            violationsCount++;
        }
        else {
          CxxUtils.LOG.warn("Already created edge from '" + sonarFile.getKey() + "' (line " + include.getLine() + ") to '" + includedFile.getKey() + "'" +
              ", previous edge from line " + fileEdge.getLine());
View Full Code Here

        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();
            if (issuable.addIssue(issue))
              violationsCount++;
          }
        }
      }
    }
View Full Code Here

    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

     *            The rule which has been violated.
     * @param sensorContext
     *            The sensor context.
     */
    private void createIssue(Resource<?> resource, Integer lineNumber, String message, ActiveRule rule, SensorContext sensorContext) {
        Issuable issuable;
        if (sensorContext.getResource(resource) != null) {
            issuable = perspectives.as(Issuable.class, resource);
            Issuable.IssueBuilder issueBuilder = issuable.newIssueBuilder().ruleKey(rule.getRule().ruleKey()).message(message);
            if (lineNumber != null) {
                issueBuilder.line(lineNumber);
            }
            issuable.addIssue(issueBuilder.build());
            LOGGER.info("Issue added for resource '{}'.", resource.getLongName());
        } else {
            LOGGER.warn("Resource '{}' not found, issue not created.", resource.getLongName());
        }
    }
View Full Code Here

    return true;
  }

  @Override
  public void decorate(Resource resource, DecoratorContext context) {
    Issuable issuable = perspectives.as(Issuable.class, resource);
    if (issuable != null) {
      doDecorate(resource);
    }
  }
View Full Code Here

    return CoreMetrics.FALSE_POSITIVE_ISSUES;
  }

  @Override
  public void decorate(Resource resource, DecoratorContext context) {
    Issuable issuable = perspectives.as(Issuable.class, resource);
    if (issuable != null) {
      int falsePositives = 0;
      for (Issue issue : issuable.resolvedIssues()) {
        if (Issue.RESOLUTION_FALSE_POSITIVE.equals(issue.resolution())) {
          falsePositives++;
        }
      }
      saveMeasure(context, CoreMetrics.FALSE_POSITIVE_ISSUES, falsePositives);
View Full Code Here

      );
  }

  @Override
  public void decorate(Resource resource, DecoratorContext context) {
    Issuable issuable = perspectives.as(Issuable.class, resource);
    if (issuable != null) {
      Collection<Issue> issues = issuable.issues();
      boolean shouldSaveNewMetrics = shouldSaveNewMetrics(context);

      Multiset<RulePriority> severityBag = HashMultiset.create();
      Map<RulePriority, Multiset<RuleKey>> rulesPerSeverity = Maps.newHashMap();
      ListMultimap<RulePriority, Issue> issuesPerSeverity = ArrayListMultimap.create();
View Full Code Here

TOP

Related Classes of org.sonar.api.issue.Issuable

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.