Search in sources :

Example 76 with OperationCanceledException

use of org.eclipse.core.runtime.OperationCanceledException in project che by eclipse.

the class TextSearchVisitor method processFile.

/**
//	 * @return returns a map from IFile to IDocument for all open, dirty editors
//	 */
//	private Map evalNonFileBufferDocuments() {
//		Map result = new HashMap();
//		IWorkbench workbench = SearchPlugin.getDefault().getWorkbench();
//		IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
//		for (int i = 0; i < windows.length; i++) {
//			IWorkbenchPage[] pages = windows[i].getPages();
//			for (int x = 0; x < pages.length; x++) {
//				IEditorReference[] editorRefs = pages[x].getEditorReferences();
//				for (int z = 0; z < editorRefs.length; z++) {
//					IEditorPart ep = editorRefs[z].getEditor(false);
//					if (ep instanceof ITextEditor && ep.isDirty()) { // only dirty editors
//						evaluateTextEditor(result, ep);
//					}
//				}
//			}
//		}
//		return result;
//	}
//	private void evaluateTextEditor(Map result, IEditorPart ep) {
//		IEditorInput input= ep.getEditorInput();
//		if (input instanceof IFileEditorInput) {
//			IFile file= ((IFileEditorInput) input).getFile();
//			if (!result.containsKey(file)) { // take the first editor found
//				ITextFileBufferManager bufferManager= FileBuffers.getTextFileBufferManager();
//				ITextFileBuffer textFileBuffer= bufferManager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
//				if (textFileBuffer != null) {
//					// file buffer has precedence
//					result.put(file, textFileBuffer.getDocument());
//				} else {
//					// use document provider
//					IDocument document= ((ITextEditor) ep).getDocumentProvider().getDocument(input);
//					if (document != null) {
//						result.put(file, document);
//					}
//				}
//			}
//		}
//	}
public boolean processFile(IFile file, Map documentsInEditors) {
    try {
        if (!fCollector.acceptFile(file) || fMatcher == null) {
            return true;
        }
        IDocument document = getOpenDocument(file, documentsInEditors);
        if (document != null) {
            DocumentCharSequence documentCharSequence = new DocumentCharSequence(document);
            // assume all documents are non-binary
            locateMatches(file, documentCharSequence);
        } else {
            CharSequence seq = null;
            try {
                seq = fFileCharSequenceProvider.newCharSequence(file);
                if (hasBinaryContent(seq, file) && !fCollector.reportBinaryFile(file)) {
                    return true;
                }
                locateMatches(file, seq);
            } catch (FileCharSequenceProvider.FileCharSequenceException e) {
                e.throwWrappedException();
            } finally {
                if (seq != null) {
                    try {
                        fFileCharSequenceProvider.releaseCharSequence(seq);
                    } catch (IOException e) {
                        SearchPlugin.log(e);
                    }
                }
            }
        }
    } catch (UnsupportedCharsetException e) {
        String[] args = { getCharSetName(file), file.getFullPath().makeRelative().toString() };
        String message = Messages.format(SearchMessages.TextSearchVisitor_unsupportedcharset, args);
        fStatus.add(new Status(IStatus.ERROR, NewSearchUI.PLUGIN_ID, IStatus.ERROR, message, e));
    } catch (IllegalCharsetNameException e) {
        String[] args = { getCharSetName(file), file.getFullPath().makeRelative().toString() };
        String message = Messages.format(SearchMessages.TextSearchVisitor_illegalcharset, args);
        fStatus.add(new Status(IStatus.ERROR, NewSearchUI.PLUGIN_ID, IStatus.ERROR, message, e));
    } catch (IOException e) {
        String[] args = { getExceptionMessage(e), file.getFullPath().makeRelative().toString() };
        String message = Messages.format(SearchMessages.TextSearchVisitor_error, args);
        fStatus.add(new Status(IStatus.ERROR, NewSearchUI.PLUGIN_ID, IStatus.ERROR, message, e));
    } catch (CoreException e) {
        String[] args = { getExceptionMessage(e), file.getFullPath().makeRelative().toString() };
        String message = Messages.format(SearchMessages.TextSearchVisitor_error, args);
        fStatus.add(new Status(IStatus.ERROR, NewSearchUI.PLUGIN_ID, IStatus.ERROR, message, e));
    } catch (StackOverflowError e) {
        String message = SearchMessages.TextSearchVisitor_patterntoocomplex0;
        fStatus.add(new Status(IStatus.ERROR, NewSearchUI.PLUGIN_ID, IStatus.ERROR, message, e));
        return false;
    } finally {
        fNumberOfScannedFiles++;
    }
    if (fProgressMonitor.isCanceled())
        throw new OperationCanceledException(SearchMessages.TextSearchVisitor_canceled);
    return true;
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IOException(java.io.IOException) IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) FileCharSequenceException(org.eclipse.search.internal.core.text.FileCharSequenceProvider.FileCharSequenceException) CoreException(org.eclipse.core.runtime.CoreException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) IDocument(org.eclipse.jface.text.IDocument)

Example 77 with OperationCanceledException

use of org.eclipse.core.runtime.OperationCanceledException in project che by eclipse.

the class WorkspaceModifyOperation method run.

/**
     * The <code>WorkspaceModifyOperation</code> implementation of this
     * <code>IRunnableWithProgress</code> method initiates a batch of changes by
     * invoking the <code>execute</code> method as a workspace runnable
     * (<code>IWorkspaceRunnable</code>).
     */
public final synchronized void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    final InvocationTargetException[] iteHolder = new InvocationTargetException[1];
    try {
        IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable() {

            public void run(IProgressMonitor pm) throws CoreException {
                try {
                    execute(pm);
                } catch (InvocationTargetException e) {
                    // Pass it outside the workspace runnable
                    iteHolder[0] = e;
                } catch (InterruptedException e) {
                    // caught and re-thrown as InterruptedException below.
                    throw new OperationCanceledException(e.getMessage());
                }
            // CoreException and OperationCanceledException are propagated
            }
        };
        ResourcesPlugin.getWorkspace().run(workspaceRunnable, rule, IResource.NONE, monitor);
    } catch (CoreException e) {
        throw new InvocationTargetException(e);
    } catch (OperationCanceledException e) {
        throw new InterruptedException(e.getMessage());
    }
    // Re-throw the InvocationTargetException, if any occurred
    if (iteHolder[0] != null) {
        throw iteHolder[0];
    }
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 78 with OperationCanceledException

use of org.eclipse.core.runtime.OperationCanceledException in project che by eclipse.

the class FileUndoState method createExistentResourceFromHandle.

public void createExistentResourceFromHandle(IResource resource, IProgressMonitor monitor) throws CoreException {
    Assert.isLegal(resource instanceof IFile);
    if (resource.exists()) {
        return;
    }
    IFile fileHandle = (IFile) resource;
    //$NON-NLS-1$
    monitor.beginTask("", 200);
    monitor.setTaskName(RefactoringCoreMessages.FileDescription_NewFileProgress);
    try {
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        if (location != null) {
            fileHandle.createLink(location, IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(monitor, 200));
        } else {
            InputStream contents = new ByteArrayInputStream(RefactoringCoreMessages.FileDescription_ContentsCouldNotBeRestored.getBytes());
            // object and are restored in #restoreResourceAttributes
            if (fileContentDescription != null && fileContentDescription.exists()) {
                contents = fileContentDescription.getContents();
            }
            fileHandle.create(contents, false, new SubProgressMonitor(monitor, 100));
            fileHandle.setCharset(charset, new SubProgressMonitor(monitor, 100));
        }
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
    } catch (CoreException e) {
        if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED) {
            fileHandle.refreshLocal(IResource.DEPTH_ZERO, null);
        } else {
            throw e;
        }
    } finally {
        monitor.done();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 79 with OperationCanceledException

use of org.eclipse.core.runtime.OperationCanceledException in project che by eclipse.

the class FileDescription method createExistentResourceFromHandle.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.internal.ide.undo.ResourceDescription#createExistentResourceFromHandle(org.eclipse.core.resources.IResource,
	 *      org.eclipse.core.runtime.IProgressMonitor)
	 */
public void createExistentResourceFromHandle(IResource resource, IProgressMonitor monitor) throws CoreException {
    Assert.isLegal(resource instanceof IFile);
    if (resource.exists()) {
        return;
    }
    IFile fileHandle = (IFile) resource;
    //$NON-NLS-1$
    monitor.beginTask("", 200);
    monitor.setTaskName(UndoMessages.FileDescription_NewFileProgress);
    try {
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        if (location != null) {
            fileHandle.createLink(location, IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(monitor, 200));
        } else {
            InputStream contents = new ByteArrayInputStream(UndoMessages.FileDescription_ContentsCouldNotBeRestored.getBytes());
            // object and are restored in #restoreResourceAttributes
            if (fileContentDescription != null && fileContentDescription.exists()) {
                contents = fileContentDescription.getContents();
            }
            fileHandle.create(contents, false, new SubProgressMonitor(monitor, 100));
            fileHandle.setCharset(charset, new SubProgressMonitor(monitor, 100));
        }
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
    } catch (CoreException e) {
        if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED) {
            fileHandle.refreshLocal(IResource.DEPTH_ZERO, null);
        } else {
            throw e;
        }
    } finally {
        monitor.done();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 80 with OperationCanceledException

use of org.eclipse.core.runtime.OperationCanceledException in project che by eclipse.

the class FolderDescription method createExistentResourceFromHandle.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.internal.ide.undo.ResourceDescription#createExistentResourceFromHandle(org.eclipse.core.resources.IResource,
	 *      org.eclipse.core.runtime.IProgressMonitor)
	 */
public void createExistentResourceFromHandle(IResource resource, IProgressMonitor monitor) throws CoreException {
    Assert.isLegal(resource instanceof IFolder);
    if (resource.exists()) {
        return;
    }
    IFolder folderHandle = (IFolder) resource;
    try {
        //$NON-NLS-1$
        monitor.beginTask("", 200);
        monitor.setTaskName(UndoMessages.FolderDescription_NewFolderProgress);
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        if (filters != null) {
            for (int i = 0; i < filters.length; i++) {
                folderHandle.createFilter(filters[i].getType(), filters[i].getFileInfoMatcherDescription(), 0, new SubProgressMonitor(monitor, 100));
            }
        }
        if (location != null) {
            folderHandle.createLink(location, IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(monitor, 100));
        } else {
            folderHandle.create(virtual ? IResource.VIRTUAL : 0, true, new SubProgressMonitor(monitor, 100));
        }
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        createChildResources(folderHandle, monitor, 100);
    } finally {
        monitor.done();
    }
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)134 CoreException (org.eclipse.core.runtime.CoreException)38 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)37 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)34 ArrayList (java.util.ArrayList)25 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)24 IOException (java.io.IOException)21 IFile (org.eclipse.core.resources.IFile)21 IStatus (org.eclipse.core.runtime.IStatus)21 InvocationTargetException (java.lang.reflect.InvocationTargetException)20 Status (org.eclipse.core.runtime.Status)16 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)16 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)16 File (java.io.File)15 SubMonitor (org.eclipse.core.runtime.SubMonitor)10 Job (org.eclipse.core.runtime.jobs.Job)9 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)9 IProject (org.eclipse.core.resources.IProject)8 HashSet (java.util.HashSet)7 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)7