use of net.sourceforge.pmd.lang.LanguageFilenameFilter in project pmd by pmd.
the class FileSelectorTest method testUnwantedJavaFile.
/**
* Test unwanted selection of a java file.
*/
@Test
public void testUnwantedJavaFile() {
LanguageFilenameFilter fileSelector = new LanguageFilenameFilter(LanguageRegistry.getLanguage(DummyLanguageModule.NAME));
File javaFile = new File("/path/to/MyClass.java");
boolean selected = fileSelector.accept(javaFile.getParentFile(), javaFile.getName());
assertEquals("Unwanted java file must not be selected!", false, selected);
}
use of net.sourceforge.pmd.lang.LanguageFilenameFilter in project pmd by pmd.
the class FileSelectorTest method testWantedFile.
/**
* Test wanted selection of a source file.
*/
@Test
public void testWantedFile() {
LanguageFilenameFilter fileSelector = new LanguageFilenameFilter(LanguageRegistry.getLanguage(DummyLanguageModule.NAME));
File javaFile = new File("/path/to/myFile.dummy");
boolean selected = fileSelector.accept(javaFile.getParentFile(), javaFile.getName());
assertEquals("This file should be selected !", true, selected);
}
use of net.sourceforge.pmd.lang.LanguageFilenameFilter in project pmd by pmd.
the class FileSelectorTest method testUnwantedFile.
/**
* Test unwanted selection of a non source file.
*/
@Test
public void testUnwantedFile() {
LanguageFilenameFilter fileSelector = new LanguageFilenameFilter(LanguageRegistry.getLanguage(DummyLanguageModule.NAME));
File javaFile = new File("/path/to/myFile.txt");
boolean selected = fileSelector.accept(javaFile.getParentFile(), javaFile.getName());
assertEquals("Not-source file must not be selected!", false, selected);
}
use of net.sourceforge.pmd.lang.LanguageFilenameFilter in project pmd by pmd.
the class Benchmarker method main.
/**
* @param args
* String[]
* @throws RuleSetNotFoundException
* @throws IOException
* @throws PMDException
*/
public static void main(String[] args) throws RuleSetNotFoundException, IOException, PMDException {
String targetjdk = findOptionalStringValue(args, "--targetjdk", "1.4");
Language language = LanguageRegistry.getLanguage("Java");
LanguageVersion languageVersion = language.getVersion(targetjdk);
if (languageVersion == null) {
languageVersion = language.getDefaultVersion();
}
String srcDir = findOptionalStringValue(args, "--source-directory", "/usr/local/java/src/java/lang/");
List<DataSource> dataSources = FileUtil.collectFiles(srcDir, new LanguageFilenameFilter(language));
boolean debug = findBooleanSwitch(args, "--debug");
boolean parseOnly = findBooleanSwitch(args, "--parse-only");
if (debug) {
System.out.println("Using " + language.getName() + " " + languageVersion.getVersion());
}
if (parseOnly) {
Parser parser = PMD.parserFor(languageVersion, null);
parseStress(parser, dataSources, debug);
} else {
String ruleset = findOptionalStringValue(args, "--ruleset", "");
if (debug) {
System.out.println("Checking directory " + srcDir);
}
Set<RuleDuration> results = new TreeSet<>();
RuleSetFactory factory = new RuleSetFactory();
if (StringUtils.isNotBlank(ruleset)) {
stress(languageVersion, factory.createRuleSet(ruleset), dataSources, results, debug);
} else {
Iterator<RuleSet> i = factory.getRegisteredRuleSets();
while (i.hasNext()) {
stress(languageVersion, i.next(), dataSources, results, debug);
}
}
TextReport report = new TextReport();
report.generate(results, System.err);
}
}
use of net.sourceforge.pmd.lang.LanguageFilenameFilter in project Gargoyle by callakrsos.
the class DoPMD method internalGetApplicableFiles.
private List<DataSource> internalGetApplicableFiles(GargoylePMDConfiguration configuration, Set<Language> languages) {
List<DataSource> files = new ArrayList<>();
LanguageFilenameFilter fileSelector = new LanguageFilenameFilter(languages);
if (null != configuration.getInputPaths()) {
files.addAll(FileUtil.collectFiles(configuration.getInputPaths(), fileSelector));
}
if (null != configuration.getSourceText()) {
String filePaths = "SourceBase";
if (null != configuration.getSourceFileName()) {
filePaths = configuration.getSourceFileName();
}
filePaths = filePaths.replaceAll("\\r?\\n", ",");
filePaths = filePaths.replaceAll(",+", ",");
String sourceText = configuration.getSourceText();
try {
Reader reader = new StringReader(sourceText);
files.addAll(Arrays.asList(new ReaderDataSource(reader, filePaths)));
} catch (Exception e) {
LOGGER.error(ValueUtil.toString(e));
}
}
return files;
}
Aggregations