@Override
 protected void computeProfileChangeRequest(MultiStatus status, IProgressMonitor monitor) {
   SubMonitor sub = SubMonitor.convert(monitor, 1);
   if (currentRemedy != null) {
     request = currentRemedy.getRequest();
     sub.worked(1);
     return;
   }
   try {
     status.add(computeAllRemediations(sub.newChild(1)));
   } catch (OperationCanceledException e) {
     status.add(Status.CANCEL_STATUS);
   }
   determineBestSolutions();
 }
Пример #2
0
 @Override
 protected IStatus run(IProgressMonitor monitor) {
   MultiStatus result =
       new MultiStatus(
           ResourcesPlugin.PI_RESOURCES,
           IResourceStatus.FAILED_SETTING_CHARSET,
           Messages.resources_updatingEncoding,
           null);
   monitor = Policy.monitorFor(monitor);
   try {
     monitor.beginTask(Messages.resources_charsetUpdating, Policy.totalWork);
     final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(workspace.getRoot());
     try {
       workspace.prepareOperation(rule, monitor);
       workspace.beginOperation(true);
       Map.Entry<IProject, Boolean> next;
       while ((next = getNextChange()) != null) {
         // just exit if the system is shutting down or has been shut down
         // it is too late to change the workspace at this point anyway
         if (systemBundle.getState() != Bundle.ACTIVE) return Status.OK_STATUS;
         IProject project = next.getKey();
         try {
           if (project.isAccessible()) {
             boolean shouldDisableCharsetDeltaJob = next.getValue().booleanValue();
             // flush preferences for non-derived resources
             flushPreferences(
                 getPreferences(project, false, false, true), shouldDisableCharsetDeltaJob);
             // flush preferences for derived resources
             flushPreferences(
                 getPreferences(project, false, true, true), shouldDisableCharsetDeltaJob);
           }
         } catch (BackingStoreException e) {
           // we got an error saving
           String detailMessage = Messages.resources_savingEncoding;
           result.add(
               new ResourceStatus(
                   IResourceStatus.FAILED_SETTING_CHARSET,
                   project.getFullPath(),
                   detailMessage,
                   e));
         }
       }
       monitor.worked(Policy.opWork);
     } catch (OperationCanceledException e) {
       workspace.getWorkManager().operationCanceled();
       throw e;
     } finally {
       workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
     }
   } catch (CoreException ce) {
     return ce.getStatus();
   } finally {
     monitor.done();
   }
   return result;
 }
 public IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor) {
   SubMonitor subMonitor = SubMonitor.convert(monitor, requests.length);
   try {
     MultiStatus overallStatus =
         new MultiStatus(TestActivator.PI_PROV_TESTS, IStatus.OK, null, null);
     for (int i = 0; i < requests.length; i++) {
       overallStatus.add(getArtifact((ArtifactRequest) requests[i], subMonitor.newChild(1)));
     }
     return (monitor.isCanceled() ? Status.CANCEL_STATUS : overallStatus);
   } finally {
     subMonitor.done();
   }
 }
Пример #4
0
  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;
  }
Пример #5
0
  private void mainPerform(
      MultiStatus status, EngineSession session, Operand[] operands, SubMonitor subMonitor) {
    IProfile profile = session.getProfile();
    subMonitor.beginTask(null, operands.length);
    for (int i = 0; i < operands.length; i++) {
      subMonitor.setWorkRemaining(operands.length - i);
      if (subMonitor.isCanceled()) throw new OperationCanceledException();
      Operand operand = operands[i];
      if (!isApplicable(operand)) continue;

      session.recordOperandStart(operand);
      List<ProvisioningAction> actions = getActions(operand);
      operandParameters = new HashMap<String, Object>(phaseParameters);
      operandParameters.put(PARM_OPERAND, operand);
      mergeStatus(status, initializeOperand(profile, operand, operandParameters, subMonitor));
      if (status.matches(IStatus.ERROR | IStatus.CANCEL)) {
        operandParameters = null;
        return;
      }

      Touchpoint operandTouchpoint = (Touchpoint) operandParameters.get(PARM_TOUCHPOINT);
      if (operandTouchpoint != null) {
        mergeStatus(
            status,
            initializeTouchpointParameters(profile, operand, operandTouchpoint, subMonitor));
        if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return;

        operandParameters = touchpointToTouchpointOperandParameters.get(operandTouchpoint);
      }

      operandParameters = Collections.unmodifiableMap(operandParameters);
      if (actions != null) {
        for (int j = 0; j < actions.size(); j++) {
          ProvisioningAction action = actions.get(j);
          Map<String, Object> parameters = operandParameters;
          Touchpoint touchpoint = action.getTouchpoint();
          if (touchpoint != null) {
            mergeStatus(
                status, initializeTouchpointParameters(profile, operand, touchpoint, subMonitor));
            if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return;

            parameters = touchpointToTouchpointOperandParameters.get(touchpoint);
          }
          IStatus actionStatus = null;
          try {
            session.recordActionExecute(action, parameters);
            actionStatus = action.execute(parameters);
          } catch (RuntimeException e) {
            if (!forced) throw e;
            // "action.execute" 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.forced_action_execute_error, action.getClass().getName()),
                    e);
          } catch (LinkageError e) {
            if (!forced) throw 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.forced_action_execute_error, action.getClass().getName()),
                    e);
          }
          if (forced && 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));
            LogHelper.log(result);
            actionStatus = Status.OK_STATUS;
          }
          mergeStatus(status, actionStatus);
          if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return;
        }
      }
      mergeStatus(
          status, touchpointCompleteOperand(profile, operand, operandParameters, subMonitor));
      mergeStatus(status, completeOperand(profile, operand, operandParameters, subMonitor));
      if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return;
      operandParameters = null;
      session.recordOperandEnd(operand);
      subMonitor.worked(1);
    }
  }