From f6570b1dac3d8ee21101c4020b4f0492a64f50de Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 28 Oct 2015 11:51:53 +0100 Subject: [PATCH] SONAR-6729 CE not fail anymore when no quality profile found --- .../computation/step/ComputeQProfileMeasureStep.java | 6 ------ .../computation/step/QualityProfileEventsStep.java | 3 ++- .../step/ComputeQProfileMeasureStepTest.java | 11 ++--------- .../step/QualityProfileEventsStepTest.java | 10 ++++++---- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ComputeQProfileMeasureStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ComputeQProfileMeasureStep.java index 3495abce8e4..bd22aeb4d6d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ComputeQProfileMeasureStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ComputeQProfileMeasureStep.java @@ -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 path) { addMeasure(project, path.current()); - Optional 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 diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/QualityProfileEventsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/QualityProfileEventsStep.java index 6a8bd53a219..1967ec3eb92 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/QualityProfileEventsStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/QualityProfileEventsStep.java @@ -89,7 +89,8 @@ public class QualityProfileEventsStep implements ComputationStep { // Load base profiles Optional 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 rawProfiles = QPMeasureData.fromJson(rawMeasure.get().getStringValue()).getProfilesByKey(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ComputeQProfileMeasureStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ComputeQProfileMeasureStepTest.java index 354c4e8b2ad..45acfd592ee 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ComputeQProfileMeasureStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ComputeQProfileMeasureStepTest.java @@ -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())); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/QualityProfileEventsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/QualityProfileEventsStepTest.java index ac4b52ea09c..7bcf0e0a658 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/QualityProfileEventsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/QualityProfileEventsStepTest.java @@ -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.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.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(); -- 2.39.5