]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1850 A new snapshot is created on project A each time project B (which depends...
authorsimonbrandhof <simon.brandhof@gmail.com>
Thu, 4 Nov 2010 10:53:21 +0000 (10:53 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Thu, 4 Nov 2010 10:53:21 +0000 (10:53 +0000)
sonar-batch/src/main/java/org/sonar/batch/indexer/LibraryPersister.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/timemachine_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb

index 640997e2f8f09bf4c5b39510fef9443f1f84c6a5..7d7fcfaf31820675c00b6fa9fbaeb724cb2fcfae 100644 (file)
@@ -55,13 +55,16 @@ public class LibraryPersister extends ResourcePersister<Library> {
     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;
   }
index 8292b558c8eee92c2fe47b51a3fed63cf10f09fd..032e19f4464bcc3142c70d15bb145b0040697973 100644 (file)
@@ -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
index 942675ecce1a39dc7005f5f5877d5d2e5250cbfe..de2cc9cac9124b2f8a10329d46e978b081946d5f 100644 (file)
@@ -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