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 * @deprecated in 3.6, replaced by {@link org.sonar.api.issue.Issuable} 112 */ 113 @Deprecated 114 List<Violation> getViolations(ViolationQuery violationQuery); 115 116 /** 117 * Returns all the active (= non switched-off) violations found on the current resource. 118 * 119 * @return the list of violations 120 * @deprecated in 3.6, replaced by {@link org.sonar.api.issue.Issuable} 121 */ 122 @Deprecated 123 List<Violation> getViolations(); 124 125 /** 126 * Save a coding rule violation. The decorator which calls this method must be depended upon BatchBarriers.END_OF_VIOLATIONS_GENERATION. 127 * 128 * @since 2.5 129 * @param force allows to force creation of violation even if it was suppressed by {@link org.sonar.api.rules.ViolationFilter} 130 * @deprecated in 3.6, replaced by {@link org.sonar.api.issue.Issuable} 131 */ 132 @Deprecated 133 DecoratorContext saveViolation(Violation violation, boolean force); 134 135 /** 136 * Save a coding rule violation. The decorator which calls this method must be depended upon BatchBarriers.END_OF_VIOLATIONS_GENERATION. 137 * @deprecated in 3.6, replaced by {@link org.sonar.api.issue.Issuable} 138 */ 139 @Deprecated 140 DecoratorContext saveViolation(Violation violation); 141 142 // EVENTS 143 144 /** 145 * @return the list of events associated to the current resource 146 */ 147 List<Event> getEvents(); 148 149 /** 150 * Creates an event for a given date 151 * 152 * @param name the event name 153 * @param description the event description 154 * @param category the event category 155 * @param date the event date 156 * @return the created event 157 */ 158 Event createEvent(String name, String description, String category, Date date); 159 160 /** 161 * Deletes an event 162 * 163 * @param event the event to delete 164 */ 165 void deleteEvent(Event event); 166 167 }