Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

This element allows you to define conditions which can be used to dynamically change the installer, e.g. the panels shown, the variables set, files parsed, files executed and much more. When you define a condition it will get a type and an id. The id has to be unique. Conditions can be referenced based on this id (e.g. with the RefCondition).

There are several built-in types of conditions. At the time of writing this, Izpack has the following built-in types:

Condition

Function

Usage

VariableCondition

based on the value of a certain variable

 

PackSelectionCondition

based on a pack selected for installation

 

JavaCondition

based on a static java field or method

 

CompareNumericsCondition

based on the comparison of a certain variable with a given value and operator

 

RefCondition

based on another condition

<condition type="ref" id="" refid="ConditionToEvaluate"/>

There are also boolean types to combine more than one condition:

AndCondition

both conditions have to be true

OrCondition

only one of both conditions has to be true

XOrCondition

one condition has to be true, the other one has to be false

NotCondition

the condition has to be false

When you define a set of conditions, you just have to write as many <condition> tags as you like. A condition can take the following attributes:

Attribute

Usage

type

the type of the condition. For built-in types, this is the lowercase portion of the condition class name without condition appended (variable,packselection,java, ...). Custom condition types should be referenced by the full qualified class name, e.g. de.dr.rules.MyCoolCondition.

id

the id of the condition. This will be used to refer to this conditions in other elements

The condition element can have several child elements depending on the type of this conditions. E.g. the VariableCondition has a name and value child element to specify, which variable should have a certain value to fullfil this condition.

This is an example which defines four conditions, two VariableConditions, a JavaCondition and a AndCondition which will refer to two of the first conditions.

<conditions>
   <condition type="variable" id="standardinstallation">
      <name>setup.type</name>
      <value>standard</value>
   </condition>
   <condition type="variable" id="expertinstallation">
      <name>setup.type</name>
      <value>expert</value>
   </condition>
   <condition type="java" id="installonwindows">
 <java>
   <class>com.izforge.izpack.util.OsVersion</class>
   <field>IS_WINDOWS</field>
 </java>
 <returnvalue type="boolean">true</returnvalue>
 </condition>
 <condition type="and" id="standardinstallation.onwindows">
   <condition type="ref" refid="standardinstallation"/>
   <condition type="ref" refid="installonwindows" />
 </condition>
</conditions>

Expression languages

Simple expression language

From IzPack 3.11 on, you don't have to define compound conditions because you can use a simple expression language. The language supports the following operators:

+

an operator for the Andcondition

|

an operator for the OrCondition

\

an operator for the XOrCondition

!

an operator for the NotCondition

These simple expressions DO NOT follow the usual boolean logic with precedence rules. Instead, they are evaluated left to right in a simple way.

Thus, !conditionA+conditionB+!conditionC DOES NOT equal (!conditionA) && conditionB && (!conditionC), but equals !(conditionA && (conditionB && !(conditionC))).

So you should define complex conditions using the xml structure or use the Complex expression language.

Complex expression language

With IZPACK-577 and IZPACK-581 fixed and released, you can also use a more Complex expression language that evaluates using the boolean precedence rules, which is also reflected in the following table. The higher an operator is, the higher is its precedence.

^

an operator for the XorConditon

&&

an operator for the AndCondition

||

an operator for the OrCondition

!

an operator for the NotCondition

!conditionA+conditionB+!conditionC equals (!conditionA) && conditionB && (!conditionC).

Parentheses may be added in the future.

More types of conditions can be defined by inheriting com.izforge.izpack.Condition class.

Built-in conditions

A number of built-in condition IDs are available for you.

Name

Condition

izpack.windowsinstall

The OS is (any) Windows

izpack.windowsinstall.xp

The OS is Windows XP

izpack.windowsinstall.2003

The OS is Windows Server 2003

izpack.windowsinstall.vista

The OS is Windows Vista

izpack.windowsinstall.7

The OS is Windows 7

izpack.macinstall

The OS is Mac OS X

izpack.linuxinstall

The OS is a Linux variant

izpack.solarisinstall

The OS is a Solaris variant

izpack.solarisinstall.x86

The OS is a Solaris x86 variant

izpack.solarisinstall.sparc

The OS is a Solaris sparc variant

  • No labels