diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-10-03 08:40:53 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-10-03 08:40:53 +0200 |
commit | ab3a0bc0746a03e3e52860c3e8571073aa06bce5 (patch) | |
tree | 33a79b7c6f40d5e0e1feb2beca35bb7391fce2fc /sonar-plugin-api | |
parent | ddb4d8c4adcbf86be6b2c70e685893963e9cddbb (diff) | |
parent | ee925d0a8d31556a37f98b6738e6f767b489e288 (diff) | |
download | sonarqube-ab3a0bc0746a03e3e52860c3e8571073aa06bce5.tar.gz sonarqube-ab3a0bc0746a03e3e52860c3e8571073aa06bce5.zip |
Merge remote-tracking branch 'remotes/origin/branch-4.5'
Conflicts:
plugins/sonar-xoo-plugin/pom.xml
sonar-plugin-api/pom.xml
sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java
Diffstat (limited to 'sonar-plugin-api')
26 files changed, 48 insertions, 736 deletions
diff --git a/sonar-plugin-api/pom.xml b/sonar-plugin-api/pom.xml index 06f98e88d24..9195d9193bf 100644 --- a/sonar-plugin-api/pom.xml +++ b/sonar-plugin-api/pom.xml @@ -89,10 +89,6 @@ <artifactId>commons-collections</artifactId> </dependency> <dependency> - <groupId>jfree</groupId> - <artifactId>jfreechart</artifactId> - </dependency> - <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/BatchComponent.java b/sonar-plugin-api/src/main/java/org/sonar/api/BatchComponent.java index 4ae6a337048..21c785caa1e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/BatchComponent.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/BatchComponent.java @@ -20,8 +20,20 @@ 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 */ diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/BatchExtension.java b/sonar-plugin-api/src/main/java/org/sonar/api/BatchExtension.java index 6867cdd88b5..95cc1c0f8f7 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/BatchExtension.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/BatchExtension.java @@ -20,7 +20,8 @@ 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 */ diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java index e13f6c3581d..079d77ad2e8 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java @@ -20,8 +20,7 @@ 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 */ diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/Extension.java b/sonar-plugin-api/src/main/java/org/sonar/api/Extension.java index a0ccc09fddc..1c5c8a52c07 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/Extension.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/Extension.java @@ -20,7 +20,7 @@ package org.sonar.api; /** - * Extension point. + * Plugin extension point * * @since 1.10 */ diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/Plugin.java b/sonar-plugin-api/src/main/java/org/sonar/api/Plugin.java index c0c1340b387..ea7bbc755e9 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/Plugin.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/Plugin.java @@ -22,10 +22,11 @@ package org.sonar.api; 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 diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/Properties.java b/sonar-plugin-api/src/main/java/org/sonar/api/Properties.java index 8191edf3319..c41c9f30958 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/Properties.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/Properties.java @@ -24,6 +24,11 @@ import java.lang.annotation.RetentionPolicy; /** * 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 */ diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/Property.java b/sonar-plugin-api/src/main/java/org/sonar/api/Property.java index e9a6fdc50c5..5b0b10964d9 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/Property.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/Property.java @@ -28,18 +28,11 @@ import java.lang.annotation.Target; * 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 */ diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ServerComponent.java b/sonar-plugin-api/src/main/java/org/sonar/api/ServerComponent.java index e2f30ed3460..281c3058a7a 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/ServerComponent.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/ServerComponent.java @@ -20,8 +20,7 @@ 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 */ diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/SonarPlugin.java b/sonar-plugin-api/src/main/java/org/sonar/api/SonarPlugin.java index 6e029ebcf96..c66422b6467 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/SonarPlugin.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/SonarPlugin.java @@ -20,7 +20,10 @@ 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 */ 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 b7e5006ad9d..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/charts/AbstractChart.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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]); - - } - } -} 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 ac3080bfe8e..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/charts/Chart.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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); -} 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 1f821aead01..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/charts/ChartParameters.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * 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; - } -} 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 358d4bbef40..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/charts/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/checks/NoSonarFilter.java b/sonar-plugin-api/src/main/java/org/sonar/api/checks/NoSonarFilter.java deleted file mode 100644 index 05c4bd9bfaf..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/checks/NoSonarFilter.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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; - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/internal/Category.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/Category.java index c8990213204..e4008f2ecea 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/internal/Category.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/Category.java @@ -17,7 +17,7 @@ * 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; +package org.sonar.api.config; import org.apache.commons.lang.StringUtils; @@ -26,29 +26,29 @@ import java.util.Locale; /** * @since 3.7 */ -public class Category { +class Category { private final String originalKey; private final boolean special; - public Category(String originalKey) { + Category(String originalKey) { this(originalKey, false); } - public Category(String originalKey, boolean special) { + Category(String originalKey, boolean special) { this.originalKey = originalKey; this.special = special; } - public String originalKey() { + String originalKey() { return originalKey; } - public String key() { + String key() { return StringUtils.lowerCase(originalKey, Locale.ENGLISH); } - public boolean isSpecial() { + boolean isSpecial() { return special; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java index 00b4af26138..5c20f786866 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java @@ -24,8 +24,6 @@ import com.google.common.collect.Maps; 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; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java index f1832884616..cea246e73a8 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java @@ -39,8 +39,9 @@ import java.util.Map; import java.util.Properties; /** - * Project Settings on batch side, Global Settings on server side. - * This component does not access to database, so property changed via setter methods are not persisted. + * 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> * For testing, you can create a new empty {@link Settings} component using {@link #Settings()} and then * populate it using all variant of {@code setProperty}. <br/> diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/internal/SubCategory.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/SubCategory.java index 8dfbcc16d10..05c96078eca 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/internal/SubCategory.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/SubCategory.java @@ -17,19 +17,18 @@ * 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; - +package org.sonar.api.config; /** * @since 3.7 */ -public class SubCategory extends Category { +class SubCategory extends Category { - public SubCategory(String originalKey) { + SubCategory(String originalKey) { super(originalKey); } - public SubCategory(String originalKey, boolean special) { + SubCategory(String originalKey, boolean special) { super(originalKey, special); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/internal/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/internal/package-info.java deleted file mode 100644 index 25458dc6179..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/internal/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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; diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/charts/AbstractChartTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/charts/AbstractChartTest.java deleted file mode 100644 index eba63156d5f..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/charts/AbstractChartTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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()); - } - } -} 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 40fbe94c3b5..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/charts/ChartParametersTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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()); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java deleted file mode 100644 index 7f4793b77cd..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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(); - - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/AesCipherTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/AesCipherTest.java index 7631b6b9b85..b2dccf589b3 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/AesCipherTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/AesCipherTest.java @@ -36,7 +36,6 @@ import java.security.Key; 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; diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/internal/CategoryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/CategoryTest.java index 1c325e5eceb..c6d9f3a733b 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/internal/CategoryTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/CategoryTest.java @@ -17,7 +17,7 @@ * 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; +package org.sonar.api.config; import org.junit.Test; diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionsTest.java index 4a43b55d1a2..333b8e15c3e 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionsTest.java @@ -22,8 +22,6 @@ package org.sonar.api.config; 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; |