]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6818 Restore warning when using sonar.profile 687/head
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 8 Dec 2015 09:37:44 +0000 (10:37 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 8 Dec 2015 09:52:24 +0000 (10:52 +0100)
sonar-batch/src/main/java/org/sonar/batch/repository/QualityProfileProvider.java
sonar-batch/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java

index e3de47efb81271499bb347d057abc31670f9bb17..fb3d8ff0a36b19ccb899c7927585e678a6e5da58 100644 (file)
  */
 package org.sonar.batch.repository;
 
+import java.util.List;
 import javax.annotation.CheckForNull;
-
-import org.sonar.api.utils.log.Profiler;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
 import org.apache.commons.lang.mutable.MutableBoolean;
-import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
-import org.sonar.batch.analysis.DefaultAnalysisMode;
+import org.picocontainer.injectors.ProviderAdapter;
 import org.sonar.api.batch.bootstrap.ProjectKey;
-
-import java.util.List;
-
+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.picocontainer.injectors.ProviderAdapter;
+import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
 
 public class QualityProfileProvider extends ProviderAdapter {
   private static final Logger LOG = Loggers.get(QualityProfileProvider.class);
@@ -44,7 +41,7 @@ public class QualityProfileProvider extends ProviderAdapter {
     if (this.profiles == null) {
       List<QualityProfile> profileList;
       MutableBoolean fromCache = new MutableBoolean();
-      
+
       Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
       if (mode.isNotAssociated() || !projectRepositories.exists()) {
         profileList = loader.loadDefault(getSonarProfile(props, mode), fromCache);
@@ -61,8 +58,10 @@ public class QualityProfileProvider extends ProviderAdapter {
   @CheckForNull
   private static String getSonarProfile(AnalysisProperties props, DefaultAnalysisMode mode) {
     String profile = null;
-    if (!mode.isIssues()) {
+    if (!mode.isIssues() && 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.");
     }
     return profile;
   }
index 567dcd1380ddad595429030fbfe840c26d67db67..af65f530131f1ef18d6799517f2ff2bdf5bdfe69 100644 (file)
  */
 package org.sonar.batch.repository;
 
-import static org.mockito.Mockito.when;
-
+import com.google.common.collect.ImmutableMap;
+import java.util.ArrayList;
+import java.util.List;
 import org.apache.commons.lang.mutable.MutableBoolean;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
 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;
 
-import java.util.ArrayList;
-import java.util.List;
-
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.isNull;
 import static org.mockito.Matchers.eq;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Matchers.isNull;
 import static org.mockito.Mockito.verify;
-import static org.assertj.core.api.Assertions.assertThat;
-import org.sonar.batch.rule.ModuleQProfiles;
-import org.junit.Test;
-import org.sonar.batch.analysis.AnalysisProperties;
-import org.mockito.MockitoAnnotations;
-import org.mockito.Mock;
-import org.junit.Before;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
 
 public class QualityProfileProviderTest {
+
+  @Rule
+  public LogTester logTester = new LogTester();
+
   private QualityProfileProvider qualityProfileProvider;
 
   @Mock
@@ -110,12 +116,15 @@ public class QualityProfileProviderTest {
     when(mode.isNotAssociated()).thenReturn(false);
     when(loader.load(eq("project"), eq("custom"), any(MutableBoolean.class))).thenReturn(response);
     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);
     assertResponse(qps);
 
     verify(loader).load(eq("project"), eq("custom"), any(MutableBoolean.class));
     verifyNoMoreInteractions(loader);
+    assertThat(logTester.logs(LoggerLevel.WARN)).contains("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.");
   }
 
   @Test
@@ -137,12 +146,15 @@ public class QualityProfileProviderTest {
     when(mode.isNotAssociated()).thenReturn(true);
     when(loader.loadDefault(eq("custom"), any(MutableBoolean.class))).thenReturn(response);
     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);
     assertResponse(qps);
 
     verify(loader).loadDefault(eq("custom"), any(MutableBoolean.class));
     verifyNoMoreInteractions(loader);
+    assertThat(logTester.logs(LoggerLevel.WARN)).contains("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.");
   }
 
   private void assertResponse(ModuleQProfiles qps) {