Esempio n. 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();
   }
 }
Esempio n. 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);
   }
 }
Esempio n. 3
0
 public ICVSRemoteResource[] getFoldersForTag(
     ICVSRepositoryLocation location, CVSTag tag, IProgressMonitor monitor) throws CVSException {
   monitor = Policy.monitorFor(monitor);
   try {
     monitor.beginTask(
         NLS.bind(
             CVSUIMessages.RepositoryManager_fetchingRemoteFolders, new String[] {tag.getName()}),
         100);
     if (tag.getType() == CVSTag.HEAD) {
       ICVSRemoteResource[] resources =
           location.members(tag, false, Policy.subMonitorFor(monitor, 60));
       RepositoryRoot root = getRepositoryRootFor(location);
       ICVSRemoteResource[] modules =
           root.getDefinedModules(tag, Policy.subMonitorFor(monitor, 40));
       ICVSRemoteResource[] result = new ICVSRemoteResource[resources.length + modules.length];
       System.arraycopy(resources, 0, result, 0, resources.length);
       System.arraycopy(modules, 0, result, resources.length, modules.length);
       return result;
     }
     if (tag.getType() == CVSTag.DATE) {
       ICVSRemoteResource[] resources =
           location.members(tag, false, Policy.subMonitorFor(monitor, 60));
       RepositoryRoot root = getRepositoryRootFor(location);
       ICVSRemoteResource[] modules =
           root.getDefinedModules(tag, Policy.subMonitorFor(monitor, 40));
       ICVSRemoteResource[] result = new ICVSRemoteResource[resources.length + modules.length];
       System.arraycopy(resources, 0, result, 0, resources.length);
       System.arraycopy(modules, 0, result, resources.length, modules.length);
       return result;
     }
     Set result = new HashSet();
     // Get the tags for the location
     RepositoryRoot root = getRepositoryRootFor(location);
     String[] paths = root.getKnownRemotePaths();
     for (int i = 0; i < paths.length; i++) {
       String path = paths[i];
       List tags = Arrays.asList(root.getAllKnownTags(path));
       if (tags.contains(tag)) {
         ICVSRemoteFolder remote =
             root.getRemoteFolder(path, tag, Policy.subMonitorFor(monitor, 100));
         result.add(remote);
       }
     }
     return (ICVSRemoteResource[]) result.toArray(new ICVSRemoteResource[result.size()]);
   } finally {
     monitor.done();
   }
 }
  @Override
  protected void execute(IProgressMonitor monitor)
      throws CoreException, InvocationTargetException, InterruptedException {
    int numUnits = fWebLocation == null ? 3 : 4;

    monitor.beginTask(PDEUIMessages.NewSiteWizard_creatingProject, numUnits);

    CoreUtility.createProject(fProject, fPath, monitor);
    fProject.open(monitor);
    CoreUtility.addNatureToProject(fProject, PDE.SITE_NATURE, monitor);
    monitor.worked(1);

    if (fWebLocation != null) {
      CoreUtility.createFolder(fProject.getFolder(fWebLocation));
      createXSLFile();
      createCSSFile();
      createHTMLFile();
      monitor.worked(1);
    }

    monitor.subTask(PDEUIMessages.NewSiteWizard_creatingManifest);
    IFile file = createSiteManifest();
    monitor.worked(1);

    openFile(file);
    monitor.worked(1);
  }
 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();
   }
 }
Esempio n. 6
0
 /**
  * The worker method. It will find the container, create the file if missing or just replace its
  * contents, and open the editor on the newly created file.
  */
 private void doFinish(String containerName, String fileName, IProgressMonitor monitor)
     throws CoreException {
   // create a sample file
   monitor.beginTask("Creating " + fileName, 2);
   IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
   IResource resource = root.findMember(new Path(containerName));
   if (!resource.exists() || !(resource instanceof IContainer)) {
     throwCoreException("Container \"" + containerName + "\" does not exist.");
   }
   IContainer container = (IContainer) resource;
   final IFile file = container.getFile(new Path(fileName));
   try {
     InputStream stream = openContentStream();
     if (file.exists()) {
       file.setContents(stream, true, true, monitor);
     } else {
       file.create(stream, true, monitor);
     }
     stream.close();
   } catch (IOException e) {
   }
   monitor.worked(1);
   monitor.setTaskName("Opening file for editing...");
   getShell()
       .getDisplay()
       .asyncExec(
           new Runnable() {
             public void run() {
               IWorkbenchPage page =
                   PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
               try {
                 IDE.openEditor(page, file, true);
               } catch (PartInitException e) {
               }
             }
           });
   monitor.worked(1);
 }
  /**
   * The worker method. It will find the container, create the file if missing or just replace its
   * contents, and open the editor on the newly created file.
   */
  private void doFinish(String containerName, String fileName, IProgressMonitor monitor)
      throws CoreException {
    // create a sample file
    monitor.beginTask("Creating " + fileName, 2);
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IResource resource = root.findMember(new Path(containerName));

    // if (!(resource.exists()) || !(resource instanceof IContainer)) {
    if (resource == null || !(resource.exists()) || !(resource instanceof IContainer)) {
      // throwCoreException("Container \"" + containerName +
      // "\" does not exist.");
      IProject datamapperProject = root.getProject(containerName);
      datamapperProject.create(null);
      datamapperProject.open(null);
      // datamapperProject.
    }
    IContainer container = (IContainer) resource;
    //
    //
    // final IFile file = container.getFile(new Path(fileName));
    // try {
    // InputStream stream = openContentStream();
    // if (file.exists()) {
    // // file.setContents(null, true, true, monitor);
    // } else {
    // file.create(null, true, monitor);
    //
    // }
    // stream.close();`
    // } catch (IOException e) {
    // }
    // monitor.worked(1);
    // monitor.setTaskName("Opening file for editing...");
    // getShell().getDisplay().asyncExec(new Runnable() {
    // public void run() {
    // IWorkbenchPage page =
    // PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    // try {
    // IDE.openEditor(page, file);
    // } catch (PartInitException e) {
    // }
    // }
    // });
    // monitor.worked(1);
  }
  @Override
  protected void doSaveDocument(
      IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
      throws CoreException {
    try {
      IStorage storage = EditorUtils.getStorageFromInput(element);
      File localFile = null;
      if (storage == null) {
        localFile = EditorUtils.getLocalFileFromInput(element);
        if (localFile == null) {
          throw new DBException("Can't obtain file from editor input");
        }
      }
      String encoding =
          (storage instanceof IEncodedStorage
              ? ((IEncodedStorage) storage).getCharset()
              : GeneralUtils.DEFAULT_FILE_CHARSET_NAME);

      Charset charset = Charset.forName(encoding);

      CharsetEncoder encoder = charset.newEncoder();
      encoder.onMalformedInput(CodingErrorAction.REPLACE);
      encoder.onUnmappableCharacter(CodingErrorAction.REPORT);

      byte[] bytes;
      ByteBuffer byteBuffer = encoder.encode(CharBuffer.wrap(document.get()));
      if (byteBuffer.hasArray()) {
        bytes = byteBuffer.array();
      } else {
        bytes = new byte[byteBuffer.limit()];
        byteBuffer.get(bytes);
      }
      InputStream stream = new ByteArrayInputStream(bytes, 0, byteBuffer.limit());

      if (storage instanceof IFile) {
        IFile file = (IFile) storage;

        if (file.exists()) {

          // inform about the upcoming content change
          fireElementStateChanging(element);
          try {
            file.setContents(stream, true, true, monitor);
          } catch (CoreException x) {
            // inform about failure
            fireElementStateChangeFailed(element);
            throw x;
          } catch (RuntimeException x) {
            // inform about failure
            fireElementStateChangeFailed(element);
            throw x;
          }

        } else {
          try {
            monitor.beginTask("Save file '" + file.getName() + "'", 2000);
            // ContainerCreator creator = new ContainerCreator(file.getWorkspace(),
            // file.getParent().getFullPath());
            // creator.createContainer(new SubProgressMonitor(monitor, 1000));
            file.create(stream, false, monitor);
          } finally {
            monitor.done();
          }
        }
      } else if (storage instanceof IPersistentStorage) {
        monitor.beginTask("Save document", 1);
        ((IPersistentStorage) storage).setContents(monitor, stream);
      } else if (localFile != null) {
        try (OutputStream os = new FileOutputStream(localFile)) {
          IOUtils.copyStream(stream, os);
        }
      } else {
        throw new DBException("Storage [" + storage + "] doesn't support save");
      }
    } catch (Exception e) {
      if (e instanceof CoreException) {
        throw (CoreException) e;
      } else {
        throw new CoreException(GeneralUtils.makeExceptionStatus(e));
      }
    }
  }
Esempio n. 9
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);
    }
  }