cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
mkapasi
Level 4

Need to write a custom code rule

In my install actions I am using a Modify text file action in order to add some srings to an existing file on the target system. I want to read the file before that and make sure that entry does not exist and only then create the entry. If the property already exists in the file then nothing needs to be done.
I understand I can only do this with a custom rule. I find the documentation to be very poor on custom rules in the Installanywhere help.
Can you please help me with this? Can someone please provide some sort of a code snippet on how I can get started? I really need help on this ASAP.
Thanks,
-Mehjabin
Labels (1)
0 Kudos
(7) Replies
RobertDickau
Flexera Alumni

A general skeleton of the code might look like this:
import com.zerog.ia.api.pub.*;

public class MyCustomCodeRule extends CustomCodeRule
{
public boolean evaluateRule( )
{
// return true if rule succeeds, false to fail
}
}
You'll need IAClasses.zip on your compiler class path.

For a bit more explanation, please see .../CustomCode/Templates/com/acme/CustomCodeRuleTemplate.java inside your InstallAnywhere distribution.
0 Kudos
mkapasi
Level 4

Thanks for the info Robert.
Can you point me to where I can get the API documentation? I did look at the CustomCodeRuleTemplate but what APIs do I use to access the installanywhere variables?
Thanks,
-Mehjabin
0 Kudos
RobertDickau
Flexera Alumni

Please see the API help in the javadoc directory of your IA distribution.
0 Kudos
tgnichols
Level 3

The API and the examples are nice, but if my rule is going to be very useful, I need to do an evaluation based on some IA variables. To get the IA variables into my custom rule, I need the CustomCodeRuleProxy class, which (I can tell from the API) takes an argument of type VariableAccess (an interface) in its constructor.

It would be really helpful if someone could provide an example of how to get the IA variables into the custom rule code - i.e. how to use the CustomCodeRuleProxy class (it would have been even better if they just included this in the example in Templates...).
0 Kudos
RobertDickau
Flexera Alumni

Actually, CustomCodeRuleTemplate.java should have commented-out examples of using ruleProxy.getValue and ruleProxy.substitute to get variable values in custom rule code...
0 Kudos
tgnichols
Level 3

Yes, this true. After taking another look at the API I noticed there is a protected attribute ruleProxy in the superclass we're extending, so just use that.

Ex:

ruleProxy.substitute("someVariable");

There is no need to create your own proxy object, this is already done for us. Still the documentation for custom code is a little sparse, especially in the manual.
0 Kudos
pv7721
Level 20

In your IA installation folder there is a javadoc subfolder containing all the API specific documentation. Have you checked that?
0 Kudos