private void moveMavenModulesToGroup( final Project project, final List<Module> mavenModules, final String[] rootGroup ) { AccessToken token = null; final ModifiableModuleModel modifiableModuleModel; try { token = ApplicationManager.getApplication().acquireReadActionLock(); modifiableModuleModel = ModuleManager.getInstance(project).getModifiableModel(); for (Module module : mavenModules) { module.setOption(HybrisConstants.DESCRIPTOR_TYPE, HybrisModuleDescriptorType.MAVEN.name()); final String[] groupPath = modifiableModuleModel.getModuleGroupPath(module); modifiableModuleModel.setModuleGroupPath(module, ArrayUtils.addAll(rootGroup, groupPath)); } } finally { if (token != null) { token.finish(); } } ApplicationManager.getApplication().invokeAndWait(() -> WriteAction.run(modifiableModuleModel::commit)); }
private void moveGradleModulesToGroup( final Project project, final List<Module> gradleModules, final String[] gradleGroup ) { final ModifiableModuleModel modifiableModuleModel = ModuleManager.getInstance(project).getModifiableModel(); for (Module module : gradleModules) { if (module == null) { // https://youtrack.jetbrains.com/issue/IDEA-177512 continue; } module.setOption(HybrisConstants.DESCRIPTOR_TYPE, HybrisModuleDescriptorType.GRADLE.name()); modifiableModuleModel.setModuleGroupPath(module, gradleGroup); } AccessToken token = null; try { token = ApplicationManager.getApplication().acquireWriteActionLock(getClass()); modifiableModuleModel.commit(); } finally { if (token != null) { token.finish(); } } }
private void moveEclipseModulesToGroup( @NotNull final Project project, @NotNull final List<Module> eclipseModules, @Nullable final String[] eclipseGroup ) { final ModifiableModuleModel modifiableModuleModel = ModuleManager.getInstance(project).getModifiableModel(); for (Module module : eclipseModules) { module.setOption(HybrisConstants.DESCRIPTOR_TYPE, HybrisModuleDescriptorType.ECLIPSE.name()); modifiableModuleModel.setModuleGroupPath(module, eclipseGroup); } AccessToken token = null; try { token = ApplicationManager.getApplication().acquireWriteActionLock(getClass()); modifiableModuleModel.commit(); } finally { if (token != null) { token.finish(); } } }
@Override public void updateProjectStructure(@NotNull final Module module) { if (!MvcModuleStructureUtil.isEnabledStructureUpdate()) return; final VirtualFile root = findAppRoot(module); if (root == null) return; AccessToken token = WriteAction.start(); try { MvcModuleStructureUtil.updateModuleStructure(module, createProjectStructure(module, false), root); if (hasSupport(module)) { MvcModuleStructureUtil.updateAuxiliaryPluginsModuleRoots(module, this); MvcModuleStructureUtil.updateGlobalPluginModule(module.getProject(), this); } } finally { token.finish(); } final Project project = module.getProject(); ChangeListManager.getInstance(project).addFilesToIgnore(IgnoredBeanFactory.ignoreUnderDirectory(getUserHomeGriffon(), project)); }
private void downloadJar(String jarUrl, String jarName) { final Project project = myModule.getProject(); final String dirPath = PropertiesComponent.getInstance(project).getValue("findjar.last.used.dir"); VirtualFile toSelect = dirPath == null ? null : LocalFileSystem.getInstance().findFileByIoFile(new File(dirPath)); final VirtualFile file = FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFolderDescriptor(), project, toSelect); if (file != null) { PropertiesComponent.getInstance(project).setValue("findjar.last.used.dir", file.getPath()); final DownloadableFileService downloader = DownloadableFileService.getInstance(); final DownloadableFileDescription description = downloader.createFileDescription(jarUrl, jarName); final List<VirtualFile> jars = downloader.createDownloader(Arrays.asList(description), jarName) .downloadFilesWithProgress(file.getPath(), project, myEditorComponent); if (jars != null && jars.size() == 1) { AccessToken token = WriteAction.start(); try { OrderEntryFix.addJarToRoots(jars.get(0).getPresentableUrl(), myModule, myRef); } finally { token.finish(); } } } }
@Nullable public static Library createLibrary(@Nullable final LibraryType type, @NotNull final JComponent parentComponent, @NotNull final Project project, @NotNull final LibrariesModifiableModel modifiableModel) { final NewLibraryConfiguration configuration = createNewLibraryConfiguration(type, parentComponent, project); if (configuration == null) return null; final LibraryType<?> libraryType = configuration.getLibraryType(); final Library library = modifiableModel.createLibrary( LibraryEditingUtil.suggestNewLibraryName(modifiableModel, configuration.getDefaultLibraryName()), libraryType != null ? libraryType.getKind() : null); final NewLibraryEditor editor = new NewLibraryEditor(libraryType, configuration.getProperties()); configuration.addRoots(editor); final Library.ModifiableModel model = library.getModifiableModel(); editor.applyTo((LibraryEx.ModifiableModelEx)model); AccessToken token = WriteAction.start(); try { model.commit(); } finally { token.finish(); } return library; }
private void addLibrary() { final LibrariesContainer.LibraryLevel level = myNameAndLevelPanel.getLibraryLevel(); AccessToken token = WriteAction.start(); try { final Module module = myModulesComboBox.getSelectedModule(); final String libraryName = myNameAndLevelPanel.getLibraryName(); if (level == LibrariesContainer.LibraryLevel.MODULE) { final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel(); LibrariesContainerFactory.createContainer(modifiableModel).createLibrary(libraryName, level, myRoots); modifiableModel.commit(); } else { final Library library = LibrariesContainerFactory.createContainer(myProject).createLibrary(libraryName, level, myRoots); if (module != null) { ModuleRootModificationUtil.addDependency(module, library); } } } finally { token.finish(); } }
/** * Read action will be taken automatically */ public static <RESULT> RESULT visit(@NotNull XSourcePosition position, @NotNull Project project, @NotNull Visitor<RESULT> visitor, RESULT defaultResult) { AccessToken token = ReadAction.start(); try { Document document = FileDocumentManager.getInstance().getDocument(position.getFile()); PsiFile file = document == null || document.getTextLength() == 0 ? null : PsiDocumentManager.getInstance(project).getPsiFile(document); if (file == null) { return defaultResult; } int positionOffset; int column = position instanceof SourceInfo ? Math.max(((SourceInfo)position).getColumn(), 0) : 0; try { positionOffset = column == 0 ? DocumentUtil.getFirstNonSpaceCharOffset(document, position.getLine()) : document.getLineStartOffset(position.getLine()) + column; } catch (IndexOutOfBoundsException ignored) { return defaultResult; } PsiElement element = file.findElementAt(positionOffset); return element == null ? defaultResult : visitor.visit(element, positionOffset, document); } finally { token.finish(); } }
private static boolean containsGroovyClasses(final Project project) { return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Boolean>() { @Nullable @Override public Result<Boolean> compute() { AccessToken accessToken = ReadAction.start(); try { return Result.create(FileTypeIndex.containsFileOfType(GroovyFileType.GROOVY_FILE_TYPE, GlobalSearchScope.projectScope(project)), PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT); } finally { accessToken.finish(); } } }); }
@Override public void loadState(final Element element) { try { if (myFirstLoad) { myModel.readExternal(element); } else { LibraryModel model = new LibraryModel(myModel); AccessToken token = WriteAction.start(); try { model.readExternal(element); commit(model); } finally { token.finish(); } } myFirstLoad = false; } catch (InvalidDataException e) { throw new RuntimeException(e); } }
protected void levelDown() { myBatchLevel -= 1; if (myChanged && myBatchLevel == 0) { AccessToken token = WriteAction.start(); try { fireChange(); } finally { try { myChanged = false; } finally { token.finish(); } } } }
@Override public PositionManager createPositionManager(@NotNull final DebugProcess process) { AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); try { JavaPsiFacade facade = JavaPsiFacade.getInstance(process.getProject()); if (facade.findPackage("com.springsource.loaded") != null || facade.findPackage("org.springsource.loaded") != null) { return new SpringLoadedPositionManager(process); } } finally { accessToken.finish(); } try { // Check spring loaded for remote process if (!process.getVirtualMachineProxy().classesByName("com.springsource.loaded.agent.SpringLoadedAgent").isEmpty() || !process.getVirtualMachineProxy().classesByName("org.springsource.loaded.agent.SpringLoadedAgent").isEmpty()) { return new SpringLoadedPositionManager(process); } } catch (Exception ignored) { // Some problem with virtual machine. } return null; }
@Override protected Couple<String> doAction(Project project, PsiElement psiElement, I18nizeQuickFixModel model) { final Couple<String> result = super.doAction(project, psiElement, model); if (result != null && psiElement instanceof PsiLiteralExpression) { final String key = result.first; final StringBuilder buffer = new StringBuilder(); buffer.append('"'); StringUtil.escapeStringCharacters(key.length(), key, buffer); buffer.append('"'); final AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(JavaCreatePropertyFix.class); try { final PsiExpression newKeyLiteral = JavaPsiFacade.getElementFactory(project).createExpressionFromText(buffer.toString(), null); psiElement.replace(newKeyLiteral); } catch (IncorrectOperationException e) { LOG.error(e); } finally { token.finish(); } } return result; }
/** * do not call this method from plugins, use {@link com.intellij.xdebugger.XDebuggerUtil#createPositionByOffset(com.intellij.openapi.vfs.VirtualFile, int)} instead */ @Nullable public static XSourcePositionImpl createByOffset(@Nullable VirtualFile file, final int offset) { if (file == null) return null; AccessToken lock = ApplicationManager.getApplication().acquireReadActionLock(); try { Document document = FileDocumentManager.getInstance().getDocument(file); if (document == null) { return null; } int line = offset < document.getTextLength() ? document.getLineNumber(offset) : -1; return new XSourcePositionImpl(file, line, offset); } finally { lock.finish(); } }
private void saveHistory() { try { if (getModel().getEntries().isEmpty()) return; if (myRootType.isHidden()) { saveHistoryOld(); return; } AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(getClass()); try { VirtualFile file = HistoryRootType.getInstance().findFile(null, getHistoryName(myRootType, myId), ScratchFileService.Option.create_if_missing); VfsUtil.saveText(file, StringUtil.join(getModel().getEntries(), myRootType.getEntrySeparator())); } finally { token.finish(); } } catch (Exception ex) { LOG.error(ex); } }
public void extractBundledResources(@NotNull PluginId pluginId, @NotNull String path) throws IOException { List<URL> bundledResources = getBundledResourceUrls(pluginId, path); if (bundledResources.isEmpty()) return; VirtualFile resourcesDirectory = findExtensionsDirectoryImpl(pluginId, path, true); if (resourcesDirectory == null) return; Application application = ApplicationManager.getApplication(); for (URL bundledResourceDirUrl : bundledResources) { VirtualFile bundledResourcesDir = VfsUtil.findFileByURL(bundledResourceDirUrl); if (!bundledResourcesDir.isDirectory()) continue; AccessToken token = application.acquireWriteActionLock(ExtensionsRootType.class); try { FileDocumentManager.getInstance().saveAllDocuments(); extractResources(bundledResourcesDir, resourcesDirectory); } finally { token.finish(); } } }
@Override public void actionPerformed(AnActionEvent e) { final VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY); final Project project = getEventProject(e); if (files == null || project == null) return; try { final ModifiableModuleModel model = ModuleManager.getInstance(project).getModifiableModel(); for (VirtualFile file : files) { model.loadModule(file.getPath()); } AccessToken token = WriteAction.start(); try { model.commit(); } finally { token.finish(); } } catch (Exception ex) { LOG.info(ex); Messages.showErrorDialog(project, "Cannot import module: " + ex.getMessage(), CommonBundle.getErrorTitle()); } }
@Nullable private String getDataAsText() { final AccessToken token = ApplicationManager.getApplication().acquireReadActionLock(); try { final List<String> names = new ArrayList<String>(); for (PsiElement element : myDataProxy.getElements()) { if (element instanceof PsiNamedElement) { String name = ((PsiNamedElement)element).getName(); if (name != null) { names.add(name); } } } return names.isEmpty() ? null : StringUtil.join(names, "\n"); } finally { token.finish(); } }
private String getFunctionName(final XLineBreakpoint breakpoint) { final VirtualFile file = breakpoint.getSourcePosition().getFile(); AccessToken lock = ApplicationManager.getApplication().acquireReadActionLock(); try { final Document document = FileDocumentManager.getInstance().getDocument(file); final Project project = getSession().getProject(); final String[] funcName = new String[1]; if (document != null) { if (file.getFileType() == PythonFileType.INSTANCE) { PsiElement psiElement = XDebuggerUtil.getInstance().findContextElement(file, breakpoint.getSourcePosition().getOffset(), project, false); PyFunction function = PsiTreeUtil.getParentOfType(psiElement, PyFunction.class); if (function != null) { funcName[0] = function.getName(); } } } return funcName[0]; } finally { lock.finish(); } }
private Object execIPythonEditor(Vector params) { String path = (String)params.get(0); int line = Integer.parseInt((String)params.get(1)); final VirtualFile file = StringUtil.isEmpty(path) ? null : LocalFileSystem.getInstance().findFileByPath(path); if (file != null) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { AccessToken at = ApplicationManager.getApplication().acquireReadActionLock(); try { FileEditorManager.getInstance(myProject).openFile(file, true); } finally { at.finish(); } } }); return Boolean.TRUE; } return Boolean.FALSE; }
@Override public void actionPerformed(AnActionEvent e) { final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext()); PsiFile file = CommonDataKeys.PSI_FILE.getData(e.getDataContext()); if (editor == null || file == null) return; final Project project = file.getProject(); CommandProcessorEx commandProcessor = (CommandProcessorEx)CommandProcessorEx.getInstance(); Object commandToken = commandProcessor.startCommand(project, e.getPresentation().getText(), e.getPresentation().getText(), UndoConfirmationPolicy.DEFAULT); AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(getClass()); try { final SelectionModel selectionModel = editor.getSelectionModel(); int[] starts = selectionModel.getBlockSelectionStarts(); int[] ends = selectionModel.getBlockSelectionEnds(); int startOffset = starts.length == 0? 0 : starts[0]; int endOffset = ends.length == 0? editor.getDocument().getTextLength() : ends[ends.length - 1]; perform(project, editor.getDocument(), startOffset, endOffset); } finally { token.finish(); commandProcessor.finishCommand(project, commandToken, null); } }
private static void rebaseCurrentBranch(@NotNull final Project project, @NotNull final GitRepository gitRepository, @NotNull final ProgressIndicator indicator) { final Git git = ServiceManager.getService(project, Git.class); final GitPlatformFacade facade = ServiceManager.getService(project, GitPlatformFacade.class); AccessToken token = DvcsUtil.workingTreeChangeStarted(project); try { List<VirtualFile> rootsToSave = Collections.singletonList(gitRepository.getRoot()); GitPreservingProcess process = new GitPreservingProcess(project, facade, git, rootsToSave, "Rebasing", "upstream/master", GitVcsSettings.UpdateChangesPolicy.STASH, indicator, new Runnable() { @Override public void run() { doRebaseCurrentBranch(project, gitRepository.getRoot(), indicator); } }); process.execute(); } finally { DvcsUtil.workingTreeChangeFinished(project, token); } }
private static Module doLoadModule(@NotNull String path, @NotNull Project project) throws IOException, JDOMException, InvalidDataException { Module module; AccessToken token = WriteAction.start(); try { module = ModuleManager.getInstance(project).newModule(path + '/' + EclipseProjectFinder.findProjectName(path) + IdeaXml.IML_EXT, StdModuleTypes.JAVA.getId()); } finally { token.finish(); } replaceRoot(path, EclipseXml.DOT_CLASSPATH_EXT, project); ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel(); new EclipseClasspathConverter(module).readClasspath(rootModel); token = WriteAction.start(); try { rootModel.commit(); } finally { token.finish(); } return module; }
@Override public void moduleRenamed(@NotNull Module module, @NotNull String oldName, @NotNull String newName) { try { CachedXmlDocumentSet fileSet = getFileCache(module); VirtualFile root = LocalFileSystem.getInstance().findFileByPath(ModuleUtilCore.getModuleDirPath(module)); VirtualFile source = root == null ? null : root.findChild(oldName + EclipseXml.IDEA_SETTINGS_POSTFIX); if (source != null && source.isValid()) { AccessToken token = WriteAction.start(); try { source.rename(this, newName + EclipseXml.IDEA_SETTINGS_POSTFIX); } finally { token.finish(); } } DotProjectFileHelper.saveDotProjectFile(module, fileSet.getParent(EclipseXml.PROJECT_FILE)); fileSet.unregister(oldName + EclipseXml.IDEA_SETTINGS_POSTFIX); fileSet.register(newName + EclipseXml.IDEA_SETTINGS_POSTFIX, ModuleUtilCore.getModuleDirPath(module)); } catch (IOException e) { EclipseClasspathWriter.LOG.warn(e); } }
@Nullable private static String getOuterClassName(final SourcePosition position) { AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); try { GroovyPsiElement sourceImage = findReferenceTypeSourceImage(position); if (sourceImage instanceof GrTypeDefinition) { return getClassNameForJvm((GrTypeDefinition)sourceImage); } else if (sourceImage == null) { return getScriptQualifiedName(position); } return null; } finally { accessToken.finish(); } }
public void perform(final Project project, MavenEmbeddersManager embeddersManager, MavenConsole console, MavenProgressIndicator indicator) throws MavenProcessCanceledException { MavenArtifactDownloader.DownloadResult result = myTree.downloadSourcesAndJavadocs(project, myProjects, myArtifacts, myDownloadSources, myDownloadDocs, embeddersManager, console, indicator); if (myCallbackResult != null) myCallbackResult.setDone(result); // todo: hack to update all file pointers. MavenUtil.invokeLater(project, new Runnable() { public void run() { AccessToken accessToken = WriteAction.start(); try { ProjectRootManagerEx.getInstanceEx(project).makeRootsChange(EmptyRunnable.getInstance(), false, true); } finally { accessToken.finish(); } } }); }
public void scheduleUpdateIndicesList(@Nullable final Consumer<List<MavenIndex>> consumer) { myUpdateQueue.queue(new Update(MavenProjectIndicesManager.this) { public void run() { Set<Pair<String, String>> remoteRepositoriesIdsAndUrls; File localRepository; AccessToken accessToken = ReadAction.start(); try { if (myProject.isDisposed()) return; remoteRepositoriesIdsAndUrls = collectRemoteRepositoriesIdsAndUrls(); localRepository = getLocalRepository(); } finally { accessToken.finish(); } myProjectIndices = MavenIndicesManager.getInstance().ensureIndicesExist(myProject, localRepository, remoteRepositoriesIdsAndUrls); if(consumer != null) { consumer.consume(myProjectIndices); } } }); }
private static MavenGeneralSettings getMavenSettings(@NotNull final Project project, @NotNull MavenProgressIndicator indicator) throws MavenProcessCanceledException { MavenGeneralSettings settings; AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); try { settings = project.isDisposed() ? null : MavenProjectsManager.getInstance(project).getGeneralSettings().clone(); } finally { accessToken.finish(); } if (settings == null) { // project was closed indicator.cancel(); indicator.checkCanceled(); } return settings; }
@Nullable public static Element read(final VirtualFile file, @Nullable final ErrorHandler handler) { String text; AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); try { if (!file.isValid()) return null; try { text = VfsUtil.loadText(file); } catch (IOException e) { if (handler != null) handler.onReadError(e); return null; } } finally { accessToken.finish(); } return doRead(text, handler); }
@Nullable private HgCommandResult graft(@NotNull List<String> params) { List<String> args = new ArrayList<String>(); args.add("--log"); args.addAll(params); AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject); try { HgCommandResult result = new HgCommandExecutor(myProject) .executeInCurrentThread(myRepository.getRoot(), "graft", args); myRepository.update(); return result; } finally { DvcsUtil.workingTreeChangeFinished(myProject, token); } }
@Override public ActionCallback perform(List<LibraryOrderEntry> orderEntriesContainingFile) { ApplicationManager.getApplication().assertIsDispatchThread(); ActionCallback callback = new ActionCallback(); callback.setDone(); if (!mySrcFile.isValid()) return callback; if (myLibrary != getLibraryFromOrderEntriesList(orderEntriesContainingFile)) return callback; AccessToken accessToken = WriteAction.start(); try { addSourceFile(mySrcFile, myLibrary); } finally { accessToken.finish(); } return callback; }
private static boolean processReferencesInUIForms(Processor<PsiReference> processor, PsiManager psiManager, PsiField field, GlobalSearchScope scope1, LocalSearchScope filterScope) { GlobalSearchScope scope = GlobalSearchScope.projectScope(psiManager.getProject()).intersectWith(scope1); final AccessToken token = ReadAction.start(); PsiClass containingClass = field.getContainingClass(); if (containingClass == null) return true; String fieldName; try { fieldName = field.getName(); } finally { token.finish(); } final List<PsiFile> files = FormClassIndex.findFormsBoundToClass(psiManager.getProject(), containingClass, scope); return processReferencesInFiles(files, psiManager, fieldName, field, filterScope, processor); }
/** * {@inheritDoc} */ protected void perform(@NotNull Project project, @NotNull List<VirtualFile> gitRoots, @NotNull VirtualFile defaultRoot, Set<VirtualFile> affectedRoots, List<VcsException> exceptions) throws VcsException { GitResetDialog d = new GitResetDialog(project, gitRoots, defaultRoot); if (!d.showAndGet()) { return; } GitLineHandler h = d.handler(); affectedRoots.add(d.getGitRoot()); AccessToken token = DvcsUtil.workingTreeChangeStarted(project); try { GitHandlerUtil.doSynchronously(h, GitBundle.getString("resetting.title"), h.printableCommandLine()); } finally { DvcsUtil.workingTreeChangeFinished(project, token); } GitRepositoryManager manager = GitUtil.getRepositoryManager(project); manager.updateRepository(d.getGitRoot()); }
private static PsiType findPsiType(Project project, Type type) { AccessToken token = ReadAction.start(); try { return DebuggerUtils.getType(type.name().replace('$', '.'), project); } finally { token.finish(); } }
@Override protected void tearDown() throws Exception { try { ModuleManager moduleManager = ModuleManager.getInstance(myProject); List<Throwable> errors = null; AccessToken token = WriteAction.start(); try { for (Module module : myModulesToDispose) { try { String moduleName = module.getName(); if (moduleManager.findModuleByName(moduleName) != null) { moduleManager.disposeModule(module); } } catch (Throwable e) { if (errors == null) { errors = new SmartList<Throwable>(); } errors.add(e); } } } finally { token.finish(); } CompoundRuntimeException.throwIfNotEmpty(errors); } finally { myModulesToDispose.clear(); super.tearDown(); } }
public void deleteClassFile(final String className) throws IOException { AccessToken token = WriteAction.start(); try { //noinspection ConstantConditions touch(JavaPsiFacade.getInstance(getProject()).findClass(className, GlobalSearchScope.allScope(getProject())).getContainingFile().getVirtualFile()); } finally { token.finish(); } }
public static void attachSourceJar(@NotNull File sourceJar, @NotNull Collection<Library> libraries) { AccessToken accessToken = WriteAction.start(); try { VirtualFile srcFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(sourceJar); if (srcFile == null) return; VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(srcFile); if (jarRoot == null) return; VirtualFile[] roots = PathUIUtils.scanAndSelectDetectedJavaSourceRoots(null, new VirtualFile[]{jarRoot}); if (roots.length == 0) { roots = new VirtualFile[]{jarRoot}; } for (Library library : libraries) { Library.ModifiableModel model = library.getModifiableModel(); List<VirtualFile> alreadyExistingFiles = Arrays.asList(model.getFiles(OrderRootType.SOURCES)); for (VirtualFile root : roots) { if (!alreadyExistingFiles.contains(root)) { model.addRoot(root, OrderRootType.SOURCES); } } model.commit(); } } finally { accessToken.finish(); } }
public void performCopyTo(final DirDiffElementImpl element) { final DiffElement<?> source = element.getSource(); if (source != null) { final String path = element.getParentNode().getPath(); if (source instanceof BackgroundOperatingDiffElement) { final Ref<String> errorMessage = new Ref<String>(); final Ref<DiffElement> diff = new Ref<DiffElement>(); Runnable onFinish = new Runnable() { @Override public void run() { ApplicationManager.getApplication().assertIsDispatchThread(); if (!myDisposed) { DiffElement newElement = diff.get(); if (newElement == null && element.getTarget() != null) { final int row = myElements.indexOf(element); element.updateTargetData(); fireTableRowsUpdated(row, row); } refreshElementAfterCopyTo(newElement, element); if (!errorMessage.isNull()) { reportException(errorMessage.get()); } } } }; ((BackgroundOperatingDiffElement)source).copyTo(myTrg, errorMessage, diff, onFinish, element.getTarget(), path); } else { final AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(getClass()); try { final DiffElement<?> diffElement = source.copyTo(myTrg, path); refreshElementAfterCopyTo(diffElement, element); } finally { token.finish(); } } } }
public void performCopyFrom(final DirDiffElementImpl element) { final DiffElement<?> target = element.getTarget(); if (target != null) { final String path = element.getParentNode().getPath(); if (target instanceof BackgroundOperatingDiffElement) { final Ref<String> errorMessage = new Ref<String>(); final Ref<DiffElement> diff = new Ref<DiffElement>(); Runnable onFinish = new Runnable() { @Override public void run() { ApplicationManager.getApplication().assertIsDispatchThread(); if (!myDisposed) { refreshElementAfterCopyFrom(element, diff.get()); if (!errorMessage.isNull()) { reportException(errorMessage.get()); } } } }; ((BackgroundOperatingDiffElement)target).copyTo(mySrc, errorMessage, diff, onFinish, element.getSource(), path); } else { final AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(getClass()); try { final DiffElement<?> diffElement = target.copyTo(mySrc, path); refreshElementAfterCopyFrom(element, diffElement); } finally { token.finish(); } } } }
@Override public void loadState(Element state) { List<ModulePath> prevPaths = myModulePaths; readExternal(state); if (prevPaths != null) { ModifiableModuleModel model = getModifiableModel(); Module[] existingModules = model.getModules(); ModuleGroupInterner groupInterner = new ModuleGroupInterner(); for (Module existingModule : existingModules) { ModulePath correspondingPath = findCorrespondingPath(existingModule); if (correspondingPath == null) { model.disposeModule(existingModule); } else { myModulePaths.remove(correspondingPath); String groupStr = correspondingPath.getModuleGroup(); String[] group = groupStr == null ? null : groupStr.split(MODULE_GROUP_SEPARATOR); if (!Arrays.equals(group, model.getModuleGroupPath(existingModule))) { groupInterner.setModuleGroupPath(model, existingModule, group); } } } loadModules((ModuleModelImpl)model); AccessToken token = WriteAction.start(); try { model.commit(); } finally { token.finish(); } } }