Class JrtfsCodeBase

    • Field Detail

      • 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.IOException
        Opens the module image of the JDK the given jrt-fs.jar belongs to, which is not necessarily the JDK running SpotBugs.

        Selecting a foreign image requires the java.home environment entry used by jdk.internal.jrtfs.JrtFileSystemProvider. Without it, the jrt provider installed in the running JVM answers the request with the running JVM's own image.

        Passing a class loader over the given jrt-fs.jar does not help: since Java 9, java.base installs a provider for the jrt scheme, and FileSystems.newFileSystem(URI, Map, ClassLoader) falls back to the loader only when no installed provider matches the scheme.

        Parameters:
        jrtFsJar - path of a jrt-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.jar back to <javaHome>.
        Returns:
        the JDK home owning the given jar, or null if the jar is not in the layout expected by the jrt file 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: ICodeBase
        Look 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: ICodeBase
        Get 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:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • close

        public void close()
        Description copied from interface: ICodeBase
        This method should be called when done using the code base.
      • iterator

        public ICodeBaseIterator iterator()
                                   throws java.lang.InterruptedException
        Description copied from interface: IScannableCodeBase
        Get 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)