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.sensor; 021 022 import com.google.common.annotations.Beta; 023 import org.sonar.api.batch.fs.FileSystem; 024 import org.sonar.api.batch.fs.InputFile; 025 import org.sonar.api.batch.measure.Metric; 026 import org.sonar.api.batch.rule.ActiveRules; 027 import org.sonar.api.batch.sensor.duplication.DuplicationBuilder; 028 import org.sonar.api.batch.sensor.duplication.DuplicationGroup; 029 import org.sonar.api.batch.sensor.duplication.DuplicationTokenBuilder; 030 import org.sonar.api.batch.sensor.highlighting.HighlightingBuilder; 031 import org.sonar.api.batch.sensor.issue.Issue; 032 import org.sonar.api.batch.sensor.issue.IssueBuilder; 033 import org.sonar.api.batch.sensor.measure.Measure; 034 import org.sonar.api.batch.sensor.measure.MeasureBuilder; 035 import org.sonar.api.batch.sensor.symbol.SymbolTableBuilder; 036 import org.sonar.api.config.Settings; 037 038 import javax.annotation.CheckForNull; 039 040 import java.io.Serializable; 041 import java.util.List; 042 043 /** 044 * Experimental - do not use 045 * @since 4.4 046 */ 047 @Beta 048 public interface SensorContext { 049 050 /** 051 * Get settings of the current project. 052 */ 053 Settings settings(); 054 055 /** 056 * Get filesystem of the current project. 057 */ 058 FileSystem fileSystem(); 059 060 /** 061 * Get list of active rules. 062 */ 063 ActiveRules activeRules(); 064 065 // ----------- MEASURES -------------- 066 067 /** 068 * Builder to create a new {@link Measure}. 069 */ 070 <G extends Serializable> MeasureBuilder<G> measureBuilder(); 071 072 /** 073 * Find a project measure. 074 */ 075 @CheckForNull 076 Measure getMeasure(String metricKey); 077 078 /** 079 * Find a project measure. 080 */ 081 @CheckForNull 082 <G extends Serializable> Measure<G> getMeasure(Metric<G> metric); 083 084 /** 085 * Find a file measure. 086 */ 087 @CheckForNull 088 Measure getMeasure(InputFile file, String metricKey); 089 090 /** 091 * Find a file measure. 092 */ 093 @CheckForNull 094 <G extends Serializable> Measure<G> getMeasure(InputFile file, Metric<G> metric); 095 096 /** 097 * Add a measure. Use {@link #measureBuilder()} to create the new measure. 098 * A measure for a given metric can only be saved once for the same resource. 099 */ 100 void addMeasure(Measure<?> measure); 101 102 // ----------- ISSUES -------------- 103 104 /** 105 * Builder to create a new {@link Issue}. 106 */ 107 IssueBuilder issueBuilder(); 108 109 /** 110 * Add an issue. Use {@link #issueBuilder()} to create the new issue. 111 * @return <code>true</code> if the new issue is registered, <code>false</code> if: 112 * <ul> 113 * <li>the rule does not exist</li> 114 * <li>the rule is disabled in the Quality profile</li> 115 * </ul> 116 */ 117 boolean addIssue(Issue issue); 118 119 // ------------ HIGHLIGHTING ------------ 120 121 /** 122 * Builder to define highlighting of a file. 123 * @since 4.5 124 */ 125 HighlightingBuilder highlightingBuilder(InputFile inputFile); 126 127 // ------------ SYMBOL REFERENCES ------------ 128 129 /** 130 * Builder to define symbol references in a file. 131 * @since 4.5 132 */ 133 SymbolTableBuilder symbolTableBuilder(InputFile inputFile); 134 135 // ------------ DUPLICATIONS ------------ 136 137 /** 138 * Builder to define tokens in a file. Tokens are used to compute duplication using default SonarQube engine. 139 * @since 4.5 140 */ 141 DuplicationTokenBuilder duplicationTokenBuilder(InputFile inputFile); 142 143 /** 144 * Builder to manually define duplications in a file. When duplication are manually computed then 145 * no need to use {@link #duplicationTokenBuilder(InputFile)}. 146 * @since 4.5 147 */ 148 DuplicationBuilder duplicationBuilder(InputFile inputFile); 149 150 /** 151 * Register all duplications of an {@link InputFile}. Use {@link #duplicationBuilder(InputFile)} to create 152 * list of duplications. 153 */ 154 void saveDuplications(InputFile inputFile, List<DuplicationGroup> duplications); 155 156 }