aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-06-02 22:33:26 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-06-02 22:33:26 +0200
commit2e004c7c6d77ffcb2b352754568bcf8a0cb21b03 (patch)
tree9b492c48db253cfe2ce1aef778608e5aac0c41ec /sonar-plugin-api/src
parentaad61ea0cf5966908e53744f0d964db2ec2aa7c9 (diff)
downloadsonarqube-2e004c7c6d77ffcb2b352754568bcf8a0cb21b03.tar.gz
sonarqube-2e004c7c6d77ffcb2b352754568bcf8a0cb21b03.zip
SONAR-4315 Improve ActionService
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Function.java6
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/HasIssuePropertyCondition.java48
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/workflow/function/CommentFunction.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/issue/condition/HasIssuePropertyConditionTest.java63
4 files changed, 112 insertions, 7 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Function.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Function.java
index 2bb6ab8ddc9..70401abc17d 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Function.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Function.java
@@ -21,11 +21,8 @@ package org.sonar.api.issue.action;
import org.sonar.api.issue.Issue;
-import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import java.util.Map;
-
/**
* @since 3.6
*/
@@ -36,9 +33,6 @@ public interface Function {
interface Context {
Issue issue();
- @CheckForNull
- Map<String, String> parameters();
-
Context setAttribute(String key, @Nullable String value);
Context addComment(@Nullable String text);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/HasIssuePropertyCondition.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/HasIssuePropertyCondition.java
new file mode 100644
index 00000000000..d6386e9ed8b
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/HasIssuePropertyCondition.java
@@ -0,0 +1,48 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.issue.condition;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import org.sonar.api.issue.Issue;
+
+/**
+ * @since 3.1
+ */
+@Beta
+public final class HasIssuePropertyCondition implements Condition {
+
+ private final String propertyKey;
+
+ public HasIssuePropertyCondition(String propertyKey) {
+ Preconditions.checkArgument(!Strings.isNullOrEmpty(propertyKey));
+ this.propertyKey = propertyKey;
+ }
+
+ public String getPropertyKey() {
+ return propertyKey;
+ }
+
+ @Override
+ public boolean matches(Issue issue) {
+ return !Strings.isNullOrEmpty(issue.attributes().get(propertyKey));
+ }
+}
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
index a312e6061d7..697e9b5f2a0 100644
--- 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
@@ -30,6 +30,6 @@ public final class CommentFunction implements Function {
@Override
public void execute(Context context) {
- context.addComment(context.parameters().get("text"));
+ context.addComment("New comment!");
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/issue/condition/HasIssuePropertyConditionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/issue/condition/HasIssuePropertyConditionTest.java
new file mode 100644
index 00000000000..e4dbfd396f4
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/issue/condition/HasIssuePropertyConditionTest.java
@@ -0,0 +1,63 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.issue.condition;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.issue.internal.DefaultIssue;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class HasIssuePropertyConditionTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ DefaultIssue issue = new DefaultIssue();
+
+ @Test
+ public void should_match() {
+ HasIssuePropertyCondition condition = new HasIssuePropertyCondition("foo");
+
+ assertThat(condition.matches(issue)).isFalse();
+ assertThat(condition.matches(issue.setAttribute("foo", ""))).isFalse();
+ assertThat(condition.matches(issue.setAttribute("foo", "bar"))).isTrue();
+ }
+
+ @Test
+ public void should_get_property_key() {
+ HasIssuePropertyCondition condition = new HasIssuePropertyCondition("foo");
+ assertThat(condition.getPropertyKey()).isEqualTo("foo");
+ }
+
+ @Test
+ public void shoul_fail_if_null_property() {
+ thrown.expect(IllegalArgumentException.class);
+ new HasIssuePropertyCondition(null);
+ }
+
+ @Test
+ public void should_fail_if_empty_property() {
+ thrown.expect(IllegalArgumentException.class);
+ new HasIssuePropertyCondition("");
+ }
+
+}