001    /*
002     * Sonar, open source software quality management tool.
003     * Copyright (C) 2009 SonarSource SA
004     * mailto:contact AT sonarsource DOT com
005     *
006     * Sonar 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     * Sonar 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
017     * License along with Sonar; if not, write to the Free Software
018     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
019     */
020    package org.sonar.api.resources;
021    
022    import java.io.File;
023    import java.io.IOException;
024    import java.nio.charset.Charset;
025    import java.util.List;
026    
027    /**
028     * @since 1.10
029     */
030    public interface ProjectFileSystem {
031      /**
032       * Source encoding. It's the default plateform charset if it is not defined in the project
033       * (Maven property 'project.build.sourceEncoding').
034       */
035      Charset getSourceCharset();
036    
037      /**
038       * Project root directory.
039       */
040      File getBasedir();
041    
042      /**
043       * Build directory. It's "${basedir}/target" by default in Maven projects.
044       */
045      File getBuildDir();
046    
047      File getBuildOutputDir();
048    
049      List<File> getSourceDirs();
050    
051      ProjectFileSystem addSourceDir(File dir);
052    
053      List<File> getTestDirs();
054    
055      ProjectFileSystem addTestDir(File dir);
056    
057      File getReportOutputDir();
058    
059      File getSonarWorkingDirectory();
060    
061      /**
062       * Get file from path. It can be absolute or relative to project basedir. For example resolvePath("pom.xml") or resolvePath("src/main/java")
063       */
064      File resolvePath(String path);
065    
066      /**
067       * Source files, excluding unit tests and files matching project exclusion patterns.
068       *
069       * @param langs language filter. Check all files, whatever their language, if null or empty.
070       */
071      List<File> getSourceFiles(Language... langs);
072    
073      /**
074       * Java source files, excluding unit tests and files matching project exclusion patterns.
075       * Shortcut for getSourceFiles(Java.INSTANCE)
076       */
077      List<File> getJavaSourceFiles();
078    
079      /**
080       * Check if the project has Java files, excluding unit tests and files matching project exclusion patterns.
081       */
082      boolean hasJavaSourceFiles();
083    
084      /**
085       * Unit test files, excluding files matching project exclusion patterns.
086       */
087      List<File> getTestFiles(Language... langs);
088    
089      /**
090       * Check if the project has unit test files, excluding files matching project exclusion patterns.
091       */
092      boolean hasTestFiles(Language lang);
093    
094      /**
095       * Save data into a new file of Sonar working directory.
096       *
097       * @return the created file
098       */
099      File writeToWorkingDirectory(String content, String fileName) throws IOException;
100    
101      File getFileFromBuildDirectory(String filename);
102    
103      Resource toResource(File file);
104    }