Package org.apache.maven.shared.jar
Class JarAnalyzer
- java.lang.Object
-
- org.apache.maven.shared.jar.JarAnalyzer
-
public class JarAnalyzer extends java.lang.Object
Open a JAR file to be analyzed. Note that once created, thecloseQuietly()
method should be called to release the associated file handle. Typical usage:JarAnalyzer jar = new JarAnalyzer( jarFile ); try { // do some analysis, such as: jarClasses = jarClassAnalyzer.analyze( jar ); } finally { jar.closeQuietly(); } // use jar.getJarData() in some way, or the data returned by the JAR analyzer. jar itself can no longer be used.
Note: that the actual data is separated from this class by design to minimise the chance of forgetting to close the JAR file. TheJarData
class exposed, as well as any data returned by actual analyzers that use this class, can be used safely once this class is out of scope.
-
-
Constructor Summary
Constructors Constructor Description JarAnalyzer(java.io.File file)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
closeQuietly()
Close the associated JAR file, ignoring any errors that may occur.java.util.List
filterEntries(java.util.regex.Pattern pattern)
Filter a list of JAR entries against the pattern.java.util.List
getClassEntries()
Get all the classes in the JAR.java.util.List
getEntries()
Get all the contained files in the JAR.java.io.InputStream
getEntryInputStream(java.util.jar.JarEntry entry)
Get the data for an individual entry in the JAR.java.io.File
getFile()
Get the file that was opened by this analyzer.JarData
getJarData()
java.util.List
getMavenPomEntries()
Get all the Maven POM entries in the JAR.java.util.List
getVersionEntries()
Get all the version text files in the JAR.
-
-
-
Constructor Detail
-
JarAnalyzer
public JarAnalyzer(java.io.File file) throws java.io.IOException
Constructor. Opens the JAR file, so should be matched by a call tocloseQuietly()
.- Parameters:
file
- the JAR file to open- Throws:
java.io.IOException
- if there is a problem opening the JAR file, or reading the manifest. The JAR file will be closed if this occurs.
-
-
Method Detail
-
getEntryInputStream
public java.io.InputStream getEntryInputStream(java.util.jar.JarEntry entry) throws java.io.IOException
Get the data for an individual entry in the JAR. The caller should closeQuietly the input stream, and should not retain the stream as the JAR file may be closed elsewhere.- Parameters:
entry
- the JAR entry to read from- Returns:
- the input stream of the individual JAR entry.
- Throws:
java.io.IOException
- if there is a problem opening the individual entry
-
closeQuietly
public void closeQuietly()
Close the associated JAR file, ignoring any errors that may occur.
-
filterEntries
public java.util.List filterEntries(java.util.regex.Pattern pattern)
Filter a list of JAR entries against the pattern.- Parameters:
pattern
- the pattern to filter against- Returns:
- the list of files found, in
JarEntry
elements
-
getClassEntries
public java.util.List getClassEntries()
Get all the classes in the JAR.- Returns:
- the list of files found, in
JarEntry
elements
-
getMavenPomEntries
public java.util.List getMavenPomEntries()
Get all the Maven POM entries in the JAR.- Returns:
- the list of files found, in
JarEntry
elements
-
getVersionEntries
public java.util.List getVersionEntries()
Get all the version text files in the JAR.- Returns:
- the list of files found, in
JarEntry
elements
-
getEntries
public java.util.List getEntries()
Get all the contained files in the JAR.- Returns:
- the list of files found, in
JarEntry
elements
-
getFile
public java.io.File getFile()
Get the file that was opened by this analyzer.- Returns:
- the JAR file reference
-
getJarData
public JarData getJarData()
-
-