From: Julien HENRY Date: Tue, 8 Dec 2015 09:37:44 +0000 (+0100) Subject: SONAR-6818 Restore warning when using sonar.profile X-Git-Tag: 5.3-RC1~9 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7f680d2af8f27bfb3c63813c66203c621c65d6ae;p=sonarqube.git SONAR-6818 Restore warning when using sonar.profile --- diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/QualityProfileProvider.java b/sonar-batch/src/main/java/org/sonar/batch/repository/QualityProfileProvider.java index e3de47efb81..fb3d8ff0a36 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/QualityProfileProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/repository/QualityProfileProvider.java @@ -19,21 +19,18 @@ */ 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 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; } diff --git a/sonar-batch/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java index 567dcd1380d..af65f530131 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java @@ -19,31 +19,37 @@ */ 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) {