org.schmant.support
Class SchmantUtil

java.lang.Object
  extended by org.schmant.support.SchmantUtil

public final class SchmantUtil
extends Object

This class contains static utility methods for Schmant scripts and tasks. Its initial state is created by the Launcher class when Schmant starts.

Since:
0.5
Author:
Karl Gustafsson

Method Summary
static void debugLogContents(File f, Report r)
          Debug log the contents of a file
static File getCommandFromPath(String cmd)
          Get a command from the PATH environment variable.
static File getCommandFromPath(String cmd, String... extensions)
          Get a command from the PATH environment variable.
static File getCommandFromPathOrNull(String cmd, String... extensions)
          Get a command from the PATH environment variable, returning null if the command was not found.
static String getPathString(Collection<?> components)
          Build a path string with the entries separated by the platform's path separator (File.pathSeparator).
static String getPathString(Collection<String> components, char separator)
          Build a path string, i.e.
static File getRelativeToScriptDirectory(File f)
          Get absolute file created by appending the supplied file to the directory of the launched script.
static File getSchmantHome()
          Get the location of the Schmant installation that is currently running.
static NamedReadableFile getScriptEFile()
          Get the currently executing script file.
static File getScriptFile()
          Get a reference to the currently executing script file as a File object.
static TwoObjects<File,Deque<NamedReadableFile>> init(File schmantHome)
          This method is called by the Launcher object that launches the Schmant script.
static NamedReadableFile popScriptFile()
          This is called by Schmant methods after executing an included script.
static void pushScriptFile(NamedReadableFile f)
          This is called by Schmant methods when the application starts or when including another script file.
static void tearDown(TwoObjects<File,Deque<NamedReadableFile>> prevContents)
          This method is called by the Launcher to tear down the data associated with this object when the Schmant program exits.
static String trimQuotes(String s)
          If s is enclosed in quotes (":s), remove them.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

init

public static TwoObjects<File,Deque<NamedReadableFile>> init(File schmantHome)
This method is called by the Launcher object that launches the Schmant script. Scripts don't have to call it.

Parameters:
schmantHome - The location of the Schmant installation that is currently running.
Returns:
An object containing the previous contents of this class. This is returned by Launcher when it calls tearDown(TwoObjects).
See Also:
tearDown(TwoObjects)

tearDown

public static void tearDown(TwoObjects<File,Deque<NamedReadableFile>> prevContents)
This method is called by the Launcher to tear down the data associated with this object when the Schmant program exits.

Parameters:
prevContents - The previous contents of this object, if any. This should be the object returned by init(File).
See Also:
init(File)

trimQuotes

public static String trimQuotes(String s)
If s is enclosed in quotes (":s), remove them.

Parameters:
s - The string to remove quotes from.
Returns:
s without enclosing quotes.

debugLogContents

public static void debugLogContents(File f,
                                    Report r)
Debug log the contents of a file

Parameters:
f - The file.
r - The Report to log to.

getCommandFromPathOrNull

public static File getCommandFromPathOrNull(String cmd,
                                            String... extensions)
Get a command from the PATH environment variable, returning null if the command was not found. The command can have one of a set of permitted file name extensions.

Tip: The org.entityfs.support.io.OsPlatform class can be used to check if the program is running on Windows or not.

Parameters:
cmd - The command, e.g. findbugs.
extensions - The list of file name extensions that the command may have, for instance "", "exe".
Returns:
A File built on the absolute path to the command, or null if the command was not found in the path.

getCommandFromPath

public static File getCommandFromPath(String cmd,
                                      String... extensions)
                               throws EntityNotFoundException
Get a command from the PATH environment variable. The command can have one of a set of permitted file name extensions.

Tip: The org.entityfs.support.io.OsPlatform class can be used to check if the program is running on Windows or not.

Parameters:
cmd - The command, e.g. findbugs.
extensions - The list of file name extensions that the command may have, for instance "", "exe".
Returns:
A File built on the absolute path to the command.
Throws:
EntityNotFoundException - If the command was not found on the PATH.

getCommandFromPath

public static File getCommandFromPath(String cmd)
                               throws EntityNotFoundException
Get a command from the PATH environment variable. The command cannot have any other file name extensions than the extension set in the cmd parameter.

Parameters:
cmd - The command, e.g. findbugs
Returns:
A File built on the absolute path to the command.
Throws:
EntityNotFoundException - If the command was not found on the PATH.

getPathString

public static String getPathString(Collection<String> components,
                                   char separator)
Build a path string, i.e. a string containing all the strings in the provided collection separated by the separator.

Parameters:
components - The strings
separator - The separator character.
Returns:
A path string.

getPathString

public static String getPathString(Collection<?> components)
Build a path string with the entries separated by the platform's path separator (File.pathSeparator).

Parameters:
components - A collection of objects. Each object is interpreted by InterpretAsFileStrategy.
Returns:
A path string.

pushScriptFile

public static void pushScriptFile(NamedReadableFile f)
This is called by Schmant methods when the application starts or when including another script file. Scripts don't need this.


popScriptFile

public static NamedReadableFile popScriptFile()
This is called by Schmant methods after executing an included script. Scripts don't need this.


getScriptFile

public static File getScriptFile()
Get a reference to the currently executing script file as a File object. If the script file is not File-backed, such as when it is in a Zip file, this method returns null.

Returns:
A reference to the currently executing script file, or null if the script file is not File-backed. (ECFileResolvable)
See Also:
getScriptEFile()

getScriptEFile

public static NamedReadableFile getScriptEFile()
Get the currently executing script file.

Returns:
The currently executing script file (read only).
Since:
0.9.1

getSchmantHome

public static File getSchmantHome()
Get the location of the Schmant installation that is currently running.

Returns:
The location of the Schmant installation.
Since:
0.8

getRelativeToScriptDirectory

public static File getRelativeToScriptDirectory(File f)
                                         throws IllegalArgumentException
Get absolute file created by appending the supplied file to the directory of the launched script.

Parameters:
f - The relative file
Returns:
The absolute file.
Throws:
IllegalArgumentException - If the file is not a relative location.
Since:
0.9