From fa39675d9807079cf5223bac2738fbcdb19a5166 Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Thu, 4 Nov 2010 10:53:21 +0000 Subject: [PATCH] SONAR-1850 A new snapshot is created on project A each time project B (which depends on A) is analyzed --- .../org/sonar/batch/indexer/LibraryPersister.java | 7 +++++-- .../WEB-INF/app/controllers/timemachine_controller.rb | 6 +++++- .../src/main/webapp/WEB-INF/app/models/snapshot.rb | 11 +++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/sonar-batch/src/main/java/org/sonar/batch/indexer/LibraryPersister.java b/sonar-batch/src/main/java/org/sonar/batch/indexer/LibraryPersister.java index 640997e2f8f..7d7fcfaf318 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/indexer/LibraryPersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/indexer/LibraryPersister.java @@ -55,13 +55,16 @@ public class LibraryPersister extends ResourcePersister { Snapshot snapshot = getSession().getSingleResult(Snapshot.class, "resourceId", resourceModel.getId(), "version", bucket.getResource().getVersion(), - "scope", Resource.SCOPE_SET, - "qualifier", Resource.QUALIFIER_LIB); + "scope", Resource.SCOPE_SET); if (snapshot == null) { snapshot = new Snapshot(resourceModel, null); snapshot.setCreatedAt(now); snapshot.setVersion(bucket.getResource().getVersion()); snapshot.setStatus(Snapshot.STATUS_PROCESSED); + + // see http://jira.codehaus.org/browse/SONAR-1850 + // The qualifier must be LIB, even if the resource is TRK, because this snapshot has no measures. + snapshot.setQualifier(Resource.QUALIFIER_LIB); } return snapshot; } diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/timemachine_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/timemachine_controller.rb index 8292b558c8e..032e19f4464 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/timemachine_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/timemachine_controller.rb @@ -35,9 +35,13 @@ class TimemachineController < ApplicationController if params[:sid] @sids = params[:sid].split(',').collect {|s| s.to_i} + + # + # see the explanation of the conditions on scope/qualifier in the method Snapshot.for_timemachine_matrix() + # @snapshots=Snapshot.find(:all, :include => 'events', - :conditions => {:id => @sids, :project_id => @project.id}, :order => 'snapshots.created_at ASC') + :conditions => {:id => @sids, :project_id => @project.id, :scope => @project.scope, :qualifier => @project.qualifier}, :order => 'snapshots.created_at ASC') else @snapshots=Snapshot.for_timemachine_matrix(@project) @sids = @snapshots.collect{|s| s.id}.uniq diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb index 942675ecce1..de2cc9cac91 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb @@ -49,7 +49,14 @@ class Snapshot < ActiveRecord::Base end def self.for_timemachine_matrix(resource) - snapshots=Snapshot.find(:all, :conditions => ["snapshots.project_id=? AND events.snapshot_id=snapshots.id AND snapshots.status=?", resource.id, STATUS_PROCESSED], + # http://jira.codehaus.org/browse/SONAR-1850 + # Conditions on scope and qualifier are required to exclude library snapshots. + # Use-case : + # 1. project A 2.0 is analyzed -> new snapshot A with qualifier TRK + # 2. project B, which depends on A 1.0, is analyzed -> new snapshot A 1.0 with qualifier LIB. + # 3. project A has 2 snapshots : the first one with qualifier=TRK has measures, the second one with qualifier LIB has no measures. Its version must not be used in time machine + # That's why the 2 following SQL requests check the qualifiers (and optionally scopes, just to be sure) + snapshots=Snapshot.find(:all, :conditions => ["snapshots.project_id=? AND events.snapshot_id=snapshots.id AND snapshots.status=? AND snapshots.scope=? AND snapshots.qualifier=?", resource.id, STATUS_PROCESSED, resource.scope, resource.qualifier], :include => 'events', :order => 'snapshots.created_at ASC') @@ -58,7 +65,7 @@ class Snapshot < ActiveRecord::Base snapshots=snapshots[-5,5] if snapshots.size>=5 snapshots.insert(0, Snapshot.find(:first, - :conditions => ["project_id = :project_id AND status IN (:status)", {:project_id => resource.id, :status => STATUS_PROCESSED}], + :conditions => ["project_id=? AND status IN (?) AND scope=? AND qualifier=?", resource.id, STATUS_PROCESSED, resource.scope, resource.qualifier], :include => 'project', :order => 'snapshots.created_at ASC', :limit => 1)) snapshots.compact.uniq end -- 2.39.5