Package org.eclipse.core.runtime

Examples of org.eclipse.core.runtime.SubMonitor


  /*
   * @see IInstallableRuntime#install(IPath, IProgressMonitor)
   */
  public void install(IPath path, IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, 1000);
    URL url = null;
    File temp = null;
    try {
      url = new URL(getArchiveUrl());
      temp = File.createTempFile("runtime", ""); //$NON-NLS-1$ //$NON-NLS-2$
      temp.deleteOnExit();
    } catch (IOException e) {
      if (monitor != null)
        monitor.done();
//      if (Trace.WARNING) {
//        Trace.trace(Trace.STRING_WARNING, "Error creating url and temp file", e);
//      }
      throw new CoreException(new Status(IStatus.ERROR, PEXServerPlugin.PLUGIN_ID, 0,
        NLS.bind(Messages.InstallableRuntime2_ErrorInstallingServer, e.getLocalizedMessage()), e));
    }
    String name = url.getQuery();
//    int slashIdx = name.lastIndexOf('/');
//    if (slashIdx >= 0)
//      name = name.substring(slashIdx + 1);
   
    int archiveSize = getArchiveSize();
   
    // download
    FileOutputStream fout = null;
    try {
      InputStream in = url.openStream();
      fout = new FileOutputStream(temp);
      download(in, fout, progress.newChild(500), name, archiveSize);
      progress.setWorkRemaining(500);
    } catch (Exception e) {
      if (monitor != null)
        monitor.done();
//      if (Trace.WARNING) {
//        Trace.trace(Trace.STRING_WARNING, "Error downloading runtime", e);
//      }
      throw new CoreException(new Status(IStatus.ERROR, PEXServerPlugin.PLUGIN_ID, 0,
        NLS.bind(Messages.InstallableRuntime2_ErrorInstallingServer, e.getLocalizedMessage()), e));
    } finally {
      try {
        if (fout != null)
          fout.close();
      } catch (IOException e) {
        // ignore
      }
    }
    if (progress.isCanceled())
      throw new CoreException(Status.CANCEL_STATUS);
   
    FileInputStream in = null;
    try {
      in = new FileInputStream(temp);
      if (name.endsWith("zip")) //$NON-NLS-1$
        unzip(in, path, progress.newChild(500));
      else if (name.endsWith("tar")) //$NON-NLS-1$
        untar(in, path, progress.newChild(500));
      else if (name.endsWith("tar.gz")) { //$NON-NLS-1$
        File tarFile = File.createTempFile("runtime", ".tar"); //$NON-NLS-1$ //$NON-NLS-2$
        tarFile.deleteOnExit();
        String tarName = name;
       
        progress.subTask(NLS.bind(Messages.InstallableRuntime2_TaskUncompressing, tarName));
        int tempSize = Integer.MAX_VALUE;
        if (temp.length() < Integer.MAX_VALUE)
          tempSize = (int)temp.length();
       
        ungzip(in, tarFile, progress.newChild(250), tempSize);
        progress.setWorkRemaining(250);
        if (!progress.isCanceled()) {
          in = new FileInputStream(tarFile);
          untar(in, path, progress.newChild(250));
        }
      }
    } catch (Exception e) {
//      if (Trace.SEVERE) {
//        Trace.trace(Trace.STRING_SEVERE, "Error uncompressing runtime", e);
//      }
      throw new CoreException(new Status(IStatus.ERROR, PEXServerPlugin.PLUGIN_ID, 0,
        NLS.bind(Messages.InstallableRuntime2_ErrorInstallingServer, e.getLocalizedMessage()), e));
    } finally {
      try {
        if (in != null)
          in.close();
      } catch (IOException e) {
        // ignore
      }
      progress.done();
    }
  }
View Full Code Here


   * @param monitor
   * @throws IOException
   */
  private void unzip(InputStream in, IPath path, IProgressMonitor monitor) throws IOException {
    int fileCnt = getFileCount();
    SubMonitor progress = SubMonitor.convert(monitor, (fileCnt > 0) ? fileCnt : DEFAULT_FILE_COUNT);
    String archivePath = getArchivePath();
    BufferedInputStream bin = new BufferedInputStream(in);
    ZipInputStream zin = new ZipInputStream(bin);
    ZipEntry entry = zin.getNextEntry();
    while (entry != null) {
      String name = entry.getName();
      progress.subTask(NLS.bind(Messages.InstallableRuntime2_TaskUncompressing, name));
      if (archivePath != null && name.startsWith(archivePath)) {
        name = name.substring(archivePath.length());
        if (name.length() > 1)
          name = name.substring(1);
      }
     
      if (name != null && name.length() > 0) {
        if (entry.isDirectory())
          path.append(name).toFile().mkdirs();
        else {
          FileOutputStream fout = new FileOutputStream(path.append(name).toFile());
          copyWithSize(zin, fout, progress.newChild(1), (int)entry.getSize());
          fout.close();
          // if count is not known, use infinite logarithmic progress
          if (fileCnt <= 0)
            progress.setWorkRemaining(DEFAULT_FILE_COUNT);
        }
      }
      zin.closeEntry();
      entry = zin.getNextEntry();
    }
View Full Code Here

   * @param monitor
   * @throws IOException
   */
  protected void untar(InputStream in, IPath path, IProgressMonitor monitor) throws IOException {
    int fileCnt = getFileCount();
    SubMonitor progress = SubMonitor.convert(monitor, (fileCnt > 0) ? fileCnt : 500);
    String archivePath = getArchivePath();
    BufferedInputStream bin = new BufferedInputStream(in);
    try {
      TarInputStream zin = new TarInputStream(bin);
      TarEntry entry = zin.getNextEntry();
      while (entry != null) {
        String name = entry.getName();
        progress.subTask(NLS.bind(Messages.InstallableRuntime2_TaskUncompressing, name));
        if (archivePath != null && name.startsWith(archivePath)) {
          name = name.substring(archivePath.length());
          if (name.length() > 1)
            name = name.substring(1);
        }
       
        if (name != null && name.length() > 0) {
          if (entry.getFileType() == TarEntry.DIRECTORY)
            path.append(name).toFile().mkdirs();
          else {
            File dir = path.append(name).removeLastSegments(1).toFile();
            if (!dir.exists())
              dir.mkdirs();
           
            FileOutputStream fout = new FileOutputStream(path.append(name).toFile());
            copyWithSize(zin, fout, progress.newChild(1), (int)entry.getSize());
            fout.close();
            if (fileCnt <= 0)
              progress.setWorkRemaining(500);
          }
        }
        entry = zin.getNextEntry();
      }
      zin.close();
View Full Code Here

   *  It is the caller's responsibility to call done() on the given monitor.
   *  Accepts null, indicating that no progress should be reported and that the
   *  operation cannot be cancelled.
   */
  public BuildNotifier(final IProgressMonitor monitor, final IProject project) {
    SubMonitor _convert = SubMonitor.convert(monitor, 100);
    this.monitor = _convert;
    this.cancelling = false;
  }
View Full Code Here

 
  public void newPhase(final String name) {
    String _upperCase = name.toUpperCase();
    final BuildPhase phase = BuildPhase.valueOf(_upperCase);
    int _work = phase.getWork();
    SubMonitor _newChild = this.monitor.newChild(_work);
    this.phaseMonitor = _newChild;
    this.phaseMonitor.setWorkRemaining(100);
  }
View Full Code Here

      _xifexpression = BuildNotifier.ERL_STEP_WORK;
    } else {
      _xifexpression = BuildNotifier.OTHER_STEP_WORK;
    }
    final int work = _xifexpression;
    SubMonitor _newChild = this.phaseMonitor.newChild(work);
    this.stepMonitor = _newChild;
    this.stepMonitor.setWorkRemaining(items);
  }
View Full Code Here

          return;
        }
      }
      final IJobRunnable[] backgroundSaveRunnable = new IJobRunnable[1];
      try {
        SubMonitor subMonitor = SubMonitor.convert(progressMonitor, 3);
        backgroundSaveRunnable[0] = model.doSave(
            subMonitor.newChild(2), shellProvider);
        if (backgroundSaveRunnable[0] == null) {
          // no further work needs to be done
          return;
        }
        if (blockUntilSaved) {
          // for now, block on close by running the runnable in the UI
          // thread
          IStatus result = backgroundSaveRunnable[0].run(subMonitor
              .newChild(1));
          if (!result.isOK()) {
            StatusUtil.handleStatus(result, StatusManager.SHOW,
                shellProvider.getShell());
            progressMonitor.setCanceled(true);
View Full Code Here

        return String.format("Create file %s", path.toString());
    }

    @Override
    public Change perform(IProgressMonitor monitor) throws CoreException {
        SubMonitor progress = SubMonitor.convert(monitor, encoding != null ? 2 : 1);

        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

        IFile file = root.getFile(path);
        file.create(source, updateFlags, progress.newChild(1, SubMonitor.SUPPRESS_NONE));

        if (encoding != null)
            file.setCharset(encoding, progress.newChild(1, SubMonitor.SUPPRESS_NONE));

        return new DeleteResourceChange(path, true);
    }
View Full Code Here

        return super.getLaunch(modifiedConfig.doSave(), mode);
    }

    @Override
    public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
        SubMonitor progress = SubMonitor.convert(monitor, 2);

        try {
            launch.setAttribute(ATTR_JUNIT_PORT, Integer.toString(junitPort));
        } catch (Exception e) {
            throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error obtaining OSGi project tester.", e));
        }

        super.launch(configuration, mode, launch, progress.newChild(1, SubMonitor.SUPPRESS_NONE));
    }
View Full Code Here

        return result;
    }

    @Override
    protected void execute(IProgressMonitor monitor) throws CoreException {
        SubMonitor progress = SubMonitor.convert(monitor);

        switch (operation.getType()) {
        case Import :
            progress.setWorkRemaining(2);
            importCnf(progress.newChild(1, SubMonitor.SUPPRESS_NONE));
            rebuildWorkspace(progress.newChild(1, SubMonitor.SUPPRESS_NONE));
            break;
        case Open :
            progress.setWorkRemaining(2);
            openProject(progress.newChild(1, SubMonitor.SUPPRESS_NONE));
            rebuildWorkspace(progress.newChild(1, SubMonitor.SUPPRESS_NONE));
            break;
        case Create :
            progress.setWorkRemaining(3);
            createOrReplaceCnf(progress.newChild(1, SubMonitor.SUPPRESS_NONE));
            rebuildWorkspace(progress.newChild(1, SubMonitor.SUPPRESS_NONE));
            break;
        case Nothing :
        default :
            break;
        }
View Full Code Here

TOP

Related Classes of org.eclipse.core.runtime.SubMonitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.