aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-05-31 19:05:13 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-06-03 11:12:48 +0200
commit6ce3ec7f1b3f0b3c1baf823037873bdd672af4e5 (patch)
treef42542ea82151fcb39fd6f7fe956f81a41364b6e
parent53f72765ff3868ef94e5b6f319bdb4d7b009dfee (diff)
downloadsonarqube-6ce3ec7f1b3f0b3c1baf823037873bdd672af4e5.tar.gz
sonarqube-6ce3ec7f1b3f0b3c1baf823037873bdd672af4e5.zip
SONAR-4315 Improve Actions API but using directly Action without using Actions
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Action.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Actions.java1
-rw-r--r--sonar-server/src/main/java/org/sonar/server/issue/ActionService.java28
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/Platform.java10
4 files changed, 36 insertions, 6 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Action.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Action.java
index 8af8b13e09c..113b1ea7fe3 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Action.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Action.java
@@ -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;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Actions.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Actions.java
index 02f3fc6cbe1..d883ab8a5c7 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Actions.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Actions.java
@@ -26,6 +26,7 @@ import java.util.Set;
/**
* @since 3.6
*/
+// TODO remove it
public interface Actions extends ServerComponent {
Actions addAction(Action action);
diff --git a/sonar-server/src/main/java/org/sonar/server/issue/ActionService.java b/sonar-server/src/main/java/org/sonar/server/issue/ActionService.java
index 1f6bd2e87cc..41b9a79a12e 100644
--- a/sonar-server/src/main/java/org/sonar/server/issue/ActionService.java
+++ b/sonar-server/src/main/java/org/sonar/server/issue/ActionService.java
@@ -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);
}
@@ -118,6 +133,11 @@ public class ActionService implements ServerComponent {
}
@Override
+ public Map<String, String> parameters() {
+ return parameters;
+ }
+
+ @Override
public Function.Context setAttribute(String key, @Nullable String value) {
updater.setAttribute(issue, key, value, changeContext);
return this;
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
index 47225cd44a6..57972aa6eb0 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
@@ -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);