use of com.puppycrawl.tools.checkstyle.Checker in project checkstyle by checkstyle.
the class SuppressionFilterTest method testRemoteFileExternalResourceContentDoesNotChange.
@Test
public void testRemoteFileExternalResourceContentDoesNotChange() throws Exception {
final String[] urlCandidates = { "http://checkstyle.sourceforge.net/files/suppressions_none.xml", "https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/site/resources/" + "files/suppressions_none.xml" };
String urlForTest = null;
for (String url : urlCandidates) {
if (isConnectionAvailableAndStable(url)) {
urlForTest = url;
break;
}
}
// instead of a skip when it doesn't pass
if (urlForTest != null) {
final DefaultConfiguration firstFilterConfig = createCheckConfig(SuppressionFilter.class);
firstFilterConfig.addAttribute("file", urlForTest);
final DefaultConfiguration firstCheckerConfig = new DefaultConfiguration("checkstyle_checks");
firstCheckerConfig.addChild(firstFilterConfig);
final String cacheFile = temporaryFolder.newFile().getPath();
firstCheckerConfig.addAttribute("cacheFile", cacheFile);
final Checker checker = new Checker();
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.configure(firstCheckerConfig);
checker.addListener(new BriefUtLogger(stream));
final String pathToEmptyFile = temporaryFolder.newFile("file.java").getPath();
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checker, pathToEmptyFile, expected);
// One more time to use cache.
final DefaultConfiguration secondFilterConfig = createCheckConfig(SuppressionFilter.class);
secondFilterConfig.addAttribute("file", urlForTest);
final DefaultConfiguration secondCheckerConfig = new DefaultConfiguration("checkstyle_checks");
secondCheckerConfig.addAttribute("cacheFile", cacheFile);
secondCheckerConfig.addChild(secondFilterConfig);
checker.configure(secondCheckerConfig);
verify(checker, pathToEmptyFile, expected);
}
}
use of com.puppycrawl.tools.checkstyle.Checker in project checkstyle by checkstyle.
the class SuppressWarningsFilterTest method createChecker.
@Override
public Checker createChecker(Configuration checkConfig) throws Exception {
final DefaultConfiguration checkerConfig = new DefaultConfiguration("configuration");
final DefaultConfiguration checksConfig = createCheckConfig(TreeWalker.class);
final DefaultConfiguration holderConfig = createCheckConfig(SuppressWarningsHolder.class);
holderConfig.addAttribute("aliasList", "com.puppycrawl.tools.checkstyle.checks.sizes." + "ParameterNumberCheck=paramnum");
checksConfig.addChild(holderConfig);
final DefaultConfiguration memberNameCheckConfig = createCheckConfig(MemberNameCheck.class);
memberNameCheckConfig.addAttribute("id", "ignore");
checksConfig.addChild(memberNameCheckConfig);
final DefaultConfiguration constantNameCheckConfig = createCheckConfig(ConstantNameCheck.class);
constantNameCheckConfig.addAttribute("id", "");
checksConfig.addChild(constantNameCheckConfig);
checksConfig.addChild(createCheckConfig(ParameterNumberCheck.class));
checksConfig.addChild(createCheckConfig(IllegalCatchCheck.class));
final DefaultConfiguration uncommentedMainCheckConfig = createCheckConfig(UncommentedMainCheck.class);
uncommentedMainCheckConfig.addAttribute("id", "ignore");
checksConfig.addChild(uncommentedMainCheckConfig);
checksConfig.addChild(createCheckConfig(JavadocTypeCheck.class));
checkerConfig.addChild(checksConfig);
if (checkConfig != null) {
checkerConfig.addChild(checkConfig);
}
final Checker checker = new Checker();
final Locale locale = Locale.ROOT;
checker.setLocaleCountry(locale.getCountry());
checker.setLocaleLanguage(locale.getLanguage());
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.configure(checkerConfig);
checker.addListener(new BriefUtLogger(stream));
return checker;
}
use of com.puppycrawl.tools.checkstyle.Checker in project checkstyle by checkstyle.
the class ImportControlCheckTest method testCacheWhenUrlExternalResourceContentDoesNotChange.
@Test
public void testCacheWhenUrlExternalResourceContentDoesNotChange() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class);
checkConfig.addAttribute("url", getUriString("import-control_one.xml"));
final Checker checker = createMockCheckerWithCache(checkConfig);
final String pathToEmptyFile = temporaryFolder.newFile("TestFile.java").getPath();
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checker, pathToEmptyFile, pathToEmptyFile, expected);
// One more time to use cache.
verify(checker, pathToEmptyFile, pathToEmptyFile, expected);
}
use of com.puppycrawl.tools.checkstyle.Checker in project checkstyle by checkstyle.
the class ImportControlCheckTest method createMockCheckerWithCache.
private Checker createMockCheckerWithCache(DefaultConfiguration checkConfig) throws IOException, CheckstyleException {
final DefaultConfiguration treeWalkerConfig = createCheckConfig(TreeWalker.class);
treeWalkerConfig.addChild(checkConfig);
final DefaultConfiguration checkerConfig = new DefaultConfiguration("checkstyle_checks");
checkerConfig.addChild(treeWalkerConfig);
checkerConfig.addAttribute("cacheFile", temporaryFolder.newFile().getPath());
final Checker checker = new Checker();
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.configure(checkerConfig);
checker.addListener(new BriefUtLogger(stream));
return checker;
}
use of com.puppycrawl.tools.checkstyle.Checker in project checkstyle by checkstyle.
the class ImportControlCheckTest method testCacheWhenFileExternalResourceContentDoesNotChange.
@Test
public void testCacheWhenFileExternalResourceContentDoesNotChange() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class);
checkConfig.addAttribute("file", getPath("import-control_one-re.xml"));
final Checker checker = createMockCheckerWithCache(checkConfig);
final String filePath = temporaryFolder.newFile("EmptyFile.java").getPath();
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checker, filePath, filePath, expected);
// One more time to use cache.
verify(checker, filePath, filePath, expected);
}
Aggregations