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;
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;
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);
}));
}
+ @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");
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);
}
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);
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;
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;
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);