diff options
Diffstat (limited to 'sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java index ee3ad649957..eb374de1094 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java @@ -30,6 +30,7 @@ import org.sonar.api.measures.MetricFinder; import org.sonar.api.resources.Resource; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -61,8 +62,10 @@ public class PastMeasuresLoader implements BatchExtension { } public List<MeasureModel> getPastMeasures(Resource resource, Snapshot projectSnapshot) { - // assume that the resource has already been saved - return getPastMeasures(resource.getId(), projectSnapshot); + if (isPersisted(resource)) { + return getPastMeasures(resource.getId(), projectSnapshot); + } + return Collections.emptyList(); } public List<MeasureModel> getPastMeasures(int resourceId, Snapshot projectSnapshot) { @@ -78,4 +81,8 @@ public class PastMeasuresLoader implements BatchExtension { .setParameter("status", Snapshot.STATUS_PROCESSED) .getResultList(); } + + private boolean isPersisted(Resource resource) { + return resource.getId()!=null; + } } |