]> source.dussan.org Git - sonarqube.git/commitdiff
Fix some quality flaws
authorJulien HENRY <julien.henry@sonarsource.com>
Wed, 10 Jul 2013 09:30:57 +0000 (11:30 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Wed, 10 Jul 2013 09:31:30 +0000 (11:31 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java
sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasureUtils.java
sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java
sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java
sonar-plugin-api/src/main/java/org/sonar/api/measures/package-info.java [new file with mode: 0644]

index c49d279ea567abbcdafab5ea2653bbeba705b236..b6b8a2fb2aaf54ce3f89c74df9807bcd521013d9 100644 (file)
  */
 package org.sonar.plugins.core.issue;
 
-import org.sonar.api.measures.FileLinesContextFactory;
-
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.FileLinesContext;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Strings;
 import com.google.common.collect.Lists;
-import org.sonar.api.batch.*;
+import org.sonar.api.batch.Decorator;
+import org.sonar.api.batch.DecoratorBarriers;
+import org.sonar.api.batch.DecoratorContext;
+import org.sonar.api.batch.DependedUpon;
+import org.sonar.api.batch.DependsUpon;
 import org.sonar.api.component.ResourcePerspectives;
 import org.sonar.api.issue.Issuable;
 import org.sonar.api.issue.Issue;
 import org.sonar.api.issue.internal.DefaultIssue;
 import org.sonar.api.issue.internal.IssueChangeContext;
+import org.sonar.api.measures.CoreMetrics;
+import org.sonar.api.measures.FileLinesContext;
+import org.sonar.api.measures.FileLinesContextFactory;
 import org.sonar.api.profiles.RulesProfile;
 import org.sonar.api.resources.Project;
 import org.sonar.api.resources.Resource;
@@ -64,13 +67,13 @@ public class IssueTrackingDecorator implements Decorator {
   private FileLinesContextFactory fileLineContextFactory;
 
   public IssueTrackingDecorator(IssueCache issueCache, InitialOpenIssuesStack initialOpenIssues, IssueTracking tracking,
-                                IssueHandlers handlers, IssueWorkflow workflow,
-                                IssueUpdater updater,
-                                Project project,
-                                ResourcePerspectives perspectives,
-                                RulesProfile rulesProfile,
-                                RuleFinder ruleFinder,
-                                FileLinesContextFactory fileLineContextFactory) {
+      IssueHandlers handlers, IssueWorkflow workflow,
+      IssueUpdater updater,
+      Project project,
+      ResourcePerspectives perspectives,
+      RulesProfile rulesProfile,
+      RuleFinder ruleFinder,
+      FileLinesContextFactory fileLineContextFactory) {
     this.issueCache = issueCache;
     this.initialOpenIssues = initialOpenIssues;
     this.tracking = tracking;
@@ -133,9 +136,10 @@ public class IssueTrackingDecorator implements Decorator {
     if (ResourceUtils.isFile(resource)) {
       FileLinesContext fileLineContext = fileLineContextFactory.createFor(resource);
       for (DefaultIssue issue : newIssues) {
-        if (issue.line() != null) {
+        Integer line = issue.line();
+        if (line != null) {
           // TODO When issue is on line 0 then who is the author?
-          String scmAuthorLogin = fileLineContext.getStringValue(CoreMetrics.SCM_AUTHORS_BY_LINE_KEY, issue.line());
+          String scmAuthorLogin = fileLineContext.getStringValue(CoreMetrics.SCM_AUTHORS_BY_LINE_KEY, line);
           if (scmAuthorLogin != null) {
             issue.setAuthorLogin(scmAuthorLogin);
           }
index 81dad9e275997ca7feae9e9c955e57329b4a010f..9f77587903cf5218b2be753e25b40c1876f61f71 100644 (file)
  */
 package org.sonar.api.measures;
 
-import java.util.Collection;
-
 import org.apache.commons.lang.StringUtils;
 
+import javax.annotation.Nullable;
+
+import java.util.Collection;
+
 /**
  * An utility class to manipulate measures
  *
@@ -62,7 +64,7 @@ public final class MeasureUtils {
    * @return <code>defaultValue</code> if measure is null or has no values.
    */
 
-  public static Double getValue(Measure measure, Double defaultValue) {
+  public static Double getValue(Measure measure, @Nullable Double defaultValue) {
     if (MeasureUtils.hasValue(measure)) {
       return measure.getValue();
     }
@@ -80,7 +82,7 @@ public final class MeasureUtils {
     return getVariation(measure, periodIndex, null);
   }
 
-  public static Double getVariation(Measure measure, int periodIndex, Double defaultValue) {
+  public static Double getVariation(Measure measure, int periodIndex, @Nullable Double defaultValue) {
     Double result = null;
     if (measure != null) {
       result = measure.getVariation(periodIndex);
@@ -92,7 +94,7 @@ public final class MeasureUtils {
     return getVariationAsLong(measure, periodIndex, null);
   }
 
-  public static Long getVariationAsLong(Measure measure, int periodIndex, Long defaultValue) {
+  public static Long getVariationAsLong(Measure measure, int periodIndex, @Nullable Long defaultValue) {
     Double result = null;
     if (measure != null) {
       result = measure.getVariation(periodIndex);
index 58ba8bc979702b8cfae14aecaa1bcf60df082adb..081bb09df62e768294742e9cb14748658ee3fea4 100644 (file)
@@ -26,6 +26,7 @@ import org.sonar.api.BatchExtension;
 import org.sonar.api.ServerExtension;
 import org.sonar.api.batch.InstantiationStrategy;
 
+import javax.annotation.Nullable;
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.EnumType;
@@ -211,7 +212,7 @@ public class Metric implements ServerExtension, BatchExtension {
    * @deprecated since 2.7 use the {@link Builder} factory.
    */
   @Deprecated
-  public Metric(String key, String name, String description, ValueType type, Integer direction, Boolean qualitative, String domain,
+  public Metric(String key, String name, String description, ValueType type, Integer direction, Boolean qualitative, @Nullable String domain,
       boolean userManaged) {
     this.key = key;
     this.description = description;
index efba225462c6d0469378bbbe0246897766cdfe7e..cf33a84c0ffaf906af0ff27608a1123508ee5673 100644 (file)
@@ -25,6 +25,8 @@ import org.apache.commons.lang.builder.ToStringBuilder;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RulePriority;
 
+import javax.annotation.Nullable;
+
 /**
  * @since 1.10
  */
@@ -36,7 +38,7 @@ public class RuleMeasure extends Measure {
   /**
    * This constructor is for internal use only. Please use static methods createForXXX().
    */
-  public RuleMeasure(Metric metric, Rule rule, RulePriority rulePriority, Integer ruleCategory) {
+  public RuleMeasure(Metric metric, @Nullable Rule rule, @Nullable RulePriority rulePriority, @Nullable Integer ruleCategory) {
     super(metric);
     this.rule = rule;
     this.rulePriority = rulePriority;
@@ -103,7 +105,7 @@ public class RuleMeasure extends Measure {
     if (obj == null) {
       return false;
     }
-    if (!(obj.getClass().equals(RuleMeasure.class))) {//NOSONAR should be refactored but kept in the current state
+    if (!(obj.getClass().equals(RuleMeasure.class))) {// NOSONAR should be refactored but kept in the current state
       // for the moment.
       return false;
     }
@@ -112,10 +114,10 @@ public class RuleMeasure extends Measure {
     }
     RuleMeasure other = (RuleMeasure) obj;
     return new EqualsBuilder()
-      .append(getMetric(), other.getMetric())
-      .append(personId, other.personId)
-      .append(rule, other.rule)
-      .isEquals();
+        .append(getMetric(), other.getMetric())
+        .append(personId, other.personId)
+        .append(rule, other.rule)
+        .isEquals();
   }
 
   @Override
@@ -126,34 +128,34 @@ public class RuleMeasure extends Measure {
   @Override
   public int hashCode() {
     return new HashCodeBuilder(17, 37)
-      .append(getMetric())
-      .append(personId)
-      .append(rule)
-      .toHashCode();
+        .append(getMetric())
+        .append(personId)
+        .append(rule)
+        .toHashCode();
   }
 
   @Override
   public String toString() {
     return new ToStringBuilder(this)
-      .append("id", getId())
-      .append("metric", metric)
-      .append("personId", personId)
-      .append("rule", rule)
-      .append("value", value)
-      .append("data", data)
-      .append("description", description)
-      .append("alertStatus", alertStatus)
-      .append("alertText", alertText)
-      .append("tendency", tendency)
-      .append("severity", rulePriority)
-      .toString();
-  }
-
-  public static RuleMeasure createForRule(Metric metric, Rule rule, Double value) {
+        .append("id", getId())
+        .append("metric", metric)
+        .append("personId", personId)
+        .append("rule", rule)
+        .append("value", value)
+        .append("data", data)
+        .append("description", description)
+        .append("alertStatus", alertStatus)
+        .append("alertText", alertText)
+        .append("tendency", tendency)
+        .append("severity", rulePriority)
+        .toString();
+  }
+
+  public static RuleMeasure createForRule(Metric metric, Rule rule, @Nullable Double value) {
     return new RuleMeasure(metric, rule, null, null).setValue(value);
   }
 
-  public static RuleMeasure createForPriority(Metric metric, RulePriority priority, Double value) {
+  public static RuleMeasure createForPriority(Metric metric, RulePriority priority, @Nullable Double value) {
     return new RuleMeasure(metric, null, priority, null).setValue(value);
   }
 
@@ -161,7 +163,7 @@ public class RuleMeasure extends Measure {
    * @deprecated since 2.5. See SONAR-2007.
    */
   @Deprecated
-  public static RuleMeasure createForCategory(Metric metric, Integer category, Double value) {
+  public static RuleMeasure createForCategory(Metric metric, Integer category, @Nullable Double value) {
     return new RuleMeasure(metric, null, null, category).setValue(value);
   }
 }
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/package-info.java
new file mode 100644 (file)
index 0000000..6a66b2a
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.measures;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+