From 9c854f825217360854b7878a28a21dc9a8c5c19b Mon Sep 17 00:00:00 2001 From: David Gageot Date: Fri, 28 Sep 2012 13:35:23 +0200 Subject: [PATCH] SONAR-3529 Get rid of property sets. Use PropertyFields instead --- .../org/sonar/plugins/core/CorePlugin.java | 300 +++++++++++------- .../org/sonar/batch/ProjectConfigurator.java | 5 +- .../sonar/batch/config/ProjectSettings.java | 1 - .../sonar/batch/ProjectConfiguratorTest.java | 1 - .../src/main/java/org/sonar/api/Property.java | 12 +- ...rtySetTemplate.java => PropertyField.java} | 34 +- .../sonar/api/config/PropertyDefinition.java | 17 +- ...ield.java => PropertyFieldDefinition.java} | 67 ++-- .../org/sonar/api/config/PropertySet.java | 37 --- .../api/config/PropertySetDefinitions.java | 50 --- .../sonar/api/config/PropertySetValue.java | 117 ------- .../java/org/sonar/api/config/Settings.java | 29 +- .../api/config/TestPropertySetTemplate.java | 34 -- .../org/sonar/api/profiles/RulesProfile.java | 11 +- .../api/config/PropertyDefinitionTest.java | 22 +- .../config/PropertySetDefinitionsTest.java | 54 ---- .../api/config/PropertySetFieldTest.java | 48 --- .../org/sonar/api/config/PropertySetTest.java | 39 --- .../api/config/PropertySetValueTest.java | 63 ---- .../org/sonar/api/config/SettingsTest.java | 59 ++-- .../org/sonar/server/platform/Platform.java | 34 +- .../server/startup/RegisterPropertySets.java | 50 --- .../java/org/sonar/server/ui/JRubyFacade.java | 37 ++- .../WEB-INF/app/helpers/settings_helper.rb | 5 - .../webapp/WEB-INF/app/models/property_set.rb | 47 --- .../app/views/settings/_multi_value.html.erb | 2 +- .../app/views/settings/_properties.html.erb | 2 +- .../app/views/settings/_single_value.html.erb | 5 + .../settings/_type_PROPERTY_SET.html.erb | 12 +- .../_type_PROPERTY_SET_DEFINITION.html.erb | 17 + .../startup/RegisterPropertySetsTest.java | 55 ---- 31 files changed, 416 insertions(+), 850 deletions(-) rename sonar-plugin-api/src/main/java/org/sonar/api/{config/PropertySetTemplate.java => PropertyField.java} (57%) rename sonar-plugin-api/src/main/java/org/sonar/api/config/{PropertySetField.java => PropertyFieldDefinition.java} (51%) delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySet.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySetDefinitions.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySetValue.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/config/TestPropertySetTemplate.java delete mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetDefinitionsTest.java delete mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetFieldTest.java delete mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetTest.java delete mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetValueTest.java delete mode 100644 sonar-server/src/main/java/org/sonar/server/startup/RegisterPropertySets.java delete mode 100644 sonar-server/src/main/webapp/WEB-INF/app/models/property_set.rb create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/settings/_single_value.html.erb create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET_DEFINITION.html.erb delete mode 100644 sonar-server/src/test/java/org/sonar/server/startup/RegisterPropertySetsTest.java diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java index d1647af4994..10ab1cbb509 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java @@ -20,10 +20,14 @@ package org.sonar.plugins.core; import com.google.common.collect.ImmutableList; -import org.sonar.api.*; +import org.sonar.api.CoreProperties; +import org.sonar.api.Extension; +import org.sonar.api.Properties; +import org.sonar.api.Property; +import org.sonar.api.PropertyField; +import org.sonar.api.PropertyType; +import org.sonar.api.SonarPlugin; import org.sonar.api.checks.NoSonarFilter; -import org.sonar.api.config.PropertySetDefinitions; -import org.sonar.api.config.TestPropertySetTemplate; import org.sonar.api.resources.Java; import org.sonar.plugins.core.batch.ExcludedResourceFilter; import org.sonar.plugins.core.batch.IndexProjectPostJob; @@ -33,19 +37,80 @@ import org.sonar.plugins.core.charts.DistributionAreaChart; import org.sonar.plugins.core.charts.DistributionBarChart; import org.sonar.plugins.core.charts.XradarChart; import org.sonar.plugins.core.colorizers.JavaColorizerFormat; -import org.sonar.plugins.core.dashboards.*; +import org.sonar.plugins.core.dashboards.DefaultDashboard; +import org.sonar.plugins.core.dashboards.HotspotsDashboard; +import org.sonar.plugins.core.dashboards.MyFavouritesDashboard; +import org.sonar.plugins.core.dashboards.ProjectsDashboard; +import org.sonar.plugins.core.dashboards.ReviewsDashboard; +import org.sonar.plugins.core.dashboards.TimeMachineDashboard; +import org.sonar.plugins.core.dashboards.TreemapDashboard; import org.sonar.plugins.core.filters.MyFavouritesFilter; import org.sonar.plugins.core.filters.ProjectFilter; import org.sonar.plugins.core.filters.TreeMapFilter; import org.sonar.plugins.core.security.ApplyProjectRolesDecorator; import org.sonar.plugins.core.security.DefaultResourcePermissions; -import org.sonar.plugins.core.sensors.*; +import org.sonar.plugins.core.sensors.BranchCoverageDecorator; +import org.sonar.plugins.core.sensors.CheckAlertThresholds; +import org.sonar.plugins.core.sensors.CommentDensityDecorator; +import org.sonar.plugins.core.sensors.CoverageDecorator; +import org.sonar.plugins.core.sensors.DirectoriesDecorator; +import org.sonar.plugins.core.sensors.FilesDecorator; +import org.sonar.plugins.core.sensors.GenerateAlertEvents; +import org.sonar.plugins.core.sensors.ItBranchCoverageDecorator; +import org.sonar.plugins.core.sensors.ItCoverageDecorator; +import org.sonar.plugins.core.sensors.ItLineCoverageDecorator; +import org.sonar.plugins.core.sensors.LineCoverageDecorator; +import org.sonar.plugins.core.sensors.ManualMeasureDecorator; +import org.sonar.plugins.core.sensors.ManualViolationInjector; +import org.sonar.plugins.core.sensors.ProfileEventsSensor; +import org.sonar.plugins.core.sensors.ProfileSensor; +import org.sonar.plugins.core.sensors.ProjectLinksSensor; +import org.sonar.plugins.core.sensors.ReviewNotifications; +import org.sonar.plugins.core.sensors.ReviewWorkflowDecorator; +import org.sonar.plugins.core.sensors.ReviewsMeasuresDecorator; +import org.sonar.plugins.core.sensors.UnitTestDecorator; +import org.sonar.plugins.core.sensors.VersionEventsSensor; +import org.sonar.plugins.core.sensors.ViolationSeverityUpdater; +import org.sonar.plugins.core.sensors.ViolationsDecorator; +import org.sonar.plugins.core.sensors.ViolationsDensityDecorator; +import org.sonar.plugins.core.sensors.WeightedViolationsDecorator; import org.sonar.plugins.core.testdetailsviewer.TestsViewerDefinition; -import org.sonar.plugins.core.timemachine.*; +import org.sonar.plugins.core.timemachine.NewCoverageAggregator; +import org.sonar.plugins.core.timemachine.NewCoverageFileAnalyzer; +import org.sonar.plugins.core.timemachine.NewItCoverageFileAnalyzer; +import org.sonar.plugins.core.timemachine.NewViolationsDecorator; +import org.sonar.plugins.core.timemachine.ReferenceAnalysis; +import org.sonar.plugins.core.timemachine.TendencyDecorator; +import org.sonar.plugins.core.timemachine.TimeMachineConfigurationPersister; +import org.sonar.plugins.core.timemachine.VariationDecorator; +import org.sonar.plugins.core.timemachine.ViolationPersisterDecorator; +import org.sonar.plugins.core.timemachine.ViolationTrackingDecorator; import org.sonar.plugins.core.web.Lcom4Viewer; -import org.sonar.plugins.core.widgets.*; +import org.sonar.plugins.core.widgets.AlertsWidget; +import org.sonar.plugins.core.widgets.CommentsDuplicationsWidget; +import org.sonar.plugins.core.widgets.ComplexityWidget; +import org.sonar.plugins.core.widgets.CoverageWidget; +import org.sonar.plugins.core.widgets.CustomMeasuresWidget; +import org.sonar.plugins.core.widgets.DescriptionWidget; +import org.sonar.plugins.core.widgets.EventsWidget; +import org.sonar.plugins.core.widgets.FilterWidget; +import org.sonar.plugins.core.widgets.HotspotMetricWidget; +import org.sonar.plugins.core.widgets.HotspotMostViolatedResourcesWidget; +import org.sonar.plugins.core.widgets.HotspotMostViolatedRulesWidget; +import org.sonar.plugins.core.widgets.ItCoverageWidget; +import org.sonar.plugins.core.widgets.RulesWidget; +import org.sonar.plugins.core.widgets.SizeWidget; +import org.sonar.plugins.core.widgets.TimeMachineWidget; +import org.sonar.plugins.core.widgets.TimelineWidget; +import org.sonar.plugins.core.widgets.TreemapWidget; import org.sonar.plugins.core.widgets.actionPlans.ActionPlansWidget; -import org.sonar.plugins.core.widgets.reviews.*; +import org.sonar.plugins.core.widgets.reviews.FalsePositiveReviewsWidget; +import org.sonar.plugins.core.widgets.reviews.MyReviewsWidget; +import org.sonar.plugins.core.widgets.reviews.PlannedReviewsWidget; +import org.sonar.plugins.core.widgets.reviews.ProjectReviewsWidget; +import org.sonar.plugins.core.widgets.reviews.ReviewsMetricsWidget; +import org.sonar.plugins.core.widgets.reviews.ReviewsPerDeveloperWidget; +import org.sonar.plugins.core.widgets.reviews.UnplannedReviewsWidget; import java.util.List; @@ -59,12 +124,27 @@ import java.util.List; global = true, category = CoreProperties.CATEGORY_GENERAL), @Property( - key = "toto", - name = "Toto", + key = "sonar.test.jira.servers", + name = "Jira Servers", global = true, + project = true, + category = "DEV", + fields = { + @PropertyField( + key = "url", + name = "Url", + type = PropertyType.STRING), + @PropertyField( + key = "port", + name = "Port", + type = PropertyType.INTEGER)}), + @Property( + key = "sonar.test.jira", + name = "Jira", + project = true, + category = "DEV", type = PropertyType.PROPERTY_SET, - propertySetName = "myset", - category = CoreProperties.CATEGORY_GENERAL), + propertySetKey = "sonar.test.jira.servers"), @Property( key = CoreProperties.PROJECT_LANGUAGE_PROPERTY, defaultValue = Java.KEY, @@ -254,115 +334,111 @@ public final class CorePlugin extends SonarPlugin { @SuppressWarnings("unchecked") public List> getExtensions() { return ImmutableList.of( - DefaultResourceTypes.class, - UserManagedMetrics.class, - ProjectFileSystemLogger.class, - - // maven - MavenInitializer.class, + DefaultResourceTypes.class, + UserManagedMetrics.class, + ProjectFileSystemLogger.class, - // languages - Java.class, + // maven + MavenInitializer.class, - // pages - TestsViewerDefinition.class, - Lcom4Viewer.class, + // languages + Java.class, - // filters - ProjectFilter.class, - TreeMapFilter.class, - MyFavouritesFilter.class, + // pages + TestsViewerDefinition.class, + Lcom4Viewer.class, - // widgets - AlertsWidget.class, - CoverageWidget.class, - ItCoverageWidget.class, - CommentsDuplicationsWidget.class, - DescriptionWidget.class, - ComplexityWidget.class, - RulesWidget.class, - SizeWidget.class, - EventsWidget.class, - CustomMeasuresWidget.class, - TimelineWidget.class, - TimeMachineWidget.class, - HotspotMetricWidget.class, - HotspotMostViolatedResourcesWidget.class, - HotspotMostViolatedRulesWidget.class, - MyReviewsWidget.class, - ProjectReviewsWidget.class, - FalsePositiveReviewsWidget.class, - ReviewsPerDeveloperWidget.class, - PlannedReviewsWidget.class, - UnplannedReviewsWidget.class, - ActionPlansWidget.class, - ReviewsMetricsWidget.class, - TreemapWidget.class, - FilterWidget.class, + // filters + ProjectFilter.class, + TreeMapFilter.class, + MyFavouritesFilter.class, - // dashboards - DefaultDashboard.class, - HotspotsDashboard.class, - ReviewsDashboard.class, - TimeMachineDashboard.class, - ProjectsDashboard.class, - TreemapDashboard.class, - MyFavouritesDashboard.class, + // widgets + AlertsWidget.class, + CoverageWidget.class, + ItCoverageWidget.class, + CommentsDuplicationsWidget.class, + DescriptionWidget.class, + ComplexityWidget.class, + RulesWidget.class, + SizeWidget.class, + EventsWidget.class, + CustomMeasuresWidget.class, + TimelineWidget.class, + TimeMachineWidget.class, + HotspotMetricWidget.class, + HotspotMostViolatedResourcesWidget.class, + HotspotMostViolatedRulesWidget.class, + MyReviewsWidget.class, + ProjectReviewsWidget.class, + FalsePositiveReviewsWidget.class, + ReviewsPerDeveloperWidget.class, + PlannedReviewsWidget.class, + UnplannedReviewsWidget.class, + ActionPlansWidget.class, + ReviewsMetricsWidget.class, + TreemapWidget.class, + FilterWidget.class, - // Property sets - PropertySetDefinitions.class, - TestPropertySetTemplate.class, + // dashboards + DefaultDashboard.class, + HotspotsDashboard.class, + ReviewsDashboard.class, + TimeMachineDashboard.class, + ProjectsDashboard.class, + TreemapDashboard.class, + MyFavouritesDashboard.class, - // chart - XradarChart.class, - DistributionBarChart.class, - DistributionAreaChart.class, + // chart + XradarChart.class, + DistributionBarChart.class, + DistributionAreaChart.class, - // colorizers - JavaColorizerFormat.class, + // colorizers + JavaColorizerFormat.class, - // batch - ProfileSensor.class, - ProfileEventsSensor.class, - ProjectLinksSensor.class, - UnitTestDecorator.class, - VersionEventsSensor.class, - CheckAlertThresholds.class, - GenerateAlertEvents.class, - ViolationsDecorator.class, - WeightedViolationsDecorator.class, - ViolationsDensityDecorator.class, - LineCoverageDecorator.class, - CoverageDecorator.class, - BranchCoverageDecorator.class, - ItLineCoverageDecorator.class, - ItCoverageDecorator.class, - ItBranchCoverageDecorator.class, - DefaultResourcePermissions.class, - ApplyProjectRolesDecorator.class, - ExcludedResourceFilter.class, - CommentDensityDecorator.class, - NoSonarFilter.class, - DirectoriesDecorator.class, - FilesDecorator.class, - ReviewNotifications.class, - ReviewWorkflowDecorator.class, - ReferenceAnalysis.class, - ManualMeasureDecorator.class, - ManualViolationInjector.class, - ViolationSeverityUpdater.class, - IndexProjectPostJob.class, - ReviewsMeasuresDecorator.class, + // batch + ProfileSensor.class, + ProfileEventsSensor.class, + ProjectLinksSensor.class, + UnitTestDecorator.class, + VersionEventsSensor.class, + CheckAlertThresholds.class, + GenerateAlertEvents.class, + ViolationsDecorator.class, + WeightedViolationsDecorator.class, + ViolationsDensityDecorator.class, + LineCoverageDecorator.class, + CoverageDecorator.class, + BranchCoverageDecorator.class, + ItLineCoverageDecorator.class, + ItCoverageDecorator.class, + ItBranchCoverageDecorator.class, + DefaultResourcePermissions.class, + ApplyProjectRolesDecorator.class, + ExcludedResourceFilter.class, + CommentDensityDecorator.class, + NoSonarFilter.class, + DirectoriesDecorator.class, + FilesDecorator.class, + ReviewNotifications.class, + ReviewWorkflowDecorator.class, + ReferenceAnalysis.class, + ManualMeasureDecorator.class, + ManualViolationInjector.class, + ViolationSeverityUpdater.class, + IndexProjectPostJob.class, + ReviewsMeasuresDecorator.class, - // time machine - TendencyDecorator.class, - VariationDecorator.class, - ViolationTrackingDecorator.class, - ViolationPersisterDecorator.class, - NewViolationsDecorator.class, - TimeMachineConfigurationPersister.class, - NewCoverageFileAnalyzer.class, - NewItCoverageFileAnalyzer.class, - NewCoverageAggregator.class); + // time machine + TendencyDecorator.class, + VariationDecorator.class, + ViolationTrackingDecorator.class, + ViolationPersisterDecorator.class, + NewViolationsDecorator.class, + TimeMachineConfigurationPersister.class, + NewCoverageFileAnalyzer.class, + NewItCoverageFileAnalyzer.class, + NewCoverageAggregator.class); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java index 1ea83f62df9..7ef42fbd60e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java @@ -19,8 +19,6 @@ */ package org.sonar.batch; -import java.util.Date; - import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.commons.lang.StringUtils; import org.apache.maven.project.MavenProject; @@ -31,10 +29,11 @@ import org.sonar.api.config.Settings; import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.ResourceModel; import org.sonar.api.database.model.Snapshot; -import org.sonar.api.resources.Java; import org.sonar.api.resources.Project; import org.sonar.api.utils.SonarException; +import java.util.Date; + public class ProjectConfigurator implements BatchComponent { private DatabaseSession databaseSession; diff --git a/sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java b/sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java index 95822bcb32a..09496102faf 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java +++ b/sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java @@ -26,7 +26,6 @@ import org.sonar.api.CoreProperties; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.config.Settings; -import org.sonar.api.resources.Java; import org.sonar.api.resources.Project; import org.sonar.batch.bootstrap.ProjectInitializer; import org.sonar.core.config.ConfigurationUtils; diff --git a/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java index 4db0e9f4c5a..3b0db7ee945 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java @@ -22,7 +22,6 @@ package org.sonar.batch; import org.junit.Test; import org.sonar.api.CoreProperties; import org.sonar.api.config.Settings; -import org.sonar.api.resources.Java; import org.sonar.api.resources.Project; import org.sonar.jpa.test.AbstractDbUnitTestCase; 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 = PropertyType.PROPERTY_SET. + * A Property of type PropertyType.PROPERTY_SET 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 similarity index 57% rename from sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySetTemplate.java rename to 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 similarity index 51% rename from sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySetField.java rename to 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 fields = Lists.newArrayList(); - - public PropertySet add(PropertySetField field) { - fields.add(field); - return this; - } - - public List 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 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 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 keyValues; - - private PropertySetValue(Map keyValues) { - this.keyValues = ImmutableMap.copyOf(keyValues); - } - - public static PropertySetValue create(Map 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 0 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 false 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 0.0 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 0L 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 null 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 null 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 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 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.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.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"); - } } 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 e6b41748b08..81901dffde6 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 @@ -44,7 +44,11 @@ import org.sonar.core.i18n.I18nManager; import org.sonar.core.i18n.RuleI18nManager; import org.sonar.core.metric.DefaultMetricFinder; import org.sonar.core.notification.DefaultNotificationManager; -import org.sonar.core.persistence.*; +import org.sonar.core.persistence.DaoUtils; +import org.sonar.core.persistence.DatabaseMigrator; +import org.sonar.core.persistence.DatabaseVersion; +import org.sonar.core.persistence.DefaultDatabase; +import org.sonar.core.persistence.MyBatis; import org.sonar.core.qualitymodel.DefaultModelFinder; import org.sonar.core.rule.DefaultRuleFinder; import org.sonar.core.user.DefaultUserFinder; @@ -64,12 +68,33 @@ import org.sonar.server.database.EmbeddedDatabaseFactory; import org.sonar.server.filters.FilterExecutor; import org.sonar.server.notifications.NotificationService; import org.sonar.server.notifications.reviews.ReviewsNotificationManager; -import org.sonar.server.plugins.*; +import org.sonar.server.plugins.ApplicationDeployer; +import org.sonar.server.plugins.DefaultServerPluginRepository; +import org.sonar.server.plugins.PluginDeployer; +import org.sonar.server.plugins.PluginDownloader; +import org.sonar.server.plugins.ServerExtensionInstaller; +import org.sonar.server.plugins.UpdateCenterClient; +import org.sonar.server.plugins.UpdateCenterMatrixFactory; import org.sonar.server.qualitymodel.DefaultModelManager; import org.sonar.server.rules.ProfilesConsole; import org.sonar.server.rules.RulesConsole; -import org.sonar.server.startup.*; -import org.sonar.server.ui.*; +import org.sonar.server.startup.ActivateDefaultProfiles; +import org.sonar.server.startup.DeleteDeprecatedMeasures; +import org.sonar.server.startup.GeneratePluginIndex; +import org.sonar.server.startup.GwtPublisher; +import org.sonar.server.startup.JdbcDriverDeployer; +import org.sonar.server.startup.RegisterMetrics; +import org.sonar.server.startup.RegisterNewDashboards; +import org.sonar.server.startup.RegisterNewFilters; +import org.sonar.server.startup.RegisterProvidedProfiles; +import org.sonar.server.startup.RegisterQualityModels; +import org.sonar.server.startup.RegisterRules; +import org.sonar.server.startup.ServerMetadataPersister; +import org.sonar.server.ui.CodeColorizers; +import org.sonar.server.ui.JRubyI18n; +import org.sonar.server.ui.PageDecorations; +import org.sonar.server.ui.SecurityRealmFactory; +import org.sonar.server.ui.Views; import javax.servlet.ServletContext; @@ -243,7 +268,6 @@ public final class Platform { startupContainer.addSingleton(GeneratePluginIndex.class); startupContainer.addSingleton(RegisterNewFilters.class); startupContainer.addSingleton(RegisterNewDashboards.class); - startupContainer.addSingleton(RegisterPropertySets.class); startupContainer.startComponents(); startupContainer.getComponentByType(ServerLifecycleNotifier.class).notifyStart(); diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterPropertySets.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterPropertySets.java deleted file mode 100644 index a3a19951391..00000000000 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterPropertySets.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.server.startup; - -import com.google.common.collect.ImmutableList; -import org.sonar.api.config.PropertySetDefinitions; -import org.sonar.api.config.PropertySetTemplate; -import org.sonar.api.utils.TimeProfiler; - -import java.util.List; - -/** - * @since 3.3 - */ -public final class RegisterPropertySets { - private final List propertySetTemplates; - private final PropertySetDefinitions propertySetDefinitions; - - public RegisterPropertySets(PropertySetTemplate[] propertySetTemplates, PropertySetDefinitions propertySetDefinitions) { - this.propertySetTemplates = ImmutableList.copyOf(propertySetTemplates); - this.propertySetDefinitions = propertySetDefinitions; - } - - public void start() { - TimeProfiler profiler = new TimeProfiler().start("Register dashboards"); - - for (PropertySetTemplate template : propertySetTemplates) { - propertySetDefinitions.register(template.getName(), template.createPropertySet()); - } - - profiler.stop(); - } -} diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java index 3738332bdcc..b588f82a924 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java @@ -23,7 +23,9 @@ import com.google.common.collect.ListMultimap; import com.google.common.collect.Lists; import org.slf4j.LoggerFactory; import org.sonar.api.CoreProperties; -import org.sonar.api.config.*; +import org.sonar.api.config.License; +import org.sonar.api.config.PropertyDefinitions; +import org.sonar.api.config.Settings; import org.sonar.api.platform.ComponentContainer; import org.sonar.api.platform.NewUserHandler; import org.sonar.api.platform.PluginMetadata; @@ -36,7 +38,11 @@ import org.sonar.api.resources.ResourceTypes; import org.sonar.api.rules.RulePriority; import org.sonar.api.rules.RuleRepository; import org.sonar.api.utils.ValidationMessages; -import org.sonar.api.web.*; +import org.sonar.api.web.Footer; +import org.sonar.api.web.NavigationSection; +import org.sonar.api.web.Page; +import org.sonar.api.web.RubyRailsWebservice; +import org.sonar.api.web.Widget; import org.sonar.api.workflow.Review; import org.sonar.api.workflow.internal.DefaultReview; import org.sonar.api.workflow.internal.DefaultWorkflowContext; @@ -55,13 +61,22 @@ import org.sonar.server.filters.Filter; import org.sonar.server.filters.FilterExecutor; import org.sonar.server.filters.FilterResult; import org.sonar.server.notifications.reviews.ReviewsNotificationManager; -import org.sonar.server.platform.*; -import org.sonar.server.plugins.*; +import org.sonar.server.platform.NewUserNotifier; +import org.sonar.server.platform.Platform; +import org.sonar.server.platform.ServerIdGenerator; +import org.sonar.server.platform.ServerSettings; +import org.sonar.server.platform.SettingsChangeNotifier; +import org.sonar.server.plugins.DefaultServerPluginRepository; +import org.sonar.server.plugins.PluginDeployer; +import org.sonar.server.plugins.PluginDownloader; +import org.sonar.server.plugins.UpdateCenterMatrix; +import org.sonar.server.plugins.UpdateCenterMatrixFactory; import org.sonar.server.rules.ProfilesConsole; import org.sonar.server.rules.RulesConsole; import org.sonar.updatecenter.common.Version; import javax.annotation.Nullable; + import java.net.InetAddress; import java.sql.Connection; import java.util.Collection; @@ -298,7 +313,7 @@ public final class JRubyFacade { public void ruleSeverityChanged(int parentProfileId, int activeRuleId, int oldSeverityId, int newSeverityId, String userName) { getProfilesManager().ruleSeverityChanged(parentProfileId, activeRuleId, RulePriority.values()[oldSeverityId], - RulePriority.values()[newSeverityId], userName); + RulePriority.values()[newSeverityId], userName); } public void ruleDeactivated(int parentProfileId, int deactivatedRuleId, String userName) { @@ -494,14 +509,10 @@ public final class JRubyFacade { // notifier is null when creating the administrator in the migration script 011. if (notifier != null) { notifier.onNewUser(NewUserHandler.Context.builder() - .setLogin(fields.get("login")) - .setName(fields.get("name")) - .setEmail(fields.get("email")) - .build()); + .setLogin(fields.get("login")) + .setName(fields.get("name")) + .setEmail(fields.get("email")) + .build()); } } - - public List listPropertySets() { - return get(PropertySetDefinitions.class).findAll(); - } } diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb index 4ff3b687e35..ca9c3da8189 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb @@ -57,9 +57,4 @@ module SettingsHelper def input_name(property) h(property.key) + (property.multi_values ? '[]' : '') end - - def property_set_value_names(property) - names = PropertySet.findAll(property.propertySetName).map(&:name); - Api::Utils.insensitive_sort(names) - end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/property_set.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/property_set.rb deleted file mode 100644 index 1defe5dece2..00000000000 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/property_set.rb +++ /dev/null @@ -1,47 +0,0 @@ -# -# Sonar, entreprise quality control 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 {library}; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 -# -class PropertySet < ActiveRecord::Base - attr_accessor :name - - def self.columns - @columns ||= []; - end - - def self.column(name, sql_type = nil, default = nil, null = true) - columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null) - end - - def self.findAll(set_name) - ActiveSupport::JSON.decode(values_as_json(set_name)).map { |set| PropertySet.new(set) } - end - - def save(validate = true) - validate ? valid? : true - end - - private - - def self.values_as_json(set_name) - json = Property.value('sonar.property_set.' + set_name) - - #json || '[]' - json || '[{"name":"set2"},{"name":"set1"}]' - end -end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_multi_value.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_multi_value.html.erb index b98f736a8d0..b2fb09af73d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_multi_value.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_multi_value.html.erb @@ -1,5 +1,5 @@
- <%= render "settings/type_#{property_type(property, value)}", :property => property, :value => value -%> + <%= render "settings/single_value", :property => property, :value => value -%> <% if delete_link -%> <%= message('delete') -%> <% end -%> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb index 458b02c27c2..8bc051e7339 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb @@ -37,7 +37,7 @@
<% else -%> - <%= render "settings/type_#{property_type(property, value)}", :property => property, :value => value -%> + <%= render "settings/single_value", :property => property, :value => value -%> <% end -%> <% p = @updated_properties[property.key] if @updated_properties -%> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_single_value.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_single_value.html.erb new file mode 100644 index 00000000000..0a6a04db28d --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_single_value.html.erb @@ -0,0 +1,5 @@ +<% if property.fields.blank? -%> + <%= render "settings/type_#{property_type(property, value)}", :property => property, :value => value -%> +<% else -%> + <%= render "settings/type_PROPERTY_SET_DEFINITION", :property => property, :value => value -%> +<% end -%> \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET.html.erb index aa9a1bbb2a0..5a5928c9730 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET.html.erb @@ -1,7 +1,7 @@ - - <% property_set_value_names(property).each do |option| %> - - <% end %> - -Edit property set... + + <% Property.values(property.propertySetKey).reject(&:blank?).each do |set_key| -%> + + <% end -%> + \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET_DEFINITION.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET_DEFINITION.html.erb new file mode 100644 index 00000000000..22777ac090f --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET_DEFINITION.html.erb @@ -0,0 +1,17 @@ +<% Property.set('sonar.test.jira.servers', 'jira1,jira2') -%> +<% Property.set('sonar.test.jira.servers.jira1.url', 'http://url1') -%> +<% Property.set('sonar.test.jira.servers.jira1.port', '1234') -%> +<% Property.set('sonar.test.jira.servers.jira2.url', 'http://url2') -%> +<% Property.set('sonar.test.jira.servers.jira2.port', '9999') -%> + +<% Property.values(property.key).reject(&:blank?).each do |set_key| -%> +

<%= set_key -%>

+ + <% property.fields.each do |field| -%> +
+ <% end -%> + + <%= message('delete') -%> +<% end -%> + + diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RegisterPropertySetsTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RegisterPropertySetsTest.java deleted file mode 100644 index b74d1b8eb54..00000000000 --- a/sonar-server/src/test/java/org/sonar/server/startup/RegisterPropertySetsTest.java +++ /dev/null @@ -1,55 +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.server.startup; - -import org.junit.Before; -import org.junit.Test; -import org.sonar.api.config.PropertySet; -import org.sonar.api.config.PropertySetDefinitions; -import org.sonar.api.config.PropertySetTemplate; - -import static org.mockito.Mockito.*; - -public class RegisterPropertySetsTest { - private RegisterPropertySets task; - private PropertySetDefinitions propertySetDefinitions = mock(PropertySetDefinitions.class); - private PropertySetTemplate firstTemplate = mock(PropertySetTemplate.class); - private PropertySetTemplate secondTemplate = mock(PropertySetTemplate.class); - private PropertySet firstPropertySet = mock(PropertySet.class); - private PropertySet secondPropertySet = mock(PropertySet.class); - - @Before - public void init() { - task = new RegisterPropertySets(new PropertySetTemplate[]{firstTemplate, secondTemplate}, propertySetDefinitions); - } - - @Test - public void should_register_on_startup() { - when(firstTemplate.getName()).thenReturn("first"); - when(secondTemplate.getName()).thenReturn("second"); - when(firstTemplate.createPropertySet()).thenReturn(firstPropertySet); - when(secondTemplate.createPropertySet()).thenReturn(secondPropertySet); - - task.start(); - - verify(propertySetDefinitions).register("first", firstPropertySet); - verify(propertySetDefinitions).register("second", secondPropertySet); - } -} -- 2.39.5