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