org.eclipse.core.runtime.CoreException#getStatus ( )源码实例Demo

下面列出了org.eclipse.core.runtime.CoreException#getStatus ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

protected IStatus run(IProgressMonitor pm) {
	try {
		if (this.externalFolders == null) 
			return Status.OK_STATUS;
		IPath externalPath = null;
		for (int index = 0; index < this.externalFolders.size(); index++ ) {
			if ((externalPath = (IPath)this.externalFolders.get(index)) != null) {
				IFolder folder = getFolder(externalPath);
				// https://bugs.eclipse.org/bugs/show_bug.cgi?id=321358
				if (folder != null)
					folder.refreshLocal(IResource.DEPTH_INFINITE, pm);
			}
			// Set the processed ones to null instead of removing the element altogether,
			// so that they will not be considered as duplicates.
			// This will also avoid elements being shifted to the left every time an element
			// is removed. However, there is a risk of Collection size to be increased more often.
			this.externalFolders.setElementAt(null, index);
		}
	} catch (CoreException e) {
		return e.getStatus();
	}
	return Status.OK_STATUS;
}
 
源代码2 项目: netbeans   文件: BugzillaExecutor.java
private static String getNotFoundError(CoreException ce) {
    IStatus status = ce.getStatus();
    Throwable t = status.getException();
    if(t instanceof UnknownHostException ||
       // XXX maybe a different msg ?     
       t instanceof SocketTimeoutException || 
       t instanceof NoRouteToHostException ||
       t instanceof ConnectException) 
    {
        Bugzilla.LOG.log(Level.FINER, null, t);
        return NbBundle.getMessage(BugzillaExecutor.class, "MSG_HOST_NOT_FOUND");                   // NOI18N
    }
    String msg = getMessage(ce);
    if(msg != null) {
        msg = msg.trim().toLowerCase();
        if(HTTP_ERROR_NOT_FOUND.equals(msg)) {
            Bugzilla.LOG.log(Level.FINER, "returned error message [{0}]", msg);                     // NOI18N
            return NbBundle.getMessage(BugzillaExecutor.class, "MSG_HOST_NOT_FOUND");               // NOI18N
        }
    }
    return null;
}
 
源代码3 项目: eclipsegraphviz   文件: SaveToFileAction.java
@Override
protected IStatus run(IProgressMonitor monitor) {
    monitor.beginTask("saving image", 100);
    getJobManager().beginRule(AbstractGraphicalContentProvider.CONTENT_LOADING_RULE, monitor);
    try {
        IGraphicalContentProvider provider = (IGraphicalContentProvider) providerDefinition.getProvider();
        Object input = providerDefinition.read(view.getSelectedFile());
        provider.saveImage(Display.getDefault(), new Point(0, 0), input, path, fileFormat);
    } catch (CoreException e) {
        return e.getStatus();
    } finally {
        getJobManager().endRule(AbstractGraphicalContentProvider.CONTENT_LOADING_RULE);
        monitor.done();
    }
    return Status.OK_STATUS;
}
 
源代码4 项目: orion.server   文件: DirectoryHandlerV1.java
/**
 * Performs the actual modification corresponding to a POST request. All preconditions
 * are assumed to be satisfied.
 * @return <code>true</code> if the operation was successful, and <code>false</code> otherwise.
 */
private boolean performPost(HttpServletRequest request, HttpServletResponse response, JSONObject requestObject, IFileStore toCreate, int options) throws CoreException, IOException, ServletException {
	boolean isCopy = (options & CREATE_COPY) != 0;
	boolean isMove = (options & CREATE_MOVE) != 0;
	try {
		if (isCopy || isMove)
			return performCopyMove(request, response, requestObject, toCreate, isCopy, options);
		if (requestObject.optBoolean(ProtocolConstants.KEY_DIRECTORY))
			toCreate.mkdir(EFS.NONE, null);
		else
			toCreate.openOutputStream(EFS.NONE, null).close();
	} catch (CoreException e) {
		IStatus status = e.getStatus();
		if (status != null && status.getCode() == EFS.ERROR_WRITE) {
			// Sanitize message, as it might contain the filepath.
			statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Failed to create: " + toCreate.getName(), null));
			return false;
		}
		throw e;
	}
	return true;
}
 
源代码5 项目: APICloud-Studio   文件: ProcessRunner.java
public IStatus run(IPath workingDirectory, Map<String, String> environment, char[] input, List<String> args,
		IProgressMonitor monitor)
{
	try
	{
		// FIXME If the monitor is cancelled we should kill the process if it is blocked! Since it's in another
		// thread we should be able to do so!
		Process p = doRun(args, workingDirectory, environment, false, null, null);
		ProcessRunnable runnable = new SudoCommandProcessRunnable(p, monitor, true, input);
		Thread t = new Thread(runnable, "Runnable for " + args.get(0)); //$NON-NLS-1$
		t.start();
		t.join();
		return runnable.getResult();
	}
	catch (CoreException ce)
	{
		return ce.getStatus();
	}
	catch (Exception e)
	{
		return new Status(Status.ERROR, CorePlugin.PLUGIN_ID, e.getMessage());
	}
}
 
@Override
protected IStatus run(IProgressMonitor monitor) {
  try {
    AppEngineStandardFacet.installAppEngineFacet(facetedProject,
        false /* installDependentFacets */, monitor);
    return Status.OK_STATUS;
  } catch (CoreException ex1) {
    // Remove App Engine as primary runtime
    try {
      facetedProject.removeTargetedRuntime(newRuntime, monitor);
      return ex1.getStatus();  // Displays missing constraints that prevented facet installation
    } catch (CoreException ex2) {
      return StatusUtil.merge(ex1.getStatus(), ex2.getStatus());
    }
  }
}
 
/**
 * Handles the exception thrown from JDT Core when the attached Javadoc
 * cannot be retrieved due to accessibility issues or location URL issue. This exception is not
 * logged but the exceptions occurred due to other reasons are logged.
 * 
 * @param e the exception thrown when retrieving the Javadoc fails
 * @return the String message for why the Javadoc could not be retrieved
 * @since 3.9
 */
public static String handleFailedJavadocFetch(CoreException e) {
	IStatus status= e.getStatus();
	if (JavaCore.PLUGIN_ID.equals(status.getPlugin())) {
		Throwable cause= e.getCause();
		int code= status.getCode();
		// See bug 120559, bug 400060 and bug 400062
		if (code == IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC_TIMEOUT
				|| (code == IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC && (cause instanceof FileNotFoundException || cause instanceof SocketException
						|| cause instanceof UnknownHostException
						|| cause instanceof ProtocolException)))
			return CorextMessages.JavaDocLocations_error_gettingAttachedJavadoc;
	}
	JavaPlugin.log(e);
	return CorextMessages.JavaDocLocations_error_gettingJavadoc;
}
 
源代码8 项目: APICloud-Studio   文件: JSMetadataLoader.java
/**
 * rebuildProjectIndexes
 */
private void rebuildProjectIndexes()
{
	Job job = new Job(Messages.JSMetadataLoader_Rebuilding_Project_Indexes)
	{
		@Override
		protected IStatus run(IProgressMonitor monitor)
		{
			IWorkspace ws = ResourcesPlugin.getWorkspace();

			try
			{
				ws.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
			}
			catch (final CoreException e)
			{
				return e.getStatus();
			}

			return Status.OK_STATUS;
		}
	};

	job.schedule();
}
 
源代码9 项目: xtext-eclipse   文件: XbaseDocumentProvider.java
@Override
protected ElementInfo createElementInfo(Object element) throws CoreException {
	if (element instanceof IClassFileEditorInput) {
		IDocument document = null;
		IStatus status = null;
		try {
			document = createDocument(element);
		} catch (CoreException x) {
			status = x.getStatus();
			document = createEmptyDocument();
		}
		ClassFileInfo info = new ClassFileInfo(document, createAnnotationModel(element));
		info.fStatus = status;
		registerAnnotationInfoProcessor(info);
		return info;
	}
	return super.createElementInfo(element);
}
 
源代码10 项目: thym   文件: RestoreProjectListener.java
@Override
public IStatus run(IProgressMonitor monitor) {
	HybridProject hybridProject  = HybridProject.getHybridProject(project);
	if(hybridProject != null){
		try{
			//do not call prepare for project with no engines otherwise cordova will complain
			if(hybridProject.getEngineManager().hasActiveEngine()) {
				hybridProject.prepare(monitor);
			}
		}catch(CoreException e){
			return e.getStatus();
		}
	}
	return Status.OK_STATUS;
}
 
源代码11 项目: ermaster-b   文件: TestEditor.java
protected void validateState(IEditorInput input) {

		IDocumentProvider provider = getDocumentProvider();
		if (!(provider instanceof IDocumentProviderExtension))
			return;

		IDocumentProviderExtension extension = (IDocumentProviderExtension) provider;

		try {

			extension.validateState(input, getSite().getShell());

		} catch (CoreException x) {
			IStatus status = x.getStatus();
			if (status == null || status.getSeverity() != IStatus.CANCEL) {
				Bundle bundle = Platform.getBundle(PlatformUI.PLUGIN_ID);
				ILog log = Platform.getLog(bundle);
				log.log(x.getStatus());

				Shell shell = getSite().getShell();
				String title = "EditorMessages.Editor_error_validateEdit_title";
				String msg = "EditorMessages.Editor_error_validateEdit_message";
				ErrorDialog.openError(shell, title, msg, x.getStatus());
			}
			return;
		}

		if (fSourceViewer != null)
			fSourceViewer.setEditable(isEditable());

	}
 
源代码12 项目: netbeans   文件: BugzillaExecutor.java
static String getMessage(CoreException ce) {
    String msg = ce.getMessage();
    if(msg != null && !msg.trim().equals("")) {                             // NOI18N
        return msg;
    }
    IStatus status = ce.getStatus();
    msg = status != null ? status.getMessage() : null;
    return msg != null ? msg.trim() : null;
}
 
protected void perform(CoreException e, Shell shell, String title, String message) {
	JavaPlugin.log(e);
	IStatus status= e.getStatus();
	if (status != null) {
		ErrorDialog.openError(shell, title, message, status);
	} else {
		displayMessageDialog(e.getMessage(), shell, title, message);
	}
}
 
源代码14 项目: bonita-studio   文件: ApplicationFileStore.java
@Override
public IStatus build(IPath buildPath, IProgressMonitor monitor) {
    IPath applicationFolderPath = buildPath.append("application");
    IFolder applicationFolder = getRepository().getProject()
            .getFolder(applicationFolderPath.makeRelativeTo(getRepository().getProject().getLocation()));
    if (!applicationFolder.exists()) {
        try {
            applicationFolder.create(true, true, new NullProgressMonitor());
            getResource().copy(applicationFolder.getFile(getName()).getFullPath(), false, new NullProgressMonitor());
        } catch (CoreException e) {
            return e.getStatus();
        }
    }
    return Status.OK_STATUS;
}
 
源代码15 项目: corrosion   文件: DebugUtil.java
/**
 * Extracts an error message that can be presented to the user from an exception
 * when trying to execute GDB via CDT tooling.
 *
 * @param e exception thrown when trying to exceute GDB
 * @return error message that can be presented to user
 */
/* package */ static String getMessageFromGdbExecutionException(CoreException e) {
	final IStatus status = e.getStatus();
	final String statusMessage = status.getMessage();
	final Throwable statusException = status.getException();
	if (statusException != null) {
		String exceptionMessage = statusException.getLocalizedMessage();
		return NLS.bind(Messages.RustDebugTabGroup_gdbErrorMsg, statusMessage, exceptionMessage);
	}
	// else
	return statusMessage;
}
 
@Override
protected IStatus run(IProgressMonitor monitor) {
  try {
    AppEngineStandardFacet.installAllAppEngineRuntimes(facetedProject, monitor);
    return Status.OK_STATUS;

  } catch (CoreException ex) {
    return ex.getStatus();
  }
}
 
源代码17 项目: spotbugs   文件: MarkerUtil.java
/**
 * Create an Eclipse marker for given BugInstance.
 *
 * @param javaProject
 *            the project
 * @param monitor
 */
public static void createMarkers(final IJavaProject javaProject, final SortedBugCollection theCollection, final ISchedulingRule rule,
        IProgressMonitor monitor) {
    if (monitor.isCanceled()) {
        return;
    }
    final List<MarkerParameter> bugParameters = createBugParameters(javaProject, theCollection, monitor);
    if (monitor.isCanceled()) {
        return;
    }
    WorkspaceJob wsJob = new WorkspaceJob("Creating SpotBugs markers") {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor1) throws CoreException {
            IProject project = javaProject.getProject();
            try {
                new MarkerReporter(bugParameters, theCollection, project).run(monitor1);
            } catch (CoreException e) {
                FindbugsPlugin.getDefault().logException(e, "Core exception on add marker");
                return e.getStatus();
            }
            return monitor1.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS;
        }
    };
    wsJob.setRule(rule);
    wsJob.setSystem(true);
    wsJob.setUser(false);
    wsJob.schedule();
}
 
源代码18 项目: tracecompass   文件: CtfTmfTraceTrimmingTest.java
/**
 * Test setup
 *
 * @throws IOException
 *             failed to load the file
 * @throws TmfTraceException
 *             failed to load the trace
 */
@Before
public void setup() throws IOException, TmfTraceException {
    fOriginalTrace = CtfTmfTestTraceUtils.getTrace(fTestTrace);
    openTrace(fOriginalTrace);

    TmfTimeRange traceCutRange = getTraceCutRange(fOriginalTrace);
    assertNotNull(traceCutRange);
    fRequestedTraceCutRange = traceCutRange;

    ITmfTimestamp requestedTraceCutEnd = traceCutRange.getEndTime();
    ITmfTimestamp requestedTraceCutStart = traceCutRange.getStartTime();
    assertTrue(fOriginalTrace.getTimeRange().contains(traceCutRange));

    TmfTimeRange range = new TmfTimeRange(
            requestedTraceCutStart,
            requestedTraceCutEnd);
    try {
        /* Perform the trim to create the new trace */
        Path newTracePath = Files.createTempDirectory("trimmed-trace-test" + fTestTrace.name());
        fNewTracePath = newTracePath;
        assertNotNull(newTracePath);
        fNewTracePath.toFile().delete();
        fOriginalTrace.trim(range, newTracePath, new NullProgressMonitor());

        /* Initialize the new trace */
        fNewTrace = new CtfTmfTrace();
        fNewTrace.initTrace(null, newTracePath.toString(), CtfTmfEvent.class);
        openTrace(fNewTrace);

    } catch (CoreException e) {
        /*
         * CoreException are more or less useless, all the interesting stuff is in their
         * "status" objects.
         */
        String msg;
        IStatus status = e.getStatus();
        IStatus[] children = status.getChildren();
        if (children == null) {
            msg = status.getMessage();
        } else {
            msg = Arrays.stream(children)
                    .map(IStatus::getMessage)
                    .collect(Collectors.joining("\n"));
        }
        fail(msg);
    }
}
 
源代码19 项目: APICloud-Studio   文件: IndexFilterManager.java
/**
 * commitFilteredItems
 */
public void commitFilteredItems()
{
	// build a preference value of all file stores we are filtering
	List<String> uris = CollectionsUtil.map(_filteredItems, new IMap<IFileStore, String>()
	{
		public String map(IFileStore item)
		{
			URI uri = item.toURI();
			return uri.toString();
		}
	});
	String value = StringUtil.join(ITEM_DELIMITER, uris);

	// now save the file store list
	IEclipsePreferences prefs = EclipseUtil.instanceScope().getNode(IndexPlugin.PLUGIN_ID);
	prefs.put(IPreferenceConstants.FILTERED_INDEX_URIS, value);
	try
	{
		prefs.flush();
	}
	catch (BackingStoreException e1)
	{
		// ignore
	}

	// determine which file stores were added and deleted
	Collection<IFileStore> nonOverlapping = CollectionsUtil.getNonOverlapping(loadFilteredItems(), _filteredItems);

	// determine which projects have been affected by the last set of changes
	Set<IProject> projects = new HashSet<IProject>(nonOverlapping.size());
	for (IFileStore f : nonOverlapping)
	{
		IResource resource = (IResource) f.getAdapter(IResource.class);

		if (resource != null)
		{
			projects.add(resource.getProject());
		}
	}

	// update project indexes that were affected by our changes
	for (final IProject p : projects)
	{
		Job job = new Job(MessageFormat.format(Messages.IndexFilterManager_Rebuilding_0, p.getName()))
		{
			protected IStatus run(IProgressMonitor monitor)
			{
				try
				{
					p.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
				}
				catch (CoreException e)
				{
					return e.getStatus();
				}
				return Status.OK_STATUS;
			}

		};
		job.schedule();
	}
}
 
源代码20 项目: bonita-studio   文件: ProcessDiagramEditor.java
/**
* @generated
*/
protected void performSaveAs(IProgressMonitor progressMonitor) {
	Shell shell = getSite().getShell();
	IEditorInput input = getEditorInput();
	SaveAsDialog dialog = new SaveAsDialog(shell);
	IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null;
	if (original != null) {
		dialog.setOriginalFile(original);
	}
	dialog.create();
	IDocumentProvider provider = getDocumentProvider();
	if (provider == null) {
		// editor has been programmatically closed while the dialog was open
		return;
	}
	if (provider.isDeleted(input) && original != null) {
		String message = NLS.bind(Messages.ProcessDiagramEditor_SavingDeletedFile, original.getName());
		dialog.setErrorMessage(null);
		dialog.setMessage(message, IMessageProvider.WARNING);
	}
	if (dialog.open() == Window.CANCEL) {
		if (progressMonitor != null) {
			progressMonitor.setCanceled(true);
		}
		return;
	}
	IPath filePath = dialog.getResult();
	if (filePath == null) {
		if (progressMonitor != null) {
			progressMonitor.setCanceled(true);
		}
		return;
	}
	IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	IFile file = workspaceRoot.getFile(filePath);
	final IEditorInput newInput = new FileEditorInput(file);
	// Check if the editor is already open
	IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy();
	IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
			.getEditorReferences();
	for (int i = 0; i < editorRefs.length; i++) {
		if (matchingStrategy.matches(editorRefs[i], newInput)) {
			MessageDialog.openWarning(shell, Messages.ProcessDiagramEditor_SaveAsErrorTitle,
					Messages.ProcessDiagramEditor_SaveAsErrorMessage);
			return;
		}
	}
	boolean success = false;
	try {
		provider.aboutToChange(newInput);
		getDocumentProvider(newInput).saveDocument(progressMonitor, newInput,
				getDocumentProvider().getDocument(getEditorInput()), true);
		success = true;
	} catch (CoreException x) {
		IStatus status = x.getStatus();
		if (status == null || status.getSeverity() != IStatus.CANCEL) {
			ErrorDialog.openError(shell, Messages.ProcessDiagramEditor_SaveErrorTitle,
					Messages.ProcessDiagramEditor_SaveErrorMessage, x.getStatus());
		}
	} finally {
		provider.changed(newInput);
		if (success) {
			setInput(newInput);
		}
	}
	if (progressMonitor != null) {
		progressMonitor.setCanceled(!success);
	}
}