001/* 002 * SonarQube, open source software quality management tool. 003 * Copyright (C) 2008-2013 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 */ 020package org.sonar.api.resources; 021 022import java.io.Serializable; 023 024/** 025 * The interface to implement to create a resource in Sonar 026 * 027 * @since 1.10 028 */ 029public abstract class Resource implements Serializable { 030 031 /** 032 * @deprecated since 2.6. Use Scopes.PROJECT. 033 */ 034 @Deprecated 035 public static final String SCOPE_SET = Scopes.PROJECT; 036 037 /** 038 * @deprecated since 2.6. Use Scopes.DIRECTORY. 039 */ 040 @Deprecated 041 public static final String SCOPE_SPACE = Scopes.DIRECTORY; 042 043 /** 044 * @deprecated since 2.6. Use Scopes.FILE. 045 */ 046 @Deprecated 047 public static final String SCOPE_ENTITY = Scopes.FILE; 048 049 /** 050 * @deprecated since 2.6. Use Qualifiers.VIEW. 051 */ 052 @Deprecated 053 public static final String QUALIFIER_VIEW = Qualifiers.VIEW; 054 055 /** 056 * @deprecated since 2.6. Use Qualifiers.SUBVIEW. 057 */ 058 @Deprecated 059 public static final String QUALIFIER_SUBVIEW = Qualifiers.SUBVIEW; 060 061 /** 062 * @deprecated since 2.6. Use Qualifiers.LIBRARY. 063 */ 064 @Deprecated 065 public static final String QUALIFIER_LIB = Qualifiers.LIBRARY; 066 067 /** 068 * @deprecated since 2.6. Use Qualifiers.PROJECT. 069 */ 070 @Deprecated 071 public static final String QUALIFIER_PROJECT = Qualifiers.PROJECT; 072 073 /** 074 * @deprecated since 2.6. Use Qualifiers.MODULE. 075 */ 076 @Deprecated 077 public static final String QUALIFIER_MODULE = Qualifiers.MODULE; 078 079 /** 080 * @deprecated since 2.6. Use Qualifiers.PACKAGE. 081 */ 082 @Deprecated 083 public static final String QUALIFIER_PACKAGE = Qualifiers.PACKAGE; 084 085 /** 086 * @deprecated since 2.6. Use Qualifiers.DIRECTORY. 087 */ 088 @Deprecated 089 public static final String QUALIFIER_DIRECTORY = Qualifiers.DIRECTORY; 090 091 /** 092 * @deprecated since 2.6. Use Qualifiers.FILE. 093 */ 094 @Deprecated 095 public static final String QUALIFIER_FILE = Qualifiers.FILE; 096 097 /** 098 * @deprecated since 2.6. Use Qualifiers.CLASS. 099 */ 100 @Deprecated 101 public static final String QUALIFIER_CLASS = Qualifiers.CLASS; 102 103 /** 104 * @deprecated since 2.6. Use Qualifiers.FIELD. 105 */ 106 @Deprecated 107 public static final String QUALIFIER_FIELD = Qualifiers.FIELD; 108 109 /** 110 * @deprecated since 2.6. Use Qualifiers.METHOD. 111 */ 112 @Deprecated 113 public static final String QUALIFIER_METHOD = Qualifiers.METHOD; 114 115 /** 116 * @deprecated since 2.6. Use Qualifiers.UNIT_TEST_FILE. 117 */ 118 @Deprecated 119 public static final String QUALIFIER_UNIT_TEST_CLASS = Qualifiers.UNIT_TEST_FILE; 120 121 private Integer id = null; 122 123 private String key = null; 124 125 private String effectiveKey = null; 126 127 private boolean isExcluded = false; 128 129 /** 130 * @return the resource key 131 */ 132 public final String getKey() { 133 return key; 134 } 135 136 protected void setKey(String s) { 137 this.key = s; 138 } 139 140 /** 141 * @return the resource name 142 */ 143 public abstract String getName(); 144 145 /** 146 * @return the resource long name 147 */ 148 public abstract String getLongName(); 149 150 /** 151 * @return the resource description 152 */ 153 public abstract String getDescription(); 154 155 /** 156 * @return the language 157 */ 158 public abstract Language getLanguage(); 159 160 /** 161 * @return the scope 162 */ 163 public abstract String getScope(); 164 165 /** 166 * The qualifier tells the type of the resource. For example, it can be a File, a Class, a Project, a Unit Test... 167 * 168 * @return the qualifier 169 * 170 * @see org.sonar.api.resources.Qualifiers for the list of qualifiers 171 * @see org.sonar.api.resources.ResourceUtils to find out if a resource if a class, a unit test,... from its qualifier 172 */ 173 public abstract String getQualifier(); 174 175 /** 176 * The parent is used to build the resources tree, for example for relations between classes, packages and projects. 177 * <p> 178 * Return null if the parent is the project. 179 * </p> 180 */ 181 public abstract Resource getParent(); 182 183 /** 184 * Check resource against an Ant pattern, like mypackag?/*Foo.java. It's used for example to match resource exclusions. 185 * 186 * @param antPattern Ant-like pattern (with **, * and ?). It includes file suffixes. 187 * @return true if the resource matches the Ant pattern 188 */ 189 public abstract boolean matchFilePattern(String antPattern); 190 191 public final Integer getId() { 192 return id; 193 } 194 195 /** 196 * Internal use only 197 */ 198 public Resource setId(Integer id) { 199 this.id = id; 200 return this; 201 } 202 203 public String getEffectiveKey() { 204 return effectiveKey; 205 } 206 207 /** 208 * Internal use only 209 */ 210 public final Resource setEffectiveKey(String effectiveKey) { 211 this.effectiveKey = effectiveKey; 212 return this; 213 } 214 215 /** 216 * @deprecated since 2.6 should use SensorContext#isExcluded(resource). It will make inheritance of Resource easier. 217 */ 218 @Deprecated 219 public final boolean isExcluded() { 220 return isExcluded; 221 } 222 223 /** 224 * Internal use only 225 * @deprecated since 2.6 should use SensorContext#isExcluded(resource). It will make inheritance of Resource easier. 226 */ 227 @Deprecated 228 public final Resource setExcluded(boolean b) { 229 isExcluded = b; 230 return this; 231 } 232 233 @Override 234 public boolean equals(Object o) { 235 if (this == o) { 236 return true; 237 } 238 if (o == null || getClass() != o.getClass()) { 239 return false; 240 } 241 242 Resource resource = (Resource) o; 243 return key.equals(resource.key); 244 245 } 246 247 @Override 248 public int hashCode() { 249 return key.hashCode(); 250 } 251}