From: Simon Brandhof Date: Tue, 22 May 2012 22:26:02 +0000 (+0200) Subject: Remove the classes RulesManager and DaoFacade. X-Git-Tag: 3.1~120 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a5e9b7728595fc28ccad401cf44574e3c08b0430;p=sonarqube.git Remove the classes RulesManager and DaoFacade. Both of them have been deprecated long time ago. --- diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DatabaseBatchCompatibility.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DatabaseBatchCompatibility.java index 21a149589aa..5b7ec00d86f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DatabaseBatchCompatibility.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DatabaseBatchCompatibility.java @@ -53,7 +53,7 @@ public class DatabaseBatchCompatibility implements BatchComponent { } private void checkCorrectServerId() { - String remoteServerId = null; + String remoteServerId; try { remoteServerId = remoteServer.getServerId(); } catch (IOException e) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java index f6a3af1b8e8..390bba94cf5 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java @@ -28,7 +28,6 @@ import org.sonar.api.resources.Language; import org.sonar.api.resources.Languages; import org.sonar.api.resources.Project; import org.sonar.api.resources.ProjectFileSystem; -import org.sonar.api.rules.DefaultRulesManager; import org.sonar.api.utils.IocContainer; import org.sonar.api.utils.SonarException; import org.sonar.batch.*; @@ -40,7 +39,6 @@ import org.sonar.batch.index.DefaultResourcePersister; import org.sonar.batch.phases.Phases; import org.sonar.batch.phases.PhasesTimeProfiler; import org.sonar.core.qualitymodel.DefaultModelFinder; -import org.sonar.jpa.dao.DaoFacade; import org.sonar.jpa.dao.ProfilesDao; import org.sonar.jpa.dao.RulesDao; @@ -76,7 +74,6 @@ public class ProjectModule extends Module { } addCoreSingleton(DefaultProjectClasspath.class); addCoreSingleton(DefaultProjectFileSystem2.class); - addCoreSingleton(DaoFacade.class); addCoreSingleton(RulesDao.class); if (!dryRun) { @@ -86,7 +83,6 @@ public class ProjectModule extends Module { addCoreSingleton(TimeMachineConfiguration.class); addCoreSingleton(org.sonar.api.database.daos.MeasuresDao.class); addCoreSingleton(ProfilesDao.class); - addCoreSingleton(DefaultRulesManager.class); addCoreSingleton(DefaultSensorContext.class); addCoreSingleton(Languages.class); addCoreSingleton(BatchExtensionDictionnary.class); diff --git a/sonar-core/src/main/java/org/sonar/jpa/dao/DaoFacade.java b/sonar-core/src/main/java/org/sonar/jpa/dao/DaoFacade.java deleted file mode 100644 index d98b02fd49d..00000000000 --- a/sonar-core/src/main/java/org/sonar/jpa/dao/DaoFacade.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * 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.jpa.dao; - -public class DaoFacade { - - private final RulesDao rulesDao; - private final MeasuresDao measuresDao; - private final ProfilesDao profilesDao; - - public DaoFacade(ProfilesDao profilesDao, RulesDao rulesDao, MeasuresDao measuresDao) { - super(); - this.rulesDao = rulesDao; - this.measuresDao = measuresDao; - this.profilesDao = profilesDao; - } - - public RulesDao getRulesDao() { - return rulesDao; - } - - public ProfilesDao getProfilesDao() { - return profilesDao; - } - - public MeasuresDao getMeasuresDao() { - return measuresDao; - } -} diff --git a/sonar-core/src/test/java/org/sonar/jpa/test/AbstractDbUnitTestCase.java b/sonar-core/src/test/java/org/sonar/jpa/test/AbstractDbUnitTestCase.java index c677f4de7e1..34c696e283f 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/test/AbstractDbUnitTestCase.java +++ b/sonar-core/src/test/java/org/sonar/jpa/test/AbstractDbUnitTestCase.java @@ -35,10 +35,6 @@ import org.sonar.core.persistence.Database; import org.sonar.core.persistence.DatabaseCommands; import org.sonar.core.persistence.InMemoryDatabase; import org.sonar.core.persistence.MyBatis; -import org.sonar.jpa.dao.DaoFacade; -import org.sonar.jpa.dao.MeasuresDao; -import org.sonar.jpa.dao.ProfilesDao; -import org.sonar.jpa.dao.RulesDao; import org.sonar.jpa.session.DatabaseSessionFactory; import org.sonar.jpa.session.DefaultDatabaseConnector; import org.sonar.jpa.session.JpaDatabaseSession; @@ -57,7 +53,6 @@ import static org.junit.Assert.fail; public abstract class AbstractDbUnitTestCase { private JpaDatabaseSession session; - private DaoFacade dao; private IDatabaseTester databaseTester; private IDatabaseConnection connection; private static Database database; @@ -108,13 +103,6 @@ public abstract class AbstractDbUnitTestCase { return myBatis; } - public DaoFacade getDao() { - if (dao == null) { - dao = new DaoFacade(new ProfilesDao(session), new RulesDao(session), new MeasuresDao(session)); - } - return dao; - } - public DatabaseSession getSession() { return session; } 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 deleted file mode 100644 index 773ac7ebe67..00000000000 --- a/sonar-deprecated/src/main/java/org/sonar/api/rules/DefaultRulesManager.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * 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 com.google.common.collect.Maps; -import org.sonar.jpa.dao.RulesDao; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * A class to manage and access rules defined in Sonar. - * - * @deprecated UGLY CLASS - */ -@Deprecated -public class DefaultRulesManager extends RulesManager { - - private final Map> rulesByPluginAndKey = Maps.newHashMap(); - private final RulesDao rulesDao; - - public DefaultRulesManager(RulesDao dao) { - this.rulesDao = dao; - } - - /** - * 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 getPluginRulesIndexedByKey(String pluginKey) { - Map rulesByKey = rulesByPluginAndKey.get(pluginKey); - if (rulesByKey == null) { - rulesByKey = new HashMap(); - List rules = rulesDao.getRulesByPlugin(pluginKey); - if (rules != null) { - for (Rule rule : rules) { - rulesByKey.put(rule.getKey(), rule); - } - } - rulesByPluginAndKey.put(pluginKey, rulesByKey); - } - return rulesByKey; - } - - /** - * 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 - */ - @Override - public Rule getPluginRule(String pluginKey, String ruleKey) { - Map rulesByKey = getPluginRulesIndexedByKey(pluginKey); - return rulesByKey.get(ruleKey); - } - -} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/rules/RulesManager.java b/sonar-deprecated/src/main/java/org/sonar/api/rules/RulesManager.java deleted file mode 100644 index d50f33c1896..00000000000 --- a/sonar-deprecated/src/main/java/org/sonar/api/rules/RulesManager.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * 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; - -/** - * @deprecated since 2.3 - */ -@Deprecated -public abstract class RulesManager { - - /** - * 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 abstract Rule getPluginRule(String pluginKey, String ruleKey); -} diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java index 91147909dc4..1542bb10aaa 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java @@ -32,7 +32,6 @@ import org.sonar.api.profiles.XMLProfileSerializer; import org.sonar.api.resources.Languages; import org.sonar.api.resources.ResourceTypes; import org.sonar.api.rules.AnnotationRuleParser; -import org.sonar.api.rules.DefaultRulesManager; import org.sonar.api.rules.XMLRuleParser; import org.sonar.api.utils.HttpDownloader; import org.sonar.api.utils.IocContainer; @@ -50,7 +49,6 @@ import org.sonar.core.review.workflow.WorkflowEngine; import org.sonar.core.review.workflow.Workflow; import org.sonar.core.rule.DefaultRuleFinder; import org.sonar.core.user.DefaultUserFinder; -import org.sonar.jpa.dao.DaoFacade; import org.sonar.jpa.dao.MeasuresDao; import org.sonar.jpa.dao.ProfilesDao; import org.sonar.jpa.dao.RulesDao; @@ -200,8 +198,6 @@ public final class Platform { servicesContainer.addComponent(MeasuresDao.class, false); servicesContainer.addComponent(org.sonar.api.database.daos.MeasuresDao.class, false); servicesContainer.addComponent(ProfilesDao.class, false); - servicesContainer.addComponent(DaoFacade.class, false); - servicesContainer.addComponent(DefaultRulesManager.class, false); servicesContainer.addComponent(ProfilesManager.class, false); servicesContainer.addComponent(Backup.class, false); servicesContainer.addSingleton(SecurityRealmFactory.class); diff --git a/sonar-server/src/test/java/org/sonar/server/configuration/MetricsBackupTest.java b/sonar-server/src/test/java/org/sonar/server/configuration/MetricsBackupTest.java index b2e26702f6f..48298acb4d6 100644 --- a/sonar-server/src/test/java/org/sonar/server/configuration/MetricsBackupTest.java +++ b/sonar-server/src/test/java/org/sonar/server/configuration/MetricsBackupTest.java @@ -47,7 +47,7 @@ public class MetricsBackupTest extends AbstractDbUnitTestCase { @Test public void shouldImportMetrics() { - MeasuresDao measuresDao = getDao().getMeasuresDao(); + MeasuresDao measuresDao = new MeasuresDao(getSession()); Collection oldMetrics = createMetrics(); measuresDao.registerMetrics(oldMetrics); diff --git a/sonar-server/src/test/java/org/sonar/server/configuration/RulesBackupTest.java b/sonar-server/src/test/java/org/sonar/server/configuration/RulesBackupTest.java index 442bc70a542..5e3f3bada92 100644 --- a/sonar-server/src/test/java/org/sonar/server/configuration/RulesBackupTest.java +++ b/sonar-server/src/test/java/org/sonar/server/configuration/RulesBackupTest.java @@ -81,7 +81,7 @@ public class RulesBackupTest extends AbstractDbUnitTestCase { private void verify() { assertThat(getSession().getResults(Rule.class).size(), is(2)); - Rule importedRule = getDao().getRulesDao().getRuleByKey("repo", "key2"); + Rule importedRule = new RulesDao(getSession()).getRuleByKey("repo", "key2"); assertThat(importedRule.getParent(), is(rule)); assertThat(importedRule.isEnabled(), is(true)); assertThat(importedRule.getName(), is("name2")); @@ -120,7 +120,7 @@ public class RulesBackupTest extends AbstractDbUnitTestCase { rulesBackup.importXml(sonarConfig); assertThat(getSession().getResults(Rule.class).size(), is(2)); - RulesDao rulesDao = getDao().getRulesDao(); + RulesDao rulesDao = new RulesDao(getSession()); Rule importedRule = rulesDao.getRuleByKey("repo", "key2"); assertThat(importedRule, notNullValue()); assertThat(rulesDao.getRuleParam(importedRule, "param"), nullValue()); diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java index 3bf2e7984ad..1c1b06b6666 100644 --- a/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java +++ b/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java @@ -61,11 +61,12 @@ public class RegisterMetricsTest extends AbstractDbUnitTestCase { public void enableOnlyLoadedMetrics() { setupData("enableOnlyLoadedMetrics"); - RegisterMetrics loader = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), null); + MeasuresDao measuresDao = new MeasuresDao(getSession()); + RegisterMetrics loader = new RegisterMetrics(getSession(), measuresDao, null); loader.start(); - assertFalse(getDao().getMeasuresDao().getMetric("deprecated").getEnabled()); - assertTrue(getDao().getMeasuresDao().getMetric(CoreMetrics.COMPLEXITY).getEnabled()); + assertFalse(measuresDao.getMetric("deprecated").getEnabled()); + assertTrue(measuresDao.getMetric(CoreMetrics.COMPLEXITY).getEnabled()); } @Test