]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6729 CE not fail anymore when no quality profile found 603/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 28 Oct 2015 10:51:53 +0000 (11:51 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 29 Oct 2015 12:58:32 +0000 (13:58 +0100)
server/sonar-server/src/main/java/org/sonar/server/computation/step/ComputeQProfileMeasureStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/QualityProfileEventsStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ComputeQProfileMeasureStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/QualityProfileEventsStepTest.java

index 3495abce8e440fa0fd1b7d89e034263b9a435a14..bd22aeb4d6db62ff20ac544dd904c4e250b3d463 100644 (file)
@@ -24,7 +24,6 @@ import com.google.common.base.Optional;
 import java.util.HashMap;
 import java.util.Map;
 import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.utils.MessageException;
 import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.CrawlerDepthLimit;
 import org.sonar.server.computation.component.PathAwareCrawler;
@@ -78,11 +77,6 @@ public class ComputeQProfileMeasureStep implements ComputationStep {
     @Override
     public void visitProject(Component project, Path<QProfiles> path) {
       addMeasure(project, path.current());
-      Optional<Measure> qProfileMeasure = measureRepository.getRawMeasure(project, qProfilesMetric);
-      if (!qProfileMeasure.isPresent() || QPMeasureData.fromJson(qProfileMeasure.get().getData()).getProfiles().isEmpty()) {
-        throw MessageException.of(String.format("No quality profiles has been found on project '%s', you probably don't have any language plugin suitable for this analysis.",
-          project.getKey()));
-      }
     }
 
     @Override
index 6a8bd53a219e0bf50e04bcc192bc031cdb50f869..1967ec3eb927933de85b37d01094df0cac8f1134 100644 (file)
@@ -89,7 +89,8 @@ public class QualityProfileEventsStep implements ComputationStep {
     // Load base profiles
     Optional<Measure> rawMeasure = measureRepository.getRawMeasure(projectComponent, metricRepository.getByKey(CoreMetrics.QUALITY_PROFILES_KEY));
     if (!rawMeasure.isPresent()) {
-      throw new IllegalStateException("Missing measure " + CoreMetrics.QUALITY_PROFILES + " for component " + projectComponent.getReportAttributes().getRef());
+      // No qualify profile computed on the project
+      return;
     }
     Map<String, QualityProfile> rawProfiles = QPMeasureData.fromJson(rawMeasure.get().getStringValue()).getProfilesByKey();
 
index 354c4e8b2ad9e563a51f9544090991aa46b2834d..45acfd592ee487573204a98c24e3db588157fd1a 100644 (file)
@@ -27,7 +27,6 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.sonar.api.utils.MessageException;
 import org.sonar.server.computation.batch.TreeRootHolderRule;
 import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.ReportComponent;
@@ -136,10 +135,7 @@ public class ComputeQProfileMeasureStepTest {
   }
 
   @Test
-  public void fail_with_message_exception_when_no_qprofile_computed_on_project() throws Exception {
-    thrown.expect(MessageException.class);
-    thrown.expectMessage("No quality profiles has been found on project 'PROJECT KEY'");
-
+  public void nothing_to_add_when_no_qprofile_computed_on_project() throws Exception {
     treeRootHolder.setRoot(MULTI_MODULE_PROJECT);
 
     underTest.execute();
@@ -148,10 +144,7 @@ public class ComputeQProfileMeasureStepTest {
   }
 
   @Test
-  public void fail_with_message_exception_when_qprofiles_computed_on_project_are_empty() throws Exception {
-    thrown.expect(MessageException.class);
-    thrown.expectMessage("No quality profiles has been found on project 'PROJECT KEY', you probably don't have any language plugin suitable for this analysis.");
-
+  public void nothing_to_add_when_qprofiles_computed_on_project_are_empty() throws Exception {
     treeRootHolder.setRoot(MULTI_MODULE_PROJECT);
     measureRepository.addRawMeasure(PROJECT_REF, QUALITY_PROFILES_KEY, newMeasureBuilder().create(toJson()));
 
index ac4b52ea09c97a65d7b4a779025dc97702c2a0c6..7bcf0e0a6585d0b509561fb70c0a2ce8742e0114 100644 (file)
@@ -89,7 +89,7 @@ public class QualityProfileEventsStepTest {
   }
 
   @Test
-  public void no_effect_if_no_base_measure() {
+  public void no_event_if_no_base_measure() {
     when(measureRepository.getBaseMeasure(treeRootHolder.getRoot(), qualityProfileMetric)).thenReturn(Optional.<Measure>absent());
 
     underTest.execute();
@@ -97,16 +97,18 @@ public class QualityProfileEventsStepTest {
     verifyNoMoreInteractions(eventRepository);
   }
 
-  @Test(expected = IllegalStateException.class)
-  public void ISE_if_no_raw_measure() {
+  @Test
+  public void no_event_if_no_raw_measure() {
     when(measureRepository.getBaseMeasure(treeRootHolder.getRoot(), qualityProfileMetric)).thenReturn(Optional.of(newMeasure()));
     when(measureRepository.getRawMeasure(treeRootHolder.getRoot(), qualityProfileMetric)).thenReturn(Optional.<Measure>absent());
 
     underTest.execute();
+
+    verifyNoMoreInteractions(eventRepository);
   }
 
   @Test
-  public void no_event_if_no_base_nor_row_QualityProfile_measure() {
+  public void no_event_if_no_base_and_quality_profile_measure_is_empty() {
     mockMeasures(treeRootHolder.getRoot(), null, null);
 
     underTest.execute();