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 */ 020package org.sonar.api.batch; 021 022import org.sonar.api.design.Dependency; 023import org.sonar.api.measures.Measure; 024import org.sonar.api.measures.MeasuresFilter; 025import org.sonar.api.measures.Metric; 026import org.sonar.api.resources.Project; 027import org.sonar.api.resources.Resource; 028import org.sonar.api.rules.Violation; 029 030import java.util.Collection; 031import java.util.Date; 032import java.util.List; 033import java.util.Set; 034 035/** 036 * @since 1.10 037 */ 038public 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 new 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 new 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 * Save a coding rule violation. The decorator which calls this method must be depended upon BatchBarriers.END_OF_VIOLATIONS_GENERATION. 105 * 106 * @since 2.5 107 * @param force allows to force creation of violation even if it was suppressed by {@link org.sonar.api.rules.ViolationFilter} 108 * @deprecated in 3.6, replaced by {@link org.sonar.api.issue.Issuable} 109 */ 110 @Deprecated 111 DecoratorContext saveViolation(Violation violation, boolean force); 112 113 /** 114 * Save a coding rule violation. The decorator which calls this method must be depended upon BatchBarriers.END_OF_VIOLATIONS_GENERATION. 115 * @deprecated in 3.6, replaced by {@link org.sonar.api.issue.Issuable} 116 */ 117 @Deprecated 118 DecoratorContext saveViolation(Violation violation); 119 120 // EVENTS 121 122 /** 123 * @return the list of events associated to the current resource 124 */ 125 List<Event> getEvents(); 126 127 /** 128 * Creates an event for a given date 129 * 130 * @param name the event name 131 * @param description the event description 132 * @param category the event category 133 * @param date the event date 134 * @return the created event 135 */ 136 Event createEvent(String name, String description, String category, Date date); 137 138 /** 139 * Deletes an event 140 * 141 * @param event the event to delete 142 */ 143 void deleteEvent(Event event); 144 145}