aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-07-05 09:28:50 +0200
committerDavid Gageot <david@gageot.net>2012-07-05 09:28:50 +0200
commite8f9f465365d336d69276cd392262b64a1516501 (patch)
treed45b23920951667102595425518f05bbd52c3cac /sonar-server
parent0607151797ad10b8905a85b8345019a35a10959c (diff)
downloadsonarqube-e8f9f465365d336d69276cd392262b64a1516501.tar.gz
sonarqube-e8f9f465365d336d69276cd392262b64a1516501.zip
Revert "SONAR-3529 First baby step in providing property sets"
This reverts commit b547f32a3de0381e41b2da6cfab1545f7447b315.
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java78
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_widget_properties.html.erb33
-rw-r--r--sonar-server/src/test/java/org/sonar/server/ui/ViewProxyTest.java38
3 files changed, 42 insertions, 107 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java b/sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java
index 0770add2d14..ae3c1b29798 100644
--- a/sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java
+++ b/sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java
@@ -20,10 +20,7 @@
package org.sonar.server.ui;
import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSetMultimap;
-import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Maps;
-import com.google.common.collect.SetMultimap;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.CompareToBuilder;
@@ -46,7 +43,6 @@ import org.sonar.api.web.WidgetLayout;
import org.sonar.api.web.WidgetLayoutType;
import org.sonar.api.web.WidgetProperties;
import org.sonar.api.web.WidgetProperty;
-import org.sonar.api.web.WidgetPropertySet;
import org.sonar.api.web.WidgetScope;
import java.util.Collection;
@@ -55,8 +51,7 @@ import java.util.Map;
@SuppressWarnings("rawtypes")
public class ViewProxy<V extends View> implements Comparable<ViewProxy> {
- private final V view;
- private final boolean isWidget;
+ private V view;
private String[] sections = {NavigationSection.HOME};
private String[] userRoles = {};
private String[] resourceScopes = {};
@@ -65,17 +60,16 @@ public class ViewProxy<V extends View> implements Comparable<ViewProxy> {
private String[] defaultForMetrics = {};
private String description = "";
private Map<String, WidgetProperty> widgetPropertiesByKey = Maps.newHashMap();
- private SetMultimap<WidgetPropertySet, WidgetProperty> widgetPropertiesBySet = LinkedHashMultimap.create();
private String[] widgetCategories = {};
private WidgetLayoutType widgetLayout = WidgetLayoutType.DEFAULT;
private boolean isDefaultTab = false;
+ private boolean isWidget = false;
private boolean isGlobal = false;
private String[] mandatoryMeasures = {};
private String[] needOneOfMeasures = {};
- public ViewProxy(V view) {
+ public ViewProxy(final V view) {
this.view = view;
- this.isWidget = (view instanceof Widget);
initUserRoles(view);
initSections(view);
@@ -89,6 +83,8 @@ public class ViewProxy<V extends View> implements Comparable<ViewProxy> {
initWidgetLayout(view);
initWidgetGlobal(view);
initRequiredMeasures(view);
+
+ isWidget = (view instanceof Widget);
}
private void initRequiredMeasures(V view) {
@@ -99,14 +95,14 @@ public class ViewProxy<V extends View> implements Comparable<ViewProxy> {
}
}
- private void initWidgetLayout(V view) {
+ private void initWidgetLayout(final V view) {
WidgetLayout layoutAnnotation = AnnotationUtils.getAnnotation(view, WidgetLayout.class);
if (layoutAnnotation != null) {
widgetLayout = layoutAnnotation.value();
}
}
- private void initWidgetCategory(V view) {
+ private void initWidgetCategory(final V view) {
WidgetCategory categAnnotation = AnnotationUtils.getAnnotation(view, WidgetCategory.class);
if (categAnnotation != null) {
widgetCategories = categAnnotation.value();
@@ -129,35 +125,29 @@ public class ViewProxy<V extends View> implements Comparable<ViewProxy> {
}
}
- private void initWidgetProperties(V view) {
+ private void initWidgetProperties(final V view) {
WidgetProperties propAnnotation = AnnotationUtils.getAnnotation(view, WidgetProperties.class);
if (propAnnotation != null) {
- for (WidgetPropertySet set : propAnnotation.sets()) {
- for (WidgetProperty property : set.value()) {
- widgetPropertiesBySet.put(set, property);
- widgetPropertiesByKey.put(property.key(), property);
- }
- }
for (WidgetProperty property : propAnnotation.value()) {
- widgetPropertiesBySet.put(WidgetPropertySet.DEFAULT, property);
widgetPropertiesByKey.put(property.key(), property);
}
}
}
- private void initDescription(V view) {
+ private void initDescription(final V view) {
Description descriptionAnnotation = AnnotationUtils.getAnnotation(view, Description.class);
if (descriptionAnnotation != null) {
description = descriptionAnnotation.value();
}
}
- private void initDefaultTabInfo(V view) {
+ private void initDefaultTabInfo(final V view) {
DefaultTab defaultTabAnnotation = AnnotationUtils.getAnnotation(view, DefaultTab.class);
if (defaultTabAnnotation != null) {
if (defaultTabAnnotation.metrics().length == 0) {
isDefaultTab = true;
defaultForMetrics = new String[0];
+
} else {
isDefaultTab = false;
defaultForMetrics = defaultTabAnnotation.metrics();
@@ -165,35 +155,35 @@ public class ViewProxy<V extends View> implements Comparable<ViewProxy> {
}
}
- private void initResourceLanguage(V view) {
+ private void initResourceLanguage(final V view) {
ResourceLanguage languageAnnotation = AnnotationUtils.getAnnotation(view, ResourceLanguage.class);
if (languageAnnotation != null) {
resourceLanguages = languageAnnotation.value();
}
}
- private void initResourceQualifier(V view) {
+ private void initResourceQualifier(final V view) {
ResourceQualifier qualifierAnnotation = AnnotationUtils.getAnnotation(view, ResourceQualifier.class);
if (qualifierAnnotation != null) {
resourceQualifiers = qualifierAnnotation.value();
}
}
- private void initResourceScope(V view) {
+ private void initResourceScope(final V view) {
ResourceScope scopeAnnotation = AnnotationUtils.getAnnotation(view, ResourceScope.class);
if (scopeAnnotation != null) {
resourceScopes = scopeAnnotation.value();
}
}
- private void initSections(V view) {
+ private void initSections(final V view) {
NavigationSection sectionAnnotation = AnnotationUtils.getAnnotation(view, NavigationSection.class);
if (sectionAnnotation != null) {
sections = sectionAnnotation.value();
}
}
- private void initUserRoles(V view) {
+ private void initUserRoles(final V view) {
UserRole userRoleAnnotation = AnnotationUtils.getAnnotation(view, UserRole.class);
if (userRoleAnnotation != null) {
userRoles = userRoleAnnotation.value();
@@ -210,7 +200,7 @@ public class ViewProxy<V extends View> implements Comparable<ViewProxy> {
public boolean isController() {
String id = view.getId();
- return id != null && !id.isEmpty() && id.charAt(0) == '/';
+ return id !=null && id.length()>0 && id.charAt(0)=='/';
}
public String getTitle() {
@@ -225,10 +215,6 @@ public class ViewProxy<V extends View> implements Comparable<ViewProxy> {
return widgetPropertiesByKey.values();
}
- public SetMultimap<WidgetPropertySet, WidgetProperty> getWidgetPropertiesBySet() {
- return ImmutableSetMultimap.copyOf(widgetPropertiesBySet);
- }
-
public WidgetProperty getWidgetProperty(String propertyKey) {
return widgetPropertiesByKey.get(propertyKey);
}
@@ -268,24 +254,23 @@ public class ViewProxy<V extends View> implements Comparable<ViewProxy> {
public boolean supportsMetric(String metricKey) {
return ArrayUtils.contains(defaultForMetrics, metricKey);
}
-
+
public boolean acceptsAvailableMeasures(String[] availableMeasures) {
for (String mandatoryMeasure : mandatoryMeasures) {
if (!ArrayUtils.contains(availableMeasures, mandatoryMeasure)) {
return false;
}
}
-
if (needOneOfMeasures.length == 0) {
return true;
- }
-
- for (String neededMeasure : needOneOfMeasures) {
- if (ArrayUtils.contains(availableMeasures, neededMeasure)) {
- return true;
+ } else {
+ for (String neededMeasure : needOneOfMeasures) {
+ if (ArrayUtils.contains(availableMeasures, neededMeasure)) {
+ return true;
+ }
}
+ return false;
}
- return false;
}
public boolean isWidget() {
@@ -309,20 +294,13 @@ public class ViewProxy<V extends View> implements Comparable<ViewProxy> {
}
public boolean hasRequiredProperties() {
+ boolean requires = false;
for (WidgetProperty property : getWidgetProperties()) {
if (!property.optional() && StringUtils.isEmpty(property.defaultValue())) {
- return true;
+ requires = true;
}
}
- return false;
- }
-
- public boolean validate(WidgetProperty property, String value) {
- try {
- return property.validation().newInstance().validate(value);
- } catch (Exception e) {
- }
- return true;
+ return requires;
}
@Override
@@ -358,6 +336,7 @@ public class ViewProxy<V extends View> implements Comparable<ViewProxy> {
.append("languages", resourceLanguages)
.append("metrics", defaultForMetrics)
.toString();
+
}
public int compareTo(ViewProxy other) {
@@ -365,5 +344,6 @@ public class ViewProxy<V extends View> implements Comparable<ViewProxy> {
.append(getTitle(), other.getTitle())
.append(getId(), other.getId())
.toComparison();
+
}
}
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_widget_properties.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_widget_properties.html.erb
index b14797cfcc3..79225aa2e72 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_widget_properties.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_widget_properties.html.erb
@@ -13,29 +13,16 @@
</tr>
<% end %>
- <% widget.java_definition.getWidgetPropertiesBySet().asMap().sort { |(s1,p1), (s2,p2)| natural_comparison(s1.key, s2.key) }.each do |set,properties| %>
- <% if widget.java_definition.getWidgetPropertiesBySet().asMap().size > 1 %>
- <% if set.key().empty? %>
- <tr>
- <td celspan="2"><h3>other</h3></td>
- </tr>
- <% else %>
- <tr>
- <td celspan="2"><h3><%= set.key() -%></h3></td>
- </tr>
- <% end %>
- <% end %>
- <% properties.sort { |w1, w2| natural_comparison(w1.key, w2.key) }.each do |property_def| %>
- <tr>
- <td class="form-key-cell"><%= property_def.key() -%><%= " *" unless property_def.optional() -%></td>
- <td class="form-val-cell" id="row_<%= property_def.key() -%>">
- <%= property_value_field(property_def, widget.property_text_value(property_def.key())) -%>
- <div class="form-val-note">
- <%= message("widget." + widget.key + ".param." + property_def.key(), :default => property_def.description()) -%>
- </div>
- </td>
- </tr>
- <% end %>
+ <% widget.java_definition.getWidgetProperties().sort { |w1, w2| natural_comparison(w1.key, w2.key) }.each do |property_def| %>
+ <tr>
+ <td class="form-key-cell"><%= property_def.key() -%><%= " *" unless property_def.optional() -%></td>
+ <td class="form-val-cell" id="row_<%= property_def.key() -%>">
+ <%= property_value_field(property_def, widget.property_text_value(property_def.key())) -%>
+ <div class="form-val-note">
+ <%= message("widget." + widget.key + ".param." + property_def.key(), :default => property_def.description()) -%>
+ </div>
+ </td>
+ </tr>
<% end %>
<tr>
diff --git a/sonar-server/src/test/java/org/sonar/server/ui/ViewProxyTest.java b/sonar-server/src/test/java/org/sonar/server/ui/ViewProxyTest.java
index 725592eb4ab..e3260630791 100644
--- a/sonar-server/src/test/java/org/sonar/server/ui/ViewProxyTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/ui/ViewProxyTest.java
@@ -19,8 +19,6 @@
*/
package org.sonar.server.ui;
-import org.sonar.api.web.WidgetPropertySet;
-
import org.junit.rules.ExpectedException;
import org.junit.Rule;
@@ -142,15 +140,6 @@ public class ViewProxyTest {
}
@Test
- public void should_support_property_sets() {
- ViewProxy proxy = new ViewProxy<Widget>(new EditableWidgetWithSets());
-
- assertThat(proxy.getWidgetProperties()).hasSize(4);
- assertThat(proxy.getWidgetPropertiesBySet().keySet()).hasSize(3);
- assertThat(proxy.getWidgetPropertiesBySet().values()).hasSize(4);
- }
-
- @Test
public void widget_should_not_be_global_by_default() {
ViewProxy proxy = new ViewProxy<Widget>(new EditableWidget());
@@ -169,7 +158,7 @@ public class ViewProxyTest {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("INVALID");
exception.expectMessage("WidgetWithInvalidScope");
-
+
new ViewProxy<Widget>(new WidgetWithInvalidScope());
}
@@ -267,6 +256,7 @@ class FakeView implements View {
@WidgetProperty(key = "bar", defaultValue = "30", type = WidgetPropertyType.INTEGER)
})
class EditableWidget implements Widget {
+
public String getId() {
return "w1";
}
@@ -276,29 +266,6 @@ class EditableWidget implements Widget {
}
}
-@WidgetProperties(sets = {
- @WidgetPropertySet(key = "set1",
- value = {
- @WidgetProperty(key = "foo", optional = false),
- @WidgetProperty(key = "bar", optional = false),
- }),
- @WidgetPropertySet(key = "set2",
- value = {
- @WidgetProperty(key = "qix", optional = false),
- })},
- value = {
- @WidgetProperty(key = "fizz", optional = false)
- })
-class EditableWidgetWithSets implements Widget {
- public String getId() {
- return "w3";
- }
-
- public String getTitle() {
- return "W3";
- }
-}
-
@WidgetScope("GLOBAL")
class GlobalWidget implements Widget {
public String getId() {
@@ -326,6 +293,7 @@ class WidgetWithInvalidScope implements Widget {
@WidgetProperty(key = "bar")
})
class WidgetWithOptionalProperties implements Widget {
+
public String getId() {
return "w2";
}