Class JrtfsCodeBase
- java.lang.Object
-
- edu.umd.cs.findbugs.classfile.impl.AbstractScannableCodeBase
-
- edu.umd.cs.findbugs.classfile.impl.JrtfsCodeBase
-
- All Implemented Interfaces:
ICodeBase,IScannableCodeBase,java.lang.AutoCloseable
public final class JrtfsCodeBase extends AbstractScannableCodeBase
Code base supporting Java 9 new jimage packed modules
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJrtfsCodeBase.JrtfsCodebaseEntryclassJrtfsCodeBase.JrtfsCodeBaseIterator-
Nested classes/interfaces inherited from interface edu.umd.cs.findbugs.classfile.ICodeBase
ICodeBase.Discovered
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringfileNameprivate java.nio.file.FileSystemfsprivate java.util.Map<java.lang.String,java.lang.Object>packageToModuleMapKey is package name in bytecode notation (e.g.private static intPRIMEprivate java.nio.file.Pathroot
-
Constructor Summary
Constructors Constructor Description JrtfsCodeBase(ICodeBaseLocator codeBaseLocator, @NonNull java.lang.String fileName)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()This method should be called when done using the code base.private @Nullable ICodeBaseEntrycreateEntry(java.lang.String resourceName, java.lang.String moduleName)java.util.Map<java.lang.String,java.lang.Object>createPackageToModuleMap(java.nio.file.FileSystem fs)booleanequals(java.lang.Object obj)(package private) static @NonNull java.lang.StringfileName(java.nio.file.Path p)private static java.lang.StringgetPackage(java.lang.String resourceName)java.lang.StringgetPathName()Get the filesystem pathname of this codebase.inthashCode()(package private) static booleanisClassFile(java.nio.file.Path p)ICodeBaseIteratoriterator()Get an iterator over the resources in the this code base.private static @Nullable java.nio.file.PathjavaHomeOf(java.lang.String jrtFsJar)Maps<javaHome>/lib/jrt-fs.jarback to<javaHome>.@Nullable ICodeBaseEntrylookupResource(java.lang.String resourceName)Look up a resource in this code base.private static java.nio.file.FileSystemopenJrtFileSystem(java.lang.String jrtFsJar)Opens the module image of the JDK the givenjrt-fs.jarbelongs to, which is not necessarily the JDK running SpotBugs.java.lang.StringtoString()-
Methods inherited from class edu.umd.cs.findbugs.classfile.impl.AbstractScannableCodeBase
addLastModifiedTime, addResourceNameTranslation, containsSourceFiles, getCodeBaseLocator, getHowDiscovered, getLastModifiedTime, isApplicationCodeBase, setApplicationCodeBase, setHowDiscovered, setLastModifiedTime, translateResourceName
-
-
-
-
Field Detail
-
PRIME
private static final int PRIME
- See Also:
- Constant Field Values
-
fs
private java.nio.file.FileSystem fs
-
fileName
private final java.lang.String fileName
-
root
private java.nio.file.Path root
-
packageToModuleMap
private java.util.Map<java.lang.String,java.lang.Object> packageToModuleMap
Key is package name in bytecode notation (e.g. 'java/lang').Values are either plain Strings for single-module packages, or sets of Strings for packages spread over multiple modules
-
-
Constructor Detail
-
JrtfsCodeBase
public JrtfsCodeBase(ICodeBaseLocator codeBaseLocator, @NonNull java.lang.String fileName) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
openJrtFileSystem
private static java.nio.file.FileSystem openJrtFileSystem(java.lang.String jrtFsJar) throws java.io.IOExceptionOpens the module image of the JDK the givenjrt-fs.jarbelongs to, which is not necessarily the JDK running SpotBugs.Selecting a foreign image requires the
java.homeenvironment entry used byjdk.internal.jrtfs.JrtFileSystemProvider. Without it, thejrtprovider installed in the running JVM answers the request with the running JVM's own image.Passing a class loader over the given
jrt-fs.jardoes not help: since Java 9,java.baseinstalls a provider for thejrtscheme, andFileSystems.newFileSystem(URI, Map, ClassLoader)falls back to the loader only when no installed provider matches the scheme.- Parameters:
jrtFsJar- path of ajrt-fs.jar, usually<javaHome>/lib/jrt-fs.jar- Returns:
- file system for the module image of that JDK, or of the running JVM if the jar is not in the layout expected by the provider
- Throws:
java.io.IOException
-
javaHomeOf
private static @Nullable java.nio.file.Path javaHomeOf(java.lang.String jrtFsJar)
Maps<javaHome>/lib/jrt-fs.jarback to<javaHome>.- Returns:
- the JDK home owning the given jar, or
nullif the jar is not in the layout expected by thejrtfile system provider
-
createPackageToModuleMap
public java.util.Map<java.lang.String,java.lang.Object> createPackageToModuleMap(java.nio.file.FileSystem fs) throws java.io.IOException- Throws:
java.io.IOException
-
lookupResource
public @Nullable ICodeBaseEntry lookupResource(java.lang.String resourceName)
Description copied from interface:ICodeBaseLook up a resource in this code base.- Parameters:
resourceName- name of the resource to look up- Returns:
- ICodeBaseEntry representing the resource or null if the resource cannot be found in this code base
-
createEntry
private @Nullable ICodeBaseEntry createEntry(java.lang.String resourceName, java.lang.String moduleName)
-
getPackage
private static java.lang.String getPackage(java.lang.String resourceName)
-
getPathName
public java.lang.String getPathName()
Description copied from interface:ICodeBaseGet the filesystem pathname of this codebase.- Returns:
- the filesystem pathname of this codebase, or null if this codebase is not accessible via the filesystem
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
close
public void close()
Description copied from interface:ICodeBaseThis method should be called when done using the code base.
-
iterator
public ICodeBaseIterator iterator() throws java.lang.InterruptedException
Description copied from interface:IScannableCodeBaseGet an iterator over the resources in the this code base.- Returns:
- ICodeBaseIterator over the resources in the code base
- Throws:
java.lang.InterruptedException
-
fileName
static @NonNull java.lang.String fileName(java.nio.file.Path p)
-
isClassFile
static boolean isClassFile(java.nio.file.Path p)
-
-