]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4315 Improve Actions API but using directly Action without using Actions
authorJulien Lancelot <julien.lancelot@gmail.com>
Fri, 31 May 2013 17:05:13 +0000 (19:05 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Mon, 3 Jun 2013 09:12:48 +0000 (11:12 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Action.java
sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Actions.java
sonar-server/src/main/java/org/sonar/server/issue/ActionService.java
sonar-server/src/main/java/org/sonar/server/platform/Platform.java

index 8af8b13e09c706f1c680cdc40a9a3fe15fd3050f..113b1ea7fe31fc1b798df890f13c5a9646f15a84 100644 (file)
@@ -22,13 +22,14 @@ package org.sonar.api.issue.action;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import com.google.common.collect.Lists;
+import org.sonar.api.ServerComponent;
 import org.sonar.api.issue.Issue;
 import org.sonar.api.issue.condition.Condition;
 
 import java.util.Arrays;
 import java.util.List;
 
-public class Action {
+public class Action implements ServerComponent {
 
   private final String key;
   private final List<Condition> conditions;
index 02f3fc6cbe19f113053d7671e9c1cd5fa326bf49..d883ab8a5c7645ea25c16a871d04f706ac236916 100644 (file)
@@ -26,6 +26,7 @@ import java.util.Set;
 /**
  * @since 3.6
  */
+// TODO remove it
 public interface Actions extends ServerComponent {
 
   Actions addAction(Action action);
index 1f6bd2e87cc39fc8b642b27053fd4d191cdbd67f..41b9a79a12e9bb2fee122cdff066a28537122728 100644 (file)
@@ -37,9 +37,12 @@ import org.sonar.core.issue.IssueUpdater;
 import org.sonar.core.issue.db.IssueStorage;
 import org.sonar.server.user.UserSession;
 
+import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
+
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 import static com.google.common.collect.Lists.newArrayList;
 
@@ -48,9 +51,10 @@ public class ActionService implements ServerComponent {
   private final DefaultIssueFinder finder;
   private final IssueStorage issueStorage;
   private final IssueUpdater updater;
-  private final DefaultActions actions;
+  private final List<Action> actions;
+//  private final DefaultActions actions;
 
-  public ActionService(DefaultIssueFinder finder, IssueStorage issueStorage, IssueUpdater updater, DefaultActions actions) {
+  public ActionService(DefaultIssueFinder finder, IssueStorage issueStorage, IssueUpdater updater, List<Action> actions) {
     this.finder = finder;
     this.issueStorage = issueStorage;
     this.updater = updater;
@@ -61,7 +65,7 @@ public class ActionService implements ServerComponent {
     IssueQueryResult queryResult = loadIssue(issueKey);
     final DefaultIssue issue = (DefaultIssue) queryResult.first();
 
-    return newArrayList(Iterables.filter(actions.getActions(), new Predicate<Action>() {
+    return newArrayList(Iterables.filter(actions, new Predicate<Action>() {
       @Override
       public boolean apply(Action action) {
         return action.supports(issue);
@@ -69,6 +73,17 @@ public class ActionService implements ServerComponent {
     }));
   }
 
+  @CheckForNull
+  public Action getAction(final String actionKey) {
+    return Iterables.find(actions, new Predicate<Action>() {
+      @Override
+      public boolean apply(Action action) {
+        return action.key().equals(actionKey);
+      }
+    }, null);
+  }
+
+  public Issue execute(String issueKey, String actionKey, UserSession userSession, Map<String, String> parameters) {
   public Issue execute(String issueKey, String actionKey, UserSession userSession) {
     Preconditions.checkArgument(!Strings.isNullOrEmpty(actionKey), "Missing action");
 
@@ -78,7 +93,7 @@ public class ActionService implements ServerComponent {
       throw new IllegalStateException("Issue is not found : " + issueKey);
     }
 
-    Action action = actions.getAction(actionKey);
+    Action action = getAction(actionKey);
     if (action == null) {
       throw new IllegalStateException("Action is not found : " + actionKey);
     }
@@ -117,6 +132,11 @@ public class ActionService implements ServerComponent {
       return issue;
     }
 
+    @Override
+    public Map<String, String> parameters() {
+      return parameters;
+    }
+
     @Override
     public Function.Context setAttribute(String key, @Nullable String value) {
       updater.setAttribute(issue, key, value, changeContext);
index 47225cd44a6ac2ae683240d46c3c6564acefb8f9..57972aa6eb040b760efabbbc085242bb04196652 100644 (file)
@@ -22,6 +22,9 @@ package org.sonar.server.platform;
 import org.apache.commons.configuration.BaseConfiguration;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.config.EmailSettings;
+import org.sonar.api.issue.Issue;
+import org.sonar.api.issue.action.Action;
+import org.sonar.api.issue.condition.HasResolution;
 import org.sonar.api.platform.ComponentContainer;
 import org.sonar.api.platform.Server;
 import org.sonar.api.profiles.AnnotationProfileParser;
@@ -34,6 +37,7 @@ import org.sonar.api.rules.XMLRuleParser;
 import org.sonar.api.utils.HttpDownloader;
 import org.sonar.api.utils.TimeProfiler;
 import org.sonar.api.utils.UriReader;
+import org.sonar.api.workflow.function.CommentFunction;
 import org.sonar.core.component.SnapshotPerspectives;
 import org.sonar.core.config.Logback;
 import org.sonar.core.i18n.GwtI18n;
@@ -272,7 +276,11 @@ public final class Platform {
     servicesContainer.addSingleton(ActionService.class);
 
     // TODO only for test
-    servicesContainer.addSingleton(ExtendWorkflow.class);
+    servicesContainer.addSingleton(Action.builder("fake")
+      .conditions(new HasResolution(Issue.RESOLUTION_FIXED))
+      .functions(new CommentFunction())
+      .build()
+    );
 
     // rules
     servicesContainer.addSingleton(RubyRuleService.class);