6 Replies Latest reply on Apr 30, 2006 5:17 AM by Scott Stark Branched to a new discussion.

    VFS doesn't support scanning

    Bill Burke Master

      Maybe this is just an implementation error, but the VFS implementation doesn't support the notion of a scanned deployment. By scanned, i mean a deployment that needs to be scanned for annotated classes. This scanning would also be necessary for nested deployments.

      The logical place for a scanning API is the ReadOnlyVFS interface, but no browsing api exists. (And there is no JAR based ReadOnlyVFS implementation). This brought me to the VirtualFile interface. The getChildren() impementation for file and jar file give you different behavior. File impl doesn't recurse directories while the Jar one lists all entries.

      The scanning api should be in the ReadOnlyVFS interface correct?

        • 1. Re: VFS doesn't support scanning
          Scott Stark Master

          Yes, my feeling would be to add a visitor pattern to the ReadOnlyVFS:

          // General acceptance visitor
          Iterator<VirtualFile> scan(Visitor acceptVisitor);
          // Simple visitor wrapper that would use a simple VirtualFile name regex
          Iterator<VirtualFile> scan(String fileNameRegex);

          I don't believe there should be a jar specific VFS implementation as a jar it not a usable protocol due to the lack of nested jars. A jar is just a compacted file system rooted under the jar name. The VirtualFile implementations for a given VFS would have to deal with nested jars.

          In terms of vfs behavior, its just a question of getting consistent behavior between a packed/unpacked jar. As you mentioned elsewhere this currently is not the case. Jars do have notions of directories so this should not be a big change to the current JarImpl.

          • 2. Re: VFS doesn't support scanning
            Bill Burke Master

            You are really contradicting yourself here. scanning can't be a VFS function if there is no Jar VFS implementation. Scanning should be a function of VirtualFile then.

            • 3. Re: VFS doesn't support scanning
              Scott Stark Master

              Why? The vfs uses the getChildren call to traverse the files. The jar is handled by a vf impl. Show me why a jar needs to be treated as a seperate url protocol.

              • 4. Re: VFS doesn't support scanning
                Scott Stark Master

                The following scan method has been added:

                public interface ReadOnlyVFS
                 * Scan the VFS for files accepted by the visitor.
                 * @param acceptVisitor - the visitor that defines which files to accept
                 * @return Iterator<VirtualFile> of the matches
                 public Iterator<VirtualFile> scan(VFSVisitor acceptVisitor);
                public interface VFSVisitor
                 * Visit a virtual file and indicate if it should be included in the scan.
                 * A directory must be included if its children are to be scanned.
                 * @param vf - the virtual file to test for inclusion
                 * @return true if the file should be included.
                 public boolean visit(VirtualFile vf);

                See the TestFileVFS.testClassScan for an example. Next is to add a testUnpackedClassScan to validate an unpacked jar vfs scan.

                • 5. Re: VFS doesn't support scanning
                  Bill Burke Master

                  I implemented something before reading this. Your interface didn't meet my requirements anyways. I added a getChildrenRecursively() to VirtualFile as I need to be able to do this on a per-child basis.

                  Also, I added some metadata to VirtualFile, specifically isArchive() so that you can know if it is a JAR, exploded jar, or just a plain file/directory.

                  Also fixed a few bugs.

                  • 6. Re: VFS doesn't support scanning
                    Scott Stark Master

                    When do you need to know whether a file is a jar or not from an external use point of view?