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