Class CUtil

java.lang.Object
net.sf.antcontrib.cpptasks.CUtil

public class CUtil extends Object
Some utilities used by the CC and Link tasks.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    A class that splits a white-space, comma-separated list into a String array.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addAll(Vector dest, Object[] src)
    Adds the elements of the array to the given vector
    static int
    Checks a array of names for non existent or non directory entries and nulls them out.
    static String
    Extracts the basename of a file, removing the extension, if present
    static File
    Gets the parent directory for the executable file name using the current directory and system executable path
    static String
    Extracts the parent of a file
    static File[]
    getPathFromEnvironment(String envVariable, String delim)
    Returns an array of File for each existing directory in the specified environment variable
    static String
    getRelativePath(String base, File targetFile)
    Returns a relative path for the targetFile relative to the base directory.
    static boolean
    isActive(org.apache.tools.ant.Project p, String ifCond, String unlessCond)
     
    static boolean
    isSignificantlyAfter(long time1, long time2)
    Determines whether time1 is later than time2 to a degree that file system time truncation is not significant.
    static boolean
    isSignificantlyBefore(long time1, long time2)
    Determines whether time1 is earlier than time2 to a degree that file system time truncation is not significant.
    static boolean
    Determines if source file has a system path, that is part of the compiler or platform.
    static File[]
    parsePath(String path, String delim)
    Parse a string containing directories into an File[]
    static int
    runCommand(CCTask task, File workingDir, String[] cmdline, boolean newEnvironment, org.apache.tools.ant.types.Environment env)
    This method is exposed so test classes can overload and test the arguments without actually spawning the compiler
    static boolean
    sameList(Object[] a, Object[] b)
    Compares the contents of 2 arrays for equaliy.
    static boolean
    Compares the contents of an array and a Vector for equality.
    static boolean
    Compares the contents of an array and a Vector for set equality.
    static String[]
    Converts a vector to a string array.
    static String
     
    static String
     
    static String
    Replaces any embedded quotes in the string so that the value can be placed in an attribute in an XML file

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • CUtil

      public CUtil()
  • Method Details

    • addAll

      public static void addAll(Vector dest, Object[] src)
      Adds the elements of the array to the given vector
    • checkDirectoryArray

      public static int checkDirectoryArray(String[] names)
      Checks a array of names for non existent or non directory entries and nulls them out.
      Returns:
      Count of non-null elements
    • getBasename

      public static String getBasename(File file)
      Extracts the basename of a file, removing the extension, if present
    • getExecutableLocation

      public static File getExecutableLocation(String exeName)
      Gets the parent directory for the executable file name using the current directory and system executable path
      Parameters:
      exeName - Name of executable such as "cl.exe"
      Returns:
      parent directory or null if not located
    • getParentPath

      public static String getParentPath(String path)
      Extracts the parent of a file
    • getPathFromEnvironment

      public static File[] getPathFromEnvironment(String envVariable, String delim)
      Returns an array of File for each existing directory in the specified environment variable
      Parameters:
      envVariable - environment variable name such as "LIB" or "INCLUDE"
      delim - delimitor used to separate parts of the path, typically ";" or ":"
      Returns:
      array of File's for each part that is an existing directory
    • getRelativePath

      public static String getRelativePath(String base, File targetFile)
      Returns a relative path for the targetFile relative to the base directory.
      Parameters:
      base - base directory as returned by File.getCanonicalPath()
      targetFile - target file
      Returns:
      relative path of target file. Returns targetFile if there were no commonalities between the base and the target
    • isActive

      public static boolean isActive(org.apache.tools.ant.Project p, String ifCond, String unlessCond) throws org.apache.tools.ant.BuildException
      Throws:
      org.apache.tools.ant.BuildException
    • parsePath

      public static File[] parsePath(String path, String delim)
      Parse a string containing directories into an File[]
      Parameters:
      path - path string, for example ".;c:\something\include"
      delim - delimiter, typically ; or :
    • runCommand

      public static int runCommand(CCTask task, File workingDir, String[] cmdline, boolean newEnvironment, org.apache.tools.ant.types.Environment env) throws org.apache.tools.ant.BuildException
      This method is exposed so test classes can overload and test the arguments without actually spawning the compiler
      Throws:
      org.apache.tools.ant.BuildException
    • sameList

      public static boolean sameList(Object[] a, Object[] b)
      Compares the contents of 2 arrays for equaliy.
    • sameList

      public static boolean sameList(Vector v, Object[] a)
      Compares the contents of an array and a Vector for equality.
    • sameSet

      public static boolean sameSet(Object[] a, Vector b)
      Compares the contents of an array and a Vector for set equality. Assumes input array and vector are sets (i.e. no duplicate entries)
    • toArray

      public static String[] toArray(Vector src)
      Converts a vector to a string array.
    • xmlAttribEncode

      public static String xmlAttribEncode(String attrValue)
      Replaces any embedded quotes in the string so that the value can be placed in an attribute in an XML file
      Parameters:
      attrValue - value to be expressed
      Returns:
      equivalent attribute literal
    • isSignificantlyBefore

      public static boolean isSignificantlyBefore(long time1, long time2)
      Determines whether time1 is earlier than time2 to a degree that file system time truncation is not significant.
      Parameters:
      time1 - long first time value
      time2 - long second time value
      Returns:
      boolean if first time value is earlier than second time value. If the values are within the rounding error of the file system return false.
    • isSignificantlyAfter

      public static boolean isSignificantlyAfter(long time1, long time2)
      Determines whether time1 is later than time2 to a degree that file system time truncation is not significant.
      Parameters:
      time1 - long first time value
      time2 - long second time value
      Returns:
      boolean if first time value is later than second time value. If the values are within the rounding error of the file system return false.
    • toWindowsPath

      public static String toWindowsPath(String path)
    • toUnixPath

      public static String toUnixPath(String path)
    • isSystemPath

      public static boolean isSystemPath(File source)
      Determines if source file has a system path, that is part of the compiler or platform.
      Parameters:
      source - source, may not be null.
      Returns:
      true is source file appears to be system library and its path should be discarded.