]> source.dussan.org Git - sonarqube.git/commitdiff
Fix some quality flaws
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 5 Apr 2012 15:40:57 +0000 (17:40 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 5 Apr 2012 15:41:10 +0000 (17:41 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AlertUtils.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CommentDensityDecorator.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/VersionEventsSensor.java
sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java
sonar-plugin-api/src/main/java/org/sonar/api/config/License.java
sonar-server/src/main/java/org/sonar/server/charts/ChartsServlet.java
sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java

index 5faddcff8212d92a981ef166fb783a9124a1030e..bd1fee2b1e7b258bc98ee6dab3909d9ccb35c510 100644 (file)
@@ -49,9 +49,11 @@ public final class AlertUtils {
 
     } else if (alertLevel.equals(Metric.Level.WARN)) {
       valueToEval = alert.getValueWarning();
+
     } else {
       throw new IllegalStateException(alertLevel.toString());
     }
+
     if (StringUtils.isEmpty(valueToEval)) {
       return false;
     }
@@ -60,13 +62,12 @@ public final class AlertUtils {
     Comparable metricValue = getMeasureValue(alert.getMetric(), measure);
 
     int comparison = metricValue.compareTo(criteriaValue);
-    if (alert.isNotEqualsOperator() && comparison == 0 ||
-        alert.isGreaterOperator() && comparison != 1 ||
-        alert.isSmallerOperator() && comparison != -1 ||
-        alert.isEqualsOperator() && comparison != 0) {
-      return false;
-    }
-    return true;
+    return !(// NOSONAR complexity of this boolean expression is under control
+        (alert.isNotEqualsOperator() && comparison == 0) ||
+        (alert.isGreaterOperator() && comparison != 1) ||
+        (alert.isSmallerOperator() && comparison != -1) ||
+        (alert.isEqualsOperator() && comparison != 0)
+    );
   }
 
 
index 7688f293a2dad74a90829be5873278d8de83e553..fb1f3ef69a155418f03780f29c881e5418756132 100644 (file)
@@ -61,11 +61,9 @@ public class CommentDensityDecorator implements Decorator {
 
     Measure ncloc = context.getMeasure(CoreMetrics.NCLOC);
     Measure comments = context.getMeasure(CoreMetrics.COMMENT_LINES);
-    if (MeasureUtils.hasValue(ncloc) && MeasureUtils.hasValue(comments)) {
-      if (comments.getValue() + ncloc.getValue() > 0) {
-        double val = 100.0 * (comments.getValue() / (comments.getValue() + ncloc.getValue()));
-        context.saveMeasure(new Measure(CoreMetrics.COMMENT_LINES_DENSITY, val));
-      }
+    if (MeasureUtils.hasValue(ncloc) && MeasureUtils.hasValue(comments) && (comments.getValue() + ncloc.getValue()) > 0) {
+      double val = 100.0 * (comments.getValue() / (comments.getValue() + ncloc.getValue()));
+      context.saveMeasure(new Measure(CoreMetrics.COMMENT_LINES_DENSITY, val));
     }
   }
 
index e74d012f075cb659d24cba5fb05a42a8a21a35c9..b1fab18025828497c5fb019f554db67fb54b84fb 100644 (file)
@@ -50,12 +50,9 @@ public class VersionEventsSensor implements Sensor {
     String snapshotVersionToDelete = (version.endsWith(SNAPSHOT_SUFFIX) ? "" : version + SNAPSHOT_SUFFIX);
     for (Iterator<Event> it = context.getEvents(project).iterator(); it.hasNext();) {
       Event event = it.next();
-      if (event.isVersionCategory()) {
-        if (version.equals(event.getName()) || snapshotVersionToDelete.equals(event.getName())) {
-          it.remove();
-          context.deleteEvent(event);
-          event = null;
-        }
+      if (event.isVersionCategory() && (version.equals(event.getName()) || snapshotVersionToDelete.equals(event.getName()))) {
+        it.remove();
+        context.deleteEvent(event);
       }
     }
   }
index 5c3bfeaefaeca3024102eafc6be6e85fc1e2e44c..74e1bfe06a43fa7bfb08911f0134630b2cb11f2d 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.api.config;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Charsets;
 import com.google.common.base.Throwables;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.io.FileUtils;
index bfc0cab23dfcb7ce31c9ba5d4c64e8788b821a78..93a22713ead55844ec00fefaabaa9364d90f4976 100644 (file)
@@ -27,6 +27,7 @@ import org.apache.commons.lang.StringUtils;
 import org.sonar.api.utils.DateUtils;
 
 import javax.annotation.Nullable;
+import java.io.IOException;
 import java.io.StringReader;
 import java.util.Calendar;
 import java.util.Date;
@@ -112,7 +113,7 @@ public final class License {
         }
       }
 
-    } catch (Exception e) {
+    } catch (IOException e) {
       // silently ignore
 
     } finally {
index 2a39719585d3762674de3a449df62fdfb66c11da..77e05930a4673ccf71667e77cbb104a485416a25 100644 (file)
@@ -37,7 +37,6 @@ import java.awt.image.BufferedImage;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Enumeration;
-import java.util.HashMap;
 import java.util.Map;
 
 public class ChartsServlet extends HttpServlet {
index 51372edf0d5f93e723d48a9776f368525671ca40..d5683bddddb9ec17595804bcdb51b7cbd9a321ee 100644 (file)
@@ -53,7 +53,6 @@ import org.sonar.server.notifications.reviews.ReviewsNotificationManager;
 import org.sonar.server.platform.GlobalSettingsUpdater;
 import org.sonar.server.platform.Platform;
 import org.sonar.server.platform.ServerIdGenerator;
-import org.sonar.server.platform.ServerSettings;
 import org.sonar.server.plugins.*;
 import org.sonar.server.rules.ProfilesConsole;
 import org.sonar.server.rules.RulesConsole;