Class OfflineInstrumenterBase
- java.lang.Object
-
- com.ibm.wala.shrike.shrikeBT.tools.OfflineInstrumenterBase
-
- Direct Known Subclasses:
OfflineInstrumenter
public abstract class OfflineInstrumenterBase extends java.lang.ObjectThis 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 interfaceOfflineInstrumenterBase.ManifestBuilderThiscallback is notified whenever an entry has been added to the output zip file.
-
Field Summary
Fields Modifier and Type Field Description protected ClassHierarchyProvidercha
-
Constructor Summary
Constructors Modifier Constructor Description protectedOfflineInstrumenterBase()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddInputClass(java.io.File baseDirectory, java.io.File f)Add a class file containing a source class to instrument.voidaddInputDirectory(java.io.File baseDirectory, java.io.File d)Add a directory containing class files to instrument.booleanaddInputElement(java.io.File baseDirectory, java.lang.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).voidaddInputJar(java.io.File f)Add a JAR file containing source classes to instrument.voidaddInputJarEntry(java.io.File f, java.lang.String name)Add a JAR entry containing a source class to instrument.java.io.OutputStreamaddOutputJarEntry(java.util.zip.ZipEntry ze)Add a raw ZipEntry to the output JAR.voidbeginTraversal()Start traversing the source class list from the beginning.voidclose()Call this when you're done modifying classes.static voidcopyStream(java.io.InputStream in, java.io.OutputStream out)voidendOutputJarEntry()Complete and flush the entry initiated by addOutputJarEntry.protected abstract java.lang.StringgetClassName(java.lang.Object cl)java.lang.StringgetLastClassResourceName()Get the name of the resource containing the last class returned.intgetNumInputClasses()java.io.FilegetOutputFile()Returns the File we are storing classes into.protected java.lang.ObjectinternalNextClass()protected booleaninternalOutputModifiedClass(java.lang.Object cf, java.lang.String name, java.lang.Object mods)protected abstract java.lang.ObjectmakeClassFromStream(java.lang.String inputName, java.io.BufferedInputStream s)java.lang.String[]parseStandardArgs(java.lang.String[] args)Parse an argument list to find elements to instrument and the name of the output file.voidsetClassHierarchyProvider(ClassHierarchyProvider cha)voidsetIgnore()Skip the last class returned in every future traversal of the class list.voidsetJARComment(java.lang.String comment)Set the JAR Comment for the output JAR.voidsetManifestBuilder(OfflineInstrumenterBase.ManifestBuilder mb)This installs a ManifestBuilder callback that this class will notify whenever an entry has been added to the output zip file.voidsetOutputJar(java.io.File f)Set the file in which instrumented classes will be deposited.voidsetPassUnmodifiedClasses(boolean pass)Indicate whether classes which are not modified will be put into the output jar anyway.protected abstract voidwriteClassTo(java.lang.Object cl, java.lang.Object mods, java.io.OutputStream s)voidwriteUnmodifiedClasses()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(java.io.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(java.io.File f) throws java.io.IOExceptionAdd a JAR file containing source classes to instrument.- Throws:
java.io.IOException
-
addInputJarEntry
public final void addInputJarEntry(java.io.File f, java.lang.String name)Add a JAR entry containing a source class to instrument.
-
addInputClass
public final void addInputClass(java.io.File baseDirectory, java.io.File f)Add a class file containing a source class to instrument.
-
addInputDirectory
public final void addInputDirectory(java.io.File baseDirectory, java.io.File d) throws java.io.IOException, java.lang.IllegalArgumentExceptionAdd a directory containing class files to instrument. All subdirectories are also scanned.- Throws:
java.lang.IllegalArgumentException- if d is nulljava.io.IOException
-
addInputElement
public final boolean addInputElement(java.io.File baseDirectory, java.lang.String a) throws java.io.IOExceptionAdd 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:
java.lang.IllegalArgumentException- if a is nulljava.io.IOException
-
parseStandardArgs
public final java.lang.String[] parseStandardArgs(java.lang.String[] args) throws java.lang.IllegalArgumentException, java.io.IOExceptionParse 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:
java.lang.IllegalArgumentException- if args == nulljava.io.IOException
-
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 java.lang.Object makeClassFromStream(java.lang.String inputName, java.io.BufferedInputStream s) throws java.io.IOException- Throws:
java.io.IOException
-
getClassName
protected abstract java.lang.String getClassName(java.lang.Object cl)
-
writeClassTo
protected abstract void writeClassTo(java.lang.Object cl, java.lang.Object mods, java.io.OutputStream s) throws java.io.IOException- Throws:
java.io.IOException
-
internalNextClass
protected final java.lang.Object internalNextClass() throws java.io.IOException- Throws:
java.io.IOException
-
getLastClassResourceName
public final java.lang.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 java.io.File getOutputFile()
Returns the File we are storing classes into.
-
internalOutputModifiedClass
protected final boolean internalOutputModifiedClass(java.lang.Object cf, java.lang.String name, java.lang.Object mods) throws java.io.IOException- Throws:
java.io.IOException
-
setJARComment
public final void setJARComment(java.lang.String comment) throws java.io.IOException, java.lang.IllegalStateExceptionSet the JAR Comment for the output JAR.- Throws:
java.io.IOExceptionjava.lang.IllegalStateException
-
setIgnore
public final void setIgnore() throws java.lang.IllegalArgumentExceptionSkip the last class returned in every future traversal of the class list.- Throws:
java.lang.IllegalArgumentException
-
copyStream
public static void copyStream(java.io.InputStream in, java.io.OutputStream out) throws java.lang.IllegalArgumentException, java.io.IOException- Throws:
java.lang.IllegalArgumentExceptionjava.io.IOException
-
addOutputJarEntry
public final java.io.OutputStream addOutputJarEntry(java.util.zip.ZipEntry ze) throws java.io.IOException, java.lang.IllegalStateExceptionAdd 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:
java.io.IOExceptionjava.lang.IllegalStateException
-
endOutputJarEntry
public final void endOutputJarEntry() throws java.io.IOException, java.lang.IllegalStateExceptionComplete and flush the entry initiated by addOutputJarEntry.- Throws:
java.io.IOExceptionjava.lang.IllegalStateException
-
writeUnmodifiedClasses
public final void writeUnmodifiedClasses() throws java.io.IOException, java.lang.IllegalStateExceptionCall 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:
java.io.IOExceptionjava.lang.IllegalStateException
-
close
public final void close() throws java.io.IOException, java.lang.IllegalStateExceptionCall this when you're done modifying classes.- Throws:
java.io.IOExceptionjava.lang.IllegalStateException
-
-