示例#1
0
  protected void upload() throws InstantiationException {
    final ResolveDependencies resolver = new ResolveDependencies(this, files, true);
    if (!resolver.resolve()) return;

    final String errors = files.checkConsistency();
    if (errors != null) {
      error(errors);
      return;
    }

    final List<String> possibleSites = new ArrayList<String>(files.getSiteNamesToUpload());
    if (possibleSites.size() == 0) {
      error("Huh? No upload site?");
      return;
    }
    String updateSiteName;
    if (possibleSites.size() == 1) updateSiteName = possibleSites.get(0);
    else {
      updateSiteName =
          SwingTools.getChoice(
              this, possibleSites, "Which site do you want to upload to?", "Update site");
      if (updateSiteName == null) return;
    }
    final FilesUploader uploader = new FilesUploader(files, updateSiteName);

    Progress progress = null;
    try {
      if (!uploader.login()) return;
      progress = getProgress("Uploading...");
      uploader.upload(progress);
      for (final FileObject file : files.toUploadOrRemove())
        if (file.getAction() == Action.UPLOAD) {
          file.markUploaded();
          file.setStatus(Status.INSTALLED);
        } else {
          file.markRemoved();
          file.setStatus(Status.OBSOLETE_UNINSTALLED);
        }
      updateFilesTable();
      canUpload = false;
      files.write();
      info("Uploaded successfully.");
      enableUploadOrNot();
      dispose();
    } catch (final Canceled e) {
      // TODO: teach uploader to remove the lock file
      error("Canceled");
      if (progress != null) progress.done();
    } catch (final Throwable e) {
      UpdaterUserInterface.get().handleException(e);
      error("Upload failed: " + e);
      if (progress != null) progress.done();
    }
  }
示例#2
0
 protected boolean initializeUpdateSite(
     final String url, final String sshHost, final String uploadDirectory)
     throws InstantiationException {
   final FilesUploader uploader = FilesUploader.initialUpload(url, sshHost, uploadDirectory);
   Progress progress = null;
   try {
     if (!uploader.login()) return false;
     progress = getProgress("Initializing Update Site...");
     uploader.upload(progress);
     // JSch needs some time to finalize the SSH connection
     try {
       Thread.sleep(1000);
     } catch (final InterruptedException e) {
       /* ignore */
     }
     return true;
   } catch (final Canceled e) {
     if (progress != null) progress.done();
   } catch (final Throwable e) {
     UpdaterUserInterface.get().handleException(e);
     if (progress != null) progress.done();
   }
   return false;
 }