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