@Test
  public void should_keep_changes_made_by_user() throws Exception {
    DefaultIssue issue =
        new DefaultIssue()
            .setKey("ABCDE")
            .setRuleKey(RuleKey.of("squid", "AvoidCycles"))
            .setComponentKey("struts:org.apache.struts.Action")
            .setNew(false);

    // Before starting scan
    issue.setAssignee(null);
    issue.setActionPlanKey("PLAN-1");
    issue.setCreationDate(DateUtils.parseDate("2012-01-01"));
    issue.setUpdateDate(DateUtils.parseDate("2012-02-02"));

    // Changed by scan
    issue.setLine(200);
    issue.setSeverity(Severity.BLOCKER);
    issue.setManualSeverity(false);
    issue.setAuthorLogin("simon");
    issue.setChecksum("CHECKSUM-ABCDE");
    issue.setResolution(null);
    issue.setStatus(Issue.STATUS_REOPENED);

    // Issue as seen and changed by end-user
    IssueDto dbIssue =
        new IssueDto()
            .setKee("ABCDE")
            .setRuleId(10)
            .setRuleKey("squid", "AvoidCycles")
            .setComponentUuid("100")
            .setComponentKey("struts:org.apache.struts.Action")
            .setLine(10)
            .setResolution(Issue.RESOLUTION_FALSE_POSITIVE)
            .setStatus(Issue.STATUS_RESOLVED)
            .setAssignee("arthur")
            .setActionPlanKey("PLAN-2")
            .setSeverity(Severity.MAJOR)
            .setManualSeverity(false);

    new UpdateConflictResolver().mergeFields(dbIssue, issue);

    assertThat(issue.key()).isEqualTo("ABCDE");
    assertThat(issue.componentKey()).isEqualTo("struts:org.apache.struts.Action");

    // Scan wins on :
    assertThat(issue.line()).isEqualTo(200);
    assertThat(issue.severity()).isEqualTo(Severity.BLOCKER);
    assertThat(issue.manualSeverity()).isFalse();

    // User wins on :
    assertThat(issue.assignee()).isEqualTo("arthur");
    assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FALSE_POSITIVE);
    assertThat(issue.status()).isEqualTo(Issue.STATUS_RESOLVED);
    assertThat(issue.actionPlanKey()).isEqualTo("PLAN-2");
  }
 private void updateIssue(DefaultIssue issue, Rule rule, ActiveRule activeRule) {
   if (Strings.isNullOrEmpty(issue.message())) {
     issue.setMessage(rule.name());
   }
   issue.setCreationDate(project.getAnalysisDate());
   issue.setUpdateDate(project.getAnalysisDate());
   if (issue.severity() == null) {
     issue.setSeverity(activeRule.severity());
   }
   DebtRemediationFunction function = rule.debtRemediationFunction();
   if (rule.debtSubCharacteristic() != null && function != null) {
     issue.setDebt(calculateDebt(function, issue.effortToFix(), rule.key()));
   }
 }
Beispiel #3
0
  private boolean initAndAddIssue(DefaultIssue issue, @Nullable Violation violation) {
    // TODO fail fast : if rule does not exist

    ActiveRule activeRule =
        qProfile.getActiveRule(issue.ruleKey().repository(), issue.ruleKey().rule());
    if (activeRule == null || activeRule.getRule() == null) {
      // rule does not exist or is not enabled -> ignore the issue
      return false;
    }
    issue.setCreationDate(project.getAnalysisDate());
    issue.setUpdateDate(project.getAnalysisDate());
    if (issue.severity() == null) {
      issue.setSeverity(activeRule.getSeverity().name());
    }
    issue.setRemediationCost(technicalDebtCalculator.cost(issue));

    if (filters.accept(issue, violation)) {
      cache.put(issue);
      return true;
    }
    return false;
  }