From 57c87a64a0a545ad81f3859b57d4962260ef6ee3 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Mon, 1 Oct 2012 10:58:42 +0200 Subject: [PATCH] SONAR-3529 Better look. Use field property type --- .../org/sonar/plugins/core/CorePlugin.java | 1 + .../java/org/sonar/api/PropertyField.java | 10 ++++++- .../sonar/api/config/PropertyDefinition.java | 4 +++ .../api/config/PropertyFieldDefinition.java | 7 ++++- .../WEB-INF/app/helpers/settings_helper.rb | 20 ++++++++++--- .../webapp/WEB-INF/app/models/property.rb | 2 +- .../app/views/settings/_properties.html.erb | 4 +-- .../app/views/settings/_set_instance.html.erb | 22 +++++++++++++++ .../app/views/settings/_settings.html.erb | 2 +- .../app/views/settings/_single_value.html.erb | 2 +- .../app/views/settings/_type_BOOLEAN.html.erb | 2 +- .../app/views/settings/_type_FLOAT.html.erb | 2 +- .../app/views/settings/_type_INTEGER.html.erb | 2 +- .../app/views/settings/_type_LICENSE.html.erb | 4 +-- .../app/views/settings/_type_METRIC.html.erb | 2 +- .../views/settings/_type_PASSWORD.html.erb | 2 +- .../settings/_type_PROPERTY_SET.html.erb | 2 +- .../_type_PROPERTY_SET_DEFINITION.html.erb | 28 ++----------------- .../_type_REGULAR_EXPRESSION.html.erb | 2 +- .../_type_SINGLE_SELECT_LIST.html.erb | 2 +- .../app/views/settings/_type_STRING.html.erb | 2 +- .../app/views/settings/_type_TEXT.html.erb | 2 +- .../src/main/webapp/stylesheets/style.css | 20 +++++++++++++ 23 files changed, 97 insertions(+), 49 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/settings/_set_instance.html.erb 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 10ab1cbb509..e10206e7952 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 @@ -133,6 +133,7 @@ import java.util.List; @PropertyField( key = "url", name = "Url", + description = "l'url du serveur jira", type = PropertyType.STRING), @PropertyField( key = "port", diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/PropertyField.java b/sonar-plugin-api/src/main/java/org/sonar/api/PropertyField.java index 4f2c9e18dce..c8114b724da 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/PropertyField.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/PropertyField.java @@ -33,7 +33,7 @@ import java.lang.annotation.Target; @Target(ElementType.TYPE) public @interface PropertyField { /** - * Unique key within a property. + * Unique key within a property. It shouldn't be prefixed. */ String key(); @@ -42,8 +42,16 @@ public @interface PropertyField { */ String defaultValue() default ""; + /** + * This name will be displayed on the Settings page. This can be overridden/translated + * by adding a a value for: field.{key of parent property}.{key of this field}.name in the language bundle. + */ String name(); + /** + * If not empty, this description will be displayed on the Settings page. This can be overridden/translated + * by adding a a value for: field.{key of parent property}.{key of this field}.description in the language bundle. + */ String description() default ""; PropertyType type() default PropertyType.STRING; 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 7e497b49aaa..6025d79bd44 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 @@ -114,6 +114,10 @@ public final class PropertyDefinition { } public Result validate(@Nullable String value) { + return validate(type, value, options); + } + + static Result validate(PropertyType type, @Nullable String value, String[] options) { if (StringUtils.isNotBlank(value)) { if (type == PropertyType.BOOLEAN) { if (!StringUtils.equalsIgnoreCase(value, "true") && !StringUtils.equalsIgnoreCase(value, "false")) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java index 51775b7fe4a..2a941b7a71c 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java @@ -22,6 +22,8 @@ package org.sonar.api.config; import org.sonar.api.PropertyField; import org.sonar.api.PropertyType; +import javax.annotation.Nullable; + /** * @since 3.3 */ @@ -56,7 +58,6 @@ public final class PropertyFieldDefinition { return definitions; } - public String getKey() { return key; } @@ -80,4 +81,8 @@ public final class PropertyFieldDefinition { public String getDescription() { return description; } + + public PropertyDefinition.Result validate(@Nullable String value) { + return PropertyDefinition.validate(type, value, options); + } } 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 d6eb4b4345a..3376c8807d2 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 @@ -23,15 +23,23 @@ module SettingsHelper end def property_name(property) - message("property.#{property.key()}.name", :default => property.name()) + message("property.#{property.key}.name", :default => property.name()) end def property_description(property) - message("property.#{property.key()}.description", :default => property.description()) + message("property.#{property.key}.description", :default => property.description) + end + + def field_name(property, field) + message("field.#{property.key}.#{field.key}.name", :default => field.name) + end + + def field_description(property, field) + message("field.#{property.key}.#{field.key}.description", :default => field.description) end def property_help(property) - message("property.#{property.key()}.help", :default => '') + message("property.#{property.key}.help", :default => '') end def property_value(property) @@ -60,6 +68,10 @@ module SettingsHelper end def input_name(property) - "settings[#{h property.key}]" + (property.multi_values ? '[]' : '') + name = "settings[#{h property.key}]" + if property.multi_values + name += '[]' + end + name end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/property.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/property.rb index ec98d312c9a..e4bec485aaf 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/property.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/property.rb @@ -157,7 +157,7 @@ class Property < ActiveRecord::Base def validate if java_definition - validation_result=java_definition.validate(text_value) + validation_result = java_definition.validate(text_value) errors.add_to_base(validation_result.getErrorKey()) unless validation_result.isValid() end 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 8bc051e7339..5d2e340b5c3 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 @@ -28,7 +28,7 @@ <% value = property_value(property) -%> <% if property.multi_values -%> - <% value.each_with_index do |sub_value, index| -%> + <% value.each do |sub_value| -%> <%= render "settings/multi_value", :property => property, :value => sub_value, :delete_link => true -%> <% end -%>