]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Sun, 21 Jun 2015 20:35:43 +0000 (22:35 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Sun, 21 Jun 2015 21:00:50 +0000 (23:00 +0200)
18 files changed:
server/sonar-server/src/main/java/org/sonar/server/app/NullJarScanner.java
server/sonar-server/src/main/java/org/sonar/server/app/TomcatAccessLog.java
server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BarChart.java
server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BaseChart.java
server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BaseChartWeb.java
server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarChart.java
server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarRenderer.java
server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/PieChart.java
server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/SparkLinesChart.java
server/sonar-server/src/main/java/org/sonar/server/computation/ComputationThreadLauncher.java
server/sonar-server/src/main/java/org/sonar/server/db/migrations/Select.java
server/sonar-server/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java
sonar-application/src/main/java/org/sonar/application/JdbcSettings.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcLeakPrevention.java
sonar-batch/src/main/java/org/sonar/batch/compute/AbstractCoverageDecorator.java
sonar-home/src/main/java/org/sonar/home/cache/FileCache.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java
sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java

index db06ae1315f777ccafaa2df17f859dde855c9472..883aeae351766dc258ed83ac7b77ad267028cc3f 100644 (file)
@@ -44,6 +44,6 @@ class NullJarScanner implements JarScanner {
 
   @Override
   public void setJarScanFilter(JarScanFilter jarScanFilter) {
-
+    // no need to filter
   }
 }
index eb34606780fecc707fa4db6d903a17eb04c1ec50..b04414de817d79d225d589f27a7d0daa16d381bb 100644 (file)
@@ -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();
index 45e397cd4463cfc20f891a4ed631c8b2b60b9ab1..513711c6f7998e3861933da58fc083c97b1fe750 100644 (file)
  */
 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;
index 6df040f1c510deb0e814c34e9c5129f33f2d09da..580ea9ba432881a59dc0950f2bd80bb3b722d553 100644 (file)
  */
 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 {
 
index e982a334f0a106ad8d2b210f8ee5b008807cb385..048780897367126c9daaac048e2b775ad9a62bcf 100644 (file)
  */
 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 {
 
index 4541ce07895f7b480b8a37b111387a011d0d1dfe..ef1c05e9449277ea8d693921e9799a5d2e504190 100644 (file)
  */
 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 {
 
index 2e6fd3a7cd75b8389cb15be94fd3549f3ad007aa..2ebb50d3479f0ee87100d6fe9057d7fff16bb8ae 100644 (file)
@@ -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 {
 
index 1c169704270667430b7d1e1230b8128356267c2b..9c122eca9757d045093577caadcac14d38848229 100644 (file)
  */
 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 {
 
index dd11353b2207d9c7736d617c8dbdb7a03a6bd75b..cc2162179b6e69c8bc2d44df0ea768d3bf5ac08a 100644 (file)
  */
 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;
index 01f43c73ef3436b591da9c2b64bd1ab0bf8e77fb..018f2e9d687ab3cc5a0772585ec36d99acd199d5 100644 (file)
@@ -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();
   }
index 8259660f63ee5cde10212ceedb0436ddac720923..5d3b8226f601ac51132842fe15e63637821e4d43 100644 (file)
@@ -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;
   }
 
index 5e004e69b2b11c7f08c08332e51c150dd2504389..24309f86f1b18d548f8858f98a55f52a2b7ef3e8 100644 (file)
@@ -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());
 
index cbfbf4d62659ebe7c107fd5506c6cd6d59a1dacc..0a8f22839f5030dea35471da27018769cf4716d3 100644 (file)
  */
 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);
     }
   }
 }
index c98fd8faf30b19128a5893ff121d9539ec4a8d75..17a80a26d5f93273de5b9b28b1d3433debefa8b1 100644 (file)
@@ -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()) {
index 4960f991ea2cda9106afb3fe869e02cdc4b51827..8db0fa46dfaa3f3667d9310b2ff8da9e24f74c24 100644 (file)
@@ -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;
   }
 
index 3b681edcff1cc1d24145b56207d03094e90189f4..5998b97a2c5dc9ba3a606cdf26f549824a6eafbe 100644 (file)
@@ -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) {
index 10989371fe38003417ee7e0493d74cc62fac9c42..945f463721e3bee84bf58869459fc9a98956ca7a 100644 (file)
@@ -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));
 
   }
 
index 1e33ff929e52d6f96500410aaa10ec11bcd9391b..86b240416fb1cd601213758e7638cdda516fa00e 100644 (file)
@@ -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);