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()));
}
}
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);
}
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);
}
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());
}
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);
}
}
Aggregations