示例#1
0
 public String getURL(final FileObject file) {
   final String siteName = file.updateSite;
   assert (siteName != null && !siteName.equals(""));
   final UpdateSite site = getUpdateSite(siteName, false);
   if (site == null) return null;
   return site.getURL() + file.filename.replace(" ", "%20") + "-" + file.getTimestamp();
 }
示例#2
0
 public String protocolsMissingUploaders(
     final UploaderService uploaderService, final Progress progress) {
   final Map<String, Set<String>> map = new LinkedHashMap<String, Set<String>>();
   for (final Map.Entry<String, UpdateSite> entry : updateSites.entrySet()) {
     final UpdateSite site = entry.getValue();
     if (!site.isUploadable()) continue;
     final String protocol = site.getUploadProtocol();
     try {
       uploaderService.installUploader(protocol, this, progress);
     } catch (IllegalArgumentException e) {
       Set<String> set = map.get(protocol);
       if (set == null) {
         set = new LinkedHashSet<String>();
         map.put(protocol, set);
       }
       set.add(entry.getKey());
     }
   }
   if (map.size() == 0) return null;
   final StringBuilder builder = new StringBuilder();
   builder.append(
       prefixUpdate("").isDirectory()
           ? "Uploads via these protocols require a restart:\n"
           : "Missing uploaders:\n");
   for (final Map.Entry<String, Set<String>> entry : map.entrySet()) {
     final String list = Arrays.toString(entry.getValue().toArray());
     builder.append("'").append(entry.getKey()).append("': ").append(list).append("\n");
   }
   return builder.toString();
 }
示例#3
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;
 }
示例#4
0
 protected void addUpdateSite(final String name, final UpdateSite updateSite) {
   UpdateSite already = updateSites.get(name);
   updateSite.rank = already != null ? already.rank : updateSites.size();
   if (already != null) updateSite.setOfficial(already.isOfficial());
   updateSites.put(name, updateSite);
   if (updateSite != already) setUpdateSitesChanged(true);
 }
示例#5
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);
 }
示例#6
0
 /** Gets the list of known update sites. */
 public Collection<UpdateSite> getUpdateSites(final boolean evenDisabled) {
   if (evenDisabled) return updateSites.values();
   final List<UpdateSite> result = new ArrayList<UpdateSite>();
   for (final UpdateSite site : updateSites.values()) {
     if (site.isActive()) result.add(site);
   }
   return result;
 }
示例#7
0
 /**
  * This constructor takes the imagejRoot primarily for testing purposes.
  *
  * @param log the log service
  * @param imagejRoot the ImageJ directory
  */
 public FilesCollection(final LogService log, final File imagejRoot) {
   this.log = log;
   this.imagejRoot = imagejRoot;
   util = new UpdaterUtil(imagejRoot);
   updateSites = new LinkedHashMap<String, UpdateSite>();
   final UpdateSite updateSite =
       addUpdateSite(DEFAULT_UPDATE_SITE, UpdaterUtil.MAIN_URL, null, null, timestamp());
   updateSite.setOfficial(true);
 }
示例#8
0
 public Collection<String> getProtocols(Iterable<FileObject> selected) {
   final Set<String> protocols = new LinkedHashSet<String>();
   for (final FileObject file : selected) {
     final UpdateSite site = getUpdateSite(file.updateSite, false);
     if (site != null) {
       if (site.getHost() == null) protocols.add("unknown(" + file.filename + ")");
       else protocols.add(site.getUploadProtocol());
     }
   }
   return protocols;
 }
示例#9
0
 public UpdateSite addUpdateSite(
     final String name,
     final String url,
     final String sshHost,
     final String uploadDirectory,
     final long timestamp) {
   final UpdateSite site =
       new UpdateSite(name, url, sshHost, uploadDirectory, null, null, timestamp);
   site.setActive(true);
   return addUpdateSite(site);
 }
示例#10
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();
  }
示例#11
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();
 }
示例#12
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);
    }
  }
 public DigestHandler(final UpdateSite site) {
   super(DIGEST);
   repoDescriptor =
       new UpdateSiteDescriptor(
           site.getUri(), ExecutionEnvironmentProfileProvider.getInstance());
   addChild(
       new FeatureHandler(),
       new ChildElementHandler<FeatureHandler>() {
         public void childHanlded(FeatureHandler child) {
           repoDescriptor.addFeature(child.feature);
         }
       });
 }
示例#14
0
 public boolean hasUploadableSites() {
   for (final UpdateSite site : updateSites.values())
     if (site.isActive() && site.isUploadable()) return true;
   return false;
 }
示例#15
0
 public UpdateSite getUpdateSite(final String name, final boolean evenDisabled) {
   if (name == null) return null;
   final UpdateSite site = updateSites.get(name);
   return evenDisabled || site == null || site.isActive() ? site : null;
 }
示例#16
0
 public UpdateSite addUpdateSite(UpdateSite site) {
   addUpdateSite(site.getName(), site);
   return site;
 }