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.internal;
021
022import java.util.Arrays;
023import java.util.Collection;
024import javax.annotation.Nullable;
025import org.sonar.api.batch.fs.InputFile;
026import org.sonar.api.batch.sensor.SensorDescriptor;
027
028public class DefaultSensorDescriptor implements SensorDescriptor {
029
030  private String name;
031  private String[] languages = new String[0];
032  private InputFile.Type type = null;
033  private String[] ruleRepositories = new String[0];
034  private String[] properties = new String[0];
035
036  public String name() {
037    return name;
038  }
039
040  public Collection<String> languages() {
041    return Arrays.asList(languages);
042  }
043
044  @Nullable
045  public InputFile.Type type() {
046    return type;
047  }
048
049  public Collection<String> ruleRepositories() {
050    return Arrays.asList(ruleRepositories);
051  }
052
053  public Collection<String> properties() {
054    return Arrays.asList(properties);
055  }
056
057  @Override
058  public DefaultSensorDescriptor name(String name) {
059    this.name = name;
060    return this;
061  }
062
063  @Override
064  public DefaultSensorDescriptor onlyOnLanguage(String languageKey) {
065    return onlyOnLanguages(languageKey);
066  }
067
068  @Override
069  public DefaultSensorDescriptor onlyOnLanguages(String... languageKeys) {
070    this.languages = languageKeys;
071    return this;
072  }
073
074  @Override
075  public DefaultSensorDescriptor onlyOnFileType(InputFile.Type type) {
076    this.type = type;
077    return this;
078  }
079
080  @Override
081  public DefaultSensorDescriptor createIssuesForRuleRepository(String... repositoryKey) {
082    return createIssuesForRuleRepositories(repositoryKey);
083  }
084
085  @Override
086  public DefaultSensorDescriptor createIssuesForRuleRepositories(String... repositoryKeys) {
087    this.ruleRepositories = repositoryKeys;
088    return this;
089  }
090
091  @Override
092  public DefaultSensorDescriptor requireProperty(String... propertyKey) {
093    return requireProperties(propertyKey);
094  }
095
096  @Override
097  public DefaultSensorDescriptor requireProperties(String... propertyKeys) {
098    this.properties = propertyKeys;
099    return this;
100  }
101
102}