Search in sources :

Example 1 with ConfigurationLocation

use of org.infernus.idea.checkstyle.model.ConfigurationLocation in project checkstyle-idea by jshiell.

the class CheckStyleConfigurableTest method buildMockPanel.

private CheckStyleConfigPanel buildMockPanel(final Project mockProject) {
    CheckStyleConfigPanel mockPanel = mock(CheckStyleConfigPanel.class);
    final SortedSet<ConfigurationLocation> mockLocations = buildMockLocations(mockProject, new ConfigurationLocationFactory());
    final PluginConfiguration mockConfigDto = PluginConfigurationBuilder.testInstance("7.1.2").withLocations(mockLocations).withThirdPartyClassPath(Arrays.asList("cp1", "cp2")).withActiveLocation(mockLocations.first()).build();
    when(mockPanel.getPluginConfiguration()).thenReturn(mockConfigDto);
    return mockPanel;
}
Also used : CheckStyleConfigPanel(org.infernus.idea.checkstyle.ui.CheckStyleConfigPanel) ConfigurationLocationFactory(org.infernus.idea.checkstyle.model.ConfigurationLocationFactory) ConfigurationLocation(org.infernus.idea.checkstyle.model.ConfigurationLocation) PluginConfiguration(org.infernus.idea.checkstyle.config.PluginConfiguration)

Example 2 with ConfigurationLocation

use of org.infernus.idea.checkstyle.model.ConfigurationLocation in project checkstyle-idea by jshiell.

the class CheckStyleConfigurableTest method buildMockLocations.

private static SortedSet<ConfigurationLocation> buildMockLocations(final Project mockProject, final ConfigurationLocationFactory mockLocFactory) {
    ConfigurationLocation mockLocation1 = mockLocFactory.create(mockProject, ConfigurationType.PROJECT_RELATIVE, "src/test/resources/emptyFile1.xml", "description1");
    ConfigurationLocation mockLocation2 = mockLocFactory.create(mockProject, ConfigurationType.PROJECT_RELATIVE, "src/test/resources/emptyFile2.xml", "description2");
    SortedSet<ConfigurationLocation> result = new TreeSet<>();
    result.add(mockLocation1);
    result.add(mockLocation2);
    return result;
}
Also used : ConfigurationLocation(org.infernus.idea.checkstyle.model.ConfigurationLocation) TreeSet(java.util.TreeSet)

Example 3 with ConfigurationLocation

use of org.infernus.idea.checkstyle.model.ConfigurationLocation in project checkstyle-idea by jshiell.

the class CheckStyleInspection method inspectFile.

@Nullable
public List<Problem> inspectFile(@NotNull final PsiFile psiFile, @Nullable final Module module, @NotNull final InspectionManager manager) {
    LOG.debug("Inspection has been invoked.");
    final CheckStylePlugin plugin = plugin(manager.getProject());
    ConfigurationLocation configurationLocation = null;
    final List<ScannableFile> scannableFiles = new ArrayList<>();
    try {
        configurationLocation = plugin.getConfigurationLocation(module, null);
        if (configurationLocation == null || configurationLocation.isBlacklisted()) {
            return NO_PROBLEMS_FOUND;
        }
        scannableFiles.addAll(ScannableFile.createAndValidate(singletonList(psiFile), plugin, module));
        return checkerFactory(psiFile.getProject()).checker(module, configurationLocation).map(checker -> checker.scan(scannableFiles, plugin.configurationManager().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, plugin, configurationLocation, manager.getProject());
        return NO_PROBLEMS_FOUND;
    } finally {
        scannableFiles.forEach(ScannableFile::deleteIfRequired);
    }
}
Also used : ScannableFile(org.infernus.idea.checkstyle.checker.ScannableFile) ArrayList(java.util.ArrayList) 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) 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) 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) ArrayList(java.util.ArrayList) ScannableFile(org.infernus.idea.checkstyle.checker.ScannableFile) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Optional.ofNullable(java.util.Optional.ofNullable) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with ConfigurationLocation

use of org.infernus.idea.checkstyle.model.ConfigurationLocation in project checkstyle-idea by jshiell.

the class PluginConfiguration method locationsAreEqual.

private boolean locationsAreEqual(final PluginConfiguration other) {
    Iterator<ConfigurationLocation> locationIterator = locations.iterator();
    Iterator<ConfigurationLocation> otherLocationIterator = other.locations.iterator();
    while (locationIterator.hasNext() && otherLocationIterator.hasNext()) {
        try {
            if (locationIterator.next().hasChangedFrom(otherLocationIterator.next())) {
                return false;
            }
        } catch (IOException e) {
            throw new CheckStylePluginException("Unable to test configuration properties for changes", e);
        }
    }
    return locations.size() == other.locations.size();
}
Also used : ConfigurationLocation(org.infernus.idea.checkstyle.model.ConfigurationLocation) IOException(java.io.IOException) CheckStylePluginException(org.infernus.idea.checkstyle.exception.CheckStylePluginException)

Example 5 with ConfigurationLocation

use of org.infernus.idea.checkstyle.model.ConfigurationLocation 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)

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