Package com.ibm.wala.shrikeBT.tools
Class OfflineInstrumenterBase
- java.lang.Object
-
- com.ibm.wala.shrikeBT.tools.OfflineInstrumenterBase
-
- Direct Known Subclasses:
OfflineInstrumenter
public abstract class OfflineInstrumenterBase extends Object
This class provides functionality for performing offline instrumentation. It is subclassed with class-toolkit-specific functionality.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
OfflineInstrumenterBase.ManifestBuilder
Thiscallback is notified whenever an entry has been added to the output zip file.
-
Field Summary
Fields Modifier and Type Field Description protected ClassHierarchyProvider
cha
-
Constructor Summary
Constructors Modifier Constructor Description protected
OfflineInstrumenterBase()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addInputClass(File baseDirectory, File f)
Add a class file containing a source class to instrument.void
addInputDirectory(File baseDirectory, File d)
Add a directory containing class files to instrument.boolean
addInputElement(File baseDirectory, String a)
Add something to instrument --- the name of a JAR file, a class file, a directory or an entry within a jar file (as filename#entryname).void
addInputJar(File f)
Add a JAR file containing source classes to instrument.void
addInputJarEntry(File f, String name)
Add a JAR entry containing a source class to instrument.OutputStream
addOutputJarEntry(ZipEntry ze)
Add a raw ZipEntry to the output JAR.void
beginTraversal()
Start traversing the source class list from the beginning.void
close()
Call this when you're done modifying classes.static void
copyStream(InputStream in, OutputStream out)
void
endOutputJarEntry()
Complete and flush the entry initiated by addOutputJarEntry.protected abstract String
getClassName(Object cl)
String
getLastClassResourceName()
Get the name of the resource containing the last class returned.int
getNumInputClasses()
File
getOutputFile()
Returns the File we are storing classes into.protected Object
internalNextClass()
protected boolean
internalOutputModifiedClass(Object cf, String name, Object mods)
protected abstract Object
makeClassFromStream(String inputName, BufferedInputStream s)
String[]
parseStandardArgs(String[] args)
Parse an argument list to find elements to instrument and the name of the output file.void
setClassHierarchyProvider(ClassHierarchyProvider cha)
void
setIgnore(boolean ignore)
Skip the last class returned in every future traversal of the class list.void
setJARComment(String comment)
Set the JAR Comment for the output JAR.void
setManifestBuilder(OfflineInstrumenterBase.ManifestBuilder mb)
This installs a ManifestBuilder callback that this class will notify whenever an entry has been added to the output zip file.void
setOutputJar(File f)
Set the file in which instrumented classes will be deposited.void
setPassUnmodifiedClasses(boolean pass)
Indicate whether classes which are not modified will be put into the output jar anyway.protected abstract void
writeClassTo(Object cl, Object mods, OutputStream s)
void
writeUnmodifiedClasses()
Call this to copy any unmodified classes to the output.
-
-
-
Field Detail
-
cha
protected ClassHierarchyProvider cha
-
-
Method Detail
-
setManifestBuilder
public void setManifestBuilder(OfflineInstrumenterBase.ManifestBuilder mb)
This installs a ManifestBuilder callback that this class will notify whenever an entry has been added to the output zip file.
-
setClassHierarchyProvider
public void setClassHierarchyProvider(ClassHierarchyProvider cha)
-
setOutputJar
public final void setOutputJar(File f)
Set the file in which instrumented classes will be deposited.
-
setPassUnmodifiedClasses
public final void setPassUnmodifiedClasses(boolean pass)
Indicate whether classes which are not modified will be put into the output jar anyway.
-
addInputJar
public final void addInputJar(File f) throws IOException
Add a JAR file containing source classes to instrument.- Throws:
IOException
-
addInputJarEntry
public final void addInputJarEntry(File f, String name) throws IOException
Add a JAR entry containing a source class to instrument.- Throws:
IOException
-
addInputClass
public final void addInputClass(File baseDirectory, File f)
Add a class file containing a source class to instrument.
-
addInputDirectory
public final void addInputDirectory(File baseDirectory, File d) throws IOException, IllegalArgumentException
Add a directory containing class files to instrument. All subdirectories are also scanned.- Throws:
IllegalArgumentException
- if d is nullIOException
-
addInputElement
public final boolean addInputElement(File baseDirectory, String a) throws IOException
Add something to instrument --- the name of a JAR file, a class file, a directory or an entry within a jar file (as filename#entryname). If we can't identify it, nothing is added and we return false.- Throws:
IllegalArgumentException
- if a is nullIOException
-
parseStandardArgs
public final String[] parseStandardArgs(String[] args) throws IllegalArgumentException, IOException
Parse an argument list to find elements to instrument and the name of the output file. The "-o filename" option selects the output JAR file name. Any other argument not starting with "-" is added to the list of elements to instrument, if it appears to be the name of a class file, JAR file, or directory. If any argument starting with "--" is encountered, the rest of the command-line is considered leftover- Returns:
- the arguments that were not understood
- Throws:
IllegalArgumentException
- if args == nullIOException
-
getNumInputClasses
public final int getNumInputClasses()
- Returns:
- the number of source classes to be instrumented
-
beginTraversal
public final void beginTraversal()
Start traversing the source class list from the beginning.
-
makeClassFromStream
protected abstract Object makeClassFromStream(String inputName, BufferedInputStream s) throws IOException
- Throws:
IOException
-
writeClassTo
protected abstract void writeClassTo(Object cl, Object mods, OutputStream s) throws IOException
- Throws:
IOException
-
internalNextClass
protected final Object internalNextClass() throws IOException
- Throws:
IOException
-
getLastClassResourceName
public final String getLastClassResourceName()
Get the name of the resource containing the last class returned. This is either a file name (e.g., "com/ibm/Main.class"), or a JAR entry name (e.g., "apps/app.jar#com/ibm/Main.class").- Returns:
- the resource name, or null if no class has been returned yet
-
getOutputFile
public final File getOutputFile()
Returns the File we are storing classes into.
-
internalOutputModifiedClass
protected final boolean internalOutputModifiedClass(Object cf, String name, Object mods) throws IOException
- Throws:
IOException
-
setJARComment
public final void setJARComment(String comment) throws IOException, IllegalStateException
Set the JAR Comment for the output JAR.- Throws:
IOException
IllegalStateException
-
setIgnore
public final void setIgnore(boolean ignore) throws IllegalArgumentException
Skip the last class returned in every future traversal of the class list.- Throws:
IllegalArgumentException
-
copyStream
public static void copyStream(InputStream in, OutputStream out) throws IllegalArgumentException, IOException
- Throws:
IllegalArgumentException
IOException
-
addOutputJarEntry
public final OutputStream addOutputJarEntry(ZipEntry ze) throws IOException, IllegalStateException
Add a raw ZipEntry to the output JAR. Call endOutputJarEntry() when you're done.- Returns:
- the OutputStream to be used to write the entry contents
- Throws:
IOException
IllegalStateException
-
endOutputJarEntry
public final void endOutputJarEntry() throws IOException, IllegalStateException
Complete and flush the entry initiated by addOutputJarEntry.- Throws:
IOException
IllegalStateException
-
writeUnmodifiedClasses
public final void writeUnmodifiedClasses() throws IOException, IllegalStateException
Call this to copy any unmodified classes to the output. This is called automatically by close(); you should only call this if you want to write an entry to the JAR file *after* the unmodified classes. This will only ever be called once per output JAR.- Throws:
IOException
IllegalStateException
-
close
public final void close() throws IOException, IllegalStateException
Call this when you're done modifying classes.- Throws:
IOException
IllegalStateException
-
-