From ae508ce93d67bb07ee70c2ec5290d6d093e12de4 Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Thu, 5 May 2011 14:23:05 +0200 Subject: [PATCH] Delete unused GWT classes --- .../api/web/gwt/client/AbstractViewer.java | 216 ------------------ .../gwt/client/webservices/FileSource.java | 41 ---- .../gwt/client/webservices/Properties.java | 48 ---- .../client/webservices/PropertiesQuery.java | 79 ------- .../web/gwt/client/webservices/Property.java | 56 ----- .../gwt/client/webservices/SourcesQuery.java | 107 --------- .../web/gwt/client/webservices/Violation.java | 84 ------- .../gwt/client/webservices/Violations.java | 91 -------- .../client/webservices/ViolationsQuery.java | 167 -------------- 9 files changed, 889 deletions(-) delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/AbstractViewer.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/FileSource.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/Properties.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/PropertiesQuery.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/Property.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/SourcesQuery.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/Violation.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/Violations.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/ViolationsQuery.java diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/AbstractViewer.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/AbstractViewer.java deleted file mode 100644 index 1fbc0c8422a..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/AbstractViewer.java +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 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.web.gwt.client; - -import com.google.gwt.core.client.EntryPoint; -import com.google.gwt.core.client.JavaScriptObject; -import com.google.gwt.user.client.ui.FlowPanel; -import com.google.gwt.user.client.ui.Panel; -import com.google.gwt.user.client.ui.RootPanel; -import com.google.gwt.user.client.ui.Widget; -import org.sonar.api.web.gwt.client.webservices.*; - -import java.util.Arrays; - -public abstract class AbstractViewer implements EntryPoint { - - public static final String HTML_ROOT_ID = "resource_viewers"; - - private Resource resource; - private String renderedResourceKey = ""; - private Panel widgetPanel = null; - private boolean standAloneMode = true; - - public void onModuleLoad() { - exportJavascript(); - } - - /** - * Export GWT javascript methods to load and control the plugin, must export currently 2 method : - * I.E for plugin GWT id : foo.bar.MyPlugin, class foo.bar.client.MyPlugin : - *

- * $wnd.load_foo_bar_MyPlugin = function() { - * called to the plugin init from JS - * obj.@foo.bar.client.MyPlugin::loadContainer()(); - * } - * $wnd.on_resource_loaded_foo_bar_MyPlugin = function() { - * called when a resource JSON object has been refreshed within the page - * obj.@foo.bar.client.MyPlugin::onResourceLoaded()(); - * } - */ - protected abstract void exportJavascript(); - - /** - * When multiple widgets are bound to the same HTML div, this method will indicate - * If the resource widget is the default one to show when the widget is initialized - * - * @param metric the metric for which the widget is shown, cannot be null - * @param resource the resource bound to the widget - * @return true or false - */ - protected abstract boolean isDefault(WSMetrics.Metric metric, Resource resource); - - /** - * Finds if a given metric is in the provided metrics list - * - * @param metric the metric to search - * @param metricsList the metric list - * @return true or false if not found - */ - protected boolean isMetricInList(WSMetrics.Metric metric, WSMetrics.Metric... metricsList) { - return Arrays.asList(metricsList).contains(metric); - } - - /** - * When multiple widgets are in the same page, this method will indicate if the widget - * can be shown for the given resource - * - * @param resource the resource bound to the page - * @return true or false - */ - protected abstract boolean isForResource(Resource resource); - - - public Resource getResource() { - return resource; - } - - private Resource loadResource() { - JavaScriptObject resourceJson = getResourceJSONObject(); - if (resourceJson != null) { - Resource resourceLoaded = ResourcesQuery.parseResources(resourceJson).get(0); - String currentMetricKey = ResourceDictionary.getViewerMetricKey(); - Boolean isDefaultForMetric = false; - if (currentMetricKey != null) { - isDefaultForMetric = isDefault(WSMetrics.get(currentMetricKey), resourceLoaded); - } - exportJSBooleanVariable("is_default_for_metric", Utils.widgetGWTIdJSEncode(getGwtId()), isDefaultForMetric); - exportJSBooleanVariable("is_for_resource", Utils.widgetGWTIdJSEncode(getGwtId()), isForResource(resourceLoaded)); - return resourceLoaded; - } - return null; - } - - /** - * Called when a resource JSON object has been loaded within the page - */ - public final void onResourceLoaded() { - resource = loadResource(); - standAloneMode = false; - } - - /** - * Called to render the widget for the given resource object loaded via the onResourceLoaded() method call - */ - public final void loadContainer() { - String resourceKey = ResourceDictionary.getViewerResourceKey(); - if (resourceKey != null) { - if (!standAloneMode && resource == null) { - Utils.showError("Unable to find JSON resource object, unable to render widget"); - return; - } else if (standAloneMode && resource == null) { - getResourceJsonObject(resourceKey); - return; - } - String currentResourceKey = isANumber(resourceKey) ? resource.getId().toString() : resource.getKey(); - if (!renderedResourceKey.equals(currentResourceKey)) { - // resource key has changed reload if not in standalone mode - if (!standAloneMode) { - resource = loadResource(); - } - - if (widgetPanel == null) { - RootPanel rootPanel = RootPanel.get(HTML_ROOT_ID); - if (rootPanel == null) { - Utils.showError("Unable to find root panel " + HTML_ROOT_ID + " in page"); - } - widgetPanel = new FlowPanel(); - widgetPanel.setStyleName("gwt-ResourceTab"); - String panelId = "tab-" + Utils.widgetGWTIdJSEncode(getGwtId()); - widgetPanel.getElement().setId(panelId); - registerTab(panelId); - widgetPanel.setVisible(false); - rootPanel.add(widgetPanel); - } - - renderedResourceKey = resourceKey; - - if (widgetPanel != null) { - widgetPanel.clear(); - widgetPanel.add(render(resource)); - } - } - } - - if (widgetPanel != null) { - widgetPanel.setVisible(true); - } - } - - private static native void registerTab(Object tabId) /*-{ - $wnd.registeredTabs.push(tabId); - }-*/; - - - private native void exportJSBooleanVariable(String varPrefix, String encodedGWTId, boolean value)/*-{ - $wnd.config[varPrefix + "_" + encodedGWTId] = value; - }-*/; - - /** - * Return the GWT id of the widget - */ - protected abstract String getGwtId(); - - /** - * Renders the widget for the current resource - */ - protected abstract Widget render(Resource resource); - - /** - * Return a JavaScriptObject object containing all the measure available for the current resource key - * - * @return the JavaScriptObject instance, should never be null - */ - protected native JavaScriptObject getResourceJSONObject()/*-{ - return $wnd.config['current_resource']; - }-*/; - - - private boolean isANumber(String resourceKey) { - boolean isIdResourceKey = true; - try { - Integer.parseInt(resourceKey); - } catch (NumberFormatException ex) { - isIdResourceKey = false; - } - return isIdResourceKey; - } - - private void getResourceJsonObject(String resourceKey) { - ResourcesQuery.get(resourceKey).execute(new StandAloneResourceHandler()); - } - - public class StandAloneResourceHandler extends BaseQueryCallback { - public void onResponse(Resources resources, JavaScriptObject jsonResponse) { - resource = resources.firstResource(); - loadContainer(); - } - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/FileSource.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/FileSource.java deleted file mode 100644 index db4a15414c3..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/FileSource.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 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.web.gwt.client.webservices; - -import java.util.Map; - -/** - * @deprecated since 2.5, use {@link org.sonar.wsclient.services.Source} instead. - */ -@Deprecated -public class FileSource extends ResponsePOJO { - - private Map sourceLines; - - public FileSource(Map sourceLines) { - super(); - this.sourceLines = sourceLines; - } - - public Map getLines() { - return sourceLines; - } - -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/Properties.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/Properties.java deleted file mode 100644 index 792ca98c957..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/Properties.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 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.web.gwt.client.webservices; - -import java.util.List; - -/** - * @deprecated since 2.5 - */ -@Deprecated -public class Properties extends ResponsePOJO { - - private List properties; - - public Properties(List properties) { - this.properties = properties; - } - - public List getProperties() { - return properties; - } - - public String get(String key, String defaultValue) { - for (Property property : properties) { - if (property.getKey().equals(key)) { - return property.getValue(); - } - } - return defaultValue; - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/PropertiesQuery.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/PropertiesQuery.java deleted file mode 100644 index 4526bbe7455..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/PropertiesQuery.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 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.web.gwt.client.webservices; - -import com.google.gwt.core.client.JavaScriptObject; -import com.google.gwt.json.client.JSONArray; -import com.google.gwt.json.client.JSONObject; -import org.sonar.api.web.gwt.client.Utils; - -import java.util.ArrayList; -import java.util.List; - -/** - * @deprecated since 2.5, use {@link org.sonar.wsclient.services.PropertyQuery} instead. - */ -@Deprecated -public final class PropertiesQuery extends Query { - - private String key; - - public PropertiesQuery() { - } - - public PropertiesQuery(String key) { - this.key = key; - } - - @Override - public String toString() { - String url = Utils.getServerApiUrl() + "/properties"; - if (key != null) { - url += "/" + key; - } - return url + "?"; - } - - @Override - public void execute(QueryCallBack callback) { - JsonUtils.requestJson(this.toString(), new JSONHandlerDispatcher(callback) { - @Override - public Properties parseResponse(JavaScriptObject obj) { - return new Properties(parseProperties(obj)); - } - - private List parseProperties(JavaScriptObject obj) { - JSONArray array = new JSONArray(obj); - List properties = new ArrayList(); - for (int i = 0; i < array.size(); i++) { - JSONObject jsonObject = array.get(i).isObject(); - if (jsonObject != null) { - properties.add(parseProperty(jsonObject)); - } - } - return properties; - } - - private Property parseProperty(JSONObject json) { - return new Property(JsonUtils.getString(json, "key"), JsonUtils.getString(json, "value")); - } - }); - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/Property.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/Property.java deleted file mode 100644 index e29d8ea4f83..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/Property.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 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.web.gwt.client.webservices; - -/** - * @deprecated since 2.5, use {@link org.sonar.wsclient.services.Property} instead - */ -@Deprecated -public class Property extends ResponsePOJO { - - private String key; - private String value; - - public Property() { - } - - public Property(String key, String value) { - this.key = key; - this.value = value; - } - - public String getKey() { - return key; - } - - public Property setKey(String key) { - this.key = key; - return this; - } - - public String getValue() { - return value; - } - - public Property setValue(String value) { - this.value = value; - return this; - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/SourcesQuery.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/SourcesQuery.java deleted file mode 100644 index fc60936362e..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/SourcesQuery.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 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.web.gwt.client.webservices; - -import com.google.gwt.core.client.JavaScriptObject; -import com.google.gwt.json.client.JSONArray; -import com.google.gwt.json.client.JSONObject; -import com.google.gwt.json.client.JSONValue; -import org.sonar.api.web.gwt.client.Utils; - -import java.util.Map; -import java.util.TreeMap; - -/** - * @deprecated since 2.5, use {@link org.sonar.wsclient.services.SourceQuery} instead - */ -@Deprecated -public final class SourcesQuery extends AbstractResourceQuery { - - private Integer from; - private Integer length; - private boolean color; - - public static SourcesQuery get(String resourceKey) { - return new SourcesQuery(resourceKey); - } - - private SourcesQuery(String resourceKey) { - super(resourceKey); - } - - public SourcesQuery setFrom(Integer from) { - this.from = from; - return this; - } - - public SourcesQuery setLength(Integer length) { - this.length = length; - return this; - } - - public SourcesQuery setColor(boolean color) { - this.color = color; - return this; - } - - @Override - public String toString() { - String url = Utils.getServerApiUrl() + "/sources?resource=" + getResourceKey() + "&"; - if (length > 0) { - url += "from=" + from + "&to=" + (from + length) + "&"; - } - if (color) { - url += "color=true&"; - } - return url; - } - - @Override - public void execute(QueryCallBack callback) { - JsonUtils.requestJson(this.toString(), new JSONHandlerDispatcher(callback) { - @Override - public FileSource parseResponse(JavaScriptObject obj) { - return parseLines(obj); - } - }); - } - - private FileSource parseLines(JavaScriptObject obj) { - Map sourceLines = new TreeMap(); - FileSource src = new FileSource(sourceLines); - JSONArray jsonArray = new JSONArray(obj); - if (jsonArray.size() == 0) - return src; - JSONObject sources = jsonArray.get(0).isObject(); - if (sources.size() == 0) - return src; - int maxSize = new Double(Math.pow(2, 16)).intValue(); - int currentLine = from == 0 ? 1 : from; - while (currentLine < maxSize) { - JSONValue line = sources.get(Integer.toString(currentLine)); - if (line == null) { - break; - } - sourceLines.put(currentLine++, line.isString().stringValue()); - } - return src; - } - -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/Violation.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/Violation.java deleted file mode 100644 index 9e522d2b028..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/Violation.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 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.web.gwt.client.webservices; - -/** - * @deprecated since 2.5, use {@link org.sonar.wsclient.services.Violation} instead. - */ -@Deprecated -public class Violation { - - private String message; - private String priority; - private int line; - private Rule rule; - private Resource resource; - - public Violation(String message, String priority, int line, Rule rule, Resource resource) { - this.message = message; - this.priority = priority; - this.line = line; - this.rule = rule; - this.resource = resource; - } - - public Violation() { - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public String getPriority() { - return priority; - } - - public void setPriority(String priority) { - this.priority = priority; - } - - public int getLine() { - return line; - } - - public void setLine(int line) { - this.line = line; - } - - public Rule getRule() { - return rule; - } - - public void setRule(Rule rule) { - this.rule = rule; - } - - public Resource getResource() { - return resource; - } - - public void setResource(Resource resource) { - this.resource = resource; - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/Violations.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/Violations.java deleted file mode 100644 index 7cd70b466cd..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/Violations.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 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.web.gwt.client.webservices; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @deprecated since 2.5 - */ -@Deprecated -public class Violations extends ResponsePOJO { - private List violations; - private Map> byLines; - - public Violations(List violations) { - this.violations = violations; - } - - public Violations() { - this.violations = new ArrayList(); - } - - public void add(Violation v) { - violations.add(v); - byLines = null; - } - - public List getAll() { - return violations; - } - - public Map> getByLines() { - if (byLines == null) { - byLines = new HashMap>(); - for (Violation violation : violations) { - List lineViolations = byLines.get(violation.getLine()); - if (lineViolations == null) { - lineViolations = new ArrayList(); - byLines.put(violation.getLine(), lineViolations); - } - lineViolations.add(violation); - } - } - return byLines; - } - - public String getLevelForLine(Integer line) { - List lineViolations = getByLines().get(line); - String level = ""; - if (lineViolations != null) { - for (Violation lineViolation : lineViolations) { - if ("BLOCKER".equals(lineViolation.getPriority()) || "CRITICAL".equals(lineViolation.getPriority()) - || "MAJOR".equals(lineViolation.getPriority())) { - level = "error"; - - } else if (!"error".equals(level)) { - level = "warning"; - } - } - } - return level; - } - - public int countForLine(Integer line) { - List lineViolations = getByLines().get(line); - if (lineViolations == null) { - return 0; - } - return lineViolations.size(); - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/ViolationsQuery.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/ViolationsQuery.java deleted file mode 100644 index ef699338d27..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/gwt/client/webservices/ViolationsQuery.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 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.web.gwt.client.webservices; - -import com.google.gwt.core.client.JavaScriptObject; -import com.google.gwt.json.client.JSONArray; -import com.google.gwt.json.client.JSONObject; -import com.google.gwt.json.client.JSONString; -import com.google.gwt.json.client.JSONValue; -import org.sonar.api.web.gwt.client.Utils; - -/** - * @deprecated since 2.5, use {@link org.sonar.wsclient.services.ViolationQuery} instead. - */ -@Deprecated -public final class ViolationsQuery extends AbstractResourceQuery { - - private String scopes; - private String qualifiers; - private String rules; - private String priorities; - private Integer depth; - - private ViolationsQuery(String resourceKey) { - super(resourceKey); - } - - public static ViolationsQuery create(String resourceKey) { - return new ViolationsQuery(resourceKey); - } - - public String getScopes() { - return scopes; - } - - public ViolationsQuery setScopes(String scopes) { - this.scopes = scopes; - return this; - } - - public String getQualifiers() { - return qualifiers; - } - - public ViolationsQuery setQualifiers(String qualifiers) { - this.qualifiers = qualifiers; - return this; - } - - public String getRules() { - return rules; - } - - public ViolationsQuery setRules(String rules) { - this.rules = rules; - return this; - } - - /** - * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007 - */ - @Deprecated - public String getCategories() { - return null; - } - - /** - * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007 - */ - @Deprecated - public ViolationsQuery setCategories(String s) { - return this; - } - - public Integer getDepth() { - return depth; - } - - public ViolationsQuery setDepth(Integer depth) { - this.depth = depth; - return this; - } - - public String getPriorities() { - return priorities; - } - - public ViolationsQuery setPriorities(String priorities) { - this.priorities = priorities; - return this; - } - - @Override - public String toString() { - String url = Utils.getServerApiUrl() + "/violations?resource=" + getResourceKey() + "&"; - if (depth != null) { - url += "depth=" + depth + "&"; - } - if (scopes != null) { - url += "scopes=" + scopes + "&"; - } - if (qualifiers != null) { - url += "qualifiers=" + qualifiers + "&"; - } - if (rules != null) { - url += "rules=" + rules + "&"; - } - if (priorities != null) { - url += "priorities=" + priorities + "&"; - } - return url; - } - - @Override - public void execute(final QueryCallBack callback) { - JsonUtils.requestJson(this.toString(), new JSONHandlerDispatcher(callback) { - @Override - public Violations parseResponse(JavaScriptObject obj) { - return parseJSON(obj); - } - }); - } - - private Violations parseJSON(JavaScriptObject obj) { - Violations result = new Violations(); - JSONArray jsonArray = new JSONArray(obj); - for (int i = 0; i < jsonArray.size(); i++) { - JSONObject jsViolation = jsonArray.get(i).isObject(); - if (jsViolation == null) { - continue; - } - JSONString message = jsViolation.get("message").isString(); - JSONString priority = jsViolation.get("priority").isString(); - JSONValue lineJson = jsViolation.get("line"); - int lineIndex = 0; - if (lineJson != null) { - lineIndex = (int) lineJson.isNumber().doubleValue(); - } - - JSONObject ruleObj = jsViolation.get("rule").isObject(); - Rule rule = new Rule( - JsonUtils.getString(ruleObj, "key"), - JsonUtils.getString(ruleObj, "name")); - - result.add(new Violation(message.stringValue(), priority.stringValue(), lineIndex, rule, null)); - } - return result; - } - -} -- 2.39.5