@Property(
key = "sonar.test.jira.servers",
name = "Jira Servers",
+ description = "List of jira server definitions",
global = true,
project = true,
category = "DEV",
fields = {
+ @PropertyField(
+ key = "key",
+ name = "Key",
+ type = PropertyType.STRING,
+ indicativeSize = 10),
@PropertyField(
key = "url",
name = "Url",
description = "l'url du serveur jira",
- type = PropertyType.STRING),
+ type = PropertyType.STRING,
+ indicativeSize = 20),
@PropertyField(
key = "port",
name = "Port",
- type = PropertyType.INTEGER)}),
+ type = PropertyType.INTEGER,
+ indicativeSize = 5)}),
+ @Property(
+ key = "sonar.demo",
+ name = "Demo",
+ global = true,
+ project = true,
+ category = "DEV",
+ fields = {
+ @PropertyField(
+ key = "text",
+ name = "text",
+ type = PropertyType.TEXT),
+ @PropertyField(
+ key = "boolean",
+ name = "boolean",
+ type = PropertyType.BOOLEAN),
+ @PropertyField(
+ key = "float",
+ name = "float",
+ type = PropertyType.FLOAT),
+ @PropertyField(
+ key = "license",
+ name = "license",
+ type = PropertyType.LICENSE),
+ @PropertyField(
+ key = "metric",
+ name = "metric",
+ type = PropertyType.METRIC),
+ @PropertyField(
+ key = "password",
+ name = "password",
+ type = PropertyType.PASSWORD),
+ @PropertyField(
+ key = "regexp",
+ name = "regexp",
+ type = PropertyType.REGULAR_EXPRESSION),
+ @PropertyField(
+ key = "list",
+ name = "list",
+ type = PropertyType.SINGLE_SELECT_LIST,
+ options = {"AAA", "BBB"})}),
@Property(
key = "sonar.test.jira",
name = "Jira",
*/
String description() default "";
+ /**
+ * Indicative size of the field value in characters. This size is not validated, it is merely used by the GUI
+ * to size the different input fields of a property set.
+ */
+ int indicativeSize() default 20;
+
PropertyType type() default PropertyType.STRING;
/**
*/
package org.sonar.api.config;
+import com.google.common.collect.Lists;
import org.sonar.api.PropertyField;
import org.sonar.api.PropertyType;
import javax.annotation.Nullable;
+import java.util.List;
+
/**
* @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 final String key;
+ private final String defaultValue;
+ private final String name;
+ private final String description;
+ private final int indicativeSize;
+ private final PropertyType type;
+ private final String[] options;
private PropertyFieldDefinition(PropertyField annotation) {
this.key = annotation.key();
- this.name = annotation.name();
this.defaultValue = annotation.defaultValue();
+ this.name = annotation.name();
this.description = annotation.description();
+ this.indicativeSize = annotation.indicativeSize();
this.type = annotation.type();
this.options = annotation.options();
}
- public static PropertyFieldDefinition create(PropertyField annotation) {
- return new PropertyFieldDefinition(annotation);
- }
-
public static PropertyFieldDefinition[] create(PropertyField[] fields) {
- PropertyFieldDefinition[] definitions = new PropertyFieldDefinition[fields.length];
-
- for (int i = 0; i < fields.length; i++) {
- definitions[i] = create(fields[i]);
+ List<PropertyFieldDefinition> definitions = Lists.newArrayList();
+ for (PropertyField field : fields) {
+ definitions.add(new PropertyFieldDefinition(field));
}
-
- return definitions;
+ return definitions.toArray(new PropertyFieldDefinition[definitions.size()]);
}
public String getKey() {
return name;
}
+ public String getDescription() {
+ return description;
+ }
+
+ public int getIndicativeSize() {
+ return indicativeSize;
+ }
+
public PropertyType getType() {
return type;
}
return options.clone();
}
- public String getDescription() {
- return description;
- }
-
public PropertyDefinition.Result validate(@Nullable String value) {
return PropertyDefinition.validate(type, value, options);
}
@Properties(@Property(key = "hello", name = "Hello", fields = {
@PropertyField(key = "first", name = "First", description = "Description", options = {"A", "B"}),
- @PropertyField(key = "second", name = "Second", type = PropertyType.INTEGER)}))
+ @PropertyField(key = "second", name = "Second", type = PropertyType.INTEGER, indicativeSize = 5)}))
static class WithPropertySet {
}
assertThat(def.getFields()[0].getDescription()).isEqualTo("Description");
assertThat(def.getFields()[0].getType()).isEqualTo(PropertyType.STRING);
assertThat(def.getFields()[0].getOptions()).containsOnly("A", "B");
+ assertThat(def.getFields()[0].getIndicativeSize()).isEqualTo(20);
assertThat(def.getFields()[1].getKey()).isEqualTo("second");
assertThat(def.getFields()[1].getName()).isEqualTo("Second");
assertThat(def.getFields()[1].getType()).isEqualTo(PropertyType.INTEGER);
assertThat(def.getFields()[1].getOptions()).isEmpty();
+ assertThat(def.getFields()[1].getIndicativeSize()).isEqualTo(5);
}
@Properties(@Property(key = "hello", name = "Hello"))
if @extension.getId()=='violations'
render_violations()
elsif (@extension.getId()=='coverage')
- puts '-------------------------------------------'
render_coverage()
elsif (@extension.getId()=='source')
render_source()
def update_property_sets(resource_id)
(params[:property_sets] || []).each do |key, set_keys|
- Property.with_key_prefix(key + '.').with_resource(resource_id).delete_all
- update_property(key, set_keys, resource_id)
+ Property.transaction do
+ # clear
+ Property.with_key_prefix(key + '.').with_resource(resource_id).delete_all
+
+ # set keys
+ update_property(key, set_keys, resource_id)
+ set_keys.each do |set_key|
+ update_property("#{key}.#{set_key}.key", set_key, resource_id)
+ end
- params[key].each do |field_key, field_values|
- field_values.zip(set_keys).each do |field_value, set_key|
- if set_key
- update_property("#{key}.#{set_key}.#{field_key}", field_value, resource_id)
+ # set fields
+ params[key].each do |field_key, field_values|
+ field_values.zip(set_keys).each do |field_value, set_key|
+ if set_key
+ update_property("#{key}.#{set_key}.#{field_key}", field_value, resource_id)
+ end
end
end
end
message("field.#{property.key}.#{field.key}.description", :default => field.description)
end
+ def key_field(property)
+ property.fields.find { |f| f.key == 'key' }
+ end
+
def option_name(property, field, option)
if field
message("option.#{property.key}.#{field.key}.#{option}.name", :default => option)
<% errors = [] -%>
+<% key_field = key_field(property) -%>
-<tr class="multi_value <%= 'template' unless set_key -%>" style="<%= 'display:none' unless set_key -%>">
- <td><%= text_field_tag "property_sets[#{property.key}][]", set_key, :size => 50 -%></td>
+<tr class="top multi_value <%= 'template' unless set_key -%>" style="<%= 'display:none' unless set_key -%>">
+ <% if key_field -%>
+ <td><%= render "settings/type_#{key_field.type}", :property => key_field, :field => key_field, :value => set_key, :name => "property_sets[#{property.key}][]", :id => "input_#{h key_field.key}", :size => key_field.indicativeSize -%></td>
+ <% else -%>
+ <%= hidden_field_tag "property_sets[#{property.key}][]", set_key -%>
+ <% end -%>
- <% property.fields.each do |field| -%>
+ <% property.fields.reject { |field| field.key == 'key' }.each do |field| -%>
<% key = "#{property.key}.#{set_key}.#{field.key}" if set_key -%>
<% value = Property.value(key, resource_id) if set_key -%>
- <td><%= render "settings/type_#{field.type}", :property => field, :field => field, :value => value, :name => "#{property.key}[#{field.key}][]", :id => "input_#{h field.key}" -%></td>
+ <td><%= render "settings/type_#{field.type}", :property => field, :field => field, :value => value, :name => "#{property.key}[#{field.key}][]", :id => "input_#{h field.key}", :size => field.indicativeSize -%></td>
<% errors << (render "settings/error", :key => key) if set_key -%>
<% end -%>
<% unless errors.all?(&:blank?) -%>
<tr>
- <td></td>
+ <% if key_field -%>
+ <td></td>
+ <% end -%>
+
<% errors.each do |error| -%>
<td><%= error -%></td>
<% end -%>
+
<td></td>
</tr>
<% end -%>
-<input type="text" name="<%= name -%>" value="<%= h value if value -%>" size="50" id="<%= id -%>"/>
\ No newline at end of file
+<input type="text" name="<%= name -%>" value="<%= h value if value -%>" size="<%= (defined? size) ? size : 50 -%>" id="<%= id -%>"/>
\ No newline at end of file
-<input type="text" name="<%= name -%>" value="<%= h value if value -%>" size="50" id="<%= id-%>"/>
\ No newline at end of file
+<input type="text" name="<%= name -%>" value="<%= h value if value -%>" size="<%= (defined? size) ? size : 50 -%>" id="<%= id-%>"/>
\ No newline at end of file
-<input type="password" name="<%= name -%>" value="<%= h value if value -%>" size="50" id="<%= id -%>"/>
\ No newline at end of file
+<input type="password" name="<%= name -%>" value="<%= h value if value -%>" size="<%= defined? size ? size : 50-%>" id="<%= id -%>"/>
\ No newline at end of file
<table class="data">
<thead>
<tr>
- <th><%= message('key') -%></th>
- <% property.fields.each do |field| -%>
+ <% if key_field(property) -%>
+ <th><%= message('key') -%></th>
+ <% end -%>
+ <% property.fields.reject { |field| field.key == 'key' }.each do |field| -%>
<th>
<%= field_name(property, field) -%>
<% desc = field_description(property, field) -%>
<%= render 'settings/set_instance', :property => property, :set_key => set_key, :resource_id => resource_id %>
<% end -%>
<%= render 'settings/set_instance', :property => property, :set_key => nil, :resource_id => resource_id %>
-
</tbody>
<tfoot>
<tr>
- <td>
+ <td colspan="<%= property.fields.size + 1 -%>">
<button class="add_value"><%= message('settings.add') -%></button>
</td>
</tr>
-<input type="text" name="<%= name -%>" value="<%= h value if value -%>" size="50" id="<%= id -%>"/>
\ No newline at end of file
+<input type="text" name="<%= name -%>" value="<%= h value if value -%>" size="<%= (defined? size) ? size : 50 -%>" id="<%= id -%>"/>
\ No newline at end of file
-<input type="text" name="<%= name -%>" value="<%= h value if value -%>" size="50" id="<%= id -%>"/>
\ No newline at end of file
+<input type="text" name="<%= name -%>" value="<%= h value if value -%>" size="<%= (defined? size) ? size : 50 -%>" id="<%= id -%>"/>
\ No newline at end of file
-<textarea rows="5" cols="80" class="width100" name="<%= name -%>" id="<%= id -%>"><%= h value if value -%></textarea>
\ No newline at end of file
+<textarea rows="5" cols="<%= (defined? size) ? size : 80 -%>" class="width100" name="<%= name -%>" id="<%= id -%>"><%= h value if value -%></textarea>
\ No newline at end of file
.coverage td.name {
text-align: right;
}
+
+.property table.data > tbody > tr > td {
+ vertical-align: top;
+}
+
+.property table.data {
+ width: auto;
+ min-width: 600px;
+}
\ No newline at end of file