]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11449 Drop deprecated property sonar.profile
authorBenoît Gianinetti <benoit.gianinetti@sonarsource.com>
Thu, 14 Mar 2019 16:42:49 +0000 (17:42 +0100)
committerSonarTech <sonartech@sonarsource.com>
Tue, 19 Mar 2019 19:21:28 +0000 (20:21 +0100)
12 files changed:
server/sonar-docs/src/pages/analysis/analysis-parameters.md
sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultQualityProfileLoader.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/QualityProfileLoader.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/QualityProfilesProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QProfileVerifier.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QualityProfiles.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultQualityProfileLoaderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/QualityProfileProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java
sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/big-multi-module-definitions-all-in-root/sonar-project.properties

index a73703a23e61e02d7a415755eb135bbf55b2fe0a..0930afe6728c9a00a8331f2eb948d6424b180b23 100644 (file)
@@ -99,6 +99,5 @@ Key | Description | Default
 Key | Description
 ---|----|---
 `sonar.branch` **![](/images/cross.svg)Deprecated since SQ 6.7** | _The Developer Edition provides fuller-featured branch functionality._ Manage SCM branches. Two branches of the same project are considered to be different projects in SonarQube. As a consequence issues found in a project A in a branch B1 are not linked to issues found for this project A in a branch B2. There is no way to automatically resolve issues from B2 when they are resolved in B1 as again A-B1 & A-B2 are considered separated projects. 
-`sonar.profile` **![](/images/cross.svg)Deprecated since SQ 4.5** | Override the profile to be used. This should be set on a per-langauge basis through the UI instead.
 `sonar.links.scm_dev` **![](/images/cross.svg)Deprecated since SQ 7.1** | Developer connection. | `<scm><developerConnection>` for Maven projects
 <!-- /sonarqube -->
index 9c8ba003e063aca7999296537db79e58facb8ddd..6c3c2f93da242324d7caaa08b59cdf2f1876350b 100644 (file)
@@ -27,7 +27,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.function.BinaryOperator;
 import java.util.function.Supplier;
-import javax.annotation.Nullable;
 import org.sonar.api.utils.MessageException;
 import org.sonar.scanner.bootstrap.ScannerWsClient;
 import org.sonar.scanner.scan.ScanProperties;
@@ -52,20 +51,20 @@ public class DefaultQualityProfileLoader implements QualityProfileLoader {
   }
 
   @Override
-  public List<QualityProfile> loadDefault(@Nullable String profileName) {
+  public List<QualityProfile> loadDefault() {
     StringBuilder url = new StringBuilder(WS_URL + "?defaults=true");
-    return handleErrors(profileName, url, () -> "Failed to load the default quality profiles");
+    return handleErrors(url, () -> "Failed to load the default quality profiles");
   }
 
   @Override
-  public List<QualityProfile> load(String projectKey, @Nullable String profileName) {
+  public List<QualityProfile> load(String projectKey) {
     StringBuilder url = new StringBuilder(WS_URL + "?projectKey=").append(encodeForUrl(projectKey));
-    return handleErrors(profileName, url, () -> String.format("Failed to load the quality profiles of project '%s'", projectKey));
+    return handleErrors(url, () -> String.format("Failed to load the quality profiles of project '%s'", projectKey));
   }
 
-  private List<QualityProfile> handleErrors(@Nullable String profileName, StringBuilder url, Supplier<String> errorMsg) {
+  private List<QualityProfile> handleErrors(StringBuilder url, Supplier<String> errorMsg) {
     try {
-      return loadAndOverrideIfNeeded(profileName, url);
+      return doLoad(url);
     } catch (HttpException e) {
       if (e.code() == 404) {
         throw MessageException.of(errorMsg.get() + ": " + ScannerWsClient.createErrorMessage(e));
@@ -78,16 +77,10 @@ public class DefaultQualityProfileLoader implements QualityProfileLoader {
     }
   }
 
-  private List<QualityProfile> loadAndOverrideIfNeeded(@Nullable String profileName, StringBuilder url) throws IOException {
+  private List<QualityProfile> doLoad(StringBuilder url) throws IOException {
     properties.organizationKey().ifPresent(k -> url.append("&organization=").append(encodeForUrl(k)));
     Map<String, QualityProfile> result = call(url.toString());
 
-    if (profileName != null) {
-      StringBuilder urlForName = new StringBuilder(WS_URL + "?profileName=");
-      urlForName.append(encodeForUrl(profileName));
-      properties.organizationKey().ifPresent(k -> urlForName.append("&organization=").append(encodeForUrl(k)));
-      result.putAll(call(urlForName.toString()));
-    }
     if (result.isEmpty()) {
       throw MessageException.of("No quality profiles have been found, you probably don't have any language plugin installed.");
     }
index 899d5f0b0f7fc66c84d1c2451ccdf7f2df9818ab..202cc6389e1d33258ac1a8a52bf01b6ab8241108 100644 (file)
 package org.sonar.scanner.repository;
 
 import java.util.List;
-import javax.annotation.Nullable;
 import org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile;
 
 public interface QualityProfileLoader {
-  List<QualityProfile> load(String projectKey, @Nullable String profileName);
+  List<QualityProfile> load(String projectKey);
 
-  List<QualityProfile> loadDefault(@Nullable String profileName);
+  List<QualityProfile> loadDefault();
 }
index 7ed441cfa08cd2ce69bfde2765932e0662c4e9d0..267d0c0172976bd31e86cadcc4467ddf3d4dbf95 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.scanner.repository;
 
 import java.util.List;
-import javax.annotation.CheckForNull;
 import org.picocontainer.injectors.ProviderAdapter;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
@@ -39,9 +38,9 @@ public class QualityProfilesProvider extends ProviderAdapter {
       List<QualityProfile> profileList;
       Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
       if (!projectRepositories.exists()) {
-        profileList = loader.loadDefault(getSonarProfile(props));
+        profileList = loader.loadDefault();
       } else {
-        profileList = loader.load(props.getKeyWithBranch(), getSonarProfile(props));
+        profileList = loader.load(props.getKeyWithBranch());
       }
       profiler.stopInfo();
       profiles = new QualityProfiles(profileList);
@@ -50,14 +49,4 @@ public class QualityProfilesProvider extends ProviderAdapter {
     return profiles;
   }
 
-  @CheckForNull
-  private static String getSonarProfile(ProcessedScannerProperties props) {
-    String profile = props.property(QualityProfiles.SONAR_PROFILE_PROP);
-    if (profile != null) {
-      LOG.warn("Ability to set quality profile from command line using '" + QualityProfiles.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 3d86c58e4763db658e7d1005d0b987dba08cfec8..26b476e82c14a5d34aa5739f0c5297c7ccdf23f3 100644 (file)
 package org.sonar.scanner.rule;
 
 import com.google.common.annotations.VisibleForTesting;
-import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.sonar.api.config.Configuration;
-import org.sonar.api.utils.MessageException;
 import org.sonar.scanner.scan.filesystem.InputComponentStore;
 
-import static org.apache.commons.lang.StringUtils.isNotEmpty;
-
 public class QProfileVerifier {
 
   private static final Logger LOG = LoggerFactory.getLogger(QProfileVerifier.class);
 
-  private final Configuration config;
   private final InputComponentStore store;
   private final QualityProfiles profiles;
 
-  public QProfileVerifier(Configuration config, InputComponentStore store, QualityProfiles profiles) {
-    this.config = config;
+  public QProfileVerifier(InputComponentStore store, QualityProfiles profiles) {
     this.store = store;
     this.profiles = profiles;
   }
@@ -49,21 +42,13 @@ public class QProfileVerifier {
 
   @VisibleForTesting
   void execute(Logger logger) {
-    String defaultName = config.get(QualityProfiles.SONAR_PROFILE_PROP).orElse(null);
-    boolean defaultNameUsed = StringUtils.isBlank(defaultName);
     for (String lang : store.languages()) {
       QProfile profile = profiles.findByLanguage(lang);
       if (profile == null) {
         logger.warn("No Quality profile found for language {}", lang);
       } else {
         logger.info("Quality profile for {}: {}", lang, profile.getName());
-        if (isNotEmpty(defaultName) && defaultName.equals(profile.getName())) {
-          defaultNameUsed = true;
-        }
       }
     }
-    if (!defaultNameUsed && !store.languages().isEmpty()) {
-      throw MessageException.of("sonar.profile was set to '" + defaultName + "' but didn't match any profile for any language. Please check your configuration.");
-    }
   }
 }
index cdfd499f161bf682d05e6dc302bddff9cf075a35..bc365d5298d6cfbd1d2ab9447021b3caa7262dfb 100644 (file)
@@ -34,7 +34,6 @@ import org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile;
 @Immutable
 public class QualityProfiles {
 
-  public static final String SONAR_PROFILE_PROP = "sonar.profile";
   private final Map<String, QProfile> byLanguage;
 
   public QualityProfiles(Collection<QualityProfile> profiles) {
index 22fbca0205b783bbe60a2b63504e84b03d1f113a..49df27855675d96cd94efe4718e178bbb961343c 100644 (file)
@@ -446,12 +446,12 @@ public class ScannerMediumTester extends ExternalResource {
     }
 
     @Override
-    public List<QualityProfile> load(String projectKey, String profileName) {
+    public List<QualityProfile> load(String projectKey) {
       return qualityProfiles;
     }
 
     @Override
-    public List<QualityProfile> loadDefault(String profileName) {
+    public List<QualityProfile> loadDefault() {
       return qualityProfiles;
     }
   }
index 3e5e21626b46079fefc32ab52d63c7550bfae9d6..757bd52ab3a1ccf683d5d619bf3e473912ba7df3 100644 (file)
@@ -47,52 +47,32 @@ public class DefaultQualityProfileLoaderTest {
   private ScanProperties properties = mock(ScanProperties.class);
   private DefaultQualityProfileLoader underTest = new DefaultQualityProfileLoader(properties, wsClient);
 
-  @Test
-  public void load_gets_profiles_for_specified_project_and_profile_name() throws IOException {
-    WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?projectKey=foo", createStreamOfProfiles("qp"));
-    WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?profileName=bar", createStreamOfProfiles("qp"));
-    underTest.load("foo", "bar");
-    verifyCalledPath("/api/qualityprofiles/search.protobuf?projectKey=foo");
-    verifyCalledPath("/api/qualityprofiles/search.protobuf?profileName=bar");
-  }
-
   @Test
   public void load_gets_all_profiles_for_specified_project() throws IOException {
     prepareCallWithResults();
-    underTest.load("foo", null);
+    underTest.load("foo");
     verifyCalledPath("/api/qualityprofiles/search.protobuf?projectKey=foo");
   }
 
   @Test
   public void load_encodes_url_parameters() throws IOException {
     WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?projectKey=foo%232", createStreamOfProfiles("qp"));
-    WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?profileName=bar%232", createStreamOfProfiles("qp"));
-    underTest.load("foo#2", "bar#2");
+    underTest.load("foo#2");
     verifyCalledPath("/api/qualityprofiles/search.protobuf?projectKey=foo%232");
-    verifyCalledPath("/api/qualityprofiles/search.protobuf?profileName=bar%232");
   }
 
   @Test
   public void load_sets_organization_parameter_if_defined_in_settings() throws IOException {
     when(properties.organizationKey()).thenReturn(Optional.of("my-org"));
     prepareCallWithResults();
-    underTest.load("foo", null);
+    underTest.load("foo");
     verifyCalledPath("/api/qualityprofiles/search.protobuf?projectKey=foo&organization=my-org");
   }
 
-  @Test
-  public void loadDefault_gets_profiles_with_specified_name() throws IOException {
-    WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?defaults=true", createStreamOfProfiles("qp"));
-    WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?profileName=foo", createStreamOfProfiles("qp"));
-    underTest.loadDefault("foo");
-    verifyCalledPath("/api/qualityprofiles/search.protobuf?defaults=true");
-    verifyCalledPath("/api/qualityprofiles/search.protobuf?profileName=foo");
-  }
-
   @Test
   public void loadDefault_gets_all_default_profiles() throws IOException {
     prepareCallWithResults();
-    underTest.loadDefault(null);
+    underTest.loadDefault();
     verifyCalledPath("/api/qualityprofiles/search.protobuf?defaults=true");
   }
 
@@ -100,10 +80,8 @@ public class DefaultQualityProfileLoaderTest {
   public void loadDefault_sets_organization_parameter_if_defined_in_settings() throws IOException {
     when(properties.organizationKey()).thenReturn(Optional.of("my-org"));
     WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?defaults=true&organization=my-org", createStreamOfProfiles("qp"));
-    WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?profileName=foo&organization=my-org", createStreamOfProfiles("qp"));
-    underTest.loadDefault("foo");
+    underTest.loadDefault();
     verifyCalledPath("/api/qualityprofiles/search.protobuf?defaults=true&organization=my-org");
-    verifyCalledPath("/api/qualityprofiles/search.protobuf?profileName=foo&organization=my-org");
   }
 
   @Test
@@ -113,7 +91,7 @@ public class DefaultQualityProfileLoaderTest {
     exception.expect(MessageException.class);
     exception.expectMessage("No quality profiles");
 
-    underTest.load("project", null);
+    underTest.load("project");
     verifyNoMoreInteractions(wsClient);
   }
 
@@ -125,7 +103,7 @@ public class DefaultQualityProfileLoaderTest {
     exception.expect(MessageException.class);
     exception.expectMessage("Failed to load the quality profiles of project 'project': No organization with key 'myorg'");
 
-    underTest.load("project", null);
+    underTest.load("project");
     verifyNoMoreInteractions(wsClient);
   }
 
index 77dddffefd377188494351da04625383b5305008..a318a6e9b5964e46bf43cef2da5d120fb60e178e 100644 (file)
@@ -72,55 +72,46 @@ public class QualityProfileProviderTest {
 
   @Test
   public void testProvide() {
-    when(loader.load("project", null)).thenReturn(response);
+    when(loader.load("project")).thenReturn(response);
     QualityProfiles qps = qualityProfileProvider.provide(loader, projectRepo, props);
     assertResponse(qps);
 
-    verify(loader).load("project", null);
+    verify(loader).load("project");
     verifyNoMoreInteractions(loader);
   }
 
   @Test
   public void testProjectDoesntExist() {
     when(projectRepo.exists()).thenReturn(false);
-    when(loader.loadDefault(anyString())).thenReturn(response);
-    when(props.property(QualityProfiles.SONAR_PROFILE_PROP)).thenReturn("profile");
+    when(loader.loadDefault()).thenReturn(response);
     QualityProfiles qps = qualityProfileProvider.provide(loader, projectRepo, props);
     assertResponse(qps);
 
-    verify(loader).loadDefault(anyString());
+    verify(loader).loadDefault();
     verifyNoMoreInteractions(loader);
   }
 
   @Test
   public void testProfileProp() {
-    when(loader.load(eq("project"), eq("custom"))).thenReturn(response);
-    when(props.property(QualityProfiles.SONAR_PROFILE_PROP)).thenReturn("custom");
-    when(props.properties()).thenReturn(ImmutableMap.of(QualityProfiles.SONAR_PROFILE_PROP, "custom"));
+    when(loader.load(eq("project"))).thenReturn(response);
 
     QualityProfiles qps = qualityProfileProvider.provide(loader, projectRepo, props);
     assertResponse(qps);
 
-    verify(loader).load(eq("project"), eq("custom"));
+    verify(loader).load(eq("project"));
     verifyNoMoreInteractions(loader);
-    assertThat(logTester.logs(LoggerLevel.WARN)).contains("Ability to set quality profile from command line using '" + QualityProfiles.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
   public void testProfilePropDefault() {
     when(projectRepo.exists()).thenReturn(false);
-    when(loader.loadDefault(eq("custom"))).thenReturn(response);
-    when(props.property(QualityProfiles.SONAR_PROFILE_PROP)).thenReturn("custom");
-    when(props.properties()).thenReturn(ImmutableMap.of(QualityProfiles.SONAR_PROFILE_PROP, "custom"));
+    when(loader.loadDefault()).thenReturn(response);
 
     QualityProfiles qps = qualityProfileProvider.provide(loader, projectRepo, props);
     assertResponse(qps);
 
-    verify(loader).loadDefault(eq("custom"));
+    verify(loader).loadDefault();
     verifyNoMoreInteractions(loader);
-    assertThat(logTester.logs(LoggerLevel.WARN)).contains("Ability to set quality profile from command line using '" + QualityProfiles.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(QualityProfiles qps) {
index 3b6188f4ca9e9cb2d015aa616545efd6fdbc8fa5..faad5baa933a46b4d5ebd22b9fc9225baddc45a7 100644 (file)
@@ -41,7 +41,6 @@ public class QProfileVerifierTest {
 
   private InputComponentStore store;
   private QualityProfiles profiles;
-  private MapSettings settings = new MapSettings();
 
   @Before
   public void before() throws Exception {
@@ -58,7 +57,7 @@ public class QProfileVerifierTest {
     store.put("foo", new TestInputFileBuilder("foo", "src/Bar.java").setLanguage("java").build());
     store.put("foo", new TestInputFileBuilder("foo", "src/Baz.cbl").setLanguage("cobol").build());
 
-    QProfileVerifier profileLogger = new QProfileVerifier(settings.asConfig(), store, profiles);
+    QProfileVerifier profileLogger = new QProfileVerifier(store, profiles);
     Logger logger = mock(Logger.class);
     profileLogger.execute(logger);
 
@@ -66,37 +65,18 @@ public class QProfileVerifierTest {
     verify(logger).info("Quality profile for {}: {}", "cobol", "My Cobol profile");
   }
 
-  @Test
-  public void should_fail_if_default_profile_not_used() {
-    store.put("foo", new TestInputFileBuilder("foo", "src/Bar.java").setLanguage("java").build());
-
-    settings.setProperty("sonar.profile", "Unknown");
-
-    QProfileVerifier profileLogger = new QProfileVerifier(settings.asConfig(), store, profiles);
-
-    thrown.expect(MessageException.class);
-    thrown.expectMessage("sonar.profile was set to 'Unknown' but didn't match any profile for any language. Please check your configuration.");
-
-    profileLogger.execute();
-  }
-
   @Test
   public void should_not_fail_if_no_language_on_project() {
-    settings.setProperty("sonar.profile", "Unknown");
-
-    QProfileVerifier profileLogger = new QProfileVerifier(settings.asConfig(), store, profiles);
+    QProfileVerifier profileLogger = new QProfileVerifier(store, profiles);
 
     profileLogger.execute();
-
   }
 
   @Test
   public void should_not_fail_if_default_profile_used_at_least_once() {
     store.put("foo", new TestInputFileBuilder("foo", "src/Bar.java").setLanguage("java").build());
 
-    settings.setProperty("sonar.profile", "My Java profile");
-
-    QProfileVerifier profileLogger = new QProfileVerifier(settings.asConfig(), store, profiles);
+    QProfileVerifier profileLogger = new QProfileVerifier(store, profiles);
 
     profileLogger.execute();
   }
index 5e4099793aa8c2e4a7767146323126fc4431d608..e27fb8607da8e326fd78e551b1b0d5f16553dc63 100644 (file)
@@ -282,7 +282,6 @@ public class ProjectReactorBuilderTest {
     ProjectDefinition projectDefinition = loadProjectDefinition("big-multi-module-definitions-all-in-root");
 
     assertThat(projectDefinition.properties().get("module11.property")).isNull();
-    assertThat(projectDefinition.properties().get("sonar.profile")).isEqualTo("Foo");
     ProjectDefinition module1 = null;
     ProjectDefinition module2 = null;
     for (ProjectDefinition prj : projectDefinition.getSubProjects()) {
@@ -294,10 +293,8 @@ public class ProjectReactorBuilderTest {
     }
     assertThat(module1.properties().get("module11.property")).isNull();
     assertThat(module1.properties().get("property")).isNull();
-    assertThat(module1.properties().get("sonar.profile")).isEqualTo("Foo");
     assertThat(module2.properties().get("module11.property")).isNull();
     assertThat(module2.properties().get("property")).isNull();
-    assertThat(module2.properties().get("sonar.profile")).isEqualTo("Foo");
 
     ProjectDefinition module11 = null;
     ProjectDefinition module12 = null;
@@ -311,10 +308,8 @@ public class ProjectReactorBuilderTest {
     assertThat(module11.properties().get("module1.module11.property")).isNull();
     assertThat(module11.properties().get("module11.property")).isNull();
     assertThat(module11.properties().get("property")).isEqualTo("My module11 property");
-    assertThat(module11.properties().get("sonar.profile")).isEqualTo("Foo");
     assertThat(module12.properties().get("module11.property")).isNull();
     assertThat(module12.properties().get("property")).isNull();
-    assertThat(module12.properties().get("sonar.profile")).isEqualTo("Foo");
   }
 
   @Test