@Override
  public void executeOn(Project project, SensorContext context) {
    System.out.println("ListAllIssuesPostJob");

    // all open issues
    for (Issue issue : projectIssues.issues()) {
      String ruleKey = issue.ruleKey().toString();
      Integer issueLine = issue.line();
      String severity = issue.severity();
      boolean isNew = issue.isNew();

      // just to illustrate, we dump some fields of the 'issue' in sysout (bad, very bad)
      System.out.println(ruleKey + " : " + issue.componentKey() + "(" + issueLine + ")");
      System.out.println("isNew: " + isNew + " | severity: " + severity);
    }

    // all resolved issues
    for (Issue issue : projectIssues.resolvedIssues()) {
      String ruleKey = issue.ruleKey().toString();
      Integer issueLine = issue.line();
      boolean isNew = issue.isNew();

      System.out.println(ruleKey + " : " + issue.componentKey() + "(" + issueLine + ")");
      System.out.println("isNew: " + isNew + " | resolution: " + issue.resolution());
    }
  }
Пример #2
0
  /** Create issue report according to issue list generated during SonarQube analysis. */
  public static SonarQubeIssuesReport extractIssueReport(
      ProjectIssues projectIssues, InputFileCache inputFileCache, File projectBaseDir) {
    SonarQubeIssuesReport result = new SonarQubeIssuesReport();

    for (Issue issue : projectIssues.issues()) {
      if (!issue.isNew()) {
        LOGGER.debug("Issue {} is not a new issue and so, not added to the report", issue.key());
      } else {
        String key = issue.key();
        String severity = issue.severity();
        String rule = issue.ruleKey().toString();
        String message = issue.message();

        int line = 0;
        if (issue.line() != null) {
          line = issue.line();
        }

        InputFile inputFile = inputFileCache.getInputFile(issue.componentKey());
        if (inputFile == null) {
          LOGGER.debug("Issue {} is not linked to a file, not added to the report", issue.key());
        } else {
          String path = new PathResolver().relativePath(projectBaseDir, inputFile.file());

          // Create the issue and Add to report
          SonarQubeIssue stashIssue = new SonarQubeIssue(key, severity, message, rule, path, line);
          result.add(stashIssue);
        }
      }
    }

    return result;
  }
  private void treatUnresolvedIssues(DecoratorContext context, List<Issue> unresolvedIssues) {
    Map<Integer, String> authorsByLine = null;
    for (Issue issue : unresolvedIssues) {
      logger.debug(
          "Treating unresolved issue [{}]: isNew = [{}], line = [{}], assignee = [{}]",
          issue.key(),
          issue.isNew(),
          issue.line(),
          issue.assignee());

      if (!isCandidateIssue(issue)) {
        logger.debug("Issue [{}] is not a candidate for auto assignment", issue.key());
        continue;
      }

      if (authorsByLine == null) {
        // Load authors by line for the current resource. Should be done only once per resource
        authorsByLine = getAuthorsByLineFromScm(context);
      }

      User autoAssignee = getAutoAssignee(issue, authorsByLine);
      if (autoAssignee != null) {
        logger.debug("Assigning issue [{}] to user [{}]", issue.key(), autoAssignee.login());
        assignIssue(issue, autoAssignee);
      } else {
        logger.debug("Leaving the issue [{}] unassigned", issue.key());
      }
    }
  }
  private User getAutoAssignee(Issue issue, Map<Integer, String> authorsByLine) {
    String scmLoginName = null;
    if (issue.line() != null || authorsByLine.get(issue.line()) != null) {
      scmLoginName = authorsByLine.get(issue.line());
    }

    User autoAssignee = null;
    if (scmLoginName == null) {
      logger.debug(
          "Cannot detect automatically the login of the assignee from SCM blame for issue [{}]",
          issue.key());
      autoAssignee = getDefaultAssigneeIfAny();
      if (autoAssignee != null) {
        logger.debug(
            "Using default assignee [{}] for issue [{}]", autoAssignee.login(), issue.key());
      }
    } else {
      autoAssignee = getUserFromLoginName(scmLoginName);
    }
    return autoAssignee;
  }