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