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.Project; 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 DecoratorContext { 037 038 /** 039 * @return the project in which the decorator is 040 */ 041 Project getProject(); 042 043 /** 044 * @return the resource that is currently decorated 045 */ 046 Resource getResource(); 047 048 /** 049 * Child contexts are read only 050 */ 051 052 List<DecoratorContext> getChildren(); 053 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 /** 079 * Add a 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 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 093 // RULES 094 095 /** 096 * Read-only rule failures. 097 * 098 * @return the rule failures for file/classes resources, null for the others 099 */ 100 List<Violation> getViolations(); 101 102 /** 103 * @return the list of events associated to the current resource 104 */ 105 List<Event> getEvents(); 106 107 /** 108 * Creates an event for a given date 109 * 110 * @param name the event name 111 * @param description the event description 112 * @param category the event category 113 * @param date the event date 114 * @return the created event 115 */ 116 Event createEvent(String name, String description, String category, Date date); 117 118 /** 119 * Deletes an event 120 * 121 * @param event the event to delete 122 */ 123 void deleteEvent(Event event); 124 125 }