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 org.sonar.api.component.Perspective; 024import org.sonar.api.rule.RuleKey; 025 026import javax.annotation.Nullable; 027 028import java.util.List; 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 */ 072 IssueBuilder line(@Nullable Integer line); 073 074 /** 075 * Optional, but recommended, plain-text message. 076 * <p/> 077 * Formats like Markdown or HTML are not supported. Size must not be greater than {@link Issue#MESSAGE_MAX_SIZE} characters. 078 */ 079 IssueBuilder message(@Nullable String message); 080 081 /** 082 * Overrides the severity declared in Quality profile. Do not execute in standard use-cases. 083 * @see org.sonar.api.rule.Severity 084 */ 085 IssueBuilder severity(@Nullable String severity); 086 087 /** 088 * Login of the user who reported the issue. Optional. 089 */ 090 IssueBuilder reporter(@Nullable String reporter); 091 092 IssueBuilder effortToFix(@Nullable Double d); 093 094 IssueBuilder attribute(String key, @Nullable String value); 095 096 Issue build(); 097 } 098 099 /** 100 * Builder is used to create the issue to be passed to {@link #addIssue(Issue)} 101 */ 102 IssueBuilder newIssueBuilder(); 103 104 /** 105 * Register an issue created with {@link #newIssueBuilder()}. 106 * <p/> 107 * This method is usually called from {@link org.sonar.api.batch.Sensor}s. {@link org.sonar.api.batch.Decorator}s calling this 108 * method must be annotated with {@code @DependedUpon(DecoratorBarriers.ISSUES_ADDED)}. 109 * 110 * @return true if the new issue is registered, false if the related rule does not exist or is disabled in the Quality profile. 111 */ 112 boolean addIssue(Issue issue); 113 114 /** 115 * Unresolved issues, including the issues reported by end-users. 116 * <p/> 117 * {@link org.sonar.api.batch.Decorator}s calling this method must be annotated with {@code @DependsUpon(DecoratorBarriers.ISSUES_TRACKED)}. 118 */ 119 List<Issue> issues(); 120 121 /** 122 * Issues marked as resolved during this scan. 123 * <p/> 124 * {@link org.sonar.api.batch.Decorator}s calling this method must be annotated with {@code @DependsUpon(DecoratorBarriers.ISSUES_TRACKED)}. 125 */ 126 List<Issue> resolvedIssues(); 127}