diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-06-10 22:34:55 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-06-11 11:20:31 +0200 |
commit | 47a1c603fa19bf115bd3a0b9689705bd68a988ff (patch) | |
tree | 4094565dc815418ffdfdd9c47a8d9abd9caa6f88 /sonar-batch | |
parent | a774a62aec4318d3db04aaa8bc0a4cf741959f03 (diff) | |
download | sonarqube-47a1c603fa19bf115bd3a0b9689705bd68a988ff.tar.gz sonarqube-47a1c603fa19bf115bd3a0b9689705bd68a988ff.zip |
SONAR-5007 remove Hibernate entities RulesProfile, ActiveRule and
ActiveRuleParam
Diffstat (limited to 'sonar-batch')
5 files changed, 33 insertions, 40 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java index 992ccf77819..0e954b0fe19 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java @@ -55,7 +55,6 @@ import org.sonar.core.purge.PurgeProfiler; import org.sonar.core.rule.CacheRuleFinder; import org.sonar.core.user.HibernateUserFinder; import org.sonar.jpa.dao.MeasuresDao; -import org.sonar.jpa.dao.ProfilesDao; import org.sonar.jpa.dao.RulesDao; import org.sonar.jpa.session.DefaultDatabaseConnector; import org.sonar.jpa.session.JpaDatabaseSession; @@ -149,7 +148,6 @@ public class BootstrapContainer extends ComponentContainer { RuleI18nManager.class, MeasuresDao.class, RulesDao.class, - ProfilesDao.class, HibernateUserFinder.class, SemaphoreUpdater.class, SemaphoresImpl.class, diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java b/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java index 23d678c7a67..75f58e07e26 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java @@ -60,6 +60,7 @@ public class ActiveRulesProvider extends ProviderAdapter { if (rule != null) { NewActiveRule newActiveRule = builder.activate(rule.ruleKey()); newActiveRule.setSeverity(activeDto.getSeverityString()); + newActiveRule.setLanguage(rule.getLanguage()); if (rule.getParent() != null) { newActiveRule.setInternalKey(rule.getParent().getConfigKey()); } else { diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java index 2e082bb3221..2b778be21dc 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java @@ -23,12 +23,16 @@ import com.google.common.collect.Lists; 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.Settings; import org.sonar.api.profiles.RulesProfile; import org.sonar.api.rules.ActiveRule; -import org.sonar.jpa.dao.ProfilesDao; +import org.sonar.api.rules.Rule; +import org.sonar.api.rules.RuleFinder; +import org.sonar.api.rules.RulePriority; import java.util.Collection; +import java.util.Map; /** * Ensures backward-compatibility with extensions that use {@link org.sonar.api.profiles.RulesProfile}. @@ -37,47 +41,49 @@ public class RulesProfileProvider extends ProviderAdapter { private RulesProfile singleton = null; - public RulesProfile provide(ModuleQProfiles qProfiles, Settings settings, ProfilesDao dao) { + public RulesProfile provide(ModuleQProfiles qProfiles, ActiveRules activeRules, RuleFinder ruleFinder, Settings settings) { if (singleton == null) { String lang = settings.getString(CoreProperties.PROJECT_LANGUAGE_PROPERTY); if (StringUtils.isNotBlank(lang)) { // Backward-compatibility with single-language modules - singleton = loadSingleLanguageProfile(qProfiles, lang, dao); + singleton = loadSingleLanguageProfile(qProfiles, activeRules, ruleFinder, lang); } else { - singleton = loadProfiles(qProfiles, dao); + singleton = loadProfiles(qProfiles, activeRules, ruleFinder); } } return singleton; } - private RulesProfile loadSingleLanguageProfile(ModuleQProfiles qProfiles, String language, ProfilesDao dao) { + private RulesProfile loadSingleLanguageProfile(ModuleQProfiles qProfiles, ActiveRules activeRules, + RuleFinder ruleFinder, String language) { ModuleQProfiles.QProfile qProfile = qProfiles.findByLanguage(language); if (qProfile != null) { - return new RulesProfileWrapper(select(qProfile, dao)); + return new RulesProfileWrapper(select(qProfile, activeRules, ruleFinder)); } return new RulesProfileWrapper(Lists.<RulesProfile>newArrayList()); } - private RulesProfile loadProfiles(ModuleQProfiles qProfiles, ProfilesDao dao) { + private RulesProfile loadProfiles(ModuleQProfiles qProfiles, ActiveRules activeRules, RuleFinder ruleFinder) { Collection<RulesProfile> dtos = Lists.newArrayList(); for (ModuleQProfiles.QProfile qProfile : qProfiles.findAll()) { - dtos.add(select(qProfile, dao)); + dtos.add(select(qProfile, activeRules, ruleFinder)); } return new RulesProfileWrapper(dtos); } - private RulesProfile select(ModuleQProfiles.QProfile qProfile, ProfilesDao dao) { - RulesProfile dto = dao.getProfile(qProfile.language(), qProfile.name()); - return hibernateHack(dto); - } - - private RulesProfile hibernateHack(RulesProfile profile) { - // hack to lazy initialize the profile collections - profile.getActiveRules().size(); - for (ActiveRule activeRule : profile.getActiveRules()) { - activeRule.getActiveRuleParams().size(); - activeRule.getRule().getParams().size(); + private RulesProfile select(ModuleQProfiles.QProfile qProfile, ActiveRules activeRules, RuleFinder ruleFinder) { + RulesProfile deprecatedProfile = new RulesProfile(); + deprecatedProfile.setVersion(qProfile.version()); + deprecatedProfile.setName(qProfile.name()); + deprecatedProfile.setLanguage(qProfile.language()); + for (org.sonar.api.batch.rule.ActiveRule activeRule : activeRules.findByLanguage(qProfile.language())) { + Rule rule = ruleFinder.findByKey(activeRule.ruleKey()); + ActiveRule deprecatedActiveRule = deprecatedProfile.activateRule(rule, RulePriority.valueOf(activeRule.severity())); + for (Map.Entry<String, String> param : activeRule.params().entrySet()) { + deprecatedActiveRule.setParameter(param.getKey(), param.getValue()); + } } - return profile; + return deprecatedProfile; } + } diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileWrapper.java b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileWrapper.java index 0d8369734a6..b65ca1b094b 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileWrapper.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileWrapper.java @@ -83,16 +83,6 @@ public class RulesProfileWrapper extends RulesProfile { return singleLanguageProfile.getLanguage(); } - // TODO remove when ProfileEventsSensor is refactored - public RulesProfile getProfileByLanguage(String languageKey) { - for (RulesProfile profile : profiles) { - if (languageKey.equals(profile.getLanguage())) { - return profile; - } - } - return null; - } - @Override public List<ActiveRule> getActiveRules() { List<ActiveRule> activeRules = new ArrayList<ActiveRule>(); diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProfileProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProfileProviderTest.java index 52e122ecbf5..3a980631b1c 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProfileProviderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProfileProviderTest.java @@ -20,9 +20,10 @@ package org.sonar.batch.rule; import org.junit.Test; +import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.config.Settings; import org.sonar.api.profiles.RulesProfile; -import org.sonar.jpa.dao.ProfilesDao; +import org.sonar.api.rules.RuleFinder; import java.util.Arrays; @@ -34,18 +35,17 @@ import static org.mockito.Mockito.when; public class RulesProfileProviderTest { ModuleQProfiles qProfiles = mock(ModuleQProfiles.class); + ActiveRules activeRules = mock(ActiveRules.class); + RuleFinder ruleFinder = mock(RuleFinder.class); Settings settings = new Settings(); - ProfilesDao dao = mock(ProfilesDao.class); RulesProfileProvider provider = new RulesProfileProvider(); @Test public void merge_profiles() throws Exception { ModuleQProfiles.QProfile qProfile = new ModuleQProfiles.QProfile(33, "Sonar way", "java", 12); when(qProfiles.findAll()).thenReturn(Arrays.asList(qProfile)); - RulesProfile hibernateProfile = new RulesProfile("Sonar way", "java"); - when(dao.getProfile("java", "Sonar way")).thenReturn(hibernateProfile); - RulesProfile profile = provider.provide(qProfiles, settings, dao); + RulesProfile profile = provider.provide(qProfiles, activeRules, ruleFinder, settings); // merge of all profiles assertThat(profile).isNotNull().isInstanceOf(RulesProfileWrapper.class); @@ -66,10 +66,8 @@ public class RulesProfileProviderTest { ModuleQProfiles.QProfile qProfile = new ModuleQProfiles.QProfile(33, "Sonar way", "java", 12); when(qProfiles.findByLanguage("java")).thenReturn(qProfile); - RulesProfile hibernateProfile = new RulesProfile("Sonar way", "java").setVersion(12); - when(dao.getProfile("java", "Sonar way")).thenReturn(hibernateProfile); - RulesProfile profile = provider.provide(qProfiles, settings, dao); + RulesProfile profile = provider.provide(qProfiles, activeRules, ruleFinder, settings); // no merge, directly the old hibernate profile assertThat(profile).isNotNull(); |