]> source.dussan.org Git - sonarqube.git/commitdiff
Extract beta api from review workflow
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 28 May 2012 21:10:10 +0000 (23:10 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 28 May 2012 21:48:50 +0000 (23:48 +0200)
103 files changed:
sonar-core/src/main/java/org/sonar/core/review/package-info.java
sonar-core/src/main/java/org/sonar/core/review/workflow/ReviewDatabaseStore.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/ReviewStore.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/SampleWorkflowBuilder.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/Workflow.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/WorkflowEngine.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/condition/AdminRoleCondition.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/condition/Condition.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/condition/Conditions.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasProjectPropertyCondition.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasReviewPropertyCondition.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/condition/NotCondition.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/condition/ProjectPropertyCondition.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/condition/ResolutionCondition.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/condition/StatusCondition.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/condition/package-info.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/function/CommentFunction.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/function/Function.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/function/package-info.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/package-info.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/review/Comment.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/review/DefaultComment.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/review/DefaultReview.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/review/DefaultWorkflowContext.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/review/ImmutableReview.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/review/MutableReview.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/review/Review.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/review/WorkflowContext.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/review/package-info.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/screen/CommentScreen.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/screen/Screen.java [deleted file]
sonar-core/src/main/java/org/sonar/core/review/workflow/screen/package-info.java [deleted file]
sonar-core/src/main/java/org/sonar/core/workflow/ImmutableReview.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/workflow/ReviewDatabaseStore.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/workflow/ReviewStore.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/workflow/WorkflowEngine.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/workflow/package-info.java [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/review/workflow/ReviewDatabaseStoreTest.java [deleted file]
sonar-core/src/test/java/org/sonar/core/review/workflow/SampleWorkflowBuilderTest.java [deleted file]
sonar-core/src/test/java/org/sonar/core/review/workflow/WorkflowEngineTest.java [deleted file]
sonar-core/src/test/java/org/sonar/core/review/workflow/WorkflowTest.java [deleted file]
sonar-core/src/test/java/org/sonar/core/review/workflow/condition/AdminRoleConditionTest.java [deleted file]
sonar-core/src/test/java/org/sonar/core/review/workflow/condition/ConditionTest.java [deleted file]
sonar-core/src/test/java/org/sonar/core/review/workflow/condition/ConditionsTest.java [deleted file]
sonar-core/src/test/java/org/sonar/core/review/workflow/condition/HasProjectPropertyConditionTest.java [deleted file]
sonar-core/src/test/java/org/sonar/core/review/workflow/condition/HasReviewPropertyConditionTest.java [deleted file]
sonar-core/src/test/java/org/sonar/core/review/workflow/condition/NotConditionTest.java [deleted file]
sonar-core/src/test/java/org/sonar/core/review/workflow/condition/ProjectPropertyConditionTest.java [deleted file]
sonar-core/src/test/java/org/sonar/core/review/workflow/condition/ResolutionConditionTest.java [deleted file]
sonar-core/src/test/java/org/sonar/core/review/workflow/condition/StatusConditionTest.java [deleted file]
sonar-core/src/test/java/org/sonar/core/review/workflow/function/CommentFunctionTest.java [deleted file]
sonar-core/src/test/java/org/sonar/core/review/workflow/screen/CommentScreenTest.java [deleted file]
sonar-core/src/test/java/org/sonar/core/workflow/ReviewDatabaseStoreTest.java [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/workflow/WorkflowEngineTest.java [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/review/workflow/ReviewDatabaseStoreTest/store-result.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/review/workflow/ReviewDatabaseStoreTest/store.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/workflow/ReviewDatabaseStoreTest/store-result.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/workflow/ReviewDatabaseStoreTest/store.xml [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/web/FilterColumn.java
sonar-plugin-api/src/main/java/org/sonar/api/workflow/Comment.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/MutableReview.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/Review.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/Workflow.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/WorkflowContext.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/AdminRoleCondition.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/Condition.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/Conditions.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/HasProjectPropertyCondition.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/HasReviewPropertyCondition.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/NotCondition.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/ProjectPropertyCondition.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/ResolutionCondition.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/StatusCondition.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/package-info.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/function/CommentFunction.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/function/Function.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/function/package-info.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultComment.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultReview.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultWorkflow.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultWorkflowContext.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/package-info.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/package-info.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/CommentScreen.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/Screen.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/package-info.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/AdminRoleConditionTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ConditionTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ConditionsTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/HasProjectPropertyConditionTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/HasReviewPropertyConditionTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/NotConditionTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ProjectPropertyConditionTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ResolutionConditionTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/StatusConditionTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/workflow/function/CommentFunctionTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/workflow/internal/DefaultWorkflowTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/workflow/screen/CommentScreenTest.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/platform/Platform.java
sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
sonar-server/src/main/webapp/WEB-INF/app/models/api/review_context.rb
sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb
sonar-server/src/main/webapp/WEB-INF/app/views/project_reviews/_view.html.erb

index 8e8e350ae15cf76f82d7a9e7e3dd02931309b850..b9180bc8ce96202767117ae27eb359a994db330e 100644 (file)
@@ -17,5 +17,7 @@
  * 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
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/ReviewDatabaseStore.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/ReviewDatabaseStore.java
deleted file mode 100644 (file)
index 9dd425e..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * 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);
-    }
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/ReviewStore.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/ReviewStore.java
deleted file mode 100644 (file)
index 3654097..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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);
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/SampleWorkflowBuilder.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/SampleWorkflowBuilder.java
deleted file mode 100644 (file)
index a6a89cc..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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());
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/Workflow.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/Workflow.java
deleted file mode 100644 (file)
index 3a4004e..0000000
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * 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;
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/WorkflowEngine.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/WorkflowEngine.java
deleted file mode 100644 (file)
index a73d42c..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * 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);
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/AdminRoleCondition.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/AdminRoleCondition.java
deleted file mode 100644 (file)
index 6868361..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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();
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/Condition.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/Condition.java
deleted file mode 100644 (file)
index f538687..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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);
-
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/Conditions.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/Conditions.java
deleted file mode 100644 (file)
index 2e3c1a1..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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);
-  }
-
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasProjectPropertyCondition.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasProjectPropertyCondition.java
deleted file mode 100644 (file)
index 046aedb..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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";
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasReviewPropertyCondition.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasReviewPropertyCondition.java
deleted file mode 100644 (file)
index a9922a9..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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));
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/NotCondition.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/NotCondition.java
deleted file mode 100644 (file)
index bdaba1b..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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;
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/ProjectPropertyCondition.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/ProjectPropertyCondition.java
deleted file mode 100644 (file)
index ae0e148..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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;
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/ResolutionCondition.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/ResolutionCondition.java
deleted file mode 100644 (file)
index b7750fa..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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);
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/StatusCondition.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/StatusCondition.java
deleted file mode 100644 (file)
index 5b443ee..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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);
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/package-info.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/package-info.java
deleted file mode 100644 (file)
index 06cd514..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * 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
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/function/CommentFunction.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/function/CommentFunction.java
deleted file mode 100644 (file)
index f9131b7..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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());
-  }
-
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/function/Function.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/function/Function.java
deleted file mode 100644 (file)
index 1f941d4..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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);
-
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/function/package-info.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/function/package-info.java
deleted file mode 100644 (file)
index 5c50525..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * 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
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/package-info.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/package-info.java
deleted file mode 100644 (file)
index 27652da..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * 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
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/review/Comment.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/review/Comment.java
deleted file mode 100644 (file)
index c648471..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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);
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/review/DefaultComment.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/review/DefaultComment.java
deleted file mode 100644 (file)
index 4702644..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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);
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/review/DefaultReview.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/review/DefaultReview.java
deleted file mode 100644 (file)
index 68989f0..0000000
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * 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;
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/review/DefaultWorkflowContext.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/review/DefaultWorkflowContext.java
deleted file mode 100644 (file)
index e8a1e3e..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * 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();
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/review/ImmutableReview.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/review/ImmutableReview.java
deleted file mode 100644 (file)
index 35c8f01..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * 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;
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/review/MutableReview.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/review/MutableReview.java
deleted file mode 100644 (file)
index 286254d..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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();
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/review/Review.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/review/Review.java
deleted file mode 100644 (file)
index 7cca22d..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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();
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/review/WorkflowContext.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/review/WorkflowContext.java
deleted file mode 100644 (file)
index 7c0f2fa..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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();
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/review/package-info.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/review/package-info.java
deleted file mode 100644 (file)
index 0e49d65..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * 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
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/screen/CommentScreen.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/screen/CommentScreen.java
deleted file mode 100644 (file)
index 6bb253c..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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");
-  }
-
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/screen/Screen.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/screen/Screen.java
deleted file mode 100644 (file)
index b37dbb3..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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;
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/screen/package-info.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/screen/package-info.java
deleted file mode 100644 (file)
index 25a1028..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * 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
diff --git a/sonar-core/src/main/java/org/sonar/core/workflow/ImmutableReview.java b/sonar-core/src/main/java/org/sonar/core/workflow/ImmutableReview.java
new file mode 100644 (file)
index 0000000..2194b53
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * 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;
+  }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/workflow/ReviewDatabaseStore.java b/sonar-core/src/main/java/org/sonar/core/workflow/ReviewDatabaseStore.java
new file mode 100644 (file)
index 0000000..81c6d0b
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * 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);
+    }
+  }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/workflow/ReviewStore.java b/sonar-core/src/main/java/org/sonar/core/workflow/ReviewStore.java
new file mode 100644 (file)
index 0000000..f5a6747
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * 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);
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/workflow/WorkflowEngine.java b/sonar-core/src/main/java/org/sonar/core/workflow/WorkflowEngine.java
new file mode 100644 (file)
index 0000000..450c949
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * 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);
+  }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/workflow/package-info.java b/sonar-core/src/main/java/org/sonar/core/workflow/package-info.java
new file mode 100644 (file)
index 0000000..c3d167a
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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
diff --git a/sonar-core/src/test/java/org/sonar/core/review/workflow/ReviewDatabaseStoreTest.java b/sonar-core/src/test/java/org/sonar/core/review/workflow/ReviewDatabaseStoreTest.java
deleted file mode 100644 (file)
index 0dbfa6a..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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");
-  }
-}
diff --git a/sonar-core/src/test/java/org/sonar/core/review/workflow/SampleWorkflowBuilderTest.java b/sonar-core/src/test/java/org/sonar/core/review/workflow/SampleWorkflowBuilderTest.java
deleted file mode 100644 (file)
index 285396c..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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);
-  }
-}
diff --git a/sonar-core/src/test/java/org/sonar/core/review/workflow/WorkflowEngineTest.java b/sonar-core/src/test/java/org/sonar/core/review/workflow/WorkflowEngineTest.java
deleted file mode 100644 (file)
index 29f86a9..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * 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);
-  }
-}
diff --git a/sonar-core/src/test/java/org/sonar/core/review/workflow/WorkflowTest.java b/sonar-core/src/test/java/org/sonar/core/review/workflow/WorkflowTest.java
deleted file mode 100644 (file)
index 00502cd..0000000
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * 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);
-  }
-}
diff --git a/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/AdminRoleConditionTest.java b/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/AdminRoleConditionTest.java
deleted file mode 100644 (file)
index f72c31c..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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();
-  }
-}
diff --git a/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/ConditionTest.java b/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/ConditionTest.java
deleted file mode 100644 (file)
index 9a3e74a..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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();
-  }
-
-}
diff --git a/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/ConditionsTest.java b/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/ConditionsTest.java
deleted file mode 100644 (file)
index a0ad857..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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");
-  }
-}
diff --git a/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/HasProjectPropertyConditionTest.java b/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/HasProjectPropertyConditionTest.java
deleted file mode 100644 (file)
index 541188c..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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 {
-
-  }
-}
diff --git a/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/HasReviewPropertyConditionTest.java b/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/HasReviewPropertyConditionTest.java
deleted file mode 100644 (file)
index ebc0fb7..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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("");
-  }
-}
diff --git a/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/NotConditionTest.java b/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/NotConditionTest.java
deleted file mode 100644 (file)
index 46ac81f..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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;
-    }
-  }
-}
diff --git a/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/ProjectPropertyConditionTest.java b/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/ProjectPropertyConditionTest.java
deleted file mode 100644 (file)
index 86d7c27..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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");
-  }
-}
diff --git a/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/ResolutionConditionTest.java b/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/ResolutionConditionTest.java
deleted file mode 100644 (file)
index caa7978..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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();
-  }
-}
diff --git a/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/StatusConditionTest.java b/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/StatusConditionTest.java
deleted file mode 100644 (file)
index 46c2a2c..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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();
-  }
-}
diff --git a/sonar-core/src/test/java/org/sonar/core/review/workflow/function/CommentFunctionTest.java b/sonar-core/src/test/java/org/sonar/core/review/workflow/function/CommentFunctionTest.java
deleted file mode 100644 (file)
index bfb4642..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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);
-  }
-}
diff --git a/sonar-core/src/test/java/org/sonar/core/review/workflow/screen/CommentScreenTest.java b/sonar-core/src/test/java/org/sonar/core/review/workflow/screen/CommentScreenTest.java
deleted file mode 100644 (file)
index db448b3..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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");
-  }
-}
diff --git a/sonar-core/src/test/java/org/sonar/core/workflow/ReviewDatabaseStoreTest.java b/sonar-core/src/test/java/org/sonar/core/workflow/ReviewDatabaseStoreTest.java
new file mode 100644 (file)
index 0000000..8294d3c
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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");
+  }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/workflow/WorkflowEngineTest.java b/sonar-core/src/test/java/org/sonar/core/workflow/WorkflowEngineTest.java
new file mode 100644 (file)
index 0000000..b38a4a8
--- /dev/null
@@ -0,0 +1,178 @@
+/*
+ * 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);
+  }
+}
diff --git a/sonar-core/src/test/resources/org/sonar/core/review/workflow/ReviewDatabaseStoreTest/store-result.xml b/sonar-core/src/test/resources/org/sonar/core/review/workflow/ReviewDatabaseStoreTest/store-result.xml
deleted file mode 100644 (file)
index a389f7f..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<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>
diff --git a/sonar-core/src/test/resources/org/sonar/core/review/workflow/ReviewDatabaseStoreTest/store.xml b/sonar-core/src/test/resources/org/sonar/core/review/workflow/ReviewDatabaseStoreTest/store.xml
deleted file mode 100644 (file)
index 8de7eda..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-<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>
diff --git a/sonar-core/src/test/resources/org/sonar/core/workflow/ReviewDatabaseStoreTest/store-result.xml b/sonar-core/src/test/resources/org/sonar/core/workflow/ReviewDatabaseStoreTest/store-result.xml
new file mode 100644 (file)
index 0000000..a389f7f
--- /dev/null
@@ -0,0 +1,31 @@
+<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>
diff --git a/sonar-core/src/test/resources/org/sonar/core/workflow/ReviewDatabaseStoreTest/store.xml b/sonar-core/src/test/resources/org/sonar/core/workflow/ReviewDatabaseStoreTest/store.xml
new file mode 100644 (file)
index 0000000..8de7eda
--- /dev/null
@@ -0,0 +1,24 @@
+<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>
index d5e8e323cd6d747b91fab5f6cd69f667562825a4..fb8516ec9f766696a59ff22ec9743fccdb1ac330 100644 (file)
@@ -91,7 +91,7 @@ public final class FilterColumn {
   }
 
   /**
-   * 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
    */
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/Comment.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/Comment.java
new file mode 100644 (file)
index 0000000..c478ad6
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * 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);
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/MutableReview.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/MutableReview.java
new file mode 100644 (file)
index 0000000..5d1e331
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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();
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/Review.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/Review.java
new file mode 100644 (file)
index 0000000..9ff51f0
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * 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();
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/Workflow.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/Workflow.java
new file mode 100644 (file)
index 0000000..0e3d4e7
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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);
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/WorkflowContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/WorkflowContext.java
new file mode 100644 (file)
index 0000000..693e43a
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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();
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/AdminRoleCondition.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/AdminRoleCondition.java
new file mode 100644 (file)
index 0000000..ee0595c
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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();
+  }
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/Condition.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/Condition.java
new file mode 100644 (file)
index 0000000..985f51b
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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);
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/Conditions.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/Conditions.java
new file mode 100644 (file)
index 0000000..ac89851
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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);
+  }
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/HasProjectPropertyCondition.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/HasProjectPropertyCondition.java
new file mode 100644 (file)
index 0000000..df9ce0d
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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";
+  }
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/HasReviewPropertyCondition.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/HasReviewPropertyCondition.java
new file mode 100644 (file)
index 0000000..09afc8c
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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));
+  }
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/NotCondition.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/NotCondition.java
new file mode 100644 (file)
index 0000000..3eabc3f
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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;
+  }
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/ProjectPropertyCondition.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/ProjectPropertyCondition.java
new file mode 100644 (file)
index 0000000..9c19004
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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;
+  }
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/ResolutionCondition.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/ResolutionCondition.java
new file mode 100644 (file)
index 0000000..080df29
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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);
+  }
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/StatusCondition.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/StatusCondition.java
new file mode 100644 (file)
index 0000000..f27709f
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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);
+  }
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/package-info.java
new file mode 100644 (file)
index 0000000..f8b3ec0
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/function/CommentFunction.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/function/CommentFunction.java
new file mode 100644 (file)
index 0000000..c75e358
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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());
+  }
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/function/Function.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/function/Function.java
new file mode 100644 (file)
index 0000000..11ad236
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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);
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/function/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/function/package-info.java
new file mode 100644 (file)
index 0000000..a6ac723
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultComment.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultComment.java
new file mode 100644 (file)
index 0000000..1887b20
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * 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();
+  }
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultReview.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultReview.java
new file mode 100644 (file)
index 0000000..019463e
--- /dev/null
@@ -0,0 +1,215 @@
+/*
+ * 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
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultWorkflow.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultWorkflow.java
new file mode 100644 (file)
index 0000000..e6a0c87
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * 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;
+  }
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultWorkflowContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultWorkflowContext.java
new file mode 100644 (file)
index 0000000..3101d43
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * 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();
+  }
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/package-info.java
new file mode 100644 (file)
index 0000000..4ac8f86
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/package-info.java
new file mode 100644 (file)
index 0000000..919b1aa
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * 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
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/CommentScreen.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/CommentScreen.java
new file mode 100644 (file)
index 0000000..aff9df5
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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");
+  }
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/Screen.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/Screen.java
new file mode 100644 (file)
index 0000000..853a29a
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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;
+  }
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/package-info.java
new file mode 100644 (file)
index 0000000..f8f7e60
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/AdminRoleConditionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/AdminRoleConditionTest.java
new file mode 100644 (file)
index 0000000..9a6d9fe
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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();
+  }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ConditionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ConditionTest.java
new file mode 100644 (file)
index 0000000..5fbb7d2
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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();
+  }
+
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ConditionsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ConditionsTest.java
new file mode 100644 (file)
index 0000000..2c913d4
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * 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");
+  }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/HasProjectPropertyConditionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/HasProjectPropertyConditionTest.java
new file mode 100644 (file)
index 0000000..87c3a4f
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * 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 {
+
+  }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/HasReviewPropertyConditionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/HasReviewPropertyConditionTest.java
new file mode 100644 (file)
index 0000000..1f57854
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * 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("");
+  }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/NotConditionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/NotConditionTest.java
new file mode 100644 (file)
index 0000000..1b73fc7
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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;
+    }
+  }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ProjectPropertyConditionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ProjectPropertyConditionTest.java
new file mode 100644 (file)
index 0000000..7e3344d
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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");
+  }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ResolutionConditionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ResolutionConditionTest.java
new file mode 100644 (file)
index 0000000..17b4427
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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();
+  }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/StatusConditionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/StatusConditionTest.java
new file mode 100644 (file)
index 0000000..2fcc17a
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * 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();
+  }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/function/CommentFunctionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/function/CommentFunctionTest.java
new file mode 100644 (file)
index 0000000..3970f22
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * 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);
+  }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/internal/DefaultWorkflowTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/internal/DefaultWorkflowTest.java
new file mode 100644 (file)
index 0000000..69bd771
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * 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);
+  }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/screen/CommentScreenTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/screen/CommentScreenTest.java
new file mode 100644 (file)
index 0000000..1404bfc
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * 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");
+  }
+}
index 1542bb10aaacd40647a791b187a23db56f3dccc4..26981427754be6f9273dafd8de6f6a8db7d1d249 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.platform;
 
+import org.sonar.api.workflow.internal.DefaultWorkflow;
 import org.sonar.server.startup.RegisterNewFilters;
 
 import org.apache.commons.configuration.BaseConfiguration;
@@ -44,9 +45,8 @@ import org.sonar.core.metric.DefaultMetricFinder;
 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;
@@ -176,7 +176,7 @@ public final class Platform {
     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);
 
index b639339f1bf07a303a6625426c3d0659a6ecc767..a2a73f25d9c968585e9a288ebf3b49e168a4ef82 100644 (file)
@@ -43,11 +43,11 @@ import org.sonar.core.persistence.Database;
 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;
index 54b68249b94a950ec28be56711b5e55d2d90549a..6fd158983ff6f78a0addea024d0ab41da5148305 100644 (file)
@@ -33,7 +33,7 @@
 class Api::ReviewContext
   
   def initialize(options={})
-    @review = options[:review]
+    @review = options[:workflow]
     @project = options[:project]
     @user = options[:user]
     @params = options[:params]
index 6ae29910d0bac84360ad7914d288cb5df129574e..72a1d405f7286c290191105e4bda6dfe3a8670fc 100644 (file)
@@ -275,7 +275,7 @@ class RuleFailure < ActiveRecord::Base
   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)
@@ -299,7 +299,7 @@ class RuleFailure < ActiveRecord::Base
   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)
index 7f52dafd51a077c5d5c7962ccd7071e3d1b1d3e7..b274fc3672fe99140c9182c6d65f9772953d7439 100644 (file)
@@ -3,5 +3,5 @@
     # 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>