diff options
16 files changed, 83 insertions, 427 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/WeightedIssuesDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/WeightedIssuesDecorator.java index b215689806d..64f8f309e79 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/WeightedIssuesDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/WeightedIssuesDecorator.java @@ -73,6 +73,7 @@ public class WeightedIssuesDecorator implements Decorator { return CoreMetrics.WEIGHTED_VIOLATIONS; } + @Override public boolean shouldExecuteOnProject(Project project) { return true; } @@ -98,7 +99,7 @@ public class WeightedIssuesDecorator implements Decorator { return weights; } - + @Override public void decorate(Resource resource, DecoratorContext context) { decorate(context); } diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/SonarConfig.java b/sonar-server/src/main/java/org/sonar/server/configuration/SonarConfig.java deleted file mode 100644 index 8c27ecf9c5a..00000000000 --- a/sonar-server/src/main/java/org/sonar/server/configuration/SonarConfig.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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.server.configuration; - -import com.thoughtworks.xstream.annotations.XStreamAlias; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.sonar.api.database.configuration.Property; -import org.sonar.api.measures.Metric; -import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.rules.Rule; - -import java.util.Collection; -import java.util.Date; - -@XStreamAlias("sonar-config") -public class SonarConfig { - - private Integer version; - - private Date date; - - private Collection<Metric> metrics; - - private Collection<Property> properties; - - private Collection<RulesProfile> profiles; - - private Collection<Rule> rules; - - public SonarConfig() { - } - - public SonarConfig(Integer version, Date date) { - this.version = version; - this.date = date; - } - - public Integer getVersion() { - return version; - } - - public void setVersion(Integer version) { - this.version = version; - } - - public Date getDate() { - return date; - } - - public void setDate(Date date) { - this.date = date; - } - - public Collection<Metric> getMetrics() { - return metrics; - } - - public void setMetrics(Collection<Metric> metrics) { - this.metrics = metrics; - } - - public Collection<Property> getProperties() { - return properties; - } - - public void setProperties(Collection<Property> properties) { - this.properties = properties; - } - - public Collection<RulesProfile> getProfiles() { - return profiles; - } - - public void setProfiles(Collection<RulesProfile> profiles) { - this.profiles = profiles; - } - - public Collection<Rule> getRules() { - return rules; - } - - public void setRules(Collection<Rule> rules) { - this.rules = rules; - } - - @Override - public String toString() { - return new ToStringBuilder(this) - .append("version", version) - .append("date", date) - .append("metrics", metrics) - .append("properties", properties) - .append("profiles", profiles) - .toString(); - } - -} diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/package-info.java b/sonar-server/src/main/java/org/sonar/server/configuration/package-info.java deleted file mode 100644 index 190ea19dcec..00000000000 --- a/sonar-server/src/main/java/org/sonar/server/configuration/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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. - */ - -@ParametersAreNonnullByDefault -package org.sonar.server.configuration; - -import javax.annotation.ParametersAreNonnullByDefault; 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 4d9ac55497e..597ec30f409 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 @@ -97,6 +97,7 @@ import org.sonar.server.plugins.*; import org.sonar.server.qualityprofile.*; import org.sonar.server.rule.*; import org.sonar.server.rule.ws.*; +import org.sonar.server.source.CodeColorizers; import org.sonar.server.source.DeprecatedSourceDecorator; import org.sonar.server.source.HtmlSourceDecorator; import org.sonar.server.source.SourceService; diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfilesBackup.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfilesBackup.java index 7c1cf830170..feb12e107e8 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfilesBackup.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfilesBackup.java @@ -34,7 +34,6 @@ import org.sonar.api.profiles.RulesProfile; import org.sonar.api.rules.*; import org.sonar.core.preview.PreviewCache; import org.sonar.jpa.dao.RulesDao; -import org.sonar.server.configuration.SonarConfig; import java.util.*; @@ -52,7 +51,6 @@ public class ProfilesBackup { private static final String PARAMS = "params"; private static final String VALUE = "value"; - private Collection<RulesProfile> profiles; private DatabaseSession session; private PreviewCache dryRunCache; @@ -61,13 +59,6 @@ public class ProfilesBackup { this.dryRunCache = dryRunCache; } - /** - * for unit tests - */ - ProfilesBackup(Collection<RulesProfile> profiles) { - this.profiles = profiles; - } - public void configure(XStream xStream) { String defaultProfile = "defaultProfile"; @@ -85,31 +76,6 @@ public class ProfilesBackup { xStream.registerConverter(getAlertsConverter()); } - public void exportXml(SonarConfig sonarConfig) { - this.profiles = (this.profiles == null ? session.getResults(RulesProfile.class) : this.profiles); - // the profiles objects must be cloned to avoid issues CGLib - List<RulesProfile> cloned = new ArrayList<RulesProfile>(); - for (RulesProfile profile : this.profiles) { - cloned.add((RulesProfile) profile.clone()); - } - - sonarConfig.setProfiles(cloned); - } - - public void importXml(SonarConfig sonarConfig) { - if (sonarConfig.getProfiles() != null && !sonarConfig.getProfiles().isEmpty()) { - LoggerFactory.getLogger(getClass()).info("Delete profiles"); - ProfilesManager profilesManager = new ProfilesManager(session, dryRunCache); - profilesManager.deleteAllProfiles(); - - RulesDao rulesDao = new RulesDao(session); - for (RulesProfile profile : sonarConfig.getProfiles()) { - LoggerFactory.getLogger(getClass()).info("Restore profile " + profile.getName()); - importProfile(rulesDao, profile); - } - } - } - public void importProfile(RulesDao rulesDao, RulesProfile toImport) { if (toImport.getVersion() == 0) { // backward-compatibility with versions < 2.9. The field "version" did not exist. Default value is 1. diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfilesManager.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfilesManager.java index c1f636dc25a..dfbe2d124a9 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfilesManager.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfilesManager.java @@ -60,20 +60,6 @@ public class ProfilesManager extends BaseDao { return toImport.getId(); } - public void deleteAllProfiles() { - // Remove history of rule changes - String hqlDeleteRc = "DELETE " + ActiveRuleChange.class.getSimpleName() + " rc"; - getSession().createQuery(hqlDeleteRc).executeUpdate(); - - List profiles = getSession().createQuery("FROM " + RulesProfile.class.getSimpleName()).getResultList(); - for (Object profile : profiles) { - getSession().removeWithoutFlush(profile); - } - getSession().commit(); - dryRunCache.reportGlobalModification(); - } - - // Managing inheritance of profiles public RuleInheritanceActions profileParentChanged(Integer profileId, @Nullable String parentName, String userName) { @@ -201,32 +187,6 @@ public class ProfilesManager extends BaseDao { return actions; } - public void revert(int profileId, int activeRuleId, String userName) { - RulesProfile profile = getSession().getEntity(RulesProfile.class, profileId); - ActiveRule oldActiveRule = getSession().getEntity(ActiveRule.class, activeRuleId); - if (oldActiveRule != null && oldActiveRule.doesOverride()) { - ActiveRule parentActiveRule = getParentProfile(profile).getActiveRule(oldActiveRule.getRule()); - if (parentActiveRule != null) { - removeActiveRule(oldActiveRule); - ActiveRule newActiveRule = (ActiveRule) parentActiveRule.clone(); - newActiveRule.setRulesProfile(profile); - newActiveRule.setInheritance(ActiveRule.INHERITED); - profile.addActiveRule(newActiveRule); - getSession().saveWithoutFlush(newActiveRule); - - // Compute change - ruleChanged(profile, oldActiveRule, newActiveRule, userName); - - for (RulesProfile child : getChildren(profile)) { - activateOrChange(child, newActiveRule, userName); - } - - getSession().commit(); - dryRunCache.reportGlobalModification(); - } - } - } - private synchronized void incrementProfileVersionIfNeeded(RulesProfile profile) { if (profile.getUsed()) { profile.setVersion(profile.getVersion() + 1); diff --git a/sonar-server/src/main/java/org/sonar/server/ui/CodeColorizers.java b/sonar-server/src/main/java/org/sonar/server/source/CodeColorizers.java index e10c3374f21..e32bc81ddf2 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/CodeColorizers.java +++ b/sonar-server/src/main/java/org/sonar/server/source/CodeColorizers.java @@ -17,7 +17,7 @@ * 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.server.ui; +package org.sonar.server.source; import org.apache.commons.lang.StringUtils; import org.sonar.api.ServerExtension; @@ -33,22 +33,25 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +/** + * Central point for sonar-colorizer extensions + */ public class CodeColorizers implements ServerExtension { - private Map<String, CodeColorizerFormat> formatPerLanguage; + private final Map<String, CodeColorizerFormat> byLang; public CodeColorizers(List<CodeColorizerFormat> formats) { - formatPerLanguage = new HashMap<String, CodeColorizerFormat>(); + byLang = new HashMap<String, CodeColorizerFormat>(); for (CodeColorizerFormat format : formats) { - formatPerLanguage.put(format.getLanguageKey(), format); + byLang.put(format.getLanguageKey(), format); } - Logs.INFO.info("Code colorizer, supported languages: " + StringUtils.join(formatPerLanguage.keySet(), ",")); + Logs.INFO.info("Code colorizer, supported languages: " + StringUtils.join(byLang.keySet(), ",")); } public String toHtml(String code, String language) { + CodeColorizerFormat format = byLang.get(language); List<Tokenizer> tokenizers; - CodeColorizerFormat format = formatPerLanguage.get(language); if (format == null) { tokenizers = Collections.emptyList(); } else { diff --git a/sonar-server/src/main/java/org/sonar/server/source/DeprecatedSourceDecorator.java b/sonar-server/src/main/java/org/sonar/server/source/DeprecatedSourceDecorator.java index 3eac6043204..78dd20a3773 100644 --- a/sonar-server/src/main/java/org/sonar/server/source/DeprecatedSourceDecorator.java +++ b/sonar-server/src/main/java/org/sonar/server/source/DeprecatedSourceDecorator.java @@ -29,11 +29,9 @@ import org.sonar.core.resource.ResourceDto; import org.sonar.core.resource.ResourceQuery; import org.sonar.core.source.db.SnapshotSourceDao; import org.sonar.server.exceptions.NotFoundException; -import org.sonar.server.ui.CodeColorizers; import javax.annotation.CheckForNull; import javax.annotation.Nullable; - import java.util.List; import static com.google.common.collect.Lists.newArrayList; @@ -44,7 +42,6 @@ import static com.google.common.collect.Lists.newArrayList; public class DeprecatedSourceDecorator implements ServerComponent { private final MyBatis mybatis; - private final ResourceDao resourceDao; private final CodeColorizers codeColorizers; private final SnapshotSourceDao snapshotSourceDao; diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java index 0ac545ac080..af23cfd191a 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java @@ -31,7 +31,6 @@ import org.sonar.api.platform.PluginRepository; import org.sonar.api.resources.Language; import org.sonar.api.resources.ResourceType; import org.sonar.api.resources.ResourceTypes; -import org.sonar.api.rules.RulePriority; import org.sonar.api.test.MutableTestPlan; import org.sonar.api.test.MutableTestable; import org.sonar.api.test.TestPlan; @@ -46,7 +45,6 @@ import org.sonar.core.purge.PurgeDao; import org.sonar.core.resource.ResourceIndexerDao; import org.sonar.core.resource.ResourceKeyUpdaterDao; import org.sonar.core.timemachine.Periods; -import org.sonar.server.qualityprofile.ProfilesManager; import org.sonar.server.db.migrations.DatabaseMigrator; import org.sonar.server.platform.Platform; import org.sonar.server.platform.ServerIdGenerator; @@ -54,13 +52,13 @@ import org.sonar.server.platform.ServerSettings; import org.sonar.server.platform.SettingsChangeNotifier; import org.sonar.server.plugins.*; import org.sonar.server.rule.RuleRepositories; +import org.sonar.server.source.CodeColorizers; import org.sonar.server.user.NewUserNotifier; import org.sonar.updatecenter.common.PluginReferential; import org.sonar.updatecenter.common.UpdateCenter; import org.sonar.updatecenter.common.Version; import javax.annotation.Nullable; - import java.net.InetAddress; import java.sql.Connection; import java.util.Collection; @@ -246,43 +244,14 @@ public final class JRubyFacade { return get(RuleRepositories.class).repositories(); } - public RuleRepositories.Repository getRuleRepository(String repositoryKey) { - return get(RuleRepositories.class).repository(repositoryKey); - } - public Collection<RuleRepositories.Repository> getRuleRepositoriesByLanguage(String languageKey) { return get(RuleRepositories.class).repositoriesForLang(languageKey); } - public void ruleActivated(int parentProfileId, int activeRuleId, String userName) { - getProfilesManager().activated(parentProfileId, activeRuleId, userName); - } - - public void ruleParamChanged(int parentProfileId, int activeRuleId, String paramKey, String oldValue, String newValue, String userName) { - getProfilesManager().ruleParamChanged(parentProfileId, activeRuleId, paramKey, oldValue, newValue, userName); - } - - public void ruleSeverityChanged(int parentProfileId, int activeRuleId, int oldSeverityId, int newSeverityId, String userName) { - getProfilesManager().ruleSeverityChanged(parentProfileId, activeRuleId, RulePriority.values()[oldSeverityId], - RulePriority.values()[newSeverityId], userName); - } - - public void ruleDeactivated(int parentProfileId, int deactivatedRuleId, String userName) { - getProfilesManager().deactivated(parentProfileId, deactivatedRuleId, userName); - } - - public void revertRule(int profileId, int activeRuleId, String userName) { - getProfilesManager().revert(profileId, activeRuleId, userName); - } - public List<Footer> getWebFooters() { return getContainer().getComponentsByType(Footer.class); } - private ProfilesManager getProfilesManager() { - return get(ProfilesManager.class); - } - public void setGlobalProperty(String key, @Nullable String value) { get(ServerSettings.class).setProperty(key, value); get(SettingsChangeNotifier.class).onGlobalPropertyChange(key, value); diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ProfilesBackupTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ProfilesBackupTest.java deleted file mode 100644 index 102f58d6abc..00000000000 --- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ProfilesBackupTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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.server.qualityprofile; - -import org.junit.Before; -import org.junit.Test; -import org.sonar.api.profiles.RulesProfile; -import org.sonar.jpa.test.AbstractDbUnitTestCase; -import org.sonar.server.configuration.SonarConfig; -import org.sonar.server.qualityprofile.ProfilesBackup; - -import java.util.Arrays; - -import static org.fest.assertions.Assertions.assertThat; -import static org.hamcrest.collection.IsCollectionContaining.hasItem; -import static org.junit.Assert.assertThat; - -public class ProfilesBackupTest extends AbstractDbUnitTestCase { - - private SonarConfig sonarConfig; - - @Before - public void setup() { - sonarConfig = new SonarConfig(); - } - - @Test - public void shouldExportClonedProfiles() { - - RulesProfile profileProvided = new RulesProfile(); - profileProvided.setProvided(false); - profileProvided.setLanguage("test"); - profileProvided.setName("provided"); - - ProfilesBackup profilesBackup = new ProfilesBackup(Arrays.asList(profileProvided)); - profilesBackup.exportXml(sonarConfig); - - assertThat(sonarConfig.getProfiles().iterator().next()).isNotSameAs(profileProvided); - assertThat(sonarConfig.getProfiles().iterator().next().getName()).isEqualTo("provided"); - } - - @Test - public void shouldExportAllProfiles() { - - RulesProfile profileProvided = new RulesProfile(); - profileProvided.setProvided(true); - profileProvided.setLanguage("test"); - profileProvided.setName("provided"); - - RulesProfile profileNotProvided = new RulesProfile(); - profileNotProvided.setProvided(false); - profileNotProvided.setLanguage("test"); - profileNotProvided.setName("not provided"); - - ProfilesBackup profilesBackup = new ProfilesBackup(Arrays.asList(profileProvided, profileNotProvided)); - profilesBackup.exportXml(sonarConfig); - - assertThat(sonarConfig.getProfiles(), hasItem(profileNotProvided)); - assertThat(sonarConfig.getProfiles(), hasItem(profileProvided)); - } - - @Test - public void shouldImportProfiles() { - - } -} diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ProfilesManagerTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ProfilesManagerTest.java index f8d3adfa8bd..41a4f922086 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ProfilesManagerTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ProfilesManagerTest.java @@ -42,21 +42,6 @@ public class ProfilesManagerTest extends AbstractDbUnitTestCase { } @Test - public void delete_all_profiles() { - RulesProfile test1 = RulesProfile.create("test1", "java"); - test1.setDefaultProfile(true); - RulesProfile test2 = RulesProfile.create("test2", "java"); - - getSession().save(test1, test2); - - assertThat(getHQLCount(RulesProfile.class)).isEqualTo(2); - - manager.deleteAllProfiles(); - - assertThat(getHQLCount(RulesProfile.class)).isEqualTo(0); - } - - @Test public void remove_activated_rules() { Rule rule1 = Rule.create("repo", "key"); diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleChangeTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleChangeTest.java index 55a19b98a5a..6ab649e7ee7 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleChangeTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleChangeTest.java @@ -22,12 +22,10 @@ package org.sonar.server.qualityprofile; import org.junit.Before; import org.junit.Test; import org.sonar.api.rules.ActiveRuleChange; -import org.sonar.api.rules.ActiveRuleParamChange; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RulePriority; import org.sonar.core.preview.PreviewCache; import org.sonar.jpa.test.AbstractDbUnitTestCase; -import org.sonar.server.qualityprofile.ProfilesManager; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -58,21 +56,21 @@ public class RuleChangeTest extends AbstractDbUnitTestCase { public void should_track_rule_activation() { setupData("initialData"); profilesManager.activated(2, 3, "admin"); - checkTables("ruleActivated", new String[] {"change_date"}, "active_rule_changes"); + checkTables("ruleActivated", new String[]{"change_date"}, "active_rule_changes"); } @Test public void should_track_rule_deactivation() { setupData("initialData"); profilesManager.deactivated(2, 3, "admin"); - checkTables("ruleDeactivated", new String[] {"change_date"}, "active_rule_changes"); + checkTables("ruleDeactivated", new String[]{"change_date"}, "active_rule_changes"); } @Test public void should_track_rule_param_change() { setupData("initialData"); profilesManager.ruleParamChanged(2, 3, "param1", "20", "30", "admin"); - checkTables("ruleParamChanged", new String[] {"change_date"}, "active_rule_changes", "active_rule_param_changes"); + checkTables("ruleParamChanged", new String[]{"change_date"}, "active_rule_changes", "active_rule_param_changes"); } @Test @@ -86,7 +84,7 @@ public class RuleChangeTest extends AbstractDbUnitTestCase { public void should_track_rule_severity_change() { setupData("initialData"); profilesManager.ruleSeverityChanged(2, 3, RulePriority.BLOCKER, RulePriority.CRITICAL, "admin"); - checkTables("ruleSeverityChanged", new String[] {"change_date"}, "active_rule_changes"); + checkTables("ruleSeverityChanged", new String[]{"change_date"}, "active_rule_changes"); } @Test @@ -97,31 +95,10 @@ public class RuleChangeTest extends AbstractDbUnitTestCase { } @Test - public void should_track_rule_revert() { - setupData("ruleReverted"); - profilesManager.revert(2, 3, "admin"); - checkTables("ruleReverted", new String[] {"change_date"}, "active_rule_changes", "active_rule_param_changes"); - } - - @Test - public void should_not_track_param_change_on_rule_revert_if_no_param() { - setupData("should_not_track_param_change_on_rule_revert_if_no_param"); - profilesManager.revert(2, 3, "admin"); - assertThat(getHQLCount(ActiveRuleParamChange.class)).isEqualTo(0); - } - - @Test - public void should_not_track_param_change_on_rule_revert_if_no_change() { - setupData("should_not_track_param_change_on_rule_revert_if_no_param"); - profilesManager.revert(2, 3, "admin"); - assertThat(getHQLCount(ActiveRuleParamChange.class)).isEqualTo(0); - } - - @Test public void should_track_change_parent_profile() { setupData("changeParentProfile"); profilesManager.profileParentChanged(2, "parent", "admin"); - checkTables("changeParentProfile", new String[] {"change_date"}, "active_rule_changes"); + checkTables("changeParentProfile", new String[]{"change_date"}, "active_rule_changes"); } @Test @@ -129,7 +106,7 @@ public class RuleChangeTest extends AbstractDbUnitTestCase { setupData("initialData"); Rule rule = getSession().reattach(Rule.class, 1); profilesManager.removeActivatedRules(rule.getId()); - checkTables("removeActivatedRules", new String[] {"change_date"}, "active_rule_changes", "active_rules"); + checkTables("removeActivatedRules", new String[]{"change_date"}, "active_rule_changes", "active_rules"); } } diff --git a/sonar-server/src/test/java/org/sonar/server/source/CodeColorizersTest.java b/sonar-server/src/test/java/org/sonar/server/source/CodeColorizersTest.java new file mode 100644 index 00000000000..6cb20900593 --- /dev/null +++ b/sonar-server/src/test/java/org/sonar/server/source/CodeColorizersTest.java @@ -0,0 +1,64 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.server.source; + +import org.junit.Test; +import org.sonar.api.web.CodeColorizerFormat; +import org.sonar.colorizer.LiteralTokenizer; +import org.sonar.colorizer.Tokenizer; + +import java.util.Arrays; +import java.util.List; + +import static org.fest.assertions.Assertions.assertThat; + +public class CodeColorizersTest { + @Test + public void colorize_source_code() throws Exception { + CodeColorizerFormat format = new LiteralFormat("java"); + CodeColorizers colorizers = new CodeColorizers(Arrays.asList(format)); + + String html = colorizers.toHtml("String s = \"foo\";", "java"); + assertThat(html).isEqualTo("String s = <span class=\"s\">\"foo\"</span>;"); + } + + @Test + public void do_not_fail_if_unsupported_language() throws Exception { + CodeColorizerFormat format = new LiteralFormat("java"); + CodeColorizers colorizers = new CodeColorizers(Arrays.asList(format)); + + String html = colorizers.toHtml("String s = \"foo\";", "groovy"); + assertThat(html).isEqualTo("String s = \"foo\";"); + } + + /** + * Highlights only litterals + */ + static class LiteralFormat extends CodeColorizerFormat { + LiteralFormat(String languageKey) { + super(languageKey); + } + + @Override + public List<Tokenizer> getTokenizers() { + return Arrays.<Tokenizer>asList(new LiteralTokenizer("<span class=\"s\">", "</span>")); + } + } +} diff --git a/sonar-server/src/test/java/org/sonar/server/source/DeprecatedSourceDecoratorTest.java b/sonar-server/src/test/java/org/sonar/server/source/DeprecatedSourceDecoratorTest.java index d08f48393ee..9811614e280 100644 --- a/sonar-server/src/test/java/org/sonar/server/source/DeprecatedSourceDecoratorTest.java +++ b/sonar-server/src/test/java/org/sonar/server/source/DeprecatedSourceDecoratorTest.java @@ -32,7 +32,6 @@ import org.sonar.core.resource.ResourceDto; import org.sonar.core.resource.ResourceQuery; import org.sonar.core.source.db.SnapshotSourceDao; import org.sonar.server.exceptions.NotFoundException; -import org.sonar.server.ui.CodeColorizers; import java.util.List; diff --git a/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ProfilesBackupTest/shouldSupportEnabledField.xml b/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ProfilesBackupTest/shouldSupportEnabledField.xml deleted file mode 100644 index cbd461b32e2..00000000000 --- a/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ProfilesBackupTest/shouldSupportEnabledField.xml +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<sonar-config> - <version><![CDATA[59]]></version> - <date><![CDATA[2009-02-19]]></date> - <metrics/> - <profiles> - <profile> - <name><![CDATA[Disabled]]></name> - <default-profile><![CDATA[false]]></default-profile> - <provided><![CDATA[false]]></provided> - <language><![CDATA[java]]></language> - <enabled><![CDATA[false]]></enabled> - <active-rules> - </active-rules> - <alerts/> - </profile> - <profile> - <name><![CDATA[Enabled]]></name> - <default-profile><![CDATA[false]]></default-profile> - <provided><![CDATA[false]]></provided> - <language><![CDATA[java]]></language> - <enabled><![CDATA[true]]></enabled> - <active-rules> - </active-rules> - <alerts/> - </profile> - </profiles> -</sonar-config> diff --git a/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ProfilesBackupTest/shouldSupportMissingEnabledField.xml b/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ProfilesBackupTest/shouldSupportMissingEnabledField.xml deleted file mode 100644 index 4ba3d1f7053..00000000000 --- a/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ProfilesBackupTest/shouldSupportMissingEnabledField.xml +++ /dev/null @@ -1,17 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<sonar-config> - <version><![CDATA[59]]></version> - <date><![CDATA[2009-02-19]]></date> - <metrics/> - <profiles> - <profile> - <name><![CDATA[Missing enabled field]]></name> - <default-profile><![CDATA[false]]></default-profile> - <provided><![CDATA[false]]></provided> - <language><![CDATA[java]]></language> - <active-rules> - </active-rules> - <alerts/> - </profile> - </profiles> -</sonar-config> |