001/*
002 * SonarQube
003 * Copyright (C) 2009-2017 SonarSource SA
004 * mailto:info 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.util.function.Predicate;
023import org.sonar.api.batch.fs.InputFile;
024import org.sonar.api.config.Configuration;
025
026/**
027 * Describe what a {@link Sensor} is doing. Information may be used by the platform
028 * to log interesting information or perform some optimization.
029 * See {@link Sensor#describe(SensorDescriptor)}
030 * @since 5.1
031 */
032public interface SensorDescriptor {
033
034  /**
035   * Displayable name of the {@link Sensor}. Will be displayed in logs.
036   */
037  SensorDescriptor name(String sensorName);
038
039  /**
040   * Language this {@link Sensor} work on. Used by the platform to skip execution of the {@link Sensor} when
041   * no file for given languages are present in the project.
042   * Default is to execute sensor for all languages.
043   */
044  SensorDescriptor onlyOnLanguage(String languageKey);
045
046  /**
047   * List languages this {@link Sensor} work on. Used by the platform to skip execution of the {@link Sensor} when
048   * no file for given languages are present in the project.
049   * Default is to execute sensor for all languages.
050   */
051  SensorDescriptor onlyOnLanguages(String... languageKeys);
052
053  /**
054   * {@link InputFile.Type} this {@link Sensor} work on. Used by the platform to skip execution of the {@link Sensor} when
055   * no file for given type are present in the project.
056   * Default is to execute sensor whatever are the available file types.
057   */
058  SensorDescriptor onlyOnFileType(InputFile.Type type);
059
060  /**
061   * Rule repository this {@link Sensor} create issues for. Used by the platform to skip execution of the {@link Sensor} when
062   * no rule is activated for the given repository.
063   */
064  SensorDescriptor createIssuesForRuleRepository(String... repositoryKey);
065
066  /**
067   * List rule repositories this {@link Sensor} create issues for. Used by the platform to skip execution of the {@link Sensor} when
068   * no rule is activated for the given repositories.
069   */
070  SensorDescriptor createIssuesForRuleRepositories(String... repositoryKeys);
071
072  /**
073   * Property this {@link Sensor} depends on. Used by the platform to skip execution of the {@link Sensor} when
074   * property is not set.
075   * @deprecated since 6.5 use {@link #onlyWhenConfiguration(Predicate)}
076   */
077  @Deprecated
078  SensorDescriptor requireProperty(String... propertyKey);
079
080  /**
081   * List properties this {@link Sensor} depends on. Used by the platform to skip execution of the {@link Sensor} when
082   * property is not set.
083   * @deprecated since 6.5 use {@link #onlyWhenConfiguration(Predicate)}
084   */
085  @Deprecated
086  SensorDescriptor requireProperties(String... propertyKeys);
087
088  /**
089   * This sensor should be executed at the project level, instead of per-module.
090   * @since 6.4
091   */
092  SensorDescriptor global();
093
094  /**
095   * Predicate that will be evaluated on current module/project {@link Configuration} by the platform to decide if execution of the {@link Sensor} should be skipped.
096   * @since 6.5
097   */
098  SensorDescriptor onlyWhenConfiguration(Predicate<Configuration> predicate);
099}