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.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.Project;
027 import org.sonar.api.resources.Resource;
028 import org.sonar.api.rules.Violation;
029 import org.sonar.api.violations.ViolationQuery;
030
031 import java.util.Collection;
032 import java.util.Date;
033 import java.util.List;
034 import java.util.Set;
035
036 /**
037 * @since 1.10
038 */
039 public interface DecoratorContext {
040
041 /**
042 * @return the project in which the decorator is
043 */
044 Project getProject();
045
046 /**
047 * @return the resource that is currently decorated
048 */
049 Resource getResource();
050
051 /**
052 * Child contexts are read only
053 */
054 List<DecoratorContext> getChildren();
055
056 // MEASURES
057
058 /**
059 * Find a measure for the resource
060 */
061 Measure getMeasure(Metric metric);
062
063 /**
064 * Never return null.
065 */
066 <M> M getMeasures(MeasuresFilter<M> filter);
067
068 /**
069 * Never return null.
070 */
071 Collection<Measure> getChildrenMeasures(MeasuresFilter filter);
072
073 /**
074 * @return the resource children measures for the given metric
075 */
076 Collection<Measure> getChildrenMeasures(Metric metric);
077
078 /**
079 * Add a new measure on the current resource. It can not be executed from children contexts.
080 *
081 * @return the same context
082 */
083 DecoratorContext saveMeasure(Measure measure);
084
085 /**
086 * Add a new measure on the current resource. It can not be executed from children contexts.
087 *
088 * @return the current object
089 */
090 DecoratorContext saveMeasure(Metric metric, Double value);
091
092 // DEPENDENCIES
093
094 Dependency saveDependency(Dependency dependency);
095
096 Set<Dependency> getDependencies();
097
098 Collection<Dependency> getIncomingDependencies();
099
100 Collection<Dependency> getOutgoingDependencies();
101
102 // RULES
103
104 /**
105 * Returns the violations that match the {@link ViolationQuery} parameters.
106 *
107 * @since 2.8
108 * @param violationQuery
109 * the request parameters specified as a {@link ViolationQuery}
110 * @return the list of violations that match those parameters
111 */
112 List<Violation> getViolations(ViolationQuery violationQuery);
113
114 /**
115 * Returns all the active (= non switched-off) violations found on the current resource.
116 *
117 * @return the list of violations
118 */
119 List<Violation> getViolations();
120
121 /**
122 * Save a coding rule violation. The decorator which calls this method must be depended upon BatchBarriers.END_OF_VIOLATIONS_GENERATION.
123 *
124 * @since 2.5
125 * @param force allows to force creation of violation even if it was suppressed by {@link org.sonar.api.rules.ViolationFilter}
126 */
127 DecoratorContext saveViolation(Violation violation, boolean force);
128
129 /**
130 * Save a coding rule violation. The decorator which calls this method must be depended upon BatchBarriers.END_OF_VIOLATIONS_GENERATION.
131 */
132 DecoratorContext saveViolation(Violation violation);
133
134 // EVENTS
135
136 /**
137 * @return the list of events associated to the current resource
138 */
139 List<Event> getEvents();
140
141 /**
142 * Creates an event for a given date
143 *
144 * @param name the event name
145 * @param description the event description
146 * @param category the event category
147 * @param date the event date
148 * @return the created event
149 */
150 Event createEvent(String name, String description, String category, Date date);
151
152 /**
153 * Deletes an event
154 *
155 * @param event the event to delete
156 */
157 void deleteEvent(Event event);
158
159 }