diff options
author | David Gageot <david@gageot.net> | 2012-09-28 13:35:23 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-09-28 15:08:45 +0200 |
commit | 9c854f825217360854b7878a28a21dc9a8c5c19b (patch) | |
tree | 787736e26eb3dc744d4b27faa39b2117c9ed1c6a /sonar-plugin-api | |
parent | f31d5fd1a99b5b3dca8cc450d97203206a06de5a (diff) | |
download | sonarqube-9c854f825217360854b7878a28a21dc9a8c5c19b.tar.gz sonarqube-9c854f825217360854b7878a28a21dc9a8c5c19b.zip |
SONAR-3529 Get rid of property sets. Use PropertyFields instead
Diffstat (limited to 'sonar-plugin-api')
16 files changed, 143 insertions, 550 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/Property.java b/sonar-plugin-api/src/main/java/org/sonar/api/Property.java index ca2c7270699..3d85cfb46f0 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/Property.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/Property.java @@ -100,9 +100,17 @@ public @interface Property { boolean multiValues() default false; /** - * Name of the property set. Used only when type = <code>PropertyType.PROPERTY_SET</code>. + * A Property of type <code>PropertyType.PROPERTY_SET</code> can reference a set of properties + * by its key. * * @since 3.3 */ - String propertySetName() default ""; + String propertySetKey() default ""; + + /** + * A Property with fields is considered a property set. + * + * @since 3.3 + */ + PropertyField[] fields() default {}; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySetTemplate.java b/sonar-plugin-api/src/main/java/org/sonar/api/PropertyField.java index cef931d16ad..4f2c9e18dce 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySetTemplate.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/PropertyField.java @@ -17,25 +17,39 @@ * License along with Sonar; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 */ -package org.sonar.api.config; +package org.sonar.api; -import org.sonar.api.ServerExtension; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; /** - * This extension point must be implemented to define a new property set. + * Property field. * * @since 3.3 */ -public abstract class PropertySetTemplate implements ServerExtension { +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface PropertyField { /** - * Returns the {@link org.sonar.api.config.PropertySet} object that a property set. - * - * @return the property set + * Unique key within a property. */ - public abstract PropertySet createPropertySet(); + String key(); /** - * Property set unique name. + * The empty string "" is considered as null, so it's not possible to have empty strings for default values. */ - public abstract String getName(); + String defaultValue() default ""; + + String name(); + + String description() default ""; + + PropertyType type() default PropertyType.STRING; + + /** + * Options for *_LIST types + */ + String[] options() default {}; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java index 5c20b5c56e5..7e497b49aaa 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java @@ -67,7 +67,8 @@ public final class PropertyDefinition { private boolean onModule = false; private boolean isGlobal = true; private boolean multiValues; - private String propertySetName; + private String propertySetKey; + private PropertyFieldDefinition[] fields; private PropertyDefinition(Property annotation) { this.key = annotation.key(); @@ -81,7 +82,8 @@ public final class PropertyDefinition { this.type = fixType(annotation.key(), annotation.type()); this.options = annotation.options(); this.multiValues = annotation.multiValues(); - this.propertySetName = annotation.propertySetName(); + propertySetKey = annotation.propertySetKey(); + this.fields = PropertyFieldDefinition.create(annotation.fields()); } private static PropertyType fixType(String key, PropertyType type) { @@ -186,7 +188,14 @@ public final class PropertyDefinition { /** * @since 3.3 */ - public String getPropertySetName() { - return propertySetName; + public String getPropertySetKey() { + return propertySetKey; + } + + /** + * @since 3.3 + */ + public PropertyFieldDefinition[] getFields() { + return fields; } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySetField.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java index 69376a4b6e3..51775b7fe4a 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySetField.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java @@ -19,46 +19,65 @@ */ package org.sonar.api.config; +import org.sonar.api.PropertyField; import org.sonar.api.PropertyType; -public final class PropertySetField { - private final String name; - private final PropertyType type; - private String description = ""; - private String defaultValue = ""; +/** + * @since 3.3 + */ +public final class PropertyFieldDefinition { + private String key; + private String defaultValue; + private String name; + private PropertyType type = PropertyType.STRING; + private String[] options; + private String description; - private PropertySetField(String name, PropertyType type) { - this.name = name; - this.type = type; + private PropertyFieldDefinition(PropertyField annotation) { + this.key = annotation.key(); + this.name = annotation.name(); + this.defaultValue = annotation.defaultValue(); + this.description = annotation.description(); + this.type = annotation.type(); + this.options = annotation.options(); } - public static PropertySetField create(String name, PropertyType type) { - return new PropertySetField(name, type); + public static PropertyFieldDefinition create(PropertyField annotation) { + return new PropertyFieldDefinition(annotation); } - public String getName() { - return name; - } + public static PropertyFieldDefinition[] create(PropertyField[] fields) { + PropertyFieldDefinition[] definitions = new PropertyFieldDefinition[fields.length]; - public PropertyType getType() { - return type; - } + for (int i = 0; i < fields.length; i++) { + definitions[i] = create(fields[i]); + } - public String getDescription() { - return description; + return definitions; } - public PropertySetField setDescription(String description) { - this.description = description; - return this; + + public String getKey() { + return key; } public String getDefaultValue() { return defaultValue; } - public PropertySetField setDefaultValue(String defaultValue) { - this.defaultValue = defaultValue; - return this; + public String getName() { + return name; + } + + public PropertyType getType() { + return type; + } + + public String[] getOptions() { + return options.clone(); + } + + public String getDescription() { + return description; } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySet.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySet.java deleted file mode 100644 index ee13b940487..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySet.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.api.config; - -import com.google.common.collect.Lists; - -import java.util.List; - -public class PropertySet { - private final List<PropertySetField> fields = Lists.newArrayList(); - - public PropertySet add(PropertySetField field) { - fields.add(field); - return this; - } - - public List<PropertySetField> getFields() { - return fields; - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySetDefinitions.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySetDefinitions.java deleted file mode 100644 index 511f3d909a6..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySetDefinitions.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.api.config; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Maps; -import org.sonar.api.ServerExtension; - -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; - -public class PropertySetDefinitions implements ServerExtension { - private final Map<String, PropertySet> index = Maps.newHashMap(); - - public void register(String name, PropertySet propertySet) { - if (null != index.put(name, propertySet)) { - throw new IllegalStateException("Unable to register two property sets with same name " + name); - } - } - - public List<PropertySet> findAll() { - return ImmutableList.copyOf(index.values()); - } - - public PropertySet findByName(String name) { - PropertySet propertySet = index.get(name); - if (propertySet == null) { - throw new NoSuchElementException("Property set not found " + name); - } - return propertySet; - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySetValue.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySetValue.java deleted file mode 100644 index 8df3ca267cb..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySetValue.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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.api.config; - -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; -import org.apache.commons.lang.ArrayUtils; -import org.sonar.api.utils.DateUtils; - -import java.util.Date; -import java.util.List; -import java.util.Map; - -/** - * @since 3.3 - */ -public final class PropertySetValue { - private final Map<String, String> keyValues; - - private PropertySetValue(Map<String, String> keyValues) { - this.keyValues = ImmutableMap.copyOf(keyValues); - } - - public static PropertySetValue create(Map<String, String> keyValues) { - return new PropertySetValue(keyValues); - } - - /** - * @return the field as String. If the field does not exist, then an empty string is returned. - */ - public String getString(String fieldName) { - String value = keyValues.get(fieldName); - return (value == null) ? "" : value; - } - - /** - * @return the field as int. If the field does not exist, then <code>0</code> is returned. - */ - public int getInt(String fieldName) { - String value = keyValues.get(fieldName); - return (value == null) ? 0 : Integer.parseInt(value); - } - - /** - * @return the field as boolean. If the field does not exist, then <code>false</code> is returned. - */ - public boolean getBoolean(String fieldName) { - String value = keyValues.get(fieldName); - return (value == null) ? false : Boolean.parseBoolean(value); - } - - /** - * @return the field as float. If the field does not exist, then <code>0.0</code> is returned. - */ - public float getFloat(String fieldName) { - String value = keyValues.get(fieldName); - return (value == null) ? 0f : Float.parseFloat(value); - } - - /** - * @return the field as long. If the field does not exist, then <code>0L</code> is returned. - */ - public long getLong(String fieldName) { - String value = keyValues.get(fieldName); - return (value == null) ? 0L : Long.parseLong(value); - } - - /** - * @return the field as Date. If the field does not exist, then <code>null</code> is returned. - */ - public Date getDate(String fieldName) { - String value = keyValues.get(fieldName); - return (value == null) ? null : DateUtils.parseDate(value); - } - - /** - * @return the field as Date with time. If the field does not exist, then <code>null</code> is returned. - */ - public Date getDateTime(String fieldName) { - String value = keyValues.get(fieldName); - return (value == null) ? null : DateUtils.parseDateTime(value); - } - - /** - * @return the field as an array of String. If the field does not exist, then an empty array is returned. - */ - public String[] getStringArray(String fieldName) { - String value = keyValues.get(fieldName); - if (value == null) { - return ArrayUtils.EMPTY_STRING_ARRAY; - } - - List<String> values = Lists.newArrayList(); - for (String v : Splitter.on(",").trimResults().split(value)) { - values.add(v.replace("%2C", ",")); - } - return values.toArray(new String[values.size()]); - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java index 0735c91073b..3ec41a5cf6e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java @@ -19,8 +19,6 @@ */ package org.sonar.api.config; -import com.google.common.collect.Iterables; - import com.google.common.base.Joiner; import com.google.common.base.Splitter; import com.google.common.base.Strings; @@ -29,14 +27,16 @@ import com.google.common.collect.Maps; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.sonar.api.BatchComponent; -import org.sonar.api.PropertyType; import org.sonar.api.ServerComponent; import org.sonar.api.utils.DateUtils; import javax.annotation.Nullable; -import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; + +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Properties; /** * Project Settings on batch side, Global Settings on server side. This component does not access to database, so @@ -184,23 +184,6 @@ public class Settings implements BatchComponent, ServerComponent { return getStringArrayBySeparator(key, ","); } - public final PropertySetValue getPropertySetValue(String key) { - PropertyDefinition property = getDefinitions().get(key); - if ((null == property) || (property.getType() != PropertyType.PROPERTY_SET)) { - throw new IllegalArgumentException("Property " + key + " is not of type PROPERTY_SET"); - } - - String propertySetName = property.getPropertySetName(); - String valueName = getString(key); - String propertySetJson = getString("sonar.property_set." + propertySetName); - - return PropertySetValue.create(lowTechJsonParsing(valueName, propertySetJson)); - } - - private static Map<String, String> lowTechJsonParsing(String valueName, String json) { - return Maps.newHashMap(); - } - /** * Value is split by carriage returns. * diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/TestPropertySetTemplate.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/TestPropertySetTemplate.java deleted file mode 100644 index fdc53be8a2a..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/TestPropertySetTemplate.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.api.config; - -import org.sonar.api.PropertyType; - -public class TestPropertySetTemplate extends PropertySetTemplate { - public PropertySet createPropertySet() { - return new PropertySet() - .add(PropertySetField.create("firstName", PropertyType.TEXT)) - .add(PropertySetField.create("lastName", PropertyType.TEXT)); - } - - public String getName() { - return "test"; - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java index 26409d1742b..c8eccd712bf 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java @@ -25,12 +25,19 @@ import org.apache.commons.collections.Transformer; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; -import org.sonar.api.database.model.ResourceModel; import org.sonar.api.rules.ActiveRule; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RulePriority; -import javax.persistence.*; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; + import java.util.ArrayList; import java.util.List; diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java index 59d3927aa33..caea3a388b7 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java @@ -19,6 +19,8 @@ */ package org.sonar.api.config; +import org.sonar.api.PropertyField; + import org.junit.Test; import org.sonar.api.Properties; import org.sonar.api.Property; @@ -47,11 +49,12 @@ public class PropertyDefinitionTest { assertThat(def.isOnProject()).isTrue(); assertThat(def.isOnModule()).isTrue(); assertThat(def.isMultiValues()).isTrue(); - assertThat(def.getPropertySetName()).isEmpty(); + assertThat(def.getPropertySetKey()).isEqualTo("set"); + assertThat(def.getFields()).isEmpty(); } @Properties(@Property(key = "hello", name = "Hello", defaultValue = "world", description = "desc", - options = {"de", "en"}, category = "categ", type = PropertyType.FLOAT, global = false, project = true, module = true, multiValues = true)) + options = {"de", "en"}, category = "categ", type = PropertyType.FLOAT, global = false, project = true, module = true, multiValues = true, propertySetKey = "set")) static class Init { } @@ -73,9 +76,13 @@ public class PropertyDefinitionTest { assertThat(def.isOnProject()).isFalse(); assertThat(def.isOnModule()).isFalse(); assertThat(def.isMultiValues()).isFalse(); + assertThat(def.getPropertySetKey()).isEmpty(); + assertThat(def.getFields()).isEmpty(); } - @Properties(@Property(key = "hello", name = "Hello", type = PropertyType.PROPERTY_SET, propertySetName = "set1")) + @Properties(@Property(key = "hello", name = "Hello", fields = { + @PropertyField(key = "first", name = "First"), + @PropertyField(key = "second", name = "Second", type = PropertyType.INTEGER)})) static class WithPropertySet { } @@ -86,8 +93,13 @@ public class PropertyDefinitionTest { PropertyDefinition def = PropertyDefinition.create(prop); - assertThat(def.getType()).isEqualTo(PropertyType.PROPERTY_SET); - assertThat(def.getPropertySetName()).isEqualTo("set1"); + assertThat(def.getFields()).hasSize(2); + assertThat(def.getFields()[0].getKey()).isEqualTo("first"); + assertThat(def.getFields()[0].getName()).isEqualTo("First"); + assertThat(def.getFields()[0].getType()).isEqualTo(PropertyType.STRING); + assertThat(def.getFields()[1].getKey()).isEqualTo("second"); + assertThat(def.getFields()[1].getName()).isEqualTo("Second"); + assertThat(def.getFields()[1].getType()).isEqualTo(PropertyType.INTEGER); } @Properties(@Property(key = "hello", name = "Hello")) diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetDefinitionsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetDefinitionsTest.java deleted file mode 100644 index cd0a3c39112..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetDefinitionsTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.api.config; - -import org.junit.Test; - -import java.util.NoSuchElementException; - -import static org.fest.assertions.Assertions.assertThat; - -public class PropertySetDefinitionsTest { - PropertySetDefinitions definitions = new PropertySetDefinitions(); - - @Test - public void should_register_by_name() { - PropertySet set = new PropertySet(); - PropertySet other = new PropertySet(); - - definitions.register("name", set); - definitions.register("other", other); - - assertThat(definitions.findByName("name")).isSameAs(set); - assertThat(definitions.findByName("other")).isSameAs(other); - assertThat(definitions.findAll()).containsOnly(set, other); - } - - @Test(expected = IllegalStateException.class) - public void should_fail_to_register_twice() { - definitions.register("name", new PropertySet()); - definitions.register("name", new PropertySet()); - } - - @Test(expected = NoSuchElementException.class) - public void should_fail_to_find_unknown_set() { - definitions.findByName("UNKNOWN"); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetFieldTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetFieldTest.java deleted file mode 100644 index c1a06cb1d96..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetFieldTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.api.config; - -import org.junit.Test; -import org.sonar.api.PropertyType; - -import static org.fest.assertions.Assertions.assertThat; - -public class PropertySetFieldTest { - @Test - public void should_set_name_and_type() { - PropertySetField field = PropertySetField.create("name", PropertyType.STRING); - - assertThat(field.getName()).isEqualTo("name"); - assertThat(field.getType()).isEqualTo(PropertyType.STRING); - assertThat(field.getDefaultValue()).isEmpty(); - assertThat(field.getDescription()).isEmpty(); - } - - @Test - public void should_set_optional_characteristics() { - PropertySetField field = PropertySetField.create("name", PropertyType.STRING); - - field.setDefaultValue("default"); - field.setDescription("description"); - - assertThat(field.getDefaultValue()).isEqualTo("default"); - assertThat(field.getDescription()).isEqualTo("description"); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetTest.java deleted file mode 100644 index cd999147ed7..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.api.config; - -import org.junit.Test; -import org.sonar.api.PropertyType; - -import static org.fest.assertions.Assertions.assertThat; - -public class PropertySetTest { - @Test - public void should_add_fields() { - PropertySetField firstField = PropertySetField.create("first", PropertyType.STRING); - PropertySetField secondField = PropertySetField.create("second", PropertyType.STRING); - - PropertySet set = new PropertySet(); - set.add(firstField); - set.add(secondField); - - assertThat(set.getFields()).containsExactly(firstField, secondField); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetValueTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetValueTest.java deleted file mode 100644 index b59ac26fbe5..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetValueTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.api.config; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; -import org.junit.Test; - -import static org.fest.assertions.Assertions.assertThat; - -public class PropertySetValueTest { - @Test - public void should_get_default_values() { - PropertySetValue value = PropertySetValue.create(Maps.<String, String>newHashMap()); - - assertThat(value.getString("UNKNOWN")).isEmpty(); - assertThat(value.getInt("UNKNOWN")).isZero(); - assertThat(value.getFloat("UNKNOWN")).isZero(); - assertThat(value.getLong("UNKNOWN")).isZero(); - assertThat(value.getDate("UNKNOWN")).isNull(); - assertThat(value.getDateTime("UNKNOWN")).isNull(); - assertThat(value.getStringArray("UNKNOWN")).isEmpty(); - } - - @Test - public void should_get_values() { - PropertySetValue value = PropertySetValue.create(ImmutableMap.<String, String>builder() - .put("age", "12") - .put("child", "true") - .put("size", "12.4") - .put("distance", "1000000000") - .put("array", "1,2,3,4,5") - .put("birth", "1975-01-29") - .put("now", "2012-09-25T10:08:30+0100") - .build()); - - assertThat(value.getString("age")).isEqualTo("12"); - assertThat(value.getInt("age")).isEqualTo(12); - assertThat(value.getBoolean("child")).isTrue(); - assertThat(value.getFloat("size")).isEqualTo(12.4f); - assertThat(value.getLong("distance")).isEqualTo(1000000000L); - assertThat(value.getStringArray("array")).contains("1", "2", "3", "4", "5"); - assertThat(value.getDate("birth")).isNotNull(); - assertThat(value.getDateTime("now")).isNotNull(); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java index 137e76a8b4f..2e5259a4995 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java @@ -19,8 +19,6 @@ */ package org.sonar.api.config; -import org.junit.Ignore; - import com.google.common.collect.ImmutableMap; import org.junit.Before; import org.junit.Rule; @@ -45,7 +43,7 @@ public class SettingsTest { @Property(key = "integer", name = "Integer", defaultValue = "12345"), @Property(key = "array", name = "Array", defaultValue = "one,two,three"), @Property(key = "multi_values", name = "Array", defaultValue = "1,2,3", multiValues = true), - @Property(key = "sonar.jira", name = "Jira Server", type = PropertyType.PROPERTY_SET, propertySetName = "jira") + @Property(key = "sonar.jira", name = "Jira Server", type = PropertyType.PROPERTY_SET, propertySetKey = "jira") }) static class Init { } @@ -155,53 +153,53 @@ public class SettingsTest { public void getStringArray() { Settings settings = new Settings(definitions); String[] array = settings.getStringArray("array"); - assertThat(array).isEqualTo(new String[]{"one", "two", "three"}); + assertThat(array).isEqualTo(new String[] {"one", "two", "three"}); } @Test public void setStringArray() { Settings settings = new Settings(definitions); - settings.setProperty("multi_values", new String[]{"A", "B"}); + settings.setProperty("multi_values", new String[] {"A", "B"}); String[] array = settings.getStringArray("multi_values"); - assertThat(array).isEqualTo(new String[]{"A", "B"}); + assertThat(array).isEqualTo(new String[] {"A", "B"}); } @Test public void setStringArrayTrimValues() { Settings settings = new Settings(definitions); - settings.setProperty("multi_values", new String[]{" A ", " B "}); + settings.setProperty("multi_values", new String[] {" A ", " B "}); String[] array = settings.getStringArray("multi_values"); - assertThat(array).isEqualTo(new String[]{"A", "B"}); + assertThat(array).isEqualTo(new String[] {"A", "B"}); } @Test public void setStringArrayEscapeCommas() { Settings settings = new Settings(definitions); - settings.setProperty("multi_values", new String[]{"A,B", "C,D"}); + settings.setProperty("multi_values", new String[] {"A,B", "C,D"}); String[] array = settings.getStringArray("multi_values"); - assertThat(array).isEqualTo(new String[]{"A,B", "C,D"}); + assertThat(array).isEqualTo(new String[] {"A,B", "C,D"}); } @Test public void setStringArrayWithEmptyValues() { Settings settings = new Settings(definitions); - settings.setProperty("multi_values", new String[]{"A,B", "", "C,D"}); + settings.setProperty("multi_values", new String[] {"A,B", "", "C,D"}); String[] array = settings.getStringArray("multi_values"); - assertThat(array).isEqualTo(new String[]{"A,B", "", "C,D"}); + assertThat(array).isEqualTo(new String[] {"A,B", "", "C,D"}); } @Test public void setStringArrayWithNullValues() { Settings settings = new Settings(definitions); - settings.setProperty("multi_values", new String[]{"A,B", null, "C,D"}); + settings.setProperty("multi_values", new String[] {"A,B", null, "C,D"}); String[] array = settings.getStringArray("multi_values"); - assertThat(array).isEqualTo(new String[]{"A,B", "", "C,D"}); + assertThat(array).isEqualTo(new String[] {"A,B", "", "C,D"}); } @Test(expected = IllegalStateException.class) public void shouldFailToSetArrayValueOnSingleValueProperty() { Settings settings = new Settings(definitions); - settings.setProperty("array", new String[]{"A", "B", "C"}); + settings.setProperty("array", new String[] {"A", "B", "C"}); } @Test @@ -216,7 +214,7 @@ public class SettingsTest { Settings settings = new Settings(); settings.setProperty("foo", " one, two, three "); String[] array = settings.getStringArray("foo"); - assertThat(array).isEqualTo(new String[]{"one", "two", "three"}); + assertThat(array).isEqualTo(new String[] {"one", "two", "three"}); } @Test @@ -224,7 +222,7 @@ public class SettingsTest { Settings settings = new Settings(); settings.setProperty("foo", " one, , two"); String[] array = settings.getStringArray("foo"); - assertThat(array).isEqualTo(new String[]{"one", "", "two"}); + assertThat(array).isEqualTo(new String[] {"one", "", "two"}); } @Test @@ -282,34 +280,34 @@ public class SettingsTest { public void getStringLines_single_line() { Settings settings = new Settings(); settings.setProperty("foo", "the line"); - assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"the line"}); + assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"the line"}); } @Test public void getStringLines_linux() { Settings settings = new Settings(); settings.setProperty("foo", "one\ntwo"); - assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"one", "two"}); + assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two"}); settings.setProperty("foo", "one\ntwo\n"); - assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"one", "two"}); + assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two"}); } @Test public void getStringLines_windows() { Settings settings = new Settings(); settings.setProperty("foo", "one\r\ntwo"); - assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"one", "two"}); + assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two"}); settings.setProperty("foo", "one\r\ntwo\r\n"); - assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"one", "two"}); + assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two"}); } @Test public void getStringLines_mix() { Settings settings = new Settings(); settings.setProperty("foo", "one\r\ntwo\nthree"); - assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"one", "two", "three"}); + assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two", "three"}); } @Test @@ -323,19 +321,4 @@ public class SettingsTest { assertThat(settings.getKeysStartingWith("sonar.jdbc")).containsOnly("sonar.jdbc.url", "sonar.jdbc.username"); assertThat(settings.getKeysStartingWith("other")).hasSize(0); } - - @Test - @Ignore - public void should_get_property_set_value() { - Settings settings = new Settings(definitions); - settings.setProperty("sonar.property_set.jira", - "[{\"set\": {\"name\": \"codehaus_jira\", \"values\": {\"key1\":\"value1\", \"key2\":\"value2\"}}},{\"set\": {\"name\": \"other\", \"values\": {\"key3\":\"value3\"}}}]"); - - settings.setProperty("sonar.jira", "codehaus_jira"); - assertThat(settings.getPropertySetValue("sonar.jira").getString("key1")).isEqualTo("value1"); - assertThat(settings.getPropertySetValue("sonar.jira").getString("key2")).isEqualTo("value2"); - - settings.setProperty("sonar.jira", "other"); - assertThat(settings.getPropertySetValue("sonar.jira").getString("key3")).isEqualTo("value3"); - } } |