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