aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-04-03 10:08:48 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-04-03 10:08:48 +0200
commit38e53c0572db4e267a704666cb0d1343992df5e1 (patch)
tree7b7bf7acb697d244dbf6ca03466b35c929662b24 /sonar-server
parentc881206bd9f2edfd6a5586ec735d003bd73d367d (diff)
downloadsonarqube-38e53c0572db4e267a704666cb0d1343992df5e1.tar.gz
sonarqube-38e53c0572db4e267a704666cb0d1343992df5e1.zip
Fix some quality flaws
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/charts/ChartsServlet.java12
-rw-r--r--sonar-server/src/main/java/org/sonar/server/charts/deprecated/BarChart.java11
-rw-r--r--sonar-server/src/main/java/org/sonar/server/charts/deprecated/BaseChartWeb.java1
-rw-r--r--sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarChart.java6
-rw-r--r--sonar-server/src/main/java/org/sonar/server/charts/deprecated/PieChart.java1
-rw-r--r--sonar-server/src/main/java/org/sonar/server/plugins/ClassLoaderUtils.java10
-rw-r--r--sonar-server/src/main/java/org/sonar/server/plugins/StaticResourcesServlet.java10
7 files changed, 24 insertions, 27 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/charts/ChartsServlet.java b/sonar-server/src/main/java/org/sonar/server/charts/ChartsServlet.java
index 81660dcca1c..2a39719585d 100644
--- a/sonar-server/src/main/java/org/sonar/server/charts/ChartsServlet.java
+++ b/sonar-server/src/main/java/org/sonar/server/charts/ChartsServlet.java
@@ -19,6 +19,7 @@
*/
package org.sonar.server.charts;
+import com.google.common.collect.Maps;
import org.apache.commons.io.IOUtils;
import org.jfree.chart.encoders.KeypointPNGEncoderAdapter;
import org.slf4j.Logger;
@@ -45,8 +46,7 @@ public class ChartsServlet extends HttpServlet {
private static final long serialVersionUID = 669857447198433893L;
@Override
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
+ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (isDeprecatedChart(request)) {
deprecatedDoGet(request, response);
@@ -71,7 +71,7 @@ public class ChartsServlet extends HttpServlet {
}
private ChartParameters getParams(HttpServletRequest request) {
- Map<String, String> map = new HashMap<String, String>();
+ Map<String, String> map = Maps.newHashMap();
Enumeration keys = request.getParameterNames();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
@@ -104,10 +104,8 @@ public class ChartsServlet extends HttpServlet {
return false;
}
- public void deprecatedDoGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
-
- Map<String, String> params = new HashMap<String, String>();
+ public void deprecatedDoGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ Map<String, String> params = Maps.newHashMap();
params.put(BaseChartWeb.CHART_PARAM_TYPE, request.getParameter(BaseChartWeb.CHART_PARAM_TYPE));
params.put(BaseChartWeb.CHART_PARAM_VALUES, request.getParameter(BaseChartWeb.CHART_PARAM_VALUES));
params.put(BaseChartWeb.CHART_PARAM_COLORS, request.getParameter(BaseChartWeb.CHART_PARAM_COLORS));
diff --git a/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BarChart.java b/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BarChart.java
index 41ddae8886e..32e9821ecb9 100644
--- a/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BarChart.java
+++ b/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BarChart.java
@@ -169,14 +169,13 @@ public class BarChart extends BaseChartWeb implements DeprecatedChart {
// Categories
String categoriesParam = params.get(BaseChartWeb.CHART_PARAM_CATEGORIES);
boolean categoriesPresent = categoriesParam != null && categoriesParam.length() > 0;
- String[] categoriesSplit = null;
+ String[] categoriesSplit;
if (categoriesPresent) {
categoriesSplit = categoriesParam.split(",");
} else {
categoriesSplit = new String[1];
categoriesSplit[0] = BaseChartWeb.DEFAULT_NAME_CATEGORY;
}
- int nbCategories = categoriesSplit.length;
// Series
String seriesParam = params.get(BaseChartWeb.CHART_PARAM_SERIES);
@@ -190,17 +189,15 @@ public class BarChart extends BaseChartWeb implements DeprecatedChart {
seriesSplit[i] = BaseChartWeb.DEFAULT_NAME_SERIE + i;
}
}
- int nbSeries = seriesSplit.length;
- for (int iCategories = 0; iCategories < nbCategories; iCategories++) {
- String currentCategory = categoriesSplit[iCategories];
- for (int iSeries = 0; iSeries < nbSeries; iSeries++) {
- String currentSerie = seriesSplit[iSeries];
+ for (String currentCategory : categoriesSplit) {
+ for (String currentSerie : seriesSplit) {
double currentValue = 0.0;
if (stValues.hasMoreTokens()) {
try {
currentValue = Double.parseDouble(stValues.nextToken());
} catch (NumberFormatException e) {
+ // ignore
}
}
dataset.addValue(currentValue, currentSerie, currentCategory);
diff --git a/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BaseChartWeb.java b/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BaseChartWeb.java
index 722eae4b242..cd6ead87c02 100644
--- a/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BaseChartWeb.java
+++ b/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BaseChartWeb.java
@@ -119,6 +119,7 @@ public abstract class BaseChartWeb extends BaseChart {
result = Double.parseDouble(paramValue);
}
catch (NumberFormatException e) {
+ // ignore
}
}
return result;
diff --git a/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarChart.java b/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarChart.java
index dd1cf0d20da..db5b3d8c168 100644
--- a/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarChart.java
+++ b/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarChart.java
@@ -118,15 +118,12 @@ public class CustomBarChart extends BarChart {
categoriesSplit[i] = DEFAULT_NAME_CATEGORY + i;
}
}
- int nbCategories = categoriesSplit.length;
// Series
String[] seriesSplit = {DEFAULT_NAME_SERIE};
int nbSeries = 1;
- //
- for (int iCategories = 0; iCategories < nbCategories; iCategories++) {
- String currentCategory = categoriesSplit[iCategories];
+ for (String currentCategory : categoriesSplit) {
for (int iSeries = 0; iSeries < nbSeries; iSeries++) {
String currentSerie = seriesSplit[iSeries];
double currentValue = 0.0;
@@ -134,6 +131,7 @@ public class CustomBarChart extends BarChart {
try {
currentValue = Double.parseDouble(stValues.nextToken());
} catch (NumberFormatException e) {
+ // ignore
}
}
dataset.addValue(currentValue, currentSerie, currentCategory);
diff --git a/sonar-server/src/main/java/org/sonar/server/charts/deprecated/PieChart.java b/sonar-server/src/main/java/org/sonar/server/charts/deprecated/PieChart.java
index f8b6da3ef83..2c28dc1255b 100644
--- a/sonar-server/src/main/java/org/sonar/server/charts/deprecated/PieChart.java
+++ b/sonar-server/src/main/java/org/sonar/server/charts/deprecated/PieChart.java
@@ -119,6 +119,7 @@ public class PieChart extends BaseChartWeb implements DeprecatedChart {
measure = Double.parseDouble(st.nextToken());
}
catch (NumberFormatException e) {
+ // ignore
}
dataset.setValue(Integer.toString(i), measure);
i++;
diff --git a/sonar-server/src/main/java/org/sonar/server/plugins/ClassLoaderUtils.java b/sonar-server/src/main/java/org/sonar/server/plugins/ClassLoaderUtils.java
index 9b971a24dc9..21c9df014bd 100644
--- a/sonar-server/src/main/java/org/sonar/server/plugins/ClassLoaderUtils.java
+++ b/sonar-server/src/main/java/org/sonar/server/plugins/ClassLoaderUtils.java
@@ -99,9 +99,7 @@ public final class ClassLoaderUtils {
URL root = classLoader.getResource(rootPath);
if (root != null) {
- if (!"jar".equals(root.getProtocol())) {
- throw new IllegalStateException("Unsupported protocol: " + root.getProtocol());
- }
+ checkJarFile(root);
// Path of the root directory
// Examples :
@@ -127,4 +125,10 @@ public final class ClassLoaderUtils {
throw Throwables.propagate(e);
}
}
+
+ private static void checkJarFile(URL root) {
+ if (!"jar".equals(root.getProtocol())) {
+ throw new IllegalStateException("Unsupported protocol: " + root.getProtocol());
+ }
+ }
}
diff --git a/sonar-server/src/main/java/org/sonar/server/plugins/StaticResourcesServlet.java b/sonar-server/src/main/java/org/sonar/server/plugins/StaticResourcesServlet.java
index d84970b7ae8..6e06c03e0e7 100644
--- a/sonar-server/src/main/java/org/sonar/server/plugins/StaticResourcesServlet.java
+++ b/sonar-server/src/main/java/org/sonar/server/plugins/StaticResourcesServlet.java
@@ -25,14 +25,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.server.platform.Platform;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
public class StaticResourcesServlet extends HttpServlet {
@@ -40,8 +39,7 @@ public class StaticResourcesServlet extends HttpServlet {
private static final long serialVersionUID = -2577454614650178426L;
@Override
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
+ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String pluginKey = getPluginKey(request);
String resource = getResourcePath(request);