From fdc48661ae475a51fed88f53e2c744629e07d08b Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Sat, 1 Feb 2014 17:49:16 +0100 Subject: Remove dead code --- .../sonar/server/configuration/SonarConfig.java | 114 --------------------- .../sonar/server/configuration/package-info.java | 24 ----- .../java/org/sonar/server/platform/Platform.java | 1 + .../server/qualityprofile/ProfilesBackup.java | 34 ------ .../server/qualityprofile/ProfilesManager.java | 40 -------- .../org/sonar/server/source/CodeColorizers.java | 62 +++++++++++ .../server/source/DeprecatedSourceDecorator.java | 3 - .../java/org/sonar/server/ui/CodeColorizers.java | 59 ----------- .../main/java/org/sonar/server/ui/JRubyFacade.java | 33 +----- .../server/qualityprofile/ProfilesBackupTest.java | 83 --------------- .../server/qualityprofile/ProfilesManagerTest.java | 15 --- .../server/qualityprofile/RuleChangeTest.java | 35 ++----- .../sonar/server/source/CodeColorizersTest.java | 64 ++++++++++++ .../source/DeprecatedSourceDecoratorTest.java | 1 - .../shouldSupportEnabledField.xml | 28 ----- .../shouldSupportMissingEnabledField.xml | 17 --- 16 files changed, 134 insertions(+), 479 deletions(-) delete mode 100644 sonar-server/src/main/java/org/sonar/server/configuration/SonarConfig.java delete mode 100644 sonar-server/src/main/java/org/sonar/server/configuration/package-info.java create mode 100644 sonar-server/src/main/java/org/sonar/server/source/CodeColorizers.java delete mode 100644 sonar-server/src/main/java/org/sonar/server/ui/CodeColorizers.java delete mode 100644 sonar-server/src/test/java/org/sonar/server/qualityprofile/ProfilesBackupTest.java create mode 100644 sonar-server/src/test/java/org/sonar/server/source/CodeColorizersTest.java delete mode 100644 sonar-server/src/test/resources/org/sonar/server/qualityprofile/ProfilesBackupTest/shouldSupportEnabledField.xml delete mode 100644 sonar-server/src/test/resources/org/sonar/server/qualityprofile/ProfilesBackupTest/shouldSupportMissingEnabledField.xml (limited to 'sonar-server') 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 metrics; - - private Collection properties; - - private Collection profiles; - - private Collection 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 getMetrics() { - return metrics; - } - - public void setMetrics(Collection metrics) { - this.metrics = metrics; - } - - public Collection getProperties() { - return properties; - } - - public void setProperties(Collection properties) { - this.properties = properties; - } - - public Collection getProfiles() { - return profiles; - } - - public void setProfiles(Collection profiles) { - this.profiles = profiles; - } - - public Collection getRules() { - return rules; - } - - public void setRules(Collection 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 profiles; private DatabaseSession session; private PreviewCache dryRunCache; @@ -61,13 +59,6 @@ public class ProfilesBackup { this.dryRunCache = dryRunCache; } - /** - * for unit tests - */ - ProfilesBackup(Collection 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 cloned = new ArrayList(); - 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/source/CodeColorizers.java b/sonar-server/src/main/java/org/sonar/server/source/CodeColorizers.java new file mode 100644 index 00000000000..e32bc81ddf2 --- /dev/null +++ b/sonar-server/src/main/java/org/sonar/server/source/CodeColorizers.java @@ -0,0 +1,62 @@ +/* + * 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.apache.commons.lang.StringUtils; +import org.sonar.api.ServerExtension; +import org.sonar.api.utils.Logs; +import org.sonar.api.web.CodeColorizerFormat; +import org.sonar.colorizer.CodeColorizer; +import org.sonar.colorizer.HtmlOptions; +import org.sonar.colorizer.Tokenizer; + +import java.io.StringReader; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Central point for sonar-colorizer extensions + */ +public class CodeColorizers implements ServerExtension { + + private final Map byLang; + + public CodeColorizers(List formats) { + byLang = new HashMap(); + for (CodeColorizerFormat format : formats) { + byLang.put(format.getLanguageKey(), format); + } + + Logs.INFO.info("Code colorizer, supported languages: " + StringUtils.join(byLang.keySet(), ",")); + } + + public String toHtml(String code, String language) { + CodeColorizerFormat format = byLang.get(language); + List tokenizers; + if (format == null) { + tokenizers = Collections.emptyList(); + } else { + tokenizers = format.getTokenizers(); + } + return new CodeColorizer(tokenizers).toHtml(new StringReader(code), HtmlOptions.ONLY_SYNTAX); + } +} 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/CodeColorizers.java b/sonar-server/src/main/java/org/sonar/server/ui/CodeColorizers.java deleted file mode 100644 index e10c3374f21..00000000000 --- a/sonar-server/src/main/java/org/sonar/server/ui/CodeColorizers.java +++ /dev/null @@ -1,59 +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.ui; - -import org.apache.commons.lang.StringUtils; -import org.sonar.api.ServerExtension; -import org.sonar.api.utils.Logs; -import org.sonar.api.web.CodeColorizerFormat; -import org.sonar.colorizer.CodeColorizer; -import org.sonar.colorizer.HtmlOptions; -import org.sonar.colorizer.Tokenizer; - -import java.io.StringReader; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class CodeColorizers implements ServerExtension { - - private Map formatPerLanguage; - - public CodeColorizers(List formats) { - formatPerLanguage = new HashMap(); - for (CodeColorizerFormat format : formats) { - formatPerLanguage.put(format.getLanguageKey(), format); - } - - Logs.INFO.info("Code colorizer, supported languages: " + StringUtils.join(formatPerLanguage.keySet(), ",")); - } - - public String toHtml(String code, String language) { - List tokenizers; - CodeColorizerFormat format = formatPerLanguage.get(language); - if (format == null) { - tokenizers = Collections.emptyList(); - } else { - tokenizers = format.getTokenizers(); - } - return new CodeColorizer(tokenizers).toHtml(new StringReader(code), HtmlOptions.ONLY_SYNTAX); - } -} 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 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