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 private boolean global = false; 036 037 public String name() { 038 return name; 039 } 040 041 public Collection<String> languages() { 042 return Arrays.asList(languages); 043 } 044 045 @Nullable 046 public InputFile.Type type() { 047 return type; 048 } 049 050 public Collection<String> ruleRepositories() { 051 return Arrays.asList(ruleRepositories); 052 } 053 054 public Collection<String> properties() { 055 return Arrays.asList(properties); 056 } 057 058 public boolean isGlobal() { 059 return global; 060 } 061 062 @Override 063 public DefaultSensorDescriptor name(String name) { 064 this.name = name; 065 return this; 066 } 067 068 @Override 069 public DefaultSensorDescriptor onlyOnLanguage(String languageKey) { 070 return onlyOnLanguages(languageKey); 071 } 072 073 @Override 074 public DefaultSensorDescriptor onlyOnLanguages(String... languageKeys) { 075 this.languages = languageKeys; 076 return this; 077 } 078 079 @Override 080 public DefaultSensorDescriptor onlyOnFileType(InputFile.Type type) { 081 this.type = type; 082 return this; 083 } 084 085 @Override 086 public DefaultSensorDescriptor createIssuesForRuleRepository(String... repositoryKey) { 087 return createIssuesForRuleRepositories(repositoryKey); 088 } 089 090 @Override 091 public DefaultSensorDescriptor createIssuesForRuleRepositories(String... repositoryKeys) { 092 this.ruleRepositories = repositoryKeys; 093 return this; 094 } 095 096 @Override 097 public DefaultSensorDescriptor requireProperty(String... propertyKey) { 098 return requireProperties(propertyKey); 099 } 100 101 @Override 102 public DefaultSensorDescriptor requireProperties(String... propertyKeys) { 103 this.properties = propertyKeys; 104 return this; 105 } 106 107 @Override 108 public SensorDescriptor global() { 109 this.global = true; 110 return this; 111 } 112 113}