Search in sources :

Example 6 with LanguageFilenameFilter

use of net.sourceforge.pmd.lang.LanguageFilenameFilter in project pmd by pmd.

the class PMD method internalGetApplicableFiles.

private static List<DataSource> internalGetApplicableFiles(PMDConfiguration configuration, Set<Language> languages) {
    LanguageFilenameFilter fileSelector = new LanguageFilenameFilter(languages);
    List<DataSource> files = new ArrayList<>();
    if (null != configuration.getInputPaths()) {
        files.addAll(FileUtil.collectFiles(configuration.getInputPaths(), fileSelector));
    }
    if (null != configuration.getInputUri()) {
        String uriString = configuration.getInputUri();
        try {
            List<DataSource> dataSources = getURIDataSources(uriString);
            files.addAll(dataSources);
        } catch (PMDException ex) {
            LOG.log(Level.SEVERE, "Problem with Input URI", ex);
            throw new RuntimeException("Problem with DBURI: " + uriString, ex);
        }
    }
    if (null != configuration.getInputFilePath()) {
        String inputFilePath = configuration.getInputFilePath();
        File file = new File(inputFilePath);
        try {
            if (!file.exists()) {
                LOG.log(Level.SEVERE, "Problem with Input File Path", inputFilePath);
                throw new RuntimeException("Problem with Input File Path: " + inputFilePath);
            } else {
                String filePaths = FileUtil.readFilelist(new File(inputFilePath));
                files.addAll(FileUtil.collectFiles(filePaths, fileSelector));
            }
        } catch (IOException ex) {
            LOG.log(Level.SEVERE, "Problem with Input File", ex);
            throw new RuntimeException("Problem with Input File Path: " + inputFilePath, ex);
        }
    }
    return files;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) LanguageFilenameFilter(net.sourceforge.pmd.lang.LanguageFilenameFilter) DataSource(net.sourceforge.pmd.util.datasource.DataSource) ReaderDataSource(net.sourceforge.pmd.util.datasource.ReaderDataSource)

Aggregations

LanguageFilenameFilter (net.sourceforge.pmd.lang.LanguageFilenameFilter)6 File (java.io.File)4 DataSource (net.sourceforge.pmd.util.datasource.DataSource)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ReaderDataSource (net.sourceforge.pmd.util.datasource.ReaderDataSource)2 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 TreeSet (java.util.TreeSet)1 RuleSet (net.sourceforge.pmd.RuleSet)1 RuleSetFactory (net.sourceforge.pmd.RuleSetFactory)1 Language (net.sourceforge.pmd.lang.Language)1 LanguageVersion (net.sourceforge.pmd.lang.LanguageVersion)1 Parser (net.sourceforge.pmd.lang.Parser)1