/* * @see IWorkspaceRunnable#run(IProgressMonitor) */ public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException { if (monitor == null) { monitor = new NullProgressMonitor(); } monitor.beginTask(MDEUIMessages.FeatureImportWizard_operation_creating, fModels.length); try { MultiStatus multiStatus = new MultiStatus( MDEPlugin.getPluginId(), IStatus.OK, MDEUIMessages.FeatureImportWizard_operation_multiProblem, null); for (int i = 0; i < fModels.length; i++) { try { createProject(fModels[i], new SubProgressMonitor(monitor, 1)); } catch (CoreException e) { multiStatus.merge(e.getStatus()); } if (monitor.isCanceled()) { throw new OperationCanceledException(); } } if (!multiStatus.isOK()) { throw new CoreException(multiStatus); } } finally { monitor.done(); } }
/** * Returns a status that represents the exceptions collected. If the collector is empty <code> * IStatus.OK</code> is returned. Otherwise a MultiStatus containing all collected exceptions is * returned. * * @return a multistatus containing the exceptions collected or IStatus.OK if the collector is * empty. */ public IStatus getStatus() { if (statuses.isEmpty()) { return Status.OK_STATUS; } else { MultiStatus multiStatus = new MultiStatus(pluginId, severity, message, null); Iterator it = statuses.iterator(); while (it.hasNext()) { IStatus status = (IStatus) it.next(); multiStatus.merge(status); } return multiStatus; } }
@Override public void handleException(Throwable exception) { if (fMulti == null) { fMulti = new MultiStatus( DartUI.ID_PLUGIN, IStatus.OK, CorrectionMessages.JavaCorrectionProcessor_error_status, null); } fMulti.merge( new Status( IStatus.ERROR, DartUI.ID_PLUGIN, IStatus.ERROR, CorrectionMessages.JavaCorrectionProcessor_error_status, exception)); }
void undo( MultiStatus status, EngineSession session, IProfile profile, Operand operand, ProvisioningAction[] actions, ProvisioningContext context) { if (operandParameters == null) { operandParameters = new HashMap<String, Object>(phaseParameters); operandParameters.put(PARM_OPERAND, operand); mergeStatus( status, initializeOperand(profile, operand, operandParameters, new NullProgressMonitor())); Touchpoint operandTouchpoint = (Touchpoint) operandParameters.get(PARM_TOUCHPOINT); if (operandTouchpoint != null) { mergeStatus( status, initializeTouchpointParameters( profile, operand, operandTouchpoint, new NullProgressMonitor())); if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return; operandParameters = touchpointToTouchpointOperandParameters.get(operandTouchpoint); } operandParameters = Collections.unmodifiableMap(operandParameters); } for (int j = 0; j < actions.length; j++) { ProvisioningAction action = actions[j]; Map<String, Object> parameters = operandParameters; Touchpoint touchpoint = action.getTouchpoint(); if (touchpoint != null) { mergeStatus( status, initializeTouchpointParameters( profile, operand, touchpoint, new NullProgressMonitor())); if (status.matches(IStatus.ERROR)) return; parameters = touchpointToTouchpointOperandParameters.get(touchpoint); } IStatus actionStatus = null; try { session.recordActionUndo(action, parameters); actionStatus = action.undo(parameters); } catch (RuntimeException e) { // "action.undo" calls user code and might throw an unchecked exception // we catch the error here to gather information on where the problem occurred. actionStatus = new Status( IStatus.ERROR, EngineActivator.ID, NLS.bind(Messages.action_undo_error, action.getClass().getName()), e); } catch (LinkageError e) { // Catch linkage errors as these are generally recoverable but let other Errors propagate // (see bug 222001) actionStatus = new Status( IStatus.ERROR, EngineActivator.ID, NLS.bind(Messages.action_undo_error, action.getClass().getName()), e); } if (actionStatus != null && actionStatus.matches(IStatus.ERROR)) { MultiStatus result = new MultiStatus(EngineActivator.ID, IStatus.ERROR, getProblemMessage(), null); result.add( new Status( IStatus.ERROR, EngineActivator.ID, session.getContextString(this, operand, action), null)); result.merge(actionStatus); } } mergeStatus( status, touchpointCompleteOperand(profile, operand, operandParameters, new NullProgressMonitor())); mergeStatus( status, completeOperand(profile, operand, operandParameters, new NullProgressMonitor())); operandParameters = null; }
/** Merges a given IStatus into a MultiStatus */ protected static void mergeStatus(MultiStatus multi, IStatus status) { if (status != null && !status.isOK()) multi.merge(status); }
/** * Return an {@link IStatus} representing the merge of the given first and second {@link * IStatus}s. * * @param s1 The first {@link IStatus}. * @param s2 The second {@link IStatus}. * @return The merge of the first and second {@link IStatus}. */ protected IStatus combine(IStatus s1, IStatus s2) { MultiStatus status = new MultiStatus(MvcBundle.PLUGIN_ID, IStatus.OK, null, null); status.merge(s1); status.merge(s2); return status; }
/** * Opens a type selection dialog. If the user selects a type (and does not cancel), an editor is * opened on the selected type. * * @see org.eclipse.jface.action.Action#runWithEvent(org.eclipse.swt.widgets.Event) */ @Override public void runWithEvent(Event e) { Shell parent = DartToolsPlugin.getActiveWorkbenchShell(); if (!doCreateProjectFirstOnEmptyWorkspace(parent)) { return; } SelectionDialog dialog = new OpenTypeSelectionDialog( parent, true, PlatformUI.getWorkbench().getProgressService(), null, SEARCH_ELEMENT_KINDS); dialog.setTitle(DartUIMessages.OpenTypeAction_dialogTitle); dialog.setMessage(DartUIMessages.OpenTypeAction_dialogMessage); int result = dialog.open(); if (result != IDialogConstants.OK_ID) { return; } Object[] types = dialog.getResult(); if (types == null || types.length == 0) { return; } if (types.length == 1) { try { DartUI.openInEditor((Element) types[0], true, true); } catch (CoreException x) { ExceptionHandler.handle( x, DartUIMessages.OpenTypeAction_errorTitle, DartUIMessages.OpenTypeAction_errorMessage); } return; } final IWorkbenchPage workbenchPage = DartToolsPlugin.getActivePage(); if (workbenchPage == null) { IStatus status = new Status( IStatus.ERROR, DartToolsPlugin.getPluginId(), DartUIMessages.OpenTypeAction_no_active_WorkbenchPage); ExceptionHandler.handle( status, DartUIMessages.OpenTypeAction_errorTitle, DartUIMessages.OpenTypeAction_errorMessage); return; } MultiStatus multiStatus = new MultiStatus( DartToolsPlugin.getPluginId(), DartStatusConstants.INTERNAL_ERROR, DartUIMessages.OpenTypeAction_multiStatusMessage, null); for (int i = 0; i < types.length; i++) { Type type = (Type) types[i]; try { DartUI.openInEditor(type, true, true); } catch (CoreException x) { multiStatus.merge(x.getStatus()); } } if (!multiStatus.isOK()) { ExceptionHandler.handle( multiStatus, DartUIMessages.OpenTypeAction_errorTitle, DartUIMessages.OpenTypeAction_errorMessage); } }
public ProfileChangeRequest generateProfileChangeRequest( IProfile profile, MultiStatus status, IProgressMonitor monitor) { ProfileChangeRequest request = new ProfileChangeRequest(profile); String carbonHome = System.getProperty("carbon.home"); String cacheLocation = carbonHome + File.separator + "repository" + File.separator + "components"; request.setProfileProperty(IProfile.PROP_CACHE, cacheLocation); request.setProfileProperty( SimpleConfiguratorConstants.PROP_KEY_USE_REFERENCE, Boolean.TRUE.toString()); for (IInstallableUnit iu : iusToInstall) { // If the user is installing a patch, we mark it optional. This allows // the patched IU to be updated later by removing the patch. if (Boolean.toString(true) .equals(iu.getProperty(MetadataFactory.InstallableUnitDescription.PROP_TYPE_PATCH))) { request.setInstallableUnitInclusionRules( iu, ProfileInclusionRules.createOptionalInclusionRule(iu)); } // Check to see if it is already installed. This may alter the request. Collection alreadyInstalled = profile .query(QueryUtil.createIUQuery(iu.getId()), new NullProgressMonitor()) .toUnmodifiableSet(); if (alreadyInstalled.size() > 0) { IInstallableUnit installedIU = (IInstallableUnit) alreadyInstalled.iterator().next(); int compareTo = iu.getVersion().compareTo(installedIU.getVersion()); // If the iu is a newer version of something already installed, consider this an // update request if (compareTo > 0) { boolean lockedForUpdate = false; String value = profile.getInstallableUnitProperty(installedIU, IProfile.PROP_PROFILE_LOCKED_IU); if (value != null) { lockedForUpdate = (Integer.parseInt(value) & IProfile.LOCK_UPDATE) == IProfile.LOCK_UPDATE; } if (lockedForUpdate) { // Add a status telling the user that this implies an update, but the // iu should not be updated status.merge( new Status( IStatus.WARNING, "temp", 10013, installedIU.getId() + "-" + installedIU.getVersion() + " will be ignored because it is already installed, " + "and updates are not permitted.", null)); } else { request.addInstallableUnits(new IInstallableUnit[] {iu}); request.removeInstallableUnits(new IInstallableUnit[] {installedIU}); // Add a status informing the user that the update has been inferred status.merge( new Status( IStatus.WARNING, "temp", 10013, installedIU.getId() + "-" + installedIU.getVersion() + " is already installed, so an update will be performed instead.", null)); // Mark it as a root if it hasn't been already if (!Boolean.toString(true) .equals( profile.getInstallableUnitProperty( installedIU, IProfile.PROP_PROFILE_ROOT_IU))) { request.setInstallableUnitProfileProperty( iu, IProfile.PROP_PROFILE_ROOT_IU, Boolean.toString(true)); } } } else if (compareTo < 0) { // An implied downgrade. We will not put this in the plan, add a status informing the // user status.merge( new Status( IStatus.WARNING, "temp", 10004, installedIU.getId() + "-" + installedIU.getVersion() + " will be ignored because a newer version is already installed.", null)); } else { if (Boolean.toString(true) .equals( profile.getInstallableUnitProperty(installedIU, IProfile.PROP_PROFILE_ROOT_IU))) // It is already a root, nothing to do. We tell the user it was already installed { status.merge( new Status( IStatus.WARNING, "temp", 10005, installedIU.getId() + "-" + installedIU.getVersion() + " will be ignored because it is already installed.", null)); } else { // It was already installed but not as a root. // Tell the user that parts of it are already installed and mark it as a root. status.merge( new Status( IStatus.WARNING, "temp", 10006, installedIU.getId() + "-" + installedIU.getVersion() + " is already present because other installed software requires it. " + "It will be added to the installed software list.", null)); request.setInstallableUnitProfileProperty( iu, "org.eclipse.equinox.p2.type.root", Boolean.toString(true)); } } } else { // install this if only this is not category type if (!Boolean.toString(true) .equals( iu.getProperty(MetadataFactory.InstallableUnitDescription.PROP_TYPE_CATEGORY))) { // Install it and mark as a root request.addInstallableUnits(new IInstallableUnit[] {iu}); request.setInstallableUnitProfileProperty( iu, "org.eclipse.equinox.p2.type.root", Boolean.toString(true)); } } } return request; }
/** * If the filePaths is empty, do batch operations! * * @param notify * @param filePaths * @param monitor * @return */ IStatus refresh(boolean notify, Collection<IPath> filePaths, IProgressMonitor monitor) { SubMonitor sub = SubMonitor.convert(monitor, 100); if (sub.isCanceled()) { return Status.CANCEL_STATUS; } this.notify = notify; final Set<String> filePathStrings = new HashSet<String>( CollectionsUtil.map( filePaths, new IMap<IPath, String>() { public String map(IPath location) { return location.toPortableString(); } })); // If we don't run this, we end up showing files as unstaged when they're no longer modified! IStatus result; synchronized (this) { repository.forceWrite(); // Do we only want to try the lock if we're in UI thread? result = GitExecutable.instance() .runInBackground( repository.workingDirectory(), "update-index", "-q", //$NON-NLS-1$ //$NON-NLS-2$ "--unmerged", "--ignore-missing", "--refresh"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ repository.exitWriteProcess(); } if (result == null) // couldn't even execute! { return new Status( IStatus.ERROR, GitPlugin.getPluginId(), "Failed to execute git update-index"); //$NON-NLS-1$ } if (!result.isOK()) { IdeLog.logError( GitPlugin.getDefault(), "Unable to run update-index: " + result.getMessage()); // $NON-NLS-1$ return result; } Set<Callable<IStatus>> jobs = new HashSet<Callable<IStatus>>(3); jobs.add(new UntrackedFilesRefreshJob(this, filePathStrings)); jobs.add(new UnstagedFilesRefreshJob(this, filePathStrings)); jobs.add(new StagedFilesRefreshJob(this, filePathStrings)); // Last chance to cancel... if (monitor != null && monitor.isCanceled()) { return Status.CANCEL_STATUS; } // Now create a new temporary list so we can build it up... this.files = Collections.synchronizedList(new ArrayList<ChangedFile>()); // Schedule all the jobs MultiStatus errors = new MultiStatus( GitPlugin.PLUGIN_ID, 1, "Errors occurred while grabbing changed file listings", null); //$NON-NLS-1$ try { List<Future<IStatus>> futures = es.invokeAll(jobs); // Now wait for them to finish for (Future<IStatus> future : futures) { while (!future.isDone()) { if (monitor != null && monitor.isCanceled()) { future.cancel(true); } Thread.yield(); } // When done, get their result try { IStatus futureResult = future.get(); if (!futureResult.isOK()) { errors.merge(futureResult); } } catch (CancellationException ce) { // ignore } catch (ExecutionException e) { Throwable t = e.getCause(); errors.merge(new Status(IStatus.ERROR, GitPlugin.PLUGIN_ID, t.getMessage(), t)); } } } catch (InterruptedException e) { IdeLog.logError(GitPlugin.getDefault(), e); } // Copy the last full list of changed files we built up on refresh. Used to pass along the delta // FIXME I think the values here may have already changed! I saw a file that had staged changes // but no unstaged // prior to commit // but here it showed true for both (which should have only gotten modified by a pre-commit // hook) Collection<ChangedFile> preRefresh; synchronized (this.changedFilesLock) { if (this.changedFiles != null) { preRefresh = new ArrayList<ChangedFile>(this.changedFiles.size()); for (ChangedFile file : this.changedFiles) { preRefresh.add(new ChangedFile(file)); } } else { preRefresh = new ArrayList<ChangedFile>(0); } // Now wipe any existing ChangedFile entries for any of the filePaths and add the ones we // generated in // dictionary if (CollectionsUtil.isEmpty(filePathStrings)) { this.changedFiles = new ArrayList<ChangedFile>(); } else { this.changedFiles = CollectionsUtil.filter( this.changedFiles, new IFilter<ChangedFile>() { public boolean include(ChangedFile item) { return !filePathStrings.contains(item.portablePath); } }); } if (!CollectionsUtil.isEmpty(this.files)) { this.changedFiles.addAll(this.files); } } // Don't hold onto temp list in memory! this.files = null; postIndexChange(preRefresh, this.changedFiles); sub.done(); if (!errors.isOK()) { return errors; } return Status.OK_STATUS; }