From: Julien HENRY Date: Tue, 16 Jul 2013 13:05:53 +0000 (+0200) Subject: SONAR-4501 Make properties (sub)categories case insensitives X-Git-Tag: 3.7~98 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3c972b4cb543743a3bc5e2bd3c7d1b581e66dd32;p=sonarqube.git SONAR-4501 Make properties (sub)categories case insensitives --- diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index 8badcd35be4..729b49aced0 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -1551,9 +1551,9 @@ email_configuration.test.email_was_sent_to_x=Email was sent to {0} # LICENSES & SERVER KEY CONFIGURATION # #------------------------------------------------------------------------------ -property.category.Licenses=Licenses -property.category.Licenses.description=In case of any issue or question about licenses, please send an email to contact@sonarsource.com. -property.category.Licenses.server_id=Server ID +property.category.licenses=Licenses +property.category.licenses.description=In case of any issue or question about licenses, please send an email to contact@sonarsource.com. +property.category.licenses.server_id=Server ID server_id_configuration.generate_button=Generate ID server_id_configuration.generating_button=Generating ID... server_id_configuration.bad_key=The ID is not valid anymore. Please check the organisation and the IP address. diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java index 084cabc0d63..027b5d9a4e8 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java @@ -72,6 +72,11 @@ public interface CoreProperties { */ String CATEGORY_EXCLUSIONS = "exclusions"; + /** + * @since 3.7 + */ + String CATEGORY_LICENSES = "licenses"; + /* Global settings */ String SONAR_HOME = "SONAR_HOME"; String PROJECT_BRANCH_PROPERTY = "sonar.branch"; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/Category.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/Category.java new file mode 100644 index 00000000000..ddb8ff34367 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/Category.java @@ -0,0 +1,73 @@ +/* + * 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.api.config; + +import org.apache.commons.lang.StringUtils; + +import java.util.Locale; + +/** + * @since 3.7 + */ +public class Category { + + private final String originalKey; + private final boolean special; + + public Category(String originalKey) { + this(originalKey, false); + } + + Category(String originalKey, boolean special) { + this.originalKey = originalKey; + this.special = special; + } + + public String originalKey() { + return originalKey; + } + + public String key() { + return StringUtils.lowerCase(originalKey, Locale.ENGLISH); + } + + public boolean isSpecial() { + return special; + } + + @Override + public int hashCode() { + return key().hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Category)) { + return false; + } + return StringUtils.equalsIgnoreCase(((Category) obj).originalKey, this.originalKey); + } + + @Override + public String toString() { + return this.originalKey; + } + +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java index b729e1064af..94edae487ff 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java @@ -23,6 +23,7 @@ import com.google.common.base.Strings; import com.google.common.collect.Maps; import org.apache.commons.lang.StringUtils; import org.sonar.api.BatchComponent; +import org.sonar.api.CoreProperties; import org.sonar.api.Properties; import org.sonar.api.Property; import org.sonar.api.ServerComponent; @@ -44,8 +45,8 @@ import java.util.Map; public final class PropertyDefinitions implements BatchComponent, ServerComponent { private final Map definitions = Maps.newHashMap(); - private final Map categories = Maps.newHashMap(); - private final Map subcategories = Maps.newHashMap(); + private final Map categories = Maps.newHashMap(); + private final Map subcategories = Maps.newHashMap(); // deprecated key -> new key private final Map deprecatedKeys = Maps.newHashMap(); @@ -107,8 +108,9 @@ public final class PropertyDefinitions implements BatchComponent, ServerComponen if (!definitions.containsKey(definition.key())) { definitions.put(definition.key(), definition); String category = StringUtils.defaultIfBlank(definition.category(), defaultCategory); - categories.put(definition.key(), category); - subcategories.put(definition.key(), StringUtils.defaultIfBlank(definition.subCategory(), category)); + categories.put(definition.key(), new Category(category)); + String subcategory = StringUtils.defaultIfBlank(definition.subCategory(), category); + subcategories.put(definition.key(), new SubCategory(subcategory)); if (!Strings.isNullOrEmpty(definition.deprecatedKey()) && !definition.deprecatedKey().equals(definition.key())) { deprecatedKeys.put(definition.deprecatedKey(), definition.key()); } @@ -130,7 +132,9 @@ public final class PropertyDefinitions implements BatchComponent, ServerComponen /** * @since 3.6 + * @deprecated since 3.7 use {@link #propertiesByCategory(String)} */ + @Deprecated public Map>> getPropertiesByCategory(@Nullable String qualifier) { Map>> byCategory = new HashMap>>(); @@ -151,10 +155,45 @@ public final class PropertyDefinitions implements BatchComponent, ServerComponen return byCategory; } + /** + * @since 3.6 + * @deprecated since 3.7 use {@link #propertiesByCategory(String)} + */ + @Deprecated public Map>> getPropertiesByCategory() { return getPropertiesByCategory(null); } + /** + * @since 3.7 + */ + public Map>> propertiesByCategory(@Nullable String qualifier) { + Map>> byCategory = new HashMap>>(); + if (qualifier == null) { + // Special categories on global page + byCategory.put(new Category("email", true), new HashMap>()); + byCategory.put(new Category("encryption", true), new HashMap>()); + HashMap> licenseSubCategories = new HashMap>(); + licenseSubCategories.put(new SubCategory("server_id", true), new ArrayList()); + byCategory.put(new Category(CoreProperties.CATEGORY_LICENSES, false), licenseSubCategories); + } + for (PropertyDefinition definition : getAll()) { + if (qualifier == null ? definition.global() : definition.qualifiers().contains(qualifier)) { + Category category = categories.get(definition.key()); + if (!byCategory.containsKey(category)) { + byCategory.put(category, new HashMap>()); + } + SubCategory subCategory = subcategories.get(definition.key()); + if (!byCategory.get(category).containsKey(subCategory)) { + byCategory.get(category).put(subCategory, new ArrayList()); + } + byCategory.get(category).get(subCategory).add(definition); + } + } + + return byCategory; + } + public String getDefaultValue(String key) { PropertyDefinition def = get(key); if (def == null) { @@ -164,11 +203,11 @@ public final class PropertyDefinitions implements BatchComponent, ServerComponen } public String getCategory(String key) { - return categories.get(validKey(key)); + return categories.get(validKey(key)).toString(); } public String getSubCategory(String key) { - return subcategories.get(validKey(key)); + return subcategories.get(validKey(key)).toString(); } public String getCategory(Property prop) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/SubCategory.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/SubCategory.java new file mode 100644 index 00000000000..cd90b20e2f0 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/SubCategory.java @@ -0,0 +1,35 @@ +/* + * 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.api.config; + +/** + * @since 3.7 + */ +public class SubCategory extends Category { + + public SubCategory(String originalKey) { + super(originalKey); + } + + SubCategory(String originalKey, boolean special) { + super(originalKey, special); + } + +} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/CategoryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/CategoryTest.java new file mode 100644 index 00000000000..e8ee207892f --- /dev/null +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/CategoryTest.java @@ -0,0 +1,37 @@ +/* + * 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.api.config; + +import org.junit.Test; + +import static org.fest.assertions.Assertions.assertThat; + +public class CategoryTest { + + @Test + public void category_key_is_case_insentive() { + assertThat(new Category("Licenses")).isEqualTo(new Category("licenses")); + } + + @Test + public void should_preserve_original_key() { + assertThat(new Category("Licenses").originalKey()).isEqualTo("Licenses"); + } +} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionsTest.java index ed794b4dc8c..9bc2eace66b 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionsTest.java @@ -34,10 +34,10 @@ public class PropertyDefinitionsTest { @Test public void should_build_with_predefined_list_of_definitions() { List list = Arrays.asList( - PropertyDefinition.builder("foo").name("Foo").build(), - PropertyDefinition.builder("one").name("One").build(), - PropertyDefinition.builder("two").name("Two").defaultValue("2").build() - ); + PropertyDefinition.builder("foo").name("Foo").build(), + PropertyDefinition.builder("one").name("One").build(), + PropertyDefinition.builder("two").name("Two").defaultValue("2").build() + ); PropertyDefinitions def = new PropertyDefinitions(list); assertProperties(def); @@ -46,9 +46,9 @@ public class PropertyDefinitionsTest { @Test public void should_inspect_plugin_objects() { PropertyDefinitions def = new PropertyDefinitions( - PropertyDefinition.builder("foo").name("Foo").build(), - PropertyDefinition.builder("one").name("One").build(), - PropertyDefinition.builder("two").name("Two").defaultValue("2").build() + PropertyDefinition.builder("foo").name("Foo").build(), + PropertyDefinition.builder("one").name("One").build(), + PropertyDefinition.builder("two").name("Two").defaultValue("2").build() ); assertProperties(def); @@ -71,8 +71,8 @@ public class PropertyDefinitionsTest { @Test public void test_categories() { PropertyDefinitions def = new PropertyDefinitions( - PropertyDefinition.builder("inCateg").name("In Categ").category("categ").build(), - PropertyDefinition.builder("noCateg").name("No categ").build() + PropertyDefinition.builder("inCateg").name("In Categ").category("categ").build(), + PropertyDefinition.builder("noCateg").name("No categ").build() ); assertThat(def.getCategory("inCateg")).isEqualTo("categ"); @@ -105,15 +105,25 @@ public class PropertyDefinitionsTest { assertThat(def.getCategory("noCateg")).isEqualTo("default"); } + @Test + public void should_return_special_categories() { + PropertyDefinitions def = new PropertyDefinitions(); + + assertThat(def.propertiesByCategory(null).keySet()).containsOnly(new Category("encryption"), new Category("email"), new Category("licenses")); + assertThat(def.propertiesByCategory(null).keySet().iterator().next().isSpecial()).isTrue(); + assertThat(def.propertiesByCategory(null).get(new Category("licenses")).keySet()).containsOnly(new SubCategory("server_id")); + assertThat(def.propertiesByCategory(null).get(new Category("licenses")).keySet().iterator().next().isSpecial()).isTrue(); + } + @Test public void should_group_by_category() { PropertyDefinitions def = new PropertyDefinitions( - PropertyDefinition.builder("global1").name("Global1").category("catGlobal1").build(), - PropertyDefinition.builder("global2").name("Global2").category("catGlobal1").build(), - PropertyDefinition.builder("global3").name("Global3").category("catGlobal2").build(), - PropertyDefinition.builder("project").name("Project").category("catProject").onlyOnQualifiers(Qualifiers.PROJECT).build(), - PropertyDefinition.builder("module").name("Module").category("catModule").onlyOnQualifiers(Qualifiers.MODULE).build(), - PropertyDefinition.builder("view").name("View").category("catView").onlyOnQualifiers(Qualifiers.VIEW).build() + PropertyDefinition.builder("global1").name("Global1").category("catGlobal1").build(), + PropertyDefinition.builder("global2").name("Global2").category("catGlobal1").build(), + PropertyDefinition.builder("global3").name("Global3").category("catGlobal2").build(), + PropertyDefinition.builder("project").name("Project").category("catProject").onlyOnQualifiers(Qualifiers.PROJECT).build(), + PropertyDefinition.builder("module").name("Module").category("catModule").onlyOnQualifiers(Qualifiers.MODULE).build(), + PropertyDefinition.builder("view").name("View").category("catView").onlyOnQualifiers(Qualifiers.VIEW).build() ); assertThat(def.getPropertiesByCategory(null).keySet()).containsOnly("catGlobal1", "catGlobal2"); @@ -121,19 +131,30 @@ public class PropertyDefinitionsTest { assertThat(def.getPropertiesByCategory(Qualifiers.MODULE).keySet()).containsOnly("catModule"); assertThat(def.getPropertiesByCategory(Qualifiers.VIEW).keySet()).containsOnly("catView"); assertThat(def.getPropertiesByCategory("Unkown").keySet()).isEmpty(); + + assertThat(def.propertiesByCategory(null).keySet()).containsOnly(new Category("encryption"), new Category("email"), new Category("licenses"), new Category("catGlobal1"), + new Category("catGlobal2")); + assertThat(def.propertiesByCategory(Qualifiers.PROJECT).keySet()).containsOnly(new Category("catProject")); + assertThat(def.propertiesByCategory(Qualifiers.MODULE).keySet()).containsOnly(new Category("catModule")); + assertThat(def.propertiesByCategory(Qualifiers.VIEW).keySet()).containsOnly(new Category("catView")); + assertThat(def.propertiesByCategory("Unkown").keySet()).isEmpty(); } @Test public void should_group_by_subcategory() { PropertyDefinitions def = new PropertyDefinitions( - PropertyDefinition.builder("global1").name("Global1").category("catGlobal1").subCategory("sub1").build(), - PropertyDefinition.builder("global2").name("Global2").category("catGlobal1").subCategory("sub2").build(), - PropertyDefinition.builder("global3").name("Global3").category("catGlobal1").build(), - PropertyDefinition.builder("global4").name("Global4").category("catGlobal2").build() + PropertyDefinition.builder("global1").name("Global1").category("catGlobal1").subCategory("sub1").build(), + PropertyDefinition.builder("global2").name("Global2").category("catGlobal1").subCategory("sub2").build(), + PropertyDefinition.builder("global3").name("Global3").category("catGlobal1").build(), + PropertyDefinition.builder("global4").name("Global4").category("catGlobal2").build() ); assertThat(def.getPropertiesByCategory(null).get("catGlobal1").keySet()).containsOnly("catGlobal1", "sub1", "sub2"); assertThat(def.getPropertiesByCategory(null).get("catGlobal2").keySet()).containsOnly("catGlobal2"); + + assertThat(def.propertiesByCategory(null).get(new Category("catGlobal1")).keySet()).containsOnly(new SubCategory("catGlobal1"), new SubCategory("sub1"), + new SubCategory("sub2")); + assertThat(def.propertiesByCategory(null).get(new Category("catGlobal2")).keySet()).containsOnly(new SubCategory("catGlobal2")); } @Test @@ -143,6 +164,11 @@ public class PropertyDefinitionsTest { assertThat(def.getPropertiesByCategory().keySet()).containsOnly("catGlobal1", "catGlobal2"); assertThat(def.getPropertiesByCategory(Qualifiers.PROJECT).keySet()).containsOnly("catProject"); assertThat(def.getPropertiesByCategory(Qualifiers.MODULE).keySet()).containsOnly("catModule"); + + assertThat(def.propertiesByCategory(null).keySet()).containsOnly(new Category("encryption"), new Category("email"), new Category("licenses"), new Category("catglobal1"), + new Category("catglobal2")); + assertThat(def.propertiesByCategory(Qualifiers.PROJECT).keySet()).containsOnly(new Category("catproject")); + assertThat(def.propertiesByCategory(Qualifiers.MODULE).keySet()).containsOnly(new Category("catmodule")); } private void assertProperties(PropertyDefinitions definitions) { diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb index cc099e2d303..13032ed779a 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb @@ -258,11 +258,51 @@ class ApplicationController < ActionController::Base end def category_name(category) - message("property.category.#{category}", :default => category) + # Try with lowercase key then with original key for backward compatibility + message("property.category.#{category.key}", :default => message("property.category.#{category.originalKey}", :default => category.originalKey)) end def subcategory_name(category, subcategory) - message("property.category.#{category}.#{subcategory}", :default => subcategory) + if (category.key == subcategory.key) + # If subcategory == category then it is the default one + category_name(category) + else + # Try with lowercase key then with original key for backward compatibility + message("property.category.#{category.key}.#{subcategory.key}", + :default => message("property.category.#{category.originalKey}.#{subcategory.originalKey}", :default => subcategory.originalKey)) + end + end + + def processProperties(definitions_per_category) + @categories = by_category_name(definitions_per_category.keys) + + default_category = @categories.empty? ? nil : @categories[0] + + if params[:category].nil? + default_category = @categories.empty? ? nil : @categories[0] + @category = default_category + else + @category = @categories.select {|c| c == Java::OrgSonarApiConfig::Category.new(params[:category])}.first + not_found('category') if @category.nil? + end + + unless @category.isSpecial then + @subcategories_per_categories = {} + definitions_per_category.each {|category, definitions_per_subcategories| @subcategories_per_categories.store(category, by_subcategory_name(category, definitions_per_subcategories.keys)) } + + if params[:subcategory].nil? + default_subcategory = + @subcategories_per_categories[@category].nil? ? nil : + ((@subcategories_per_categories[@category].include? @category) ? @category : @subcategories_per_categories[@category][0]) + @subcategory = default_subcategory + else + @subcategory = @subcategories_per_categories[@category].select {|s| s == Java::OrgSonarApiConfig::SubCategory.new(params[:subcategory])}.first + not_found('subcategory') if @subcategory.nil? + end + + @definitions = definitions_per_category[@category] || {} + @definitions = @definitions[@subcategory] || [] + end end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb index e7fef2f9573..ed99ec19552 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb @@ -239,30 +239,12 @@ class ProjectController < ApplicationController @resource = get_current_project(params[:id]) @snapshot = @resource.last_snapshot - if @resource && !java_facade.getResourceTypeBooleanProperty(@resource.qualifier, 'configurable') + if !java_facade.getResourceTypeBooleanProperty(@resource.qualifier, 'configurable') redirect_to :action => 'index', :id => params[:id] end - definitions_per_category = java_facade.propertyDefinitions.getPropertiesByCategory(@resource ? @resource.qualifier : nil) - @categories = definitions_per_category.keys || [] - @categories = by_category_name(@categories) - - default_category = nil - default_category = @categories[0] if !@categories.empty? - @category = params[:category] || default_category - - not_found('category') unless @categories.include? @category - - @subcategories_per_categories = {} - definitions_per_category.each {|category, definitions_per_subcategories| @subcategories_per_categories.store(category, by_subcategory_name(category, definitions_per_subcategories.keys)) } - - default_subcategory = - @subcategories_per_categories[@category].nil? ? nil : - ((@subcategories_per_categories[@category].include? @category) ? @category : @subcategories_per_categories[@category][0]) - @subcategory = params[:subcategory] || default_subcategory - - @definitions = definitions_per_category[@category] || {} - @definitions = @definitions[@subcategory] || [] + definitions_per_category = java_facade.propertyDefinitions.propertiesByCategory(@resource.qualifier) + processProperties(definitions_per_category) end def update_version diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb index ed05613c90d..a1c8b353fab 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb @@ -21,11 +21,6 @@ class SettingsController < ApplicationController SECTION=Navigation::SECTION_CONFIGURATION - LICENSES_CATEGORY='Licenses' - SERVER_ID_SUBCATEGORY='server_id' - SPECIAL_CATEGORIES=%w(email encryption) + [LICENSES_CATEGORY] - - verify :method => :post, :only => %w(update), :redirect_to => {:action => :index} before_filter :admin_required, :only => %w(index) @@ -103,30 +98,8 @@ class SettingsController < ApplicationController end def load_properties - definitions_per_category = java_facade.propertyDefinitions.getPropertiesByCategory(@resource ? @resource.qualifier : nil) - @categories = definitions_per_category.keys + SPECIAL_CATEGORIES - @categories = by_category_name(@categories.uniq) - - default_category = @categories.empty? ? nil : @categories[0] - @category = params[:category] || default_category - - not_found('category') unless @categories.include? @category - - @subcategories_per_categories = {} - definitions_per_category.each {|category, definitions_per_subcategories| @subcategories_per_categories.store(category, by_subcategory_name(category, definitions_per_subcategories.keys)) } - - if (@subcategories_per_categories[LICENSES_CATEGORY].nil?) - @subcategories_per_categories.store(LICENSES_CATEGORY, [SERVER_ID_SUBCATEGORY]) - else - @subcategories_per_categories[LICENSES_CATEGORY].push(SERVER_ID_SUBCATEGORY) - end - - default_subcategory = - @subcategories_per_categories[@category].nil? ? nil : - ((@subcategories_per_categories[@category].include? @category) ? @category : @subcategories_per_categories[@category][0]) - @subcategory = params[:subcategory] || default_subcategory - - @definitions = definitions_per_category[@category] || {} - @definitions = @definitions[@subcategory] || [] + definitions_per_category = java_facade.propertyDefinitions.propertiesByCategory(nil) + processProperties(definitions_per_category) end + end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb index 5361d4b3f9a..ced1751e0a1 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb @@ -21,15 +21,18 @@ module SettingsHelper include PropertiesHelper def category_name(category) - message("property.category.#{category}", :default => category) + # Try with lowercase key then with original key for backward compatibility + message("property.category.#{category.key}", :default => message("property.category.#{category.originalKey}", :default => category.originalKey)) end def subcategory_name(category, subcategory) - if (category == subcategory) + if (category.key == subcategory.key) # If subcategory == category then it is the default one category_name(category) else - message("property.category.#{category}.#{subcategory}", :default => subcategory) + # Try with lowercase key then with original key for backward compatibility + message("property.category.#{category.key}.#{subcategory.key}", + :default => message("property.category.#{category.originalKey}.#{subcategory.originalKey}", :default => subcategory.originalKey)) end end @@ -62,11 +65,11 @@ module SettingsHelper end def category_desc(category) - message("property.category.#{category}.description", :default => '') + message("property.category.#{category.key}.description", :default => '') end def subcategory_desc(category, subcategory) - message("property.category.#{category}.#{subcategory}.description", :default => '') + message("property.category.#{category.key}.#{subcategory.key}.description", :default => '') end def property_value(property) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb index 6687598bd4f..ce676b40dd5 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb @@ -1,7 +1,7 @@ -<% if SettingsController::SPECIAL_CATEGORIES.include?(@category) && @category != SettingsController::LICENSES_CATEGORY -%> - <%= render 'special', :url => url_for(:controller => "#{@category}_configuration") -%> +<% if @category.isSpecial -%> + <%= render 'special', :url => url_for(:controller => "#{@category.key}_configuration") -%> <% else -%> - <% form_remote_tag :url => {:controller => 'settings', :action => 'update', :category => @category, :subcategory => @subcategory, :resource_id => @resource ? @resource.id : nil}, + <% form_remote_tag :url => {:controller => 'settings', :action => 'update', :category => @category.key, :subcategory => @subcategory.key, :resource_id => @resource ? @resource.id : nil}, :method => :post, :before => "$('submit_settings').hide();$('loading_settings').show();", :update => 'properties', @@ -10,21 +10,21 @@
    <% subcategories.each do |subcategory| -%>
  • - <%= link_to subcategory_name(@category, subcategory), {:controller => @resource ? 'project' : 'settings', :action => @resource ? 'settings' : 'index', :category => @category, :subcategory => subcategory, :id => @resource ? @resource.id : nil}, :class => @subcategory==subcategory ? 'selected' : nil -%> + <%= link_to subcategory_name(@category, subcategory), {:controller => @resource ? 'project' : 'settings', :action => @resource ? 'settings' : 'index', :category => @category.key, :subcategory => subcategory.key, :id => @resource ? @resource.id : nil}, :class => @subcategory==subcategory ? 'selected' : nil -%>
  • <% end -%>
- <% if @category == SettingsController::LICENSES_CATEGORY && @subcategory == SettingsController::SERVER_ID_SUBCATEGORY %> - <%= render 'special', :url => url_for(:controller => "#{SettingsController::SERVER_ID_SUBCATEGORY}_configuration") -%> + <% if @subcategory.isSpecial %> + <%= render 'special', :url => url_for(:controller => "#{@subcategory.key}_configuration") -%> <% else %> - <% if @subcategory == @category && !category_desc(@category).blank? -%> + <% if @subcategory.key == @category.key && !category_desc(@category).blank? -%> <% end -%> - <% if @subcategory != @category && !subcategory_desc(@category, @subcategory).blank? -%> + <% if @subcategory.key != @category.key && !subcategory_desc(@category, @subcategory).blank? -%> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_settings.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_settings.html.erb index 99e1dc041a5..323ea8e0e05 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_settings.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_settings.html.erb @@ -12,8 +12,8 @@ <% @categories.each do |category| -%> - - + + <% end -%>
<%= category_desc(@category) -%>
<%= subcategory_desc(@category, @subcategory) -%>
<%= link_to category_name(category), :category => category -%>
<%= link_to category_name(category), :category => category.key -%>