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.batch;
021
022 import org.sonar.api.design.Dependency;
023 import org.sonar.api.measures.Measure;
024 import org.sonar.api.measures.MeasuresFilter;
025 import org.sonar.api.measures.Metric;
026 import org.sonar.api.resources.ProjectLink;
027 import org.sonar.api.resources.Resource;
028 import org.sonar.api.rules.Violation;
029
030 import java.util.Collection;
031 import java.util.Date;
032 import java.util.List;
033 import java.util.Set;
034
035 /**
036 * @since 1.10
037 */
038 public interface SensorContext {
039
040 // ----------- MEASURES ON PROJECT --------------
041
042 /**
043 * Find a project measure
044 */
045 Measure getMeasure(Metric metric);
046
047 /**
048 * All measures of the project. Never return null.
049 */
050 <M> M getMeasures(MeasuresFilter<M> filter);
051
052 /**
053 * Add a measure on project
054 */
055 Measure saveMeasure(Measure measure);
056
057 /**
058 * Add a measure on project
059 */
060 Measure saveMeasure(Metric metric, Double value);
061
062 // ----------- MEASURES ON RESOURCES --------------
063
064 /**
065 * Find a measure for this project
066 */
067 Measure getMeasure(Resource resource, Metric metric);
068
069 /**
070 * Key is updated when saving the resource.
071 *
072 * @return the key as saved in database. Null if the resource is set as excluded.
073 */
074 String saveResource(Resource resource);
075
076 /**
077 * @return the resource saved in sonar index
078 */
079 Resource getResource(Resource resource);
080
081 /**
082 * Find all measures for this project. Never return null.
083 */
084 <M> M getMeasures(Resource resource, MeasuresFilter<M> filter);
085
086 /**
087 * Add or update a measure.
088 * <p>
089 * The resource is automatically saved, so there is no need to execute the method saveResource(). Does nothing if the resource is set as
090 * excluded.
091 * </p>
092 */
093 Measure saveMeasure(Resource resource, Metric metric, Double value);
094
095 /**
096 * Add or update a measure.
097 * <p>
098 * The resource is automatically saved, so there is no need to execute the method saveResource(). Does nothing if the resource is set as
099 * excluded.
100 * </p>
101 */
102 Measure saveMeasure(Resource resource, Measure measure);
103
104 // ----------- RULE VIOLATIONS --------------
105
106 /**
107 * Save a coding rule violation.
108 *
109 * @since 2.5
110 * @param force allows to force creation of violation even if it was supressed by {@link org.sonar.api.rules.ViolationFilter}
111 */
112 void saveViolation(Violation violation, boolean force);
113
114 /**
115 * Save a coding rule violation.
116 */
117 void saveViolation(Violation violation);
118
119 /**
120 * Saves a list of violations.
121 */
122 void saveViolations(Collection<Violation> violations);
123
124 // ----------- DEPENDENCIES BETWEEN RESOURCES --------------
125
126 /**
127 * Build a new dependency : from depends upon to. The dependency is NOT saved. The method saveDependency() must still be executed.
128 */
129 Dependency saveDependency(Dependency dependency);
130
131 Set<Dependency> getDependencies();
132
133 Collection<Dependency> getIncomingDependencies(Resource to);
134
135 Collection<Dependency> getOutgoingDependencies(Resource from);
136
137 // ----------- FILE SOURCES --------------
138
139 /**
140 * Does nothing if the resource is set as excluded.
141 */
142 void saveSource(Resource resource, String source);
143
144 // ----------- LINKS --------------
145
146 /**
147 * add a link to an external page like project homepage, sources (subversion, ...), continuous integration server... Example :
148 * context.addLink(new ProjectLink("maven_site, "Maven site", "http://my.maven.com)
149 */
150 void saveLink(ProjectLink link);
151
152 /**
153 * remove a link. It does not fail if key is unknown.
154 */
155 void deleteLink(String key);
156
157 // ----------- EVENTS --------------
158
159 /**
160 * @param resource set null for project events
161 */
162 List<Event> getEvents(Resource resource);
163
164 /**
165 * Creates an event for a given date
166 *
167 * @param name the event name
168 * @param description the event description
169 * @param category the event category
170 * @param date the event date
171 * @return the created event
172 */
173 Event createEvent(Resource resource, String name, String description, String category, Date date);
174
175 /**
176 * Deletes an event
177 *
178 * @param event the event to delete
179 */
180 void deleteEvent(Event event);
181
182 }