if params[:category].nil?
# Select the 'general' category by default. If 'general' category is not found, then return the first one.
- default_category = @categories.empty? ? nil : (@categories.find {|c| c == Java::OrgSonarApiConfigInternal::Category.new('general')} || @categories[0])
+ default_category = @categories.empty? ? nil : (@categories.find {|c| c && c.key == 'general'} || @categories[0])
@category = default_category
else
- @category = @categories.find {|c| c == Java::OrgSonarApiConfigInternal::Category.new(params[:category])}
+ @category = @categories.find {|c| c && c.key == params[:category]}
not_found('category') if @category.nil?
end
((@subcategories_per_categories[@category].include? @category) ? @category : @subcategories_per_categories[@category][0])
@subcategory = default_subcategory
else
- @subcategory = @subcategories_per_categories[@category].find {|s| s == Java::OrgSonarApiConfigInternal::SubCategory.new(params[:subcategory])}
+ @subcategory = @subcategories_per_categories[@category].find {|s| s && s.key == params[:subcategory]}
not_found('subcategory') if @subcategory.nil?
end
/**
* @since 3.7
*/
-class Category {
+public class Category {
private final String originalKey;
private final boolean special;
this.special = special;
}
- String originalKey() {
+ public String originalKey() {
return originalKey;
}
- String key() {
+ public String key() {
return StringUtils.lowerCase(originalKey, Locale.ENGLISH);
}
- boolean isSpecial() {
+ public boolean isSpecial() {
return special;
}
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import org.apache.commons.lang.StringUtils;
-import org.sonar.api.*;
+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;
import org.sonar.api.utils.AnnotationUtils;
import javax.annotation.Nullable;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
/**
* Metadata of all the properties declared by plugins
/**
* @since 3.7
*/
-class SubCategory extends Category {
+public class SubCategory extends Category {
SubCategory(String originalKey) {
super(originalKey);
PropertyDefinition.builder("view").name("View").category("catView").onlyOnQualifiers(Qualifiers.VIEW).build()
);
- assertThat(def.getPropertiesByCategory(null).keySet()).containsOnly("catGlobal1", "catGlobal2");
- assertThat(def.getPropertiesByCategory(Qualifiers.PROJECT).keySet()).containsOnly("catProject");
- 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()).contains(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"));
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"));
public void should_group_by_category_on_annotation_plugin() {
PropertyDefinitions def = new PropertyDefinitions(ByCategory.class);
- 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()).contains(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"));