コード例 #1
0
ファイル: TestHotFixes.java プロジェクト: nuxeo/nuxeo-connect
 public void testResolutionOrder() throws Exception {
   DependencyResolution depResolution =
       pm.resolveDependencies(Arrays.asList("hf11-1.0.0"), null, null, null);
   log.info(depResolution.toString());
   assertTrue(depResolution.isValidated());
   String expectedOrder =
       "hf00-1.0.0/hf01-1.0.0/hf01PATCH-1.0.0/hf02-1.0.0/hf03-1.0.0/hf04-1.0.0/hf05-1.0.0/hf06-1.0.0/hf07-1.0.0/hf08-1.0.0/hf09-1.0.0/hf10-1.0.0/hf11-1.0.0";
   assertEquals(
       "Bad dependencies order", expectedOrder, depResolution.getInstallationOrderAsString());
 }
コード例 #2
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;
  }