001    /*
002     * Sonar, open source software quality management tool.
003     * Copyright (C) 2008-2011 SonarSource
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      List<DecoratorContext> getChildren();
054    
055      // MEASURES
056    
057      /**
058       * Find a measure for the resource
059       */
060      Measure getMeasure(Metric metric);
061    
062      /**
063       * Never return null.
064       */
065      <M> M getMeasures(MeasuresFilter<M> filter);
066    
067      /**
068       * Never return null.
069       */
070      Collection<Measure> getChildrenMeasures(MeasuresFilter filter);
071    
072      /**
073       * @return the resource children measures for the given metric
074       */
075      Collection<Measure> getChildrenMeasures(Metric metric);
076    
077      /**
078       * Add a measure on the current resource. It can not be executed from children contexts.
079       * 
080       * @return the same context
081       */
082      DecoratorContext saveMeasure(Measure measure);
083    
084      /**
085       * Add a measure on the current resource. It can not be executed from children contexts.
086       * 
087       * @return the current object
088       */
089      DecoratorContext saveMeasure(Metric metric, Double value);
090    
091      // DEPENDENCIES
092    
093      Dependency saveDependency(Dependency dependency);
094    
095      Set<Dependency> getDependencies();
096    
097      Collection<Dependency> getIncomingDependencies();
098    
099      Collection<Dependency> getOutgoingDependencies();
100    
101      // RULES
102    
103      /**
104       * Read-only rule violations.
105       */
106      List<Violation> getViolations();
107    
108      /**
109       * Save a coding rule violation. The decorator which calls this method must be depended upon BatchBarriers.END_OF_VIOLATIONS_GENERATION.
110       * 
111       * @since 2.5
112       * @param force allows to force creation of violation even if it was suppressed by {@link org.sonar.api.rules.ViolationFilter}
113       */
114      DecoratorContext saveViolation(Violation violation, boolean force);
115    
116      /**
117       * Save a coding rule violation. The decorator which calls this method must be depended upon BatchBarriers.END_OF_VIOLATIONS_GENERATION.
118       */
119      DecoratorContext saveViolation(Violation violation);
120    
121      // EVENTS
122    
123      /**
124       * @return the list of events associated to the current resource
125       */
126      List<Event> getEvents();
127    
128      /**
129       * Creates an event for a given date
130       * 
131       * @param name the event name
132       * @param description the event description
133       * @param category the event category
134       * @param date the event date
135       * @return the created event
136       */
137      Event createEvent(String name, String description, String category, Date date);
138    
139      /**
140       * Deletes an event
141       * 
142       * @param event the event to delete
143       */
144      void deleteEvent(Event event);
145    
146    }