aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-06-21 22:35:43 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-06-21 23:00:50 +0200
commit71e022071f6b244422f74580ec3c04179695a3ea (patch)
treea40a03e941f1e30ab3cc1a39e30c3c4f8990f79d
parent44447ed6b69b1497ed60cc4d610742a5d9987873 (diff)
downloadsonarqube-71e022071f6b244422f74580ec3c04179695a3ea.tar.gz
sonarqube-71e022071f6b244422f74580ec3c04179695a3ea.zip
Fix quality flaws
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/app/NullJarScanner.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/app/TomcatAccessLog.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BarChart.java9
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BaseChart.java11
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BaseChartWeb.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarChart.java7
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarRenderer.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/PieChart.java11
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/SparkLinesChart.java9
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/ComputationThreadLauncher.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/db/migrations/Select.java14
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java6
-rw-r--r--sonar-application/src/main/java/org/sonar/application/JdbcSettings.java19
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcLeakPrevention.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/compute/AbstractCoverageDecorator.java2
-rw-r--r--sonar-home/src/main/java/org/sonar/home/cache/FileCache.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java11
18 files changed, 55 insertions, 64 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/app/NullJarScanner.java b/server/sonar-server/src/main/java/org/sonar/server/app/NullJarScanner.java
index db06ae1315f..883aeae3517 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/app/NullJarScanner.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/app/NullJarScanner.java
@@ -44,6 +44,6 @@ class NullJarScanner implements JarScanner {
@Override
public void setJarScanFilter(JarScanFilter jarScanFilter) {
-
+ // no need to filter
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/app/TomcatAccessLog.java b/server/sonar-server/src/main/java/org/sonar/server/app/TomcatAccessLog.java
index eb34606780f..b04414de817 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/app/TomcatAccessLog.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/app/TomcatAccessLog.java
@@ -40,7 +40,7 @@ class TomcatAccessLog {
configureLogbackAccess(tomcat, props);
}
- private void configureLogbackAccess(Tomcat tomcat, Props props) {
+ private static void configureLogbackAccess(Tomcat tomcat, Props props) {
if (props.valueAsBoolean(PROPERTY_ENABLE, true)) {
ProgrammaticLogbackValve valve = new ProgrammaticLogbackValve();
LogbackHelper helper = new LogbackHelper();
diff --git a/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BarChart.java b/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BarChart.java
index 45e397cd446..513711c6f79 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BarChart.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BarChart.java
@@ -19,6 +19,10 @@
*/
package org.sonar.server.charts.deprecated;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.util.Map;
+import java.util.StringTokenizer;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
@@ -31,11 +35,6 @@ import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.RectangleInsets;
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.util.Map;
-import java.util.StringTokenizer;
-
public class BarChart extends BaseChartWeb implements DeprecatedChart {
private BarRenderer renderer = null;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BaseChart.java b/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BaseChart.java
index 6df040f1c51..580ea9ba432 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BaseChart.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BaseChart.java
@@ -19,17 +19,16 @@
*/
package org.sonar.server.charts.deprecated;
-import org.jfree.chart.JFreeChart;
-import org.jfree.chart.encoders.KeypointPNGEncoderAdapter;
-import org.jfree.chart.title.LegendTitle;
-import org.jfree.chart.title.TextTitle;
-import org.jfree.ui.RectangleEdge;
-
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.encoders.KeypointPNGEncoderAdapter;
+import org.jfree.chart.title.LegendTitle;
+import org.jfree.chart.title.TextTitle;
+import org.jfree.ui.RectangleEdge;
public abstract class BaseChart {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BaseChartWeb.java b/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BaseChartWeb.java
index e982a334f0a..04878089736 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BaseChartWeb.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BaseChartWeb.java
@@ -19,12 +19,11 @@
*/
package org.sonar.server.charts.deprecated;
-import org.jfree.chart.JFreeChart;
-import org.jfree.chart.renderer.AbstractRenderer;
-
import java.awt.*;
import java.util.Map;
import java.util.StringTokenizer;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.renderer.AbstractRenderer;
public abstract class BaseChartWeb extends BaseChart {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarChart.java b/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarChart.java
index 4541ce07895..ef1c05e9449 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarChart.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarChart.java
@@ -19,15 +19,14 @@
*/
package org.sonar.server.charts.deprecated;
-import org.jfree.chart.plot.CategoryPlot;
-import org.jfree.data.category.DefaultCategoryDataset;
-import org.jfree.ui.RectangleInsets;
-
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Map;
import java.util.StringTokenizer;
+import org.jfree.chart.plot.CategoryPlot;
+import org.jfree.data.category.DefaultCategoryDataset;
+import org.jfree.ui.RectangleInsets;
public class CustomBarChart extends BarChart {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarRenderer.java b/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarRenderer.java
index 2e6fd3a7cd7..2ebb50d3479 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarRenderer.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarRenderer.java
@@ -19,9 +19,8 @@
*/
package org.sonar.server.charts.deprecated;
-import org.jfree.chart.renderer.category.BarRenderer;
-
import java.awt.*;
+import org.jfree.chart.renderer.category.BarRenderer;
public class CustomBarRenderer extends BarRenderer {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/PieChart.java b/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/PieChart.java
index 1c169704270..9c122eca975 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/PieChart.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/PieChart.java
@@ -19,17 +19,16 @@
*/
package org.sonar.server.charts.deprecated;
-import org.jfree.chart.JFreeChart;
-import org.jfree.chart.plot.PiePlot;
-import org.jfree.chart.title.TextTitle;
-import org.jfree.data.general.DefaultPieDataset;
-import org.jfree.ui.RectangleInsets;
-
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Map;
import java.util.StringTokenizer;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.PiePlot;
+import org.jfree.chart.title.TextTitle;
+import org.jfree.data.general.DefaultPieDataset;
+import org.jfree.ui.RectangleInsets;
public class PieChart extends BaseChartWeb implements DeprecatedChart {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/SparkLinesChart.java b/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/SparkLinesChart.java
index dd11353b220..cc2162179b6 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/SparkLinesChart.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/SparkLinesChart.java
@@ -19,6 +19,10 @@
*/
package org.sonar.server.charts.deprecated;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.util.Map;
+import java.util.StringTokenizer;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.DateTickUnit;
@@ -30,11 +34,6 @@ import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.RectangleInsets;
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.util.Map;
-import java.util.StringTokenizer;
-
public class SparkLinesChart extends BaseChartWeb implements DeprecatedChart {
private XYSeriesCollection dataset = null;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationThreadLauncher.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationThreadLauncher.java
index 01f43c73ef3..018f2e9d687 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationThreadLauncher.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationThreadLauncher.java
@@ -89,7 +89,7 @@ public class ComputationThreadLauncher implements Startable, ServerStartHandler
executorService.scheduleAtFixedRate(new ComputationThread(queue, sqContainer, containerFactory), delayForFirstStart, delayBetweenTasks, timeUnit);
}
- private ThreadFactory newThreadFactory() {
+ private static ThreadFactory newThreadFactory() {
return new ThreadFactoryBuilder()
.setNameFormat(THREAD_NAME_PREFIX + "%d").setPriority(Thread.MIN_PRIORITY).build();
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/Select.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/Select.java
index 8259660f63e..5d3b8226f60 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/Select.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/Select.java
@@ -30,7 +30,7 @@ import javax.annotation.CheckForNull;
public interface Select extends SqlStatement<Select> {
- static class Row {
+ class Row {
private final ResultSet rs;
Row(ResultSet rs) {
@@ -127,11 +127,11 @@ public interface Select extends SqlStatement<Select> {
}
}
- static interface RowReader<T> {
+ interface RowReader<T> {
T read(Row row) throws SQLException;
}
- static class LongReader implements RowReader<Long> {
+ class LongReader implements RowReader<Long> {
private LongReader() {
}
@@ -141,9 +141,9 @@ public interface Select extends SqlStatement<Select> {
}
}
- static final RowReader<Long> LONG_READER = new LongReader();
+ RowReader<Long> LONG_READER = new LongReader();
- static class StringReader implements RowReader<String> {
+ class StringReader implements RowReader<String> {
private StringReader() {
}
@@ -153,9 +153,9 @@ public interface Select extends SqlStatement<Select> {
}
}
- static final RowReader<String> STRING_READER = new StringReader();
+ RowReader<String> STRING_READER = new StringReader();
- static interface RowHandler<T> {
+ interface RowHandler {
void handle(Row row) throws SQLException;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java b/server/sonar-server/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java
index 5e004e69b2b..24309f86f1b 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java
@@ -95,8 +95,8 @@ public class EmailNotificationChannel extends NotificationChannel {
@Override
public void deliver(Notification notification, String username) {
User user = userFinder.findByLogin(username);
- if (StringUtils.isBlank(user.email())) {
- LOG.debug("Email not defined for user: " + username);
+ if (user == null || StringUtils.isBlank(user.email())) {
+ LOG.debug("User does not exist or has no email: {}", username);
return;
}
EmailMessage emailMessage = format(notification);
@@ -133,7 +133,7 @@ public class EmailNotificationChannel extends NotificationChannel {
}
private void send(EmailMessage emailMessage) throws EmailException {
- // Trick to correctly initilize javax.mail library
+ // Trick to correctly initialize javax.mail library
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
diff --git a/sonar-application/src/main/java/org/sonar/application/JdbcSettings.java b/sonar-application/src/main/java/org/sonar/application/JdbcSettings.java
index cbfbf4d6265..0a8f22839f5 100644
--- a/sonar-application/src/main/java/org/sonar/application/JdbcSettings.java
+++ b/sonar-application/src/main/java/org/sonar/application/JdbcSettings.java
@@ -19,18 +19,17 @@
*/
package org.sonar.application;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.LoggerFactory;
-import org.sonar.process.MessageException;
-import org.sonar.process.ProcessProperties;
-import org.sonar.process.Props;
-
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.process.MessageException;
+import org.sonar.process.ProcessProperties;
+import org.sonar.process.Props;
public class JdbcSettings {
@@ -73,13 +72,13 @@ public class JdbcSettings {
Pattern pattern = Pattern.compile("jdbc:(\\w+):.+");
Matcher matcher = pattern.matcher(url);
if (!matcher.find()) {
- throw new MessageException(String.format("Bad format of JDBC URL: " + url));
+ throw new MessageException(String.format("Bad format of JDBC URL: %s", url));
}
String key = matcher.group(1);
try {
return Provider.valueOf(StringUtils.upperCase(key));
} catch (IllegalArgumentException e) {
- throw new MessageException(String.format(String.format("Unsupported JDBC driver provider: %s", key)));
+ throw new MessageException(String.format("Unsupported JDBC driver provider: %s", key));
}
}
@@ -100,7 +99,7 @@ public class JdbcSettings {
private void checkRecommendedParameter(String url, String val) {
if (!url.contains(val)) {
- LoggerFactory.getLogger(getClass()).warn(String.format("JDBC URL is recommended to have the property '%s'", val));
+ Loggers.get(getClass()).warn("JDBC URL is recommended to have the property '{}'", val);
}
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcLeakPrevention.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcLeakPrevention.java
index c98fd8faf30..17a80a26d5f 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcLeakPrevention.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcLeakPrevention.java
@@ -59,7 +59,7 @@ public class JdbcLeakPrevention {
return unregisteredNames;
}
- private Set<Driver> registeredDrivers() {
+ private static Set<Driver> registeredDrivers() {
Set<Driver> registeredDrivers = new HashSet<>();
Enumeration<Driver> drivers = DriverManager.getDrivers();
while (drivers.hasMoreElements()) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/compute/AbstractCoverageDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/compute/AbstractCoverageDecorator.java
index 4960f991ea2..8db0fa46dfa 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/compute/AbstractCoverageDecorator.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/compute/AbstractCoverageDecorator.java
@@ -84,7 +84,7 @@ public abstract class AbstractCoverageDecorator implements Decorator {
}
}
- private double calculateCoverage(final long coveredLines, final long lines) {
+ private static double calculateCoverage(final long coveredLines, final long lines) {
return (100.0 * coveredLines) / lines;
}
diff --git a/sonar-home/src/main/java/org/sonar/home/cache/FileCache.java b/sonar-home/src/main/java/org/sonar/home/cache/FileCache.java
index 3b681edcff1..5998b97a2c5 100644
--- a/sonar-home/src/main/java/org/sonar/home/cache/FileCache.java
+++ b/sonar-home/src/main/java/org/sonar/home/cache/FileCache.java
@@ -106,7 +106,7 @@ public class FileCache {
// Check if the file was cached by another process during download
if (!rename && !targetFile.exists()) {
log.warn(String.format("Unable to rename %s to %s", sourceFile.getAbsolutePath(), targetFile.getAbsolutePath()));
- log.warn(String.format("A copy/delete will be tempted but with no garantee of atomicity"));
+ log.warn("A copy/delete will be tempted but with no guarantee of atomicity");
try {
Files.move(sourceFile.toPath(), targetFile.toPath());
} catch (IOException e) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java
index 10989371fe3..945f463721e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java
@@ -621,7 +621,7 @@ public class ProjectDefinition {
}
ProjectDefinition that = (ProjectDefinition) o;
String key = getKey();
- return !(key != null ? !key.equals(that.getKey()) : that.getKey() != null);
+ return !((key != null) ? !key.equals(that.getKey()) : (that.getKey() != null));
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java
index 1e33ff929e5..86b240416fb 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java
@@ -55,20 +55,19 @@ public final class ZipUtils {
return toDir;
}
+ public static File unzip(InputStream zip, File toDir) throws IOException {
+ unzip(zip, toDir, TrueZipEntryFilter.INSTANCE);
+ return toDir;
+ }
+
private enum TrueZipEntryFilter implements ZipEntryFilter {
INSTANCE;
-
@Override
public boolean accept(ZipEntry entry) {
return true;
}
}
- public static File unzip(InputStream zip, File toDir) throws IOException {
- unzip(zip, toDir, TrueZipEntryFilter.INSTANCE);
- return toDir;
- }
-
public static File unzip(InputStream stream, File toDir, ZipEntryFilter filter) throws IOException {
if (!toDir.exists()) {
FileUtils.forceMkdir(toDir);