Search in sources :

Example 36 with AccessToken

use of com.intellij.openapi.application.AccessToken in project moe-ide-integration by multi-os-engine.

the class MOEMavenRunner method runBatch.

public boolean runBatch(List<MavenRunnerParameters> commands, @Nullable MavenGeneralSettings coreSettings, @Nullable MavenRunnerSettings runnerSettings, @Nullable final String action, @Nullable ProgressIndicator indicator) {
    LOG.assertTrue(!ApplicationManager.getApplication().isReadAccessAllowed());
    if (commands.isEmpty())
        return true;
    MavenConsole console;
    AccessToken accessToken = ReadAction.start();
    try {
        if (myProject.isDisposed())
            return false;
        console = createConsole();
    } finally {
        accessToken.finish();
    }
    try {
        int count = 0;
        for (MavenRunnerParameters command : commands) {
            if (indicator != null) {
                indicator.setFraction(((double) count++) / commands.size());
            }
            MavenExecutor executor;
            accessToken = ReadAction.start();
            try {
                if (myProject.isDisposed())
                    break;
                executor = createExecutor(command, coreSettings, runnerSettings, console);
            } finally {
                accessToken.finish();
            }
            executor.setAction(action);
            if (!executor.execute(indicator)) {
                updateTargetFolders();
                return false;
            }
        }
        updateTargetFolders();
    } finally {
        console.finish();
    }
    return true;
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) MavenConsole(org.jetbrains.idea.maven.project.MavenConsole)

Example 37 with AccessToken

use of com.intellij.openapi.application.AccessToken in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudAttachDialog method stash.

private boolean stash() {
    if (!syncResult.hasLocalRepository()) {
        LOG.error("unexpected null local repro in call to stash");
        return false;
    }
    final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
    if (changeListManager.isFreezedWithNotification("Can not stash changes now")) {
        return false;
    }
    final GitLineHandler handler = new GitLineHandler(project, sourceRepository.getRoot(), GitCommand.STASH);
    handler.addParameters("save");
    handler.addParameters("--keep-index");
    String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date());
    stashMessage = "Cloud Debugger saved changes from branch " + originalBranchName + " at " + date;
    handler.addParameters(stashMessage);
    AccessToken token = DvcsUtil.workingTreeChangeStarted(project);
    try {
        GitHandlerUtil.doSynchronously(handler, GitBundle.getString("stashing.title"), handler.printableCommandLine());
    } finally {
        token.finish();
    }
    return true;
}
Also used : GitLineHandler(git4idea.commands.GitLineHandler) AccessToken(com.intellij.openapi.application.AccessToken) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) Date(java.util.Date)

Example 38 with AccessToken

use of com.intellij.openapi.application.AccessToken in project azure-tools-for-java by Microsoft.

the class ApplicationInsightsPanel method configureAzureSDK.

private void configureAzureSDK() {
    final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
    for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
        if (orderEntry instanceof ModuleLibraryOrderEntryImpl && AzureLibrary.APP_INSIGHTS.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
            return;
        }
    }
    final LibrariesContainer.LibraryLevel level = LibrariesContainer.LibraryLevel.MODULE;
    AccessToken token = WriteAction.start();
    try {
        Library newLibrary = LibrariesContainerFactory.createContainer(modifiableModel).createLibrary(AzureLibrary.APP_INSIGHTS.getName(), level, new ArrayList<OrderRoot>());
        for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
            if (orderEntry instanceof ModuleLibraryOrderEntryImpl && AzureLibrary.APP_INSIGHTS.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
                ((ModuleLibraryOrderEntryImpl) orderEntry).setExported(true);
                break;
            }
        }
        Library.ModifiableModel newLibraryModel = newLibrary.getModifiableModel();
        AddLibraryUtility.addLibraryFiles(new File(PluginHelper.getAzureLibLocation()), newLibraryModel, AzureLibrary.APP_INSIGHTS.getFiles());
        newLibraryModel.commit();
        modifiableModel.commit();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        token.finish();
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) OrderEntry(com.intellij.openapi.roots.OrderEntry) AccessToken(com.intellij.openapi.application.AccessToken) ModuleLibraryOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl) LibrariesContainer(com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) Library(com.intellij.openapi.roots.libraries.Library) File(java.io.File)

Example 39 with AccessToken

use of com.intellij.openapi.application.AccessToken in project azure-tools-for-java by Microsoft.

the class LibrariesConfigurationDialog method removeLibrary.

private void removeLibrary() {
    AzureLibrary azureLibrary = (AzureLibrary) librariesList.getSelectedValue();
    AccessToken token = WriteAction.start();
    try {
        final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
        modifiableModel.getModuleLibraryTable().removeLibrary(modifiableModel.getModuleLibraryTable().getLibraryByName(azureLibrary.getName()));
        modifiableModel.commit();
    } finally {
        token.finish();
    }
    ((DefaultListModel) librariesList.getModel()).removeElement(azureLibrary);
    tempList.remove(azureLibrary);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) AccessToken(com.intellij.openapi.application.AccessToken)

Example 40 with AccessToken

use of com.intellij.openapi.application.AccessToken in project azure-tools-for-java by Microsoft.

the class LibrariesConfigurationDialog method editLibrary.

private void editLibrary() {
    AzureLibrary azureLibrary = (AzureLibrary) librariesList.getSelectedValue();
    final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
    OrderEntry libraryOrderEntry = null;
    for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
        if (orderEntry instanceof ModuleLibraryOrderEntryImpl && azureLibrary.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
            libraryOrderEntry = orderEntry;
            break;
        }
    }
    if (libraryOrderEntry != null) {
        LibraryPropertiesPanel libraryPropertiesPanel = new LibraryPropertiesPanel(module, azureLibrary, true, ((ModuleLibraryOrderEntryImpl) libraryOrderEntry).isExported());
        DefaultDialogWrapper libraryProperties = new DefaultDialogWrapper(module.getProject(), libraryPropertiesPanel);
        libraryProperties.show();
        if (libraryProperties.isOK()) {
            AccessToken token = WriteAction.start();
            try {
                ((ModuleLibraryOrderEntryImpl) libraryOrderEntry).setExported(libraryPropertiesPanel.isExported());
                modifiableModel.commit();
            } finally {
                token.finish();
            }
            LocalFileSystem.getInstance().findFileByPath(PluginUtil.getModulePath(module)).refresh(true, true);
        }
    } else {
        PluginUtil.displayInfoDialog("Library not found", "Library was not found");
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) OrderEntry(com.intellij.openapi.roots.OrderEntry) AccessToken(com.intellij.openapi.application.AccessToken) DefaultDialogWrapper(com.microsoft.intellij.ui.components.DefaultDialogWrapper) ModuleLibraryOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl)

Aggregations

AccessToken (com.intellij.openapi.application.AccessToken)97 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 Nullable (org.jetbrains.annotations.Nullable)15 Module (com.intellij.openapi.module.Module)13 Project (com.intellij.openapi.project.Project)12 Document (com.intellij.openapi.editor.Document)10 GitRepository (git4idea.repo.GitRepository)9 ArrayList (java.util.ArrayList)9 PsiElement (com.intellij.psi.PsiElement)7 NotNull (org.jetbrains.annotations.NotNull)6 File (java.io.File)5 IOException (java.io.IOException)5 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)4 PsiFile (com.intellij.psi.PsiFile)4 List (java.util.List)4 HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)4 ReadAction (com.intellij.openapi.application.ReadAction)3 CompileContext (com.intellij.openapi.compiler.CompileContext)3 CompileTask (com.intellij.openapi.compiler.CompileTask)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3