--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.plugins.core.charts;
+
+import org.apache.commons.io.FileUtils;
+import org.jfree.chart.ChartUtilities;
+import org.jfree.ui.ApplicationFrame;
+import org.jfree.ui.RefineryUtilities;
+
+import javax.swing.JPanel;
+
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import static org.junit.Assert.assertTrue;
+
+public abstract class AbstractChartTest {
+ protected void assertChartSizeGreaterThan(BufferedImage img, int size) throws IOException {
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ ChartUtilities.writeBufferedImageAsPNG(output, img);
+ assertTrue("PNG size in bits=" + output.size(), output.size() > size);
+ }
+
+ protected void assertChartSizeLesserThan(BufferedImage img, int size) throws IOException {
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ ChartUtilities.writeBufferedImageAsPNG(output, img);
+ assertTrue("PNG size in bits=" + output.size(), output.size() < size);
+ }
+
+ protected void saveChart(BufferedImage img, String name) throws IOException {
+ File target = new File("target/tmp-chart", name);
+ FileUtils.forceMkdir(target.getParentFile());
+ ByteArrayOutputStream imgOutput = new ByteArrayOutputStream();
+ ChartUtilities.writeBufferedImageAsPNG(imgOutput, img);
+ OutputStream out = new FileOutputStream(target);
+ out.write(imgOutput.toByteArray());
+ out.close();
+
+ }
+
+ protected static void displayTestPanel(BufferedImage image) {
+ ApplicationFrame frame = new ApplicationFrame("testframe");
+ BufferedPanel imgPanel = new BufferedPanel(image);
+ frame.setContentPane(imgPanel);
+ frame.pack();
+ RefineryUtilities.centerFrameOnScreen(frame);
+ frame.setVisible(true);
+ }
+
+ protected static Date stringToDate(String sDate) throws ParseException {
+ SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy hh'h'mm");
+ return sdf.parse(sDate);
+ }
+
+ private static class BufferedPanel extends JPanel {
+ private final BufferedImage chartImage;
+
+ public BufferedPanel(BufferedImage chartImage) {
+ this.chartImage = chartImage;
+ }
+
+ @Override
+ protected void paintComponent(Graphics graphics) {
+ super.paintComponent(graphics);
+ graphics.drawImage(chartImage, 0, 0, null);
+ }
+
+ @Override
+ public Dimension getPreferredSize() {
+ return new Dimension(chartImage.getWidth(), chartImage.getHeight());
+ }
+ }
+}
package org.sonar.plugins.core.charts;
import org.junit.Test;
-import org.sonar.api.charts.AbstractChartTest;
import org.sonar.api.charts.ChartParameters;
import java.awt.image.BufferedImage;
package org.sonar.plugins.core.charts;
import org.junit.Test;
-import org.sonar.api.charts.AbstractChartTest;
import org.sonar.api.charts.ChartParameters;
import java.awt.image.BufferedImage;
package org.sonar.plugins.core.charts;
import org.junit.Test;
-import org.sonar.api.charts.AbstractChartTest;
import org.sonar.api.charts.ChartParameters;
import java.awt.image.BufferedImage;
<artifactId>sonar-plugin-api</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
<!-- unit testing -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>sonar-plugin-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>jfree</groupId>
+ <artifactId>jfreechart</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<scope>provided</scope>
</dependency>
+
<!-- unit test -->
<dependency>
<groupId>junit</groupId>
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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
+ */
+ 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 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]);
+
+ }
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.ServerExtension;
+
+import java.awt.image.BufferedImage;
+
+/**
+ * Extension point to generate charts
+ *
+ * @since 1.10
+ * @deprecated in 4.5.1, replaced by Javascript charts
+ */
+@Deprecated
+public interface Chart extends ServerExtension {
+ String getKey();
+
+ /**
+ * The method to implement to generate the chart
+ *
+ * @param params the chart parameters
+ * @return the image generated
+ */
+ BufferedImage generateImage(ChartParameters params);
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.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, String>();
+ 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, "" + 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, "" + 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 String decode(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;
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.
+ */
+/**
+ * Deprecated in 4.5.1. JFreechart charts are replaced by Javascript charts.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.api.charts;
+
+import javax.annotation.ParametersAreNonnullByDefault;
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.checks;
+
+import com.google.common.collect.Maps;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.api.batch.SensorContext;
+import org.sonar.api.resources.Resource;
+import org.sonar.api.rules.Violation;
+import org.sonar.api.rules.ViolationFilter;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @since 2.1
+ * @deprecated in 3.6. Replaced by {@link org.sonar.api.issue.NoSonarFilter}
+ */
+@Deprecated
+public class NoSonarFilter implements ViolationFilter {
+
+ private final Map<Resource, Set<Integer>> noSonarLinesByResource = Maps.newHashMap();
+ private SensorContext context;
+
+ public NoSonarFilter(SensorContext context) {
+ this.context = context;
+ }
+
+ public void addResource(Resource model, Set<Integer> noSonarLines) {
+ if (model != null && noSonarLines != null) {
+ // Reload resource to handle backward compatibility of resource keys
+ Resource resource = context.getResource(model);
+ if (resource != null) {
+ noSonarLinesByResource.put(resource, noSonarLines);
+ }
+ }
+ }
+
+ public boolean isIgnored(Violation violation) {
+ boolean ignored = false;
+ if (violation.getResource() != null && violation.getLineId() != null) {
+ Set<Integer> noSonarLines = noSonarLinesByResource.get(violation.getResource());
+ ignored = noSonarLines != null && noSonarLines.contains(violation.getLineId());
+ if (ignored && violation.getRule() != null && StringUtils.containsIgnoreCase(violation.getRule().getKey(), "nosonar")) {
+ ignored = false;
+ }
+ }
+ return ignored;
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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());
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.checks;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.batch.SensorContext;
+import org.sonar.api.resources.File;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.Violation;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class NoSonarFilterTest {
+
+ private SensorContext sensorContext = mock(SensorContext.class);
+ NoSonarFilter filter = new NoSonarFilter(sensorContext);
+ private File javaFile;
+
+ @Before
+ public void prepare() {
+ javaFile = new File("org.foo.Bar");
+ when(sensorContext.getResource(javaFile)).thenReturn(javaFile);
+ }
+
+ @Test
+ public void ignoreLinesCommentedWithNoSonar() {
+ Set<Integer> noSonarLines = new HashSet<Integer>();
+ noSonarLines.add(31);
+ noSonarLines.add(55);
+ filter.addResource(javaFile, noSonarLines);
+
+ // violation on class
+ assertThat(filter.isIgnored(new Violation(null, javaFile))).isFalse();
+
+ // violation on lines
+ assertThat(filter.isIgnored(new Violation(null, javaFile).setLineId(30))).isFalse();
+ assertThat(filter.isIgnored(new Violation(null, javaFile).setLineId(31))).isTrue();
+ }
+
+ @Test
+ public void doNotIgnoreWhenNotFoundInSquid() {
+ assertThat(filter.isIgnored(new Violation(null, javaFile).setLineId(30))).isFalse();
+ }
+
+ @Test
+ public void should_accept_violations_from_no_sonar_rules() throws Exception {
+ // The "No Sonar" rule logs violations on the lines that are flagged with "NOSONAR" !!
+
+ Set<Integer> noSonarLines = new HashSet<Integer>();
+ noSonarLines.add(31);
+ filter.addResource(javaFile, noSonarLines);
+
+ Rule noSonarRule = new Rule("squid", "NoSonarCheck");
+ assertThat(filter.isIgnored(new Violation(noSonarRule, javaFile).setLineId(31))).isFalse();
+
+ }
+}
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
- <dependency>
- <groupId>jfree</groupId>
- <artifactId>jfreechart</artifactId>
- </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
package org.sonar.api;
/**
- * Dependency Injection : all the classes implementing this interface are available in the batch IoC container.
- * Just add a parameter to the constructor of your component.
+ * Marker interface for all the components available in container of batch (code analyzer). Note that
+ * injection of dependencies by constructor is used :
+ * <pre>
+ * public class Foo implements BatchComponent {
+ *
+ * }
+ * public class Bar implements BatchComponent {
+ * private final Foo foo;
+ * public Bar(Foo f) {
+ * this.foo = f;
+ * }
+ * }
+ *
+ * </pre>
*
* @since 2.2
*/
package org.sonar.api;
/**
- * Batch extension point.
+ * Marker interface for all the batch extension points, which are aimed to be implemented
+ * by plugins.
*
* @since 1.10
*/
package org.sonar.api;
/**
- * CoreProperties is used to group various properties of Sonar as well
- * as default values of configuration in a single place
+ * Non-exhaustive list of constants of core properties.
*
* @since 1.11
*/
package org.sonar.api;
/**
- * Extension point.
+ * Plugin extension point
*
* @since 1.10
*/
import java.util.List;
/**
- * A plugin is a group of extensions. See <code>org.sonar.api.Extension</code> interface to get all extension points.
+ * A plugin is a group of extensions. See <code>org.sonar.api.Extension</code> interface to browse
+ * available extension points.
* <p/>
* <p>The manifest property <code>Plugin-Class</code> must declare the name of the implementation class.
- * See META-INF/MANIFEST.MF.</p>
+ * It is automatically set by sonar-packaging-maven-plugin when building plugins.</p>
*
* @see org.sonar.api.Extension
* @since 1.10
/**
* Plugin properties. This annotation is only used on classes implementing org.sonar.api.Plugin.
+ * <p/>
+ * Note that {@link org.sonar.api.config.PropertyDefinition} is an alternative, programmatic and recommended approach
+ * to declare properties.
+ * <p/>
+ * Effective property values are accessible at runtime through the component {@link org.sonar.api.config.Settings}
*
* @since 1.10
*/
* Property value can be set in different ways :
* <ul>
* <li>System property</li>
- * <li>Maven command-line (-Dfoo=bar)</li>
+ * <li>Batch command-line (-Dfoo=bar in Maven or sonar-runner)</li>
* <li>Maven pom.xml (element <properties>)</li>
* <li>Maven settings.xml</li>
- * <li>Sonar web interface</li>
+ * <li>SonarQube web administration console</li>
* </ul>
- * <p/>
- * Value is accessible in batch extensions via the Configuration object of class <code>org.sonar.api.resources.Project</code>
- * (see method <code>getConfiguration()</code>).
- * <p/>
- * <p><strong>Must be used in <code>org.sonar.api.Plugin</code> classes only.</strong></p>
- * <p></p>
- * It's recommended to use the class {@link org.sonar.api.config.PropertyDefinition} since v3.6.
*
* @since 1.10
*/
package org.sonar.api;
/**
- * Dependency Injection : all the classes implementing this interface are available in the server IoC container.
- * Just add a parameter to the constructor of your component.
+ * Same than {@link org.sonar.api.BatchComponent} but for server-side components.
*
* @since 2.2
*/
package org.sonar.api;
/**
- * A plugin is a group of extensions. See {@link Extension} interface to get all extension points.
+ * Plugin entry-point used to declare its extensions (see {@link org.sonar.api.Extension}.
+ * <p/>
+ * <p>The JAR manifest must declare the name of the implementation class in the property <code>Plugin-Class</code>.
+ * This property is automatically set by sonar-packaging-maven-plugin when building plugin.</p>
*
* @since 2.8
*/
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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;
-
-/**
- * An extension point to generate JFreeChart charts
- *
- * @since 1.10
- */
-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
- */
- 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 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]);
-
- }
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.ServerExtension;
-
-import java.awt.image.BufferedImage;
-
-/**
- * An Extension to create charts
- *
- * @since 1.10
- */
-public interface Chart extends ServerExtension {
- String getKey();
-
- /**
- * The method to implement to generate the chart
- *
- * @param params the chart parameters
- * @return the image generated
- */
- BufferedImage generateImage(ChartParameters params);
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.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
- */
-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, String>();
- 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, "" + 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, "" + 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 String decode(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;
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.checks;
-
-import com.google.common.collect.Maps;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.batch.SensorContext;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.rules.Violation;
-import org.sonar.api.rules.ViolationFilter;
-
-import java.util.Map;
-import java.util.Set;
-
-/**
- * @since 2.1
- * @deprecated in 3.6. Replaced by {@link org.sonar.api.issue.NoSonarFilter}
- */
-@Deprecated
-public class NoSonarFilter implements ViolationFilter {
-
- private final Map<Resource, Set<Integer>> noSonarLinesByResource = Maps.newHashMap();
- private SensorContext context;
-
- public NoSonarFilter(SensorContext context) {
- this.context = context;
- }
-
- public void addResource(Resource model, Set<Integer> noSonarLines) {
- if (model != null && noSonarLines != null) {
- // Reload resource to handle backward compatibility of resource keys
- Resource resource = context.getResource(model);
- if (resource != null) {
- noSonarLinesByResource.put(resource, noSonarLines);
- }
- }
- }
-
- public boolean isIgnored(Violation violation) {
- boolean ignored = false;
- if (violation.getResource() != null && violation.getLineId() != null) {
- Set<Integer> noSonarLines = noSonarLinesByResource.get(violation.getResource());
- ignored = noSonarLines != null && noSonarLines.contains(violation.getLineId());
- if (ignored && violation.getRule() != null && StringUtils.containsIgnoreCase(violation.getRule().getKey(), "nosonar")) {
- ignored = false;
- }
- }
- return ignored;
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.config;
+
+import org.apache.commons.lang.StringUtils;
+
+import java.util.Locale;
+
+/**
+ * @since 3.7
+ */
+class Category {
+
+ private final String originalKey;
+ private final boolean special;
+
+ Category(String originalKey) {
+ this(originalKey, false);
+ }
+
+ Category(String originalKey, boolean special) {
+ this.originalKey = originalKey;
+ this.special = special;
+ }
+
+ String originalKey() {
+ return originalKey;
+ }
+
+ String key() {
+ return StringUtils.lowerCase(originalKey, Locale.ENGLISH);
+ }
+
+ boolean isSpecial() {
+ return special;
+ }
+
+ @Override
+ public int hashCode() {
+ return key().hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof Category)) {
+ return false;
+ }
+ return StringUtils.equalsIgnoreCase(((Category) obj).originalKey, this.originalKey);
+ }
+
+ @Override
+ public String toString() {
+ return this.originalKey;
+ }
+
+}
import org.apache.commons.lang.StringUtils;
import org.sonar.api.*;
import org.sonar.api.Properties;
-import org.sonar.api.config.internal.Category;
-import org.sonar.api.config.internal.SubCategory;
import org.sonar.api.utils.AnnotationUtils;
import javax.annotation.Nullable;
import java.util.Properties;
/**
- * Project Settings on batch side, Global Settings on server side. This component does not access to database, so
+ * Project settings on batch side, or global settings on server side. This component does not access to database, so
* property changed via setter methods are not persisted.
* <p/>
* <p>
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.config;
+
+/**
+ * @since 3.7
+ */
+class SubCategory extends Category {
+
+ SubCategory(String originalKey) {
+ super(originalKey);
+ }
+
+ SubCategory(String originalKey, boolean special) {
+ super(originalKey, special);
+ }
+
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.config.internal;
-
-import org.apache.commons.lang.StringUtils;
-
-import java.util.Locale;
-
-/**
- * @since 3.7
- */
-public class Category {
-
- private final String originalKey;
- private final boolean special;
-
- public Category(String originalKey) {
- this(originalKey, false);
- }
-
- public Category(String originalKey, boolean special) {
- this.originalKey = originalKey;
- this.special = special;
- }
-
- public String originalKey() {
- return originalKey;
- }
-
- public String key() {
- return StringUtils.lowerCase(originalKey, Locale.ENGLISH);
- }
-
- public boolean isSpecial() {
- return special;
- }
-
- @Override
- public int hashCode() {
- return key().hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof Category)) {
- return false;
- }
- return StringUtils.equalsIgnoreCase(((Category) obj).originalKey, this.originalKey);
- }
-
- @Override
- public String toString() {
- return this.originalKey;
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.config.internal;
-
-
-/**
- * @since 3.7
- */
-public class SubCategory extends Category {
-
- public SubCategory(String originalKey) {
- super(originalKey);
- }
-
- public SubCategory(String originalKey, boolean special) {
- super(originalKey, special);
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.config.internal;
-
-import javax.annotation.ParametersAreNonnullByDefault;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.apache.commons.io.FileUtils;
-import org.jfree.chart.ChartUtilities;
-import org.jfree.ui.ApplicationFrame;
-import org.jfree.ui.RefineryUtilities;
-
-import javax.swing.JPanel;
-
-import java.awt.Dimension;
-import java.awt.Graphics;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import static org.junit.Assert.assertTrue;
-
-public abstract class AbstractChartTest {
- protected void assertChartSizeGreaterThan(BufferedImage img, int size) throws IOException {
- ByteArrayOutputStream output = new ByteArrayOutputStream();
- ChartUtilities.writeBufferedImageAsPNG(output, img);
- assertTrue("PNG size in bits=" + output.size(), output.size() > size);
- }
-
- protected void assertChartSizeLesserThan(BufferedImage img, int size) throws IOException {
- ByteArrayOutputStream output = new ByteArrayOutputStream();
- ChartUtilities.writeBufferedImageAsPNG(output, img);
- assertTrue("PNG size in bits=" + output.size(), output.size() < size);
- }
-
- protected void saveChart(BufferedImage img, String name) throws IOException {
- File target = new File("target/tmp-chart", name);
- FileUtils.forceMkdir(target.getParentFile());
- ByteArrayOutputStream imgOutput = new ByteArrayOutputStream();
- ChartUtilities.writeBufferedImageAsPNG(imgOutput, img);
- OutputStream out = new FileOutputStream(target);
- out.write(imgOutput.toByteArray());
- out.close();
-
- }
-
- protected static void displayTestPanel(BufferedImage image) {
- ApplicationFrame frame = new ApplicationFrame("testframe");
- BufferedPanel imgPanel = new BufferedPanel(image);
- frame.setContentPane(imgPanel);
- frame.pack();
- RefineryUtilities.centerFrameOnScreen(frame);
- frame.setVisible(true);
- }
-
- protected static Date stringToDate(String sDate) throws ParseException {
- SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy hh'h'mm");
- return sdf.parse(sDate);
- }
-
- private static class BufferedPanel extends JPanel {
- private final BufferedImage chartImage;
-
- public BufferedPanel(BufferedImage chartImage) {
- this.chartImage = chartImage;
- }
-
- @Override
- protected void paintComponent(Graphics graphics) {
- super.paintComponent(graphics);
- graphics.drawImage(chartImage, 0, 0, null);
- }
-
- @Override
- public Dimension getPreferredSize() {
- return new Dimension(chartImage.getWidth(), chartImage.getHeight());
- }
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 static org.junit.Assert.*;
-import org.junit.Test;
-
-import java.util.Locale;
-
-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());
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.checks;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.batch.SensorContext;
-import org.sonar.api.resources.File;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.Violation;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class NoSonarFilterTest {
-
- private SensorContext sensorContext = mock(SensorContext.class);
- NoSonarFilter filter = new NoSonarFilter(sensorContext);
- private File javaFile;
-
- @Before
- public void prepare() {
- javaFile = new File("org.foo.Bar");
- when(sensorContext.getResource(javaFile)).thenReturn(javaFile);
- }
-
- @Test
- public void ignoreLinesCommentedWithNoSonar() {
- Set<Integer> noSonarLines = new HashSet<Integer>();
- noSonarLines.add(31);
- noSonarLines.add(55);
- filter.addResource(javaFile, noSonarLines);
-
- // violation on class
- assertThat(filter.isIgnored(new Violation(null, javaFile))).isFalse();
-
- // violation on lines
- assertThat(filter.isIgnored(new Violation(null, javaFile).setLineId(30))).isFalse();
- assertThat(filter.isIgnored(new Violation(null, javaFile).setLineId(31))).isTrue();
- }
-
- @Test
- public void doNotIgnoreWhenNotFoundInSquid() {
- assertThat(filter.isIgnored(new Violation(null, javaFile).setLineId(30))).isFalse();
- }
-
- @Test
- public void should_accept_violations_from_no_sonar_rules() throws Exception {
- // The "No Sonar" rule logs violations on the lines that are flagged with "NOSONAR" !!
-
- Set<Integer> noSonarLines = new HashSet<Integer>();
- noSonarLines.add(31);
- filter.addResource(javaFile, noSonarLines);
-
- Rule noSonarRule = new Rule("squid", "NoSonarCheck");
- assertThat(filter.isIgnored(new Violation(noSonarRule, javaFile).setLineId(31))).isFalse();
-
- }
-}
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.Is.isA;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.config;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class CategoryTest {
+
+ @Test
+ public void category_key_is_case_insentive() {
+ assertThat(new Category("Licenses")).isEqualTo(new Category("licenses"));
+
+ // Just to raise coverage
+ assertThat(new Category("Licenses")).isNotEqualTo("Licenses");
+ }
+
+ @Test
+ public void should_preserve_original_key() {
+ assertThat(new Category("Licenses").originalKey()).isEqualTo("Licenses");
+ }
+
+ @Test
+ public void should_normalize_key() throws Exception {
+ assertThat(new Category("Licenses").key()).isEqualTo("licenses");
+ }
+
+ @Test
+ public void should_use_original_key() throws Exception {
+ assertThat(new Category("Licenses").toString()).isEqualTo("Licenses");
+ }
+
+}
import org.junit.Test;
import org.sonar.api.Properties;
import org.sonar.api.Property;
-import org.sonar.api.config.internal.Category;
-import org.sonar.api.config.internal.SubCategory;
import org.sonar.api.resources.Qualifiers;
import java.util.Arrays;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.config.internal;
-
-import org.junit.Test;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class CategoryTest {
-
- @Test
- public void category_key_is_case_insentive() {
- assertThat(new Category("Licenses")).isEqualTo(new Category("licenses"));
-
- // Just to raise coverage
- assertThat(new Category("Licenses")).isNotEqualTo("Licenses");
- }
-
- @Test
- public void should_preserve_original_key() {
- assertThat(new Category("Licenses").originalKey()).isEqualTo("Licenses");
- }
-
- @Test
- public void should_normalize_key() throws Exception {
- assertThat(new Category("Licenses").key()).isEqualTo("licenses");
- }
-
- @Test
- public void should_use_original_key() throws Exception {
- assertThat(new Category("Licenses").toString()).isEqualTo("Licenses");
- }
-
-}