001 /* 002 * SonarQube, open source software quality management tool. 003 * Copyright (C) 2008-2013 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 */ 020 package org.sonar.api.scan.filesystem; 021 022 import com.google.common.collect.Lists; 023 import com.google.common.collect.Sets; 024 025 import java.io.FileFilter; 026 import java.util.Arrays; 027 import java.util.Collection; 028 import java.util.Set; 029 030 /** 031 * @since 3.5 032 */ 033 public class FileQuery { 034 035 public static FileQuery on(FileType... types) { 036 return new FileQuery(types); 037 } 038 039 public static FileQuery onSource() { 040 return on(FileType.SOURCE); 041 } 042 043 public static FileQuery onTest() { 044 return on(FileType.TEST); 045 } 046 047 private final Set<FileType> types; 048 private final Set<String> languages = Sets.newLinkedHashSet(); 049 private final Set<String> inclusions = Sets.newLinkedHashSet(); 050 private final Set<String> exclusions = Sets.newLinkedHashSet(); 051 private final Collection<FileFilter> filters = Lists.newLinkedList(); 052 053 private FileQuery(FileType... types) { 054 this.types = Sets.newHashSet(types); 055 } 056 057 public Collection<FileType> types() { 058 return types; 059 } 060 061 public Collection<String> languages() { 062 return languages; 063 } 064 065 public FileQuery onLanguage(String... languages) { 066 this.languages.addAll(Arrays.asList(languages)); 067 return this; 068 } 069 070 public Collection<String> inclusions() { 071 return inclusions; 072 } 073 074 public FileQuery withInclusions(String... inclusions) { 075 this.inclusions.addAll(Arrays.asList(inclusions)); 076 return this; 077 } 078 079 public Collection<String> exclusions() { 080 return exclusions; 081 } 082 083 public FileQuery withExclusions(String... exclusions) { 084 this.exclusions.addAll(Arrays.asList(exclusions)); 085 return this; 086 } 087 088 public Collection<FileFilter> filters() { 089 return filters; 090 } 091 092 public FileQuery withFilters(FileFilter... filters) { 093 this.filters.addAll(Arrays.asList(filters)); 094 return this; 095 } 096 } 097