aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-deprecated/src
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-09-06 14:08:06 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-09-06 14:08:06 +0000
commitaeadc1f9129274949daaa57738c7c4550bdfbc7b (patch)
tree08dadf5ef7474fc41d1d48f74648f1ba8b55f34d /sonar-deprecated/src
downloadsonarqube-aeadc1f9129274949daaa57738c7c4550bdfbc7b.tar.gz
sonarqube-aeadc1f9129274949daaa57738c7c4550bdfbc7b.zip
SONAR-236 remove deprecated code from checkstyle plugin + display default value of rule parameters in Q profile console
Diffstat (limited to 'sonar-deprecated/src')
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractPurge.java35
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/database/daos/MeasuresDao.java75
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/database/daos/RulesDao.java97
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/rules/DefaultRulesManager.java247
-rw-r--r--sonar-deprecated/src/test/java/org/sonar/api/rules/DefaultRulesManagerTest.java90
5 files changed, 544 insertions, 0 deletions
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractPurge.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractPurge.java
new file mode 100644
index 00000000000..f4218432165
--- /dev/null
+++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractPurge.java
@@ -0,0 +1,35 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.batch;
+
+import org.sonar.api.database.DatabaseSession;
+
+/**
+ * @since 1.10
+ * @deprecated database components have been moved to sonar-database. Please extend org.sonar.core.purge.AbstractPurge.
+ */
+@Deprecated
+public abstract class AbstractPurge extends org.sonar.core.purge.AbstractPurge {
+
+ public AbstractPurge(DatabaseSession session) {
+ super(session);
+ }
+
+}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/database/daos/MeasuresDao.java b/sonar-deprecated/src/main/java/org/sonar/api/database/daos/MeasuresDao.java
new file mode 100644
index 00000000000..383864d37c8
--- /dev/null
+++ b/sonar-deprecated/src/main/java/org/sonar/api/database/daos/MeasuresDao.java
@@ -0,0 +1,75 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.database.daos;
+
+import org.sonar.api.measures.Metric;
+
+import java.util.Collection;
+import java.util.List;
+
+@Deprecated
+public class MeasuresDao {
+
+ private org.sonar.jpa.dao.MeasuresDao target;
+
+ public MeasuresDao(org.sonar.jpa.dao.MeasuresDao target) {
+ this.target = target;
+ }
+ public Metric getMetric(Metric metric) {
+ return target.getMetric(metric);
+ }
+
+ public List<Metric> getMetrics(List<Metric> metrics) {
+ return target.getMetrics(metrics);
+ }
+
+ public Metric getMetric(String metricName) {
+ return target.getMetric(metricName);
+ }
+
+ public Collection<Metric> getMetrics() {
+ return target.getMetrics();
+ }
+
+ public Collection<Metric> getEnabledMetrics() {
+ return target.getEnabledMetrics();
+ }
+
+ public Collection<Metric> getUserDefinedMetrics() {
+ return target.getUserDefinedMetrics();
+ }
+
+ public void disableAutomaticMetrics() {
+ target.disableAutomaticMetrics();
+ }
+
+ public void registerMetrics(Collection<Metric> metrics) {
+ target.registerMetrics(metrics);
+ }
+
+ public void persistMetric(Metric metric) {
+ target.persistMetric(metric);
+ }
+
+ public void disabledMetrics(Collection<Metric> metrics) {
+ target.disabledMetrics(metrics);
+ }
+
+}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/database/daos/RulesDao.java b/sonar-deprecated/src/main/java/org/sonar/api/database/daos/RulesDao.java
new file mode 100644
index 00000000000..1d5d5fb90bc
--- /dev/null
+++ b/sonar-deprecated/src/main/java/org/sonar/api/database/daos/RulesDao.java
@@ -0,0 +1,97 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.database.daos;
+
+import org.sonar.api.database.model.RuleFailureModel;
+import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.profiles.RulesProfile;
+import org.sonar.api.rules.ActiveRule;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RuleParam;
+import org.sonar.api.rules.RulesCategory;
+
+import java.util.List;
+
+@Deprecated
+public class RulesDao {
+
+ private org.sonar.jpa.dao.RulesDao target;
+
+ public RulesDao(org.sonar.jpa.dao.RulesDao target) {
+ this.target = target;
+ }
+
+ public List<Rule> getRules() {
+ return target.getRules();
+ }
+
+ public List<Rule> getRulesByPlugin(String pluginKey) {
+ return target.getRulesByPlugin(pluginKey);
+ }
+
+ public List<Rule> getRulesByCategory(RulesCategory categ) {
+ return target.getRulesByCategory(categ);
+ }
+
+ public Rule getRuleByKey(String pluginKey, String ruleKey) {
+ return target.getRuleByKey(pluginKey, ruleKey);
+ }
+
+ public Long countRules(List<String> plugins, String categoryName) {
+ return target.countRules(plugins, categoryName);
+ }
+
+ public List<RulesCategory> getCategories() {
+ return target.getCategories();
+ }
+
+ public RulesCategory getCategory(String key) {
+ return target.getCategory(key);
+ }
+
+
+ public List<RuleParam> getRuleParams() {
+ return target.getRuleParams();
+ }
+
+ public RuleParam getRuleParam(Rule rule, String paramKey) {
+ return target.getRuleParam(rule, paramKey);
+ }
+
+ public void addActiveRulesToProfile(List<ActiveRule> activeRules, int profileId, String pluginKey) {
+ target.addActiveRulesToProfile(activeRules, profileId, pluginKey);
+ }
+
+ public List<RuleFailureModel> getViolations(Snapshot snapshot) {
+ return target.getViolations(snapshot);
+ }
+
+ public void synchronizeRuleOfActiveRule(ActiveRule activeRule, String pluginKey) {
+ target.synchronizeRuleOfActiveRule(activeRule, pluginKey);
+ }
+
+ public boolean isRuleParamEqual(RuleParam ruleParam, RuleParam ruleParamFromDatabase, String ruleKey, String pluginKey) {
+ return target.isRuleParamEqual(ruleParam, ruleParamFromDatabase, ruleKey, pluginKey);
+ }
+
+ public RulesProfile getProfileById(int profileId) {
+ return target.getProfileById(profileId);
+ }
+}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/rules/DefaultRulesManager.java b/sonar-deprecated/src/main/java/org/sonar/api/rules/DefaultRulesManager.java
new file mode 100644
index 00000000000..dce362a38a6
--- /dev/null
+++ b/sonar-deprecated/src/main/java/org/sonar/api/rules/DefaultRulesManager.java
@@ -0,0 +1,247 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.rules;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.sonar.api.Plugin;
+import org.sonar.api.Plugins;
+import org.sonar.jpa.dao.RulesDao;
+import org.sonar.api.resources.Language;
+
+import java.util.*;
+
+/**
+ * A class to manage and access rules defined in Sonar.
+ *
+ * @deprecated UGLY CLASS - WILL BE COMPLETELY REFACTORED IN SONAR 2.3
+ */
+@Deprecated
+public class DefaultRulesManager extends RulesManager {
+
+ private final Set<Language> languages;
+ private final RulesRepository<?>[] repositories;
+ private final Map<Language, List<RulesRepository<?>>> rulesByLanguage;
+ private final Map<Language, List<Plugin>> pluginsByLanguage;
+ private final Map<String, Map<String, Rule>> rulesByPluginAndKey = new HashMap<String, Map<String, Rule>>();
+ private final RulesDao rulesDao;
+ private final Plugins plugins;
+
+ /**
+ * Creates a RuleManager
+ * @param plugins the plugins dictionnary
+ * @param repositories the repositories of rules
+ * @param dao the dao object
+ */
+ public DefaultRulesManager(Plugins plugins, RulesRepository[] repositories, RulesDao dao) {
+ this.plugins = plugins;
+ this.rulesDao = dao;
+
+ languages = new HashSet<Language>();
+ rulesByLanguage = new HashMap<Language, List<RulesRepository<?>>>();
+ pluginsByLanguage = new HashMap<Language, List<Plugin>>();
+ this.repositories = repositories;
+
+ for (RulesRepository<?> repository : repositories) {
+ languages.add(repository.getLanguage());
+
+ List<RulesRepository<?>> list = rulesByLanguage.get(repository.getLanguage());
+ if (list == null) {
+ list = new ArrayList<RulesRepository<?>>();
+ rulesByLanguage.put(repository.getLanguage(), list);
+ }
+ list.add(repository);
+
+ List<Plugin> languagePlugins = pluginsByLanguage.get(repository.getLanguage());
+ if (languagePlugins == null) {
+ languagePlugins = new ArrayList<Plugin>();
+ pluginsByLanguage.put(repository.getLanguage(), languagePlugins);
+ }
+ languagePlugins.add(plugins.getPluginByExtension(repository));
+ }
+ }
+
+ /**
+ * Constructor for tests only
+ *
+ * @param dao the dao
+ */
+ protected DefaultRulesManager(RulesDao dao, Plugins plugins) {
+ this.rulesDao = dao;
+ this.plugins = plugins;
+ languages = new HashSet<Language>();
+ rulesByLanguage = new HashMap<Language, List<RulesRepository<?>>>();
+ pluginsByLanguage = new HashMap<Language, List<Plugin>>();
+ repositories = null;
+
+ }
+
+ /**
+ * Returns the list of languages for which there is a rule repository
+ *
+ * @return a Set of languages
+ */
+ public Set<Language> getLanguages() {
+ return languages;
+ }
+
+ /**
+ * Gets the list of Rules Repositories available for a language
+ *
+ * @param language the language
+ * @return the list of rules repositories
+ */
+ public List<RulesRepository<?>> getRulesRepositories(Language language) {
+ List<RulesRepository<?>> rulesRepositories = rulesByLanguage.get(language);
+ if (CollectionUtils.isNotEmpty(rulesRepositories)) {
+ return rulesRepositories;
+ }
+ return Collections.emptyList();
+ }
+
+ /**
+ * Gets the complete list of Rules Repositories in the Sonar instance
+ *
+ * @return the list of rules repositories
+ */
+ public List<RulesRepository<?>> getRulesRepositories() {
+ return Arrays.asList(repositories);
+ }
+
+ /**
+ * Gets the list of rules plugins for a given language
+ * @param language the language
+ * @return the list of plugins
+ */
+ public List<Plugin> getPlugins(Language language) {
+ List<Plugin> result = pluginsByLanguage.get(language);
+ if (!CollectionUtils.isEmpty(result)) {
+ return result;
+ }
+ return Collections.emptyList();
+ }
+
+ /**
+ * Gets count of rules by categories defined for a given language
+ *
+ * @param language the language
+ * @return a Map with the category as key and the count as value
+ */
+ public Map<String, Long> countRulesByCategory(Language language) {
+ return countRulesByCategory(language, rulesDao);
+ }
+
+ protected Map<String, Long> countRulesByCategory(Language language, RulesDao rulesDao) {
+ Map<String, Long> countByCategory = new HashMap<String, Long>();
+ List<Plugin> result = getPlugins(language);
+ if (!CollectionUtils.isEmpty(result)) {
+ List<String> keys = getPluginKeys(getPlugins(language));
+ for (RulesCategory rulesCategory : rulesDao.getCategories()) {
+ Long rulesCount = rulesDao.countRules(keys, rulesCategory.getName());
+ countByCategory.put(rulesCategory.getName(), rulesCount);
+ }
+ }
+ return countByCategory;
+ }
+
+ private List<String> getPluginKeys(List<Plugin> plugins) {
+ ArrayList<String> keys = new ArrayList<String>();
+ for (Plugin plugin : plugins) {
+ keys.add(plugin.getKey());
+ }
+ return keys;
+ }
+
+ /**
+ * Get the list of rules plugin that implement a mechanism of export for a given language
+ *
+ * @param language the language
+ * @return the list of plugins
+ */
+ public List<Plugin> getExportablePlugins(Language language) {
+ List<Plugin> targets = new ArrayList<Plugin>();
+ List<RulesRepository<?>> rulesRepositories = getRulesRepositories(language);
+ for (RulesRepository<?> repository : rulesRepositories) {
+ if (repository instanceof ConfigurationExportable) {
+ targets.add(plugins.getPluginByExtension(repository));
+ }
+ }
+ return targets;
+ }
+
+ /**
+ * Get the list of rules plugin that implement a mechanism of import for a given language
+ *
+ * @param language the language
+ * @return the list of plugins
+ */
+ public List<Plugin> getImportablePlugins(Language language) {
+ List<Plugin> targets = new ArrayList<Plugin>();
+ for (RulesRepository<?> repository : getRulesRepositories(language)) {
+ if (repository instanceof ConfigurationImportable) {
+ targets.add(plugins.getPluginByExtension(repository));
+ }
+ }
+ return targets;
+ }
+
+ /**
+ * Gets a list of rules indexed by their key for a given plugin
+ * @param pluginKey the plugin key
+ * @return a Map with the rule key and the rule
+ */
+ public Map<String, Rule> getPluginRulesIndexedByKey(String pluginKey) {
+ Map<String, Rule> rulesByKey = rulesByPluginAndKey.get(pluginKey);
+ if (rulesByKey == null) {
+ rulesByKey = new HashMap<String, Rule>();
+ List<Rule> rules = rulesDao.getRulesByPlugin(pluginKey);
+ if (rules != null) {
+ for (Rule rule : rules) {
+ rulesByKey.put(rule.getKey(), rule);
+ }
+ }
+ rulesByPluginAndKey.put(pluginKey, rulesByKey);
+ }
+ return rulesByKey;
+ }
+
+ /**
+ * Gets a collection of rules belonging to a plugin
+ *
+ * @param pluginKey the plugin key
+ * @return the collection of rules
+ */
+ public Collection<Rule> getPluginRules(String pluginKey) {
+ Map<String, Rule> rulesByKey = getPluginRulesIndexedByKey(pluginKey);
+ return rulesByKey.values();
+ }
+
+ /**
+ * Gets a rule belonging to a defined plugin based on its key
+ *
+ * @param pluginKey the plugin key
+ * @param ruleKey the rule key
+ * @return the rule
+ */
+ public Rule getPluginRule(String pluginKey, String ruleKey) {
+ Map<String, Rule> rulesByKey = getPluginRulesIndexedByKey(pluginKey);
+ return rulesByKey.get(ruleKey);
+ }
+
+}
diff --git a/sonar-deprecated/src/test/java/org/sonar/api/rules/DefaultRulesManagerTest.java b/sonar-deprecated/src/test/java/org/sonar/api/rules/DefaultRulesManagerTest.java
new file mode 100644
index 00000000000..62aa2a3a077
--- /dev/null
+++ b/sonar-deprecated/src/test/java/org/sonar/api/rules/DefaultRulesManagerTest.java
@@ -0,0 +1,90 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.rules;
+
+import org.junit.Test;
+import org.sonar.api.Plugin;
+import org.sonar.api.Plugins;
+import org.sonar.jpa.dao.RulesDao;
+import org.sonar.api.resources.Language;
+import org.sonar.jpa.dao.DaoFacade;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class DefaultRulesManagerTest {
+
+ @Test
+ public void shouldReturnsZeroRulesByCategoryWhenNoPluginsForALanguage() {
+ DefaultRulesManager rulesManager = createRulesManagerForAlanguageWithNoPlugins();
+
+ Language language = mock(Language.class);
+ Map<String, Long> result = rulesManager.countRulesByCategory(language);
+ assertThat(result.size(), is(0));
+ }
+
+ @Test
+ public void shouldReturnsZeroExportablePluginsWhenLanguageHasNoRulesPlugin() {
+ DefaultRulesManager rulesManager = createRulesManagerForAlanguageWithNoPlugins();
+
+ Language language = mock(Language.class);
+ List<Plugin> result = rulesManager.getExportablePlugins(language);
+ assertThat(result.size(), is(0));
+ }
+
+ @Test
+ public void shouldReturnsZeroImportablePluginsWhenLanguageHasNoRulesPlugin() {
+ DefaultRulesManager rulesManager = createRulesManagerForAlanguageWithNoPlugins();
+
+ Language language = mock(Language.class);
+ List<Plugin> result = rulesManager.getImportablePlugins(language);
+ assertThat(result.size(), is(0));
+ }
+
+ @Test
+ public void shouldReturnZeroPluginWhenLanguageHasNoRulesPlugin() {
+ DefaultRulesManager rulesManager = createRulesManagerForAlanguageWithNoPlugins();
+ Language language = mock(Language.class);
+ List<Plugin> result = rulesManager.getPlugins(language);
+ assertThat(result.size(), is(0));
+ }
+
+ @Test
+ public void shouldReturnZeroRulesRepositoryWhenLanguageHasNoRulesRepository() {
+ DefaultRulesManager rulesManager = createRulesManagerForAlanguageWithNoPlugins();
+ Language language = mock(Language.class);
+ List<RulesRepository<?>> result = rulesManager.getRulesRepositories(language);
+ assertThat(result.size(), is(0));
+ }
+
+ private DefaultRulesManager createRulesManagerForAlanguageWithNoPlugins() {
+ DaoFacade dao = mock(DaoFacade.class);
+ RulesDao rulesDao = mock(RulesDao.class);
+ when(rulesDao.getCategories()).thenReturn(Collections.<RulesCategory>emptyList());
+ DefaultRulesManager rulesManager = new DefaultRulesManager(rulesDao, new Plugins(null));
+ return rulesManager;
+ }
+}