001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2009 SonarSource SA
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 public static final String SCOPE_SET = "PRJ";
030 public static final String SCOPE_SPACE = "DIR";
031 public static final String SCOPE_ENTITY = "FIL";
032
033 /**
034 * Use SCOPE_SET instead
035 */
036 @Deprecated
037 public static final String SCOPE_PROJECT = SCOPE_SET;
038
039 /**
040 * Use SCOPE_SPACE instead
041 */
042 @Deprecated
043 public static final String SCOPE_DIRECTORY = SCOPE_SPACE;
044
045 /**
046 * Use SCOPE_ENTITY instead
047 */
048 @Deprecated
049 public static final String SCOPE_FILE = SCOPE_ENTITY;
050
051
052 public static final String QUALIFIER_VIEW = "VW";
053 public static final String QUALIFIER_SUBVIEW = "SVW";
054 public static final String QUALIFIER_LIB = "LIB";
055 public static final String QUALIFIER_PROJECT = "TRK";
056 public static final String QUALIFIER_MODULE = "BRC";
057 public static final String QUALIFIER_PACKAGE = "PAC";
058 public static final String QUALIFIER_DIRECTORY = "DIR";
059 public static final String QUALIFIER_FILE = "FIL";
060 public static final String QUALIFIER_CLASS = "CLA";
061 public static final String QUALIFIER_FIELD = "FLD";
062 public static final String QUALIFIER_METHOD = "MET";
063 public static final String QUALIFIER_UNIT_TEST_CLASS = "UTS";
064
065 /**
066 * Use QUALIFIER_PROJECT instead
067 */
068 @Deprecated
069 public static final String QUALIFIER_PROJECT_TRUNK = QUALIFIER_PROJECT;
070
071 /**
072 * Use QUALIFIER_MODULE instead
073 */
074 @Deprecated
075 public static final String QUALIFIER_PROJECT_BRANCH = QUALIFIER_MODULE;
076
077 private Integer id = null;
078
079 private String key = null;
080
081 private String effectiveKey = null;
082
083 private boolean isExcluded = false;
084
085
086 /**
087 * @return the resource key
088 */
089 public final String getKey() {
090 return key;
091 }
092
093 protected void setKey(String s) {
094 this.key = s;
095 }
096
097 /**
098 * @return the resource name
099 */
100 public abstract String getName();
101
102 /**
103 * @return the resource long name
104 */
105 public abstract String getLongName();
106
107 /**
108 * @return the resource description
109 */
110 public abstract String getDescription();
111
112 /**
113 * @return the language
114 */
115 public abstract Language getLanguage();
116
117 /**
118 * @return the scope
119 */
120 public abstract String getScope();
121
122 /**
123 * @return the qualifier
124 */
125 public abstract String getQualifier();
126
127 /**
128 * The parent is used to build the resources tree, for example for relations between classes, packages and projects.
129 * <p>Return null if the parent is the project.</p>
130 */
131 public abstract PARENT getParent();
132
133 /**
134 * Check resource against an Ant pattern, like mypackag?/*Foo.java. It's used for example
135 * to match resource exclusions.
136 *
137 * @param antPattern Ant-like pattern (with **, * and ?). It includes file suffixes.
138 * @return true if the resource matches the Ant pattern
139 */
140 public abstract boolean matchFilePattern(String antPattern);
141
142
143 public final Integer getId() {
144 return id;
145 }
146
147 /**
148 * Internal use only
149 */
150 public Resource setId(Integer id) {
151 this.id = id;
152 return this;
153 }
154
155 public final String getEffectiveKey() {
156 return effectiveKey;
157 }
158
159 /**
160 * Internal use only
161 */
162 public final Resource setEffectiveKey(String effectiveKey) {
163 this.effectiveKey = effectiveKey;
164 return this;
165 }
166
167 public final boolean isExcluded() {
168 return isExcluded;
169 }
170
171 /**
172 * Internal use only
173 */
174 public final Resource setExcluded(boolean b) {
175 isExcluded = b;
176 return this;
177 }
178
179 @Override
180 public boolean equals(Object o) {
181 if (this == o) {
182 return true;
183 }
184 if (o == null || getClass() != o.getClass()) {
185 return false;
186 }
187
188 Resource resource = (Resource) o;
189 return key.equals(resource.key);
190
191 }
192
193 @Override
194 public int hashCode() {
195 return key.hashCode();
196 }
197 }