]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10776 fix NPE when user has issues on branch without ce activity
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 18 Jul 2018 13:34:29 +0000 (15:34 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 19 Jul 2018 18:21:25 +0000 (20:21 +0200)
server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java

index bfb362e478fc06c3d5ae1b0069b796592acfd608..ae2e55d4f54665478a74516c3bbdaa04a9d9a9a7 100644 (file)
@@ -32,7 +32,6 @@ import org.apache.ibatis.session.RowBounds;
 import org.sonar.core.util.stream.MoreCollectors;
 import org.sonar.db.Dao;
 import org.sonar.db.DbSession;
-import org.sonar.db.ce.CeActivityDto.Status;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkState;
@@ -111,7 +110,7 @@ public class SnapshotDao implements Dao {
       .mapToObj(i -> new ComponentUuidFromDatePair(componentUuids.get(i), fromDates.get(i)))
       .collect(MoreCollectors.toList(componentUuids.size()));
 
-    return executeLargeInputs(componentUuidFromDatePairs, partition -> mapper(dbSession).selectFinishedByComponentUuidsAndFromDates(partition, Status.SUCCESS), i -> i / 2);
+    return executeLargeInputs(componentUuidFromDatePairs, partition -> mapper(dbSession).selectFinishedByComponentUuidsAndFromDates(partition), i -> i / 2);
   }
 
   public void switchIsLastFlagAndSetProcessedStatus(DbSession dbSession, String componentUuid, String analysisUuid) {
index 17d6c1cdfd3372c9709a47affa4a5a5be1d857cb..66eacc9af672b5e934df011c6a7f5c88b167c0d0 100644 (file)
@@ -24,7 +24,6 @@ import java.util.List;
 import javax.annotation.CheckForNull;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.session.RowBounds;
-import org.sonar.db.ce.CeActivityDto;
 import org.sonar.db.component.SnapshotDao.ComponentUuidFromDatePair;
 
 public interface SnapshotMapper {
@@ -55,7 +54,6 @@ public interface SnapshotMapper {
 
   void update(SnapshotDto analysis);
 
-  List<SnapshotDto> selectFinishedByComponentUuidsAndFromDates(@Param("componentUuidFromDatePairs") List<ComponentUuidFromDatePair> pairs,
-    @Param("ceStatus") CeActivityDto.Status ceStatus);
+  List<SnapshotDto> selectFinishedByComponentUuidsAndFromDates(@Param("componentUuidFromDatePairs") List<ComponentUuidFromDatePair> pairs);
 
 }
index 3cf493d3241600e078a5eb22745de06fca2d8b6f..03f78b74776980057bea2cd260f7c7db477c18c3 100644 (file)
     from snapshots s
       inner join projects p on p.uuid=s.component_uuid and p.enabled=${_true}
       inner join project_branches pb on pb.uuid=p.uuid
-      inner join ce_activity ca on ca.analysis_uuid = s.uuid and ca.component_uuid = pb.project_uuid
     where
       <foreach collection="componentUuidFromDatePairs" open="(" close=")" item="componentUuidFromDatePair" separator=" or ">
         (pb.project_uuid=#{componentUuidFromDatePair.componentUuid, jdbcType=VARCHAR} and s.created_at >= #{componentUuidFromDatePair.from, jdbcType=BIGINT})
       </foreach>
       and s.status = 'P'
-      and ca.status=#{ceStatus, jdbcType=VARCHAR}
     order by
       s.created_at
   </select>
index 88fcd2f82036df82bb8c76d01a6e9e7ab60dec5d..a4a00f53aba5f8282ce469fa8b4ea2cb582106e3 100644 (file)
@@ -235,7 +235,7 @@ public class SnapshotDaoTest {
   }
 
   @Test
-  public void selectFinishedByComponentUuidsAndFromDates_ignores_unsuccessful_analysis() {
+  public void selectFinishedByComponentUuidsAndFromDates_returns_processed_analysis_even_if_analysis_failed() {
     long from = 1_500_000_000_000L;
     ComponentDto project = db.components().insertMainBranch();
     SnapshotDto unprocessedAnalysis = db.components().insertSnapshot(project, s -> s.setStatus(STATUS_UNPROCESSED).setCreatedAt(from + 1_000_000L));
@@ -248,7 +248,7 @@ public class SnapshotDaoTest {
     List<SnapshotDto> result = underTest.selectFinishedByComponentUuidsAndFromDates(dbSession, singletonList(project.uuid()), singletonList(from));
 
     assertThat(result).extracting(SnapshotDto::getUuid)
-      .containsExactlyInAnyOrder(finishedAnalysis.getUuid());
+      .containsExactlyInAnyOrder(finishedAnalysis.getUuid(), canceledAnalysis.getUuid());
   }
 
   @Test