diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-09-24 08:29:39 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-09-24 08:29:39 +0200 |
commit | c1994d915d17b5f004270ec1de917f4301d80010 (patch) | |
tree | ecf41257e2cdfcfd11f13946b7d1c03e7834f702 | |
parent | eac9c2698d8d64b0e1fe46265286dba80ee31db3 (diff) | |
download | sonarqube-c1994d915d17b5f004270ec1de917f4301d80010.tar.gz sonarqube-c1994d915d17b5f004270ec1de917f4301d80010.zip |
Fix quality flaws
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java | 11 | ||||
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java | 10 |
2 files changed, 14 insertions, 7 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java index 6c1c1fc545b..b4b3cf7a064 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java @@ -32,6 +32,8 @@ import org.sonar.api.config.Settings; import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Qualifiers; +import javax.annotation.Nullable; + import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; @@ -96,7 +98,7 @@ public class PastSnapshotFinder implements BatchExtension { return conf.getString(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + index, defaultValue); } - public PastSnapshot find(Snapshot projectSnapshot, String rootQualifier, Settings settings, int index) { + public PastSnapshot find(Snapshot projectSnapshot, @Nullable String rootQualifier, Settings settings, int index) { String propertyValue = getPropertyValue(rootQualifier, settings, index); PastSnapshot pastSnapshot = find(projectSnapshot, index, propertyValue); if (pastSnapshot == null && StringUtils.isNotBlank(propertyValue)) { @@ -109,7 +111,7 @@ public class PastSnapshotFinder implements BatchExtension { return find(projectSnapshot, null, settings, index); } - static String getPropertyValue(String rootQualifier, Settings settings, int index) { + static String getPropertyValue(@Nullable String rootQualifier, Settings settings, int index) { String value = settings.getString(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + index); // For periods 4 and 5 we're searching for a property prefixed by the qualifier if (index > 3 && Strings.isNullOrEmpty(value)) { @@ -122,6 +124,7 @@ public class PastSnapshotFinder implements BatchExtension { return finderByPreviousAnalysis.findByPreviousAnalysis(projectSnapshot); } + @Nullable public PastSnapshot find(Snapshot projectSnapshot, int index, String property) { if (StringUtils.isBlank(property)) { return null; @@ -148,6 +151,7 @@ public class PastSnapshotFinder implements BatchExtension { return result; } + @Nullable private PastSnapshot findByPreviousAnalysis(Snapshot projectSnapshot, String property) { PastSnapshot pastSnapshot = null; if (StringUtils.equals(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, property)) { @@ -156,6 +160,7 @@ public class PastSnapshotFinder implements BatchExtension { return pastSnapshot; } + @Nullable private PastSnapshot findByPreviousVersion(Snapshot projectSnapshot, String property) { PastSnapshot pastSnapshot = null; if (StringUtils.equals(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, property)) { @@ -164,6 +169,7 @@ public class PastSnapshotFinder implements BatchExtension { return pastSnapshot; } + @Nullable private PastSnapshot findByDate(Snapshot projectSnapshot, String property) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); try { @@ -179,6 +185,7 @@ public class PastSnapshotFinder implements BatchExtension { return finderByVersion.findByVersion(projectSnapshot, property); } + @Nullable private PastSnapshot findByDays(Snapshot projectSnapshot, String property) { try { int days = Integer.parseInt(property); diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java index df39afe3273..673c1541054 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java @@ -111,12 +111,12 @@ public final class MeasurePersister { } private static boolean isMeasureNotEmpty(Measure measure){ + boolean isNotEmpty = false; + for (int i = 1; i<=5; i++) { + isNotEmpty = isNotEmpty || measure.getVariation(i) != null; + } return measure.getValue() != null || measure.getData() != null - || measure.getVariation1() != null - || measure.getVariation2() != null - || measure.getVariation3() != null - || measure.getVariation4() != null - || measure.getVariation5() != null; + || isNotEmpty; } private List<MeasureModelAndDetails> getMeasuresToSave() { |