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 021package org.sonar.api.issue; 022 023import java.util.List; 024import javax.annotation.Nullable; 025import org.sonar.api.batch.sensor.issue.NewIssue; 026import org.sonar.api.batch.sensor.issue.NewIssueLocation; 027import org.sonar.api.component.Perspective; 028import org.sonar.api.rule.RuleKey; 029 030/** 031 * This perspective allows to add and get issues related to the selected component. It can be used from 032 * {@link org.sonar.api.batch.Sensor}s and {@link org.sonar.api.batch.Decorator}s. Web extensions 033 * must use {@link RubyIssueService}. 034 * <p/> 035 * Example: 036 * <pre> 037 * import org.sonar.api.component.ResourcePerspectives; 038 * public class MySensor extends Sensor { 039 * private final ResourcePerspectives perspectives; 040 * 041 * public MySensor(ResourcePerspectives p) { 042 * this.perspectives = p; 043 * } 044 * 045 * public void analyse(Project project, SensorContext context) { 046 * Resource myResource; // to be set 047 * Issuable issuable = perspectives.as(Issuable.class, myResource); 048 * if (issuable != null) { 049 * // can be used 050 * Issue issue = issuable.newIssueBuilder() 051 * .setRuleKey(RuleKey.of("pmd", "AvoidArrayLoops") 052 * .setLine(10) 053 * .build(); 054 * issuable.addIssue(issue); 055 * } 056 * } 057 * } 058 * </pre> 059 * @since 3.6 060 */ 061public interface Issuable extends Perspective { 062 063 interface IssueBuilder { 064 /** 065 * The rule key is mandatory. Example: {@code RuleKey.of("pmd", "AvoidArrayLoops")} 066 */ 067 IssueBuilder ruleKey(RuleKey ruleKey); 068 069 /** 070 * Optional line index, starting from 1. It must not be zero or negative. 071 * @deprecated since 5.2 use {@link #at(NewIssueLocation)} 072 */ 073 @Deprecated 074 IssueBuilder line(@Nullable Integer line); 075 076 /** 077 * Optional, but recommended, plain-text message. 078 * <p/> 079 * Formats like Markdown or HTML are not supported. Size must not be greater than {@link Issue#MESSAGE_MAX_SIZE} characters. 080 * @deprecated since 5.2 use {@link #at(NewIssueLocation)} 081 */ 082 @Deprecated 083 IssueBuilder message(@Nullable String message); 084 085 /** 086 * @since 5.2 087 * Create a new location for this issue. First registered location is considered as primary location. 088 */ 089 NewIssueLocation newLocation(); 090 091 /** 092 * @since 5.2 093 * Register primary location for this issue. 094 */ 095 IssueBuilder at(NewIssueLocation primaryLocation); 096 097 /** 098 * @since 5.2 099 * @see NewIssue#addLocation(NewIssueLocation) 100 */ 101 IssueBuilder addLocation(NewIssueLocation secondaryLocation); 102 103 /** 104 * @since 5.2 105 * @see NewIssue#addFlow(Iterable) 106 */ 107 IssueBuilder addFlow(Iterable<NewIssueLocation> flowLocations); 108 109 /** 110 * Overrides the severity declared in Quality profile. Do not execute in standard use-cases. 111 * @see org.sonar.api.rule.Severity 112 */ 113 IssueBuilder severity(@Nullable String severity); 114 115 /** 116 * Login of the user who reported the issue. Optional. 117 */ 118 IssueBuilder reporter(@Nullable String reporter); 119 120 IssueBuilder effortToFix(@Nullable Double d); 121 122 /** 123 * No more supported from batch side since 5.2 124 */ 125 IssueBuilder attribute(String key, @Nullable String value); 126 127 Issue build(); 128 } 129 130 /** 131 * Builder is used to create the issue to be passed to {@link #addIssue(Issue)} 132 */ 133 IssueBuilder newIssueBuilder(); 134 135 /** 136 * Register an issue created with {@link #newIssueBuilder()}. 137 * <p/> 138 * This method is usually called from {@link org.sonar.api.batch.Sensor}s. {@link org.sonar.api.batch.Decorator}s calling this 139 * method must be annotated with {@code @DependedUpon(DecoratorBarriers.ISSUES_ADDED)}. 140 * 141 * @return true if the new issue is registered, false if the related rule does not exist or is disabled in the Quality profile. 142 */ 143 boolean addIssue(Issue issue); 144 145 /** 146 * @deprecated since 5.2 no more decorators on batch side 147 */ 148 @Deprecated 149 List<Issue> issues(); 150 151 /** 152 * @deprecated since 5.2 no more decorators on batch side 153 */ 154 @Deprecated 155 List<Issue> resolvedIssues(); 156}