]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8518 "sonar.profile" makes the analysis fail in preview mode 1518/head
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Tue, 10 Jan 2017 14:00:03 +0000 (15:00 +0100)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 11 Jan 2017 16:50:13 +0000 (17:50 +0100)
it/it-tests/src/test/java/it/analysis/IssuesModeTest.java
sonar-scanner-engine/src/main/java/org/sonar/batch/repository/QualityProfileProvider.java
sonar-scanner-engine/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java

index 5817eed3030855967730a2693c153c7dc4ae3205..0c3a23d67476036a06568877c33279fb7cacda54 100644 (file)
@@ -208,6 +208,22 @@ public class IssuesModeTest {
     ItUtils.assertIssuesInJsonReport(result, 3, 0, 17);
   }
 
+  // SONAR-8518
+  @Test
+  public void shoud_support_sonar_profile_prop() throws IOException {
+    restoreProfile("one-issue-per-line.xml");
+    restoreProfile("empty.xml");
+    orchestrator.getServer().provisionProject("sample", "xoo-sample");
+    orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "empty");
+
+    SonarRunner runner = configureRunner("shared/xoo-sample",
+      "sonar.verbose", "true",
+      "sonar.analysis.mode", "issues",
+      "sonar.profile", "one-issue-per-line");
+    BuildResult result = orchestrator.executeBuild(runner);
+    ItUtils.assertIssuesInJsonReport(result, 17, 0, 0);
+  }
+
   // SONAR-5715
   @Test
   public void test_issues_mode_on_project_with_space_in_filename() throws IOException {
index 0b62b406a41656b9fc0334e1496ad22391124b8c..2cb4d897accad7a7f839e695cf742790754207d8 100644 (file)
@@ -27,7 +27,6 @@ import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.api.utils.log.Profiler;
 import org.sonar.batch.analysis.AnalysisProperties;
-import org.sonar.batch.analysis.DefaultAnalysisMode;
 import org.sonar.batch.rule.ModuleQProfiles;
 import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
 
@@ -36,14 +35,14 @@ public class QualityProfileProvider extends ProviderAdapter {
   private static final String LOG_MSG = "Load quality profiles";
   private ModuleQProfiles profiles = null;
 
-  public ModuleQProfiles provide(ProjectKey projectKey, QualityProfileLoader loader, ProjectRepositories projectRepositories, AnalysisProperties props, DefaultAnalysisMode mode) {
+  public ModuleQProfiles provide(ProjectKey projectKey, QualityProfileLoader loader, ProjectRepositories projectRepositories, AnalysisProperties props) {
     if (this.profiles == null) {
       List<QualityProfile> profileList;
       Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
       if (!projectRepositories.exists()) {
-        profileList = loader.loadDefault(getSonarProfile(props, mode));
+        profileList = loader.loadDefault(getSonarProfile(props));
       } else {
-        profileList = loader.load(projectKey.get(), getSonarProfile(props, mode));
+        profileList = loader.load(projectKey.get(), getSonarProfile(props));
       }
       profiler.stopInfo();
       profiles = new ModuleQProfiles(profileList);
@@ -53,9 +52,9 @@ public class QualityProfileProvider extends ProviderAdapter {
   }
 
   @CheckForNull
-  private static String getSonarProfile(AnalysisProperties props, DefaultAnalysisMode mode) {
+  private static String getSonarProfile(AnalysisProperties props) {
     String profile = null;
-    if (!mode.isIssues() && props.properties().containsKey(ModuleQProfiles.SONAR_PROFILE_PROP)) {
+    if (props.properties().containsKey(ModuleQProfiles.SONAR_PROFILE_PROP)) {
       profile = props.property(ModuleQProfiles.SONAR_PROFILE_PROP);
       LOG.warn("Ability to set quality profile from command line using '" + ModuleQProfiles.SONAR_PROFILE_PROP
         + "' is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server.");
index bdbdb0ea703aa40145c4cfb26d3a7a2ab9634e5f..68490734071673afa46c2a72252548b6110d2295 100644 (file)
@@ -31,7 +31,6 @@ import org.sonar.api.batch.bootstrap.ProjectKey;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.batch.analysis.AnalysisProperties;
-import org.sonar.batch.analysis.DefaultAnalysisMode;
 import org.sonar.batch.rule.ModuleQProfiles;
 import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
 
@@ -53,8 +52,6 @@ public class QualityProfileProviderTest {
   @Mock
   private QualityProfileLoader loader;
   @Mock
-  private DefaultAnalysisMode mode;
-  @Mock
   private AnalysisProperties props;
   @Mock
   private ProjectKey key;
@@ -78,7 +75,7 @@ public class QualityProfileProviderTest {
   @Test
   public void testProvide() {
     when(loader.load(eq("project"), isNull(String.class))).thenReturn(response);
-    ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props, mode);
+    ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
     assertResponse(qps);
 
     verify(loader).load(eq("project"), isNull(String.class));
@@ -89,7 +86,7 @@ public class QualityProfileProviderTest {
   public void testProjectDoesntExist() {
     when(projectRepo.exists()).thenReturn(false);
     when(loader.loadDefault(anyString())).thenReturn(response);
-    ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props, mode);
+    ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
     assertResponse(qps);
 
     verify(loader).loadDefault(anyString());
@@ -102,7 +99,7 @@ public class QualityProfileProviderTest {
     when(props.property(ModuleQProfiles.SONAR_PROFILE_PROP)).thenReturn("custom");
     when(props.properties()).thenReturn(ImmutableMap.of(ModuleQProfiles.SONAR_PROFILE_PROP, "custom"));
 
-    ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props, mode);
+    ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
     assertResponse(qps);
 
     verify(loader).load(eq("project"), eq("custom"));
@@ -111,19 +108,6 @@ public class QualityProfileProviderTest {
       + "' is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server.");
   }
 
-  @Test
-  public void testIgnoreSonarProfileIssuesMode() {
-    when(mode.isIssues()).thenReturn(true);
-    when(loader.load(eq("project"), (String) eq(null))).thenReturn(response);
-    when(props.property(ModuleQProfiles.SONAR_PROFILE_PROP)).thenReturn("custom");
-
-    ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props, mode);
-    assertResponse(qps);
-
-    verify(loader).load(eq("project"), (String) eq(null));
-    verifyNoMoreInteractions(loader);
-  }
-
   @Test
   public void testProfilePropDefault() {
     when(projectRepo.exists()).thenReturn(false);
@@ -131,7 +115,7 @@ public class QualityProfileProviderTest {
     when(props.property(ModuleQProfiles.SONAR_PROFILE_PROP)).thenReturn("custom");
     when(props.properties()).thenReturn(ImmutableMap.of(ModuleQProfiles.SONAR_PROFILE_PROP, "custom"));
 
-    ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props, mode);
+    ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
     assertResponse(qps);
 
     verify(loader).loadDefault(eq("custom"));