Пример #1
0
  private int dfsVisit(Pack u, int[] status, boolean wipe, Map<String, PackColor> colours) {
    colours.put(u.getName(), PackColor.GREY);
    int check = checkValues[getPos(u.getName())];

    if (Math.abs(check) != 1) {
      wipe = true;
    }
    List<String> deps = u.getDependants();
    if (deps != null) {
      for (String name : deps) {
        Pack v = nameToPack.get(name);
        if (wipe) {
          status[getPos(v.getName())] = 1;
        }
        if (colours.get(v.getName()) == PackColor.WHITE) {
          final int result = dfsVisit(v, status, wipe, colours);
          if (result != 0) {
            return result;
          }
        }
      }
    }
    colours.put(u.getName(), PackColor.BLACK);
    return 0;
  }
Пример #2
0
 /**
  * This function updates the checkboxes after a change by disabling packs that cannot be installed
  * anymore and enabling those that can after the change. This is accomplished by running a search
  * that pinpoints the packs that must be disabled by a non-fullfiled dependency.
  */
 private void updateDeps() {
   int[] statusArray = new int[packs.size()];
   for (int i = 0; i < statusArray.length; i++) {
     statusArray[i] = 0;
   }
   dfs(statusArray);
   for (int i = 0; i < statusArray.length; i++) {
     if (statusArray[i] == 0 && checkValues[i] < 0) {
       checkValues[i] += 2;
     }
     if (statusArray[i] == 1 && checkValues[i] >= 0) {
       checkValues[i] = -2;
     }
   }
   // The required ones must propagate their required status to all the
   // ones
   // that they depend on
   for (Pack pack : packs) {
     if (pack.isRequired()) {
       String packid = pack.getLangPackId();
       if (packid != null) {
         if (!(!this.rules.canInstallPack(packid, this.variables)
             && this.rules.canInstallPackOptional(packid, this.variables))) {
           propRequirement(pack.getName());
         }
       } else {
         propRequirement(pack.getName());
       }
     }
   }
 }
Пример #3
0
  private void initvalues() {
    // name to pack position map
    namesPos = new HashMap<String, Integer>();
    for (int i = 0; i < packs.size(); i++) {
      Pack pack = packs.get(i);
      namesPos.put(pack.getName(), i);
    }
    // Init to the first values
    for (int i = 0; i < packs.size(); i++) {
      Pack pack = packs.get(i);
      if (packsToInstall.contains(pack)) {
        checkValues[i] = 1;
      }
    }

    // Check out and disable the ones that are excluded by non fullfiled
    // deps
    for (int i = 0; i < packs.size(); i++) {
      Pack pack = packs.get(i);
      if (checkValues[i] == 0) {
        List<String> deps = pack.getDependants();
        for (int j = 0; deps != null && j < deps.size(); j++) {
          String name = deps.get(j);
          int pos = getPos(name);
          checkValues[pos] = -2;
        }
      }
      // for mutual exclusion, uncheck uncompatible packs too
      // (if available in the current installGroup)

      if (checkValues[i] > 0 && pack.getExcludeGroup() != null) {
        for (int q = 0; q < packs.size(); q++) {
          if (q != i) {
            Pack otherpack = packs.get(q);
            if (pack.getExcludeGroup().equals(otherpack.getExcludeGroup())) {
              if (checkValues[q] == 1) {
                checkValues[q] = 0;
              }
            }
          }
        }
      }
    }
    // The required ones must propagate their required status to all the
    // ones
    // that they depend on
    for (Pack pack : packs) {
      if (pack.isRequired()) {
        propRequirement(pack.getName());
      }
    }

    refreshPacksToInstall();
  }
Пример #4
0
 /**
  * Generate a map from a pack's name to its pack object.
  *
  * @param packs list of pack objects
  * @return map from a pack's name to its pack object.
  */
 private Map<String, Pack> getNametoPackMapping(List<Pack> packs) {
   Map<String, Pack> nameToPack = new HashMap<String, Pack>();
   for (Pack pack : packs) {
     nameToPack.put(pack.getName(), pack);
   }
   return nameToPack;
 }
Пример #5
0
 /**
  * This function updates the checkboxes after a change by disabling packs that cannot be installed
  * anymore and enabling those that can after the change. This is accomplished by running a search
  * that pinpoints the packs that must be disabled by a non-fullfiled dependency. TODO: Look into
  * "+2" and "-2", doesn't look safe
  */
 protected void updateDeps() {
   int[] statusArray = new int[packs.size()];
   for (int i = 0; i < statusArray.length; i++) {
     statusArray[i] = 0;
   }
   dfs(statusArray);
   for (int i = 0; i < statusArray.length; i++) {
     if (statusArray[i] == 0 && checkValues[i] < 0) {
       checkValues[i] += PARTIAL_SELECTED;
     }
     if (statusArray[i] == 1 && checkValues[i] >= 0) {
       checkValues[i] = DEPENDENT_DESELECTED;
     }
   }
   // The required ones must propagate their required status to all the ones that they depend on
   for (Pack pack : packs) {
     if (pack.isRequired()) {
       String name = pack.getName();
       if (!(!rules.canInstallPack(name, variables)
           && rules.canInstallPackOptional(name, variables))) {
         checkValues = propRequirement(name, checkValues);
       }
     }
   }
 }
Пример #6
0
 /** Creates the reverse dependency graph */
 private void reverseDeps() {
   // name to pack map
   namesObj = new HashMap<String, Pack>();
   for (Pack pack : packs) {
     namesObj.put(pack.getName(), pack);
   }
   // process each pack
   for (Pack pack : packs) {
     List<String> deps = pack.getDependencies();
     for (int j = 0; deps != null && j < deps.size(); j++) {
       String name = deps.get(j);
       Pack parent = namesObj.get(name);
       parent.addDependant(pack.getName());
     }
   }
 }
Пример #7
0
  /**
   * Update the conditions for dependent packages. Update the conditions for optional packages.
   *
   * @param initial indicates if its the first time updating conditions.
   */
  private void updateConditions(boolean initial) {
    boolean changes = true;

    while (changes) {
      changes = false;
      for (Pack pack : packs) {
        String packName = pack.getName();
        int pos = getPos(packName);
        logger.fine("Conditions fulfilled for: " + packName + "?");
        if (!rules.canInstallPack(packName, variables)) {
          logger.fine("no");
          if (rules.canInstallPackOptional(packName, variables)) {
            logger.fine("optional");
            logger.fine(packName + " can be installed optionally.");
            if (initial) {
              if (checkValues[pos] != DESELECTED) {
                checkValues[pos] = DESELECTED;
                changes = true;
              }
            }
          } else {
            if (checkValues[pos] != DEPENDENT_DESELECTED) {
              logger.fine("Pack" + packName + " cannot be installed");
              checkValues[pos] = DEPENDENT_DESELECTED;
              changes = true;
            }
          }
        }
      }
    }
  }
Пример #8
0
 /**
  * Generate a map from a pack's name to its row number visible on the UI.
  *
  * @param packs list of pack objects
  * @return map from a pack's name to its row number visible on the UI
  */
 private Map<String, Integer> getNametoRowMapping(List<Pack> packs) {
   Map<String, Integer> nameToPos = new HashMap<String, Integer>();
   for (int i = 0; i < packs.size(); i++) {
     Pack pack = packs.get(i);
     nameToPos.put(pack.getName(), i);
   }
   return nameToPos;
 }
Пример #9
0
  /**
   * Ensure that parent packs know which packs are their children. Ensure that packs who have
   * dependants know which packs depend on them
   *
   * @param packs packs visible to the user
   * @param nameToPack mapping from pack names to pack objects
   * @return packs
   */
  private List<Pack> setPackProperties(List<Pack> packs, Map<String, Pack> nameToPack) {
    Pack parent;
    for (Pack pack : packs) {
      if (pack.hasParent()) {
        String parentName = pack.getParent();
        parent = nameToPack.get(parentName);
        parent.addChild(pack.getName());
      }

      if (pack.hasDependencies()) {
        for (String name : pack.getDependencies()) {
          parent = nameToPack.get(name);
          parent.addDependant(pack.getName());
        }
      }
    }
    return packs;
  }
Пример #10
0
  /**
   * Set the value of children packs to the same value as the parent pack.
   *
   * @param parentPack
   */
  private void updateChildren(Pack parentPack) {
    String parentName = parentPack.getName();
    int parentPosition = nameToRow.get(parentName);
    int parentValue = checkValues[parentPosition];

    for (String childName : parentPack.getChildren()) {
      int childPosition = nameToRow.get(childName);
      checkValues[childPosition] = parentValue;
    }
  }
Пример #11
0
  /**
   * Update packs to installed. A pack to be installed is: 1. A visible pack that has its checkbox
   * checked 2. A hidden pack that condition
   *
   * @return
   */
  public List<Pack> updatePacksToInstall() {
    packsToInstall.clear();
    for (int i = 0; i < packs.size(); i++) {
      Pack pack = packs.get(i);
      if (isChecked(i) && !installedPacks.containsKey(pack.getName())) {
        packsToInstall.add(pack);
      } else if (installedPacks.containsKey(pack.getName())) {
        checkValues[i] = REQUIRED_PARTIAL_SELECTED;
      }
    }

    for (Pack hiddenPack : this.hiddenPacks) {
      if (this.rules.canInstallPack(hiddenPack.getName(), variables)) {
        packsToInstall.add(hiddenPack);
      }
    }

    installData.setSelectedPacks(packsToInstall);
    return packsToInstall;
  }
Пример #12
0
 private boolean isTrue(List<Pack> selectedpacks) {
   if (selectedpacks != null) {
     for (Pack selectedpack : selectedpacks) {
       if (name.equals(selectedpack.getName())) {
         // pack is selected
         return true;
       }
     }
   }
   // pack is not selected
   return false;
 }
Пример #13
0
  @Override
  public boolean runConsole(InstallData installData, Console console) {
    java.util.List<Pack> selectedPacks = new ArrayList<Pack>();
    String installationMode = null;

    do {
      installationMode =
          console.prompt("Do you to execute the defaut installation ? Y for yes, N for no", null);
    } while (!isGoodValue(installationMode));
    if (isYes(installationMode)) {
      for (Pack p : installData.getAvailablePacks()) {
        if (p.isRequired() || p.isPreselected()) {
          selectedPacks.add(p);
        }
      }
    } else if (isNo(installationMode)) {
      for (Pack p : installData.getAvailablePacks()) {

        if (p.isRequired()) {
          selectedPacks.add(p);
        } else {
          String packToInstall = null;

          do {
            packToInstall =
                console.prompt(
                    "Do you want to install  [" + p.getName() + "] Y for yes, N for no ", null);
          } while (!isGoodValue(packToInstall));

          if (isYes(packToInstall)) {
            selectedPacks.add(p);
          } else if (isNo(packToInstall)) {
            console.println("Installation of " + p.getName() + " skipped");
          }
        }
      }
    }
    installData.setSelectedPacks(selectedPacks);
    return promptEndPanel(installData, console);
  }
Пример #14
0
  /**
   * Remove pack that are already installed
   *
   * @param selectedPacks
   */
  private void removeAlreadyInstalledPacks(List<Pack> selectedPacks) {
    List<Pack> removePacks = new ArrayList<Pack>();

    for (Pack selectedPack : selectedPacks) {
      if (installedPacks.containsKey(selectedPack.getName())) {
        // pack is already installed, remove it
        removePacks.add(selectedPack);
      }
    }
    for (Pack removePack : removePacks) {
      selectedPacks.remove(removePack);
    }
  }
Пример #15
0
  private void updateConditions(boolean initial) {
    boolean changes = true;

    while (changes) {
      changes = false;
      // look for packages,
      for (Pack pack : packs) {
        int pos = getPos(pack.getName());
        logger.fine("Conditions fulfilled for: " + pack.getName() + "?");
        if (!this.rules.canInstallPack(
            pack.getLangPackId(), this.variables)) // TODO - see IZPACK-799
        {
          logger.fine("no");
          if (this.rules.canInstallPackOptional(pack.getLangPackId(), this.variables)) {
            logger.fine("optional");
            logger.fine(pack.getLangPackId() + " can be installed optionally.");
            if (initial) {
              if (checkValues[pos] != 0) {
                checkValues[pos] = 0;
                changes = true;
                // let the process start from the beginning
                break;
              }
            }
          } else {
            logger.fine("Pack" + pack.getLangPackId() + " cannot be installed");
            if (checkValues[pos] != -2) {
              checkValues[pos] = -2;
              changes = true;
              // let the process start from the beginning
              break;
            }
          }
        }
      }
      refreshPacksToInstall();
    }
  }
Пример #16
0
  /*
   * @see TableModel#setValueAt(Object, int, int)
   * Update the value of some checkbox
   */
  @Override
  public void setValueAt(Object checkValue, int rowIndex, int columnIndex) {
    if (columnIndex != 0 || !(checkValue instanceof Integer)) {
      return;
    } else {
      Pack pack = packs.get(rowIndex);

      boolean added;
      if ((Integer) checkValue == SELECTED) {
        added = true;
        String name = pack.getName();
        if (rules.canInstallPack(name, variables)
            || rules.canInstallPackOptional(name, variables)) {
          if (pack.isRequired()) {
            checkValues[rowIndex] = REQUIRED_SELECTED;
          } else {
            checkValues[rowIndex] = SELECTED;
          }
        }
      } else {
        added = false;
        checkValues[rowIndex] = DESELECTED;
      }

      updateExcludes(rowIndex);
      updateDeps();

      if (added) {
        onSelectionUpdate(rowIndex);
        this.packsToInstall.add(pack); // Temporarily add
        updateConditions();
        this.packsToInstall.remove(pack); // Redo
      } else {
        onDeselectionUpdate(rowIndex);
        this.packsToInstall.remove(pack); // Temporarily remove
        updateConditions();
        this.packsToInstall.add(pack); // Redo
      }

      updatePacksToInstall();

      if (pack.hasParent()) {
        updateParent(pack);
      } else if (pack.hasChildren()) {
        updateChildren(pack);
      }

      fireTableDataChanged();
    }
  }
Пример #17
0
  /**
   * We use a modified dfs graph search algorithm as described in: Thomas H. Cormen, Charles
   * Leiserson, Ronald Rivest and Clifford Stein. Introduction to algorithms 2nd Edition 540-549,MIT
   * Press, 2001
   */
  private int dfs(int[] status) {
    Map<String, PackColor> colours = new HashMap<String, PackColor>();
    for (int i = 0; i < packs.size(); i++) {
      for (Pack pack : packs) {
        colours.put(pack.getName(), PackColor.WHITE);
      }
      Pack pack = packs.get(i);
      boolean wipe = false;

      if (dfsVisit(pack, status, wipe, colours) != 0) {
        return -1;
      }
    }
    return 0;
  }
Пример #18
0
  private void refreshPacksToInstall() {

    packsToInstall.clear();
    for (int i = 0; i < packs.size(); i++) {
      Pack pack = packs.get(i);
      String key = "";
      if ((pack.getLangPackId() != null) && (pack.getLangPackId().length() > 0)) {
        key = pack.getLangPackId();
      } else {
        key = pack.getName();
      }
      if ((Math.abs(checkValues[i]) == 1) && (!installedpacks.containsKey(key))) {
        packsToInstall.add(pack);
      }
    }

    for (int i = 0; i < packs.size(); i++) {
      Pack pack = packs.get(i);

      String key = "";
      if ((pack.getLangPackId() != null) && (pack.getLangPackId().length() > 0)) {
        key = pack.getLangPackId();
      } else {
        key = pack.getName();
      }
      if (installedpacks.containsKey(key)) {
        checkValues[i] = -3;
      }
    }
    // add hidden packs
    for (Pack hiddenpack : this.hiddenPacks) {
      if (this.rules.canInstallPack(hiddenpack.getLangPackId(), variables)) {
        packsToInstall.add(hiddenpack);
      }
    }
  }
Пример #19
0
  private Map<String, Pack> loadInstallationInformation(boolean modifyInstallation) {
    Map<String, Pack> installedpacks = new HashMap<String, Pack>();
    if (!modifyInstallation) {
      return installedpacks;
    }

    // installation shall be modified
    // load installation information
    ObjectInputStream oin = null;
    try {
      FileInputStream fin =
          new FileInputStream(
              new File(
                  installData.getInstallPath()
                      + File.separator
                      + InstallData.INSTALLATION_INFORMATION));
      oin = new ObjectInputStream(fin);
      List<Pack> packsinstalled = (List<Pack>) oin.readObject();
      for (Pack installedpack : packsinstalled) {
        installedpacks.put(installedpack.getName(), installedpack);
      }
      this.removeAlreadyInstalledPacks(installData.getSelectedPacks());
      logger.fine("Found " + packsinstalled.size() + " installed packs");

      Properties variables = (Properties) oin.readObject();

      for (Object key : variables.keySet()) {
        installData.setVariable((String) key, (String) variables.get(key));
      }
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      if (oin != null) {
        try {
          oin.close();
        } catch (IOException e) {
        }
      }
    }
    return installedpacks;
  }
Пример #20
0
  /**
   * Initialize the data that represented the checkbox states.
   *
   * @param packs
   * @param packsToInstall
   * @return
   */
  private int[] initCheckValues(List<Pack> packs, List<Pack> packsToInstall) {
    int[] checkValues = new int[packs.size()];

    // If a pack is indicated to be installed checkbox value should be SELECTED
    for (int i = 0; i < packs.size(); i++) {
      Pack pack = packs.get(i);
      if (packsToInstall.contains(pack)) {
        checkValues[i] = SELECTED;
      }
    }

    // If a packs dependency cannot be resolved checkboc value should be DEPENDENT_DESELECTED
    for (int i = 0; i < packs.size(); i++) {
      Pack pack = packs.get(i);
      if (checkValues[i] == DESELECTED) {
        List<String> deps = pack.getDependants();
        for (int j = 0; deps != null && j < deps.size(); j++) {
          String name = deps.get(j);
          int pos = getPos(name);
          checkValues[pos] = DEPENDENT_DESELECTED;
        }
      }

      // for mutual exclusion, uncheck uncompatible packs too
      // (if available in the current installGroup)
      if (checkValues[i] > 0 && pack.getExcludeGroup() != null) {
        for (int q = 0; q < packs.size(); q++) {
          if (q != i) {
            Pack otherPack = packs.get(q);
            if (pack.getExcludeGroup().equals(otherPack.getExcludeGroup())) {
              if (checkValues[q] == SELECTED) {
                checkValues[q] = DESELECTED;
              }
            }
          }
        }
      }
    }

    // Configure required packs
    for (Pack pack : packs) {
      if (pack.isRequired()) {
        checkValues = propRequirement(pack.getName(), checkValues);
      }
    }

    return checkValues;
  }
Пример #21
0
  private void removeAlreadyInstalledPacks(List<Pack> selectedpacks) {
    List<Pack> removepacks = new ArrayList<Pack>();

    for (Pack selectedpack : selectedpacks) {
      String key = "";
      if (selectedpack.getLangPackId() != null) {
        key = selectedpack.getLangPackId();
      } else {
        key = selectedpack.getName();
      }
      if (installedpacks.containsKey(key)) {
        // pack is already installed, remove it
        removepacks.add(selectedpack);
      }
    }
    for (Pack removepack : removepacks) {
      selectedpacks.remove(removepack);
    }
  }
Пример #22
0
  @Override
  public Object getValueAt(int rowIndex, int columnIndex) {
    Pack pack = packs.get(rowIndex);
    switch (columnIndex) {
      case 0:
        return checkValues[rowIndex];

      case 1:
        Object name = null;
        if (messages != null && pack.getLangPackId() != null && !pack.getLangPackId().equals("")) {
          name = messages.get(pack.getLangPackId());
        }
        if (name == null || "".equals(name)) {
          name = pack.getName();
        }
        return name;

      case 2:
        return Pack.toByteUnitsString(pack.getSize());

      default:
        return null;
    }
  }
Пример #23
0
  public PacksModel(PacksPanelInterface panel, GUIInstallData idata, RulesEngine rules) {
    this.idata = idata;
    modifyinstallation = Boolean.valueOf(idata.getVariable(InstallData.MODIFY_INSTALLATION));
    this.installedpacks = new HashMap<String, Pack>();

    if (modifyinstallation) {
      // installation shall be modified
      // load installation information

      try {
        FileInputStream fin =
            new FileInputStream(
                new File(
                    idata.getInstallPath()
                        + File.separator
                        + InstallData.INSTALLATION_INFORMATION));
        ObjectInputStream oin = new ObjectInputStream(fin);
        List<Pack> packsinstalled = (List<Pack>) oin.readObject();
        for (Pack installedpack : packsinstalled) {
          if ((installedpack.getLangPackId() != null)
              && (installedpack.getLangPackId().length() > 0)) {
            this.installedpacks.put(installedpack.getLangPackId(), installedpack);
          } else {
            this.installedpacks.put(installedpack.getName(), installedpack);
          }
        }
        this.removeAlreadyInstalledPacks(idata.getSelectedPacks());
        logger.fine("Found " + packsinstalled.size() + " installed packs");

        Properties variables = (Properties) oin.readObject();

        for (Object key : variables.keySet()) {
          idata.setVariable((String) key, (String) variables.get(key));
        }
        fin.close();
      } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    this.rules = rules;

    this.packs = new ArrayList<Pack>();
    this.hiddenPacks = new ArrayList<Pack>();
    for (Pack availablePack : idata.getAvailablePacks()) {
      // only add a pack if not hidden
      if (!availablePack.isHidden()) {
        this.packs.add(availablePack);
      } else {
        this.hiddenPacks.add(availablePack);
      }
    }

    this.packsToInstall = idata.getSelectedPacks();
    this.panel = panel;
    variables = idata.getVariables();
    variables.set(INITAL_PACKSELECTION, Boolean.toString(true));
    messages = panel.getMessages();
    checkValues = new int[packs.size()];
    reverseDeps();
    initvalues();
    this.updateConditions(true);
    refreshPacksToInstall();
    variables.set(INITAL_PACKSELECTION, Boolean.toString(false));
  }