Index: src/lib/com/izforge/izpack/panels/UserInputPanelConsoleHelper.java =================================================================== --- src/lib/com/izforge/izpack/panels/UserInputPanelConsoleHelper.java (revision 2787) +++ src/lib/com/izforge/izpack/panels/UserInputPanelConsoleHelper.java (working copy) @@ -32,12 +32,14 @@ import java.util.StringTokenizer; import java.util.Vector; +import com.izforge.izpack.Pack; import com.izforge.izpack.Panel; import com.izforge.izpack.adaptator.IXMLElement; import com.izforge.izpack.installer.AutomatedInstallData; import com.izforge.izpack.installer.PanelConsole; import com.izforge.izpack.installer.PanelConsoleHelper; import com.izforge.izpack.util.Debug; +import com.izforge.izpack.util.OsVersion; import com.izforge.izpack.util.SpecHelper; import com.izforge.izpack.util.VariableSubstitutor; @@ -116,8 +118,16 @@ private static final String DESCRIPTION = "description"; private static final String TRUE = "true"; - - + + private static final String NAME = "name"; + + private static final String FAMILY = "family"; + + private static final String OS = "os"; + + private static final String SELECTEDPACKS = "createForPack"; // renamed + + private static Input SPACE_INTPUT_FIELD = new Input(SPACE, null, null, SPACE, "\r", 0); private static Input DIVIDER_INPUT_FIELD = new Input(DIVIDER, null, null, DIVIDER, "------------------------------------------", 0); @@ -162,9 +172,11 @@ public boolean runConsole(AutomatedInstallData idata) { - - collectInputs(idata); - VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables()); + + boolean processpanel = collectInputs(idata); + if (!processpanel) { + return true; + } boolean status = true; Iterator inputsIterator = listInputs.iterator(); while (inputsIterator.hasNext()) @@ -236,6 +248,7 @@ { e1.printStackTrace(); + return false; } specElements = specHelper.getSpec().getChildrenNamed(NODE_ID); @@ -247,26 +260,44 @@ if (((attribute != null) && instance.equals(attribute)) || ((dataID != null) && (panelid != null) && (panelid.equals(dataID)))) { - spec = data; + + Vector forPacks = data.getChildrenNamed(SELECTEDPACKS); + Vector forOs = data.getChildrenNamed(OS); + + if (itemRequiredFor(forPacks, idata) && itemRequiredForOs(forOs)) { + spec = data; + break; + } } } + + if (spec == null) { + return false; + } Vector fields = spec.getChildrenNamed(FIELD_NODE_ID); for (int i = 0; i < fields.size(); i++) { IXMLElement field = fields.elementAt(i); - String conditionid = field.getAttribute(ATTRIBUTE_CONDITIONID_NAME); - if (conditionid != null) - { - // check if condition is fulfilled - if (!idata.getRules().isConditionTrue(conditionid, idata.getVariables())) + + Vector forPacks = field.getChildrenNamed(SELECTEDPACKS); + Vector forOs = field.getChildrenNamed(OS); + + if (itemRequiredFor(forPacks, idata) && itemRequiredForOs(forOs)) { + + String conditionid = field.getAttribute(ATTRIBUTE_CONDITIONID_NAME); + if (conditionid != null) { - continue; + // check if condition is fulfilled + if (!idata.getRules().isConditionTrue(conditionid, idata.getVariables())) + { + continue; + } + } + Input in = getInputFromField(field, idata); + if (in != null) { + listInputs.add(in); } } - Input in = getInputFromField(field, idata); - if (in != null) { - listInputs.add(in); - } } return true; } @@ -311,16 +342,13 @@ if (set == null) { set = ""; - } + } } - else - { - if (set != null && !"".equals(set)) - { - VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables()); - set = vs.substitute(set, null); - } + if (set != null && !"".equals(set)) + { + VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables()); + set = vs.substitute(set, null); } fieldText = input.listChoices.get(0).strText; @@ -824,6 +852,103 @@ return null; } + /*--------------------------------------------------------------------------*/ + /** + * Verifies if an item is required for any of the packs listed. An item is required for a pack + * in the list if that pack is actually selected for installation.
+ *
+ * Note:
+ * If the list of selected packs is empty then true is always returnd. The same is + * true if the packs list is empty. + * + * @param packs a Vector of Strings. Each of the strings denotes a + * pack for which an item should be created if the pack is actually installed. + * @return true if the item is required for at least one pack in the list, + * otherwise returns false. + */ + /*--------------------------------------------------------------------------*/ + /* + * $ @design + * + * The information about the installed packs comes from InstallData.selectedPacks. This assumes + * that this panel is presented to the user AFTER the PacksPanel. + * -------------------------------------------------------------------------- + */ + private boolean itemRequiredFor(Vector packs, AutomatedInstallData idata) + { + + String selected; + String required; + + if (packs.size() == 0) { return (true); } + + // ---------------------------------------------------- + // We are getting to this point if any packs have been + // specified. This means that there is a possibility + // that some UI elements will not get added. This + // means that we can not allow to go back to the + // PacksPanel, because the process of building the + // UI is not reversable. + // ---------------------------------------------------- + // packsDefined = true; + + // ---------------------------------------------------- + // analyze if the any of the packs for which the item + // is required have been selected for installation. + // ---------------------------------------------------- + for (int i = 0; i < idata.selectedPacks.size(); i++) + { + selected = ((Pack) idata.selectedPacks.get(i)).name; + + for (int k = 0; k < packs.size(); k++) + { + required = (packs.elementAt(k)).getAttribute(NAME, ""); + if (selected.equals(required)) { return (true); } + } + } + + return (false); + } + + /** + * Verifies if an item is required for the operating system the installer executed. The + * configuration for this feature is:
+ * <os family="unix"/>
+ *
+ * Note:
+ * If the list of the os is empty then true is always returnd. + * + * @param os The Vector of Strings. containing the os names + * @return true if the item is required for the os, otherwise returns + * false. + */ + public boolean itemRequiredForOs(Vector os) + { + if (os.size() == 0) { return true; } + + for (int i = 0; i < os.size(); i++) + { + String family = (os.elementAt(i)).getAttribute(FAMILY); + boolean match = false; + + if ("windows".equals(family)) + { + match = OsVersion.IS_WINDOWS; + } + else if ("mac".equals(family)) + { + match = OsVersion.IS_OSX; + } + else if ("unix".equals(family)) + { + match = OsVersion.IS_UNIX; + } + if (match) { return true; } + } + return false; + } + + public static class Input {