001/* 002 * SonarQube, open source software quality management tool. 003 * Copyright (C) 2008-2014 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * SonarQube is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * SonarQube is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020 021package org.sonar.wsclient.services; 022 023import javax.annotation.CheckForNull; 024import javax.annotation.Nullable; 025 026import java.util.*; 027 028/** 029 * @since 2.7 030 */ 031public class Profile extends Model { 032 033 private String language; 034 private String name; 035 private boolean defaultProfile; 036 private String parentName; 037 private List<Rule> rules = new ArrayList<Rule>(); 038 039 @CheckForNull 040 public String getLanguage() { 041 return language; 042 } 043 044 public Profile setLanguage(@Nullable String s) { 045 this.language = s; 046 return this; 047 } 048 049 @CheckForNull 050 public String getName() { 051 return name; 052 } 053 054 public Profile setName(@Nullable String name) { 055 this.name = name; 056 return this; 057 } 058 059 public boolean isDefaultProfile() { 060 return defaultProfile; 061 } 062 063 public Profile setDefaultProfile(boolean b) { 064 this.defaultProfile = b; 065 return this; 066 } 067 068 public String getParentName() { 069 return parentName; 070 } 071 072 @CheckForNull 073 public Profile setParentName(@Nullable String s) { 074 this.parentName = s; 075 return this; 076 } 077 078 public List<Rule> getRules() { 079 return rules; 080 } 081 082 public Rule getRule(String repositoryKey, String ruleKey) { 083 for (Rule rule : rules) { 084 if (repositoryKey.equals(rule.getRepository()) && ruleKey.equals(rule.getKey())) { 085 return rule; 086 } 087 } 088 return null; 089 } 090 091 public Profile addRule(Rule rule) { 092 rules.add(rule); 093 return this; 094 } 095 096 public static final class Rule { 097 private String key; 098 private String repository; 099 private String severity; 100 private String inheritance; 101 private Map<String,String> parameters; 102 103 @CheckForNull 104 public String getKey() { 105 return key; 106 } 107 108 public Rule setKey(@Nullable String key) { 109 this.key = key; 110 return this; 111 } 112 113 @CheckForNull 114 public String getRepository() { 115 return repository; 116 } 117 118 public Rule setRepository(@Nullable String repository) { 119 this.repository = repository; 120 return this; 121 } 122 123 @CheckForNull 124 public String getSeverity() { 125 return severity; 126 } 127 128 public Rule setSeverity(@Nullable String severity) { 129 this.severity = severity; 130 return this; 131 } 132 133 @CheckForNull 134 public String getInheritance() { 135 return inheritance; 136 } 137 138 public Rule setInheritance(@Nullable String inheritance) { 139 this.inheritance = inheritance; 140 return this; 141 } 142 143 public Map<String, String> getParameters() { 144 if (parameters==null) { 145 return Collections.emptyMap(); 146 } 147 return parameters; 148 } 149 150 public String getParameter(String key) { 151 return getParameters().get(key); 152 } 153 154 public Rule addParameter(@Nullable String key, @Nullable String value) { 155 if (parameters==null) { 156 parameters = new HashMap<String,String>(); 157 } 158 parameters.put(key, value); 159 return this; 160 } 161 } 162}