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;
}
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));
}
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();
}
}
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);
}
});
}
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();
}
Aggregations