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