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    
063      // ----------- MEASURES ON RESOURCES --------------
064    
065      /**
066       * Find a measure for this project
067       */
068      Measure getMeasure(Resource resource, Metric metric);
069    
070      /**
071       * Key is updated when saving the resource.
072       *
073       * @return the key as saved in database. Null if the resource is set as excluded.
074       */
075      String saveResource(Resource resource);
076    
077      /**
078       * @return the resource saved in sonar index
079       */
080      Resource getResource(Resource resource);
081    
082      /**
083       * Find all measures for this project. Never return null.
084       */
085      <M> M getMeasures(Resource resource, MeasuresFilter<M> filter);
086    
087      /**
088       * Add or update a measure.
089       * <p/>
090       * <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>
091       */
092      Measure saveMeasure(Resource resource, Metric metric, Double value);
093    
094      /**
095       * Add or update a measure.
096       * <p/>
097       * <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>
098       */
099      Measure saveMeasure(Resource resource, Measure measure);
100    
101    
102      // ----------- RULE VIOLATIONS --------------
103    
104      /**
105       * Save a coding rule violation.
106       */
107      void saveViolation(Violation violation);
108    
109      /**
110       * Saves a list of violations
111       */
112      void saveViolations(Collection<Violation> violations);
113    
114    
115      // ----------- DEPENDENCIES BETWEEN RESOURCES  --------------
116    
117      /**
118       * Build a new dependency : from depends upon to. The dependency is NOT saved. The method saveDependency() must still be executed.
119       */
120      Dependency saveDependency(Dependency dependency);
121    
122      Set<Dependency> getDependencies();
123    
124      Collection<Dependency> getIncomingDependencies(Resource to);
125    
126      Collection<Dependency> getOutgoingDependencies(Resource from);
127    
128      // ----------- FILE SOURCES  --------------
129    
130      /**
131       * Does nothing if the resource is set as excluded.
132       */
133      void saveSource(Resource resource, String source);
134    
135    
136      // ----------- LINKS --------------
137    
138      /**
139       * add a link to an external page like project homepage, sources (subversion, ...), continuous integration server...
140       * Example : context.addLink(new ProjectLink("maven_site, "Maven site", "http://my.maven.com)
141       */
142      void saveLink(ProjectLink link);
143    
144      /**
145       * remove a link. It does not fail if key is unknown.
146       */
147      void deleteLink(String key);
148    
149    
150      // ----------- EVENTS --------------
151    
152      /**
153       * @param resource set null for project events
154       */
155      List<Event> getEvents(Resource resource);
156    
157      /**
158       * Creates an event for a given date
159       *
160       * @param name        the event name
161       * @param description the event description
162       * @param category    the event category
163       * @param date        the event date
164       * @return the created event
165       */
166      Event createEvent(Resource resource, String name, String description, String category, Date date);
167    
168      /**
169       * Deletes an event
170       *
171       * @param event the event to delete
172       */
173      void deleteEvent(Event event);
174    
175    }