*/
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
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;
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;
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;
}
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);
}
+++ /dev/null
-/*
- * 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;
- }
-
-}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
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);
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<>();
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()) {
+++ /dev/null
-/*
- * 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);
- }
-}
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;
@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);
--- /dev/null
+/*
+ * 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);
+ }
+}
+++ /dev/null
-/*
- * 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;
- }
-
-}
+++ /dev/null
-/*
- * 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();
- }
-
-}
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;
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;
ModuleIssueFilters.class,
CoverageExclusions.class,
- // rules
- new RulesProfileProvider(),
- CheckFactory.class,
-
// issues
ModuleIssues.class,
NoSonarFilter.class,
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;
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;
// rules
new ActiveRulesProvider(),
- new QualityProfileProvider(),
+ new QualityProfilesProvider(),
+ CheckFactory.class,
// issues
IssueCache.class,
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;
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;
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;
@Rule
public LogTester logTester = new LogTester();
- private QualityProfileProvider qualityProfileProvider;
+ private QualityProfilesProvider qualityProfileProvider;
@Mock
private QualityProfileLoader loader;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- qualityProfileProvider = new QualityProfileProvider();
+ qualityProfileProvider = new QualityProfilesProvider();
when(key.get()).thenReturn("project");
when(projectRepo.exists()).thenReturn(true);
@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);
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());
@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.");
}
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");
}
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);
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) {
profiles.add(p);
}
- return new ModuleQProfiles(profiles);
+ return new QualityProfiles(profiles);
}
private static LoadedActiveRule mockRule(String name) {
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);
+++ /dev/null
-/*
- * 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");
- }
-}