From 96a2e77ad59364031ec7689b2c1f0ed036ec6ef7 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 3 Jun 2013 15:42:55 +0200 Subject: [PATCH] SONAR-3755 Manage errors from actions and transitions --- .../condition/IsUnResolved.java} | 19 +- .../org/sonar/api/workflow/MutableReview.java | 45 ---- .../java/org/sonar/api/workflow/Review.java | 83 ------- .../sonar/api/workflow/WorkflowContext.java | 48 ---- .../condition/AdminRoleCondition.java | 44 ---- .../api/workflow/condition/Condition.java | 59 ----- .../api/workflow/condition/Conditions.java | 59 ----- .../HasProjectPropertyCondition.java | 51 ----- .../condition/HasReviewPropertyCondition.java | 52 ----- .../api/workflow/condition/NotCondition.java | 51 ----- .../condition/ProjectPropertyCondition.java | 42 ---- .../condition/ResolutionCondition.java | 61 ----- .../workflow/condition/StatusCondition.java | 61 ----- .../api/workflow/condition/package-info.java | 23 -- .../api/workflow/internal/DefaultComment.java | 60 ----- .../api/workflow/internal/DefaultReview.java | 215 ------------------ .../internal/DefaultWorkflowContext.java | 109 --------- .../api/workflow/internal/package-info.java | 31 --- .../org/sonar/api/workflow/package-info.java | 24 -- .../api/workflow/screen/CommentScreen.java | 38 ---- .../org/sonar/api/workflow/screen/Screen.java | 54 ----- .../api/workflow/screen/package-info.java | 23 -- .../issue/condition/HasResolutionTest.java | 5 +- .../condition/IsUnResolvedTest.java} | 20 +- .../condition/AdminRoleConditionTest.java | 44 ---- .../api/workflow/condition/ConditionTest.java | 51 ----- .../workflow/condition/ConditionsTest.java | 68 ------ .../HasProjectPropertyConditionTest.java | 63 ----- .../HasReviewPropertyConditionTest.java | 62 ----- .../workflow/condition/NotConditionTest.java | 53 ----- .../ProjectPropertyConditionTest.java | 57 ----- .../condition/ResolutionConditionTest.java | 61 ----- .../condition/StatusConditionTest.java | 62 ----- .../workflow/internal/DefaultReviewTest.java | 37 --- .../issue/InternalRubyIssueService.java | 68 ++++-- .../app/controllers/api/issues_controller.rb | 71 +++--- .../app/controllers/issue_controller.rb | 26 ++- .../WEB-INF/app/views/issue/_error.html.erb | 6 + .../WEB-INF/app/views/issue/_issue.html.erb | 2 +- .../src/main/webapp/javascripts/issue.js | 3 +- 40 files changed, 134 insertions(+), 1877 deletions(-) rename sonar-plugin-api/src/main/java/org/sonar/api/{workflow/Comment.java => issue/condition/IsUnResolved.java} (79%) delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/MutableReview.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/Review.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/WorkflowContext.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/AdminRoleCondition.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/Condition.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/Conditions.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/HasProjectPropertyCondition.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/HasReviewPropertyCondition.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/NotCondition.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/ProjectPropertyCondition.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/ResolutionCondition.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/StatusCondition.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/package-info.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultComment.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultReview.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultWorkflowContext.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/package-info.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/package-info.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/CommentScreen.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/Screen.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/package-info.java rename sonar-plugin-api/src/test/java/org/sonar/api/{workflow/screen/CommentScreenTest.java => issue/condition/IsUnResolvedTest.java} (71%) delete mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/AdminRoleConditionTest.java delete mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ConditionTest.java delete mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ConditionsTest.java delete mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/HasProjectPropertyConditionTest.java delete mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/HasReviewPropertyConditionTest.java delete mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/NotConditionTest.java delete mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ProjectPropertyConditionTest.java delete mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ResolutionConditionTest.java delete mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/StatusConditionTest.java delete mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/workflow/internal/DefaultReviewTest.java create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/issue/_error.html.erb diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/Comment.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/IsUnResolved.java similarity index 79% rename from sonar-plugin-api/src/main/java/org/sonar/api/workflow/Comment.java rename to sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/IsUnResolved.java index c7d032b896f..ed181fb8290 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/Comment.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/IsUnResolved.java @@ -17,20 +17,17 @@ * 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.api.workflow; +package org.sonar.api.issue.condition; -import com.google.common.annotations.Beta; +import org.sonar.api.issue.Issue; /** - * @since 3.1 + * @since 3.6 */ -@Beta -public interface Comment { - String getMarkdownText(); +public class IsUnResolved implements Condition { - Long getUserId(); - - Comment setMarkdownText(String s); - - Comment setUserId(Long l); + @Override + public boolean matches(Issue issue) { + return issue.resolution() == null; + } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/MutableReview.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/MutableReview.java deleted file mode 100644 index 9a0f7e25fd5..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/MutableReview.java +++ /dev/null @@ -1,45 +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.api.workflow; - -import com.google.common.annotations.Beta; - -import javax.annotation.Nullable; -import java.util.List; - -/** - * Review that can be changed by functions. It does not support (yet) changes - * on creation date, author, severity, existing comments or switched-off attribute. - * - * @since 3.1 - */ -@Beta -public interface MutableReview extends Review { - - MutableReview setStatus(String s); - - MutableReview setResolution(@Nullable String resolution); - - MutableReview setProperty(String key, @Nullable String value); - - Comment createComment(); - - List getNewComments(); -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/Review.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/Review.java deleted file mode 100644 index f9fa9046292..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/Review.java +++ /dev/null @@ -1,83 +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.api.workflow; - -import com.google.common.annotations.Beta; - -import java.util.Map; - -/** - * @since 3.1 - */ -@Beta -public interface Review { - - /** - * This method will probably be removed in order to decrease - * coupling with database. - * - * @return not-null review id (primary key of the table REVIEWS). - */ - Long getReviewId(); - - /** - * @return not-null rule repository, for example "checkstyle" - */ - String getRuleRepositoryKey(); - - /** - * @return not-null rule key - */ - String getRuleKey(); - - /** - * @return not-null rule name, in English. - */ - String getRuleName(); - - boolean isSwitchedOff(); - - String getMessage(); - - /** - * @return not-null properties - */ - Map getProperties(); - - String getStatus(); - - String getResolution(); - - /** - * @return not-null severity, from INFO to BLOCKER - */ - String getSeverity(); - - /** - * @return optional line, starting from 1 - */ - Long getLine(); - - /** - * @return true if the violation has been created by an automated rule engine, - * false if created by an end-user. - */ - boolean isManual(); -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/WorkflowContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/WorkflowContext.java deleted file mode 100644 index c643de96a01..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/WorkflowContext.java +++ /dev/null @@ -1,48 +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.api.workflow; - -import com.google.common.annotations.Beta; -import org.sonar.api.config.Settings; - -/** - * @since 3.1 - */ -@Beta -public interface WorkflowContext { - - /** - * TODO : to be replaced by getProjectKey() - */ - Long getProjectId(); - - Long getUserId(); - - String getUserLogin(); - - String getUserName(); - - String getUserEmail(); - - boolean isAdmin(); - - Settings getProjectSettings(); - -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/AdminRoleCondition.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/AdminRoleCondition.java deleted file mode 100644 index 9b7fd482094..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/AdminRoleCondition.java +++ /dev/null @@ -1,44 +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.api.workflow.condition; - -import com.google.common.annotations.Beta; -import org.sonar.api.workflow.Review; -import org.sonar.api.workflow.WorkflowContext; - -import javax.annotation.Nullable; - -/** - * Checks that user has admin rights on project. - * - * @since 3.1 - */ -@Beta -public final class AdminRoleCondition extends Condition { - - public AdminRoleCondition() { - super(true); - } - - @Override - public boolean doVerify(@Nullable Review review, WorkflowContext context) { - return context.isAdmin(); - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/Condition.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/Condition.java deleted file mode 100644 index 0d72044a7c7..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/Condition.java +++ /dev/null @@ -1,59 +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.api.workflow.condition; - -import com.google.common.annotations.Beta; -import org.sonar.api.workflow.Review; -import org.sonar.api.workflow.WorkflowContext; - -import javax.annotation.Nullable; - -/** - * Conditions control who can perform a command (i.e. who can see the screen - * associated to the command). - * - * @since 3.1 - */ -@Beta -public abstract class Condition { - - private final boolean onContext; - - protected Condition(boolean onContext) { - this.onContext = onContext; - } - - /** - * @return true if the condition relates to a review, false if it relates to the resource - * context (selected file, end-user, ...) - */ - public final boolean isOnContext() { - return onContext; - } - - /** - * @param review the review on "review conditions" like StatusCondition, null on "context conditions" - * like AdminRoleCondition or ProjectPropertyCondition - * @param context - * @return is the condition verified ? - */ - public abstract boolean doVerify(@Nullable Review review, WorkflowContext context); - -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/Conditions.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/Conditions.java deleted file mode 100644 index 2edb0964952..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/Conditions.java +++ /dev/null @@ -1,59 +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.api.workflow.condition; - -import com.google.common.annotations.Beta; - -/** - * Static utility methods pertaining to {@link Condition} instances. - * - * @since 3.1 - */ -@Beta -public final class Conditions { - - private Conditions() { - } - - public static Condition not(Condition c) { - return new NotCondition(c); - } - - public static Condition hasReviewProperty(String propertyKey) { - return new HasReviewPropertyCondition(propertyKey); - } - - public static Condition hasProjectProperty(String propertyKey) { - return new HasProjectPropertyCondition(propertyKey); - } - - public static Condition hasAdminRole() { - return new AdminRoleCondition(); - } - - public static Condition statuses(String... statuses) { - return new StatusCondition(statuses); - } - - public static Condition resolutions(String... resolutions) { - return new ResolutionCondition(resolutions); - } - -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/HasProjectPropertyCondition.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/HasProjectPropertyCondition.java deleted file mode 100644 index b0275edef18..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/HasProjectPropertyCondition.java +++ /dev/null @@ -1,51 +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.api.workflow.condition; - -import com.google.common.annotations.Beta; -import org.sonar.api.config.Settings; -import org.sonar.api.workflow.Review; -import org.sonar.api.workflow.WorkflowContext; - -import javax.annotation.Nullable; - -/** - * Checks that a project property is set, whatever its value. - * - * @since 3.1 - */ -@Beta -public final class HasProjectPropertyCondition extends ProjectPropertyCondition { - - public HasProjectPropertyCondition(String propertyKey) { - super(propertyKey); - } - - @Override - public boolean doVerify(@Nullable Review review, WorkflowContext context) { - Settings settings = context.getProjectSettings(); - return settings.hasKey(getPropertyKey()) || settings.getDefaultValue(getPropertyKey()) != null; - } - - @Override - public String toString() { - return "Property " + getPropertyKey() + " must be set"; - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/HasReviewPropertyCondition.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/HasReviewPropertyCondition.java deleted file mode 100644 index f33202085b8..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/HasReviewPropertyCondition.java +++ /dev/null @@ -1,52 +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.api.workflow.condition; - -import com.google.common.annotations.Beta; -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import org.sonar.api.workflow.Review; -import org.sonar.api.workflow.WorkflowContext; - -import javax.annotation.Nullable; - -/** - * @since 3.1 - */ -@Beta -public final class HasReviewPropertyCondition extends Condition { - - private final String propertyKey; - - public HasReviewPropertyCondition(String propertyKey) { - super(false); - Preconditions.checkArgument(!Strings.isNullOrEmpty(propertyKey)); - this.propertyKey = propertyKey; - } - - public String getPropertyKey() { - return propertyKey; - } - - @Override - public boolean doVerify(@Nullable Review review, WorkflowContext context) { - return review != null && !Strings.isNullOrEmpty(review.getProperties().get(propertyKey)); - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/NotCondition.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/NotCondition.java deleted file mode 100644 index bb5525392c7..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/NotCondition.java +++ /dev/null @@ -1,51 +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.api.workflow.condition; - -import com.google.common.annotations.Beta; -import com.google.common.annotations.VisibleForTesting; -import org.sonar.api.workflow.Review; -import org.sonar.api.workflow.WorkflowContext; - -import javax.annotation.Nullable; - -/** - * @since 3.1 - */ -@Beta -public final class NotCondition extends Condition { - - private Condition condition; - - public NotCondition(Condition c) { - super(c.isOnContext()); - this.condition = c; - } - - @Override - public boolean doVerify(@Nullable Review review, WorkflowContext context) { - return !condition.doVerify(review, context); - } - - @VisibleForTesting - Condition getCondition() { - return condition; - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/ProjectPropertyCondition.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/ProjectPropertyCondition.java deleted file mode 100644 index 8fc7f46e79a..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/ProjectPropertyCondition.java +++ /dev/null @@ -1,42 +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.api.workflow.condition; - -import com.google.common.annotations.Beta; -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; - -/** - * @since 3.1 - */ -@Beta -public abstract class ProjectPropertyCondition extends Condition { - private final String propertyKey; - - protected ProjectPropertyCondition(String propertyKey) { - super(true); - Preconditions.checkArgument(!Strings.isNullOrEmpty(propertyKey)); - this.propertyKey = propertyKey; - } - - public final String getPropertyKey() { - return propertyKey; - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/ResolutionCondition.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/ResolutionCondition.java deleted file mode 100644 index 572aaa4b452..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/ResolutionCondition.java +++ /dev/null @@ -1,61 +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.api.workflow.condition; - -import com.google.common.annotations.Beta; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; -import org.sonar.api.workflow.Review; -import org.sonar.api.workflow.WorkflowContext; - -import javax.annotation.Nullable; -import java.util.Arrays; -import java.util.Set; - -/** - * @since 3.1 - */ -@Beta -public final class ResolutionCondition extends Condition { - private final Set resolutions; - - public ResolutionCondition(Set resolutions) { - super(false); - Preconditions.checkNotNull(resolutions); - Preconditions.checkArgument(!resolutions.isEmpty(), "No resolutions defined"); - this.resolutions = resolutions; - } - - public ResolutionCondition(String... resolutions) { - this(Sets.newLinkedHashSet(Arrays.asList(resolutions))); - } - - @Override - public boolean doVerify(@Nullable Review review, WorkflowContext context) { - return review != null && resolutions.contains(review.getResolution()); - } - - @VisibleForTesting - Set getResolutions() { - return ImmutableSet.copyOf(resolutions); - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/StatusCondition.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/StatusCondition.java deleted file mode 100644 index c1f7e6632c2..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/StatusCondition.java +++ /dev/null @@ -1,61 +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.api.workflow.condition; - -import com.google.common.annotations.Beta; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; -import org.sonar.api.workflow.Review; -import org.sonar.api.workflow.WorkflowContext; - -import javax.annotation.Nullable; -import java.util.Arrays; -import java.util.Set; - -/** - * @since 3.1 - */ -@Beta -public final class StatusCondition extends Condition { - private final Set statuses; - - public StatusCondition(Set statuses) { - super(false); - Preconditions.checkNotNull(statuses); - Preconditions.checkArgument(!statuses.isEmpty(), "No statuses defined"); - this.statuses = statuses; - } - - public StatusCondition(String... statuses) { - this(Sets.newLinkedHashSet(Arrays.asList(statuses))); - } - - @Override - public boolean doVerify(@Nullable Review review, WorkflowContext context) { - return review != null && statuses.contains(review.getStatus()); - } - - @VisibleForTesting - Set getStatuses() { - return ImmutableSet.copyOf(statuses); - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/package-info.java deleted file mode 100644 index b9b583feb2c..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/package-info.java +++ /dev/null @@ -1,23 +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. - */ -@ParametersAreNonnullByDefault -package org.sonar.api.workflow.condition; - -import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultComment.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultComment.java deleted file mode 100644 index 8e14abfeba4..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultComment.java +++ /dev/null @@ -1,60 +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.api.workflow.internal; - -import com.google.common.annotations.Beta; -import org.apache.commons.lang.builder.ReflectionToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; -import org.sonar.api.workflow.Comment; - -/** - * @since 3.1 - */ -@Beta -public final class DefaultComment implements Comment { - private String markdownText; - private Long userId; - - DefaultComment() { - } - - public String getMarkdownText() { - return markdownText; - } - - public DefaultComment setMarkdownText(String s) { - this.markdownText = s; - return this; - } - - public Long getUserId() { - return userId; - } - - public DefaultComment setUserId(Long l) { - this.userId = l; - return this; - } - - @Override - public String toString() { - return new ReflectionToStringBuilder(this, ToStringStyle.SIMPLE_STYLE).toString(); - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultReview.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultReview.java deleted file mode 100644 index 5d334877649..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultReview.java +++ /dev/null @@ -1,215 +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.api.workflow.internal; - -import com.google.common.annotations.Beta; -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import org.apache.commons.lang.builder.ReflectionToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; -import org.sonar.api.workflow.Comment; -import org.sonar.api.workflow.MutableReview; -import org.sonar.api.utils.KeyValueFormat; - -import javax.annotation.Nullable; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * @since 3.1 - */ -@Beta -public final class DefaultReview implements MutableReview { - - private Long violationId; - private Long reviewId; - private String ruleRepositoryKey; - private String ruleKey; - private String ruleName; - private Long line; - private boolean switchedOff = false; - private boolean manual = false; - private String message; - private String status; - private String resolution; - private String severity; - private Map properties; - private List newComments; - - public Long getViolationId() { - return violationId; - } - - public DefaultReview setViolationId(Long violationId) { - this.violationId = violationId; - return this; - } - - public Long getReviewId() { - return reviewId; - } - - public DefaultReview setReviewId(Long reviewId) { - this.reviewId = reviewId; - return this; - } - - public String getRuleRepositoryKey() { - return ruleRepositoryKey; - } - - public DefaultReview setRuleRepositoryKey(String s) { - this.ruleRepositoryKey = s; - return this; - } - - public String getRuleKey() { - return ruleKey; - } - - public DefaultReview setRuleKey(String s) { - this.ruleKey = s; - return this; - } - - public String getRuleName() { - return ruleName; - } - - public DefaultReview setRuleName(String s) { - this.ruleName = s; - return this; - } - - public Long getLine() { - return line; - } - - public DefaultReview setLine(Long line) { - this.line = line; - return this; - } - - public boolean isSwitchedOff() { - return switchedOff; - } - - public DefaultReview setSwitchedOff(boolean b) { - this.switchedOff = b; - return this; - } - - public boolean isManual() { - return manual; - } - - public DefaultReview setManual(boolean manual) { - this.manual = manual; - return this; - } - - public String getMessage() { - return message; - } - - public DefaultReview setMessage(String message) { - this.message = message; - return this; - } - - public String getStatus() { - return status; - } - - public DefaultReview setStatus(String s) { - Preconditions.checkArgument(!Strings.isNullOrEmpty(s)); - this.status = s; - return this; - } - - public String getResolution() { - return resolution; - } - - public DefaultReview setResolution(@Nullable String s) { - this.resolution = s; - return this; - } - - public String getSeverity() { - return severity; - } - - public DefaultReview setSeverity(String s) { - Preconditions.checkArgument(!Strings.isNullOrEmpty(s)); - this.severity = s; - return this; - } - - public Map getProperties() { - if (properties == null) { - return Collections.emptyMap(); - } - return properties; - } - - public DefaultReview setProperties(Map properties) { - this.properties = properties; - return this; - } - - public DefaultReview setPropertiesAsString(@Nullable String s) { - this.properties = (s == null ? null : KeyValueFormat.parse(s)); - return this; - } - - public Comment createComment() { - if (newComments == null) { - newComments = Lists.newArrayList(); - } - Comment comment = new DefaultComment(); - newComments.add(comment); - return comment; - } - - public List getNewComments() { - if (newComments == null) { - return Collections.emptyList(); - } - return newComments; - } - - public DefaultReview setProperty(String key, @Nullable String value) { - if (properties == null) { - // keeping entries ordered by key allows to have consistent behavior in unit tests - properties = Maps.newLinkedHashMap(); - } - properties.put(key, value); - return this; - } - - @Override - public String toString() { - return new ReflectionToStringBuilder(this, ToStringStyle.SIMPLE_STYLE).toString(); - } -} \ No newline at end of file diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultWorkflowContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultWorkflowContext.java deleted file mode 100644 index 4796d29cfce..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultWorkflowContext.java +++ /dev/null @@ -1,109 +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.api.workflow.internal; - -import com.google.common.annotations.Beta; -import org.apache.commons.lang.builder.ReflectionToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; -import org.sonar.api.config.Settings; -import org.sonar.api.workflow.WorkflowContext; - -/** - * @since 3.1 - */ -@Beta -public final class DefaultWorkflowContext implements WorkflowContext { - - private Long userId; - private String userLogin; - private String userName; - private String userEmail; - private boolean isAdmin = false; - private Long projectId; - private Settings settings; - - public Long getUserId() { - return userId; - } - - public DefaultWorkflowContext setUserId(Long l) { - this.userId = l; - return this; - } - - public String getUserLogin() { - return userLogin; - } - - public DefaultWorkflowContext setUserLogin(String s) { - this.userLogin = s; - return this; - } - - public String getUserName() { - return userName; - } - - public DefaultWorkflowContext setUserName(String s) { - this.userName = s; - return this; - } - - public String getUserEmail() { - return userEmail; - } - - public DefaultWorkflowContext setUserEmail(String userEmail) { - this.userEmail = userEmail; - return this; - } - - public boolean isAdmin() { - return isAdmin; - } - - public DefaultWorkflowContext setIsAdmin(boolean b) { - isAdmin = b; - return this; - } - - public Long getProjectId() { - return projectId; - } - - public DefaultWorkflowContext setProjectId(Long l) { - this.projectId = l; - return this; - } - - public Settings getProjectSettings() { - return settings; - } - - public DefaultWorkflowContext setSettings(Settings s) { - this.settings = s; - return this; - } - - @Override - public String toString() { - return new ReflectionToStringBuilder(this, ToStringStyle.SIMPLE_STYLE).toString(); - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/package-info.java deleted file mode 100644 index 52219cfbec1..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/package-info.java +++ /dev/null @@ -1,31 +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. - */ - -/** - This package is not considered as API and future versions can break backward-compatibility. -

- It provides some classes that can be helpful for unit tests but must - ABSOLUTELY NOT be used by plugins production code. -

- */ -@ParametersAreNonnullByDefault -package org.sonar.api.workflow.internal; - -import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/package-info.java deleted file mode 100644 index 64b31cee194..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/package-info.java +++ /dev/null @@ -1,24 +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. - */ - -@ParametersAreNonnullByDefault -package org.sonar.api.workflow; - -import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/CommentScreen.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/CommentScreen.java deleted file mode 100644 index 4498cb9188d..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/CommentScreen.java +++ /dev/null @@ -1,38 +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.api.workflow.screen; - -/** - * Form with only a textarea field to type a comment. - */ - -import com.google.common.annotations.Beta; - -/** - * @since 3.1 - */ -@Beta -public final class CommentScreen extends Screen { - - public CommentScreen() { - super("comment"); - } - -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/Screen.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/Screen.java deleted file mode 100644 index 696f0ab06a5..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/Screen.java +++ /dev/null @@ -1,54 +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.api.workflow.screen; - -import com.google.common.annotations.Beta; - -/** - *

Localization

- *

At least two buttons must have labels :

- *
    - *
  • the button in the violation toolbar that displays the form screen. Key is 'reviews.command..button'.
  • - *
  • the button in the form screen that submits the command. Key is 'reviews.command..submit'.
  • - *
- * @since 3.1 - */ -@Beta -public abstract class Screen { - private final String key; - private String commandKey; - - protected Screen(String key) { - this.key = key; - } - - public final String getKey() { - return key; - } - - public final String getCommandKey() { - return commandKey; - } - - public final Screen setCommandKey(String commandKey) { - this.commandKey = commandKey; - return this; - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/package-info.java deleted file mode 100644 index e83da0e9545..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/package-info.java +++ /dev/null @@ -1,23 +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. - */ -@ParametersAreNonnullByDefault -package org.sonar.api.workflow.screen; - -import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/issue/condition/HasResolutionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/issue/condition/HasResolutionTest.java index c183f49e1ae..527a8aba400 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/issue/condition/HasResolutionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/issue/condition/HasResolutionTest.java @@ -20,6 +20,7 @@ package org.sonar.api.issue.condition; import org.junit.Test; +import org.sonar.api.issue.Issue; import org.sonar.api.issue.internal.DefaultIssue; import static org.fest.assertions.Assertions.assertThat; @@ -30,13 +31,11 @@ public class HasResolutionTest { @Test public void should_match() throws Exception { - HasResolution condition = new HasResolution("OPEN", "FIXED", "FALSE-POSITIVE"); + HasResolution condition = new HasResolution(Issue.RESOLUTION_FIXED, Issue.RESOLUTION_FALSE_POSITIVE); - assertThat(condition.matches(issue.setResolution("OPEN"))).isTrue(); assertThat(condition.matches(issue.setResolution("FIXED"))).isTrue(); assertThat(condition.matches(issue.setResolution("FALSE-POSITIVE"))).isTrue(); - assertThat(condition.matches(issue.setResolution("open"))).isFalse(); assertThat(condition.matches(issue.setResolution("Fixed"))).isFalse(); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/screen/CommentScreenTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/issue/condition/IsUnResolvedTest.java similarity index 71% rename from sonar-plugin-api/src/test/java/org/sonar/api/workflow/screen/CommentScreenTest.java rename to sonar-plugin-api/src/test/java/org/sonar/api/issue/condition/IsUnResolvedTest.java index 6731a501fec..338e8c59942 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/screen/CommentScreenTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/issue/condition/IsUnResolvedTest.java @@ -17,21 +17,23 @@ * 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.api.workflow.screen; + +package org.sonar.api.issue.condition; import org.junit.Test; +import org.sonar.api.issue.internal.DefaultIssue; import static org.fest.assertions.Assertions.assertThat; -public class CommentScreenTest { - @Test - public void testCommentScreen() { - CommentScreen screen = new CommentScreen(); +public class IsUnResolvedTest { - assertThat(screen.getKey()).isEqualTo("comment"); + DefaultIssue issue = new DefaultIssue(); + + @Test + public void should_match() throws Exception { + IsUnResolved condition = new IsUnResolved(); - assertThat(screen.getCommandKey()).isNull(); - assertThat(screen.setCommandKey("create-jira-issue")); - assertThat(screen.getCommandKey()).isEqualTo("create-jira-issue"); + assertThat(condition.matches(issue)).isTrue(); + assertThat(condition.matches(issue.setResolution("FIXED"))).isFalse(); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/AdminRoleConditionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/AdminRoleConditionTest.java deleted file mode 100644 index 68bd741e272..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/AdminRoleConditionTest.java +++ /dev/null @@ -1,44 +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.api.workflow.condition; - -import org.junit.Test; -import org.sonar.api.workflow.internal.DefaultReview; -import org.sonar.api.workflow.internal.DefaultWorkflowContext; - -import static org.fest.assertions.Assertions.assertThat; - -public class AdminRoleConditionTest { - @Test - public void verifiedIfAdminRole() { - AdminRoleCondition condition = new AdminRoleCondition(); - DefaultWorkflowContext context = new DefaultWorkflowContext(); - context.setIsAdmin(true); - assertThat(condition.doVerify(new DefaultReview(), context)).isTrue(); - } - - @Test - public void failIfNotAdminRole() { - AdminRoleCondition condition = new AdminRoleCondition(); - DefaultWorkflowContext context = new DefaultWorkflowContext(); - context.setIsAdmin(false); - assertThat(condition.doVerify(new DefaultReview(), context)).isFalse(); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ConditionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ConditionTest.java deleted file mode 100644 index 493757e91dd..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ConditionTest.java +++ /dev/null @@ -1,51 +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.api.workflow.condition; - -import org.junit.Test; -import org.sonar.api.workflow.Review; -import org.sonar.api.workflow.WorkflowContext; - -import static org.fest.assertions.Assertions.assertThat; - -public class ConditionTest { - @Test - public void checkedOncePerGroupOfReviews() { - Condition condition = new Condition(true) { - @Override - public boolean doVerify(Review review, WorkflowContext context) { - return false; - } - }; - assertThat(condition.isOnContext()).isTrue(); - } - - @Test - public void checkedForEveryReview() { - Condition condition = new Condition(false) { - @Override - public boolean doVerify(Review review, WorkflowContext context) { - return false; - } - }; - assertThat(condition.isOnContext()).isFalse(); - } - -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ConditionsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ConditionsTest.java deleted file mode 100644 index edf9c90a17a..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ConditionsTest.java +++ /dev/null @@ -1,68 +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.api.workflow.condition; - -import org.junit.Test; - -import static org.fest.assertions.Assertions.assertThat; - -public class ConditionsTest { - @Test - public void not() { - StatusCondition target = new StatusCondition("OPEN"); - Condition not = Conditions.not(target); - assertThat(not).isInstanceOf(NotCondition.class); - assertThat(((NotCondition) not).getCondition()).isSameAs(target); - } - - @Test - public void hasReviewProperty() { - Condition condition = Conditions.hasReviewProperty("foo"); - assertThat(condition).isInstanceOf(HasReviewPropertyCondition.class); - assertThat(((HasReviewPropertyCondition) condition).getPropertyKey()).isEqualTo("foo"); - } - - @Test - public void hasProjectProperty() { - Condition condition = Conditions.hasProjectProperty("foo"); - assertThat(condition).isInstanceOf(HasProjectPropertyCondition.class); - assertThat(((HasProjectPropertyCondition) condition).getPropertyKey()).isEqualTo("foo"); - } - - @Test - public void hasAdminRole() { - Condition condition = Conditions.hasAdminRole(); - assertThat(condition).isInstanceOf(AdminRoleCondition.class); - } - - @Test - public void statuses() { - Condition condition = Conditions.statuses("OPEN", "CLOSED"); - assertThat(condition).isInstanceOf(StatusCondition.class); - assertThat(((StatusCondition) condition).getStatuses()).containsOnly("OPEN", "CLOSED"); - } - - @Test - public void resolutions() { - Condition condition = Conditions.resolutions("", "RESOLVED"); - assertThat(condition).isInstanceOf(ResolutionCondition.class); - assertThat(((ResolutionCondition) condition).getResolutions()).containsOnly("", "RESOLVED"); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/HasProjectPropertyConditionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/HasProjectPropertyConditionTest.java deleted file mode 100644 index 37f9d9940c8..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/HasProjectPropertyConditionTest.java +++ /dev/null @@ -1,63 +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.api.workflow.condition; - -import org.junit.Test; -import org.sonar.api.Properties; -import org.sonar.api.Property; -import org.sonar.api.config.PropertyDefinitions; -import org.sonar.api.config.Settings; -import org.sonar.api.workflow.internal.DefaultReview; -import org.sonar.api.workflow.internal.DefaultWorkflowContext; - -import static org.fest.assertions.Assertions.assertThat; - -public class HasProjectPropertyConditionTest { - @Test - public void doVerify() { - HasProjectPropertyCondition condition = new HasProjectPropertyCondition("jira.url"); - DefaultWorkflowContext context = new DefaultWorkflowContext(); - context.setSettings(new Settings().setProperty("jira.url", "http://jira")); - assertThat(condition.doVerify(new DefaultReview(), context)).isTrue(); - } - - @Test - public void missingProperty() { - HasProjectPropertyCondition condition = new HasProjectPropertyCondition("jira.url"); - DefaultWorkflowContext context = new DefaultWorkflowContext(); - context.setSettings(new Settings()); - assertThat(condition.doVerify(new DefaultReview(), context)).isFalse(); - } - - @Test - public void returnTrueIfDefaultValue() { - HasProjectPropertyCondition condition = new HasProjectPropertyCondition("jira.url"); - DefaultWorkflowContext context = new DefaultWorkflowContext(); - context.setSettings(new Settings(new PropertyDefinitions().addComponent(WithDefaultValue.class))); - assertThat(condition.doVerify(new DefaultReview(), context)).isTrue(); - } - - @Properties({ - @Property(key = "jira.url", name = "JIRA URL", defaultValue = "http://jira.com") - }) - private static class WithDefaultValue { - - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/HasReviewPropertyConditionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/HasReviewPropertyConditionTest.java deleted file mode 100644 index 1263b6d3cbb..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/HasReviewPropertyConditionTest.java +++ /dev/null @@ -1,62 +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.api.workflow.condition; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.workflow.internal.DefaultReview; -import org.sonar.api.workflow.internal.DefaultWorkflowContext; - -import static org.fest.assertions.Assertions.assertThat; - -public class HasReviewPropertyConditionTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void doVerify() { - HasReviewPropertyCondition condition = new HasReviewPropertyCondition("foo"); - - DefaultWorkflowContext context = new DefaultWorkflowContext(); - assertThat(condition.doVerify(new DefaultReview(), context)).isFalse(); - assertThat(condition.doVerify(new DefaultReview().setProperty("foo", ""), context)).isFalse(); - assertThat(condition.doVerify(new DefaultReview().setProperty("foo", "bar"), context)).isTrue(); - } - - @Test - public void getPropertyKey() { - HasReviewPropertyCondition condition = new HasReviewPropertyCondition("foo"); - assertThat(condition.getPropertyKey()).isEqualTo("foo"); - } - - @Test - public void failIfNullProperty() { - thrown.expect(IllegalArgumentException.class); - new HasReviewPropertyCondition(null); - } - - @Test - public void failIfEmptyProperty() { - thrown.expect(IllegalArgumentException.class); - new HasReviewPropertyCondition(""); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/NotConditionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/NotConditionTest.java deleted file mode 100644 index 83f4eb7853c..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/NotConditionTest.java +++ /dev/null @@ -1,53 +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.api.workflow.condition; - -import org.junit.Test; -import org.sonar.api.workflow.internal.DefaultReview; -import org.sonar.api.workflow.internal.DefaultWorkflowContext; -import org.sonar.api.workflow.Review; -import org.sonar.api.workflow.WorkflowContext; - -import static org.fest.assertions.Assertions.assertThat; - -public class NotConditionTest { - @Test - public void doVerifyInverse() { - Condition target = new TargetCondition(true); - assertThat(new NotCondition(target).doVerify(new DefaultReview(), new DefaultWorkflowContext())).isFalse(); - - target = new TargetCondition(false); - assertThat(new NotCondition(target).doVerify(new DefaultReview(), new DefaultWorkflowContext())).isTrue(); - } - - private static class TargetCondition extends Condition { - private boolean returns; - - private TargetCondition(boolean returns) { - super(false); - this.returns = returns; - } - - @Override - public boolean doVerify(Review review, WorkflowContext context) { - return returns; - } - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ProjectPropertyConditionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ProjectPropertyConditionTest.java deleted file mode 100644 index 1b3ce5a58dd..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ProjectPropertyConditionTest.java +++ /dev/null @@ -1,57 +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.api.workflow.condition; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.workflow.Review; -import org.sonar.api.workflow.WorkflowContext; - -import javax.annotation.Nullable; - -import static org.fest.assertions.Assertions.assertThat; - -public class ProjectPropertyConditionTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void getPropertyKey() { - ProjectPropertyCondition condition = new ProjectPropertyCondition("foo") { - @Override - public boolean doVerify(Review review, WorkflowContext context) { - return false; - } - }; - assertThat(condition.getPropertyKey()).isEqualTo("foo"); - } - - @Test - public void keyIsMandatory() { - thrown.expect(IllegalArgumentException.class); - new ProjectPropertyCondition(""){ - @Override - public boolean doVerify(@Nullable Review review, WorkflowContext context) { - return false; - } - }; - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ResolutionConditionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ResolutionConditionTest.java deleted file mode 100644 index caedc231ee1..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ResolutionConditionTest.java +++ /dev/null @@ -1,61 +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.api.workflow.condition; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.workflow.Review; -import org.sonar.api.workflow.internal.DefaultReview; -import org.sonar.api.workflow.internal.DefaultWorkflowContext; - -import static org.fest.assertions.Assertions.assertThat; - -public class ResolutionConditionTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void failIfNoResolution() { - thrown.expect(IllegalArgumentException.class); - new ResolutionCondition(); - } - - @Test - public void getResolutions() { - ResolutionCondition condition = new ResolutionCondition("", "RESOLVED"); - assertThat(condition.getResolutions()).containsOnly("", "RESOLVED"); - } - - @Test - public void doVerify_review_has_resolution() { - Condition condition = new ResolutionCondition("", "RESOLVED"); - Review review = new DefaultReview().setResolution(""); - assertThat(condition.doVerify(review, new DefaultWorkflowContext())).isTrue(); - } - - @Test - public void doVerify_review_does_not_have_resolution() { - Condition condition = new ResolutionCondition("", "RESOLVED"); - Review review = new DefaultReview().setResolution("OTHER"); - assertThat(condition.doVerify(review, new DefaultWorkflowContext())).isFalse(); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/StatusConditionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/StatusConditionTest.java deleted file mode 100644 index 50bf96ba39e..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/StatusConditionTest.java +++ /dev/null @@ -1,62 +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.api.workflow.condition; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.workflow.Review; -import org.sonar.api.workflow.internal.DefaultReview; -import org.sonar.api.workflow.internal.DefaultWorkflowContext; - -import static org.fest.assertions.Assertions.assertThat; - -public class StatusConditionTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void failIfNoStatus() { - thrown.expect(IllegalArgumentException.class); - new StatusCondition(); - } - - - @Test - public void getStatuses() { - StatusCondition condition = new StatusCondition("OPEN", "CLOSED"); - assertThat(condition.getStatuses()).containsOnly("OPEN", "CLOSED"); - } - - @Test - public void doVerify_review_has_status() { - Condition condition = new StatusCondition("OPEN", "CLOSED"); - Review review = new DefaultReview().setStatus("CLOSED"); - assertThat(condition.doVerify(review, new DefaultWorkflowContext())).isTrue(); - } - - @Test - public void doVerify_review_does_not_have_status() { - Condition condition = new StatusCondition("OPEN", "CLOSED"); - Review review = new DefaultReview().setStatus("OTHER"); - assertThat(condition.doVerify(review, new DefaultWorkflowContext())).isFalse(); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/internal/DefaultReviewTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/internal/DefaultReviewTest.java deleted file mode 100644 index 556e7efe36f..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/internal/DefaultReviewTest.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.api.workflow.internal; - -import org.junit.Test; -import org.sonar.api.workflow.MutableReview; - -import static org.fest.assertions.Assertions.assertThat; - -public class DefaultReviewTest { - @Test - public void createComment_keep_order() { - MutableReview review = new DefaultReview(); - review.createComment().setMarkdownText("first"); - review.createComment().setMarkdownText("second"); - assertThat(review.getNewComments()).hasSize(2); - assertThat(review.getNewComments().get(0).getMarkdownText()).isEqualTo("first"); - assertThat(review.getNewComments().get(1).getMarkdownText()).isEqualTo("second"); - } -} diff --git a/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java b/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java index adb53c4b0c6..c97dafdfaa1 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java @@ -75,7 +75,7 @@ public class InternalRubyIssueService implements ServerComponent { this.actionService = actionService; } - public IssueStatsFinder.IssueStatsResult findIssueAssignees(Map params){ + public IssueStatsFinder.IssueStatsResult findIssueAssignees(Map params) { return issueStatsFinder.findIssueAssignees(PublicRubyIssueService.toQuery(params)); } @@ -100,24 +100,54 @@ public class InternalRubyIssueService implements ServerComponent { return changeService.changelog(issueKey); } - public Issue doTransition(String issueKey, String transitionKey) { - return issueService.doTransition(issueKey, transitionKey, UserSession.get()); + public Result doTransition(String issueKey, String transitionKey) { + Result result = Result.of(); + try { + result.set(issueService.doTransition(issueKey, transitionKey, UserSession.get())); + } catch (Exception e) { + result.addError(e.getMessage()); + } + return result; } - public Issue assign(String issueKey, @Nullable String assignee) { - return issueService.assign(issueKey, StringUtils.defaultIfBlank(assignee, null), UserSession.get()); + public Result assign(String issueKey, @Nullable String assignee) { + Result result = Result.of(); + try { + result.set(issueService.assign(issueKey, StringUtils.defaultIfBlank(assignee, null), UserSession.get())); + } catch (Exception e) { + result.addError(e.getMessage()); + } + return result; } - public Issue setSeverity(String issueKey, String severity) { - return issueService.setSeverity(issueKey, severity, UserSession.get()); + public Result setSeverity(String issueKey, String severity) { + Result result = Result.of(); + try { + result.set(issueService.setSeverity(issueKey, severity, UserSession.get())); + } catch (Exception e) { + result.addError(e.getMessage()); + } + return result; } - public Issue plan(String issueKey, @Nullable String actionPlanKey) { - return issueService.plan(issueKey, actionPlanKey, UserSession.get()); + public Result plan(String issueKey, @Nullable String actionPlanKey) { + Result result = Result.of(); + try { + result.set(issueService.plan(issueKey, actionPlanKey, UserSession.get())); + } catch (Exception e) { + result.addError(e.getMessage()); + } + return result; } - public IssueComment addComment(String issueKey, String text) { - return changeService.addComment(issueKey, text, UserSession.get()); + public Result addComment(String issueKey, String text) { + Result result = Result.of(); + try { + result.set(changeService.addComment(issueKey, text, UserSession.get())); + } catch (Exception e) { + result.addError(e.getMessage()); + } + return result; } public IssueComment deleteComment(String commentKey) { @@ -312,15 +342,25 @@ public class InternalRubyIssueService implements ServerComponent { return result; } - public Issue executeAction(String issueKey, String actionKey) { - return actionService.execute(issueKey, actionKey, UserSession.get()); + public Result executeAction(String issueKey, String actionKey) { + // TODO verify authorization + + Result result = Result.of(); + try { + result.set(actionService.execute(issueKey, actionKey, UserSession.get())); + } catch (Exception e) { + result.addError(e.getMessage()); + result.addError(e.getMessage()); + } + return result; } - public List listActions(String issueKey){ + public List listActions(String issueKey) { return actionService.listAvailableActions(issueKey); } public List listActions(Issue issue) { return actionService.listAvailableActions(issue); } + } \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb index 4cde1b10929..a4a83556c18 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb @@ -73,14 +73,8 @@ class Api::IssuesController < Api::ApiController verify_post_request require_parameters :issue, :transition - issue = Internal.issues.doTransition(params[:issue], params[:transition]) - if issue - render :json => jsonp({ - :issue => Issue.to_hash(issue) - }) - else - render :status => 400 - end + result = Internal.issues.doTransition(params[:issue], params[:transition]) + render_result_issue(result) end # @@ -98,8 +92,17 @@ class Api::IssuesController < Api::ApiController require_parameters :issue, :text text = Api::Utils.read_post_request_param(params[:text]) - comment = Internal.issues.addComment(params[:issue], text) - render :json => jsonp({:comment => Issue.comment_to_hash(comment)}) + result = Internal.issues.addComment(params[:issue], text) + + http_status = (result.ok ? 200 : 400) + hash = result_to_hash(result) + hash[:comment] = Issue.comment_to_hash(result.get) if result.get + + respond_to do |format| + # if the request header "Accept" is "*/*", then the default format is the first one (json) + format.json { render :json => jsonp(hash), :status => result.httpStatus } + format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'sonar', :status => http_status) } + end end # @@ -151,8 +154,8 @@ class Api::IssuesController < Api::ApiController verify_post_request require_parameters :issue - issue = Internal.issues.assign(params[:issue], params[:assignee]) - render :json => jsonp({:issue => Issue.to_hash(issue)}) + result = Internal.issues.assign(params[:issue], params[:assignee]) + render_result_issue(result) end @@ -168,9 +171,8 @@ class Api::IssuesController < Api::ApiController verify_post_request require_parameters :issue, :severity - issue = Internal.issues.setSeverity(params[:issue], params[:severity]) - - render :json => jsonp({:issue => Issue.to_hash(issue)}) + result = Internal.issues.setSeverity(params[:issue], params[:severity]) + render_result_issue(result) end # @@ -188,9 +190,8 @@ class Api::IssuesController < Api::ApiController plan = nil plan = params[:plan] if params[:plan] && !params[:plan].blank? - issue = Internal.issues.plan(params[:issue], plan) - - render :json => jsonp({:issue => Issue.to_hash(issue)}) + result = Internal.issues.plan(params[:issue], plan) + render_result_issue(result) end # @@ -214,16 +215,7 @@ class Api::IssuesController < Api::ApiController verify_post_request issue_result = Internal.issues.create(params) - - http_status = (issue_result.ok ? 200 : 400) - hash = result_to_hash(issue_result) - hash[:issue] = Issue.to_hash(issue_result.get) if issue_result.get - - respond_to do |format| - # if the request header "Accept" is "*/*", then the default format is the first one (json) - format.json { render :json => jsonp(hash), :status => issue_result.httpStatus } - format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'sonar', :status => http_status) } - end + render_result_issue(issue_result) end # @@ -254,18 +246,25 @@ class Api::IssuesController < Api::ApiController verify_post_request require_parameters :issue, :actionKey - issue = Internal.issues.executeAction(params[:issue], params[:actionKey]) - if issue - render :json => jsonp({ - :issue => Issue.to_hash(issue) - }) - else - render :status => 400 - end + result = Internal.issues.executeAction(params[:issue], params[:actionKey]) + render_result_issue(result) end + protected + def render_result_issue(result) + http_status = (result.ok ? 200 : 400) + hash = result_to_hash(result) + hash[:issue] = Issue.to_hash(result.get) if result.get + + respond_to do |format| + # if the request header "Accept" is "*/*", then the default format is the first one (json) + format.json { render :json => jsonp(hash), :status => result.httpStatus } + format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'sonar', :status => http_status) } + end + end + def component_to_hash(component) hash = { :key => component.key, diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb index 9f1fb5c4f51..980c1bee0cd 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb @@ -52,7 +52,7 @@ class IssueController < ApplicationController require_parameters :id, :issue @issue_result = Api.issues.find(params[:issue]) - @issue = @issue_result.issues().get(0) + @issue = @issue_result.first bad_request('Unknown issue') unless @issue @@ -69,25 +69,31 @@ class IssueController < ApplicationController issue_key = params[:issue] if action_type=='comment' - Internal.issues.addComment(issue_key, params[:text]) + issue_result = Internal.issues.addComment(issue_key, params[:text]) elsif action_type=='assign' assignee = (params[:me]=='true' ? current_user.login : params[:assignee]) - Internal.issues.assign(issue_key, assignee) + issue_result = Internal.issues.assign(issue_key, assignee) elsif action_type=='transition' - Internal.issues.doTransition(issue_key, params[:transition]) + issue_result = Internal.issues.doTransition(issue_key, params[:transition]) elsif action_type=='severity' - Internal.issues.setSeverity(issue_key, params[:severity]) + issue_result = Internal.issues.setSeverity(issue_key, params[:severity]) elsif action_type=='plan' - Internal.issues.plan(issue_key, params[:plan]) + issue_result = Internal.issues.plan(issue_key, params[:plan]) elsif action_type=='unplan' - Internal.issues.plan(issue_key, nil) + issue_result = Internal.issues.plan(issue_key, nil) else # Execute action defined by plugin - Internal.issues.executeAction(issue_key, action_type) + issue_result = Internal.issues.executeAction(issue_key, action_type) + end + + if issue_result.ok + @issue_results = Api.issues.find(issue_key) + render :partial => 'issue/issue', :locals => {:issue => @issue_results.first} + else + @errors = issue_result.errors + render :partial => 'issue/error', :status => issue_result.httpStatus end - @issue_results = Api.issues.find(issue_key) - render :partial => 'issue/issue', :locals => {:issue => @issue_results.issues.get(0)} end # Form used to edit comment diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_error.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_error.html.erb new file mode 100644 index 00000000000..003652dc122 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_error.html.erb @@ -0,0 +1,6 @@ +
+ <% @errors.each do |msg| %> +
<%= h (msg.text ? msg.text : Api::Utils.message(msg.l10nKey, :params => msg.l10nParams)) -%>
+ <% end %> + <%= link_to_function message('close'), 'refreshIssue(this)' -%> +
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb index 7ea645906f3..16a648dfd86 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb @@ -61,6 +61,7 @@ <% end %> <% if current_user %> +
<%= message('issue.comment.formlink') -%> <% unless issue.resolution %> @@ -104,7 +105,6 @@ <% plugin_actions = Internal.issues.listActions(issue) - puts "### " shouldDisplayDropDown = transitions.size > 1 || !issue.resolution || !plugin_actions.empty? if shouldDisplayDropDown transitions.remove(0) diff --git a/sonar-server/src/main/webapp/javascripts/issue.js b/sonar-server/src/main/webapp/javascripts/issue.js index ca2e2818e70..f57267528b3 100644 --- a/sonar-server/src/main/webapp/javascripts/issue.js +++ b/sonar-server/src/main/webapp/javascripts/issue.js @@ -87,8 +87,7 @@ function doIssueAction(elt, action, parameters) { notifyIssueChange(issueKey); } ).fail(function (jqXHR, textStatus) { - closeIssueForm(elt); - alert(textStatus); + issueElt.find('.code-issue-actions').replaceWith(jqXHR.responseText); }); return false; } -- 2.39.5