]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11471 Stop providing RulesProfile on scanner side
authorJulien HENRY <julien.henry@sonarsource.com>
Mon, 12 Nov 2018 09:53:04 +0000 (10:53 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 16 Jan 2019 08:42:59 +0000 (09:42 +0100)
17 files changed:
sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/CheckFactory.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/QualityProfileProvider.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/QualityProfilesProvider.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ActiveRulesProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ModuleQProfiles.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QProfileVerifier.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QualityProfiles.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileProvider.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileWrapper.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/QualityProfileProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RulesProfileProviderTest.java [deleted file]

index ff43207aefcede814fcc4027a2d7aa61e2e53b69..ae8c5016076eb310f5ea333f655e774d1a9bb07a 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.api.batch.rule;
 
-import org.sonar.api.batch.ScannerSide;
+import org.sonar.api.scanner.ScannerSide;
 
 /**
  * Creates {@link org.sonar.api.batch.rule.Checks}. This class is available
index 6b5fbc8e15a9141848ef849a5ad9e601d950c5f2..73eced44cda6442929ce6c82564160aeff5106b1 100644 (file)
@@ -37,7 +37,7 @@ import org.sonar.scanner.cpd.CpdSettings;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReport.Metadata.BranchType;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
-import org.sonar.scanner.rule.ModuleQProfiles;
+import org.sonar.scanner.rule.QualityProfiles;
 import org.sonar.scanner.rule.QProfile;
 import org.sonar.scanner.scan.ScanProperties;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
@@ -48,7 +48,7 @@ public class MetadataPublisher implements ReportPublisherStep {
   private static final Logger LOG = Loggers.get(MetadataPublisher.class);
 
   private final ScanProperties properties;
-  private final ModuleQProfiles qProfiles;
+  private final QualityProfiles qProfiles;
   private final ProjectAnalysisInfo projectAnalysisInfo;
   private final InputModuleHierarchy moduleHierarchy;
   private final CpdSettings cpdSettings;
@@ -59,8 +59,8 @@ public class MetadataPublisher implements ReportPublisherStep {
   private final ScmConfiguration scmConfiguration;
 
   public MetadataPublisher(ProjectAnalysisInfo projectAnalysisInfo, InputModuleHierarchy moduleHierarchy, ScanProperties properties,
-    ModuleQProfiles qProfiles, CpdSettings cpdSettings, ScannerPluginRepository pluginRepository, BranchConfiguration branchConfiguration,
-    @Nullable ScmConfiguration scmConfiguration) {
+                           QualityProfiles qProfiles, CpdSettings cpdSettings, ScannerPluginRepository pluginRepository, BranchConfiguration branchConfiguration,
+                           @Nullable ScmConfiguration scmConfiguration) {
     this.projectAnalysisInfo = projectAnalysisInfo;
     this.moduleHierarchy = moduleHierarchy;
     this.properties = properties;
@@ -72,7 +72,7 @@ public class MetadataPublisher implements ReportPublisherStep {
   }
 
   public MetadataPublisher(ProjectAnalysisInfo projectAnalysisInfo, InputModuleHierarchy moduleHierarchy, ScanProperties properties,
-    ModuleQProfiles qProfiles, CpdSettings cpdSettings, ScannerPluginRepository pluginRepository, BranchConfiguration branchConfiguration) {
+                           QualityProfiles qProfiles, CpdSettings cpdSettings, ScannerPluginRepository pluginRepository, BranchConfiguration branchConfiguration) {
     this(projectAnalysisInfo, moduleHierarchy, properties, qProfiles, cpdSettings, pluginRepository, branchConfiguration, null);
   }
 
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/QualityProfileProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/QualityProfileProvider.java
deleted file mode 100644 (file)
index 1cd2baa..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.repository;
-
-import java.util.List;
-import javax.annotation.CheckForNull;
-import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.batch.bootstrap.ProjectKey;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.api.utils.log.Profiler;
-import org.sonar.scanner.analysis.AnalysisProperties;
-import org.sonar.scanner.rule.ModuleQProfiles;
-import org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile;
-
-public class QualityProfileProvider extends ProviderAdapter {
-  private static final Logger LOG = Loggers.get(QualityProfileProvider.class);
-  private static final String LOG_MSG = "Load quality profiles";
-  private ModuleQProfiles profiles = null;
-
-  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));
-      } else {
-        profileList = loader.load(projectKey.get(), getSonarProfile(props));
-      }
-      profiler.stopInfo();
-      profiles = new ModuleQProfiles(profileList);
-    }
-
-    return profiles;
-  }
-
-  @CheckForNull
-  private static String getSonarProfile(AnalysisProperties props) {
-    String profile = props.property(ModuleQProfiles.SONAR_PROFILE_PROP);
-    if (profile != null) {
-      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-scanner-engine/src/main/java/org/sonar/scanner/repository/QualityProfilesProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/QualityProfilesProvider.java
new file mode 100644 (file)
index 0000000..24286de
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.scanner.repository;
+
+import java.util.List;
+import javax.annotation.CheckForNull;
+import org.picocontainer.injectors.ProviderAdapter;
+import org.sonar.api.batch.bootstrap.ProjectKey;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.api.utils.log.Profiler;
+import org.sonar.scanner.analysis.AnalysisProperties;
+import org.sonar.scanner.rule.QualityProfiles;
+import org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile;
+
+public class QualityProfilesProvider extends ProviderAdapter {
+  private static final Logger LOG = Loggers.get(QualityProfilesProvider.class);
+  private static final String LOG_MSG = "Load quality profiles";
+  private QualityProfiles profiles = null;
+
+  public QualityProfiles 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));
+      } else {
+        profileList = loader.load(projectKey.get(), getSonarProfile(props));
+      }
+      profiler.stopInfo();
+      profiles = new QualityProfiles(profileList);
+    }
+
+    return profiles;
+  }
+
+  @CheckForNull
+  private static String getSonarProfile(AnalysisProperties 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 309b6d4f0fdd0975e15797329d48d1863f526e19..d0cc579617663f9d388854f1473e7b5ed266a282 100644 (file)
@@ -43,7 +43,7 @@ public class ActiveRulesProvider extends ProviderAdapter {
   private static final String LOG_MSG = "Load active rules";
   private ActiveRules singleton = null;
 
-  public ActiveRules provide(ActiveRulesLoader loader, ModuleQProfiles qProfiles) {
+  public ActiveRules provide(ActiveRulesLoader loader, QualityProfiles qProfiles) {
     if (singleton == null) {
       Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
       singleton = load(loader, qProfiles);
@@ -52,7 +52,7 @@ public class ActiveRulesProvider extends ProviderAdapter {
     return singleton;
   }
 
-  private static ActiveRules load(ActiveRulesLoader loader, ModuleQProfiles qProfiles) {
+  private static ActiveRules load(ActiveRulesLoader loader, QualityProfiles qProfiles) {
 
     Collection<String> qProfileKeys = getKeys(qProfiles);
     Set<RuleKey> loadedRulesKey = new HashSet<>();
@@ -98,7 +98,7 @@ public class ActiveRulesProvider extends ProviderAdapter {
     return loader.load(qProfileKey);
   }
 
-  private static Collection<String> getKeys(ModuleQProfiles qProfiles) {
+  private static Collection<String> getKeys(QualityProfiles qProfiles) {
     List<String> keys = new ArrayList<>(qProfiles.findAll().size());
 
     for (QProfile qp : qProfiles.findAll()) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ModuleQProfiles.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ModuleQProfiles.java
deleted file mode 100644 (file)
index 83d1a8c..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.rule;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import javax.annotation.CheckForNull;
-import javax.annotation.concurrent.Immutable;
-import org.sonar.api.batch.ScannerSide;
-import org.sonar.api.utils.DateUtils;
-import org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile;
-
-/**
- * Lists the Quality profiles enabled on the current module.
- */
-@ScannerSide
-@Immutable
-public class ModuleQProfiles {
-
-  public static final String SONAR_PROFILE_PROP = "sonar.profile";
-  private final Map<String, QProfile> byLanguage;
-
-  public ModuleQProfiles(Collection<QualityProfile> profiles) {
-    Map<String, QProfile> map = new HashMap<>(profiles.size());
-
-    for (QualityProfile qProfile : profiles) {
-      map.put(qProfile.getLanguage(),
-        new QProfile.Builder()
-          .setKey(qProfile.getKey())
-          .setName(qProfile.getName())
-          .setLanguage(qProfile.getLanguage())
-          .setRulesUpdatedAt(DateUtils.parseDateTime(qProfile.getRulesUpdatedAt())).build());
-    }
-    byLanguage = Collections.unmodifiableMap(map);
-  }
-
-  public Collection<QProfile> findAll() {
-    return byLanguage.values();
-  }
-
-  @CheckForNull
-  public QProfile findByLanguage(String language) {
-    return byLanguage.get(language);
-  }
-}
index 49ce2203b44e443f5240d3c962615743d8867f73..21f44b0cfa523b5d2c5c564a8560d19816fe3d8f 100644 (file)
@@ -37,9 +37,9 @@ public class QProfileVerifier {
 
   private final Configuration settings;
   private final FileSystem fs;
-  private final ModuleQProfiles profiles;
+  private final QualityProfiles profiles;
 
-  public QProfileVerifier(Configuration settings, FileSystem fs, ModuleQProfiles profiles) {
+  public QProfileVerifier(Configuration settings, FileSystem fs, QualityProfiles profiles) {
     this.settings = settings;
     this.fs = fs;
     this.profiles = profiles;
@@ -51,7 +51,7 @@ public class QProfileVerifier {
 
   @VisibleForTesting
   void execute(Logger logger) {
-    String defaultName = settings.get(ModuleQProfiles.SONAR_PROFILE_PROP).orElse(null);
+    String defaultName = settings.get(QualityProfiles.SONAR_PROFILE_PROP).orElse(null);
     boolean defaultNameUsed = StringUtils.isBlank(defaultName);
     for (String lang : fs.languages()) {
       QProfile profile = profiles.findByLanguage(lang);
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QualityProfiles.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QualityProfiles.java
new file mode 100644 (file)
index 0000000..cdfd499
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.scanner.rule;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.CheckForNull;
+import javax.annotation.concurrent.Immutable;
+import org.sonar.api.utils.DateUtils;
+import org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile;
+
+/**
+ * Lists the Quality profiles enabled on the current project.
+ */
+@Immutable
+public class QualityProfiles {
+
+  public static final String SONAR_PROFILE_PROP = "sonar.profile";
+  private final Map<String, QProfile> byLanguage;
+
+  public QualityProfiles(Collection<QualityProfile> profiles) {
+    Map<String, QProfile> map = new HashMap<>(profiles.size());
+
+    for (QualityProfile qProfile : profiles) {
+      map.put(qProfile.getLanguage(),
+        new QProfile.Builder()
+          .setKey(qProfile.getKey())
+          .setName(qProfile.getName())
+          .setLanguage(qProfile.getLanguage())
+          .setRulesUpdatedAt(DateUtils.parseDateTime(qProfile.getRulesUpdatedAt())).build());
+    }
+    byLanguage = Collections.unmodifiableMap(map);
+  }
+
+  public Collection<QProfile> findAll() {
+    return byLanguage.values();
+  }
+
+  @CheckForNull
+  public QProfile findByLanguage(String language) {
+    return byLanguage.get(language);
+  }
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileProvider.java
deleted file mode 100644 (file)
index a960a99..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.rule;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Map;
-import org.apache.commons.lang.StringUtils;
-import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.rule.ActiveRules;
-import org.sonar.api.config.Configuration;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rules.ActiveRule;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RulePriority;
-
-/**
- * Ensures backward-compatibility with extensions that use {@link org.sonar.api.profiles.RulesProfile}.
- */
-public class RulesProfileProvider extends ProviderAdapter {
-
-  private RulesProfile singleton = null;
-
-  public RulesProfile provide(ModuleQProfiles qProfiles, ActiveRules activeRules, Configuration settings) {
-    if (singleton == null) {
-      String lang = settings.get(CoreProperties.PROJECT_LANGUAGE_PROPERTY).orElse(null);
-      if (StringUtils.isNotBlank(lang)) {
-        // Backward-compatibility with single-language modules
-        singleton = loadSingleLanguageProfile(qProfiles, activeRules, lang);
-      } else {
-        singleton = loadProfiles(qProfiles, activeRules);
-      }
-    }
-    return singleton;
-  }
-
-  private static RulesProfile loadSingleLanguageProfile(ModuleQProfiles qProfiles, ActiveRules activeRules, String language) {
-    QProfile qProfile = qProfiles.findByLanguage(language);
-    if (qProfile != null) {
-      return new RulesProfileWrapper(select(qProfile, activeRules));
-    }
-    return new RulesProfileWrapper(new ArrayList<>());
-  }
-
-  private static RulesProfile loadProfiles(ModuleQProfiles qProfiles, ActiveRules activeRules) {
-    Collection<QProfile> profiles = qProfiles.findAll();
-    Collection<RulesProfile> dtos = new ArrayList<>(profiles.size());
-    for (QProfile qProfile : profiles) {
-      dtos.add(select(qProfile, activeRules));
-    }
-    return new RulesProfileWrapper(dtos);
-  }
-
-  private static RulesProfile select(QProfile qProfile, ActiveRules activeRules) {
-    RulesProfile deprecatedProfile = new RulesProfile();
-    deprecatedProfile.setName(qProfile.getName());
-    deprecatedProfile.setLanguage(qProfile.getLanguage());
-    for (org.sonar.api.batch.rule.ActiveRule activeRule : activeRules.findByLanguage(qProfile.getLanguage())) {
-      Rule rule = Rule.create(activeRule.ruleKey().repository(), activeRule.ruleKey().rule());
-      rule.setConfigKey(activeRule.internalKey());
-
-      // SONAR-6706
-      if (activeRule.templateRuleKey() != null) {
-        rule.setTemplate(Rule.create(activeRule.ruleKey().repository(), activeRule.templateRuleKey()));
-      }
-
-      ActiveRule deprecatedActiveRule = deprecatedProfile.activateRule(rule,
-        RulePriority.valueOf(activeRule.severity()));
-      for (Map.Entry<String, String> param : activeRule.params().entrySet()) {
-        rule.createParameter(param.getKey());
-        deprecatedActiveRule.setParameter(param.getKey(), param.getValue());
-      }
-    }
-    return deprecatedProfile;
-  }
-
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileWrapper.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileWrapper.java
deleted file mode 100644 (file)
index 7a42b98..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.rule;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rules.ActiveRule;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.utils.SonarException;
-
-/**
- * This wrapper is used to try to preserve backward compatibility for plugins that used to
- * depends on {@link org.sonar.api.profiles.RulesProfile}
- *
- * @since 4.2
- */
-public class RulesProfileWrapper extends RulesProfile {
-
-  private static final Logger LOG = LoggerFactory.getLogger(RulesProfileWrapper.class);
-  private static final String DEPRECATED_USAGE_MESSAGE = "Please update your plugin to support multi-language analysis";
-
-  private final Collection<RulesProfile> profiles;
-  private final RulesProfile singleLanguageProfile;
-
-  public RulesProfileWrapper(Collection<RulesProfile> profiles) {
-    this.profiles = profiles;
-    this.singleLanguageProfile = null;
-  }
-
-  public RulesProfileWrapper(RulesProfile profile) {
-    this.profiles = Collections.singletonList(profile);
-    this.singleLanguageProfile = profile;
-  }
-
-  @Override
-  public Integer getId() {
-    return getSingleProfileOrFail().getId();
-  }
-
-  private RulesProfile getSingleProfileOrFail() {
-    if (singleLanguageProfile == null) {
-      throw new IllegalStateException(DEPRECATED_USAGE_MESSAGE);
-    }
-    return singleLanguageProfile;
-  }
-
-  @Override
-  public String getName() {
-    return singleLanguageProfile != null ? singleLanguageProfile.getName() : "SonarQube";
-  }
-
-  @Override
-  public String getLanguage() {
-    if (singleLanguageProfile == null) {
-      // Multi-languages module
-      // This is a hack for CommonChecksDecorator that call this method in its constructor
-      LOG.debug(DEPRECATED_USAGE_MESSAGE, new SonarException(DEPRECATED_USAGE_MESSAGE));
-      return "";
-    }
-    return singleLanguageProfile.getLanguage();
-  }
-
-  @Override
-  public List<ActiveRule> getActiveRules() {
-    List<ActiveRule> activeRules = new ArrayList<>();
-    for (RulesProfile profile : profiles) {
-      activeRules.addAll(profile.getActiveRules());
-    }
-    return activeRules;
-  }
-
-  @Override
-  public ActiveRule getActiveRule(String repositoryKey, String ruleKey) {
-    for (RulesProfile profile : profiles) {
-      ActiveRule activeRule = profile.getActiveRule(repositoryKey, ruleKey);
-      if (activeRule != null) {
-        return activeRule;
-      }
-    }
-    return null;
-  }
-
-  @Override
-  public List<ActiveRule> getActiveRulesByRepository(String repositoryKey) {
-    List<ActiveRule> activeRules = new ArrayList<>();
-    for (RulesProfile profile : profiles) {
-      activeRules.addAll(profile.getActiveRulesByRepository(repositoryKey));
-    }
-    return activeRules;
-  }
-
-  @Override
-  public List<ActiveRule> getActiveRules(boolean acceptDisabledRules) {
-    List<ActiveRule> activeRules = new ArrayList<>();
-    for (RulesProfile profile : profiles) {
-      activeRules.addAll(profile.getActiveRules(acceptDisabledRules));
-    }
-    return activeRules;
-  }
-
-  @Override
-  public ActiveRule getActiveRule(Rule rule) {
-    for (RulesProfile profile : profiles) {
-      ActiveRule activeRule = profile.getActiveRule(rule);
-      if (activeRule != null) {
-        return activeRule;
-      }
-    }
-    return null;
-  }
-
-  @Override
-  public Boolean getDefaultProfile() {
-    return getSingleProfileOrFail().getDefaultProfile();
-  }
-
-}
index 033ec860832de5e62bbffeb64dde267e36e390d1..a8cf432e5f64c92b4aa6ff2ad6c93d839aa5bb29 100644 (file)
@@ -23,7 +23,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.batch.fs.internal.FileMetadata;
-import org.sonar.api.batch.rule.CheckFactory;
 import org.sonar.api.issue.NoSonarFilter;
 import org.sonar.api.scan.filesystem.FileExclusions;
 import org.sonar.core.extension.CoreExtensionsInstaller;
@@ -50,7 +49,6 @@ import org.sonar.scanner.phases.SensorsExecutor;
 import org.sonar.scanner.postjob.DefaultPostJobContext;
 import org.sonar.scanner.postjob.PostJobOptimizer;
 import org.sonar.scanner.rule.QProfileVerifier;
-import org.sonar.scanner.rule.RulesProfileProvider;
 import org.sonar.scanner.scan.filesystem.DefaultModuleFileSystem;
 import org.sonar.scanner.scan.filesystem.ExclusionFilters;
 import org.sonar.scanner.scan.filesystem.FileIndexer;
@@ -130,10 +128,6 @@ public class ModuleScanContainer extends ComponentContainer {
       ModuleIssueFilters.class,
       CoverageExclusions.class,
 
-      // rules
-      new RulesProfileProvider(),
-      CheckFactory.class,
-
       // issues
       ModuleIssues.class,
       NoSonarFilter.class,
index a5c38184cba03f030715e14c7a843065080301e6..e9c8b229b26461bc202ea0eb370eabddcf7889a9 100644 (file)
@@ -24,6 +24,7 @@ import javax.annotation.Nullable;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.batch.fs.internal.SensorStrategy;
+import org.sonar.api.batch.rule.CheckFactory;
 import org.sonar.api.resources.Languages;
 import org.sonar.api.resources.ResourceTypes;
 import org.sonar.api.scan.filesystem.PathResolver;
@@ -76,7 +77,7 @@ import org.sonar.scanner.repository.ProjectRepositories;
 import org.sonar.scanner.repository.ProjectRepositoriesLoader;
 import org.sonar.scanner.repository.ProjectRepositoriesProvider;
 import org.sonar.scanner.repository.QualityProfileLoader;
-import org.sonar.scanner.repository.QualityProfileProvider;
+import org.sonar.scanner.repository.QualityProfilesProvider;
 import org.sonar.scanner.repository.ServerIssuesLoader;
 import org.sonar.scanner.repository.language.DefaultLanguagesRepository;
 import org.sonar.scanner.rule.ActiveRulesLoader;
@@ -167,7 +168,8 @@ public class ProjectScanContainer extends ComponentContainer {
 
       // rules
       new ActiveRulesProvider(),
-      new QualityProfileProvider(),
+      new QualityProfilesProvider(),
+      CheckFactory.class,
 
       // issues
       IssueCache.class,
index 9280aeb7b2ea483c4dfb1c49777413f902198d47..5831a40d59d7c06e8878156442f3fd9afbd92326 100644 (file)
@@ -43,7 +43,7 @@ import org.sonar.scanner.cpd.CpdSettings;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReportReader;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
-import org.sonar.scanner.rule.ModuleQProfiles;
+import org.sonar.scanner.rule.QualityProfiles;
 import org.sonar.scanner.rule.QProfile;
 import org.sonar.scanner.scan.ScanProperties;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
@@ -66,7 +66,7 @@ public class MetadataPublisherTest {
   private DefaultInputModule rootModule;
   private MetadataPublisher underTest;
   private ScanProperties properties = mock(ScanProperties.class);
-  private ModuleQProfiles qProfiles = mock(ModuleQProfiles.class);
+  private QualityProfiles qProfiles = mock(QualityProfiles.class);
   private ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class);
   private CpdSettings cpdSettings = mock(CpdSettings.class);
   private InputModuleHierarchy inputModuleHierarchy;
index 0201b78839c16f1f581648053dffd9fa092677f1..5c715af7e3abaecc35c1e41054e38b1155c6f9b2 100644 (file)
@@ -33,7 +33,7 @@ import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.scanner.analysis.AnalysisProperties;
-import org.sonar.scanner.rule.ModuleQProfiles;
+import org.sonar.scanner.rule.QualityProfiles;
 import org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -48,7 +48,7 @@ public class QualityProfileProviderTest {
   @Rule
   public LogTester logTester = new LogTester();
 
-  private QualityProfileProvider qualityProfileProvider;
+  private QualityProfilesProvider qualityProfileProvider;
 
   @Mock
   private QualityProfileLoader loader;
@@ -64,7 +64,7 @@ public class QualityProfileProviderTest {
   @Before
   public void setUp() {
     MockitoAnnotations.initMocks(this);
-    qualityProfileProvider = new QualityProfileProvider();
+    qualityProfileProvider = new QualityProfilesProvider();
 
     when(key.get()).thenReturn("project");
     when(projectRepo.exists()).thenReturn(true);
@@ -76,7 +76,7 @@ public class QualityProfileProviderTest {
   @Test
   public void testProvide() {
     when(loader.load("project", null)).thenReturn(response);
-    ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
+    QualityProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
     assertResponse(qps);
 
     verify(loader).load("project", null);
@@ -87,8 +87,8 @@ public class QualityProfileProviderTest {
   public void testProjectDoesntExist() {
     when(projectRepo.exists()).thenReturn(false);
     when(loader.loadDefault(anyString())).thenReturn(response);
-    when(props.property(ModuleQProfiles.SONAR_PROFILE_PROP)).thenReturn("profile");
-    ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
+    when(props.property(QualityProfiles.SONAR_PROFILE_PROP)).thenReturn("profile");
+    QualityProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
     assertResponse(qps);
 
     verify(loader).loadDefault(anyString());
@@ -98,15 +98,15 @@ public class QualityProfileProviderTest {
   @Test
   public void testProfileProp() {
     when(loader.load(eq("project"), eq("custom"))).thenReturn(response);
-    when(props.property(ModuleQProfiles.SONAR_PROFILE_PROP)).thenReturn("custom");
-    when(props.properties()).thenReturn(ImmutableMap.of(ModuleQProfiles.SONAR_PROFILE_PROP, "custom"));
+    when(props.property(QualityProfiles.SONAR_PROFILE_PROP)).thenReturn("custom");
+    when(props.properties()).thenReturn(ImmutableMap.of(QualityProfiles.SONAR_PROFILE_PROP, "custom"));
 
-    ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
+    QualityProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
     assertResponse(qps);
 
     verify(loader).load(eq("project"), eq("custom"));
     verifyNoMoreInteractions(loader);
-    assertThat(logTester.logs(LoggerLevel.WARN)).contains("Ability to set quality profile from command line using '" + ModuleQProfiles.SONAR_PROFILE_PROP
+    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.");
   }
 
@@ -114,19 +114,19 @@ public class QualityProfileProviderTest {
   public void testProfilePropDefault() {
     when(projectRepo.exists()).thenReturn(false);
     when(loader.loadDefault(eq("custom"))).thenReturn(response);
-    when(props.property(ModuleQProfiles.SONAR_PROFILE_PROP)).thenReturn("custom");
-    when(props.properties()).thenReturn(ImmutableMap.of(ModuleQProfiles.SONAR_PROFILE_PROP, "custom"));
+    when(props.property(QualityProfiles.SONAR_PROFILE_PROP)).thenReturn("custom");
+    when(props.properties()).thenReturn(ImmutableMap.of(QualityProfiles.SONAR_PROFILE_PROP, "custom"));
 
-    ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
+    QualityProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
     assertResponse(qps);
 
     verify(loader).loadDefault(eq("custom"));
     verifyNoMoreInteractions(loader);
-    assertThat(logTester.logs(LoggerLevel.WARN)).contains("Ability to set quality profile from command line using '" + ModuleQProfiles.SONAR_PROFILE_PROP
+    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(ModuleQProfiles qps) {
+  private void assertResponse(QualityProfiles qps) {
     assertThat(qps.findAll()).extracting("key").containsExactly("profile");
 
   }
index 6380d4bb803906d619fc2b774e414c33d288a17a..2773208a00faa61f15a30d41db71513cfa8aa02f 100644 (file)
@@ -66,7 +66,7 @@ public class ActiveRulesProviderTest {
     when(loader.load(eq("qp2"))).thenReturn(qp2Rules);
     when(loader.load(eq("qp3"))).thenReturn(qp3Rules);
 
-    ModuleQProfiles profiles = mockProfiles("qp1", "qp2", "qp3");
+    QualityProfiles profiles = mockProfiles("qp1", "qp2", "qp3");
     ActiveRules activeRules = provider.provide(loader, profiles);
 
     assertThat(activeRules.findAll()).hasSize(3);
@@ -88,20 +88,19 @@ public class ActiveRulesProviderTest {
     List<LoadedActiveRule> qpRules = ImmutableList.of(r1, r2);
     when(loader.load(eq("qp"))).thenReturn(qpRules);
 
-    ModuleQProfiles profiles = mockProfiles("qp");
+    QualityProfiles profiles = mockProfiles("qp");
     ActiveRules activeRules = provider.provide(loader, profiles);
 
     assertThat(activeRules.findAll()).hasSize(2);
     assertThat(activeRules.findAll()).extracting("ruleKey", "params").containsOnly(
       Tuple.tuple(RuleKey.of("rule1", "rule1"), ImmutableMap.of()),
-      Tuple.tuple(RuleKey.of("rule2", "rule2"), ImmutableMap.of("foo1", "bar1", "foo2", "bar2"))
-    );
+      Tuple.tuple(RuleKey.of("rule2", "rule2"), ImmutableMap.of("foo1", "bar1", "foo2", "bar2")));
 
     verify(loader).load(eq("qp"));
     verifyNoMoreInteractions(loader);
   }
 
-  private static ModuleQProfiles mockProfiles(String... keys) {
+  private static QualityProfiles mockProfiles(String... keys) {
     List<QualityProfile> profiles = new LinkedList<>();
 
     for (String k : keys) {
@@ -109,7 +108,7 @@ public class ActiveRulesProviderTest {
       profiles.add(p);
     }
 
-    return new ModuleQProfiles(profiles);
+    return new QualityProfiles(profiles);
   }
 
   private static LoadedActiveRule mockRule(String name) {
index 93ee555491d8f6a8628c9486beec073d35f857f2..fb432157a58f57d572d9ecb0f9a30e0db3b17bad 100644 (file)
@@ -43,13 +43,13 @@ public class QProfileVerifierTest {
   public ExpectedException thrown = ExpectedException.none();
 
   private DefaultFileSystem fs;
-  private ModuleQProfiles profiles;
+  private QualityProfiles profiles;
   private MapSettings settings = new MapSettings();
 
   @Before
   public void before() throws Exception {
     fs = new DefaultFileSystem(temp.newFolder().toPath());
-    profiles = mock(ModuleQProfiles.class);
+    profiles = mock(QualityProfiles.class);
     QProfile javaProfile = new QProfile("p1", "My Java profile", "java", null);
     when(profiles.findByLanguage("java")).thenReturn(javaProfile);
     QProfile cobolProfile = new QProfile("p2", "My Cobol profile", "cobol", null);
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RulesProfileProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RulesProfileProviderTest.java
deleted file mode 100644 (file)
index ca1c2d0..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.rule;
-
-import java.util.Arrays;
-import org.junit.Test;
-import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
-import org.sonar.api.batch.rule.internal.NewActiveRule;
-import org.sonar.api.config.internal.MapSettings;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rule.RuleKey;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class RulesProfileProviderTest {
-
-  private ModuleQProfiles qProfiles = mock(ModuleQProfiles.class);
-  private MapSettings settings = new MapSettings();
-  private RulesProfileProvider provider = new RulesProfileProvider();
-
-  @Test
-  public void merge_profiles() {
-    QProfile qProfile = new QProfile("java-sw", "Sonar way", "java", null);
-    when(qProfiles.findAll()).thenReturn(Arrays.asList(qProfile));
-
-    RulesProfile profile = provider.provide(qProfiles, new ActiveRulesBuilder().build(), settings.asConfig());
-
-    // merge of all profiles
-    assertThat(profile).isNotNull().isInstanceOf(RulesProfileWrapper.class);
-    assertThat(profile.getLanguage()).isEqualTo("");
-    assertThat(profile.getName()).isEqualTo("SonarQube");
-    assertThat(profile.getActiveRules()).isEmpty();
-    try {
-      profile.getId();
-      fail();
-    } catch (IllegalStateException e) {
-      // id must not be used at all
-    }
-  }
-
-  @Test
-  public void keep_compatibility_with_single_language_projects() {
-    settings.setProperty("sonar.language", "java");
-
-    QProfile qProfile = new QProfile("java-sw", "Sonar way", "java", null);
-    when(qProfiles.findByLanguage("java")).thenReturn(qProfile);
-
-    RulesProfile profile = provider.provide(qProfiles, new ActiveRulesBuilder().build(), settings.asConfig());
-
-    // no merge, directly the old hibernate profile
-    assertThat(profile).isNotNull();
-    assertThat(profile.getLanguage()).isEqualTo("java");
-    assertThat(profile.getName()).isEqualTo("Sonar way");
-  }
-
-  @Test
-  public void support_rule_templates() {
-    QProfile qProfile = new QProfile("java-sw", "Sonar way", "java", null);
-    when(qProfiles.findAll()).thenReturn(Arrays.asList(qProfile));
-    ActiveRulesBuilder activeRulesBuilder = new ActiveRulesBuilder();
-    activeRulesBuilder.addRule(new NewActiveRule.Builder()
-      .setRuleKey(RuleKey.of("java", "S001"))
-      .setTemplateRuleKey("T001").setLanguage("java")
-      .build());
-
-    RulesProfile profile = provider.provide(qProfiles, activeRulesBuilder.build(), settings.asConfig());
-
-    assertThat(profile.getActiveRule("java", "S001").getRule().getTemplate().getKey()).isEqualTo("T001");
-  }
-}