Ejemplo n.º 1
0
 /**
  * Validate a panel.
  *
  * @param p The panel to validate
  * @throws InstallerException thrown if the validation fails.
  */
 private boolean validatePanel(final Panel p) throws InstallerException {
   boolean bValidity = true;
   String dataValidator = p.getValidator();
   if (dataValidator != null) {
     DataValidator validator = DataValidatorFactory.createDataValidator(dataValidator);
     Status validationResult = validator.validateData(installdata);
     if (validationResult != DataValidator.Status.OK) {
       // if defaultAnswer is true, result is ok
       if (validationResult == Status.WARNING && validator.getDefaultAnswer()) {
         System.out.println(
             "Configuration said, it's ok to go on, if validation is not successfull");
       }
       // make installation fail instantly
       bValidity = false;
       System.out.println("Validation failed, please verify your input");
     }
   }
   return bValidity;
 }
Ejemplo n.º 2
0
  protected void iterateAndPerformAction(String strAction) throws Exception {
    if (!checkInstallerRequirements(this.installdata)) {
      Debug.log("not all installerconditions are fulfilled.");
      return;
    }
    Debug.log("[ Starting console installation ] " + strAction);

    try {
      this.result = true;
      Iterator<Panel> panelsIterator = this.installdata.panelsOrder.iterator();
      this.installdata.curPanelNumber = -1;
      VariableSubstitutor substitutor = new VariableSubstitutor(this.installdata.getVariables());
      while (panelsIterator.hasNext()) {
        Panel p = (Panel) panelsIterator.next();
        this.installdata.curPanelNumber++;
        String praefix = "com.izforge.izpack.panels.";
        if (p.className.compareTo(".") > -1) {
          praefix = "";
        }
        if (!OsConstraint.oneMatchesCurrentSystem(p.osConstraints)) {
          continue;
        }
        String panelClassName = p.className;
        String consoleHelperClassName = praefix + panelClassName + "ConsoleHelper";
        Class<PanelConsole> consoleHelperClass = null;

        Debug.log("ConsoleHelper:" + consoleHelperClassName);
        try {

          consoleHelperClass = (Class<PanelConsole>) Class.forName(consoleHelperClassName);

        } catch (ClassNotFoundException e) {
          Debug.log("ClassNotFoundException-skip :" + consoleHelperClassName);
          continue;
        }
        PanelConsole consoleHelperInstance = null;
        if (consoleHelperClass != null) {
          try {
            Debug.log("Instantiate :" + consoleHelperClassName);
            refreshDynamicVariables(substitutor, installdata);
            consoleHelperInstance = consoleHelperClass.newInstance();
          } catch (Exception e) {
            Debug.log(
                "ERROR: no default constructor for " + consoleHelperClassName + ", skipping...");
            continue;
          }
        }

        if (consoleHelperInstance != null) {
          try {
            Debug.log(
                "consoleHelperInstance." + strAction + ":" + consoleHelperClassName + " entered.");
            boolean bActionResult = true;
            boolean bIsConditionFulfilled = true;
            String strCondition = p.getCondition();
            if (strCondition != null) {
              bIsConditionFulfilled = installdata.getRules().isConditionTrue(strCondition);
            }

            if (strAction.equals("doInstall") && bIsConditionFulfilled) {
              do {
                bActionResult = consoleHelperInstance.runConsole(this.installdata);
              } while (!validatePanel(p));
            } else if (strAction.equals("doGeneratePropertiesFile")) {
              bActionResult =
                  consoleHelperInstance.runGeneratePropertiesFile(
                      this.installdata, this.printWriter);
            } else if (strAction.equals("doInstallFromPropertiesFile") && bIsConditionFulfilled) {
              bActionResult =
                  consoleHelperInstance.runConsoleFromPropertiesFile(
                      this.installdata, this.properties);
            }
            if (!bActionResult) {
              this.result = false;
              return;
            } else {
              Debug.log(
                  "consoleHelperInstance."
                      + strAction
                      + ":"
                      + consoleHelperClassName
                      + " successfully done.");
            }
          } catch (Exception e) {
            Debug.log("ERROR: console installation failed for panel " + panelClassName);
            e.printStackTrace();
            this.result = false;
          }
        }
      }

      if (this.result) {
        System.out.println("[ Console installation done ]");
      } else {
        System.out.println("[ Console installation FAILED! ]");
      }
    } catch (Exception e) {
      this.result = false;
      System.err.println(e.toString());
      e.printStackTrace();
      System.out.println("[ Console installation FAILED! ]");
    }
  }