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.measures.Measure;
023 import org.sonar.api.measures.MeasuresFilter;
024 import org.sonar.api.measures.Metric;
025 import org.sonar.api.resources.ProjectLink;
026 import org.sonar.api.resources.Resource;
027 import org.sonar.api.rules.Violation;
028
029 import java.util.Collection;
030 import java.util.Date;
031 import java.util.List;
032
033 /**
034 * @since 1.10
035 */
036 public interface SensorContext {
037
038 // ----------- MEASURES ON PROJECT --------------
039
040 /**
041 * Find a project measure
042 */
043 Measure getMeasure(Metric metric);
044
045 /**
046 * All measures of the project. Never return null.
047 */
048 <M> M getMeasures(MeasuresFilter<M> filter);
049
050 /**
051 * Add a measure on project
052 */
053 Measure saveMeasure(Measure measure);
054
055 /**
056 * Add a measure on project
057 */
058 Measure saveMeasure(Metric metric, Double value);
059
060
061 // ----------- MEASURES ON RESOURCES --------------
062 /**
063 * Find a measure for this project
064 */
065 Measure getMeasure(Resource resource, Metric metric);
066
067 /**
068 * Key is updated when saving the resource.
069 *
070 * @return the key as saved in database. Null if the resource is set as excluded.
071 */
072 String saveResource(Resource resource);
073
074 Resource getResource(String key);
075
076 /**
077 * Find all measures for this project. Never return null.
078 */
079 <M> M getMeasures(Resource resource, MeasuresFilter<M> filter);
080
081
082 Measure saveMeasure(Resource resource, Metric metric, Double value);
083
084 /**
085 * Add or update a measure.
086 * <p/>
087 * <p>The resource is automatically saved, so there is no need to execute the method saveResource(). Does nothing if the resource is set as excluded.</p>
088 */
089 Measure saveMeasure(Resource resource, Measure measure);
090
091
092 // ----------- RULE VIOLATIONS --------------
093
094 void saveViolation(Violation violation);
095
096 void saveViolations(Collection<Violation> violations);
097
098 // ----------- FILE SOURCES --------------
099 /**
100 * Does nothing if the resource is set as excluded.
101 */
102 void saveSource(Resource resource, String source);
103
104
105 // ----------- LINKS --------------
106 /**
107 * add a link to an external page like project homepage, sources (subversion, ...), continuous integration server...
108 * Example : context.addLink(new ProjectLink("maven_site, "Maven site", "http://my.maven.com)
109 */
110 void saveLink(ProjectLink link);
111
112 /**
113 * remove a link. It does not fail if key is unknown.
114 */
115 void deleteLink(String key);
116
117
118 // ----------- EVENTS --------------
119
120 /**
121 * @param resource set null for project events
122 */
123 List<Event> getEvents(Resource resource);
124
125 /**
126 * Creates an event for a given date
127 *
128 * @param name the event name
129 * @param description the event description
130 * @param category the event category
131 * @param date the event date
132 * @return the created event
133 */
134 Event createEvent(Resource resource, String name, String description, String category, Date date);
135
136 /**
137 * Deletes an event
138 *
139 * @param event the event to delete
140 */
141 void deleteEvent(Event event);
142 }