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 */ 020package org.sonar.api.batch.fs; 021 022import org.sonar.api.BatchComponent; 023 024import javax.annotation.CheckForNull; 025import java.io.File; 026import java.nio.charset.Charset; 027import java.util.SortedSet; 028 029/** 030 * <p>The unit tests needing an instance of FileSystem can use the implementation 031 * {@link org.sonar.api.batch.fs.internal.DefaultFileSystem} and the related {@link org.sonar.api.scan.filesystem.internal.DefaultInputFile}:</p> 032 * <pre> 033 * DefaultFileSystem fs = new DefaultFileSystem(); 034 * fs.add(new DefaultInputFile("src/foo/bar.php")); 035 * </pre> 036 * 037 * @since 4.2 038 */ 039public interface FileSystem extends BatchComponent { 040 041 /** 042 * Absolute base directory of module 043 */ 044 File baseDir(); 045 046 /** 047 * Default encoding of input files. If it's not defined, then 048 * the platform default encoding is returned 049 */ 050 Charset encoding(); 051 052 /** 053 * Absolute work directory. It can be used to 054 * store third-party analysis reports. 055 * <p/> 056 * The work directory can be located outside {@link #baseDir()}. 057 */ 058 File workDir(); 059 060 /** 061 * Returns the single element matching the predicate. If more than one elements match 062 * the predicate, then {@link IllegalArgumentException} is thrown. Returns {@code null} 063 * if no files match. 064 * @see org.sonar.api.batch.fs.FilePredicates 065 */ 066 @CheckForNull 067 InputFile inputFile(FilePredicate predicate); 068 069 /** 070 * Input files matching the given attributes. Return all the files if the parameter 071 * <code>attributes</code> is empty. 072 * <p/> 073 * Important - result is an {@link java.lang.Iterable} to benefit from streaming and decreasing 074 * memory consumption. It should be iterated only once, else copy it into a list : 075 * {@code com.google.common.collect.Lists.newArrayList(inputFiles(predicate))} 076 * @see org.sonar.api.batch.fs.FilePredicates 077 */ 078 Iterable<InputFile> inputFiles(FilePredicate predicate); 079 080 /** 081 * Returns true if at least one {@link org.sonar.api.batch.fs.InputFile} matches 082 * the given predicate. This method can be faster than checking if {@link #inputFiles(org.sonar.api.batch.fs.FilePredicate...)} 083 * has elements. 084 * @see org.sonar.api.batch.fs.FilePredicates 085 */ 086 boolean hasFiles(FilePredicate predicate); 087 088 /** 089 * Files matching the given predicate. 090 * @see org.sonar.api.batch.fs.FilePredicates 091 */ 092 Iterable<File> files(FilePredicate predicate); 093 094 /** 095 * Languages detected in all files, whatever their type (main or test) 096 */ 097 SortedSet<String> languages(); 098}