diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-05-20 20:52:57 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-05-20 20:53:52 +0200 |
commit | 97e7d751080fdc0b45845a066efc03bc7a14ac6c (patch) | |
tree | ad3bbfdbb0ad12e4123feaff5f7a5af3fd0e8d1f /sonar-core | |
parent | cb2f76a16944e74801a7820c16a3201916392c31 (diff) | |
download | sonarqube-97e7d751080fdc0b45845a066efc03bc7a14ac6c.tar.gz sonarqube-97e7d751080fdc0b45845a066efc03bc7a14ac6c.zip |
SONAR-3755 close issues when rule is disabled or deleted
Diffstat (limited to 'sonar-core')
8 files changed, 42 insertions, 16 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java index 7ec803e8cdb..6a67dcf6774 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java @@ -59,11 +59,11 @@ public class IssueDao implements BatchComponent, ServerComponent { } } - // TODO rename selectOpenIssuesByProject. Is it by module or project ?? - public List<IssueDto> selectOpenIssues(Integer componentId) { + public List<IssueDto> selectNonClosedIssuesByRootComponent(int componentId) { SqlSession session = mybatis.openSession(); try { - return session.selectList("org.sonar.core.issue.db.IssueMapper.selectOpenIssues", componentId); + IssueMapper mapper = session.getMapper(IssueMapper.class); + return mapper.selectNonClosedIssues(componentId); } finally { MyBatis.closeQuietly(session); } diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java index f31e977f6aa..e7bf13f7e5a 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java @@ -310,7 +310,7 @@ public final class IssueDto { return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); } - public static IssueDto toDto(DefaultIssue issue, Integer componentId, Integer ruleId) { + public static IssueDto toDtoForInsert(DefaultIssue issue, Integer componentId, Integer ruleId) { return new IssueDto() .setKee(issue.key()) .setLine(issue.line()) @@ -335,6 +335,29 @@ public final class IssueDto { .setIssueUpdateDate(issue.updateDate()); } + public static IssueDto toDtoForUpdate(DefaultIssue issue) { + // Invariant fields, like key and rule, can't be updated + return new IssueDto() + .setKee(issue.key()) + .setLine(issue.line()) + .setMessage(issue.message()) + .setEffortToFix(issue.effortToFix()) + .setResolution(issue.resolution()) + .setStatus(issue.status()) + .setSeverity(issue.severity()) + .setChecksum(issue.getChecksum()) + .setManualSeverity(issue.manualSeverity()) + .setReporter(issue.reporter()) + .setAssignee(issue.assignee()) + .setActionPlanKey(issue.actionPlanKey()) + .setAttributes(issue.attributes() != null ? KeyValueFormat.format(issue.attributes()) : "") + .setAuthorLogin(issue.authorLogin()) + .setUpdatedAt(issue.technicalUpdateDate()) + .setIssueCreationDate(issue.creationDate()) + .setIssueCloseDate(issue.closeDate()) + .setIssueUpdateDate(issue.updateDate()); + } + public DefaultIssue toDefaultIssue() { DefaultIssue issue = new DefaultIssue(); issue.setKey(kee); diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java index cc32f7272fa..478a66da894 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java @@ -31,6 +31,8 @@ public interface IssueMapper { List<IssueDto> select(IssueQuery query); + List<IssueDto> selectNonClosedIssues(int rootComponentId); + void insert(IssueDto issue); int update(IssueDto issue); diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueStorage.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueStorage.java index af308fb0029..8064e7502c3 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueStorage.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueStorage.java @@ -54,14 +54,15 @@ public abstract class IssueStorage { List<DefaultIssue> conflicts = Lists.newArrayList(); for (DefaultIssue issue : issues) { - int ruleId = ruleId(issue); - int componentId = componentId(issue); - - IssueDto dto = IssueDto.toDto(issue, componentId, ruleId); if (issue.isNew()) { + int componentId = componentId(issue); + int ruleId = ruleId(issue); + IssueDto dto = IssueDto.toDtoForInsert(issue, componentId, ruleId); issueMapper.insert(dto); + } else /* TODO if hasChanges */ { // TODO manage condition on update date + IssueDto dto = IssueDto.toDtoForUpdate(issue); int count = issueMapper.update(dto); if (count < 1) { conflicts.add(issue); diff --git a/sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java b/sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java index 3b2f2943ad6..926b769bcb9 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java @@ -80,7 +80,7 @@ public class IssueWorkflow implements BatchComponent, ServerComponent, Startable // Close the issues that do not exist anymore. Note that isAlive() is true on manual issues .transition(Transition.builder("automaticclose") .from(Issue.STATUS_OPEN).to(Issue.STATUS_CLOSED) - .conditions(new IsAlive(false), new IsManual(false)) + .conditions(new IsAlive(false)) .functions(new SetResolution(Issue.RESOLUTION_FIXED), new SetCloseDate(true)) .automatic() .build()) diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml index 36ce2d7dde2..40fc177e27d 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml @@ -59,10 +59,11 @@ #{issueUpdateDate}, #{issueCloseDate}, #{createdAt}, #{updatedAt}) </insert> + <!-- + IMPORTANT - invariant columns can't be updated. See IssueDto#toDtoForUpdate() + --> <update id="update" parameterType="Issue"> update issues set - resource_id=#{resourceId}, - rule_id=#{ruleId}, action_plan_key=#{actionPlanKey}, severity=#{severity}, manual_severity=#{manualSeverity}, @@ -79,7 +80,6 @@ issue_creation_date=#{issueCreationDate}, issue_update_date=#{issueUpdateDate}, issue_close_date=#{issueCloseDate}, - created_at=#{createdAt}, updated_at=#{updatedAt} where kee = #{kee} </update> @@ -91,12 +91,12 @@ where i.kee=#{kee} and i.rule_id=r.id and p.id=i.resource_id </select> - <select id="selectOpenIssues" parameterType="String" resultType="Issue"> + <select id="selectNonClosedIssues" parameterType="int" resultType="Issue"> select distinct <include refid="issueColumns"/> from issues i, rules r, projects p where i.status <> 'CLOSED' - and (p.root_id=#{componentId} or (p.root_id is null and p.id=#{componentId})) + and (p.root_id=#{id} or (p.root_id is null and p.id=#{id})) and i.resource_id=p.id and r.id=i.rule_id </select> diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java index 1ac718d52cb..2bc8932b731 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java @@ -246,7 +246,7 @@ public class IssueDaoTest extends AbstractDaoTestCase { public void should_select_open_issues() { setupData("shared", "should_select_open_issues"); - List<IssueDto> dtos = dao.selectOpenIssues(400); + List<IssueDto> dtos = dao.selectNonClosedIssuesByRootComponent(400); assertThat(dtos).hasSize(2); IssueDto issue = dtos.get(0); diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate-result.xml index 67d9024f5c7..57bc88451ea 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate-result.xml @@ -38,7 +38,7 @@ issue_creation_date="2013-05-18" issue_update_date="2013-05-19" issue_close_date="2013-05-20" - created_at="2013-05-21" + created_at="[null]" updated_at="2013-05-22" action_plan_key="current_sprint" /> |