Beispiel #1
0
 @Override
 public void setCharset(String newCharset, IProgressMonitor monitor) throws CoreException {
   monitor = Policy.monitorFor(monitor);
   try {
     String message = NLS.bind(Messages.resources_settingCharset, getFullPath());
     monitor.beginTask(message, Policy.totalWork);
     // need to get the project as a scheduling rule because we might be creating a new folder/file
     // to
     // hold the project settings
     final ISchedulingRule rule = workspace.getRuleFactory().charsetRule(this);
     try {
       workspace.prepareOperation(rule, monitor);
       ResourceInfo info = getResourceInfo(false, false);
       checkAccessible(getFlags(info));
       workspace.beginOperation(true);
       workspace.getCharsetManager().setCharsetFor(getFullPath(), newCharset);
       info = getResourceInfo(false, true);
       info.incrementCharsetGenerationCount();
       monitor.worked(Policy.opWork);
     } catch (OperationCanceledException e) {
       workspace.getWorkManager().operationCanceled();
       throw e;
     } finally {
       workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
     }
   } finally {
     monitor.done();
   }
 }
Beispiel #2
0
 @Override
 public void setContents(InputStream content, int updateFlags, IProgressMonitor monitor)
     throws CoreException {
   monitor = Policy.monitorFor(monitor);
   try {
     String message = NLS.bind(Messages.resources_settingContents, getFullPath());
     monitor.beginTask(message, Policy.totalWork);
     if (workspace.shouldValidate) workspace.validateSave(this);
     final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this);
     try {
       workspace.prepareOperation(rule, monitor);
       ResourceInfo info = getResourceInfo(false, false);
       checkAccessible(getFlags(info));
       workspace.beginOperation(true);
       IFileInfo fileInfo = getStore().fetchInfo();
       internalSetContents(
           content, fileInfo, updateFlags, false, Policy.subMonitorFor(monitor, Policy.opWork));
     } catch (OperationCanceledException e) {
       workspace.getWorkManager().operationCanceled();
       throw e;
     } finally {
       workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
     }
   } finally {
     monitor.done();
     FileUtil.safeClose(content);
   }
 }
 /*
  * Execute the RunnableEvent
  */
 private void executeRunnable(Event event, IProgressMonitor monitor) {
   try {
     // Dispatch any queued results to clear pending output events
     dispatchEvents(Policy.subMonitorFor(monitor, 1));
   } catch (TeamException e) {
     handleException(e);
   }
   try {
     ((RunnableEvent) event).run(Policy.subMonitorFor(monitor, 1));
   } catch (CoreException e) {
     handleException(e);
   }
 }
  /**
   * This is run by the job scheduler. A list of subscribers will be refreshed, errors will not stop
   * the job and it will continue to refresh the other subscribers.
   */
  @Override
  public IStatus run(IProgressMonitor monitor) {
    // Perform a pre-check for auto-build or manual build jobs
    // when auto-refreshing
    if (shouldReschedule()
        && (isJobInFamilyRunning(ResourcesPlugin.FAMILY_AUTO_BUILD)
            || isJobInFamilyRunning(ResourcesPlugin.FAMILY_MANUAL_BUILD))) {
      return POSTPONED;
    }
    // Only allow one refresh job at a time
    // NOTE: It would be cleaner if this was done by a scheduling
    // rule but at the time of writing, it is not possible due to
    // the scheduling rule containment rules.
    // Acquiring lock to ensure only one refresh job is running at a particular time
    boolean acquired = false;
    try {
      while (!acquired) {
        try {
          acquired = lock.acquire(1000);
        } catch (InterruptedException e1) {
          acquired = false;
        }
        Policy.checkCanceled(monitor);
      }

      IChangeDescription changeDescription = createChangeDescription();
      RefreshEvent event =
          new RefreshEvent(
              reschedule ? IRefreshEvent.SCHEDULED_REFRESH : IRefreshEvent.USER_REFRESH,
              participant,
              changeDescription);
      IStatus status = null;
      NonblockingProgressMonitor wrappedMonitor = null;
      try {
        event.setStartTime(System.currentTimeMillis());
        if (monitor.isCanceled()) {
          return Status.CANCEL_STATUS;
        }
        // Pre-Notify
        notifyListeners(STARTED, event);
        // Perform the refresh
        monitor.setTaskName(getName());
        wrappedMonitor = new NonblockingProgressMonitor(monitor, this);
        doRefresh(changeDescription, wrappedMonitor);
        // Prepare the results
        setProperty(IProgressConstants.KEEPONE_PROPERTY, Boolean.valueOf(!isJobModal()));
      } catch (OperationCanceledException e2) {
        if (monitor.isCanceled()) {
          // The refresh was canceled by the user
          status = Status.CANCEL_STATUS;
        } else {
          // The refresh was canceled due to a blockage or a canceled authentication
          if (wrappedMonitor != null && wrappedMonitor.wasBlocking()) {
            status = POSTPONED;
          } else {
            status = Status.CANCEL_STATUS;
          }
        }
      } catch (CoreException e) {
        // Determine the status to be returned and the GOTO action
        status = e.getStatus();
        if (!isUser()) {
          // Use the GOTO action to show the error and return OK
          Object prop = getProperty(IProgressConstants.ACTION_PROPERTY);
          if (prop instanceof GotoActionWrapper) {
            GotoActionWrapper wrapper = (GotoActionWrapper) prop;
            wrapper.setStatus(e.getStatus());
            status =
                new Status(IStatus.OK, TeamUIPlugin.ID, IStatus.OK, e.getStatus().getMessage(), e);
          }
        }
        if (!isUser() && status.getSeverity() == IStatus.ERROR) {
          // Never prompt for errors on non-user jobs
          setProperty(IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY, Boolean.TRUE);
        }
      } finally {
        event.setStopTime(System.currentTimeMillis());
      }

      // Post-Notify
      if (status == null) {
        status = calculateStatus(event);
      }
      event.setStatus(status);
      notifyListeners(DONE, event);
      if (event.getChangeDescription().getChangeCount() > 0) {
        if (participant instanceof AbstractSynchronizeParticipant) {
          AbstractSynchronizeParticipant asp = (AbstractSynchronizeParticipant) participant;
          asp.firePropertyChange(
              participant, ISynchronizeParticipant.P_CONTENT, null, event.getChangeDescription());
        }
      }
      return event.getStatus();
    } finally {
      if (acquired) lock.release();
      monitor.done();
    }
  }
Beispiel #5
0
  @Override
  public void create(InputStream content, int updateFlags, IProgressMonitor monitor)
      throws CoreException {
    final boolean monitorNull = monitor == null;
    monitor = Policy.monitorFor(monitor);
    try {
      String message =
          monitorNull ? "" : NLS.bind(Messages.resources_creating, getFullPath()); // $NON-NLS-1$
      monitor.beginTask(message, Policy.totalWork);
      checkValidPath(path, FILE, true);
      final ISchedulingRule rule = workspace.getRuleFactory().createRule(this);
      try {
        workspace.prepareOperation(rule, monitor);
        checkDoesNotExist();
        Container parent = (Container) getParent();
        ResourceInfo info = parent.getResourceInfo(false, false);
        parent.checkAccessible(getFlags(info));
        checkValidGroupContainer(parent, false, false);

        workspace.beginOperation(true);
        IFileStore store = getStore();
        IFileInfo localInfo = store.fetchInfo();
        if (BitMask.isSet(updateFlags, IResource.FORCE)) {
          if (!Workspace.caseSensitive) {
            if (localInfo.exists()) {
              String name = getLocalManager().getLocalName(store);
              if (name == null || localInfo.getName().equals(name)) {
                delete(true, null);
              } else {
                // The file system is not case sensitive and there is already a file
                // under this location.
                message =
                    NLS.bind(
                        Messages.resources_existsLocalDifferentCase,
                        new Path(store.toString()).removeLastSegments(1).append(name).toOSString());
                throw new ResourceException(
                    IResourceStatus.CASE_VARIANT_EXISTS, getFullPath(), message, null);
              }
            }
          }
        } else {
          if (localInfo.exists()) {
            // return an appropriate error message for case variant collisions
            if (!Workspace.caseSensitive) {
              String name = getLocalManager().getLocalName(store);
              if (name != null && !localInfo.getName().equals(name)) {
                message =
                    NLS.bind(
                        Messages.resources_existsLocalDifferentCase,
                        new Path(store.toString()).removeLastSegments(1).append(name).toOSString());
                throw new ResourceException(
                    IResourceStatus.CASE_VARIANT_EXISTS, getFullPath(), message, null);
              }
            }
            message = NLS.bind(Messages.resources_fileExists, store.toString());
            throw new ResourceException(
                IResourceStatus.FAILED_WRITE_LOCAL, getFullPath(), message, null);
          }
        }
        monitor.worked(Policy.opWork * 40 / 100);

        info = workspace.createResource(this, updateFlags);
        boolean local = content != null;
        if (local) {
          try {
            internalSetContents(
                content,
                localInfo,
                updateFlags,
                false,
                Policy.subMonitorFor(monitor, Policy.opWork * 60 / 100));
          } catch (CoreException e) {
            // a problem happened creating the file on disk, so delete from the workspace and disk
            workspace.deleteResource(this);
            store.delete(EFS.NONE, null);
            throw e; // rethrow
          } catch (OperationCanceledException e) {
            // the operation of setting contents has been canceled, so delete the file from the
            // workspace and disk
            workspace.deleteResource(this);
            store.delete(EFS.NONE, null);
            throw e;
          }
        }
        internalSetLocal(local, DEPTH_ZERO);
        if (!local) getResourceInfo(true, true).clearModificationStamp();
      } catch (OperationCanceledException e) {
        workspace.getWorkManager().operationCanceled();
        throw e;
      } finally {
        workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
      }
    } finally {
      monitor.done();
      FileUtil.safeClose(content);
    }
  }