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;
}
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
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')
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