]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 do not generate event on QProfile change on first analysis
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 20 Jun 2014 10:02:30 +0000 (12:02 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 20 Jun 2014 10:08:15 +0000 (12:08 +0200)
sonar-batch/src/main/java/org/sonar/batch/rule/QProfileEventsDecorator.java
sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/rules/QProfile.java

index 9f05d4e5fa0328d868be3e41ad615c0759f23322..eeb1c7fd7778f98e0a13e64341474366c0109f74 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.batch.rule;
 
-import com.google.common.collect.Maps;
 import org.sonar.api.batch.Decorator;
 import org.sonar.api.batch.DecoratorContext;
 import org.sonar.api.batch.DependsUpon;
@@ -66,16 +65,17 @@ public class QProfileEventsDecorator implements Decorator {
       return;
     }
 
-    // Load current profiles
-    Measure currentMeasure = context.getMeasure(CoreMetrics.QUALITY_PROFILES);
-    Map<String, QProfile> currentProfiles = UsedQProfiles.fromJson(currentMeasure.getData()).profilesByKey();
-
     // Load previous profiles
-    Map<String, QProfile> previousProfiles = Maps.newHashMap();
     Measure previousMeasure = getPreviousMeasure(resource, CoreMetrics.QUALITY_PROFILES);
-    if (previousMeasure != null && previousMeasure.getData() != null) {
-      previousProfiles = UsedQProfiles.fromJson(previousMeasure.getData()).profilesByKey();
+    if (previousMeasure == null || previousMeasure.getData() == null) {
+      // first analysis -> do not generate events
+      return;
     }
+    Map<String, QProfile> previousProfiles = UsedQProfiles.fromJson(previousMeasure.getData()).profilesByKey();
+
+    // Load current profiles
+    Measure currentMeasure = context.getMeasure(CoreMetrics.QUALITY_PROFILES);
+    Map<String, QProfile> currentProfiles = UsedQProfiles.fromJson(currentMeasure.getData()).profilesByKey();
 
     // Detect new profiles or updated profiles
     for (QProfile profile : currentProfiles.values()) {
index 5401261cfa50bd0c7d9ae227118adae9f86ddbc7..e2d9ab3c51a543e74a73418424cad222cf35e1db 100644 (file)
@@ -31,7 +31,7 @@ public class PurgeableSnapshotDto implements Comparable<PurgeableSnapshotDto> {
   private boolean isLast;
 
   public Date getDate() {
-    return date;//NOSONAR May expose internal representation by returning reference to mutable object
+    return date;
   }
 
   public long getSnapshotId() {
@@ -47,7 +47,7 @@ public class PurgeableSnapshotDto implements Comparable<PurgeableSnapshotDto> {
   }
 
   public PurgeableSnapshotDto setDate(Date date) {
-    this.date = date;//NOSONAR May expose internal representation by incorporating reference to mutable object
+    this.date = date;
     return this;
   }
 
index 189cdc06158222584767a660dd98a6f2eeec762f..7a8d62152d7656652f620174efe98fd0676467f0 100644 (file)
@@ -19,6 +19,8 @@
  */
 package org.sonar.api.batch.rules;
 
+import com.google.common.base.Objects;
+
 public class QProfile {
 
   private final String key, name, language;
@@ -58,4 +60,13 @@ public class QProfile {
   public int hashCode() {
     return key.hashCode();
   }
+
+  @Override
+  public String toString() {
+    return Objects.toStringHelper(this)
+      .add("key", key)
+      .add("name", name)
+      .add("language", language)
+      .toString();
+  }
 }