Search in sources :

Example 1 with PerformAnalysisInBackgroundOption

use of com.intellij.analysis.PerformAnalysisInBackgroundOption in project intellij-community by JetBrains.

the class DependenciesHandlerBase method analyze.

public void analyze() {
    final List<DependenciesBuilder> builders = new ArrayList<>();
    final Task task;
    if (canStartInBackground()) {
        task = new Task.Backgroundable(myProject, getProgressTitle(), true, new PerformAnalysisInBackgroundOption(myProject)) {

            @Override
            public void run(@NotNull final ProgressIndicator indicator) {
                perform(builders);
            }

            @Override
            public void onSuccess() {
                DependenciesHandlerBase.this.onSuccess(builders);
            }
        };
    } else {
        task = new Task.Modal(myProject, getProgressTitle(), true) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                perform(builders);
            }

            @Override
            public void onSuccess() {
                DependenciesHandlerBase.this.onSuccess(builders);
            }
        };
    }
    ProgressManager.getInstance().run(task);
}
Also used : DependenciesBuilder(com.intellij.packageDependencies.DependenciesBuilder) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ArrayList(java.util.ArrayList) PerformAnalysisInBackgroundOption(com.intellij.analysis.PerformAnalysisInBackgroundOption)

Example 2 with PerformAnalysisInBackgroundOption

use of com.intellij.analysis.PerformAnalysisInBackgroundOption in project intellij-community by JetBrains.

the class ViewOfflineResultsAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent event) {
    final Project project = event.getData(CommonDataKeys.PROJECT);
    LOG.assertTrue(project != null);
    final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false) {

        @Override
        public Icon getIcon(VirtualFile file) {
            if (file.isDirectory()) {
                if (file.findChild(InspectionApplication.DESCRIPTIONS + "." + StdFileTypes.XML.getDefaultExtension()) != null) {
                    return AllIcons.Nodes.InspectionResults;
                }
            }
            return super.getIcon(file);
        }
    };
    descriptor.setTitle("Select Path");
    descriptor.setDescription("Select directory which contains exported inspections results");
    final VirtualFile virtualFile = FileChooser.chooseFile(descriptor, project, null);
    if (virtualFile == null || !virtualFile.isDirectory())
        return;
    final Map<String, Map<String, Set<OfflineProblemDescriptor>>> resMap = new HashMap<>();
    final String[] profileName = new String[1];
    ProgressManager.getInstance().run(new Task.Backgroundable(project, InspectionsBundle.message("parsing.inspections.dump.progress.title"), true, new PerformAnalysisInBackgroundOption(project)) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            final VirtualFile[] files = virtualFile.getChildren();
            try {
                for (final VirtualFile inspectionFile : files) {
                    if (inspectionFile.isDirectory())
                        continue;
                    final String shortName = inspectionFile.getNameWithoutExtension();
                    final String extension = inspectionFile.getExtension();
                    if (shortName.equals(InspectionApplication.DESCRIPTIONS)) {
                        profileName[0] = ReadAction.compute(() -> OfflineViewParseUtil.parseProfileName(LoadTextUtil.loadText(inspectionFile).toString()));
                    } else if (XML_EXTENSION.equals(extension)) {
                        resMap.put(shortName, ReadAction.compute(() -> OfflineViewParseUtil.parse(LoadTextUtil.loadText(inspectionFile).toString())));
                    }
                }
            } catch (final Exception e) {
                //all parse exceptions
                ApplicationManager.getApplication().invokeLater(() -> Messages.showInfoMessage(e.getMessage(), InspectionsBundle.message("offline.view.parse.exception.title")));
                //cancel process
                throw new ProcessCanceledException();
            }
        }

        @Override
        public void onSuccess() {
            ApplicationManager.getApplication().invokeLater(() -> {
                final String name = profileName[0];
                showOfflineView(project, name, resMap, InspectionsBundle.message("offline.view.title") + " (" + (name != null ? name : InspectionsBundle.message("offline.view.editor.settings.title")) + ")");
            });
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) HashMap(java.util.HashMap) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) OfflineProblemDescriptor(com.intellij.codeInspection.offline.OfflineProblemDescriptor) Project(com.intellij.openapi.project.Project) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) PerformAnalysisInBackgroundOption(com.intellij.analysis.PerformAnalysisInBackgroundOption) HashMap(java.util.HashMap) Map(java.util.Map) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 3 with PerformAnalysisInBackgroundOption

use of com.intellij.analysis.PerformAnalysisInBackgroundOption in project intellij-community by JetBrains.

the class CyclicDependenciesHandler method analyze.

public void analyze() {
    final CyclicDependenciesBuilder builder = new CyclicDependenciesBuilder(myProject, myScope);
    final Runnable process = () -> builder.analyze();
    final Runnable successRunnable = () -> SwingUtilities.invokeLater(() -> {
        CyclicDependenciesPanel panel = new CyclicDependenciesPanel(myProject, builder);
        Content content = ContentFactory.SERVICE.getInstance().createContent(panel, AnalysisScopeBundle.message("action.analyzing.cyclic.dependencies.in.scope", builder.getScope().getDisplayName()), false);
        content.setDisposer(panel);
        panel.setContent(content);
        DependenciesToolWindow.getInstance(myProject).addContent(content);
    });
    ProgressManager.getInstance().runProcessWithProgressAsynchronously(myProject, AnalysisScopeBundle.message("package.dependencies.progress.title"), process, successRunnable, null, new PerformAnalysisInBackgroundOption(myProject));
}
Also used : CyclicDependenciesBuilder(com.intellij.cyclicDependencies.CyclicDependenciesBuilder) Content(com.intellij.ui.content.Content) CyclicDependenciesPanel(com.intellij.cyclicDependencies.ui.CyclicDependenciesPanel) PerformAnalysisInBackgroundOption(com.intellij.analysis.PerformAnalysisInBackgroundOption)

Aggregations

PerformAnalysisInBackgroundOption (com.intellij.analysis.PerformAnalysisInBackgroundOption)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Task (com.intellij.openapi.progress.Task)2 OfflineProblemDescriptor (com.intellij.codeInspection.offline.OfflineProblemDescriptor)1 CyclicDependenciesBuilder (com.intellij.cyclicDependencies.CyclicDependenciesBuilder)1 CyclicDependenciesPanel (com.intellij.cyclicDependencies.ui.CyclicDependenciesPanel)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 DependenciesBuilder (com.intellij.packageDependencies.DependenciesBuilder)1 Content (com.intellij.ui.content.Content)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1