diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-05-22 22:12:08 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-05-22 22:28:19 +0200 |
commit | 9d3852ae697aebc26f32af9066bbd8257cff1334 (patch) | |
tree | 5160c9c54ba15895657f925aa63a9fdcccdf08bc | |
parent | 46605e701878daa426e851a1bd26f5fe2e73649c (diff) | |
download | sonarqube-9d3852ae697aebc26f32af9066bbd8257cff1334.tar.gz sonarqube-9d3852ae697aebc26f32af9066bbd8257cff1334.zip |
SONAR-2706 some refactoring
10 files changed, 75 insertions, 37 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/review/ReviewDto.java b/sonar-core/src/main/java/org/sonar/core/review/ReviewDto.java index f0ea3fb26a3..8fe5d79efff 100644 --- a/sonar-core/src/main/java/org/sonar/core/review/ReviewDto.java +++ b/sonar-core/src/main/java/org/sonar/core/review/ReviewDto.java @@ -19,15 +19,12 @@ */ package org.sonar.core.review; -import com.google.common.collect.ImmutableMap; +import com.google.common.base.Preconditions; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; -import org.sonar.api.utils.KeyValueFormat; import javax.annotation.Nullable; - import java.util.Date; -import java.util.Map; /** * @since 2.13 @@ -226,35 +223,13 @@ public final class ReviewDto { return data; } - public ReviewDto setData(String data) { - this.data = data; + public ReviewDto setData(String s) { + Preconditions.checkArgument(s == null || s.length() <= 4000, + "Review data must not exceed 4000 characters: " + s); + this.data = s; return this; } - /** - * Returns an immutable Map of the properties store in the "data" column - * of the review. To modify the properties, use {@link #removeKeyFromData(String)} - * or {@link #addKeyValueToData(String)}. - * - * @return the map of properties - */ - @SuppressWarnings("unchecked") - public ImmutableMap<String, String> getDataMap() { - return ImmutableMap.copyOf(KeyValueFormat.parse(data)); - } - - public void removeKeyFromData(String key) { - Map<String, String> dataMap = KeyValueFormat.parse(data); - dataMap.remove(key); - data = KeyValueFormat.format(dataMap); - } - - public void addKeyValueToData(String key, String value) { - Map<String, String> dataMap = KeyValueFormat.parse(data); - dataMap.put(key, value); - data = KeyValueFormat.format(dataMap); - } - @Override public String toString() { return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); 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 index 903df42e1ba..db66d26956a 100644 --- 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 @@ -32,6 +32,7 @@ import org.sonar.core.review.workflow.function.Function; import org.sonar.core.review.workflow.review.*; import org.sonar.core.review.workflow.screen.Screen; +import javax.annotation.Nullable; import java.util.List; import java.util.Map; @@ -110,7 +111,7 @@ public class WorkflowEngine implements ServerComponent { // TODO notify listeners } - private boolean verifyConditions(Review review, WorkflowContext context, List<Condition> conditions) { + private boolean verifyConditions(@Nullable Review review, WorkflowContext context, List<Condition> conditions) { for (Condition condition : conditions) { if (!condition.doVerify(review, context)) { return false; 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 index 54734cb43c9..6868361fde2 100644 --- 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 @@ -19,13 +19,17 @@ */ 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 */ -public class AdminRoleCondition extends Condition { +@Beta +public final class AdminRoleCondition extends Condition { public AdminRoleCondition() { super(true); 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 index e44e4c88d3e..f5386879bf4 100644 --- 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 @@ -19,11 +19,16 @@ */ 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; 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 index 8b376cb88e2..2e3c1a1a564 100644 --- 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 @@ -19,11 +19,14 @@ */ 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() { 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 index 354915cff0e..6992ddcd123 100644 --- 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 @@ -19,13 +19,19 @@ */ 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; +import javax.annotation.concurrent.Immutable; + /** * Checks that a project property is set, whatever its value. + * + * @since 3.1 */ +@Beta public final class HasProjectPropertyCondition extends ProjectPropertyCondition { public HasProjectPropertyCondition(String propertyKey) { 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 index 903db40658d..1e34b4feeb7 100644 --- 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 @@ -19,12 +19,17 @@ */ 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; -public class HasReviewPropertyCondition extends Condition { +/** + * @since 3.1 + */ +@Beta +public final class HasReviewPropertyCondition extends Condition { private final String propertyKey; diff --git a/sonar-core/src/test/java/org/sonar/core/review/ReviewDaoTest.java b/sonar-core/src/test/java/org/sonar/core/review/ReviewDaoTest.java index 0a59a5587f6..ed070c34fef 100644 --- a/sonar-core/src/test/java/org/sonar/core/review/ReviewDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/review/ReviewDaoTest.java @@ -111,9 +111,7 @@ public class ReviewDaoTest extends DaoTestCase { review.setTitle("NEW_TITLE"); review.setCreatedAt(DateUtils.parseDate("2012-05-18")); review.setUpdatedAt(DateUtils.parseDate("2012-07-01")); - review.removeKeyFromData("prop2"); - review.addKeyValueToData("prop3", "bing"); - review.addKeyValueToData("prop4", "bang"); + review.setData("big=bang"); dao.update(reviews); diff --git a/sonar-core/src/test/java/org/sonar/core/review/ReviewDtoTest.java b/sonar-core/src/test/java/org/sonar/core/review/ReviewDtoTest.java new file mode 100644 index 00000000000..660af20d013 --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/review/ReviewDtoTest.java @@ -0,0 +1,41 @@ +/* + * 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; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class ReviewDtoTest { + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void setData_check_maximal_length() { + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Review data must not exceed 4000 characters: "); + + StringBuilder s = new StringBuilder(4500); + for (int i=0 ; i<4500 ; i++) { + s.append('a'); + } + new ReviewDto().setData(s.toString()); + } +} diff --git a/sonar-core/src/test/resources/org/sonar/core/review/ReviewDaoTest/update-result.xml b/sonar-core/src/test/resources/org/sonar/core/review/ReviewDaoTest/update-result.xml index 353b5825335..97382156bb6 100644 --- a/sonar-core/src/test/resources/org/sonar/core/review/ReviewDaoTest/update-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/review/ReviewDaoTest/update-result.xml @@ -17,7 +17,7 @@ rule_id="500" manual_severity="[true]" manual_violation="[false]" - data="prop1=foo;prop3=bing;prop4=bang" + data="big=bang" /> </dataset> |