Search in sources :

Example 1 with ReadAction

use of com.intellij.openapi.application.ReadAction in project intellij-community by JetBrains.

the class GenericCompilerRunner method invokeCompiler.

private <T extends BuildTarget, Item extends CompileItem<Key, SourceState, OutputState>, Key, SourceState, OutputState> boolean invokeCompiler(GenericCompiler<Key, SourceState, OutputState> compiler, final GenericCompilerInstance<T, Item, Key, SourceState, OutputState> instance) throws IOException, ExitException {
    final GenericCompilerCache<Key, SourceState, OutputState> cache = CompilerCacheManager.getInstance(myProject).getGenericCompilerCache(compiler);
    GenericCompilerPersistentData data = new GenericCompilerPersistentData(getGenericCompilerCacheDir(myProject, compiler), compiler.getVersion());
    if (data.isVersionChanged()) {
        LOG.info("Clearing cache for " + compiler.getDescription());
        cache.wipe();
        data.save();
    }
    final Set<String> targetsToRemove = new HashSet<>(data.getAllTargets());
    new ReadAction() {

        protected void run(@NotNull final Result result) {
            for (T target : instance.getAllTargets()) {
                targetsToRemove.remove(target.getId());
            }
        }
    }.execute();
    if (!myOnlyCheckStatus) {
        for (final String target : targetsToRemove) {
            final int id = data.removeId(target);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Removing obsolete target '" + target + "' (id=" + id + ")");
            }
            final List<Key> keys = new ArrayList<>();
            CompilerUtil.runInContext(myContext, "Processing obsolete targets...", () -> {
                cache.processSources(id, new CommonProcessors.CollectProcessor<>(keys));
                List<GenericCompilerCacheState<Key, SourceState, OutputState>> obsoleteSources = new ArrayList<>();
                for (Key key : keys) {
                    final GenericCompilerCache.PersistentStateData<SourceState, OutputState> state = cache.getState(id, key);
                    obsoleteSources.add(new GenericCompilerCacheState<>(key, state.mySourceState, state.myOutputState));
                }
                instance.processObsoleteTarget(target, obsoleteSources);
            });
            checkForErrorsOrCanceled();
            for (Key key : keys) {
                cache.remove(id, key);
            }
        }
    }
    final List<T> selectedTargets = new ReadAction<List<T>>() {

        protected void run(@NotNull final Result<List<T>> result) {
            result.setResult(instance.getSelectedTargets());
        }
    }.execute().getResultObject();
    boolean didSomething = false;
    for (T target : selectedTargets) {
        int id = data.getId(target.getId());
        didSomething |= processTarget(target, id, compiler, instance, cache);
    }
    data.save();
    return didSomething;
}
Also used : GenericCompilerCache(com.intellij.compiler.impl.generic.GenericCompilerCache) NotNull(org.jetbrains.annotations.NotNull) GenericCompilerPersistentData(com.intellij.compiler.impl.generic.GenericCompilerPersistentData) Result(com.intellij.openapi.application.Result) RunResult(com.intellij.openapi.application.RunResult) ReadAction(com.intellij.openapi.application.ReadAction) CommonProcessors(com.intellij.util.CommonProcessors) THashSet(gnu.trove.THashSet)

Example 2 with ReadAction

use of com.intellij.openapi.application.ReadAction in project intellij-community by JetBrains.

the class ProjectStructureDaemonAnalyzer method doCheck.

private void doCheck(final ProjectStructureElement element) {
    final ProjectStructureProblemsHolderImpl problemsHolder = new ProjectStructureProblemsHolderImpl();
    new ReadAction() {

        @Override
        protected void run(@NotNull final Result result) {
            if (myStopped.get())
                return;
            if (LOG.isDebugEnabled()) {
                LOG.debug("checking " + element);
            }
            ProjectStructureValidator.check(element, problemsHolder);
        }
    }.execute();
    myResultsUpdateQueue.queue(new ProblemsComputedUpdate(element, problemsHolder));
}
Also used : ReadAction(com.intellij.openapi.application.ReadAction) Result(com.intellij.openapi.application.Result)

Example 3 with ReadAction

use of com.intellij.openapi.application.ReadAction in project intellij-community by JetBrains.

the class XDebugSessionImpl method enableBreakpoints.

private void enableBreakpoints() {
    if (myBreakpointsDisabled) {
        myBreakpointsDisabled = false;
        new ReadAction() {

            @Override
            protected void run(@NotNull Result result) {
                processAllBreakpoints(true, false);
            }
        }.execute();
    }
}
Also used : ReadAction(com.intellij.openapi.application.ReadAction) Result(com.intellij.openapi.application.Result)

Example 4 with ReadAction

use of com.intellij.openapi.application.ReadAction in project intellij-community by JetBrains.

the class ImportMavenRepositoriesTask method performTask.

private void performTask() {
    if (myProject.isDisposed())
        return;
    if (ApplicationManager.getApplication().isUnitTestMode())
        return;
    final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
    final List<PsiFile> psiFileList = ContainerUtil.newArrayList();
    final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
    for (Module module : moduleManager.getModules()) {
        if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
            continue;
        final String modulePath = ExternalSystemApiUtil.getExternalProjectPath(module);
        if (modulePath == null)
            continue;
        String buildScript = FileUtil.findFileInProvidedPath(modulePath, GradleConstants.DEFAULT_SCRIPT_NAME);
        if (StringUtil.isEmpty(buildScript))
            continue;
        VirtualFile virtualFile = localFileSystem.refreshAndFindFileByPath(buildScript);
        if (virtualFile == null)
            continue;
        final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(virtualFile);
        if (psiFile == null)
            continue;
        psiFileList.add(psiFile);
    }
    final PsiFile[] psiFiles = ArrayUtil.toObjectArray(psiFileList, PsiFile.class);
    final Set<MavenRemoteRepository> mavenRemoteRepositories = new ReadAction<Set<MavenRemoteRepository>>() {

        @Override
        protected void run(@NotNull Result<Set<MavenRemoteRepository>> result) throws Throwable {
            Set<MavenRemoteRepository> myRemoteRepositories = ContainerUtil.newHashSet();
            for (PsiFile psiFile : psiFiles) {
                List<GrClosableBlock> repositoriesBlocks = ContainerUtil.newArrayList();
                repositoriesBlocks.addAll(findClosableBlocks(psiFile, "repositories"));
                for (GrClosableBlock closableBlock : findClosableBlocks(psiFile, "buildscript", "subprojects", "allprojects", "project", "configure")) {
                    repositoriesBlocks.addAll(findClosableBlocks(closableBlock, "repositories"));
                }
                for (GrClosableBlock repositoriesBlock : repositoriesBlocks) {
                    myRemoteRepositories.addAll(findMavenRemoteRepositories(repositoriesBlock));
                }
            }
            result.setResult(myRemoteRepositories);
        }
    }.execute().getResultObject();
    if (mavenRemoteRepositories == null || mavenRemoteRepositories.isEmpty())
        return;
    // register imported maven repository URLs but do not force to download the index
    // the index can be downloaded and/or updated later using Maven Configuration UI (Settings -> Build, Execution, Deployment -> Build tools -> Maven -> Repositories)
    MavenRepositoriesHolder.getInstance(myProject).update(mavenRemoteRepositories);
    MavenProjectIndicesManager.getInstance(myProject).scheduleUpdateIndicesList(indexes -> {
        if (myProject.isDisposed())
            return;
        final List<String> repositoriesWithEmptyIndex = ContainerUtil.mapNotNull(indexes, index -> index.getUpdateTimestamp() == -1 && MavenRepositoriesHolder.getInstance(myProject).contains(index.getRepositoryPathOrUrl()) ? index.getRepositoryPathOrUrl() : null);
        if (!repositoriesWithEmptyIndex.isEmpty()) {
            final NotificationData notificationData = new NotificationData(GradleBundle.message("gradle.integrations.maven.notification.not_updated_repository.title"), "\n<br>" + GradleBundle.message("gradle.integrations.maven.notification.not_updated_repository.text", StringUtil.join(repositoriesWithEmptyIndex, "<br>")), NotificationCategory.WARNING, NotificationSource.PROJECT_SYNC);
            notificationData.setBalloonNotification(true);
            notificationData.setBalloonGroup(UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP);
            notificationData.setListener("#open", new NotificationListener.Adapter() {

                @Override
                protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
                    ShowSettingsUtil.getInstance().showSettingsDialog(myProject, MavenRepositoriesConfigurable.class);
                }
            });
            notificationData.setListener("#disable", new NotificationListener.Adapter() {

                @Override
                protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
                    final int result = Messages.showYesNoDialog(myProject, "Notification will be disabled for all projects.\n\n" + "Settings | Appearance & Behavior | Notifications | " + UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP + "\ncan be used to configure the notification.", "Unindexed Maven Repositories Gradle Detection", "Disable Notification", CommonBundle.getCancelButtonText(), Messages.getWarningIcon());
                    if (result == Messages.YES) {
                        NotificationsConfigurationImpl.getInstanceImpl().changeSettings(UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP, NotificationDisplayType.NONE, false, false);
                        notification.hideBalloon();
                    }
                }
            });
            ExternalSystemNotificationManager.getInstance(myProject).showNotification(GradleConstants.SYSTEM_ID, notificationData);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HyperlinkEvent(javax.swing.event.HyperlinkEvent) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) ModuleManager(com.intellij.openapi.module.ModuleManager) NotNull(org.jetbrains.annotations.NotNull) Notification(com.intellij.notification.Notification) Result(com.intellij.openapi.application.Result) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) ReadAction(com.intellij.openapi.application.ReadAction) MavenRemoteRepository(org.jetbrains.idea.maven.model.MavenRemoteRepository) MavenRepositoriesConfigurable(org.jetbrains.idea.maven.indices.MavenRepositoriesConfigurable) Module(com.intellij.openapi.module.Module) NotificationData(com.intellij.openapi.externalSystem.service.notification.NotificationData) NotificationListener(com.intellij.notification.NotificationListener)

Example 5 with ReadAction

use of com.intellij.openapi.application.ReadAction in project intellij-community by JetBrains.

the class CreateTestDialog method selectTargetDirectory.

@Nullable
private PsiDirectory selectTargetDirectory() throws IncorrectOperationException {
    final String packageName = getPackageName();
    final PackageWrapper targetPackage = new PackageWrapper(PsiManager.getInstance(myProject), packageName);
    final VirtualFile selectedRoot = new ReadAction<VirtualFile>() {

        protected void run(@NotNull Result<VirtualFile> result) throws Throwable {
            final List<VirtualFile> testFolders = CreateTestAction.computeTestRoots(myTargetModule);
            List<VirtualFile> roots;
            if (testFolders.isEmpty()) {
                roots = new ArrayList<>();
                List<String> urls = CreateTestAction.computeSuitableTestRootUrls(myTargetModule);
                for (String url : urls) {
                    ContainerUtil.addIfNotNull(roots, VfsUtil.createDirectories(VfsUtilCore.urlToPath(url)));
                }
                if (roots.isEmpty()) {
                    JavaProjectRootsUtil.collectSuitableDestinationSourceRoots(myTargetModule, roots);
                }
                if (roots.isEmpty())
                    return;
            } else {
                roots = new ArrayList<>(testFolders);
            }
            if (roots.size() == 1) {
                result.setResult(roots.get(0));
            } else {
                PsiDirectory defaultDir = chooseDefaultDirectory(targetPackage.getDirectories(), roots);
                result.setResult(MoveClassesOrPackagesUtil.chooseSourceRoot(targetPackage, roots, defaultDir));
            }
        }
    }.execute().getResultObject();
    if (selectedRoot == null)
        return null;
    return new WriteCommandAction<PsiDirectory>(myProject, CodeInsightBundle.message("create.directory.command")) {

        protected void run(@NotNull Result<PsiDirectory> result) throws Throwable {
            result.setResult(RefactoringUtil.createPackageDirectoryInSourceRoot(targetPackage, selectedRoot));
        }
    }.execute().getResultObject();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) ReadAction(com.intellij.openapi.application.ReadAction) NotNull(org.jetbrains.annotations.NotNull) PackageWrapper(com.intellij.refactoring.PackageWrapper) Result(com.intellij.openapi.application.Result) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ReadAction (com.intellij.openapi.application.ReadAction)16 Result (com.intellij.openapi.application.Result)16 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 NotNull (org.jetbrains.annotations.NotNull)7 Module (com.intellij.openapi.module.Module)3 GenericCompilerCache (com.intellij.compiler.impl.generic.GenericCompilerCache)2 Notification (com.intellij.notification.Notification)2 RunResult (com.intellij.openapi.application.RunResult)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Project (com.intellij.openapi.project.Project)2 Artifact (com.intellij.packaging.artifacts.Artifact)2 THashSet (gnu.trove.THashSet)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)1 GradleInvocationResult (com.android.tools.idea.gradle.project.build.invoker.GradleInvocationResult)1 GradleBuildModelFixture (com.android.tools.idea.tests.gui.framework.fixture.gradle.GradleBuildModelFixture)1 GenericCompilerPersistentData (com.intellij.compiler.impl.generic.GenericCompilerPersistentData)1 NotificationListener (com.intellij.notification.NotificationListener)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1