Evaluate Custom Rule Rule

InstallAnywhere 2018

Custom rules built using the specifications outlined in the InstallAnywhere API can be tailored to fit the needs of the installation.

The process of creating a custom rule is similar to creating a custom action. To create a rule, you create a custom class that extends com.zerog.ia.api.pub.CustomCodeRule, and this class must implement an evaluateRule method that returns true if the rule succeeds and false if the rule fails.

At run time, if the rule succeeds, the action associated with it will be installed or performed, and if the rule fails the action will be skipped.

The Evaluate Custom Rule customizer includes the following options:

Evaluate Custom Rule Customizer

Option

Description

Path

Click the Choose JAR or ZIP button and browse for the .jar or .zip file.

Class

Enter the fully qualified custom rule class name (such as com.acme.MyCustomCodeRule).

Note • This class must extend com.zerog.ia.api.pub.CustomCodeRule and must implement a public boolean evaluateRule() method.

Configure Dependencies

Click to open the Custom Rules Dependencies dialog box, where you can select a .JAR or .ZIP file which contains classes referenced by your custom rule so that those classes are included in the archive and are available to the rule at runtime.

Open Javadocs

Click to open the documentation for the InstallAnywhere API.

Evaluate Custom Rule Examples

The following are examples of rules that could be used in an Evaluate Custom Rule rule:

Example: Rule That Always Succeeds
Example: Ensuring Minimum Target System Screen Resolution

Example: Rule That Always Succeeds

The implementation of a rule that always succeeds would appear similar to the following:

import com.zerog.ia.api.pub.*;

 

public class AlwaysSucceedsRule extends CustomCodeRule

{

    public boolean evaluateRule( )

    {

        return true; // always succeed

    }

}

You compile the rule class the same way you compile other custom code (by including IAClasses.zip in the compiler classpath), and package the .class file in a .jar file or .zip file.

Example: Ensuring Minimum Target System Screen Resolution

Suppose you want to ensure the target system screen resolution is above a given minimum. A custom code rule that succeeds if the target system’s resolution is at least 1024 by 768 might appear as follows.

import com.zerog.ia.api.pub.*;

import java.awt.*;

 

public class CheckScreenDimensionsRule extends CustomCodeRule

{

    private static final int MIN_WIDTH = 1024;

    private static final int MIN_HEIGHT = 768;

 

    public boolean evaluateRule( )

    {

        Toolkit tk = Toolkit.getDefaultToolkit( );

        Dimension d = tk.getScreenSize( );

 

        // fail if either dimension is below minimum

        if ((d.width < MIN_WIDTH) || (d.height < MIN_HEIGHT))

            return false;

        else

            return true;

    }

}

You compile the class and package it in a .jar or .zip file.

After you build and run the installer, the action containing the custom code rule will be skipped if the target system does not meet the minimum screen resolution.

Proxy Variable ruleProxy

The CustomCodeRule class provides the proxy variable ruleProxy (of type CustomCodeRuleProxy). With ruleProxy you can obtain the values of InstallAnywhere variables with the same methods getVariable and substitute available to custom code actions. For example, a refinement for the previous rule might be to enable the rule to automatically succeed if the installer is running in silent mode or console mode, using the $INSTALLER_UI$ variable.

See Also