Search in sources :

Example 1 with BriefUtLogger

use of com.puppycrawl.tools.checkstyle.BriefUtLogger 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);
    }
}
Also used : Checker(com.puppycrawl.tools.checkstyle.Checker) DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) BriefUtLogger(com.puppycrawl.tools.checkstyle.BriefUtLogger) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with BriefUtLogger

use of com.puppycrawl.tools.checkstyle.BriefUtLogger 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;
}
Also used : Locale(java.util.Locale) JavadocTypeCheck(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck) Checker(com.puppycrawl.tools.checkstyle.Checker) ParameterNumberCheck(com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck) DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) BriefUtLogger(com.puppycrawl.tools.checkstyle.BriefUtLogger) IllegalCatchCheck(com.puppycrawl.tools.checkstyle.checks.coding.IllegalCatchCheck)

Example 3 with BriefUtLogger

use of com.puppycrawl.tools.checkstyle.BriefUtLogger 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;
}
Also used : Checker(com.puppycrawl.tools.checkstyle.Checker) DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) BriefUtLogger(com.puppycrawl.tools.checkstyle.BriefUtLogger)

Example 4 with BriefUtLogger

use of com.puppycrawl.tools.checkstyle.BriefUtLogger in project checkstyle by checkstyle.

the class HeaderCheckTest method testCacheHeaderFile.

@Test
public void testCacheHeaderFile() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(HeaderCheck.class);
    checkConfig.addAttribute("headerFile", getConfigPath("java.header"));
    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_MISSING) };
    verify(checker, getPath("InputHeader.java"), expected);
    // One more time to use cache.
    verify(checker, getPath("InputHeader.java"), expected);
}
Also used : Checker(com.puppycrawl.tools.checkstyle.Checker) DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) BriefUtLogger(com.puppycrawl.tools.checkstyle.BriefUtLogger) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with BriefUtLogger

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;
}
Also used : Locale(java.util.Locale) Checker(com.puppycrawl.tools.checkstyle.Checker) DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) BriefUtLogger(com.puppycrawl.tools.checkstyle.BriefUtLogger)

Aggregations

BriefUtLogger (com.puppycrawl.tools.checkstyle.BriefUtLogger)10 Checker (com.puppycrawl.tools.checkstyle.Checker)10 DefaultConfiguration (com.puppycrawl.tools.checkstyle.DefaultConfiguration)10 Locale (java.util.Locale)5 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 IllegalCatchCheck (com.puppycrawl.tools.checkstyle.checks.coding.IllegalCatchCheck)3 FileContentsHolder (com.puppycrawl.tools.checkstyle.checks.FileContentsHolder)2 JavadocTypeCheck (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck)1 ParameterNumberCheck (com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck)1