edu.rice.cs.cunit
Class FileInstrumentor

java.lang.Object
  extended by edu.rice.cs.cunit.FileInstrumentor
Direct Known Subclasses:
TCFileInstrumentor

public class FileInstrumentor
extends java.lang.Object

Author:
Mathias Ricken

Nested Class Summary
static class FileInstrumentor.Tool
          Class to perform the command line utility tasks.
 
Field Summary
protected static boolean _addAnnotationAttribute
          Add an instrumentation describing that this class has been instrumented?
protected static java.io.FileOutputStream _debugOut
          File output stream if output is to a file instead of to regular Debug.out.
protected static java.lang.String _defaultCunitRtJarName
          Default name of the Concutest jar file that gets mixed in when instrumenting the rt.jar.
protected static java.lang.String _defaultDestRtJarName
          Default name of the destination file when instrumenting the rt.jar.
protected static java.lang.String _defaultInstrumentorName
          Default instrumentor name.
protected static java.lang.String _defaultSystemInstrumentorName
          Default system instrumentor name..
protected static boolean _forceInstrumentation
          Force instrumentation even if the class has already been instrumented?
protected  java.util.ArrayList<IInstrumentationStrategy> _instrumentors
          List of instrumentors that should be applied to a class.
static java.lang.String INSTRUMENTOR_PACKAGE_PREFIX
          Package prefix of where instrumentors are usually located (includes the '.' at the end).
 
Constructor Summary
FileInstrumentor(IInstrumentationStrategy[] instrumentors)
          Creates a new instrumenting class loader using specified instrumentors.
 
Method Summary
static void addClassJarStream(java.lang.String inFileName, java.lang.String outFileName, java.util.jar.JarOutputStream jos, boolean markAsInstrumented)
          Add a class to a Jar stream.
 void addJarStream(java.lang.String inJarName, java.util.jar.JarOutputStream jos, boolean markAsInstrumented)
          Instrument all classes in the specified Jar file and write the output to a Jar stream.
 void done()
          Call done on all instrumentors.
static java.lang.String getDefaultCunitRtJarName()
           
static java.lang.String getDefaultDestRtJarName()
           
static java.lang.String getDefaultInstrumentorName()
           
static java.lang.String getDefaultSourceRtJarName()
           
static java.lang.String getDefaultSystemInstrumentorName()
           
 java.util.List<IInstrumentationStrategy> getInstrumentors()
          Returns a list of instrumentors.
private static boolean instrumentAndRename(java.lang.String classFileName, FileInstrumentor fi)
           
private static void instrumentAndRenameJar(java.lang.String jarFileName, FileInstrumentor fi)
           
 boolean instrumentFile(java.lang.String inName, java.lang.String outName)
          Instrument the class in the specified class file and write the output the another class file.
 void instrumentJar(java.lang.String inJarName, java.lang.String outJarName)
          Instrument all classes in the specified Jar file and write the output to another Jar file.
 void instrumentJarStream(java.lang.String inJarName, java.util.jar.JarOutputStream jos, java.util.List<java.lang.String> filters)
          Instrument all classes in the specified Jar file and write the output to a Jar stream.
private static void instrumentList(boolean createBackups, boolean recurse, FileInstrumentor fi, java.util.HashMap<java.lang.String,java.io.File> tempDirMap, ILambda.Binary<java.lang.Void,java.lang.String,java.io.IOException> exceptionAction, java.lang.String... names)
          Instrument a list of files.
private static void instrumentRTJar(java.lang.String sourceRtJarName, java.lang.String destRtJarName, java.lang.String cunitRtJarName, java.util.List<java.lang.String> cunitFilters, FileInstrumentor fi, FileInstrumentor fiSystem)
           
 boolean instrumentStream(java.io.InputStream is, java.io.OutputStream os)
          Instrument the class from the input stream and generate a class for the output stream.
static void main(java.lang.String[] args)
          Run the general file instrumentor.
static void setDefaultCunitRtJarName(java.lang.String defaultCunitRtJarName)
          Set the name of the CUnit mixin jar file.
static void setDefaultDestRtJarName(java.lang.String defaultDestRtJarName)
          Set the name of the default destination rt.jar file.
static void setDefaultInstrumentorName(java.lang.String defaultInstrumentorName)
          Set the name of the instrumentor.
static void setDefaultSystemInstrumentorName(java.lang.String defaultSystemInstrumentorName)
          Set the name of the system instrumentor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_instrumentors

protected java.util.ArrayList<IInstrumentationStrategy> _instrumentors
List of instrumentors that should be applied to a class.


INSTRUMENTOR_PACKAGE_PREFIX

public static final java.lang.String INSTRUMENTOR_PACKAGE_PREFIX
Package prefix of where instrumentors are usually located (includes the '.' at the end).

See Also:
Constant Field Values

_debugOut

protected static java.io.FileOutputStream _debugOut
File output stream if output is to a file instead of to regular Debug.out. Otherwise null.


_addAnnotationAttribute

protected static boolean _addAnnotationAttribute
Add an instrumentation describing that this class has been instrumented?


_forceInstrumentation

protected static boolean _forceInstrumentation
Force instrumentation even if the class has already been instrumented?


_defaultDestRtJarName

protected static java.lang.String _defaultDestRtJarName
Default name of the destination file when instrumenting the rt.jar.


_defaultCunitRtJarName

protected static java.lang.String _defaultCunitRtJarName
Default name of the Concutest jar file that gets mixed in when instrumenting the rt.jar.


_defaultInstrumentorName

protected static java.lang.String _defaultInstrumentorName
Default instrumentor name.


_defaultSystemInstrumentorName

protected static java.lang.String _defaultSystemInstrumentorName
Default system instrumentor name..

Constructor Detail

FileInstrumentor

public FileInstrumentor(IInstrumentationStrategy[] instrumentors)
Creates a new instrumenting class loader using specified instrumentors.

Parameters:
instrumentors - array of instrumentors
Method Detail

getInstrumentors

public java.util.List<IInstrumentationStrategy> getInstrumentors()
Returns a list of instrumentors.

Returns:
list of instrumentors

done

public void done()
Call done on all instrumentors.


instrumentStream

public boolean instrumentStream(java.io.InputStream is,
                                java.io.OutputStream os)
                         throws java.io.IOException,
                                java.lang.ClassFormatError
Instrument the class from the input stream and generate a class for the output stream.

Parameters:
is - input stream
os - output stream
Returns:
true if class was instrumented
Throws:
java.io.IOException
java.lang.ClassFormatError

instrumentFile

public boolean instrumentFile(java.lang.String inName,
                              java.lang.String outName)
                       throws java.io.IOException,
                              java.lang.ClassFormatError
Instrument the class in the specified class file and write the output the another class file.

Parameters:
inName - input file name
outName - output file name
Returns:
true if class was instrumented
Throws:
java.io.IOException
java.lang.ClassFormatError

instrumentJarStream

public void instrumentJarStream(java.lang.String inJarName,
                                java.util.jar.JarOutputStream jos,
                                java.util.List<java.lang.String> filters)
                         throws java.io.IOException,
                                java.lang.ClassFormatError
Instrument all classes in the specified Jar file and write the output to a Jar stream.

Parameters:
inJarName - name of the input Jar
jos - Jar output stream
filters - filters; if non-empty and no filter matches, file is skipped
Throws:
java.io.IOException
java.lang.ClassFormatError

instrumentJar

public void instrumentJar(java.lang.String inJarName,
                          java.lang.String outJarName)
                   throws java.io.IOException,
                          java.lang.ClassFormatError
Instrument all classes in the specified Jar file and write the output to another Jar file.

Parameters:
inJarName - name of the input Jar
outJarName - name of the output Jar
Throws:
java.io.IOException
java.lang.ClassFormatError

addClassJarStream

public static void addClassJarStream(java.lang.String inFileName,
                                     java.lang.String outFileName,
                                     java.util.jar.JarOutputStream jos,
                                     boolean markAsInstrumented)
                              throws java.io.IOException
Add a class to a Jar stream.

Parameters:
inFileName - file name of the class to add
outFileName - file name inside the Jar
jos - Jar output stream
markAsInstrumented - mark this class as instrumented
Throws:
java.io.IOException

addJarStream

public void addJarStream(java.lang.String inJarName,
                         java.util.jar.JarOutputStream jos,
                         boolean markAsInstrumented)
                  throws java.io.IOException,
                         java.lang.ClassFormatError
Instrument all classes in the specified Jar file and write the output to a Jar stream.

Parameters:
inJarName - name of the input Jar
jos - Jar output stream
markAsInstrumented - true if these classes should be marked as instrumented
Throws:
java.io.IOException
java.lang.ClassFormatError

getDefaultSystemInstrumentorName

public static java.lang.String getDefaultSystemInstrumentorName()
Returns:
the default name of the system instrumentor.

setDefaultSystemInstrumentorName

public static void setDefaultSystemInstrumentorName(java.lang.String defaultSystemInstrumentorName)
Set the name of the system instrumentor.

Parameters:
defaultSystemInstrumentorName - new name

getDefaultInstrumentorName

public static java.lang.String getDefaultInstrumentorName()
Returns:
the default name of the instrumentor.

setDefaultInstrumentorName

public static void setDefaultInstrumentorName(java.lang.String defaultInstrumentorName)
Set the name of the instrumentor.

Parameters:
defaultInstrumentorName - new name

getDefaultDestRtJarName

public static java.lang.String getDefaultDestRtJarName()
Returns:
the default name of the destination rt.jar file.

setDefaultDestRtJarName

public static void setDefaultDestRtJarName(java.lang.String defaultDestRtJarName)
Set the name of the default destination rt.jar file.

Parameters:
defaultDestRtJarName - new name

getDefaultCunitRtJarName

public static java.lang.String getDefaultCunitRtJarName()
Returns:
the default name of the cunit jar file.

setDefaultCunitRtJarName

public static void setDefaultCunitRtJarName(java.lang.String defaultCunitRtJarName)
Set the name of the CUnit mixin jar file.

Parameters:
defaultCunitRtJarName - new name

getDefaultSourceRtJarName

public static java.lang.String getDefaultSourceRtJarName()
Returns:
the default name of the rt.jar file.

instrumentList

private static void instrumentList(boolean createBackups,
                                   boolean recurse,
                                   FileInstrumentor fi,
                                   java.util.HashMap<java.lang.String,java.io.File> tempDirMap,
                                   ILambda.Binary<java.lang.Void,java.lang.String,java.io.IOException> exceptionAction,
                                   java.lang.String... names)
                            throws java.io.IOException
Instrument a list of files.

Parameters:
createBackups - true if backups should be created (unless in a temporary directory)
recurse - recurse into subdirectories
fi - TCFileInstrumentor to use
tempDirMap - map from jar file name to temporary directory
exceptionAction - action to execute if an IOException occurs; if null, IOExceptions will not be caught
names - array of file names
Throws:
java.io.IOException - IOException during instrumentation

instrumentAndRename

private static boolean instrumentAndRename(java.lang.String classFileName,
                                           FileInstrumentor fi)
                                    throws java.io.IOException
Throws:
java.io.IOException

instrumentAndRenameJar

private static void instrumentAndRenameJar(java.lang.String jarFileName,
                                           FileInstrumentor fi)
                                    throws java.io.IOException
Throws:
java.io.IOException

instrumentRTJar

private static void instrumentRTJar(java.lang.String sourceRtJarName,
                                    java.lang.String destRtJarName,
                                    java.lang.String cunitRtJarName,
                                    java.util.List<java.lang.String> cunitFilters,
                                    FileInstrumentor fi,
                                    FileInstrumentor fiSystem)
                             throws java.io.IOException
Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)
Run the general file instrumentor.

Parameters:
args - command line arguments.