diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-02-01 22:22:13 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-02-02 16:23:42 +0100 |
commit | 9c9a8bb5dd608b710c3a16d1eaa7101e6742b3a5 (patch) | |
tree | dc311a5bf36aa6b996ad6db1feb65ac8bcdd4794 /sonar-plugin-api | |
parent | 8f7a9ad479a219fc22ac729a23f220e450c572b7 (diff) | |
download | sonarqube-9c9a8bb5dd608b710c3a16d1eaa7101e6742b3a5.tar.gz sonarqube-9c9a8bb5dd608b710c3a16d1eaa7101e6742b3a5.zip |
SONAR-5582 drop jfreechart
Diffstat (limited to 'sonar-plugin-api')
6 files changed, 0 insertions, 441 deletions
diff --git a/sonar-plugin-api/pom.xml b/sonar-plugin-api/pom.xml index b3c4449a78b..0755b50c910 100644 --- a/sonar-plugin-api/pom.xml +++ b/sonar-plugin-api/pom.xml @@ -110,14 +110,6 @@ <artifactId>staxmate</artifactId> </dependency> - - <dependency> - <groupId>jfree</groupId> - <artifactId>jfreechart</artifactId> - <scope>provided</scope> - </dependency> - - <dependency> <groupId>com.google.code.findbugs</groupId> <artifactId>jsr305</artifactId> diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/charts/AbstractChart.java b/sonar-plugin-api/src/main/java/org/sonar/api/charts/AbstractChart.java deleted file mode 100644 index ca28e343276..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/charts/AbstractChart.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.api.charts; - -import org.jfree.chart.JFreeChart; -import org.jfree.chart.plot.CategoryPlot; -import org.jfree.chart.plot.Plot; -import org.jfree.chart.renderer.AbstractRenderer; -import org.jfree.chart.title.TextTitle; -import org.jfree.data.Values2D; - -import java.awt.Color; -import java.awt.image.BufferedImage; - -/** - * Base implementation to generate charts with JFreechart - * - * @since 1.10 - * @deprecated in 4.5.1, replaced by Javascript charts - */ -@Deprecated -public abstract class AbstractChart implements Chart { - - public static final int FONT_SIZE = 13; - public static final Color OUTLINE_COLOR = new Color(51, 51, 51); - public static final Color GRID_COLOR = new Color(204, 204, 204); - public static final Color[] COLORS = new Color[] { Color.decode("#4192D9"), Color.decode("#800000"), Color.decode("#A7B307"), - Color.decode("#913C9F"), Color.decode("#329F4D") }; - - protected abstract Plot getPlot(ChartParameters params); - - protected boolean hasLegend() { - return false; - } - - /** - * Generates a JFreeChart chart using a set of parameters - * - * @param params the chart parameters - * @return the generated chart - */ - @Override - public BufferedImage generateImage(ChartParameters params) { - JFreeChart chart = new JFreeChart(null, TextTitle.DEFAULT_FONT, getPlot(params), hasLegend()); - improveChart(chart, params); - return chart.createBufferedImage(params.getWidth(), params.getHeight()); - } - - private static void improveChart(JFreeChart jfrechart, ChartParameters params) { - Color background = Color.decode("#" + params.getValue(ChartParameters.PARAM_BACKGROUND_COLOR, "FFFFFF", false)); - jfrechart.setBackgroundPaint(background); - - jfrechart.setBorderVisible(false); - jfrechart.setAntiAlias(true); - jfrechart.setTextAntiAlias(true); - jfrechart.removeLegend(); - } - - @Override - public String toString() { - return getKey(); - } - - /** - * Helper to set color of series. If the parameter colorsHex is null, then default Sonar colors are used. - */ - protected void configureColors(Values2D dataset, CategoryPlot plot, String[] colorsHex) { - Color[] colors = COLORS; - if (colorsHex != null && colorsHex.length > 0) { - colors = new Color[colorsHex.length]; - for (int i = 0; i < colorsHex.length; i++) { - colors[i] = Color.decode("#" + colorsHex[i]); - } - } - - dataset.getColumnCount(); - AbstractRenderer renderer = (AbstractRenderer) plot.getRenderer(); - for (int i = 0; i < dataset.getColumnCount(); i++) { - renderer.setSeriesPaint(i, colors[i % colors.length]); - - } - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/charts/Chart.java b/sonar-plugin-api/src/main/java/org/sonar/api/charts/Chart.java deleted file mode 100644 index 6b3ef8f3e4a..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/charts/Chart.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.api.charts; - -import org.sonar.api.server.ServerSide; - -import java.awt.image.BufferedImage; - -/** - * Extension point to generate charts - * - * @since 1.10 - * @deprecated in 4.5.1, replaced by Javascript charts - */ -@Deprecated -@ServerSide -public interface Chart { - String getKey(); - - /** - * The method to implement to generate the chart - * - * @param params the chart parameters - * @return the image generated - */ - BufferedImage generateImage(ChartParameters params); -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/charts/ChartParameters.java b/sonar-plugin-api/src/main/java/org/sonar/api/charts/ChartParameters.java deleted file mode 100644 index 364f2813f91..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/charts/ChartParameters.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.api.charts; - -import javax.annotation.Nullable; -import org.apache.commons.lang.CharEncoding; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.text.StrTokenizer; -import org.sonar.api.utils.SonarException; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -/** - * The class to hold parameters to configure a chart - * @since 1.10 - * @deprecated in 4.5.1, replaced by Javascript charts - */ -@Deprecated -public class ChartParameters { - private static final String[] EMPTY = new String[0]; - - public static final String PARAM_WIDTH = "w"; - public static final String PARAM_BACKGROUND_COLOR = "bgc"; - public static final String PARAM_HEIGHT = "h"; - public static final int MAX_WIDTH = 900; - public static final String PARAM_LOCALE = "locale"; - - public static final int MAX_HEIGHT = 900; - public static final int DEFAULT_WIDTH = 200; - - public static final int DEFAULT_HEIGHT = 200; - - - private final Map<String, String> params; - - /** - * Creates a ChartParameter based on a list of parameters - * @param params the list of parameters - */ - public ChartParameters(Map<String, String> params) { - this.params = params; - } - - /** - * Creates a Chartparameter based on a query string with a format key1=value1&key2=value2... - * - * @param queryString string - */ - public ChartParameters(String queryString) { - this.params = new HashMap<>(); - String[] groups = StringUtils.split(queryString, "&"); - for (String group : groups) { - String[] keyval = StringUtils.split(group, "="); - params.put(keyval[0], keyval[1]); - } - } - - /** - * Shortcut to getValue with no decoding and no default value - * @param key the param ket - * @return the value of the param - */ - public String getValue(String key) { - return getValue(key, "", false); - } - - /** - * Returns the [decoded or not] value of a param from its key or the default value - * if id does not exist - * - * @param key the param ket - * @param defaultValue the default value if not exist - * @param decode whther the value should be decoded - * @return the value of the param - */ - - public String getValue(String key, String defaultValue, boolean decode) { - String val = params.get(key); - if (decode) { - val = decode(val); - } - if (val == null) { - val = defaultValue; - } - return val; - } - - /** - * Returns an array of a param values, given its key and the values delimiter - * - * @param key the param key - * @param delimiter the values delimiter - * @return the list of vaalues - */ - public String[] getValues(String key, String delimiter) { - String value = params.get(key); - if (value != null) { - return StringUtils.split(value, delimiter); - } - return EMPTY; - } - - /** - * Returns an array of a param values, given its key and the values delimiter - * Values can be decoded or not - * - * @param key the param key - * @param delimiter the values delimiter - * @param decode whether to decode values - * @return the list of vaalues - */ - public String[] getValues(String key, String delimiter, boolean decode) { - String value = params.get(key); - if (value != null) { - if (decode) { - value = decode(value); - } - return new StrTokenizer(value, delimiter).setIgnoreEmptyTokens(false).getTokenArray(); - } - return EMPTY; - } - - /** - * Get the chart width - * - * @return width - */ - public int getWidth() { - int width = Integer.parseInt(getValue(PARAM_WIDTH, Integer.toString(DEFAULT_WIDTH), false)); - return Math.min(width, MAX_WIDTH); - } - - /** - * Get the chart height - * - * @return height - */ - public int getHeight() { - int height = Integer.parseInt(getValue(PARAM_HEIGHT, Integer.toString(DEFAULT_HEIGHT), false)); - return Math.min(height, MAX_HEIGHT); - } - - /** - * Get the Locale - * - * @return Locale - */ - public Locale getLocale() { - String locale = getValue(PARAM_LOCALE); - if (StringUtils.isNotBlank(locale)) { - return new Locale(locale); - } - return Locale.ENGLISH; - } - - private static String decode(@Nullable String val) { - if (val != null) { - try { - val = URLDecoder.decode(val, CharEncoding.UTF_8); - } catch (UnsupportedEncodingException e) { - throw new SonarException("Decoding chart parameter : " + val, e); - } - } - return val; - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/charts/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/charts/package-info.java deleted file mode 100644 index 610896c29e3..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/charts/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.api.charts; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/charts/ChartParametersTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/charts/ChartParametersTest.java deleted file mode 100644 index 1c38d7a5f67..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/charts/ChartParametersTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.api.charts; - -import org.junit.Test; - -import java.util.Locale; - -import static org.junit.Assert.*; - -public class ChartParametersTest { - @Test - public void shouldForbidHighSizeForSecurityReasons() { - String url = ChartParameters.PARAM_WIDTH + "=100000&" + ChartParameters.PARAM_HEIGHT + "=9999999"; - ChartParameters params = new ChartParameters(url); - assertEquals(ChartParameters.MAX_WIDTH, params.getWidth()); - assertEquals(ChartParameters.MAX_HEIGHT, params.getHeight()); - } - - @Test - public void shouldReadImageSizeFromParameters() { - String url = ChartParameters.PARAM_WIDTH + "=200&" + ChartParameters.PARAM_HEIGHT + "=300"; - ChartParameters params = new ChartParameters(url); - assertEquals(200, params.getWidth()); - assertEquals(300, params.getHeight()); - } - - @Test - public void shouldGetDefaultSizesIfNoParameters() { - ChartParameters params = new ChartParameters("foo=bar"); - assertEquals(ChartParameters.DEFAULT_WIDTH, params.getWidth()); - assertEquals(ChartParameters.DEFAULT_HEIGHT, params.getHeight()); - } - - @Test - public void shouldDecodeValue() { - ChartParameters params = new ChartParameters("foo=0%3D10,3%3D8"); - assertEquals("0=10,3=8", params.getValue("foo", "", true)); - assertEquals("0%3D10,3%3D8", params.getValue("foo")); - assertNull(params.getValue("bar", null, true)); - } - - @Test - public void shouldDecodeValues() { - ChartParameters params = new ChartParameters("foo=0%3D10,3%3D8|5%3D5,7%3D17"); - assertArrayEquals(new String[]{"0%3D10,3%3D8", "5%3D5,7%3D17"}, params.getValues("foo", "|")); - assertArrayEquals(new String[]{"0=10,3=8", "5=5,7=17"}, params.getValues("foo", "|", true)); - assertArrayEquals(new String[0], params.getValues("bar", "|", true)); - } - - @Test - public void getLocale() { - ChartParameters params = new ChartParameters("foo=0&locale=fr"); - assertEquals(Locale.FRENCH, params.getLocale()); - - params = new ChartParameters("foo=0&locale=fr-CH"); - assertEquals("fr-ch", params.getLocale().getLanguage()); - - params = new ChartParameters("foo=0"); - assertEquals(Locale.ENGLISH, params.getLocale()); - } -} |