Exemplo n.º 1
0
 protected boolean pkgUpgradeByType(PackageType type) {
   List<DownloadablePackage> upgrades =
       NuxeoConnectClient.getPackageManager().listUpdatePackages(type, targetPlatform);
   List<String> upgradeIds = new ArrayList<String>();
   for (DownloadablePackage upgrade : upgrades) {
     upgradeIds.add(upgrade.getId());
   }
   return pkgRequest(null, upgradeIds, null, null);
 }
Exemplo n.º 2
0
 protected boolean isRemotePackageId(String pkgId) {
   List<DownloadablePackage> remotePackages =
       NuxeoConnectClient.getPackageManager().listAllPackages();
   boolean foundId = false;
   for (DownloadablePackage pkg : remotePackages) {
     if (pkg.getId().equals(pkgId)) {
       foundId = true;
       break;
     }
   }
   return foundId;
 }
Exemplo n.º 3
0
 @GET
 @Produces("text/html")
 @Path(value = "progressPage/{pkgId}")
 public Object getDownloadProgressPage(
     @PathParam("pkgId") String pkgId,
     @QueryParam("source") String source,
     @QueryParam("install") Boolean install,
     @QueryParam("depCheck") Boolean depCheck,
     @QueryParam("type") String pkgType,
     @QueryParam("onlyRemote") Boolean onlyRemote,
     @QueryParam("filterOnPlatform") Boolean filterOnPlatform) {
   DownloadablePackage pkg = getDownloadingPackage(pkgId);
   boolean downloadOver = false;
   // flag to start install after download
   if (install == null) {
     install = false;
   }
   if (depCheck == null) {
     depCheck = true;
   }
   if (pkg == null) {
     PackageManager pm = Framework.getLocalService(PackageManager.class);
     pkg = pm.getPackage(pkgId);
     if (pkg.getPackageState() != PackageState.DOWNLOADING) {
       downloadOver = true;
     }
   }
   return getView("downloadStarted")
       .arg("pkg", pkg)
       .arg("source", source)
       .arg("over", downloadOver)
       .arg("install", install)
       .arg("depCheck", depCheck)
       .arg("filterOnPlatform", filterOnPlatform.toString())
       .arg("type", pkgType.toString())
       .arg("onlyRemote", onlyRemote.toString());
 }
Exemplo n.º 4
0
 public static boolean isSnapshot(DownloadablePackage pkg) {
   return pkg.getVersion() != null && pkg.getVersion().toString().endsWith(SNAPSHOT_SUFFIX);
 }
Exemplo n.º 5
0
  @SuppressWarnings("unchecked")
  public boolean pkgRequest(
      List<String> pkgsToAdd,
      List<String> pkgsToInstall,
      List<String> pkgsToUninstall,
      List<String> pkgsToRemove) {
    boolean cmdOk = true;
    // Add local files
    cmdOk = pkgAdd(pkgsToAdd);
    // Build solver request
    List<String> solverInstall = new ArrayList<String>();
    List<String> solverRemove = new ArrayList<String>();
    List<String> solverUpgrade = new ArrayList<String>();
    if (pkgsToInstall != null) {
      // If install request is a file name, add to cache and get the id
      List<String> namesOrIdsToInstall = new ArrayList<String>();
      for (String pkgToInstall : pkgsToInstall) {
        if (isLocalPackageFile(pkgToInstall)) {
          LocalPackage addedPkg = pkgAdd(pkgToInstall);
          if (addedPkg != null) {
            namesOrIdsToInstall.add(addedPkg.getId());
          } else {
            cmdOk = false;
          }
          // TODO: set flag to prefer local package
        } else {
          namesOrIdsToInstall.add(pkgToInstall);
        }
      }
      // Check whether we have new installs or upgrades
      for (String pkgToInstall : namesOrIdsToInstall) {
        Map<String, DownloadablePackage> allPackagesByID =
            NuxeoConnectClient.getPackageManager().getAllPackagesByID();
        DownloadablePackage pkg = allPackagesByID.get(pkgToInstall);
        if (pkg != null) {
          // This is a known ID
          if (isInstalledPackageName(pkg.getName())) {
            // The package is installed in another version
            solverUpgrade.add(pkgToInstall);
          } else {
            // The package isn't installed yet
            solverInstall.add(pkgToInstall);
          }
        } else {
          // This is a name (or a non-existing ID)
          String id = getInstalledPackageIdFromName(pkgToInstall);
          if (id != null) {
            // The package is installed in another version
            solverUpgrade.add(id);
          } else {
            // The package isn't installed yet
            solverInstall.add(pkgToInstall);
          }
        }
      }
    }
    if (pkgsToUninstall != null) {
      solverRemove.addAll(pkgsToUninstall);
    }
    if (pkgsToRemove != null) {
      // Add packages to remove to uninstall list
      solverRemove.addAll(pkgsToRemove);
    }
    if ((solverInstall.size() != 0) || (solverRemove.size() != 0) || (solverUpgrade.size() != 0)) {
      // Check whether we need to relax restriction to targetPlatform
      String requestPlatform = targetPlatform;
      List<String> requestPackages = new ArrayList<String>();
      requestPackages.addAll(solverInstall);
      requestPackages.addAll(solverRemove);
      requestPackages.addAll(solverUpgrade);
      try {
        String nonCompliantPkg =
            getPackageManager().getNonCompliant(requestPackages, targetPlatform);
        if (nonCompliantPkg != null) {
          requestPlatform = null;
          if ("ask".equalsIgnoreCase(relax)) {
            relax =
                readConsole(
                    "Package %s is not available on platform version %s.\n"
                        + "Do you want to relax the constraint (yes/no)? [no] ",
                    "no", nonCompliantPkg, targetPlatform);
          }

          if (Boolean.parseBoolean(relax)) {
            log.warn(
                String.format(
                    "Relax restriction to target platform %s because of package %s",
                    targetPlatform, nonCompliantPkg));
          } else {
            throw new PackageException(
                String.format(
                    "Package %s is not available on platform version %s (relax is not allowed)",
                    nonCompliantPkg, targetPlatform));
          }
        }
      } catch (PackageException e) {
        log.error(e);
        return false;
      }

      log.debug("solverInstall: " + solverInstall);
      log.debug("solverRemove: " + solverRemove);
      log.debug("solverUpgrade: " + solverUpgrade);
      DependencyResolution resolution =
          getPackageManager()
              .resolveDependencies(solverInstall, solverRemove, solverUpgrade, requestPlatform);
      log.info(resolution);
      if (resolution.isFailed()) {
        return false;
      }
      if (resolution.isEmpty()) {
        pkgRemove(pkgsToRemove);
        return cmdOk;
      }
      if ("ask".equalsIgnoreCase(accept)) {
        accept = readConsole("Do you want to continue (yes/no)? [yes] ", "yes");
      }
      if (!Boolean.parseBoolean(accept)) {
        log.warn("Exit");
        return false;
      }

      List<String> packageIdsToRemove = resolution.getOrderedPackageIdsToRemove();
      List<String> packageIdsToUpgrade = resolution.getUpgradePackageIds();
      List<String> packageIdsToInstall = resolution.getOrderedPackageIdsToInstall();
      List<String> packagesIdsToReInstall = new ArrayList<String>();

      // Download remote packages
      if (!downloadPackages(resolution.getDownloadPackageIds())) {
        log.error("Aborting packages change request");
        return false;
      }

      // Uninstall
      if (!packageIdsToUpgrade.isEmpty()) {
        // Add packages to upgrade to uninstall list
        // Don't use IDs to avoid downgrade instead of uninstall
        packageIdsToRemove.addAll(resolution.getLocalPackagesToUpgrade().keySet());
        DependencyResolution uninstallResolution =
            getPackageManager()
                .resolveDependencies(null, packageIdsToRemove, null, requestPlatform);
        log.debug("Sub-resolution (uninstall) " + uninstallResolution);
        if (uninstallResolution.isFailed()) {
          return false;
        }
        List<String> newPackageIdsToRemove = uninstallResolution.getOrderedPackageIdsToRemove();
        packagesIdsToReInstall = ListUtils.subtract(newPackageIdsToRemove, packageIdsToRemove);
        packagesIdsToReInstall.removeAll(packageIdsToUpgrade);
        packageIdsToRemove = newPackageIdsToRemove;
      }
      if (!pkgUninstall(packageIdsToRemove)) {
        return false;
      }

      // Install
      if (!packagesIdsToReInstall.isEmpty()) {
        // Add list of packages uninstalled because of upgrade
        packageIdsToInstall.addAll(packagesIdsToReInstall);
        DependencyResolution installResolution =
            getPackageManager()
                .resolveDependencies(packageIdsToInstall, null, null, requestPlatform);
        log.debug("Sub-resolution (install) " + installResolution);
        if (installResolution.isFailed()) {
          return false;
        }
        packageIdsToInstall = installResolution.getOrderedPackageIdsToInstall();
      }
      if (!pkgInstall(packageIdsToInstall)) {
        return false;
      }

      pkgRemove(pkgsToRemove);
    }
    return cmdOk;
  }