]> source.dussan.org Git - sonarqube.git/commitdiff
Fix issue tracking when no server analysis
authorJulien HENRY <julien.henry@sonarsource.com>
Mon, 3 Aug 2015 17:28:44 +0000 (19:28 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Mon, 3 Aug 2015 17:28:44 +0000 (19:28 +0200)
sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java

index 8fcbe931c362a73e364f9faaecc4812d74088b14..ecd8ba5ad2c3ba28adad6f17432edf2664ec1d29 100644 (file)
@@ -69,11 +69,12 @@ public class LocalIssueTracking {
   private final ActiveRules activeRules;
   private final BatchComponentCache componentCache;
   private final ServerIssueRepository serverIssueRepository;
-  private final ProjectRepositories projectRepositories;
   private final AnalysisMode analysisMode;
   private final ReportPublisher reportPublisher;
   private final Date analysisDate;
 
+  private boolean hasServerAnalysis;
+
   public LocalIssueTracking(BatchComponentCache resourceCache, IssueCache issueCache, IssueTracking tracking,
     ServerLineHashesLoader lastLineHashes, IssueWorkflow workflow, IssueUpdater updater,
     ActiveRules activeRules, ServerIssueRepository serverIssueRepository,
@@ -85,21 +86,19 @@ public class LocalIssueTracking {
     this.workflow = workflow;
     this.updater = updater;
     this.serverIssueRepository = serverIssueRepository;
-    this.projectRepositories = projectRepositories;
     this.analysisMode = analysisMode;
     this.reportPublisher = reportPublisher;
     this.analysisDate = ((Project) resourceCache.getRoot().resource()).getAnalysisDate();
     this.changeContext = IssueChangeContext.createScan(analysisDate);
     this.activeRules = activeRules;
+    this.hasServerAnalysis = projectRepositories.lastAnalysisDate() != null;
   }
 
   public void execute() {
-    if (projectRepositories.lastAnalysisDate() == null) {
-      LOG.debug("No previous analysis, skipping issue tracking");
-      return;
+    if (hasServerAnalysis) {
+      serverIssueRepository.load();
     }
 
-    serverIssueRepository.load();
     BatchReportReader reader = new BatchReportReader(reportPublisher.getReportDir());
 
     for (BatchComponent component : componentCache.all()) {
@@ -124,23 +123,25 @@ public class LocalIssueTracking {
       throw new IllegalStateException("Can't read issues for " + component.key(), e);
     }
 
-    // all the issues that are not closed in db before starting this module scan, including manual issues
-    Collection<ServerIssue> serverIssues = loadServerIssues(component);
+    List<DefaultIssue> trackedIssues = Lists.newArrayList();
+    if (hasServerAnalysis) {
+      // all the issues that are not closed in db before starting this module scan, including manual issues
+      Collection<ServerIssue> serverIssues = loadServerIssues(component);
 
-    SourceHashHolder sourceHashHolder = loadSourceHashes(component);
+      SourceHashHolder sourceHashHolder = loadSourceHashes(component);
 
-    IssueTrackingResult trackingResult = tracking.track(sourceHashHolder, serverIssues, rawIssues);
+      IssueTrackingResult trackingResult = tracking.track(sourceHashHolder, serverIssues, rawIssues);
 
-    List<DefaultIssue> trackedIssues = Lists.newArrayList();
-    // unmatched from server = issues that have been resolved + issues on disabled/removed rules + manual issues
-    addUnmatchedFromServer(trackingResult.unmatched(), sourceHashHolder, trackedIssues);
+      // unmatched from server = issues that have been resolved + issues on disabled/removed rules + manual issues
+      addUnmatchedFromServer(trackingResult.unmatched(), sourceHashHolder, trackedIssues);
 
-    mergeMatched(component, trackingResult, trackedIssues, rawIssues);
+      mergeMatched(component, trackingResult, trackedIssues, rawIssues);
+    }
 
     // Unmatched raw issues = new issues
     addUnmatchedRawIssues(component, rawIssues, trackedIssues);
 
-    if (ResourceUtils.isRootProject(component.resource())) {
+    if (hasServerAnalysis && ResourceUtils.isRootProject(component.resource())) {
       // issues that relate to deleted components
       addIssuesOnDeletedComponents(trackedIssues);
     }