001/*
002 * SonarQube
003 * Copyright (C) 2009-2016 SonarSource SA
004 * mailto:contact AT sonarsource DOT com
005 *
006 * This program 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 * This program 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 */
020package org.sonar.api.batch.sensor;
021
022import java.io.Serializable;
023import org.sonar.api.batch.fs.FileSystem;
024import org.sonar.api.batch.fs.InputModule;
025import org.sonar.api.batch.rule.ActiveRules;
026import org.sonar.api.batch.sensor.coverage.NewCoverage;
027import org.sonar.api.batch.sensor.cpd.NewCpdTokens;
028import org.sonar.api.batch.sensor.highlighting.NewHighlighting;
029import org.sonar.api.batch.sensor.internal.SensorContextTester;
030import org.sonar.api.batch.sensor.issue.Issue;
031import org.sonar.api.batch.sensor.issue.NewIssue;
032import org.sonar.api.batch.sensor.measure.Measure;
033import org.sonar.api.batch.sensor.measure.NewMeasure;
034import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
035import org.sonar.api.config.Settings;
036import org.sonar.api.utils.Version;
037
038/**
039 * See {@link Sensor#execute(SensorContext)}
040 * In order to write unit tests you can use {@link SensorContextTester}
041 * @since 5.1
042 */
043public interface SensorContext {
044
045  /**
046   * Get settings of the current module.
047   */
048  Settings settings();
049
050  /**
051   * Get filesystem of the current module.
052   */
053  FileSystem fileSystem();
054
055  /**
056   * Get list of active rules.
057   */
058  ActiveRules activeRules();
059
060  /**
061   * @since 5.5
062   */
063  InputModule module();
064
065  /**
066   * @since 5.5
067   */
068  Version getSonarQubeVersion();
069
070  // ----------- MEASURES --------------
071
072  /**
073   * Fluent builder to create a new {@link Measure}. Don't forget to call {@link NewMeasure#save()} once all parameters are provided.
074   */
075  <G extends Serializable> NewMeasure<G> newMeasure();
076
077  // ----------- ISSUES --------------
078
079  /**
080   * Fluent builder to create a new {@link Issue}. Don't forget to call {@link NewIssue#save()} once all parameters are provided.
081   */
082  NewIssue newIssue();
083
084  // ------------ HIGHLIGHTING ------------
085
086  /**
087   * Builder to define highlighting of a file. Don't forget to call {@link NewHighlighting#save()} once all elements are provided.
088   */
089  NewHighlighting newHighlighting();
090
091  // ------------ SYMBOL TABLE ------------
092
093  /**
094   * Builder to define symbol table of a file. Don't forget to call {@link NewSymbolTable#save()} once all symbols are provided.
095   * @since 5.6
096   */
097  NewSymbolTable newSymbolTable();
098
099  // ------------ TESTS ------------
100
101  /**
102   * Builder to define coverage in a file.
103   * Don't forget to call {@link NewCoverage#save()}.
104   */
105  NewCoverage newCoverage();
106
107  // ------------ CPD ------------
108
109  /**
110   * Builder to define CPD tokens in a file.
111   * Don't forget to call {@link NewCpdTokens#save()}.
112   * @since 5.5
113   */
114  NewCpdTokens newCpdTokens();
115
116}