示例#1
0
 /**
  * Activate the given update site.
  *
  * @param updateSite the update site to activate
  * @param progress the object to display the progress
  * @throws ParserConfigurationException
  * @throws IOException
  * @throws SAXException
  */
 public void activateUpdateSite(final UpdateSite updateSite, final Progress progress)
     throws ParserConfigurationException, IOException, SAXException {
   if (updateSite.isActive()) return;
   updateSite.setActive(true);
   reReadUpdateSite(updateSite.getName(), progress);
   markForUpdate(updateSite.getName(), false);
 }
示例#2
0
 public Set<GroupAction> getValidActions() {
   final Set<GroupAction> actions = new LinkedHashSet<GroupAction>();
   actions.add(new KeepAsIs());
   boolean hasChanges = hasChanges(), hasUploadOrRemove = hasUploadOrRemove();
   if (!hasUploadOrRemove) {
     actions.add(new InstallOrUpdate());
   }
   if (hasUploadOrRemove || !hasChanges) {
     final Collection<String> siteNames = getSiteNamesToUpload();
     final Map<String, UpdateSite> updateSites;
     if (siteNames.size() == 0) updateSites = this.updateSites;
     else {
       updateSites = new LinkedHashMap<String, UpdateSite>();
       for (final String name : siteNames) {
         updateSites.put(name, getUpdateSite(name, true));
       }
     }
     for (final UpdateSite updateSite : getUpdateSites(false)) {
       if (updateSite.isUploadable()) {
         final String name = updateSite.getName();
         actions.add(new Upload(name));
         actions.add(new Remove(name));
       }
     }
   }
   if (!hasUploadOrRemove) {
     actions.add(new Uninstall());
   }
   return actions;
 }
示例#3
0
  /**
   * Utility method for Fiji's Bug Submitter
   *
   * @return the list of files known to the Updater, with versions, as a String
   */
  public static String getInstalledVersions(final File ijDirectory, final Progress progress) {
    final StringBuilder sb = new StringBuilder();
    final FilesCollection files = new FilesCollection(ijDirectory);
    try {
      files.read();
    } catch (Exception e) {
      sb.append("Error while reading db.xml.gz: ").append(e.getMessage()).append("\n\n");
    }
    final Checksummer checksummer = new Checksummer(files, progress);
    try {
      checksummer.updateFromLocal();
    } catch (UpdateCanceledException t) {
      return null;
    }

    final Map<String, FileObject.Version> checksums = checksummer.getCachedChecksums();

    sb.append("Activated update sites:\n");
    for (final UpdateSite site : files.getUpdateSites(false)) {
      sb.append(site.getName())
          .append(": ")
          .append(site.getURL())
          .append(" (last check:")
          .append(site.getTimestamp())
          .append(")\n");
    }
    boolean notUpToDateShown = false;
    for (final Map.Entry<String, FileObject.Version> entry : checksums.entrySet()) {
      String file = entry.getKey();
      if (file.startsWith(":") && file.length() == 41) continue;
      final FileObject fileObject = files.get(file);
      if (fileObject != null && fileObject.getStatus() == Status.INSTALLED) continue;
      if (!notUpToDateShown) {
        sb.append("\nFiles not up-to-date:\n");
        notUpToDateShown = true;
      }
      final FileObject.Version version = entry.getValue();
      String checksum = version.checksum;
      if (version.checksum != null && version.checksum.length() > 8) {
        final StringBuilder rebuild = new StringBuilder();
        for (final String element : checksum.split(":")) {
          if (rebuild.length() > 0) rebuild.append(":");
          if (element == null || element.length() <= 8) rebuild.append(element);
          else rebuild.append(element.substring(0, 8));
        }
        checksum = rebuild.toString();
      }
      sb.append("  ").append(checksum).append(" ");
      if (fileObject != null) sb.append("(").append(fileObject.getStatus()).append(") ");
      sb.append(version.timestamp).append(" ");
      sb.append(file).append("\n");
    }
    return sb.toString();
  }
示例#4
0
 /**
  * Deactivates the given update site.
  *
  * @param site the site to deactivate
  * @return the number of files marked for update/install/uninstall
  */
 public int deactivateUpdateSite(final UpdateSite site) {
   if (!site.isActive()) return 0;
   final List<FileObject> list = new ArrayList<FileObject>();
   final String updateSite = site.getName();
   for (final FileObject file : forUpdateSite(updateSite)) {
     list.add(file);
   }
   for (final FileObject file : list) {
     file.removeFromUpdateSite(updateSite, this);
   }
   site.setActive(false);
   return list.size();
 }
示例#5
0
  public void renameUpdateSite(final String oldName, final String newName) {
    if (getUpdateSite(newName, true) != null)
      throw new RuntimeException("Update site " + newName + " exists already!");
    if (getUpdateSite(oldName, true) == null)
      throw new RuntimeException("Update site " + oldName + " does not exist!");

    // handle all files
    for (final FileObject file : this)
      if (oldName.equals(file.updateSite)) file.updateSite = newName;

    // preserve order
    final Map<String, UpdateSite> oldMap = updateSites;
    updateSites = new LinkedHashMap<String, UpdateSite>();
    for (final String name : oldMap.keySet()) {
      final UpdateSite site = oldMap.get(name);
      if (name.equals(oldName)) site.setName(newName);
      addUpdateSite(site.getName(), site);
    }
  }
示例#6
0
 public UpdateSite addUpdateSite(UpdateSite site) {
   addUpdateSite(site.getName(), site);
   return site;
 }