Simplest Enterprise Continuous Integration Solutions

Saturday, November 20, 2010

InstallAnywhere: customcode via NetBeans


Here are the steps for creating an InstallAnywhere CustomCode (plugin) via NetBeans.


1. NetBeans IDE creates a new "Java Application" project - CompareVersionString, with com.qxc.ia.customcode.actions.CompareVersionString Main Class


CompareVersionString.java

package com.qxc.ia.customcode.actions;

import com.zerog.ia.api.pub.*;
import java.util.Arrays;
import java.util.List;

/**
 * CompareString.java
 *
 *
 */
public class CompareVersionString extends CustomCodeAction {

    /**
     *  This is the method that is called at install-time.  The InstallerProxy
     *  instance provides methods to access information in the installer,
     *  set status, and control flow.
     */
    public void install(InstallerProxy ip) throws InstallException {
        try {
            String myVar1 = ip.substitute("$OLD_VERSION_STR$");
            String myVar2 = ip.substitute("$NEW_VERSION_STR$");
            Integer myResultVariable = null;

            if (getComparisonResults(myVar1, myVar2) == 1) {
                myResultVariable = 1;
            } else if (getComparisonResults(myVar1, myVar2) == -1) {
                myResultVariable = -1;
            } else if (getComparisonResults(myVar1, myVar2) == 0) {
                myResultVariable = 0;
            }

            ip.setVariable("$COMPARISON_RESULT$", myResultVariable);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     *  This is the method that is called at uninstall-time.  The DataInput
     *  instance provides access to any information written at install-time
     *  with the instance of DataOutput provided by UninstallerProxy.getLogOutput().
     */
    public void uninstall(UninstallerProxy up) throws InstallException {
    }

    /**
     *  This method will be called to display a status message during the
     *  installation.
     */
    public String getInstallStatusMessage() {
        return "Comparing string";
    }

    /**
     *  This method will be called to display a status message during the
     *  uninstall.
     */
    public String getUninstallStatusMessage() {
        return "Comparing string";
    }

    public static int getComparisonResults(String oldString, String newVersion) {
        oldString = oldString.replaceAll("\\s", "");
        newVersion = newVersion.replaceAll("\\s", "");
        String[] a1 = oldString.split("\\.");
        String[] a2 = newVersion.split("\\.");
        List<String> list1 = Arrays.asList(a1);
        List<String> list2 = Arrays.asList(a2);

        int i = 0;
        while (true) {
            Double digit1 = null;
            Double digit2 = null;

            try {
                digit1 = Double.parseDouble(list1.get(i));
            } catch (IndexOutOfBoundsException e) {
            }

            try {
                digit2 = Double.parseDouble(list2.get(i));
            } catch (IndexOutOfBoundsException e) {
            }

            if (digit1 != null && digit2 != null) {
                if (digit1.doubleValue() > digit2.doubleValue()) {
                    return 1;
                } else if (digit1.doubleValue() < digit2.doubleValue()) {
                    return -1;
                }
            } else if (digit2 == null && digit1 != null) {
                if (digit1.doubleValue() > 0) {
                    return 1;
                }
            } else if (digit1 == null && digit2 != null) {
                if (digit2.doubleValue() > 0) {
                    return -1;
                }
            } else {
                break;
            }
            i++;
        }
        return 0;
    }
}


2. Under Source Packages, add help.htm and customcode.properties

help.htm:

<!--
<html>
<head>
<title>Plugin</title>
</head>
<body>
<b>Custom Code Action: CompareVersionString</b>
<br>
Classname: com.qxc.ia.customcode.actions.CompareVersionString
<br>
<br>
<b>Description:</b> This class compares dot delimited two version strings.
<br>
<br>
<b>Input InstallAnywhere Variables:</b>
<br>
<br>
$OLD_VERSION_STR$: contains dot delimited version string (i.e. 1.1.0.0).
<br>
$NEW_VERSION_STR$: contains dot delimited version string (i.e. 1.1.0.1).
<br>
<br>
<b>Output InstallAnywhere Variables:</b>
<br>
<br>
$COMPARISON_RESULT$: contains comparison result
<br>
(i.e.
<br>
"1" for $OLD_VERSION_STR$ is greater than $NEW_VERSION_STR$
<br>
"-1" for $OLD_VERSION_STR$ is less than $NEW_VERSION_STR$
<br>
"0" for $OLD_VERSION_STR$ is equal to $NEW_VERSION_STR$
<br>
) .
<br>
</body>
</html>

-->

customcode.properties:

plugin.main.class=com.qxc.ia.customcode.actions.CompareVersionString
plugin.name=CompareVersionString
plugin.type=action
plugin.available=preinstall,install,postinstall,preuninstall,postuninstall
property.OLD_VERSION_STR=
property.NEW_VERSION_STR=



3. Add <InstallAnywhere Install Dir>\IAClasses.zip for import com.zerog.ia.api.pub.*


4. NetBeans "Clean and Build" to generate CompareVersionString.jar


5. Copy the CompareVersionString.jar to <InstallAnywhere Install Dir>\plugins



6. CompareVersionString plugin is avaiable now










1 comment:

  1. Just push “spin” 라이브카지노 and wait for successful mixtures — that’s the way to|tips on how to} play free online slots machines! Online slots games are perhaps the most popular casino games giving the opportunity to win fast! At the identical time,free slots gamesattract gamers with high-quality graphics, fascinating plots, and wonderful music.

    ReplyDelete