Package org.eclipse.steady.java
Class JarAnalyzer
- java.lang.Object
-
- org.eclipse.steady.java.JarAnalyzer
-
- All Implemented Interfaces:
Callable<FileAnalyzer>,FileAnalyzer,JarEntryWriter
- Direct Known Subclasses:
AarAnalyzer,WarAnalyzer
@NotThreadSafe public class JarAnalyzer extends Object implements Callable<FileAnalyzer>, JarEntryWriter, FileAnalyzer
Analyzes a single Java archives as to identify (and potentially instrument) all its constructs.
-
-
Field Summary
Fields Modifier and Type Field Description protected intclassCountprotected Set<ConstructId>constructsprotected intenumCountprotected InstrumentationControlinstrControlprotected booleaninstrumentprotected intinterfaceCountprotected JarFilejarprotected JarWriterjarWriterprotected booleanrenameprotected Stringurlprotected PathworkDir
-
Constructor Summary
Constructors Constructor Description JarAnalyzer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidanalyze(File _file)FileAnalyzercall()This method is called byArchiveAnalysisManager.booleancanAnalyze(File _file)booleancontainsConstruct(ConstructId _id)protected voidcreateInstrumentedArchive()See here: http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.htmlbooleanequals(Object obj)static org.eclipse.steady.shared.json.model.ApplicationgetAppContext()getAppContext.Set<FileAnalyzer>getChilds(boolean _recursive)Set<String>getClassNames()Returns the class names for all class files found in the given archive.protected static javassist.ClassPoolgetClassPool()getClassPool.ConstructgetConstruct(ConstructId _id)Set<ConstructId>getConstructIds()Identifies allConstructIds of all methods and constructors.Map<ConstructId,Construct>getConstructs()StringgetFileName()getFileName.longgetFileSize()Returns the size of the original JAR file (before instrumentation).static StringgetFqClassname(String _jar_entry_name)Returns the fully-qualified Java class identifier for a given JAR entry.InputStreamgetInputStream(String _regex, JarEntry _entry)Callback used for rewriting particular JAR entries.InstrumentationControlgetInstrumentationControl()getInstrumentationControl.FilegetInstrumentedArchive()getInstrumentedArchive.longgetInstrumentedFileSize()Returns the size of the instrumented JAR file (or -1 if no instrumentation took place).org.eclipse.steady.shared.json.model.LibrarygetLibrary()Returns aLibraryrepresenting the analyzed Java archive.JarAnalyzergetParent()Getter for the fieldparent.PathgetPath()getPath.StringgetSHA1()Returns the SHA1 digest of the JAR.List<org.eclipse.steady.shared.json.model.ConstructId>getSharedConstructs()getSharedConstructs.String[]getSupportedFileExtensions()booleanhasChilds()inthashCode()booleanhasJARConstructs()hasJARConstructs.static voidinsertClasspath(String _url)Adds a given URL to the classpath of the class pool.static booleanisJavaIdentifier(String _name)isJavaIdentifier.static voidsetAppContext(org.eclipse.steady.shared.json.model.Application _ctx)setAppContext.voidsetInstrument(boolean _instrument)Setter for the fieldinstrument.voidsetLibraryId(org.eclipse.steady.shared.json.model.LibraryId _id)Sets the Maven Id for the JAR to be analyzed.voidsetParent(JarAnalyzer ja)Setter for the fieldparent.voidsetRename(boolean _b)Determines whether the instrumented JAR is renamed or not.voidsetWorkDir(Path _p)Specifies the work directory into which instrumented JARs are written.StringtoString()toString.
-
-
-
Field Detail
-
constructs
protected Set<ConstructId> constructs
-
url
protected String url
-
jar
protected JarFile jar
-
instrument
protected boolean instrument
-
rename
protected boolean rename
-
classCount
protected int classCount
-
enumCount
protected int enumCount
-
interfaceCount
protected int interfaceCount
-
workDir
protected Path workDir
-
jarWriter
protected JarWriter jarWriter
-
instrControl
protected InstrumentationControl instrControl
-
-
Method Detail
-
getSupportedFileExtensions
public String[] getSupportedFileExtensions()
- Specified by:
getSupportedFileExtensionsin interfaceFileAnalyzer
-
canAnalyze
public final boolean canAnalyze(File _file)
- Specified by:
canAnalyzein interfaceFileAnalyzer
-
analyze
public void analyze(File _file) throws FileAnalysisException
- Specified by:
analyzein interfaceFileAnalyzer- Throws:
FileAnalysisException
-
setInstrument
public void setInstrument(boolean _instrument)
Setter for the field
instrument.- Parameters:
_instrument- a boolean.
-
setParent
public void setParent(JarAnalyzer ja)
Setter for the field
parent.- Parameters:
ja- aJarAnalyzerobject.
-
getParent
public JarAnalyzer getParent()
Getter for the field
parent.- Returns:
- a
JarAnalyzerobject.
-
getFileSize
public long getFileSize()
Returns the size of the original JAR file (before instrumentation).- Returns:
- a long.
- See Also:
getInstrumentedFileSize()
-
getInstrumentedFileSize
public long getInstrumentedFileSize()
Returns the size of the instrumented JAR file (or -1 if no instrumentation took place).- Returns:
- a long.
- See Also:
getFileSize()
-
setWorkDir
public void setWorkDir(Path _p)
Specifies the work directory into which instrumented JARs are written. If null, a temporary directory will be created.- Parameters:
_p- aPathobject.
-
setRename
public void setRename(boolean _b)
Determines whether the instrumented JAR is renamed or not. If yes, the new file name follows the following format: - If app context is provided: [originalJarName]-vulas-[appGroupId]-[appArtifactId]-[appVersion].jar - Otherwise: [originalJarName]-vulas-instr.jar- Parameters:
_b- a boolean.
-
setLibraryId
public void setLibraryId(org.eclipse.steady.shared.json.model.LibraryId _id)
Sets the Maven Id for the JAR to be analyzed. The Maven ID is already known in some contexts (e.g., during Maven plugin execution).- Parameters:
_id- aLibraryIdobject.
-
getLibrary
public org.eclipse.steady.shared.json.model.Library getLibrary() throws FileAnalysisExceptionReturns aLibraryrepresenting the analyzed Java archive.- Returns:
- a
Libraryobject. - Throws:
FileAnalysisException
-
getSHA1
public String getSHA1()
Returns the SHA1 digest of the JAR. Either taken from the manifest (entry VULAS-originalSHA1, in case the original JAR has been instrumented offline), or by computing it on the fly.- Returns:
- the SHA1 digest of the JAR
-
call
public FileAnalyzer call()
This method is called byArchiveAnalysisManager.- Specified by:
callin interfaceCallable<FileAnalyzer>- Returns:
- a
FileAnalyzerobject.
-
createInstrumentedArchive
protected void createInstrumentedArchive() throws JarAnalysisExceptionSee here: http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html- Throws:
JarAnalysisException
-
getInstrumentedArchive
public final File getInstrumentedArchive()
getInstrumentedArchive.
- Returns:
- a
Fileobject.
-
getClassNames
public Set<String> getClassNames()
Returns the class names for all class files found in the given archive.- Returns:
- a
Setobject.
-
hasJARConstructs
public boolean hasJARConstructs()
hasJARConstructs.
- Returns:
- a boolean.
-
hasChilds
public boolean hasChilds()
- Specified by:
hasChildsin interfaceFileAnalyzer
-
getChilds
public Set<FileAnalyzer> getChilds(boolean _recursive)
- Specified by:
getChildsin interfaceFileAnalyzer
-
getConstructIds
public Set<ConstructId> getConstructIds()
Identifies allConstructIds of all methods and constructors.- Returns:
- a
Setobject.
-
toString
public String toString()
toString.
-
getInstrumentationControl
public InstrumentationControl getInstrumentationControl()
getInstrumentationControl.
- Returns:
- a
InstrumentationControlobject.
-
getInputStream
public InputStream getInputStream(String _regex, JarEntry _entry)
Callback used for rewriting particular JAR entries. Return null to rewrite the original JAR entry. In case the archive is rewritten, this method is used to rewrite certainJarEntrys (rather than taking the file from the original archive). The callback registration takes place increateInstrumentedArchive().- Specified by:
getInputStreamin interfaceJarEntryWriter- Parameters:
_regex- aStringobject._entry- aJarEntryobject.- Returns:
- a
InputStreamobject.
-
getConstructs
public Map<ConstructId,Construct> getConstructs() throws FileAnalysisException
- Specified by:
getConstructsin interfaceFileAnalyzer- Throws:
FileAnalysisException
-
getSharedConstructs
public List<org.eclipse.steady.shared.json.model.ConstructId> getSharedConstructs() throws FileAnalysisException
getSharedConstructs.
- Returns:
- a
Listobject. - Throws:
FileAnalysisException- if any.
-
containsConstruct
public boolean containsConstruct(ConstructId _id) throws FileAnalysisException
- Specified by:
containsConstructin interfaceFileAnalyzer- Throws:
FileAnalysisException
-
getConstruct
public Construct getConstruct(ConstructId _id) throws FileAnalysisException
- Specified by:
getConstructin interfaceFileAnalyzer- Throws:
FileAnalysisException
-
equals
public boolean equals(Object obj)
- Specified by:
equalsin interfaceFileAnalyzer- Overrides:
equalsin classObject
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceFileAnalyzer- Overrides:
hashCodein classObject
-
isJavaIdentifier
public static boolean isJavaIdentifier(String _name)
isJavaIdentifier.
- Parameters:
_name- aStringobject.- Returns:
- a boolean.
-
getFqClassname
public static String getFqClassname(String _jar_entry_name)
Returns the fully-qualified Java class identifier for a given JAR entry. This is done by removing the file extension and by interpreting folders as packages. If anything goes wrong, null is returned.
-
setAppContext
public static void setAppContext(org.eclipse.steady.shared.json.model.Application _ctx)
setAppContext.
- Parameters:
_ctx- aApplicationobject.
-
getAppContext
public static org.eclipse.steady.shared.json.model.Application getAppContext()
getAppContext.
- Returns:
- a
Applicationobject.
-
insertClasspath
public static void insertClasspath(String _url) throws javassist.NotFoundException
Adds a given URL to the classpath of the class pool. This allows maintaining dependencies needed for the compilation of instrumented classes.- Parameters:
_url- aStringobject.- Throws:
javassist.NotFoundException
-
getClassPool
protected static javassist.ClassPool getClassPool()
getClassPool.
- Returns:
- a
ClassPoolobject.
-
-