001 /* 002 * SonarQube, open source software quality management tool. 003 * Copyright (C) 2008-2014 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 */ 020 package org.sonar.api.batch; 021 022 import org.sonar.api.batch.fs.InputFile; 023 import org.sonar.api.design.Dependency; 024 import org.sonar.api.measures.Measure; 025 import org.sonar.api.measures.MeasuresFilter; 026 import org.sonar.api.measures.Metric; 027 import org.sonar.api.resources.ProjectLink; 028 import org.sonar.api.resources.Resource; 029 import org.sonar.api.rules.Violation; 030 031 import javax.annotation.CheckForNull; 032 033 import java.io.Serializable; 034 import java.util.Collection; 035 import java.util.Date; 036 import java.util.List; 037 import java.util.Set; 038 039 /** 040 * @since 1.10 041 * @deprecated since 4.5 042 */ 043 @Deprecated 044 public interface SensorContext { 045 046 /** 047 * Indexes a resource as a direct child of project. This method does nothing and returns true if the resource already indexed. 048 * 049 * @return false if the resource is excluded 050 * @deprecated since 4.2 Resource indexing is done by the platform for all physical resources. 051 */ 052 @Deprecated 053 boolean index(Resource resource); 054 055 /** 056 * Indexes a resource. This method does nothing if the resource is already indexed. 057 * 058 * @param resource the resource to index. Not nullable 059 * @param parentReference a reference to the parent. If null, the the resource is indexed as a direct child of project. 060 * @return false if the parent is not indexed or if the resource is excluded 061 * @deprecated since 4.2 Resource indexing is done by the platform for all physical resources. 062 */ 063 @Deprecated 064 boolean index(Resource resource, Resource parentReference); 065 066 /** 067 * Returns true if the referenced resource is indexed and excluded. 068 * 069 * @since 2.6 070 * @deprecated since 4.2 Excluded resources are not indexed. 071 */ 072 @Deprecated 073 boolean isExcluded(Resource reference); 074 075 /** 076 * Returns true if the referenced resource is indexed. 077 * 078 * @since 2.6 079 * @deprecated since 4.2 Excluded resources are not indexed. 080 */ 081 @Deprecated 082 boolean isIndexed(Resource reference, boolean acceptExcluded); 083 084 /** 085 * Search for an indexed resource. 086 * 087 * @param reference the resource reference 088 * @return the indexed resource, null if it's not indexed 089 * @since 1.10. Generic types since 2.6. 090 */ 091 @CheckForNull 092 <R extends Resource> R getResource(R reference); 093 094 /** 095 * @since 2.6 096 */ 097 Resource getParent(Resource reference); 098 099 /** 100 * @since 2.6 101 */ 102 103 Collection<Resource> getChildren(Resource reference); 104 105 // ----------- MEASURES ON PROJECT -------------- 106 107 /** 108 * Find a project measure 109 */ 110 <G extends Serializable> Measure<G> getMeasure(Metric<G> metric); 111 112 /** 113 * All measures of the project. Never return null. 114 */ 115 <M> M getMeasures(MeasuresFilter<M> filter); 116 117 /** 118 * Add a measure on project 119 */ 120 Measure saveMeasure(Measure measure); 121 122 /** 123 * Add a measure on project 124 */ 125 Measure saveMeasure(Metric metric, Double value); 126 127 // ----------- MEASURES ON RESOURCES -------------- 128 129 /** 130 * Find a measure for this project 131 */ 132 <G extends Serializable> Measure<G> getMeasure(Resource resource, Metric<G> metric); 133 134 /** 135 * Key is updated when saving the resource. 136 * 137 * @return the key as saved in database. Null if the resource is set as excluded. 138 * @deprecated use the methods index() 139 */ 140 @Deprecated 141 String saveResource(Resource resource); 142 143 /** 144 * Find all measures for this project. Never return null. 145 */ 146 <M> M getMeasures(Resource resource, MeasuresFilter<M> filter); 147 148 /** 149 * Add or update a measure. 150 * <p> 151 * The resource is automatically saved, so there is no need to execute the method saveResource(). Does nothing if the resource is set as 152 * excluded. 153 * </p> 154 */ 155 Measure saveMeasure(Resource resource, Metric metric, Double value); 156 157 /** 158 * Add or update a measure. 159 * <p> 160 * The resource is automatically saved, so there is no need to execute the method saveResource(). Does nothing if the resource is set as 161 * excluded. 162 * </p> 163 */ 164 Measure saveMeasure(Resource resource, Measure measure); 165 166 // ----------- RULE VIOLATIONS -------------- 167 168 /** 169 * Save a coding rule violation. 170 * 171 * @param force allows to force creation of violation even if it was supressed by {@link org.sonar.api.rules.ViolationFilter} 172 * @since 2.5 173 */ 174 void saveViolation(Violation violation, boolean force); 175 176 /** 177 * Save a coding rule violation. 178 */ 179 void saveViolation(Violation violation); 180 181 /** 182 * Saves a list of violations. 183 */ 184 void saveViolations(Collection<Violation> violations); 185 186 // ----------- DEPENDENCIES BETWEEN RESOURCES -------------- 187 188 /** 189 * Build a new dependency : from depends upon to. The dependency is NOT saved. The method saveDependency() must still be executed. 190 */ 191 Dependency saveDependency(Dependency dependency); 192 193 Set<Dependency> getDependencies(); 194 195 Collection<Dependency> getIncomingDependencies(Resource to); 196 197 Collection<Dependency> getOutgoingDependencies(Resource from); 198 199 // ----------- FILE SOURCES -------------- 200 201 /** 202 * Save the source code of a file. The file must be have been indexed before. 203 * 204 * @throws org.sonar.api.resources.DuplicatedSourceException if the source has already been set on this resource 205 * @since 1.10. Returns a boolean since 2.6. 206 * @deprecated since 4.2 Source import is done by the platform 207 */ 208 @Deprecated 209 void saveSource(Resource reference, String source); 210 211 // ----------- LINKS -------------- 212 213 /** 214 * add a link to an external page like project homepage, sources (subversion, ...), continuous integration server... Example : 215 * context.addLink(new ProjectLink("maven_site, "Maven site", "http://my.maven.com) 216 */ 217 void saveLink(ProjectLink link); 218 219 /** 220 * remove a link. It does not fail if key is unknown. 221 */ 222 void deleteLink(String key); 223 224 // ----------- EVENTS -------------- 225 226 /** 227 * @param resource set null for project events 228 */ 229 List<Event> getEvents(Resource resource); 230 231 /** 232 * Creates an event for a given date 233 * 234 * @param name the event name 235 * @param description the event description 236 * @param category the event category 237 * @param date the event date 238 * @return the created event 239 */ 240 Event createEvent(Resource resource, String name, String description, String category, Date date); 241 242 /** 243 * Deletes an event 244 * 245 * @param event the event to delete 246 */ 247 void deleteEvent(Event event); 248 249 /** 250 * Experimental 251 * @since 4.2 252 */ 253 Measure saveMeasure(InputFile inputFile, Metric metric, Double value); 254 255 /** 256 * Experimental 257 * @since 4.2 258 */ 259 Measure saveMeasure(InputFile inputFile, Measure measure); 260 }