aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/rule/QProfileEventsDecorator.java16
-rw-r--r--sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rules/QProfile.java11
3 files changed, 21 insertions, 10 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileEventsDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileEventsDecorator.java
index 9f05d4e5fa0..eeb1c7fd777 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileEventsDecorator.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileEventsDecorator.java
@@ -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()) {
diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java
index 5401261cfa5..e2d9ab3c51a 100644
--- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java
+++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java
@@ -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;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rules/QProfile.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rules/QProfile.java
index 189cdc06158..7a8d62152d7 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rules/QProfile.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rules/QProfile.java
@@ -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();
+ }
}