Package com.google.common.reflect
Class ClassPath.LocationInfo
- java.lang.Object
-
- com.google.common.reflect.ClassPath.LocationInfo
-
- Enclosing class:
- ClassPath
static final class ClassPath.LocationInfo extends java.lang.Object
Represents a single location (a directory or a jar file) in the class path and is responsible for scanning resources from this location.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ClassLoader
classloader
(package private) java.io.File
home
-
Constructor Summary
Constructors Constructor Description LocationInfo(java.io.File home, java.lang.ClassLoader classloader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
java.io.File
file()
Returns the file this location is from.int
hashCode()
private void
scan(java.io.File file, java.util.Set<java.io.File> scannedUris, ImmutableSet.Builder<ClassPath.ResourceInfo> builder)
private void
scanDirectory(java.io.File directory, ImmutableSet.Builder<ClassPath.ResourceInfo> builder)
private void
scanDirectory(java.io.File directory, java.lang.String packagePrefix, java.util.Set<java.io.File> currentPath, ImmutableSet.Builder<ClassPath.ResourceInfo> builder)
Recursively scan the given directory, adding resources for each file encountered.private void
scanJar(java.io.File file, java.util.Set<java.io.File> scannedUris, ImmutableSet.Builder<ClassPath.ResourceInfo> builder)
private void
scanJarFile(java.util.jar.JarFile file, ImmutableSet.Builder<ClassPath.ResourceInfo> builder)
ImmutableSet<ClassPath.ResourceInfo>
scanResources()
Scans this location and returns all scanned resources.ImmutableSet<ClassPath.ResourceInfo>
scanResources(java.util.Set<java.io.File> scannedFiles)
Scans this location and returns all scanned resources.java.lang.String
toString()
-
-
-
Method Detail
-
file
public final java.io.File file()
Returns the file this location is from.
-
scanResources
public ImmutableSet<ClassPath.ResourceInfo> scanResources() throws java.io.IOException
Scans this location and returns all scanned resources.- Throws:
java.io.IOException
-
scanResources
public ImmutableSet<ClassPath.ResourceInfo> scanResources(java.util.Set<java.io.File> scannedFiles) throws java.io.IOException
Scans this location and returns all scanned resources.This file and jar files from "Class-Path" entry in the scanned manifest files will be added to
scannedFiles
.A file will be scanned at most once even if specified multiple times by one or multiple jar files' "Class-Path" manifest entries. Particularly, if a jar file from the "Class-Path" manifest entry is already in
scannedFiles
, either because it was scanned earlier, or it was intentionally added to the set by the caller, it will not be scanned again.Note that when you call
location.scanResources(scannedFiles)
, the location will always be scanned even ifscannedFiles
already contains it.- Throws:
java.io.IOException
-
scan
private void scan(java.io.File file, java.util.Set<java.io.File> scannedUris, ImmutableSet.Builder<ClassPath.ResourceInfo> builder) throws java.io.IOException
- Throws:
java.io.IOException
-
scanJar
private void scanJar(java.io.File file, java.util.Set<java.io.File> scannedUris, ImmutableSet.Builder<ClassPath.ResourceInfo> builder) throws java.io.IOException
- Throws:
java.io.IOException
-
scanJarFile
private void scanJarFile(java.util.jar.JarFile file, ImmutableSet.Builder<ClassPath.ResourceInfo> builder)
-
scanDirectory
private void scanDirectory(java.io.File directory, ImmutableSet.Builder<ClassPath.ResourceInfo> builder) throws java.io.IOException
- Throws:
java.io.IOException
-
scanDirectory
private void scanDirectory(java.io.File directory, java.lang.String packagePrefix, java.util.Set<java.io.File> currentPath, ImmutableSet.Builder<ClassPath.ResourceInfo> builder) throws java.io.IOException
Recursively scan the given directory, adding resources for each file encountered. Symlinks which have already been traversed in the current tree path will be skipped to eliminate cycles; otherwise symlinks are traversed.- Parameters:
directory
- the root of the directory to scanpackagePrefix
- resource path prefix insideclassloader
for any files found underdirectory
currentPath
- canonical files already visited in the current directory tree path, for cycle elimination- Throws:
java.io.IOException
-
equals
public boolean equals(@CheckForNull java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-