use of org.infernus.idea.checkstyle.model.ConfigurationLocation 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.model.ConfigurationLocation in project checkstyle-idea by jshiell.
the class CheckStyleInspection method inspectFile.
private List<Problem> inspectFile(@NotNull final PsiFile psiFile, @NotNull final List<ScannableFile> scannableFiles, @Nullable final Module module, @NotNull final InspectionManager manager) {
LOG.debug("Inspection has been invoked for " + psiFile.getName());
ConfigurationLocation configurationLocation = null;
try {
configurationLocation = configurationLocationSource(manager.getProject()).getConfigurationLocation(module, null);
if (configurationLocation == null || configurationLocation.isBlocked()) {
return NO_PROBLEMS_FOUND;
}
return checkerFactory(psiFile.getProject()).checker(module, configurationLocation).map(checker -> checker.scan(scannableFiles, configurationManager(psiFile.getProject()).getCurrent().isSuppressErrors())).map(results -> results.get(psiFile)).map(this::dropIgnoredProblems).orElse(NO_PROBLEMS_FOUND);
} catch (ProcessCanceledException | AssertionError e) {
LOG.debug("Process cancelled when scanning: " + psiFile.getName());
return NO_PROBLEMS_FOUND;
} catch (CheckStylePluginParseException e) {
LOG.debug("Parse exception caught when scanning: " + psiFile.getName(), e);
return NO_PROBLEMS_FOUND;
} catch (Throwable e) {
handlePluginException(e, psiFile, configurationLocation, manager.getProject());
return NO_PROBLEMS_FOUND;
} finally {
scannableFiles.forEach(ScannableFile::deleteIfRequired);
}
}
use of org.infernus.idea.checkstyle.model.ConfigurationLocation in project checkstyle-idea by jshiell.
the class CheckstylePluginApi method visitCurrentConfiguration.
public void visitCurrentConfiguration(@NotNull final ConfigurationVisitor visitor) {
ConfigurationLocation activeLocation = pluginConfigurationManager().getCurrent().getActiveLocation();
if (activeLocation != null) {
CheckstyleActions checkstyleInstance = checkstyleProjectService().getCheckstyleInstance();
checkstyleInstance.peruseConfiguration(checkstyleInstance.loadConfiguration(activeLocation, true, new HashMap<>()), module -> visitor.accept(activeLocation.getDescription(), module));
}
}
use of org.infernus.idea.checkstyle.model.ConfigurationLocation in project checkstyle-idea by jshiell.
the class ServiceLayerBasicTest method createChecker.
private CheckStyleChecker createChecker(@NotNull final String configXmlFile) throws IOException, URISyntaxException {
final ConfigurationLocation configLoc = new StringConfigurationLocation(FileUtil.readFile(configXmlFile), mock(Project.class));
final Module module = mock(Module.class);
when(module.getProject()).thenReturn(PROJECT);
final TabWidthAndBaseDirProvider configurations = mock(TabWidthAndBaseDirProvider.class);
when(configurations.tabWidth()).thenReturn(2);
when(configurations.baseDir()).thenReturn(Optional.of(new File(getClass().getResource(configXmlFile).toURI()).getParent()));
final CheckstyleActions csInstance = checkstyleProjectService.getCheckstyleInstance();
return csInstance.createChecker(module, configLoc, Collections.emptyMap(), configurations, getClass().getClassLoader());
}
use of org.infernus.idea.checkstyle.model.ConfigurationLocation in project checkstyle-idea by jshiell.
the class ProjectConfigurationState method deserialiseLocation.
@Nullable
private ConfigurationLocation deserialiseLocation(@NotNull final Map<String, String> loadedMap, @NotNull final String key) {
final String serialisedLocation = loadedMap.get(key);
try {
final ConfigurationLocation location = configurationLocationFactory().create(project, serialisedLocation);
location.setProperties(propertiesFor(loadedMap, key));
return location;
} catch (IllegalArgumentException e) {
LOG.warn("Could not parse location: " + serialisedLocation, e);
return null;
}
}
Aggregations