Zelix KlassMaster - Documentation
 

Calling Zelix KlassMaster™ from a Build Tool

Zelix KlassMaster™ exposes a generic Java API that allows it to be called by a build tool. Although the build API is generic, it has only been tested with the Apache Ant build tool. A simple example of the Apache Ant XML appears below.

Generic API

package com.zelix;

   public class ZKM

      public static void run(String zkmScriptFileName, 
                             String logFileName,
                             String trimLogFileName,
                             String defaultExcludeFileName, 
                             String defaultTrimExcludeFileName, 
                             String defaultDirectoryName, 
                             boolean isVerbose, 
                             boolean isParseOnly) 
                      throws Exception

      public static void run(String zkmScriptFileName, 
                             String logFileName, 
                             String trimLogFileName,
                             String defaultExcludeFileName, 
                             String defaultTrimExcludeFileName, 
                             String defaultDirectoryName, 
                             boolean isVerbose, 
                             boolean isParseOnly,
                             Hashtable extraPropertiesTable) 
                      throws Exception

      public static void run(String zkmScriptFileName, 
                             String logFileName, 
                             String trimLogFileName,
                             String defaultExcludeFileName, 
                             String defaultTrimExcludeFileName, 
                             String defaultDirectoryName, 
                             boolean isVerbose, 
                             boolean isParseOnly,
                             Properties extraProperties) 
                      throws Exception

      public static void run(String zkmScriptFileName, 
                             String logFileName, 
                             String trimLogFileName,
                             String defaultExcludeFileName, 
                             String defaultTrimExcludeFileName, 
                             String defaultDirectoryName, 
                             String redirectOutFileName, 
                             String redirectErrFileName,
                             boolean isVerbose, 
                             boolean isParseOnly,
                             Properties extraProperties) 
                      throws Exception
         
Parameters:
zkmScriptFileName The path name of the ZKM Script file to execute. May be relative or absolute. Mandatory. If the path is relative, Zelix KlassMaster™ will look in the default directory.
logFileName The path name of the log file to which messages should be written. May be relative or absolute. Optional. If the path is relative, then it will be written to the default directory. If null then the file "ZKM_log.txt" will be used.
trimLogFileName The path name of the trim log file to which trim results should be written. May be relative or absolute. Optional. If the path is relative, then it will be written to the default directory. If null then the file "ZKM_TrimLog.txt" will be used.
defaultExcludeFileName The path name of the file containing the default name exclusions. May be relative or absolute. Optional. If the path is relative, Zelix KlassMaster™ will look in the default directory. If null then Zelix KlassMaster™ will look in the default directory for the file "defaultExclude.txt".
defaultTrimExcludeFileName The path name of the file containing the default trim exclusions. May be relative or absolute. Optional. If the path is relative, Zelix KlassMaster™ will look in the default directory. If the path is null then Zelix KlassMaster™ will look in the default directory for the file "defaultTrimExclude.txt".
defaultDirectoryName The path name of the directory which will be used as the default directory. May be relative or absolute. Optional. If the path is relative, then it will be relative to the current working directory. If the path is null then the default directory will be the current working directory.
isVerbose If true, extra information is written to the log file.
isParseOnly If true, the ZKM Script file will be parsed but not executed.
extraPropertiesTable A Hashtable of String name value pairs for use in ZKM Script System Variable substitution.
extraProperties A Properties object containing name value pairs for use in ZKM Script System Variable substitution.
redirectOutFileName The file to which stdout should be redirected. May be null.
redirectErrFileName The file to which stderr should be redirected. May be null.
Throws:
Exception If any errors are encountered in parsing and executing the ZKM Script.

For example:

com.zelix.ZKM.run("/projects/myScript.txt", null, null, null, null, null, false, false, myProperties);

Apache Ant Example

A simple Ant task for the Zelix KlassMaster™ obfuscator is already included in the ZKM.jar file. The task is called ZKMTask. An example of a simple build.xml to call ZKMTask appears below.
<?xml version="1.0"?>
<project name="ZKMTask" default="main" basedir=".">
  <property name="MY_PROPERTY" value="myValue"/> <!-- Example of setting a property for use as a ZKM Script System Variable -->
  <taskdef name="ZKM" classname="ZKMTask" classpath="ZKM.jar"/>
  <target name="main">
     <!-- Attributes correspond to Zelix KlassMaster™ command line options. scriptFileName is only mandatory attribute -->
     <ZKM scriptFileName="myZKMScript.txt"
          logFileName="ZKM_log.txt" 
          trimLogFileName="ZKM_TrimLog.txt" 
          defaultExcludeFileName="defaultExclude.txt" 
          defaultTrimExcludeFileName="defaultTrimExclude.txt" 
          defaultDirectoryName="." 
          isParseOnly="false" 
          isVerbose="true" 
     >
        <!--  the sysproperty tag provides an easy way of setting a System property -->
        <sysproperty key="ZKM_NEW_CHANGE_LOG_ENCODING" value="UTF-16" /> 
    </ZKM>		
  </target>
</project>

Apache Ant 1.4.1 Task Definition

ZKMTask is a simple Ant task definition for the Zelix KlassMaster™ obfuscator. It passes in the Ant Project properties by default. It can be modified to pass in Properties of your own choosing. The compiled version of this class is already included in the ZKM.jar file.

/*
 * Copyright (c) 2003-2014 Zelix Pty Ltd  (ACN 078 740 093). All  Rights Reserved.
 *
 * You are free to use this software with or without modifications
 * subject to the following conditions.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS," WITHOUT A WARRANTY OF ANY KIND.
 * ZELIX PTY LTD MAKES NO WARRANTIES, EITHER EXPRESS OR IMPLIED, WITH
 * RESPECT TO THIS SOFTWARE INCLUDING BUT NOT LIMITED TO ANY WARRANTY
 * OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE.
 * ZELIX PTY LTD DOES NOT WARRANT THAT THE OPERATION OF THE SOFTWARE WILL
 * BE UNINTERRUPTED OR ERROR-FREE, OR THAT DEFECTS IN THE SOFTWARE WILL
 * BE CORRECTED.  YOU THE USER ARE SOLELY RESPONSIBLE FOR DETERMINING THE
 * APPROPRIATENESS OF THE SOFTWARE FOR YOUR USE AND ACCEPT FULL RESPONSIBILITY
 * FOR ALL RISKS ASSOCIATED WITH ITS USE.  ZELIX PTY LTD IS NOT AND WILL
 * NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR INCIDENTAL DAMAGES
 * (INCLUDING LOSS OF PROFITS OR INTERRUPTION OF BUSINESS) HOWEVER CAUSED
 * EVEN IF ZELIX PTY LTD HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 */

import org.apache.tools.ant.*;
import java.util.*;

public class ZKMTask extends Task {

   private static final String TRUE = "true";
   private static final String YES = "yes";
   private String scriptFileName;
   private String logFileName;
   private String trimLogFileName;
   private String defaultExcludeFileName;
   private String defaultTrimExcludeFileName;
   private String defaultDirectoryName;
   private boolean isVerbose = false;
   private boolean isParseOnly = false;

   /**
   * A ZKM Script file name must be specified.
   */
   public void setScriptFileName(String scriptFileName) {
      this.scriptFileName = scriptFileName;
   }

   /**
   * Set the log file name. The file name can be relative or absolute. This parameter is optional.
   * The log file name will default to "ZKM_log.txt".
   */
   public void setLogFileName(String logFileName) {
      this.logFileName = logFileName;
   }

   /**
   * Set the trim log file name. The file name can be relative or absolute. This parameter is optional.
   * The trim log file name will default to "ZKM_TrimLog.txt".
   */
   public void setTrimLogFileName(String trimLogFileName) {
      this.trimLogFileName = trimLogFileName;
   }

   /**
   * Set the 'default exclusions' file name. The file name can be relative or absolute. This parameter is optional.
   * The 'default exclusions' file name will default to "defaultExclude.txt".
   */
   public void setDefaultExcludeFileName(String defaultExcludeFileName) {
      this.defaultExcludeFileName = defaultExcludeFileName;
   }

   /**
   * Set the 'default trim exclusions' file name. The file name can be relative or absolute. This parameter is optional.
   * The 'default trim exclusions' file name will default to "defaultTrimExclude.txt".
   */
   public void setDefaultTrimExcludeFileName(String defaultTrimExcludeFileName) {
      this.defaultTrimExcludeFileName = defaultTrimExcludeFileName;
   }

   /**
   * Set the name of the default directory . The directory name can be relative or absolute.
   * If any of the log file, trim log file, 'default exclusion' file and the 'default trim exclusions' file names are relative then
   * they will be relative to this miscellaneous files directory. This parameter is optional.
   * The directory name will default to that of the current working directory.
   */
   public void setDefaultDirectoryName(String defaultDirectoryName) {
      this.defaultDirectoryName = defaultDirectoryName;
   }

   /**
   * Optional. Defaults to false.
   * @param isParseOnlyString Should be "true" or "false"
   */
   public void setIsVerbose(String isVerboseString) {
      if (isVerboseString != null) {
         if (isVerboseString.equalsIgnoreCase(TRUE) ||
             isVerboseString.equalsIgnoreCase(YES))
         {
            isVerbose = true;
         }
      }
   }

   /**
   * Optional. Defaults to false.
   * @param isParseOnlyString Should be "true" or "false"
   */
   public void setIsParseOnly(String isParseOnlyString) {
      if (isParseOnlyString != null) {
         if (isParseOnlyString.equalsIgnoreCase(TRUE) ||
             isParseOnlyString.equalsIgnoreCase(YES))
         {
            isParseOnly = true;
         }
      }
   }

   public void execute() throws BuildException {
      if (scriptFileName == null || scriptFileName.length() == 0) {
         throw new BuildException("Missing or empty ZKM Script file name");
      }
      if (sysproperties != null) {
         Properties systemProperties = System.getProperties();
         for (Iterator it=sysproperties.iterator(); it.hasNext(); ) {
            Sysproperty sysproperty = (Sysproperty)it.next();
            systemProperties.put(sysproperty.getKey(), sysproperty.getValue());
         }
      }

      try {
         com.zelix.ZKM.run(scriptFileName, logFileName, trimLogFileName, defaultExcludeFileName, defaultTrimExcludeFileName,
                           defaultDirectoryName, isVerbose, isParseOnly, project.getProperties());
      }
      catch(Exception ex) {
         ex.printStackTrace();
         throw new BuildException(ex.toString());
      }
   }

   ArrayList sysproperties = new ArrayList();

   public Sysproperty createSysproperty() {
      Sysproperty sysproperty = new Sysproperty();
      sysproperties.add(sysproperty);
      return sysproperty;
   }

   public class Sysproperty {
      private String key;
      private String value;

      public void setKey(String key) {
         this.key = key;
      }

      public String getKey() {
         return key;
      }

      public void setValue(String value) {
         this.value = value;
      }

      public String getValue() {
         return value;
      }
   }
}      
 
Documentation Table of Contents