Search in sources :

Example 41 with ProcessCanceledException

use of com.intellij.openapi.progress.ProcessCanceledException in project android by JetBrains.

the class AllocationsEditor method parseAllocationsFileInBackground.

private void parseAllocationsFileInBackground(final Project project, final VirtualFile file) {
    final Task.Modal parseTask = new Task.Modal(project, "Parsing allocations file", false) {

        private AllocationInfo[] myAllocations;

        private String myErrorMessage;

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
            final File allocationsFile = VfsUtilCore.virtualToIoFile(file);
            ByteBuffer data;
            try {
                data = ByteBufferUtil.mapFile(allocationsFile, 0, ByteOrder.BIG_ENDIAN);
            } catch (IOException ex) {
                myErrorMessage = "Error reading from allocations file " + allocationsFile.getAbsolutePath();
                throw new ProcessCanceledException();
            }
            if (AllocationsParser.hasOverflowedNumEntriesBug(data)) {
                myErrorMessage = "Invalid allocations file detected. Please refer to https://code.google.com/p/android/issues/detail?id=204503 for details.";
                throw new ProcessCanceledException();
            }
            try {
                myAllocations = AllocationsParser.parse(data);
            } catch (final Throwable throwable) {
                //noinspection ThrowableResultOfMethodCallIgnored
                myErrorMessage = "Unexpected error while parsing allocations file: " + Throwables.getRootCause(throwable).getMessage();
                throw new ProcessCanceledException();
            }
        }

        @Override
        public void onSuccess() {
            AllocationsView view = new AllocationsView(project, myAllocations);
            myPanel.add(view.getComponent(), BorderLayout.CENTER);
        }

        @Override
        public void onCancel() {
            Messages.showErrorDialog(project, myErrorMessage, getName());
        }
    };
    ApplicationManager.getApplication().invokeLater(parseTask::queue);
}
Also used : Task(com.intellij.openapi.progress.Task) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull) ByteBuffer(java.nio.ByteBuffer) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 42 with ProcessCanceledException

use of com.intellij.openapi.progress.ProcessCanceledException in project android by JetBrains.

the class AndroidUtils method executeCommand.

@NotNull
public static ExecutionStatus executeCommand(@NotNull GeneralCommandLine commandLine, @Nullable final OutputProcessor processor, @Nullable WaitingStrategies.Strategy strategy) throws ExecutionException {
    LOG.info(commandLine.getCommandLineString());
    OSProcessHandler handler = new OSProcessHandler(commandLine);
    final ProcessAdapter listener = new ProcessAdapter() {

        @Override
        public void onTextAvailable(final ProcessEvent event, final Key outputType) {
            if (processor != null) {
                final String message = event.getText();
                processor.onTextAvailable(message);
            }
        }
    };
    if (!(strategy instanceof WaitingStrategies.DoNotWait)) {
        handler.addProcessListener(listener);
    }
    handler.startNotify();
    try {
        if (!(strategy instanceof WaitingStrategies.WaitForever)) {
            if (strategy instanceof WaitingStrategies.WaitForTime) {
                handler.waitFor(((WaitingStrategies.WaitForTime) strategy).getTimeMs());
            }
        } else {
            handler.waitFor();
        }
    } catch (ProcessCanceledException e) {
        return ExecutionStatus.ERROR;
    }
    if (!handler.isProcessTerminated()) {
        return ExecutionStatus.TIMEOUT;
    }
    if (!(strategy instanceof WaitingStrategies.DoNotWait)) {
        handler.removeProcessListener(listener);
    }
    int exitCode = handler.getProcess().exitValue();
    return exitCode == 0 ? ExecutionStatus.SUCCESS : ExecutionStatus.ERROR;
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) Key(com.intellij.openapi.util.Key) RelativePoint(com.intellij.ui.awt.RelativePoint) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

Example 43 with ProcessCanceledException

use of com.intellij.openapi.progress.ProcessCanceledException in project android by JetBrains.

the class MergedManifest method syncWithReadPermission.

protected void syncWithReadPermission() {
    AndroidFacet facet = AndroidFacet.getInstance(myModule);
    assert facet != null : "Attempt to obtain manifest info from a non Android module: " + myModule.getName();
    if (myManifestFile == null) {
        myManifestFile = ManifestInfo.ManifestFile.create(facet);
    }
    // Check to see if our data is up to date
    boolean refresh = myManifestFile.refresh();
    if (!refresh) {
        // Already have up to date data
        return;
    }
    myActivityAttributesMap = new HashMap<String, ActivityAttributes>();
    myManifestTheme = null;
    myTargetSdk = AndroidVersion.DEFAULT;
    myMinSdk = AndroidVersion.DEFAULT;
    //$NON-NLS-1$
    myPackage = "";
    //$NON-NLS-1$
    myApplicationId = "";
    myVersionCode = null;
    myApplicationIcon = null;
    myApplicationLabel = null;
    myApplicationSupportsRtl = false;
    myNodeKeys = null;
    myActivities = Lists.newArrayList();
    myActivityAliases = Lists.newArrayListWithExpectedSize(4);
    myServices = Lists.newArrayListWithExpectedSize(4);
    Set<String> permissions = Sets.newHashSetWithExpectedSize(30);
    Set<String> revocable = Sets.newHashSetWithExpectedSize(2);
    try {
        Document document = myManifestFile.getXmlDocument();
        if (document == null) {
            return;
        }
        myDocument = document;
        myManifestFiles = myManifestFile.getManifestFiles();
        Element root = document.getDocumentElement();
        if (root == null) {
            return;
        }
        myApplicationId = getAttributeValue(root, null, ATTRIBUTE_PACKAGE);
        // The package comes from the main manifest, NOT from the merged manifest.
        Manifest manifest = facet.getManifest();
        myPackage = manifest == null ? myApplicationId : manifest.getPackage().getValue();
        String versionCode = getAttributeValue(root, ANDROID_URI, SdkConstants.ATTR_VERSION_CODE);
        try {
            myVersionCode = Integer.valueOf(versionCode);
        } catch (NumberFormatException ignored) {
        }
        Node node = root.getFirstChild();
        while (node != null) {
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                String nodeName = node.getNodeName();
                if (NODE_APPLICATION.equals(nodeName)) {
                    Element application = (Element) node;
                    myApplicationIcon = getAttributeValue(application, ANDROID_URI, ATTRIBUTE_ICON);
                    myApplicationLabel = getAttributeValue(application, ANDROID_URI, ATTRIBUTE_LABEL);
                    myManifestTheme = getAttributeValue(application, ANDROID_URI, ATTRIBUTE_THEME);
                    myApplicationSupportsRtl = VALUE_TRUE.equals(getAttributeValue(application, ANDROID_URI, ATTRIBUTE_SUPPORTS_RTL));
                    String debuggable = getAttributeValue(application, ANDROID_URI, ATTRIBUTE_DEBUGGABLE);
                    myApplicationDebuggable = debuggable == null ? null : VALUE_TRUE.equals(debuggable);
                    Node child = node.getFirstChild();
                    while (child != null) {
                        if (child.getNodeType() == Node.ELEMENT_NODE) {
                            String childNodeName = child.getNodeName();
                            if (NODE_ACTIVITY.equals(childNodeName)) {
                                Element element = (Element) child;
                                ActivityAttributes attributes = new ActivityAttributes(element, myApplicationId);
                                myActivityAttributesMap.put(attributes.getName(), attributes);
                                myActivities.add(element);
                            } else if (NODE_ACTIVITY_ALIAS.equals(childNodeName)) {
                                myActivityAliases.add((Element) child);
                            } else if (NODE_SERVICE.equals(childNodeName)) {
                                myServices.add((Element) child);
                            }
                        }
                        child = child.getNextSibling();
                    }
                } else if (NODE_USES_SDK.equals(nodeName)) {
                    // Look up target SDK
                    Element usesSdk = (Element) node;
                    myMinSdk = getApiVersion(usesSdk, ATTRIBUTE_MIN_SDK_VERSION, AndroidVersion.DEFAULT);
                    myTargetSdk = getApiVersion(usesSdk, ATTRIBUTE_TARGET_SDK_VERSION, myMinSdk);
                } else if (TAG_USES_PERMISSION.equals(nodeName) || TAG_USES_PERMISSION_SDK_23.equals(nodeName) || TAG_USES_PERMISSION_SDK_M.equals(nodeName)) {
                    Element element = (Element) node;
                    String name = element.getAttributeNS(ANDROID_URI, ATTR_NAME);
                    if (!name.isEmpty()) {
                        permissions.add(name);
                    }
                } else if (nodeName.equals(TAG_PERMISSION)) {
                    Element element = (Element) node;
                    String protectionLevel = element.getAttributeNS(ANDROID_URI, ATTR_PROTECTION_LEVEL);
                    if (VALUE_DANGEROUS.equals(protectionLevel)) {
                        String name = element.getAttributeNS(ANDROID_URI, ATTR_NAME);
                        if (!name.isEmpty()) {
                            revocable.add(name);
                        }
                    }
                }
            }
            node = node.getNextSibling();
        }
        myPermissionHolder = new ModulePermissions(ImmutableSet.copyOf(permissions), ImmutableSet.copyOf(revocable));
    } catch (ProcessCanceledException e) {
        // clear the file, to make sure we reload everything on next call to this method
        myManifestFile = null;
        myDocument = null;
        throw e;
    } catch (Exception e) {
        Logger.getInstance(MergedManifest.class).warn("Could not read Manifest data", e);
    }
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) XmlNode(com.android.manifmerger.XmlNode) Document(org.w3c.dom.Document) AndroidManifest(com.android.xml.AndroidManifest) Manifest(org.jetbrains.android.dom.manifest.Manifest) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 44 with ProcessCanceledException

use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.

the class GitRebaseProcess method doRebase.

/**
   * Given a GitRebaseSpec this method either starts, or continues the ongoing rebase in multiple repositories.
   * <ul>
   * <li>It does nothing with "already successfully rebased repositories" (the ones which have {@link GitRebaseStatus} == SUCCESSFUL,
   * and just remembers them to use in the resulting notification.</li>
   * <li>If there is a repository with rebase in progress, it calls `git rebase --continue` (or `--skip`).
   * It is assumed that there is only one such repository.</li>
   * <li>For all remaining repositories rebase on which didn't start yet, it calls {@code git rebase <original parameters>}</li>
   * </ul>
   */
private void doRebase() {
    LOG.info("Started rebase");
    LOG.debug("Started rebase with the following spec: " + myRebaseSpec);
    Map<GitRepository, GitRebaseStatus> statuses = newLinkedHashMap(myRebaseSpec.getStatuses());
    Collection<GitRepository> toRefresh = newLinkedHashSet();
    List<GitRepository> repositoriesToRebase = myRebaseSpec.getIncompleteRepositories();
    AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject);
    try {
        if (!saveDirtyRootsInitially(repositoriesToRebase))
            return;
        GitRepository failed = null;
        for (GitRepository repository : repositoriesToRebase) {
            GitRebaseResumeMode customMode = null;
            if (repository == myRebaseSpec.getOngoingRebase()) {
                customMode = myCustomMode == null ? GitRebaseResumeMode.CONTINUE : myCustomMode;
            }
            GitRebaseStatus rebaseStatus = rebaseSingleRoot(repository, customMode, getSuccessfulRepositories(statuses));
            // make the repo state info actual ASAP
            repository.update();
            statuses.put(repository, rebaseStatus);
            if (shouldBeRefreshed(rebaseStatus)) {
                toRefresh.add(repository);
            }
            if (rebaseStatus.getType() != GitRebaseStatus.Type.SUCCESS) {
                failed = repository;
                break;
            }
        }
        if (failed == null) {
            LOG.debug("Rebase completed successfully.");
            mySaver.load();
        }
        refresh(toRefresh);
        if (failed == null) {
            notifySuccess(getSuccessfulRepositories(statuses), getSkippedCommits(statuses));
        }
        saveUpdatedSpec(statuses);
    } catch (ProcessCanceledException pce) {
        throw pce;
    } catch (Throwable e) {
        myRepositoryManager.setOngoingRebaseSpec(null);
        ExceptionUtil.rethrowUnchecked(e);
    } finally {
        token.finish();
    }
}
Also used : GitRepository(git4idea.repo.GitRepository) AccessToken(com.intellij.openapi.application.AccessToken) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 45 with ProcessCanceledException

use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.

the class GitMergeUpdater method doUpdate.

@Override
@NotNull
protected GitUpdateResult doUpdate() {
    LOG.info("doUpdate ");
    final GitMerger merger = new GitMerger(myProject);
    MergeLineListener mergeLineListener = new MergeLineListener();
    GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector = new GitUntrackedFilesOverwrittenByOperationDetector(myRoot);
    String originalText = myProgressIndicator.getText();
    myProgressIndicator.setText("Merging" + GitUtil.mention(myRepository) + "...");
    try {
        GitCommandResult result = myGit.merge(myRepository, assertNotNull(myTrackedBranches.get(myRoot).getDest()).getName(), asList("--no-stat", "-v"), mergeLineListener, untrackedFilesDetector, GitStandardProgressAnalyzer.createListener(myProgressIndicator));
        myProgressIndicator.setText(originalText);
        return result.success() ? GitUpdateResult.SUCCESS : handleMergeFailure(mergeLineListener, untrackedFilesDetector, merger, result.getErrorOutputAsJoinedString());
    } catch (ProcessCanceledException pce) {
        cancel();
        return GitUpdateResult.CANCEL;
    }
}
Also used : GitMerger(git4idea.merge.GitMerger) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ObjectUtils.assertNotNull(com.intellij.util.ObjectUtils.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)175 NotNull (org.jetbrains.annotations.NotNull)45 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)41 VirtualFile (com.intellij.openapi.vfs.VirtualFile)38 Project (com.intellij.openapi.project.Project)28 Nullable (org.jetbrains.annotations.Nullable)23 IOException (java.io.IOException)20 Task (com.intellij.openapi.progress.Task)16 File (java.io.File)16 Document (com.intellij.openapi.editor.Document)14 Ref (com.intellij.openapi.util.Ref)13 PsiFile (com.intellij.psi.PsiFile)12 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)11 Logger (com.intellij.openapi.diagnostic.Logger)10 StringUtil (com.intellij.openapi.util.text.StringUtil)9 ContainerUtil (com.intellij.util.containers.ContainerUtil)9 ArrayList (java.util.ArrayList)9 NonNls (org.jetbrains.annotations.NonNls)9 ProgressManager (com.intellij.openapi.progress.ProgressManager)8 java.util (java.util)8