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.Project;
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 DecoratorContext {
039
040 /**
041 * @return the project in which the decorator is
042 */
043 Project getProject();
044
045 /**
046 * @return the resource that is currently decorated
047 */
048 Resource getResource();
049
050 /**
051 * Child contexts are read only
052 */
053
054 List<DecoratorContext> getChildren();
055
056
057 // MEASURES
058
059 /**
060 * Find a measure for the resource
061 */
062 Measure getMeasure(Metric metric);
063
064 /**
065 * Never return null.
066 */
067 <M> M getMeasures(MeasuresFilter<M> filter);
068
069 /**
070 * Never return null.
071 */
072 Collection<Measure> getChildrenMeasures(MeasuresFilter filter);
073
074 /**
075 * @return the resource children measures for the given metric
076 */
077 Collection<Measure> getChildrenMeasures(Metric metric);
078
079
080 /**
081 * Add a measure on the current resource. It can not be executed from children contexts.
082 *
083 * @return the same context
084 */
085 DecoratorContext saveMeasure(Measure measure);
086
087 /**
088 * Add a measure on the current resource. It can not be executed from children contexts.
089 *
090 * @return the current object
091 */
092 DecoratorContext saveMeasure(Metric metric, Double value);
093
094
095 Dependency saveDependency(Dependency dependency);
096
097 Set<Dependency> getDependencies();
098
099 Collection<Dependency> getIncomingDependencies();
100
101 Collection<Dependency> getOutgoingDependencies();
102
103
104 // RULES
105
106 /**
107 * Read-only rule failures.
108 *
109 * @return the rule failures for file/classes resources, null for the others
110 */
111 List<Violation> getViolations();
112
113
114 /**
115 * Save a coding rule violation. The decorator which calls this method must implement org.sonar.api.batch.GeneratesViolations
116 */
117 DecoratorContext saveViolation(Violation violation);
118
119 /**
120 * @return the list of events associated to the current resource
121 */
122 List<Event> getEvents();
123
124 /**
125 * Creates an event for a given date
126 *
127 * @param name the event name
128 * @param description the event description
129 * @param category the event category
130 * @param date the event date
131 * @return the created event
132 */
133 Event createEvent(String name, String description, String category, Date date);
134
135 /**
136 * Deletes an event
137 *
138 * @param event the event to delete
139 */
140 void deleteEvent(Event event);
141
142
143
144 }