private String[] resourceLanguages = {};
private String[] defaultForMetrics = {};
private String description = "";
- private Map<String, WidgetProperty> widgetPropertiesByKey = Maps.newHashMap();
+ private Map<String, WidgetProperty> widgetPropertiesByKey = Maps.newLinkedHashMap();
private String[] widgetCategories = {};
private WidgetLayoutType widgetLayout = WidgetLayoutType.DEFAULT;
private boolean isDefaultTab = false;
public boolean isController() {
String id = view.getId();
- return id !=null && id.length()>0 && id.charAt(0)=='/';
+ return id != null && id.length() > 0 && id.charAt(0) == '/';
}
public String getTitle() {
public boolean supportsMetric(String metricKey) {
return ArrayUtils.contains(defaultForMetrics, metricKey);
}
-
+
public boolean acceptsAvailableMeasures(String[] availableMeasures) {
for (String mandatoryMeasure : mandatoryMeasures) {
if (!ArrayUtils.contains(availableMeasures, mandatoryMeasure)) {
}
ViewProxy rhs = (ViewProxy) obj;
return new EqualsBuilder()
- .append(getId(), rhs.getId())
- .isEquals();
+ .append(getId(), rhs.getId())
+ .isEquals();
}
@Override
public String toString() {
return new ToStringBuilder(this)
- .append("id", view.getId())
- .append("sections", sections)
- .append("userRoles", userRoles)
- .append("scopes", resourceScopes)
- .append("qualifiers", resourceQualifiers)
- .append("languages", resourceLanguages)
- .append("metrics", defaultForMetrics)
- .toString();
+ .append("id", view.getId())
+ .append("sections", sections)
+ .append("userRoles", userRoles)
+ .append("scopes", resourceScopes)
+ .append("qualifiers", resourceQualifiers)
+ .append("languages", resourceLanguages)
+ .append("metrics", defaultForMetrics)
+ .toString();
}
public int compareTo(ViewProxy other) {
return new CompareToBuilder()
- .append(getTitle(), other.getTitle())
- .append(getId(), other.getId())
- .toComparison();
+ .append(getTitle(), other.getTitle())
+ .append(getId(), other.getId())
+ .toComparison();
}
}
html += "\">X</a></span>"
end
- #
- # Compares 2 strings using the human natural order.
- # For instance, the following array:
- # ['foo10', 'foo2', foo1']
- # , will be sorted this way:
- # ['foo1', 'foo2', foo10']
- # , instead of (with standard String sort):
- # ['foo1', 'foo10', foo2']
- #
- # Source: http://www.justskins.com/forums/natural-order-sort-101199.html
- #
- def natural_comparison(str1, str2, caseInsensitive=false)
- str1, str2 = str1.dup, str2.dup
- compareExpression = /^(\D*)(\d*)(.*)$/
-
- if caseInsensitive
- str1.downcase!
- str2.downcase!
- end
-
- # Remove all whitespace
- str1.gsub!(/\s*/, '')
- str2.gsub!(/\s*/, '')
-
- while (str1.length > 0) or (str2.length > 0) do
- # Extract non-digits, digits and rest of string
- str1 =~ compareExpression
- chars1, num1, str1 = $1.dup, $2.dup, $3.dup
-
- str2 =~ compareExpression
- chars2, num2, str2 = $1.dup, $2.dup, $3.dup
-
- # Compare the non-digits
- case (chars1 <=> chars2)
- when 0
- # Non-digits are the same, compare the digits...
- # If either number begins with a zero, then compare
- # alphabetically, otherwise compare numerically
- if (num1[0] != 48) and (num2[0] != 48)
- num1, num2 = num1.to_i, num2.to_i
- end
-
- case (num1 <=> num2)
- when -1 then
- return -1
- when 1 then
- return 1
- end
- when -1 then
- return -1
- when 1 then
- return 1
- end # case
-
- end # while
-
- # Strings are naturally equal
- return 0
- end
-
-
#
# Creates an enhanced dropdown selection box of resources. Values are loaded on the fly via Ajax requests.
# ==== Options
*/
package org.sonar.server.ui;
+import com.google.common.collect.Lists;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.web.WidgetPropertyType;
import org.sonar.api.web.WidgetScope;
+import java.util.List;
+
import static com.google.common.collect.Iterables.getOnlyElement;
import static org.fest.assertions.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.is;
ViewProxy proxy = new ViewProxy<View>(view);
assertThat(proxy.getTarget(), is(view));
- assertArrayEquals(proxy.getSections(), new String[] {NavigationSection.RESOURCE});
- assertArrayEquals(proxy.getUserRoles(), new String[] {UserRole.ADMIN});
+ assertArrayEquals(proxy.getSections(), new String[]{NavigationSection.RESOURCE});
+ assertArrayEquals(proxy.getUserRoles(), new String[]{UserRole.ADMIN});
}
@Test
ViewProxy proxy = new ViewProxy<View>(view);
assertThat(proxy.getTarget(), is(view));
- assertArrayEquals(proxy.getSections(), new String[] {NavigationSection.HOME});
+ assertArrayEquals(proxy.getSections(), new String[]{NavigationSection.HOME});
assertThat(proxy.getUserRoles().length, org.hamcrest.Matchers.is(0));
}
ViewProxy proxy = new ViewProxy<MyView>(new MyView());
assertThat(proxy.isDefaultTab(), is(false));
- assertThat(proxy.getDefaultTabForMetrics(), is(new String[] {"ncloc", "coverage"}));
+ assertThat(proxy.getDefaultTabForMetrics(), is(new String[]{"ncloc", "coverage"}));
}
@Test
ViewProxy<Widget> proxy = new ViewProxy<Widget>(new EditableWidget());
assertThat(proxy.isEditable()).isTrue();
- assertThat(proxy.getWidgetProperties()).hasSize(2);
+ assertThat(proxy.getWidgetProperties()).hasSize(3);
+ }
+
+ @Test
+ public void load_widget_properties_in_the_same_order_than_annotations() {
+ ViewProxy<Widget> proxy = new ViewProxy<Widget>(new EditableWidget());
+
+ List<WidgetProperty> widgetProperties = Lists.newArrayList(proxy.getWidgetProperties());
+ assertThat(widgetProperties).hasSize(3);
+ assertThat(widgetProperties.get(0).key()).isEqualTo("first_prop");
+ assertThat(widgetProperties.get(1).key()).isEqualTo("second_prop");
+ assertThat(widgetProperties.get(2).key()).isEqualTo("third_prop");
}
@Test
exception.expect(IllegalArgumentException.class);
exception.expectMessage("INVALID");
exception.expectMessage("WidgetWithInvalidScope");
-
+
new ViewProxy<Widget>(new WidgetWithInvalidScope());
}
}
ViewProxy proxy = new ViewProxy<MyView>(new MyView());
- assertThat(proxy.acceptsAvailableMeasures(new String[] {"lines", "ncloc", "coverage"}), is(true));
+ assertThat(proxy.acceptsAvailableMeasures(new String[]{"lines", "ncloc", "coverage"}), is(true));
}
@Test
}
ViewProxy proxy = new ViewProxy<MyView>(new MyView());
- assertThat(proxy.acceptsAvailableMeasures(new String[] {"lines", "ncloc", "coverage"}), is(true));
- assertThat(proxy.acceptsAvailableMeasures(new String[] {"lines", "coverage"}), is(false));
+ assertThat(proxy.acceptsAvailableMeasures(new String[]{"lines", "ncloc", "coverage"}), is(true));
+ assertThat(proxy.acceptsAvailableMeasures(new String[]{"lines", "coverage"}), is(false));
}
@Test
}
ViewProxy proxy = new ViewProxy<MyView>(new MyView());
- assertThat(proxy.acceptsAvailableMeasures(new String[] {"lines", "coverage"}), is(true));
- assertThat(proxy.acceptsAvailableMeasures(new String[] {"complexity", "coverage"}), is(false));
+ assertThat(proxy.acceptsAvailableMeasures(new String[]{"lines", "coverage"}), is(true));
+ assertThat(proxy.acceptsAvailableMeasures(new String[]{"complexity", "coverage"}), is(false));
}
@Test
ViewProxy proxy = new ViewProxy<MyView>(new MyView());
// ok, mandatory measures and 1 needed measure
- assertThat(proxy.acceptsAvailableMeasures(new String[] {"lines", "ncloc", "coverage", "duplications"}), is(true));
+ assertThat(proxy.acceptsAvailableMeasures(new String[]{"lines", "ncloc", "coverage", "duplications"}), is(true));
// ko, one of the needed measures but not all of the mandatory ones
- assertThat(proxy.acceptsAvailableMeasures(new String[] {"lines", "coverage", "duplications"}), is(false));
+ assertThat(proxy.acceptsAvailableMeasures(new String[]{"lines", "coverage", "duplications"}), is(false));
// ko, mandatory measures but no one of the needed measures
- assertThat(proxy.acceptsAvailableMeasures(new String[] {"lines", "nloc", "coverage", "dsm"}), is(false));
+ assertThat(proxy.acceptsAvailableMeasures(new String[]{"lines", "nloc", "coverage", "dsm"}), is(false));
}
}
}
@WidgetProperties({
- @WidgetProperty(key = "foo", optional = false),
- @WidgetProperty(key = "bar", defaultValue = "30", type = WidgetPropertyType.INTEGER)
+ @WidgetProperty(key = "first_prop", optional = false),
+ @WidgetProperty(key = "second_prop", defaultValue = "30", type = WidgetPropertyType.INTEGER),
+ @WidgetProperty(key = "third_prop", type = WidgetPropertyType.INTEGER)
})
class EditableWidget implements Widget {
public String getId() {