Search in sources :

Example 1 with CheckStyleChecker

use of org.infernus.idea.checkstyle.checker.CheckStyleChecker in project checkstyle-idea by jshiell.

the class ServiceLayerBasicTest method aCustomCheckThatUsedApisBrokenIn6_6And6_7DoesNotWorkWithTheseRuntimes.

@Test
public void aCustomCheckThatUsedApisBrokenIn6_6And6_7DoesNotWorkWithTheseRuntimes() throws IOException, URISyntaxException {
    assumeThat(currentCsVersion(), isLessThan("8.0"));
    // noinspection ThrowableNotThrown
    CustomCheck3.popErrorOccurred4UnitTest();
    final CheckStyleChecker checker = createChecker(CONFIG_FILE_BREAKS_ON_6_6);
    runChecker(checker);
    final Throwable errorOccurred = CustomCheck3.popErrorOccurred4UnitTest();
    if (csVersionIsOneOf("6.6", "6.7")) {
        assertThat(errorOccurred, allOf(is(not(nullValue())), instanceOf(NoSuchMethodError.class), hasMessage(containsString("getFilename"))));
    } else {
        assertThat(errorOccurred, is(nullValue()));
    }
}
Also used : CheckStyleChecker(org.infernus.idea.checkstyle.checker.CheckStyleChecker) Test(org.junit.Test)

Example 2 with CheckStyleChecker

use of org.infernus.idea.checkstyle.checker.CheckStyleChecker in project checkstyle-idea by jshiell.

the class OpCreateCheckerTest method testCreateCheckerWithConfigsMock.

@Test
public void testCreateCheckerWithConfigsMock() throws IOException, URISyntaxException {
    final ConfigurationLocation configLoc = new StringConfigurationLocation(FileUtil.readFile("cmd/" + CONFIG_FILE), mock(Project.class));
    final CheckStyleChecker checker = new CheckstyleActionsImpl(PROJECT, checkstyleProjectServiceMock).createChecker(moduleMock, configLoc, emptyMap(), configurationsMock, getClass().getClassLoader());
    assertNotNull(checker);
}
Also used : CheckstyleActionsImpl(org.infernus.idea.checkstyle.service.CheckstyleActionsImpl) Project(com.intellij.openapi.project.Project) CheckStyleChecker(org.infernus.idea.checkstyle.checker.CheckStyleChecker) ConfigurationLocation(org.infernus.idea.checkstyle.model.ConfigurationLocation) StringConfigurationLocation(org.infernus.idea.checkstyle.service.StringConfigurationLocation) StringConfigurationLocation(org.infernus.idea.checkstyle.service.StringConfigurationLocation) Test(org.junit.Test)

Example 3 with CheckStyleChecker

use of org.infernus.idea.checkstyle.checker.CheckStyleChecker in project checkstyle-idea by jshiell.

the class OpCreateCheckerTest method testCreateChecker_noModule.

@Test
public void testCreateChecker_noModule() throws IOException, URISyntaxException {
    final ConfigurationLocation configLoc = new StringConfigurationLocation(FileUtil.readFile("cmd/" + CONFIG_FILE), mock(Project.class));
    // noinspection ConstantConditions
    CheckStyleChecker checker = new CheckstyleActionsImpl(PROJECT, checkstyleProjectServiceMock).createChecker(null, configLoc, emptyMap(), configurationsMock, getClass().getClassLoader());
    assertNotNull(checker);
}
Also used : CheckstyleActionsImpl(org.infernus.idea.checkstyle.service.CheckstyleActionsImpl) Project(com.intellij.openapi.project.Project) CheckStyleChecker(org.infernus.idea.checkstyle.checker.CheckStyleChecker) ConfigurationLocation(org.infernus.idea.checkstyle.model.ConfigurationLocation) StringConfigurationLocation(org.infernus.idea.checkstyle.service.StringConfigurationLocation) StringConfigurationLocation(org.infernus.idea.checkstyle.service.StringConfigurationLocation) Test(org.junit.Test)

Example 4 with CheckStyleChecker

use of org.infernus.idea.checkstyle.checker.CheckStyleChecker in project checkstyle-idea by jshiell.

the class OpCreateChecker method execute.

@Override
@NotNull
public CheckStyleChecker execute(@NotNull final Project project) throws CheckstyleException {
    final Configuration csConfig = loadConfig(project);
    final Checker checker = new Checker();
    // for Checkstyle to load modules (checks)
    checker.setModuleClassLoader(getClass().getClassLoader());
    // for checks to load the classes and resources to be analyzed
    setClassLoader(checker, loaderOfCheckedCode);
    try {
        checker.configure(csConfig);
    } catch (Error e) {
        // e.g. java.lang.NoClassDefFoundError thrown by Checkstyle for pre-8.0 custom checks
        throw new CheckstyleToolException(e);
    }
    CheckerWithConfig cwc = new CheckerWithConfig(checker, csConfig);
    final TabWidthAndBaseDirProvider configs = configurations != null ? configurations : new Configurations(module, csConfig);
    return new CheckStyleChecker(cwc, configs.tabWidth(), configs.baseDir(), checkstyleProjectService.getCheckstyleInstance());
}
Also used : CheckStyleChecker(org.infernus.idea.checkstyle.checker.CheckStyleChecker) CheckStyleChecker(org.infernus.idea.checkstyle.checker.CheckStyleChecker) Checker(com.puppycrawl.tools.checkstyle.Checker) Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) CheckerWithConfig(org.infernus.idea.checkstyle.service.entities.CheckerWithConfig) CheckstyleToolException(org.infernus.idea.checkstyle.exception.CheckstyleToolException) TabWidthAndBaseDirProvider(org.infernus.idea.checkstyle.csapi.TabWidthAndBaseDirProvider) Configurations(org.infernus.idea.checkstyle.service.Configurations) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with CheckStyleChecker

use of org.infernus.idea.checkstyle.checker.CheckStyleChecker in project checkstyle-idea by jshiell.

the class VersionMixExceptionTest method testVersionMixException.

/**
 * Test that a {@link CheckstyleVersionMixException} is thrown when a
 * {@link org.infernus.idea.checkstyle.csapi.CheckstyleInternalObject CheckstyleInternalObject} outlives its class
 * loader.
 */
public void testVersionMixException() throws IOException, URISyntaxException {
    Module module = mock(Module.class);
    when(module.getProject()).thenReturn(project);
    final CheckStyleChecker checker = createChecker(module);
    runChecker(checker);
    try {
        assertNotEquals(OTHER_VERSION, BASE_VERSION);
        // changes class loader, cause of error
        csService.activateCheckstyleVersion(OTHER_VERSION, null);
        runChecker(checker);
        fail("expected exception was not thrown");
    } catch (CheckstyleVersionMixException e) {
        // expected
        final String internalClassName = "org.infernus.idea.checkstyle.service.entities.CheckerWithConfig";
        assertTrue(e.getMessage().contains("Expected: " + internalClassName + ", actual: " + internalClassName));
    // Yes! Error, even though both class names are identical (but class loaders differ).
    } finally {
        csService.activateCheckstyleVersion(BASE_VERSION, null);
    }
}
Also used : CheckStyleChecker(org.infernus.idea.checkstyle.checker.CheckStyleChecker) CheckstyleVersionMixException(org.infernus.idea.checkstyle.exception.CheckstyleVersionMixException) Module(com.intellij.openapi.module.Module)

Aggregations

CheckStyleChecker (org.infernus.idea.checkstyle.checker.CheckStyleChecker)6 Test (org.junit.Test)3 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 ConfigurationLocation (org.infernus.idea.checkstyle.model.ConfigurationLocation)2 CheckstyleActionsImpl (org.infernus.idea.checkstyle.service.CheckstyleActionsImpl)2 StringConfigurationLocation (org.infernus.idea.checkstyle.service.StringConfigurationLocation)2 Checker (com.puppycrawl.tools.checkstyle.Checker)1 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)1 TabWidthAndBaseDirProvider (org.infernus.idea.checkstyle.csapi.TabWidthAndBaseDirProvider)1 CheckstyleToolException (org.infernus.idea.checkstyle.exception.CheckstyleToolException)1 CheckstyleVersionMixException (org.infernus.idea.checkstyle.exception.CheckstyleVersionMixException)1 Configurations (org.infernus.idea.checkstyle.service.Configurations)1 CheckerWithConfig (org.infernus.idea.checkstyle.service.entities.CheckerWithConfig)1 NotNull (org.jetbrains.annotations.NotNull)1