* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
+@ParametersAreNonnullByDefault
package org.sonar.core.review;
+import javax.annotation.ParametersAreNonnullByDefault;
\ No newline at end of file
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow;
-
-import com.google.common.annotations.VisibleForTesting;
-import org.apache.ibatis.session.SqlSession;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.ServerComponent;
-import org.sonar.api.config.Settings;
-import org.sonar.api.utils.KeyValueFormat;
-import org.sonar.core.persistence.MyBatis;
-import org.sonar.core.properties.PropertiesMapper;
-import org.sonar.core.properties.PropertyDto;
-import org.sonar.core.review.ReviewCommentDto;
-import org.sonar.core.review.ReviewCommentMapper;
-import org.sonar.core.review.ReviewDto;
-import org.sonar.core.review.ReviewMapper;
-import org.sonar.core.review.workflow.review.Comment;
-import org.sonar.core.review.workflow.review.DefaultReview;
-import java.util.Date;
-import java.util.List;
-
-public class ReviewDatabaseStore implements ReviewStore, ServerComponent {
- private static final Logger LOG = LoggerFactory.getLogger(ReviewDatabaseStore.class);
-
- private MyBatis mybatis;
-
- public ReviewDatabaseStore(MyBatis mb) {
- this.mybatis = mb;
- }
-
- public void store(DefaultReview review) {
- store(review, new Date());
- }
-
- @VisibleForTesting
- void store(DefaultReview review, Date now) {
- if (review.getReviewId() == null) {
- LOG.error("Review has no id. Violation id is: " + review.getViolationId());
- return;
- }
-
- SqlSession session = mybatis.openSession();
- ReviewMapper mapper = session.getMapper(ReviewMapper.class);
- ReviewCommentMapper commentMapper = session.getMapper(ReviewCommentMapper.class);
- try {
- ReviewDto dto = mapper.findById(review.getReviewId());
- dto.setResolution(review.getResolution());
- dto.setStatus(review.getStatus());
- dto.setData(KeyValueFormat.format(review.getProperties()));
- dto.setUpdatedAt(now);
- mapper.update(dto);
-
- for (Comment comment : review.getNewComments()) {
- ReviewCommentDto commentDto = new ReviewCommentDto();
- commentDto.setReviewId(dto.getId());
- commentDto.setText(comment.getMarkdownText());
- commentDto.setCreatedAt(now);
- commentDto.setUpdatedAt(now);
- commentDto.setUserId(comment.getUserId());
- commentMapper.insert(commentDto);
- }
- session.commit();
-
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public void completeProjectSettings(Long projectId, Settings settings, List<String> propertyKeys) {
- if (propertyKeys.isEmpty()) {
- return;
- }
-
- SqlSession session = mybatis.openSession();
- PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
- try {
- List<PropertyDto> dtos = mapper.selectSetOfResourceProperties(projectId, propertyKeys);
- for (PropertyDto dto : dtos) {
- settings.setProperty(dto.getKey(), dto.getValue());
- }
-
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow;
-
-import org.sonar.api.config.Settings;
-import org.sonar.core.review.workflow.review.DefaultReview;
-import java.util.List;
-
-public interface ReviewStore {
- void store(DefaultReview review);
-
- void completeProjectSettings(Long projectId, Settings settings, List<String> propertyKeys);
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow;
-
-import org.sonar.api.ServerExtension;
-import org.sonar.core.review.workflow.function.CommentFunction;
-import org.sonar.core.review.workflow.screen.CommentScreen;
-
-/**
- * Sample of workflow customization. Not used.
- */
-public class SampleWorkflowBuilder implements ServerExtension {
-
- private final Workflow workflow;
-
- public SampleWorkflowBuilder(Workflow workflow) {
- this.workflow = workflow;
- }
-
- public void start() {
- workflow.addCommand("comment");
- workflow.setScreen("comment", new CommentScreen());
- workflow.addFunction("comment", new CommentFunction());
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import com.google.common.collect.*;
-import org.sonar.api.ServerComponent;
-import org.sonar.core.review.workflow.condition.Condition;
-import org.sonar.core.review.workflow.condition.ProjectPropertyCondition;
-import org.sonar.core.review.workflow.function.Function;
-import org.sonar.core.review.workflow.screen.Screen;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-public class Workflow implements ServerComponent {
-
- private Set<String> commands = Sets.newLinkedHashSet();
- private ListMultimap<String, Condition> conditionsByCommand = ArrayListMultimap.create();
- private ListMultimap<String, Function> functionsByCommand = ArrayListMultimap.create();
- private Map<String, Screen> screensByCommand = Maps.newLinkedHashMap();
-
- /**
- * Keys of all the properties that are required by conditions (see {@link org.sonar.core.review.workflow.condition.ProjectPropertyCondition}
- */
- private List<String> projectPropertyKeys = Lists.newArrayList();
-
- /**
- * Optimization: fast way to get all context conditions
- */
- private ListMultimap<String, Condition> contextConditionsByCommand = ArrayListMultimap.create();
-
- /**
- * Optimization: fast way to get all review conditions
- */
- private ListMultimap<String, Condition> reviewConditionsByCommand = ArrayListMultimap.create();
-
-
- public Workflow addCommand(String key) {
- Preconditions.checkArgument(!Strings.isNullOrEmpty(key), "Empty command key");
- commands.add(key);
- return this;
- }
-
- public Set<String> getCommands() {
- return commands;
- }
-
- public boolean hasCommand(String key) {
- return commands.contains(key);
- }
-
- List<String> getProjectPropertyKeys() {
- return projectPropertyKeys;
- }
-
- /**
- * Shortcut for: getReviewConditions(commandKey) + getContextConditions(commandKey)
- */
- public List<Condition> getConditions(String commandKey) {
- return conditionsByCommand.get(commandKey);
- }
-
- public List<Condition> getReviewConditions(String commandKey) {
- return reviewConditionsByCommand.get(commandKey);
- }
-
- public List<Condition> getContextConditions(String commandKey) {
- return contextConditionsByCommand.get(commandKey);
- }
-
- public Workflow addCondition(String commandKey, Condition condition) {
- Preconditions.checkArgument(hasCommand(commandKey), "Unknown command: " + commandKey);
- Preconditions.checkNotNull(condition);
- conditionsByCommand.put(commandKey, condition);
- if (condition instanceof ProjectPropertyCondition) {
- projectPropertyKeys.add(((ProjectPropertyCondition) condition).getPropertyKey());
- }
- if (condition.isOnContext()) {
- contextConditionsByCommand.put(commandKey, condition);
- } else {
- reviewConditionsByCommand.put(commandKey, condition);
- }
- return this;
- }
-
- public List<Function> getFunctions(String commandKey) {
- return functionsByCommand.get(commandKey);
- }
-
- public Workflow addFunction(String commandKey, Function function) {
- Preconditions.checkArgument(hasCommand(commandKey), "Unknown command: " + commandKey);
- Preconditions.checkNotNull(function);
- functionsByCommand.put(commandKey, function);
- return this;
- }
-
- public Screen getScreen(String commandKey) {
- return screensByCommand.get(commandKey);
- }
-
- public Workflow setScreen(String commandKey, Screen screen) {
- Preconditions.checkArgument(hasCommand(commandKey), "Unknown command: " + commandKey);
- Preconditions.checkNotNull(screen);
- Preconditions.checkState(Strings.isNullOrEmpty(screen.getCommandKey()), "Screen is already associated with command: " + screen.getCommandKey());
- screen.setCommandKey(commandKey);
- screensByCommand.put(commandKey, screen);
- return this;
- }
-
- Map<String, Screen> getScreensByCommand() {
- return screensByCommand;
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ListMultimap;
-import com.google.common.collect.Lists;
-import org.sonar.api.ServerComponent;
-import org.sonar.api.config.Settings;
-import org.sonar.core.review.workflow.condition.Condition;
-import org.sonar.core.review.workflow.function.Function;
-import org.sonar.core.review.workflow.review.DefaultReview;
-import org.sonar.core.review.workflow.review.DefaultWorkflowContext;
-import org.sonar.core.review.workflow.review.Review;
-import org.sonar.core.review.workflow.review.WorkflowContext;
-import org.sonar.core.review.workflow.screen.Screen;
-
-import javax.annotation.Nullable;
-
-import java.util.List;
-import java.util.Map;
-
-public class WorkflowEngine implements ServerComponent {
-
- private final Workflow workflow;
- private final ReviewStore store;
- private final Settings settings;
-
- public WorkflowEngine(Workflow workflow, ReviewStore store, Settings settings) {
- this.workflow = workflow;
- this.store = store;
- this.settings = settings;
- }
-
- /**
- * @return non-null list of screens per review#violationId
- */
- public ListMultimap<Long, Screen> listAvailableScreens(DefaultReview[] reviews, DefaultWorkflowContext context, boolean verifyConditions) {
- ListMultimap<Long, Screen> result = ArrayListMultimap.create();
-
- completeProjectSettings(context);
-
- for (Map.Entry<String, Screen> entry : workflow.getScreensByCommand().entrySet()) {
- String commandKey = entry.getKey();
- if (!verifyConditions || verifyConditionsQuietly(null, context, workflow.getContextConditions(commandKey))) {
- for (DefaultReview review : reviews) {
- if (!verifyConditions || verifyConditionsQuietly(review, context, workflow.getReviewConditions(commandKey))) {
- result.put(review.getViolationId(), entry.getValue());
- }
- }
- }
- }
- return result;
- }
-
- public List<Screen> listAvailableScreens(Review review, DefaultWorkflowContext context, boolean verifyConditions) {
- List<Screen> result = Lists.newArrayList();
- completeProjectSettings(context);
- for (Map.Entry<String, Screen> entry : workflow.getScreensByCommand().entrySet()) {
- String commandKey = entry.getKey();
- if (!verifyConditions || verifyConditionsQuietly(review, context, workflow.getConditions(commandKey))) {
- result.add(entry.getValue());
-
- }
- }
- return result;
- }
-
- /**
- * @return the optional (nullable) screen associated to the command
- */
- public Screen getScreen(String commandKey) {
- return workflow.getScreen(commandKey);
- }
-
- public void execute(String commandKey, DefaultReview review, DefaultWorkflowContext context, Map<String, String> parameters) {
- Preconditions.checkArgument(!Strings.isNullOrEmpty(commandKey), "Missing command");
- Preconditions.checkArgument(workflow.hasCommand(commandKey), "Unknown command: " + commandKey);
-
- completeProjectSettings(context);
-
- verifyConditions(review, context, workflow.getConditions(commandKey));
-
- Map<String, String> immutableParameters = ImmutableMap.copyOf(parameters);
-
- // TODO execute functions are change state before functions that consume state (like "create-jira-issue")
- Review initialReview = review.cloneImmutable();
- for (Function function : workflow.getFunctions(commandKey)) {
- function.doExecute(review, initialReview, context, immutableParameters);
- }
-
- // should it be extracted to a core function ?
- store.store(review);
-
- // TODO notify listeners
- }
-
- private boolean verifyConditionsQuietly(@Nullable Review review, WorkflowContext context, List<Condition> conditions) {
- for (Condition condition : conditions) {
- if (!condition.doVerify(review, context)) {
- return false;
- }
- }
- return true;
- }
-
- private void verifyConditions(@Nullable Review review, WorkflowContext context, List<Condition> conditions) {
- for (Condition condition : conditions) {
- if (!condition.doVerify(review, context)) {
- throw new IllegalStateException("Condition is not respected: " + condition.toString());
- }
- }
- }
-
- private void completeProjectSettings(DefaultWorkflowContext context) {
- Settings projectSettings = new Settings(settings);
- List<String> propertyKeys = workflow.getProjectPropertyKeys();
- store.completeProjectSettings(context.getProjectId(), projectSettings, propertyKeys);
- context.setSettings(projectSettings);
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.condition;
-
-import com.google.common.annotations.Beta;
-import org.sonar.core.review.workflow.review.Review;
-import org.sonar.core.review.workflow.review.WorkflowContext;
-
-/**
- * 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(Review review, WorkflowContext context) {
- return context.isAdmin();
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.condition;
-
-import com.google.common.annotations.Beta;
-import org.sonar.core.review.workflow.review.Review;
-import org.sonar.core.review.workflow.review.WorkflowContext;
-
-import javax.annotation.Nullable;
-
-/**
- * @since 3.1
- */
-@Beta
-public abstract class Condition {
-
- private final boolean onContext;
-
- protected Condition(boolean onContext) {
- this.onContext = onContext;
- }
-
- 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);
-
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.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);
- }
-
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.condition;
-
-import com.google.common.annotations.Beta;
-import org.sonar.api.config.Settings;
-import org.sonar.core.review.workflow.review.Review;
-import org.sonar.core.review.workflow.review.WorkflowContext;
-
-/**
- * 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(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";
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.condition;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import org.sonar.core.review.workflow.review.Review;
-import org.sonar.core.review.workflow.review.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));
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.condition;
-
-import com.google.common.annotations.VisibleForTesting;
-import org.sonar.core.review.workflow.review.Review;
-import org.sonar.core.review.workflow.review.WorkflowContext;
-
-public final class NotCondition extends Condition {
-
- private Condition condition;
-
- public NotCondition(Condition c) {
- super(c.isOnContext());
- this.condition = c;
- }
-
- @Override
- public boolean doVerify(Review review, WorkflowContext context) {
- return !condition.doVerify(review, context);
- }
-
- @VisibleForTesting
- Condition getCondition() {
- return condition;
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.condition;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-
-
-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;
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.condition;
-
-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.core.review.workflow.review.Review;
-import org.sonar.core.review.workflow.review.WorkflowContext;
-
-import java.util.Arrays;
-import java.util.Set;
-
-public final class ResolutionCondition extends Condition {
- private final Set<String> resolutions;
-
- public ResolutionCondition(Set<String> 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(Review review, WorkflowContext context) {
- return resolutions.contains(review.getResolution());
- }
-
- @VisibleForTesting
- Set<String> getResolutions() {
- return ImmutableSet.copyOf(resolutions);
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.condition;
-
-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.core.review.workflow.review.Review;
-import org.sonar.core.review.workflow.review.WorkflowContext;
-
-import java.util.Arrays;
-import java.util.Set;
-
-public final class StatusCondition extends Condition {
- private final Set<String> statuses;
-
- public StatusCondition(Set<String> 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(Review review, WorkflowContext context) {
- return statuses.contains(review.getStatus());
- }
-
- @VisibleForTesting
- Set<String> getStatuses() {
- return ImmutableSet.copyOf(statuses);
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-@ParametersAreNonnullByDefault
-package org.sonar.core.review.workflow.condition;
-
-import javax.annotation.ParametersAreNonnullByDefault;
\ No newline at end of file
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.function;
-
-import org.sonar.core.review.workflow.review.Comment;
-import org.sonar.core.review.workflow.review.MutableReview;
-import org.sonar.core.review.workflow.review.Review;
-import org.sonar.core.review.workflow.review.WorkflowContext;
-
-import java.util.Map;
-
-public final class CommentFunction extends Function {
-
- @Override
- public void doExecute(MutableReview review, Review initialReview, WorkflowContext context, Map<String, String> parameters) {
- Comment comment = review.createComment();
- comment.setMarkdownText(parameters.get("text"));
- comment.setUserId(context.getUserId());
- }
-
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.function;
-
-import com.google.common.annotations.Beta;
-import org.sonar.core.review.workflow.review.MutableReview;
-import org.sonar.core.review.workflow.review.Review;
-import org.sonar.core.review.workflow.review.WorkflowContext;
-
-import java.util.Map;
-
-/**
- * @since 3.1
- */
-@Beta
-public abstract class Function {
-
- /**
- * This method is executed when all the conditions pass.
- *
- * @param review the review that can be changed
- * @param initialReview the read-only review as stated before execution of functions
- * @param context information about the user who executed the command and about project
- * @param parameters the command parameters sent by end user, generally from forms displayed in screens
- */
- public abstract void doExecute(MutableReview review, Review initialReview, WorkflowContext context, Map<String, String> parameters);
-
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-@ParametersAreNonnullByDefault
-package org.sonar.core.review.workflow.function;
-
-import javax.annotation.ParametersAreNonnullByDefault;
\ No newline at end of file
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-@ParametersAreNonnullByDefault
-package org.sonar.core.review.workflow;
-
-import javax.annotation.ParametersAreNonnullByDefault;
\ No newline at end of file
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.review;
-
-public interface Comment {
- String getMarkdownText();
-
- Long getUserId();
-
- Comment setMarkdownText(String s);
-
- Comment setUserId(Long l);
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.review;
-
-import org.apache.commons.lang.builder.ReflectionToStringBuilder;
-import org.apache.commons.lang.builder.ToStringStyle;
-
-public final class DefaultComment implements Comment, Cloneable {
- 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();
- }
-
- @Override
- public Comment clone() {
- return new DefaultComment().setMarkdownText(markdownText).setUserId(userId);
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.review;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import com.google.common.collect.ImmutableMap;
-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.utils.KeyValueFormat;
-
-import javax.annotation.Nullable;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-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<String, String> properties;
- private List<Comment> 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<String, String> getProperties() {
- if (properties == null) {
- return Collections.emptyMap();
- }
- return properties;
- }
-
- public DefaultReview setProperties(Map<String, String> 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<Comment> 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();
- }
-
- /**
- * Note : implementation is still mutable.
- */
- public ImmutableReview cloneImmutable() {
- ImmutableReview clone = new ImmutableReview();
- clone.setLine(line);
- clone.setManual(manual);
- clone.setMessage(message);
- clone.setProperties(ImmutableMap.copyOf(getProperties()));
- clone.setResolution(resolution);
- clone.setReviewId(reviewId);
- clone.setRuleKey(ruleKey);
- clone.setRuleRepositoryKey(ruleRepositoryKey);
- clone.setRuleName(ruleName);
- clone.setSeverity(severity);
- clone.setStatus(status);
- clone.setSwitchedOff(switchedOff);
- clone.setViolationId(violationId);
- clone.setProperties(ImmutableMap.copyOf(getProperties()));
- return clone;
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.review;
-
-import org.apache.commons.lang.builder.ReflectionToStringBuilder;
-import org.apache.commons.lang.builder.ToStringStyle;
-import org.sonar.api.config.Settings;
-
-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();
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.review;
-
-import java.util.Map;
-
-public class ImmutableReview implements Review {
- 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<String, String> properties;
-
- public Long getViolationId() {
- return violationId;
- }
-
- void setViolationId(Long violationId) {
- this.violationId = violationId;
- }
-
- public Long getReviewId() {
- return reviewId;
- }
-
- void setReviewId(Long reviewId) {
- this.reviewId = reviewId;
- }
-
- public String getRuleName() {
- return ruleName;
- }
-
- void setRuleName(String s) {
- this.ruleName = s;
- }
-
- public String getRuleRepositoryKey() {
- return ruleRepositoryKey;
- }
-
- void setRuleRepositoryKey(String ruleRepositoryKey) {
- this.ruleRepositoryKey = ruleRepositoryKey;
- }
-
- public String getRuleKey() {
- return ruleKey;
- }
-
- void setRuleKey(String ruleKey) {
- this.ruleKey = ruleKey;
- }
-
- public Long getLine() {
- return line;
- }
-
- void setLine(Long line) {
- this.line = line;
- }
-
- public boolean isSwitchedOff() {
- return switchedOff;
- }
-
- void setSwitchedOff(boolean switchedOff) {
- this.switchedOff = switchedOff;
- }
-
- public boolean isManual() {
- return manual;
- }
-
- void setManual(boolean manual) {
- this.manual = manual;
- }
-
- public String getMessage() {
- return message;
- }
-
- void setMessage(String message) {
- this.message = message;
- }
-
- public String getStatus() {
- return status;
- }
-
- void setStatus(String status) {
- this.status = status;
- }
-
- public String getResolution() {
- return resolution;
- }
-
- void setResolution(String resolution) {
- this.resolution = resolution;
- }
-
- public String getSeverity() {
- return severity;
- }
-
- void setSeverity(String severity) {
- this.severity = severity;
- }
-
- public Map<String, String> getProperties() {
- return properties;
- }
-
- void setProperties(Map<String, String> properties) {
- this.properties = properties;
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.review;
-
-import javax.annotation.Nullable;
-import java.util.List;
-
-public interface MutableReview extends Review {
-
- MutableReview setStatus(String s);
-
- MutableReview setResolution(@Nullable String resolution);
-
- MutableReview setProperty(String key, @Nullable String value);
-
- Comment createComment();
-
- List<Comment> getNewComments();
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.review;
-
-import java.util.Map;
-
-public interface Review {
-
- Long getReviewId();
-
- String getRuleRepositoryKey();
-
- String getRuleKey();
-
- String getRuleName();
-
- boolean isSwitchedOff();
-
- String getMessage();
-
- Map<String,String> getProperties();
-
- String getStatus();
-
- String getResolution();
-
- String getSeverity();
-
- Long getLine();
-
- boolean isManual();
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.review;
-
-import org.sonar.api.config.Settings;
-
-public interface WorkflowContext {
- Long getProjectId();
-
- Long getUserId();
-
- String getUserLogin();
-
- String getUserName();
-
- String getUserEmail();
-
- boolean isAdmin();
-
- Settings getProjectSettings();
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-@ParametersAreNonnullByDefault
-package org.sonar.core.review.workflow.review;
-
-import javax.annotation.ParametersAreNonnullByDefault;
\ No newline at end of file
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.screen;
-
-/**
- * Form with only a textarea field to type a comment.
- */
-public final class CommentScreen extends Screen {
-
- public CommentScreen() {
- super("comment");
- }
-
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.screen;
-
-/**
- * <h2>Localization</h2>
- * <p>At least two buttons must have labels :</p>
- * <ul>
- * <li>the button in the violation toolbar that displays the form screen. Key is 'reviews.command.<command_key>.button'.</li>
- * <li>the button in the form screen that submits the command. Key is 'reviews.command.<command_key>.submit'.</li>
- * </ul>
- */
-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;
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-@ParametersAreNonnullByDefault
-package org.sonar.core.review.workflow.screen;
-
-import javax.annotation.ParametersAreNonnullByDefault;
\ No newline at end of file
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.workflow;
+
+import com.google.common.collect.ImmutableMap;
+import org.sonar.api.workflow.Review;
+import org.sonar.api.workflow.internal.DefaultReview;
+
+import java.util.Map;
+
+public final class ImmutableReview implements Review {
+ private final Long violationId;
+ private final Long reviewId;
+ private final String ruleRepositoryKey;
+ private final String ruleKey;
+ private final String ruleName;
+ private final Long line;
+ private final boolean switchedOff;
+ private final boolean manual;
+ private final String message;
+ private final String status;
+ private final String resolution;
+ private final String severity;
+ private final Map<String, String> properties;
+
+ /**
+ * Warning : implementation is still mutable.
+ */
+ public ImmutableReview(DefaultReview review) {
+ this.line = review.getLine();
+ this.manual = review.isManual();
+ this.message = review.getMessage();
+ this.properties = ImmutableMap.copyOf(review.getProperties());
+ this.resolution = review.getResolution();
+ this.reviewId = review.getReviewId();
+ this.ruleKey = review.getRuleKey();
+ this.ruleRepositoryKey = review.getRuleRepositoryKey();
+ this.ruleName = review.getRuleName();
+ this.severity = review.getSeverity();
+ this.status = review.getStatus();
+ this.switchedOff = review.isSwitchedOff();
+ this.violationId = review.getViolationId();
+ }
+
+ public Long getViolationId() {
+ return violationId;
+ }
+
+ public Long getReviewId() {
+ return reviewId;
+ }
+
+ public String getRuleName() {
+ return ruleName;
+ }
+
+ public String getRuleRepositoryKey() {
+ return ruleRepositoryKey;
+ }
+
+ public String getRuleKey() {
+ return ruleKey;
+ }
+
+ public Long getLine() {
+ return line;
+ }
+
+ public boolean isSwitchedOff() {
+ return switchedOff;
+ }
+
+ public boolean isManual() {
+ return manual;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public String getResolution() {
+ return resolution;
+ }
+
+ public String getSeverity() {
+ return severity;
+ }
+
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.workflow;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.ibatis.session.SqlSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.ServerComponent;
+import org.sonar.api.config.Settings;
+import org.sonar.api.utils.KeyValueFormat;
+import org.sonar.core.persistence.MyBatis;
+import org.sonar.core.properties.PropertiesMapper;
+import org.sonar.core.properties.PropertyDto;
+import org.sonar.core.review.ReviewCommentDto;
+import org.sonar.core.review.ReviewCommentMapper;
+import org.sonar.core.review.ReviewDto;
+import org.sonar.core.review.ReviewMapper;
+import org.sonar.api.workflow.Comment;
+import org.sonar.api.workflow.internal.DefaultReview;
+import java.util.Date;
+import java.util.List;
+
+public class ReviewDatabaseStore implements ReviewStore, ServerComponent {
+ private static final Logger LOG = LoggerFactory.getLogger(ReviewDatabaseStore.class);
+
+ private MyBatis mybatis;
+
+ public ReviewDatabaseStore(MyBatis mb) {
+ this.mybatis = mb;
+ }
+
+ public void store(DefaultReview review) {
+ store(review, new Date());
+ }
+
+ @VisibleForTesting
+ void store(DefaultReview review, Date now) {
+ if (review.getReviewId() == null) {
+ LOG.error("Review has no id. Violation id is: " + review.getViolationId());
+ return;
+ }
+
+ SqlSession session = mybatis.openSession();
+ ReviewMapper mapper = session.getMapper(ReviewMapper.class);
+ ReviewCommentMapper commentMapper = session.getMapper(ReviewCommentMapper.class);
+ try {
+ ReviewDto dto = mapper.findById(review.getReviewId());
+ dto.setResolution(review.getResolution());
+ dto.setStatus(review.getStatus());
+ dto.setData(KeyValueFormat.format(review.getProperties()));
+ dto.setUpdatedAt(now);
+ mapper.update(dto);
+
+ for (Comment comment : review.getNewComments()) {
+ ReviewCommentDto commentDto = new ReviewCommentDto();
+ commentDto.setReviewId(dto.getId());
+ commentDto.setText(comment.getMarkdownText());
+ commentDto.setCreatedAt(now);
+ commentDto.setUpdatedAt(now);
+ commentDto.setUserId(comment.getUserId());
+ commentMapper.insert(commentDto);
+ }
+ session.commit();
+
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public void completeProjectSettings(Long projectId, Settings settings, List<String> propertyKeys) {
+ if (propertyKeys.isEmpty()) {
+ return;
+ }
+
+ SqlSession session = mybatis.openSession();
+ PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
+ try {
+ List<PropertyDto> dtos = mapper.selectSetOfResourceProperties(projectId, propertyKeys);
+ for (PropertyDto dto : dtos) {
+ settings.setProperty(dto.getKey(), dto.getValue());
+ }
+
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.workflow;
+
+import org.sonar.api.config.Settings;
+import org.sonar.api.workflow.internal.DefaultReview;
+import java.util.List;
+
+public interface ReviewStore {
+ void store(DefaultReview review);
+
+ void completeProjectSettings(Long projectId, Settings settings, List<String> propertyKeys);
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.workflow;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ListMultimap;
+import com.google.common.collect.Lists;
+import org.sonar.api.ServerComponent;
+import org.sonar.api.config.Settings;
+import org.sonar.api.workflow.Review;
+import org.sonar.api.workflow.WorkflowContext;
+import org.sonar.api.workflow.condition.Condition;
+import org.sonar.api.workflow.function.Function;
+import org.sonar.api.workflow.internal.DefaultReview;
+import org.sonar.api.workflow.internal.DefaultWorkflow;
+import org.sonar.api.workflow.internal.DefaultWorkflowContext;
+import org.sonar.api.workflow.screen.Screen;
+
+import javax.annotation.Nullable;
+import java.util.List;
+import java.util.Map;
+
+public class WorkflowEngine implements ServerComponent {
+
+ private final DefaultWorkflow workflow;
+ private final ReviewStore store;
+ private final Settings settings;
+
+ public WorkflowEngine(DefaultWorkflow workflow, ReviewStore store, Settings settings) {
+ this.workflow = workflow;
+ this.store = store;
+ this.settings = settings;
+ }
+
+ /**
+ * @return non-null list of screens per review#violationId
+ */
+ public ListMultimap<Long, Screen> listAvailableScreens(DefaultReview[] reviews, DefaultWorkflowContext context, boolean verifyConditions) {
+ ListMultimap<Long, Screen> result = ArrayListMultimap.create();
+
+ completeProjectSettings(context);
+
+ for (Map.Entry<String, Screen> entry : workflow.getScreensByCommand().entrySet()) {
+ String commandKey = entry.getKey();
+ if (!verifyConditions || verifyConditionsQuietly(null, context, workflow.getContextConditions(commandKey))) {
+ for (DefaultReview review : reviews) {
+ if (!verifyConditions || verifyConditionsQuietly(review, context, workflow.getReviewConditions(commandKey))) {
+ result.put(review.getViolationId(), entry.getValue());
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ public List<Screen> listAvailableScreens(Review review, DefaultWorkflowContext context, boolean verifyConditions) {
+ List<Screen> result = Lists.newArrayList();
+ completeProjectSettings(context);
+ for (Map.Entry<String, Screen> entry : workflow.getScreensByCommand().entrySet()) {
+ String commandKey = entry.getKey();
+ if (!verifyConditions || verifyConditionsQuietly(review, context, workflow.getConditions(commandKey))) {
+ result.add(entry.getValue());
+
+ }
+ }
+ return result;
+ }
+
+ /**
+ * @return the optional (nullable) screen associated to the command
+ */
+ public Screen getScreen(String commandKey) {
+ return workflow.getScreen(commandKey);
+ }
+
+ public void execute(String commandKey, DefaultReview review, DefaultWorkflowContext context, Map<String, String> parameters) {
+ Preconditions.checkArgument(!Strings.isNullOrEmpty(commandKey), "Missing command");
+ Preconditions.checkArgument(workflow.hasCommand(commandKey), "Unknown command: " + commandKey);
+
+ completeProjectSettings(context);
+
+ verifyConditions(review, context, workflow.getConditions(commandKey));
+
+ Map<String, String> immutableParameters = ImmutableMap.copyOf(parameters);
+
+ // TODO execute functions are change state before functions that consume state (like "create-jira-issue")
+ Review initialReview = new ImmutableReview(review);
+ for (Function function : workflow.getFunctions(commandKey)) {
+ function.doExecute(review, initialReview, context, immutableParameters);
+ }
+
+ // should it be extracted to a core function ?
+ store.store(review);
+
+ // TODO notify listeners
+ }
+
+ private boolean verifyConditionsQuietly(@Nullable Review review, WorkflowContext context, List<Condition> conditions) {
+ for (Condition condition : conditions) {
+ if (!condition.doVerify(review, context)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private void verifyConditions(@Nullable Review review, WorkflowContext context, List<Condition> conditions) {
+ for (Condition condition : conditions) {
+ if (!condition.doVerify(review, context)) {
+ throw new IllegalStateException("Condition is not respected: " + condition.toString());
+ }
+ }
+ }
+
+ private void completeProjectSettings(DefaultWorkflowContext context) {
+ Settings projectSettings = new Settings(settings);
+ List<String> propertyKeys = workflow.getProjectPropertyKeys();
+ store.completeProjectSettings(context.getProjectId(), projectSettings, propertyKeys);
+ context.setSettings(projectSettings);
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.core.workflow;
+
+import javax.annotation.ParametersAreNonnullByDefault;
\ No newline at end of file
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow;
-
-import org.junit.Test;
-import org.sonar.api.utils.DateUtils;
-import org.sonar.core.persistence.DaoTestCase;
-import org.sonar.core.review.workflow.review.Comment;
-import org.sonar.core.review.workflow.review.DefaultReview;
-import java.util.Date;
-
-public class ReviewDatabaseStoreTest extends DaoTestCase {
-
- @Test
- public void store() {
- setupData("store");
- ReviewDatabaseStore store = new ReviewDatabaseStore(getMyBatis());
- DefaultReview review = new DefaultReview().setReviewId(1234L);
- review.setStatus("CLOSED");
- review.setResolution("RESOLVED");
- review.setProperty("who", "me");
- review.setProperty("why", "because");
- Comment comment = review.createComment();
- comment.setMarkdownText("this is a comment");
- comment.setUserId(555L);
-
- Date now = DateUtils.parseDate("2012-05-18");
- store.store(review, now);
-
- checkTables("store", "reviews");
- checkTables("store", new String[]{"id"}, "review_comments");
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow;
-
-import org.junit.Test;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class SampleWorkflowBuilderTest {
- @Test
- public void completeWorkflowAtStartup() {
- Workflow workflow = new Workflow();
-
- new SampleWorkflowBuilder(workflow).start();
-
- assertThat(workflow.getCommands()).containsOnly("comment");
- assertThat(workflow.getScreen("comment")).isNotNull();
- assertThat(workflow.getFunctions("comment")).hasSize(1);
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow;
-
-import com.google.common.collect.ListMultimap;
-import com.google.common.collect.Maps;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.config.Settings;
-import org.sonar.core.review.workflow.condition.Condition;
-import org.sonar.core.review.workflow.condition.HasProjectPropertyCondition;
-import org.sonar.core.review.workflow.function.Function;
-import org.sonar.core.review.workflow.review.*;
-import org.sonar.core.review.workflow.screen.CommentScreen;
-import org.sonar.core.review.workflow.screen.Screen;
-
-import java.util.List;
-import java.util.Map;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.junit.matchers.JUnitMatchers.hasItem;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.*;
-
-public class WorkflowEngineTest {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Test
- public void listAvailableScreensForReview_empty() {
- WorkflowEngine engine = new WorkflowEngine(new Workflow(), mock(ReviewStore.class), new Settings());
- List<Screen> screens = engine.listAvailableScreens(new DefaultReview(), new DefaultWorkflowContext(), true);
- assertThat(screens).isEmpty();
- }
-
- @Test
- public void listAvailableScreensForReview() {
- Workflow workflow = new Workflow();
- workflow.addCommand("command-without-screen");
- workflow.addCommand("resolve");
- CommentScreen screen = new CommentScreen();
- workflow.setScreen("resolve", screen);
-
- WorkflowEngine engine = new WorkflowEngine(workflow, mock(ReviewStore.class), new Settings());
- List<Screen> screens = engine.listAvailableScreens(new DefaultReview(), new DefaultWorkflowContext(), true);
- assertThat(screens).containsExactly(screen);
- }
-
- @Test
- public void listAvailableScreensForReview_verify_conditions() {
- Workflow workflow = new Workflow();
- workflow.addCommand("resolve");
- Condition condition = mock(Condition.class);
- when(condition.doVerify(any(Review.class), any(WorkflowContext.class))).thenReturn(false);
- workflow.addCondition("resolve", condition);
- workflow.setScreen("resolve", new CommentScreen());
-
- WorkflowEngine engine = new WorkflowEngine(workflow, mock(ReviewStore.class), new Settings());
- DefaultReview review = new DefaultReview();
- DefaultWorkflowContext context = new DefaultWorkflowContext();
- assertThat(engine.listAvailableScreens(review, context, true)).isEmpty();
-
- verify(condition).doVerify(review, context);
- }
-
- @Test
- public void listAvailableScreensForReviews_empty() {
- WorkflowEngine engine = new WorkflowEngine(new Workflow(), mock(ReviewStore.class), new Settings());
- ListMultimap<Long, Screen> screens = engine.listAvailableScreens(
- new DefaultReview[]{new DefaultReview().setViolationId(1000L), new DefaultReview().setViolationId(2000L)},
- new DefaultWorkflowContext(), true);
- assertThat(screens.size()).isEqualTo(0);
- }
-
- @Test
- public void listAvailableScreensForReviews() {
- Workflow workflow = new Workflow();
- workflow.addCommand("command-without-screen");
- workflow.addCommand("resolve");
- CommentScreen screen = new CommentScreen();
- workflow.setScreen("resolve", screen);
- WorkflowEngine engine = new WorkflowEngine(workflow, mock(ReviewStore.class), new Settings());
- ListMultimap<Long, Screen> screens = engine.listAvailableScreens(
- new DefaultReview[]{new DefaultReview().setViolationId(1000L), new DefaultReview().setViolationId(2000L)},
- new DefaultWorkflowContext(), true);
- assertThat(screens.size()).isEqualTo(2);
- assertThat(screens.get(1000L)).containsExactly(screen);
- assertThat(screens.get(2000L)).containsExactly(screen);
- }
-
- @Test
- public void listAvailableScreensForReviews_load_project_properties() {
- Workflow workflow = new Workflow();
- workflow.addCommand("resolve");
- workflow.addCondition("resolve", new HasProjectPropertyCondition("foo"));
-
- ReviewStore store = mock(ReviewStore.class);
- WorkflowEngine engine = new WorkflowEngine(workflow, store, new Settings());
-
- engine.listAvailableScreens(
- new DefaultReview[]{new DefaultReview().setViolationId(1000L), new DefaultReview().setViolationId(2000L)},
- new DefaultWorkflowContext().setProjectId(300L),
- true);
-
- verify(store).completeProjectSettings(eq(300L), any(Settings.class), (List<String>) argThat(hasItem("foo")));
- }
-
- @Test
- public void execute_conditions_pass() {
- Workflow workflow = new Workflow();
- workflow.addCommand("resolve");
- workflow.addCondition("resolve", new HasProjectPropertyCondition("foo"));
- Function function = mock(Function.class);
- workflow.addFunction("resolve", function);
-
- ReviewStore store = mock(ReviewStore.class);
- Settings settings = new Settings();
- settings.setProperty("foo", "bar");
- WorkflowEngine engine = new WorkflowEngine(workflow, store, settings);
-
- DefaultReview review = new DefaultReview().setViolationId(1000L);
- Map<String, String> parameters = Maps.newHashMap();
- DefaultWorkflowContext context = new DefaultWorkflowContext().setProjectId(300L);
-
- engine.execute("resolve", review, context, parameters);
-
- verify(store).completeProjectSettings(eq(300L), any(Settings.class), (List<String>) argThat(hasItem("foo")));
- verify(function).doExecute(eq(review), any(ImmutableReview.class), eq(context), eq(parameters));
- }
-
- @Test
- public void execute_fail_if_conditions_dont_pass() {
- thrown.expect(IllegalStateException.class);
- thrown.expectMessage("Condition is not respected: Property foo must be set");
-
- Workflow workflow = new Workflow();
- workflow.addCommand("resolve");
- workflow.addCondition("resolve", new HasProjectPropertyCondition("foo"));
- Function function = mock(Function.class);
- workflow.addFunction("resolve", function);
-
- ReviewStore store = mock(ReviewStore.class);
- Settings settings = new Settings();// missing property 'foo'
- WorkflowEngine engine = new WorkflowEngine(workflow, store, settings);
-
- DefaultReview review = new DefaultReview().setViolationId(1000L);
- Map<String, String> parameters = Maps.newHashMap();
- DefaultWorkflowContext context = new DefaultWorkflowContext().setProjectId(300L);
-
- engine.execute("resolve", review, context, parameters);
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow;
-
-import org.fest.assertions.MapAssert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.core.review.workflow.condition.Condition;
-import org.sonar.core.review.workflow.condition.HasProjectPropertyCondition;
-import org.sonar.core.review.workflow.condition.StatusCondition;
-import org.sonar.core.review.workflow.function.CommentFunction;
-import org.sonar.core.review.workflow.function.Function;
-import org.sonar.core.review.workflow.screen.CommentScreen;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class WorkflowTest {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Test
- public void addCommand() {
- Workflow workflow = new Workflow();
- assertThat(workflow.getCommands()).isEmpty();
-
- assertThat(workflow.addCommand("resolve")).isSameAs(workflow);
- assertThat(workflow.getCommands()).containsOnly("resolve");
- assertThat(workflow.hasCommand("resolve")).isTrue();
- }
-
- @Test
- public void addCommand_does_not_accept_blank() {
- thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("Empty command key");
-
- Workflow workflow = new Workflow();
- workflow.addCommand("");
- }
-
- @Test
- public void addSeveralTimesTheSameCommand() {
- Workflow workflow = new Workflow();
- workflow.addCommand("resolve");
- workflow.addCommand("resolve");
- assertThat(workflow.getCommands()).containsOnly("resolve");
- assertThat(workflow.getCommands()).hasSize(1);
- }
-
- @Test
- public void addCondition_fail_if_unknown_command() {
- thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("Unknown command: resolve");
-
- Workflow workflow = new Workflow();
- workflow.addCondition("resolve", new StatusCondition("OPEN"));
- }
-
- @Test
- public void addCondition() {
- Workflow workflow = new Workflow();
- Condition condition = new StatusCondition("OPEN");
- workflow.addCommand("resolve");
-
- workflow.addCondition("resolve", condition);
-
- assertThat(workflow.getConditions("resolve")).containsExactly(condition);
- }
-
- @Test
- public void getConditions_empty() {
- Workflow workflow = new Workflow();
- assertThat(workflow.getConditions("resolve")).isEmpty();
- }
-
- @Test
- public void keepCacheOfProjectPropertiesRequiredByConditions() {
- Workflow workflow = new Workflow();
- Condition condition1 = new HasProjectPropertyCondition("jira.url");
- Condition condition2 = new HasProjectPropertyCondition("jira.login");
- workflow.addCommand("create-jira-issue");
- workflow.addCondition("create-jira-issue", condition1);
- workflow.addCondition("create-jira-issue", condition2);
-
- assertThat(workflow.getProjectPropertyKeys()).containsExactly("jira.url", "jira.login");
- }
-
- @Test
- public void cacheOfProjectPropertiesIsNotNull() {
- Workflow workflow = new Workflow();
-
- assertThat(workflow.getProjectPropertyKeys()).isEmpty();
- }
-
- @Test
- public void keepFastLinksToReviewAndContextConditions() {
- Workflow workflow = new Workflow();
- workflow.addCommand("create-jira-issue");
- Condition contextCondition = new HasProjectPropertyCondition("jira.url");
- workflow.addCondition("create-jira-issue", contextCondition);
- Condition reviewCondition = new StatusCondition("OPEN");
- workflow.addCondition("create-jira-issue", reviewCondition);
-
- assertThat(workflow.getContextConditions("create-jira-issue")).containsExactly(contextCondition);
- assertThat(workflow.getReviewConditions("create-jira-issue")).containsExactly(reviewCondition);
- }
-
- @Test
- public void addFunction() {
- Workflow workflow = new Workflow();
- workflow.addCommand("resolve");
-
- Function function = new CommentFunction();
- workflow.addFunction("resolve", function);
-
- assertThat(workflow.getFunctions("resolve")).containsExactly(function);
- }
-
- @Test
- public void getFunctions_empty() {
- Workflow workflow = new Workflow();
- assertThat(workflow.getFunctions("resolve")).isEmpty();
- }
-
- @Test
- public void addFunction_fail_if_unknown_command() {
- thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("Unknown command: resolve");
-
- Workflow workflow = new Workflow();
- workflow.addFunction("resolve", new CommentFunction());
- }
-
- @Test
- public void setScreen_fail_if_unknown_command() {
- thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("Unknown command: resolve");
-
- Workflow workflow = new Workflow();
- workflow.setScreen("resolve", new CommentScreen());
- }
-
- @Test
- public void setScreen() {
- Workflow workflow = new Workflow();
- workflow.addCommand("resolve");
- CommentScreen screen = new CommentScreen();
- workflow.setScreen("resolve", screen);
-
- assertThat(workflow.getScreen("resolve")).isSameAs(screen);
- assertThat(workflow.getScreensByCommand()).includes(MapAssert.entry("resolve", screen));
- assertThat(workflow.getScreensByCommand()).hasSize(1);
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.condition;
-
-import org.junit.Test;
-import org.sonar.core.review.workflow.review.DefaultReview;
-import org.sonar.core.review.workflow.review.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();
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.condition;
-
-import org.junit.Test;
-import org.sonar.core.review.workflow.review.Review;
-import org.sonar.core.review.workflow.review.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();
- }
-
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.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");
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.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.core.review.workflow.review.DefaultReview;
-import org.sonar.core.review.workflow.review.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 {
-
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.condition;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.core.review.workflow.review.DefaultReview;
-import org.sonar.core.review.workflow.review.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("");
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.condition;
-
-import org.junit.Test;
-import org.sonar.core.review.workflow.review.DefaultReview;
-import org.sonar.core.review.workflow.review.DefaultWorkflowContext;
-import org.sonar.core.review.workflow.review.Review;
-import org.sonar.core.review.workflow.review.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;
- }
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.condition;
-
-import org.junit.Test;
-import org.sonar.core.review.workflow.review.Review;
-import org.sonar.core.review.workflow.review.WorkflowContext;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class ProjectPropertyConditionTest {
- @Test
- public void getPropertyKey() {
- ProjectPropertyCondition condition = new ProjectPropertyCondition("foo") {
- @Override
- public boolean doVerify(Review review, WorkflowContext context) {
- return false;
- }
- };
- assertThat(condition.getPropertyKey()).isEqualTo("foo");
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.condition;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.core.review.workflow.review.DefaultReview;
-import org.sonar.core.review.workflow.review.DefaultWorkflowContext;
-import org.sonar.core.review.workflow.review.Review;
-
-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();
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.condition;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.core.review.workflow.review.DefaultReview;
-import org.sonar.core.review.workflow.review.DefaultWorkflowContext;
-import org.sonar.core.review.workflow.review.Review;
-
-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();
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.function;
-
-import com.google.common.collect.Maps;
-import org.junit.Test;
-import org.sonar.core.review.workflow.review.Comment;
-import org.sonar.core.review.workflow.review.DefaultReview;
-import org.sonar.core.review.workflow.review.DefaultWorkflowContext;
-
-import java.util.List;
-import java.util.Map;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class CommentFunctionTest {
- @Test
- public void setTextAndUserId() {
- CommentFunction function = new CommentFunction();
- Map<String, String> parameters = Maps.newHashMap();
- parameters.put("text", "foo");
- DefaultReview review = new DefaultReview();
- DefaultWorkflowContext context = new DefaultWorkflowContext();
- context.setUserId(1234L);
-
- function.doExecute(review, new DefaultReview(), context, parameters);
-
- List<Comment> newComments = review.getNewComments();
- assertThat(newComments).hasSize(1);
- assertThat(newComments.get(0).getMarkdownText()).isEqualTo("foo");
- assertThat(newComments.get(0).getUserId()).isEqualTo(1234L);
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.screen;
-
-import org.junit.Test;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class CommentScreenTest {
- @Test
- public void testCommentScreen() {
- CommentScreen screen = new CommentScreen();
-
- assertThat(screen.getKey()).isEqualTo("comment");
-
- assertThat(screen.getCommandKey()).isNull();
- assertThat(screen.setCommandKey("create-jira-issue"));
- assertThat(screen.getCommandKey()).isEqualTo("create-jira-issue");
- }
-}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.workflow;
+
+import org.junit.Test;
+import org.sonar.api.utils.DateUtils;
+import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.api.workflow.Comment;
+import org.sonar.api.workflow.internal.DefaultReview;
+import org.sonar.core.workflow.ReviewDatabaseStore;
+
+import java.util.Date;
+
+public class ReviewDatabaseStoreTest extends DaoTestCase {
+
+ @Test
+ public void store() {
+ setupData("store");
+ ReviewDatabaseStore store = new ReviewDatabaseStore(getMyBatis());
+ DefaultReview review = new DefaultReview().setReviewId(1234L);
+ review.setStatus("CLOSED");
+ review.setResolution("RESOLVED");
+ review.setProperty("who", "me");
+ review.setProperty("why", "because");
+ Comment comment = review.createComment();
+ comment.setMarkdownText("this is a comment");
+ comment.setUserId(555L);
+
+ Date now = DateUtils.parseDate("2012-05-18");
+ store.store(review, now);
+
+ checkTables("store", "reviews");
+ checkTables("store", new String[]{"id"}, "review_comments");
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.workflow;
+
+import com.google.common.collect.ListMultimap;
+import com.google.common.collect.Maps;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.config.Settings;
+import org.sonar.api.workflow.internal.DefaultWorkflow;
+import org.sonar.api.workflow.Review;
+import org.sonar.api.workflow.WorkflowContext;
+import org.sonar.api.workflow.condition.Condition;
+import org.sonar.api.workflow.condition.HasProjectPropertyCondition;
+import org.sonar.api.workflow.function.Function;
+import org.sonar.api.workflow.internal.DefaultReview;
+import org.sonar.api.workflow.internal.DefaultWorkflowContext;
+import org.sonar.api.workflow.screen.CommentScreen;
+import org.sonar.api.workflow.screen.Screen;
+import org.sonar.core.workflow.ImmutableReview;
+import org.sonar.core.workflow.ReviewStore;
+import org.sonar.core.workflow.WorkflowEngine;
+
+import java.util.List;
+import java.util.Map;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItem;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.*;
+
+public class WorkflowEngineTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void listAvailableScreensForReview_empty() {
+ WorkflowEngine engine = new WorkflowEngine(new DefaultWorkflow(), mock(ReviewStore.class), new Settings());
+ List<Screen> screens = engine.listAvailableScreens(new DefaultReview(), new DefaultWorkflowContext(), true);
+ assertThat(screens).isEmpty();
+ }
+
+ @Test
+ public void listAvailableScreensForReview() {
+ DefaultWorkflow workflow = new DefaultWorkflow();
+ workflow.addCommand("command-without-screen");
+ workflow.addCommand("resolve");
+ CommentScreen screen = new CommentScreen();
+ workflow.setScreen("resolve", screen);
+
+ WorkflowEngine engine = new WorkflowEngine(workflow, mock(ReviewStore.class), new Settings());
+ List<Screen> screens = engine.listAvailableScreens(new DefaultReview(), new DefaultWorkflowContext(), true);
+ assertThat(screens).containsExactly(screen);
+ }
+
+ @Test
+ public void listAvailableScreensForReview_verify_conditions() {
+ DefaultWorkflow workflow = new DefaultWorkflow();
+ workflow.addCommand("resolve");
+ Condition condition = mock(Condition.class);
+ when(condition.doVerify(any(Review.class), any(WorkflowContext.class))).thenReturn(false);
+ workflow.addCondition("resolve", condition);
+ workflow.setScreen("resolve", new CommentScreen());
+
+ WorkflowEngine engine = new WorkflowEngine(workflow, mock(ReviewStore.class), new Settings());
+ DefaultReview review = new DefaultReview();
+ DefaultWorkflowContext context = new DefaultWorkflowContext();
+ assertThat(engine.listAvailableScreens(review, context, true)).isEmpty();
+
+ verify(condition).doVerify(review, context);
+ }
+
+ @Test
+ public void listAvailableScreensForReviews_empty() {
+ WorkflowEngine engine = new WorkflowEngine(new DefaultWorkflow(), mock(ReviewStore.class), new Settings());
+ ListMultimap<Long, Screen> screens = engine.listAvailableScreens(
+ new DefaultReview[]{new DefaultReview().setViolationId(1000L), new DefaultReview().setViolationId(2000L)},
+ new DefaultWorkflowContext(), true);
+ assertThat(screens.size()).isEqualTo(0);
+ }
+
+ @Test
+ public void listAvailableScreensForReviews() {
+ DefaultWorkflow workflow = new DefaultWorkflow();
+ workflow.addCommand("command-without-screen");
+ workflow.addCommand("resolve");
+ CommentScreen screen = new CommentScreen();
+ workflow.setScreen("resolve", screen);
+ WorkflowEngine engine = new WorkflowEngine(workflow, mock(ReviewStore.class), new Settings());
+ ListMultimap<Long, Screen> screens = engine.listAvailableScreens(
+ new DefaultReview[]{new DefaultReview().setViolationId(1000L), new DefaultReview().setViolationId(2000L)},
+ new DefaultWorkflowContext(), true);
+ assertThat(screens.size()).isEqualTo(2);
+ assertThat(screens.get(1000L)).containsExactly(screen);
+ assertThat(screens.get(2000L)).containsExactly(screen);
+ }
+
+ @Test
+ public void listAvailableScreensForReviews_load_project_properties() {
+ DefaultWorkflow workflow = new DefaultWorkflow();
+ workflow.addCommand("resolve");
+ workflow.addCondition("resolve", new HasProjectPropertyCondition("foo"));
+
+ ReviewStore store = mock(ReviewStore.class);
+ WorkflowEngine engine = new WorkflowEngine(workflow, store, new Settings());
+
+ engine.listAvailableScreens(
+ new DefaultReview[]{new DefaultReview().setViolationId(1000L), new DefaultReview().setViolationId(2000L)},
+ new DefaultWorkflowContext().setProjectId(300L),
+ true);
+
+ verify(store).completeProjectSettings(eq(300L), any(Settings.class), (List<String>) argThat(hasItem("foo")));
+ }
+
+ @Test
+ public void execute_conditions_pass() {
+ DefaultWorkflow workflow = new DefaultWorkflow();
+ workflow.addCommand("resolve");
+ workflow.addCondition("resolve", new HasProjectPropertyCondition("foo"));
+ Function function = mock(Function.class);
+ workflow.addFunction("resolve", function);
+
+ ReviewStore store = mock(ReviewStore.class);
+ Settings settings = new Settings();
+ settings.setProperty("foo", "bar");
+ WorkflowEngine engine = new WorkflowEngine(workflow, store, settings);
+
+ DefaultReview review = new DefaultReview().setViolationId(1000L);
+ Map<String, String> parameters = Maps.newHashMap();
+ DefaultWorkflowContext context = new DefaultWorkflowContext().setProjectId(300L);
+
+ engine.execute("resolve", review, context, parameters);
+
+ verify(store).completeProjectSettings(eq(300L), any(Settings.class), (List<String>) argThat(hasItem("foo")));
+ verify(function).doExecute(eq(review), any(ImmutableReview.class), eq(context), eq(parameters));
+ }
+
+ @Test
+ public void execute_fail_if_conditions_dont_pass() {
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("Condition is not respected: Property foo must be set");
+
+ DefaultWorkflow workflow = new DefaultWorkflow();
+ workflow.addCommand("resolve");
+ workflow.addCondition("resolve", new HasProjectPropertyCondition("foo"));
+ Function function = mock(Function.class);
+ workflow.addFunction("resolve", function);
+
+ ReviewStore store = mock(ReviewStore.class);
+ Settings settings = new Settings();// missing property 'foo'
+ WorkflowEngine engine = new WorkflowEngine(workflow, store, settings);
+
+ DefaultReview review = new DefaultReview().setViolationId(1000L);
+ Map<String, String> parameters = Maps.newHashMap();
+ DefaultWorkflowContext context = new DefaultWorkflowContext().setProjectId(300L);
+
+ engine.execute("resolve", review, context, parameters);
+ }
+}
+++ /dev/null
-<dataset>
-
- <reviews
- id="1234"
- rule_failure_permanent_id="1"
- created_at="2012-01-01"
- project_id="20"
- title="[null]"
- resource_line="200"
- severity="BLOCKER"
- user_id="300"
- assignee_id="33"
- resource_id="400"
- rule_id="500"
- manual_violation="[true]"
- manual_severity="[false]"
-
- updated_at="2012-05-18"
- status="CLOSED"
- resolution="RESOLVED"
- data="who=me;why=because"
- />
-
- <review_comments
- review_id="1234"
- user_id="555"
- review_text="this is a comment"
- created_at="2012-05-18"
- updated_at="2012-05-18"
- />
-</dataset>
+++ /dev/null
-<dataset>
-
- <reviews
- id="1234"
- rule_failure_permanent_id="1"
- created_at="2012-01-01"
- project_id="20"
- title="[null]"
- resource_line="200"
- severity="BLOCKER"
- user_id="300"
- assignee_id="33"
- resource_id="400"
- rule_id="500"
- manual_violation="[true]"
- manual_severity="[false]"
-
- updated_at="[null]"
- status="OPEN"
- resolution="[null]"
- data="[null]"
- />
-
-</dataset>
--- /dev/null
+<dataset>
+
+ <reviews
+ id="1234"
+ rule_failure_permanent_id="1"
+ created_at="2012-01-01"
+ project_id="20"
+ title="[null]"
+ resource_line="200"
+ severity="BLOCKER"
+ user_id="300"
+ assignee_id="33"
+ resource_id="400"
+ rule_id="500"
+ manual_violation="[true]"
+ manual_severity="[false]"
+
+ updated_at="2012-05-18"
+ status="CLOSED"
+ resolution="RESOLVED"
+ data="who=me;why=because"
+ />
+
+ <review_comments
+ review_id="1234"
+ user_id="555"
+ review_text="this is a comment"
+ created_at="2012-05-18"
+ updated_at="2012-05-18"
+ />
+</dataset>
--- /dev/null
+<dataset>
+
+ <reviews
+ id="1234"
+ rule_failure_permanent_id="1"
+ created_at="2012-01-01"
+ project_id="20"
+ title="[null]"
+ resource_line="200"
+ severity="BLOCKER"
+ user_id="300"
+ assignee_id="33"
+ resource_id="400"
+ rule_id="500"
+ manual_violation="[true]"
+ manual_severity="[false]"
+
+ updated_at="[null]"
+ status="OPEN"
+ resolution="[null]"
+ data="[null]"
+ />
+
+</dataset>
}
/**
- * A column can be based on the varation of a value rather than on the value itself.
+ * A column can be based on the variation of a value rather than on the value itself.
*
* @return <code>true</code> when the variation is used rather than the value
*/
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.workflow;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * @since 3.1
+ */
+@Beta
+public interface Comment {
+ String getMarkdownText();
+
+ Long getUserId();
+
+ Comment setMarkdownText(String s);
+
+ Comment setUserId(Long l);
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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<Comment> getNewComments();
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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<String, String> 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();
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.workflow;
+
+import com.google.common.annotations.Beta;
+import org.sonar.api.ServerComponent;
+import org.sonar.api.workflow.condition.Condition;
+import org.sonar.api.workflow.function.Function;
+import org.sonar.api.workflow.screen.Screen;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Experimental component to customize the actions that can be
+ * executed on reviews.
+ *
+ * @since 3.1
+ */
+@Beta
+public interface Workflow extends ServerComponent {
+ Workflow addCommand(String key);
+
+ Set<String> getCommands();
+
+ List<Condition> getConditions(String commandKey);
+
+ Workflow addCondition(String commandKey, Condition condition);
+
+ List<Function> getFunctions(String commandKey);
+
+ Workflow addFunction(String commandKey, Function function);
+
+ Screen getScreen(String commandKey);
+
+ Workflow setScreen(String commandKey, Screen screen);
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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();
+
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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();
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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);
+
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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);
+ }
+
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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";
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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));
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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;
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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;
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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<String> resolutions;
+
+ public ResolutionCondition(Set<String> 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<String> getResolutions() {
+ return ImmutableSet.copyOf(resolutions);
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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<String> statuses;
+
+ public StatusCondition(Set<String> 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<String> getStatuses() {
+ return ImmutableSet.copyOf(statuses);
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.api.workflow.condition;
+
+import javax.annotation.ParametersAreNonnullByDefault;
\ No newline at end of file
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.workflow.function;
+
+import com.google.common.annotations.Beta;
+import org.sonar.api.workflow.Comment;
+import org.sonar.api.workflow.MutableReview;
+import org.sonar.api.workflow.Review;
+import org.sonar.api.workflow.WorkflowContext;
+
+import java.util.Map;
+
+/**
+ * @since 3.1
+ */
+@Beta
+public final class CommentFunction extends Function {
+
+ @Override
+ public void doExecute(MutableReview review, Review initialReview, WorkflowContext context, Map<String, String> parameters) {
+ Comment comment = review.createComment();
+ comment.setMarkdownText(parameters.get("text"));
+ comment.setUserId(context.getUserId());
+ }
+
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.workflow.function;
+
+import com.google.common.annotations.Beta;
+import org.sonar.api.workflow.MutableReview;
+import org.sonar.api.workflow.Review;
+import org.sonar.api.workflow.WorkflowContext;
+
+import java.util.Map;
+
+/**
+ * Functions perform actions when the command is executed, e.g.:
+ *
+ * <ul>
+ * <li>Assign the issue to a particular user (not yet implemented)</li>
+ * <li>Add a comment</li>
+ * <li>Set a review property</li>
+ * </ul>
+ *
+ * @since 3.1
+ */
+@Beta
+public abstract class Function {
+
+ /**
+ * This method is executed when all the conditions pass.
+ *
+ * @param review the review that can be changed
+ * @param initialReview the read-only review as stated before execution of functions
+ * @param context information about the user who executed the command and about project
+ * @param parameters the command parameters sent by end user, generally from forms displayed in screens
+ */
+ public abstract void doExecute(MutableReview review, Review initialReview, WorkflowContext context, Map<String, String> parameters);
+
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.api.workflow.function;
+
+import javax.annotation.ParametersAreNonnullByDefault;
\ No newline at end of file
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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();
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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<String, String> properties;
+ private List<Comment> 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<String, String> getProperties() {
+ if (properties == null) {
+ return Collections.emptyMap();
+ }
+ return properties;
+ }
+
+ public DefaultReview setProperties(Map<String, String> 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<Comment> 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
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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.*;
+import org.sonar.api.workflow.Workflow;
+import org.sonar.api.workflow.condition.Condition;
+import org.sonar.api.workflow.condition.ProjectPropertyCondition;
+import org.sonar.api.workflow.function.Function;
+import org.sonar.api.workflow.screen.Screen;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @since 3.1
+ */
+@Beta
+public final class DefaultWorkflow implements Workflow {
+
+ private Set<String> commands = Sets.newLinkedHashSet();
+ private ListMultimap<String, Condition> conditionsByCommand = ArrayListMultimap.create();
+ private ListMultimap<String, Function> functionsByCommand = ArrayListMultimap.create();
+ private Map<String, Screen> screensByCommand = Maps.newLinkedHashMap();
+
+ /**
+ * Keys of all the properties that are required by conditions (see {@link org.sonar.api.workflow.condition.ProjectPropertyCondition}
+ */
+ private List<String> projectPropertyKeys = Lists.newArrayList();
+
+ /**
+ * Optimization: fast way to get all context conditions
+ */
+ private ListMultimap<String, Condition> contextConditionsByCommand = ArrayListMultimap.create();
+
+ /**
+ * Optimization: fast way to get all review conditions
+ */
+ private ListMultimap<String, Condition> reviewConditionsByCommand = ArrayListMultimap.create();
+
+
+ public Workflow addCommand(String key) {
+ Preconditions.checkArgument(!Strings.isNullOrEmpty(key), "Empty command key");
+ commands.add(key);
+ return this;
+ }
+
+ public Set<String> getCommands() {
+ return commands;
+ }
+
+ public boolean hasCommand(String key) {
+ return commands.contains(key);
+ }
+
+ public List<String> getProjectPropertyKeys() {
+ return projectPropertyKeys;
+ }
+
+ /**
+ * Shortcut for: getReviewConditions(commandKey) + getContextConditions(commandKey)
+ */
+ public List<Condition> getConditions(String commandKey) {
+ return conditionsByCommand.get(commandKey);
+ }
+
+ public List<Condition> getReviewConditions(String commandKey) {
+ return reviewConditionsByCommand.get(commandKey);
+ }
+
+ public List<Condition> getContextConditions(String commandKey) {
+ return contextConditionsByCommand.get(commandKey);
+ }
+
+ public Workflow addCondition(String commandKey, Condition condition) {
+ Preconditions.checkArgument(hasCommand(commandKey), "Unknown command: " + commandKey);
+ Preconditions.checkNotNull(condition);
+ conditionsByCommand.put(commandKey, condition);
+ if (condition instanceof ProjectPropertyCondition) {
+ projectPropertyKeys.add(((ProjectPropertyCondition) condition).getPropertyKey());
+ }
+ if (condition.isOnContext()) {
+ contextConditionsByCommand.put(commandKey, condition);
+ } else {
+ reviewConditionsByCommand.put(commandKey, condition);
+ }
+ return this;
+ }
+
+ public List<Function> getFunctions(String commandKey) {
+ return functionsByCommand.get(commandKey);
+ }
+
+ public Workflow addFunction(String commandKey, Function function) {
+ Preconditions.checkArgument(hasCommand(commandKey), "Unknown command: " + commandKey);
+ Preconditions.checkNotNull(function);
+ functionsByCommand.put(commandKey, function);
+ return this;
+ }
+
+ public Screen getScreen(String commandKey) {
+ return screensByCommand.get(commandKey);
+ }
+
+ public Workflow setScreen(String commandKey, Screen screen) {
+ Preconditions.checkArgument(hasCommand(commandKey), "Unknown command: " + commandKey);
+ Preconditions.checkNotNull(screen);
+ Preconditions.checkState(Strings.isNullOrEmpty(screen.getCommandKey()), "Screen is already associated with command: " + screen.getCommandKey());
+ screen.setCommandKey(commandKey);
+ screensByCommand.put(commandKey, screen);
+ return this;
+ }
+
+ public Map<String, Screen> getScreensByCommand() {
+ return screensByCommand;
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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();
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+
+/**
+ This package is not considered as API and future versions can break backward-compatibility.
+ <p>
+ It provides some classes that can be helpful for unit tests but must
+ <b>ABSOLUTELY NOT</b> be used by plugins production code.
+ </p>
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.api.workflow.internal;
+
+import javax.annotation.ParametersAreNonnullByDefault;
\ No newline at end of file
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.api.workflow;
+
+import javax.annotation.ParametersAreNonnullByDefault;
\ No newline at end of file
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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");
+ }
+
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.workflow.screen;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * <h2>Localization</h2>
+ * <p>At least two buttons must have labels :</p>
+ * <ul>
+ * <li>the button in the violation toolbar that displays the form screen. Key is 'reviews.command.<command_key>.button'.</li>
+ * <li>the button in the form screen that submits the command. Key is 'reviews.command.<command_key>.submit'.</li>
+ * </ul>
+ * @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;
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.api.workflow.screen;
+
+import javax.annotation.ParametersAreNonnullByDefault;
\ No newline at end of file
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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();
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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();
+ }
+
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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");
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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 {
+
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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("");
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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;
+ }
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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 ProjectPropertyConditionTest {
+ @Test
+ public void getPropertyKey() {
+ ProjectPropertyCondition condition = new ProjectPropertyCondition("foo") {
+ @Override
+ public boolean doVerify(Review review, WorkflowContext context) {
+ return false;
+ }
+ };
+ assertThat(condition.getPropertyKey()).isEqualTo("foo");
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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();
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+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();
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.workflow.function;
+
+import com.google.common.collect.Maps;
+import org.junit.Test;
+import org.sonar.api.workflow.Comment;
+import org.sonar.api.workflow.internal.DefaultReview;
+import org.sonar.api.workflow.internal.DefaultWorkflowContext;
+
+import java.util.List;
+import java.util.Map;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class CommentFunctionTest {
+ @Test
+ public void setTextAndUserId() {
+ CommentFunction function = new CommentFunction();
+ Map<String, String> parameters = Maps.newHashMap();
+ parameters.put("text", "foo");
+ DefaultReview review = new DefaultReview();
+ DefaultWorkflowContext context = new DefaultWorkflowContext();
+ context.setUserId(1234L);
+
+ function.doExecute(review, new DefaultReview(), context, parameters);
+
+ List<Comment> newComments = review.getNewComments();
+ assertThat(newComments).hasSize(1);
+ assertThat(newComments.get(0).getMarkdownText()).isEqualTo("foo");
+ assertThat(newComments.get(0).getUserId()).isEqualTo(1234L);
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.workflow.internal;
+
+import org.fest.assertions.MapAssert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.workflow.Workflow;
+import org.sonar.api.workflow.condition.Condition;
+import org.sonar.api.workflow.condition.HasProjectPropertyCondition;
+import org.sonar.api.workflow.condition.StatusCondition;
+import org.sonar.api.workflow.function.CommentFunction;
+import org.sonar.api.workflow.function.Function;
+import org.sonar.api.workflow.screen.CommentScreen;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DefaultWorkflowTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void addCommand() {
+ DefaultWorkflow workflow = new DefaultWorkflow();
+ assertThat(workflow.getCommands()).isEmpty();
+
+ assertThat(workflow.addCommand("resolve")).isSameAs(workflow);
+ assertThat(workflow.getCommands()).containsOnly("resolve");
+ assertThat(workflow.hasCommand("resolve")).isTrue();
+ }
+
+ @Test
+ public void addCommand_does_not_accept_blank() {
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage("Empty command key");
+
+ Workflow workflow = new DefaultWorkflow();
+ workflow.addCommand("");
+ }
+
+ @Test
+ public void addSeveralTimesTheSameCommand() {
+ Workflow workflow = new DefaultWorkflow();
+ workflow.addCommand("resolve");
+ workflow.addCommand("resolve");
+ assertThat(workflow.getCommands()).containsOnly("resolve");
+ assertThat(workflow.getCommands()).hasSize(1);
+ }
+
+ @Test
+ public void addCondition_fail_if_unknown_command() {
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage("Unknown command: resolve");
+
+ Workflow workflow = new DefaultWorkflow();
+ workflow.addCondition("resolve", new StatusCondition("OPEN"));
+ }
+
+ @Test
+ public void addCondition() {
+ Workflow workflow = new DefaultWorkflow();
+ Condition condition = new StatusCondition("OPEN");
+ workflow.addCommand("resolve");
+
+ workflow.addCondition("resolve", condition);
+
+ assertThat(workflow.getConditions("resolve")).containsExactly(condition);
+ }
+
+ @Test
+ public void getConditions_empty() {
+ Workflow workflow = new DefaultWorkflow();
+ assertThat(workflow.getConditions("resolve")).isEmpty();
+ }
+
+ @Test
+ public void keepCacheOfProjectPropertiesRequiredByConditions() {
+ DefaultWorkflow workflow = new DefaultWorkflow();
+ Condition condition1 = new HasProjectPropertyCondition("jira.url");
+ Condition condition2 = new HasProjectPropertyCondition("jira.login");
+ workflow.addCommand("create-jira-issue");
+ workflow.addCondition("create-jira-issue", condition1);
+ workflow.addCondition("create-jira-issue", condition2);
+
+ assertThat(workflow.getProjectPropertyKeys()).containsExactly("jira.url", "jira.login");
+ }
+
+ @Test
+ public void cacheOfProjectPropertiesIsNotNull() {
+ DefaultWorkflow workflow = new DefaultWorkflow();
+
+ assertThat(workflow.getProjectPropertyKeys()).isEmpty();
+ }
+
+ @Test
+ public void keepFastLinksToReviewAndContextConditions() {
+ DefaultWorkflow workflow = new DefaultWorkflow();
+ workflow.addCommand("create-jira-issue");
+ Condition contextCondition = new HasProjectPropertyCondition("jira.url");
+ workflow.addCondition("create-jira-issue", contextCondition);
+ Condition reviewCondition = new StatusCondition("OPEN");
+ workflow.addCondition("create-jira-issue", reviewCondition);
+
+ assertThat(workflow.getContextConditions("create-jira-issue")).containsExactly(contextCondition);
+ assertThat(workflow.getReviewConditions("create-jira-issue")).containsExactly(reviewCondition);
+ }
+
+ @Test
+ public void addFunction() {
+ Workflow workflow = new DefaultWorkflow();
+ workflow.addCommand("resolve");
+
+ Function function = new CommentFunction();
+ workflow.addFunction("resolve", function);
+
+ assertThat(workflow.getFunctions("resolve")).containsExactly(function);
+ }
+
+ @Test
+ public void getFunctions_empty() {
+ Workflow workflow = new DefaultWorkflow();
+ assertThat(workflow.getFunctions("resolve")).isEmpty();
+ }
+
+ @Test
+ public void addFunction_fail_if_unknown_command() {
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage("Unknown command: resolve");
+
+ Workflow workflow = new DefaultWorkflow();
+ workflow.addFunction("resolve", new CommentFunction());
+ }
+
+ @Test
+ public void setScreen_fail_if_unknown_command() {
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage("Unknown command: resolve");
+
+ Workflow workflow = new DefaultWorkflow();
+ workflow.setScreen("resolve", new CommentScreen());
+ }
+
+ @Test
+ public void setScreen() {
+ DefaultWorkflow workflow = new DefaultWorkflow();
+ workflow.addCommand("resolve");
+ CommentScreen screen = new CommentScreen();
+ workflow.setScreen("resolve", screen);
+
+ assertThat(workflow.getScreen("resolve")).isSameAs(screen);
+ assertThat(workflow.getScreensByCommand()).includes(MapAssert.entry("resolve", screen));
+ assertThat(workflow.getScreensByCommand()).hasSize(1);
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.workflow.screen;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class CommentScreenTest {
+ @Test
+ public void testCommentScreen() {
+ CommentScreen screen = new CommentScreen();
+
+ assertThat(screen.getKey()).isEqualTo("comment");
+
+ assertThat(screen.getCommandKey()).isNull();
+ assertThat(screen.setCommandKey("create-jira-issue"));
+ assertThat(screen.getCommandKey()).isEqualTo("create-jira-issue");
+ }
+}
*/
package org.sonar.server.platform;
+import org.sonar.api.workflow.internal.DefaultWorkflow;
import org.sonar.server.startup.RegisterNewFilters;
import org.apache.commons.configuration.BaseConfiguration;
import org.sonar.core.notification.DefaultNotificationManager;
import org.sonar.core.persistence.*;
import org.sonar.core.qualitymodel.DefaultModelFinder;
-import org.sonar.core.review.workflow.ReviewDatabaseStore;
-import org.sonar.core.review.workflow.WorkflowEngine;
-import org.sonar.core.review.workflow.Workflow;
+import org.sonar.core.workflow.ReviewDatabaseStore;
+import org.sonar.core.workflow.WorkflowEngine;
import org.sonar.core.rule.DefaultRuleFinder;
import org.sonar.core.user.DefaultUserFinder;
import org.sonar.jpa.dao.MeasuresDao;
ServerExtensionInstaller extensionRegistrar = servicesContainer.getComponentByType(ServerExtensionInstaller.class);
extensionRegistrar.registerExtensions(servicesContainer);
- servicesContainer.addSingleton(Workflow.class);
+ servicesContainer.addSingleton(DefaultWorkflow.class);
servicesContainer.addSingleton(ReviewDatabaseStore.class);
servicesContainer.addSingleton(WorkflowEngine.class);
import org.sonar.core.persistence.DatabaseMigrator;
import org.sonar.core.purge.PurgeDao;
import org.sonar.core.resource.ResourceIndexerDao;
-import org.sonar.core.review.workflow.WorkflowEngine;
-import org.sonar.core.review.workflow.review.DefaultReview;
-import org.sonar.core.review.workflow.review.DefaultWorkflowContext;
-import org.sonar.core.review.workflow.review.Review;
-import org.sonar.core.review.workflow.screen.Screen;
+import org.sonar.core.workflow.WorkflowEngine;
+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.screen.Screen;
import org.sonar.markdown.Markdown;
import org.sonar.server.configuration.Backup;
import org.sonar.server.configuration.ProfilesManager;
class Api::ReviewContext
def initialize(options={})
- @review = options[:review]
+ @review = options[:workflow]
@project = options[:project]
@user = options[:user]
@params = options[:params]
end
def self.to_java_workflow_review(violation)
- java_review=Java::OrgSonarCoreReviewWorkflowReview::DefaultReview.new
+ java_review=Java::OrgSonarApiWorkflowInternal::DefaultReview.new
java_review.setViolationId(violation.id)
java_review.setSeverity(violation.severity.to_s)
java_review.setRuleKey(violation.rule.plugin_rule_key)
end
def self.to_java_workflow_context(project, user)
- java_context = Java::OrgSonarCoreReviewWorkflowReview::DefaultWorkflowContext.new
+ java_context = Java::OrgSonarApiWorkflowInternal::DefaultWorkflowContext.new
java_context.setUserId(user.id)
java_context.setUserLogin(user.login)
java_context.setUserName(user.name)
# hack in case 'error_message' is nil (this should disappear when refactoring the '_view' and '_review' partials)
error_message = error_message
%>
- <%= render :partial => 'project_reviews/review', :locals => {:review => @review, :error_message => error_message} -%>
+ <%= render :partial => 'project_reviews/review', :locals => {:workflow => @review, :error_message => error_message} -%>
</div>