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 platform charset if it is not defined in the project (Maven property 'project.build.sourceEncoding').
033       */
034      Charset getSourceCharset();
035    
036      /**
037       * Project root directory.
038       */
039      File getBasedir();
040    
041      /**
042       * Build directory. It's "${basedir}/target" by default in Maven projects.
043       */
044      File getBuildDir();
045    
046      File getBuildOutputDir();
047    
048      List<File> getSourceDirs();
049    
050      ProjectFileSystem addSourceDir(File dir);
051    
052      List<File> getTestDirs();
053    
054      ProjectFileSystem addTestDir(File dir);
055    
056      File getReportOutputDir();
057    
058      File getSonarWorkingDirectory();
059    
060      /**
061       * Get file from path. It can be absolute or relative to project basedir. For example resolvePath("pom.xml") or
062       * 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. Shortcut for getSourceFiles(Java.INSTANCE)
075       */
076      List<File> getJavaSourceFiles();
077    
078      /**
079       * Check if the project has Java files, excluding unit tests and files matching project exclusion patterns.
080       */
081      boolean hasJavaSourceFiles();
082    
083      /**
084       * Unit test files, excluding files matching project exclusion patterns.
085       */
086      List<File> getTestFiles(Language... langs);
087    
088      /**
089       * Check if the project has unit test files, excluding files matching project exclusion patterns.
090       */
091      boolean hasTestFiles(Language lang);
092    
093      /**
094       * Save data into a new file of Sonar working directory.
095       * 
096       * @return the created file
097       */
098      File writeToWorkingDirectory(String content, String fileName) throws IOException;
099    
100      File getFileFromBuildDirectory(String filename);
101    
102      Resource toResource(File file);
103    }