From 4c0821e6661f451031c3c17069d775d154f7b20a Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 28 May 2013 07:46:26 +0200 Subject: SONAR-4355 new resolution "REMOVED" --- .../java/org/sonar/core/issue/DefaultIssue.java | 23 +++++++++---- .../org/sonar/core/issue/DefaultIssueBuilder.java | 3 ++ .../org/sonar/core/issue/workflow/IsAlive.java | 37 --------------------- .../org/sonar/core/issue/workflow/IsEndOfLife.java | 37 +++++++++++++++++++++ .../sonar/core/issue/workflow/IssueWorkflow.java | 26 +++++++-------- .../issue/workflow/SetEndOfLifeResolution.java | 38 ++++++++++++++++++++++ 6 files changed, 108 insertions(+), 56 deletions(-) delete mode 100644 sonar-core/src/main/java/org/sonar/core/issue/workflow/IsAlive.java create mode 100644 sonar-core/src/main/java/org/sonar/core/issue/workflow/IsEndOfLife.java create mode 100644 sonar-core/src/main/java/org/sonar/core/issue/workflow/SetEndOfLifeResolution.java (limited to 'sonar-core/src/main') diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java index a020f13445b..56fb83bebe4 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java @@ -74,9 +74,11 @@ public class DefaultIssue implements Issue { // true if the the issue did not exist in the previous scan. private boolean isNew = true; - // true if the the issue did exist in the previous scan but not in the current one. That means + // True if the the issue did exist in the previous scan but not in the current one. That means // that this issue should be closed. - private boolean isAlive = true; + private boolean endOfLife = false; + + private boolean onDisabledRule = false; // true if some fields have been changed since the previous scan private boolean isChanged = false; @@ -257,12 +259,21 @@ public class DefaultIssue implements Issue { return this; } - public boolean isAlive() { - return isAlive; + public boolean isEndOfLife() { + return endOfLife; + } + + public DefaultIssue setEndOfLife(boolean b) { + endOfLife = b; + return this; + } + + public boolean isOnDisabledRule() { + return onDisabledRule; } - public DefaultIssue setAlive(boolean b) { - isAlive = b; + public DefaultIssue setOnDisabledRule(boolean b) { + onDisabledRule = b; return this; } diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java index 0546585f7aa..e3ec577a3ca 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java @@ -139,6 +139,9 @@ public class DefaultIssueBuilder implements Issuable.IssueBuilder { issue.setAttributes(attributes); issue.setResolution(null); issue.setStatus(Issue.STATUS_OPEN); + issue.setNew(true); + issue.setEndOfLife(false); + issue.setOnDisabledRule(false); return issue; } } diff --git a/sonar-core/src/main/java/org/sonar/core/issue/workflow/IsAlive.java b/sonar-core/src/main/java/org/sonar/core/issue/workflow/IsAlive.java deleted file mode 100644 index 7a3179c5cd0..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/issue/workflow/IsAlive.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.core.issue.workflow; - -import org.sonar.api.issue.Issue; -import org.sonar.core.issue.DefaultIssue; - -class IsAlive implements Condition { - - private final boolean alive; - - IsAlive(boolean alive) { - this.alive = alive; - } - - @Override - public boolean matches(Issue issue) { - return ((DefaultIssue) issue).isAlive() == alive; - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/issue/workflow/IsEndOfLife.java b/sonar-core/src/main/java/org/sonar/core/issue/workflow/IsEndOfLife.java new file mode 100644 index 00000000000..741f7dbbd40 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/issue/workflow/IsEndOfLife.java @@ -0,0 +1,37 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.core.issue.workflow; + +import org.sonar.api.issue.Issue; +import org.sonar.core.issue.DefaultIssue; + +class IsEndOfLife implements Condition { + + private final boolean endOfLife; + + IsEndOfLife(boolean endOfLife) { + this.endOfLife = endOfLife; + } + + @Override + public boolean matches(Issue issue) { + return ((DefaultIssue) issue).isEndOfLife() == endOfLife; + } +} 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 4b4780f4122..f6b8dc2511d 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 @@ -81,7 +81,7 @@ public class IssueWorkflow implements BatchComponent, ServerComponent, Startable .functions(new SetResolution(null), new SetCloseDate(false)) .build()) - // resolve as false-positive + // resolve as false-positive .transition(Transition.builder(DefaultTransitions.FALSE_POSITIVE) .from(Issue.STATUS_OPEN).to(Issue.STATUS_RESOLVED) .conditions(new IsManual(false)) @@ -100,37 +100,37 @@ public class IssueWorkflow implements BatchComponent, ServerComponent, Startable // automatic transitions - // Close the issues that do not exist anymore. Note that isAlive() is true on manual issues + // Close the issues that do not exist anymore. Note that isEndOfLife() is false on manual issues .transition(Transition.builder("automaticclose") .from(Issue.STATUS_OPEN).to(Issue.STATUS_CLOSED) - .conditions(new IsAlive(false)) - .functions(new SetResolution(Issue.RESOLUTION_FIXED), new SetCloseDate(true)) + .conditions(new IsEndOfLife(true)) + .functions(new SetEndOfLifeResolution(), new SetCloseDate(true)) .automatic() .build()) .transition(Transition.builder("automaticclose") .from(Issue.STATUS_REOPENED).to(Issue.STATUS_CLOSED) - .conditions(new IsAlive(false)) - .functions(new SetResolution(Issue.RESOLUTION_FIXED), new SetCloseDate(true)) + .conditions(new IsEndOfLife(true)) + .functions(new SetEndOfLifeResolution(), new SetCloseDate(true)) .automatic() .build()) .transition(Transition.builder("automaticclose") .from(Issue.STATUS_CONFIRMED).to(Issue.STATUS_CLOSED) - .conditions(new IsAlive(false)) - .functions(new SetResolution(Issue.RESOLUTION_FIXED), new SetCloseDate(true)) + .conditions(new IsEndOfLife(true)) + .functions(new SetEndOfLifeResolution(), new SetCloseDate(true)) .automatic() .build()) // Close the issues marked as resolved and that do not exist anymore. // Note that false-positives are kept resolved and are not closed. .transition(Transition.builder("automaticclose") .from(Issue.STATUS_RESOLVED).to(Issue.STATUS_CLOSED) - .conditions(new IsAlive(false)) - .functions(new SetCloseDate(true)) + .conditions(new IsEndOfLife(true)) + .functions(new SetEndOfLifeResolution(), new SetCloseDate(true)) .automatic() .build()) .transition(Transition.builder("automaticreopen") .from(Issue.STATUS_RESOLVED).to(Issue.STATUS_REOPENED) - .conditions(new IsAlive(true), new HasResolution(Issue.RESOLUTION_FIXED)) - .functions(new SetResolution(null)) + .conditions(new IsEndOfLife(false), new HasResolution(Issue.RESOLUTION_FIXED)) + .functions(new SetResolution(null), new SetCloseDate(false)) .automatic() .build()) .build(); @@ -168,7 +168,7 @@ public class IssueWorkflow implements BatchComponent, ServerComponent, Startable private State stateOf(DefaultIssue issue) { State state = machine.state(issue.status()); - if (state==null) { + if (state == null) { throw new IllegalStateException("Unknown status: " + issue.status() + " [issue=" + issue.key() + "]"); } return state; diff --git a/sonar-core/src/main/java/org/sonar/core/issue/workflow/SetEndOfLifeResolution.java b/sonar-core/src/main/java/org/sonar/core/issue/workflow/SetEndOfLifeResolution.java new file mode 100644 index 00000000000..387e69f6aea --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/issue/workflow/SetEndOfLifeResolution.java @@ -0,0 +1,38 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.core.issue.workflow; + +import org.sonar.api.issue.Issue; +import org.sonar.core.issue.DefaultIssue; + +public class SetEndOfLifeResolution implements Function { + @Override + public void execute(Context context) { + DefaultIssue issue = (DefaultIssue) context.issue(); + if (!issue.isEndOfLife()) { + throw new IllegalStateException("Issue is still alive: " + issue); + } + if (issue.isOnDisabledRule()) { + context.setResolution(Issue.RESOLUTION_REMOVED); + } else { + context.setResolution(Issue.RESOLUTION_FIXED); + } + } +} -- cgit v1.2.3