Search in sources :

Example 1 with ExclusionItem

use of org.sonarlint.intellij.config.project.ExclusionItem in project sonarlint-intellij by SonarSource.

the class LocalFileExclusions method loadProjectExclusions.

private void loadProjectExclusions(SonarLintProjectSettings settings) {
    List<ExclusionItem> projectExclusionsItems = settings.getFileExclusions().stream().map(ExclusionItem::parse).filter(Objects::nonNull).collect(Collectors.toList());
    Set<String> projectFileExclusions = getExclusionsOfType(projectExclusionsItems, ExclusionItem.Type.FILE);
    Set<String> projectDirExclusions = getExclusionsOfType(projectExclusionsItems, ExclusionItem.Type.DIRECTORY);
    Set<String> projectGlobExclusions = getExclusionsOfType(projectExclusionsItems, ExclusionItem.Type.GLOB);
    this.projectExclusions = new FileExclusions(projectFileExclusions, projectDirExclusions, projectGlobExclusions);
}
Also used : FileExclusions(org.sonarsource.sonarlint.core.client.api.common.FileExclusions) ExclusionItem(org.sonarlint.intellij.config.project.ExclusionItem)

Example 2 with ExclusionItem

use of org.sonarlint.intellij.config.project.ExclusionItem in project sonarlint-intellij by SonarSource.

the class ExcludeFileAction method update.

@Override
public void update(AnActionEvent e) {
    super.update(e);
    Project project = e.getProject();
    if (project == null || !project.isInitialized() || project.isDisposed()) {
        e.getPresentation().setEnabled(false);
        e.getPresentation().setVisible(true);
        return;
    }
    VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    if (!ActionPlaces.isPopupPlace(e.getPlace()) || files == null || files.length == 0) {
        e.getPresentation().setEnabled(false);
        e.getPresentation().setVisible(false);
        return;
    }
    e.getPresentation().setVisible(true);
    SonarLintProjectSettings settings = SonarLintUtils.get(project, SonarLintProjectSettings.class);
    List<String> exclusions = new ArrayList<>(settings.getFileExclusions());
    boolean anyFileToAdd = Arrays.stream(files).map(vf -> toExclusion(project, vf)).filter(exclusion -> !exclusion.item().isEmpty()).map(ExclusionItem::toStringWithType).anyMatch(path -> !exclusions.contains(path));
    if (!anyFileToAdd) {
        e.getPresentation().setEnabled(false);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SonarLintUtils(org.sonarlint.intellij.util.SonarLintUtils) ProjectConfigurationListener(org.sonarlint.intellij.messages.ProjectConfigurationListener) Arrays(java.util.Arrays) SonarLintProjectSettings(org.sonarlint.intellij.config.project.SonarLintProjectSettings) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExclusionItem(org.sonarlint.intellij.config.project.ExclusionItem) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) List(java.util.List) ActionPlaces(com.intellij.openapi.actionSystem.ActionPlaces) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Project(com.intellij.openapi.project.Project) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) Project(com.intellij.openapi.project.Project) SonarLintProjectSettings(org.sonarlint.intellij.config.project.SonarLintProjectSettings) ArrayList(java.util.ArrayList)

Example 3 with ExclusionItem

use of org.sonarlint.intellij.config.project.ExclusionItem in project sonarlint-intellij by SonarSource.

the class ExcludeFileAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    if (project == null || project.isDisposed() || files == null || files.length == 0) {
        return;
    }
    SonarLintProjectSettings settings = SonarLintUtils.get(project, SonarLintProjectSettings.class);
    List<String> exclusions = new ArrayList<>(settings.getFileExclusions());
    List<String> newExclusions = Arrays.stream(files).map(vf -> toExclusion(project, vf)).filter(exclusion -> !exclusion.item().isEmpty()).map(ExclusionItem::toStringWithType).filter(path -> !exclusions.contains(path)).collect(Collectors.toList());
    if (!newExclusions.isEmpty()) {
        exclusions.addAll(newExclusions);
        settings.setFileExclusions(exclusions);
        ProjectConfigurationListener projectListener = project.getMessageBus().syncPublisher(ProjectConfigurationListener.TOPIC);
        projectListener.changed(settings);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SonarLintUtils(org.sonarlint.intellij.util.SonarLintUtils) ProjectConfigurationListener(org.sonarlint.intellij.messages.ProjectConfigurationListener) Arrays(java.util.Arrays) SonarLintProjectSettings(org.sonarlint.intellij.config.project.SonarLintProjectSettings) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExclusionItem(org.sonarlint.intellij.config.project.ExclusionItem) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) List(java.util.List) ActionPlaces(com.intellij.openapi.actionSystem.ActionPlaces) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Project(com.intellij.openapi.project.Project) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) Project(com.intellij.openapi.project.Project) SonarLintProjectSettings(org.sonarlint.intellij.config.project.SonarLintProjectSettings) ProjectConfigurationListener(org.sonarlint.intellij.messages.ProjectConfigurationListener) ArrayList(java.util.ArrayList) ExclusionItem(org.sonarlint.intellij.config.project.ExclusionItem)

Aggregations

ExclusionItem (org.sonarlint.intellij.config.project.ExclusionItem)3 ActionPlaces (com.intellij.openapi.actionSystem.ActionPlaces)2 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)2 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 SonarLintProjectSettings (org.sonarlint.intellij.config.project.SonarLintProjectSettings)2 ProjectConfigurationListener (org.sonarlint.intellij.messages.ProjectConfigurationListener)2 SonarLintUtils (org.sonarlint.intellij.util.SonarLintUtils)2 FileExclusions (org.sonarsource.sonarlint.core.client.api.common.FileExclusions)1