use of com.puppycrawl.tools.checkstyle.BriefUtLogger in project checkstyle by checkstyle.
the class BaseCheckTestSupport method createChecker.
/**
* Creates {@link Checker} instance based on specified {@link Configuration}.
* @param checkConfig {@link Configuration} instance.
* @return {@link Checker} instance.
* @throws CheckstyleException if an exception occurs during checker configuration.
*/
protected Checker createChecker(Configuration checkConfig) throws Exception {
final DefaultConfiguration dc = createCheckerConfig(checkConfig);
final Checker checker = new Checker();
// make sure the tests always run with English error messages
// so the tests don't fail in supported locales like German
final Locale locale = Locale.ENGLISH;
checker.setLocaleCountry(locale.getCountry());
checker.setLocaleLanguage(locale.getLanguage());
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.configure(dc);
checker.addListener(new BriefUtLogger(stream));
return checker;
}
use of com.puppycrawl.tools.checkstyle.BriefUtLogger in project checkstyle by checkstyle.
the class SuppressionCommentFilterTest method createChecker.
@Override
public Checker createChecker(Configuration checkConfig) throws CheckstyleException {
final DefaultConfiguration checkerConfig = new DefaultConfiguration("configuration");
final DefaultConfiguration checksConfig = createCheckConfig(TreeWalker.class);
checksConfig.addChild(createCheckConfig(FileContentsHolder.class));
final DefaultConfiguration memberNameCheckConfig = createCheckConfig(MemberNameCheck.class);
memberNameCheckConfig.addAttribute("id", "ignore");
checksConfig.addChild(memberNameCheckConfig);
final DefaultConfiguration constantNameCheckConfig = createCheckConfig(ConstantNameCheck.class);
constantNameCheckConfig.addAttribute("id", null);
checksConfig.addChild(constantNameCheckConfig);
checksConfig.addChild(createCheckConfig(IllegalCatchCheck.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.BriefUtLogger in project checkstyle by checkstyle.
the class SuppressionFilterTest method testLocalFileExternalResourceContentDoesNotChange.
@Test
public void testLocalFileExternalResourceContentDoesNotChange() throws Exception {
final DefaultConfiguration filterConfig = createCheckConfig(SuppressionFilter.class);
filterConfig.addAttribute("file", getPath("suppressions_none.xml"));
final DefaultConfiguration checkerConfig = new DefaultConfiguration("checkstyle_checks");
checkerConfig.addChild(filterConfig);
final String cacheFile = temporaryFolder.newFile().getPath();
checkerConfig.addAttribute("cacheFile", cacheFile);
final Checker checker = new Checker();
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.addListener(new BriefUtLogger(stream));
checker.configure(checkerConfig);
final String filePath = temporaryFolder.newFile("file.java").getPath();
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checker, filePath, expected);
// One more time to use cache.
verify(checker, filePath, expected);
}
use of com.puppycrawl.tools.checkstyle.BriefUtLogger in project checkstyle by checkstyle.
the class SuppressWithNearbyCommentFilterTest method createChecker.
@Override
public Checker createChecker(Configuration checkConfig) throws CheckstyleException {
final DefaultConfiguration checkerConfig = new DefaultConfiguration("configuration");
final DefaultConfiguration checksConfig = createCheckConfig(TreeWalker.class);
checksConfig.addChild(createCheckConfig(FileContentsHolder.class));
final DefaultConfiguration memberNameCheckConfig = createCheckConfig(MemberNameCheck.class);
memberNameCheckConfig.addAttribute("id", "ignore");
checksConfig.addChild(memberNameCheckConfig);
final DefaultConfiguration constantNameCheckConfig = createCheckConfig(ConstantNameCheck.class);
constantNameCheckConfig.addAttribute("id", null);
checksConfig.addChild(constantNameCheckConfig);
checksConfig.addChild(createCheckConfig(IllegalCatchCheck.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.BriefUtLogger in project checkstyle by checkstyle.
the class HeaderCheckTest method testCacheHeaderWithoutFile.
@Test
public void testCacheHeaderWithoutFile() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(HeaderCheck.class);
checkConfig.addAttribute("header", "Test");
final DefaultConfiguration checkerConfig = new DefaultConfiguration("checkstyle_checks");
checkerConfig.addChild(checkConfig);
checkerConfig.addAttribute("cacheFile", temporaryFolder.newFile().getPath());
final Checker checker = new Checker();
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.configure(checkerConfig);
checker.addListener(new BriefUtLogger(stream));
final String[] expected = { "1: " + getCheckMessage(MSG_MISMATCH, "Test") };
verify(checker, getPath("InputHeader.java"), expected);
}
Aggregations