Search in sources :

Example 6 with ConfigurationLocation

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);
}
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 7 with ConfigurationLocation

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);
    }
}
Also used : InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) ScannableFile(org.infernus.idea.checkstyle.checker.ScannableFile) TreeSet(java.util.TreeSet) Collections.singletonList(java.util.Collections.singletonList) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) SeverityLevel(org.infernus.idea.checkstyle.csapi.SeverityLevel) ModuleUtil(com.intellij.openapi.module.ModuleUtil) InspectionManager(com.intellij.codeInspection.InspectionManager) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) Problem(org.infernus.idea.checkstyle.checker.Problem) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) CheckStyleBundle.message(org.infernus.idea.checkstyle.CheckStyleBundle.message) ConfigurationLocationSource(org.infernus.idea.checkstyle.config.ConfigurationLocationSource) Notifications.showException(org.infernus.idea.checkstyle.util.Notifications.showException) CheckerFactory(org.infernus.idea.checkstyle.checker.CheckerFactory) Optional.ofNullable(java.util.Optional.ofNullable) IOException(java.io.IOException) ConfigurationLocation(org.infernus.idea.checkstyle.model.ConfigurationLocation) FileNotFoundException(java.io.FileNotFoundException) CheckStylePluginParseException(org.infernus.idea.checkstyle.exception.CheckStylePluginParseException) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ServiceManager(com.intellij.openapi.components.ServiceManager) Notifications.showWarning(org.infernus.idea.checkstyle.util.Notifications.showWarning) CheckStyleInspectionPanel(org.infernus.idea.checkstyle.ui.CheckStyleInspectionPanel) LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool) PluginConfigurationManager(org.infernus.idea.checkstyle.config.PluginConfigurationManager) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) Async.asyncResultOf(org.infernus.idea.checkstyle.util.Async.asyncResultOf) javax.swing(javax.swing) CheckStylePluginParseException(org.infernus.idea.checkstyle.exception.CheckStylePluginParseException) ConfigurationLocation(org.infernus.idea.checkstyle.model.ConfigurationLocation) ScannableFile(org.infernus.idea.checkstyle.checker.ScannableFile) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 8 with ConfigurationLocation

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));
    }
}
Also used : CheckstyleActions(org.infernus.idea.checkstyle.csapi.CheckstyleActions) HashMap(java.util.HashMap) ConfigurationLocation(org.infernus.idea.checkstyle.model.ConfigurationLocation)

Example 9 with ConfigurationLocation

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());
}
Also used : CheckstyleActions(org.infernus.idea.checkstyle.csapi.CheckstyleActions) Project(com.intellij.openapi.project.Project) ConfigurationLocation(org.infernus.idea.checkstyle.model.ConfigurationLocation) TabWidthAndBaseDirProvider(org.infernus.idea.checkstyle.csapi.TabWidthAndBaseDirProvider) Module(com.intellij.openapi.module.Module) File(java.io.File)

Example 10 with ConfigurationLocation

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;
    }
}
Also used : ConfigurationLocation(org.infernus.idea.checkstyle.model.ConfigurationLocation) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ConfigurationLocation (org.infernus.idea.checkstyle.model.ConfigurationLocation)17 Project (com.intellij.openapi.project.Project)6 Module (com.intellij.openapi.module.Module)4 IOException (java.io.IOException)4 TreeSet (java.util.TreeSet)4 ScannableFile (org.infernus.idea.checkstyle.checker.ScannableFile)3 Nullable (org.jetbrains.annotations.Nullable)3 Test (org.junit.Test)3 InspectionManager (com.intellij.codeInspection.InspectionManager)2 LocalInspectionTool (com.intellij.codeInspection.LocalInspectionTool)2 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)2 ServiceManager (com.intellij.openapi.components.ServiceManager)2 Logger (com.intellij.openapi.diagnostic.Logger)2 ModuleUtil (com.intellij.openapi.module.ModuleUtil)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 PsiFile (com.intellij.psi.PsiFile)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 Collections (java.util.Collections)2 Collections.singletonList (java.util.Collections.singletonList)2