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      /**
075       * @return the resource associated to the key
076       */
077      Resource getResource(String key);
078    
079      /**
080       * Find all measures for this project. Never return null.
081       */
082      <M> M getMeasures(Resource resource, MeasuresFilter<M> filter);
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, Metric metric, Double value);
090    
091      /**
092       * Add or update a measure.
093       * <p/>
094       * <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>
095       */
096      Measure saveMeasure(Resource resource, Measure measure);
097    
098    
099      // ----------- RULE VIOLATIONS --------------
100    
101      /**
102       * Saves a violation on a resource of the context 
103       */
104      void saveViolation(Violation violation);
105    
106      /**
107       * Saves a list of violations
108       */
109      void saveViolations(Collection<Violation> violations);
110    
111      // ----------- FILE SOURCES  --------------
112      /**
113       * Does nothing if the resource is set as excluded.
114       */
115      void saveSource(Resource resource, String source);
116    
117    
118      // ----------- LINKS --------------
119      /**
120       * add a link to an external page like project homepage, sources (subversion, ...), continuous integration server...
121       * Example : context.addLink(new ProjectLink("maven_site, "Maven site", "http://my.maven.com)
122       */
123      void saveLink(ProjectLink link);
124    
125      /**
126       * remove a link. It does not fail if key is unknown.
127       */
128      void deleteLink(String key);
129    
130    
131      // ----------- EVENTS --------------
132    
133      /**
134       * @param resource set null for project events
135       */
136      List<Event> getEvents(Resource resource);
137    
138      /**
139       * Creates an event for a given date
140       *
141       * @param name        the event name
142       * @param description the event description
143       * @param category    the event category
144       * @param date        the event date
145       * @return the created event
146       */
147      Event createEvent(Resource resource, String name, String description, String category, Date date);
148    
149      /**
150       * Deletes an event
151       *
152       * @param event the event to delete
153       */
154      void deleteEvent(Event event);
155    }