Class ClassPathBuilder
- java.lang.Object
-
- edu.umd.cs.findbugs.classfile.impl.ClassPathBuilder
-
- All Implemented Interfaces:
IClassPathBuilder
public class ClassPathBuilder extends java.lang.Object implements IClassPathBuilder
Implementation of IClassPathBuilder.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
ClassPathBuilder.DiscoveredCodeBase
A codebase discovered during classpath building.(package private) static class
ClassPathBuilder.WorkListItem
Worklist item.
-
Field Summary
Fields Modifier and Type Field Description private java.util.LinkedList<ClassDescriptor>
appClassList
private IClassFactory
classFactory
private static boolean
DEBUG
private java.util.LinkedList<ClassPathBuilder.DiscoveredCodeBase>
discoveredCodeBaseList
private java.util.Map<java.lang.String,ClassPathBuilder.DiscoveredCodeBase>
discoveredCodeBaseMap
private IErrorLogger
errorLogger
private static boolean
NO_PARSE_CLASS_NAMES
private java.util.LinkedList<ClassPathBuilder.WorkListItem>
projectWorkList
private boolean
scanNestedArchives
private static boolean
VERBOSE
-
Constructor Summary
Constructors Constructor Description ClassPathBuilder(IClassFactory classFactory, IErrorLogger errorLogger)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCodeBase(ICodeBaseLocator locator, boolean isApplication)
Add a project codebase.private void
addToWorkList(java.util.LinkedList<ClassPathBuilder.WorkListItem> workList, ClassPathBuilder.WorkListItem itemToAdd)
Add a worklist item to the worklist.private void
addWorkListItemsForClasspath(java.util.LinkedList<ClassPathBuilder.WorkListItem> workList, java.lang.String path)
Add worklist items from given system classpath.private void
addWorkListItemsForExtDir(java.util.LinkedList<ClassPathBuilder.WorkListItem> workList, java.lang.String extDir)
Add worklist items from given extensions directory.void
build(IClassPath classPath, IClassPathBuilderProgress progress)
Build the classpath.private java.util.LinkedList<ClassPathBuilder.WorkListItem>
buildFindBugsAnnotationCodebaseList()
Create a worklist that will add the FindBugs lib/annotations.jar to the classpath.private java.util.LinkedList<ClassPathBuilder.WorkListItem>
buildFindBugsFullJarCodebaseList()
private java.util.LinkedList<ClassPathBuilder.WorkListItem>
buildJSR305AnnotationsCodebaseList()
Create a worklist that will add the FindBugs lib/jsr305.jar to the classpath.private java.util.LinkedList<ClassPathBuilder.WorkListItem>
buildSystemCodebaseList()
private java.util.LinkedList<ClassPathBuilder.WorkListItem>
createFindBugsLibWorkList(java.lang.String jarFileName)
private void
dumpCodeBaseList(java.util.Iterator<? extends ICodeBase> i, java.lang.String desc)
java.util.List<ClassDescriptor>
getAppClassList()
Get the list of application classes discovered while scanning the classpath.private static boolean
isJava9orLater()
private void
locateCodebasesRequiredForAnalysis(IClassPath classPath, IClassPathBuilderProgress progress)
Make an effort to find the codebases containing any files required for analysis.private boolean
matchesJarFile(java.lang.String entry, java.lang.String jarFileName)
private void
parseClassName(ICodeBaseEntry entry)
Attempt to parse data of given resource in order to divine the real name of the class contained in the resource.private boolean
probeCodeBaseForResource(ClassPathBuilder.DiscoveredCodeBase discoveredCodeBase, java.lang.String resourceName)
Probe a codebase to see if a given source exists in that code base.private void
processWorkList(IClassPath classPath, java.util.LinkedList<ClassPathBuilder.WorkListItem> workList, IClassPathBuilderProgress progress)
Process classpath worklist items.private boolean
runningFindBugsFullJar()
private void
scanCodebase(IClassPath classPath, java.util.LinkedList<ClassPathBuilder.WorkListItem> workList, ClassPathBuilder.DiscoveredCodeBase discoveredCodeBase)
Scan given codebase in order to check the codebase for nested archives (adding any found to the worklist) build a list of class resources found in the codebaseprivate void
scanJarManifestForClassPathEntries(java.util.LinkedList<ClassPathBuilder.WorkListItem> workList, ICodeBase codeBase)
Check a codebase for a Jar manifest to examine for Class-Path entries.void
scanNestedArchives(boolean scanNestedArchives)
Set whether or not nested archives should be scanned.
-
-
-
Field Detail
-
VERBOSE
private static final boolean VERBOSE
-
DEBUG
private static final boolean DEBUG
-
NO_PARSE_CLASS_NAMES
private static final boolean NO_PARSE_CLASS_NAMES
-
classFactory
private final IClassFactory classFactory
-
errorLogger
private final IErrorLogger errorLogger
-
projectWorkList
private final java.util.LinkedList<ClassPathBuilder.WorkListItem> projectWorkList
-
discoveredCodeBaseList
private final java.util.LinkedList<ClassPathBuilder.DiscoveredCodeBase> discoveredCodeBaseList
-
discoveredCodeBaseMap
private final java.util.Map<java.lang.String,ClassPathBuilder.DiscoveredCodeBase> discoveredCodeBaseMap
-
appClassList
private final java.util.LinkedList<ClassDescriptor> appClassList
-
scanNestedArchives
private boolean scanNestedArchives
-
-
Constructor Detail
-
ClassPathBuilder
ClassPathBuilder(IClassFactory classFactory, IErrorLogger errorLogger)
Constructor.- Parameters:
classFactory
- the class factoryerrorLogger
- the error logger
-
-
Method Detail
-
addCodeBase
public void addCodeBase(ICodeBaseLocator locator, boolean isApplication)
Description copied from interface:IClassPathBuilder
Add a project codebase.- Specified by:
addCodeBase
in interfaceIClassPathBuilder
- Parameters:
locator
- locator for project codebaseisApplication
- true if the codebase is an application codebase, false otherwise
-
scanNestedArchives
public void scanNestedArchives(boolean scanNestedArchives)
Description copied from interface:IClassPathBuilder
Set whether or not nested archives should be scanned. This should be called before the build() method is called.- Specified by:
scanNestedArchives
in interfaceIClassPathBuilder
- Parameters:
scanNestedArchives
- true if nested archives should be scanned, false otherwise
-
build
public void build(IClassPath classPath, IClassPathBuilderProgress progress) throws CheckedAnalysisException, java.io.IOException, java.lang.InterruptedException
Description copied from interface:IClassPathBuilder
Build the classpath.- Specified by:
build
in interfaceIClassPathBuilder
- Parameters:
classPath
- IClassPath object to buildprogress
- IClassPathBuilderProgress callback- Throws:
ResourceNotFoundException
java.io.IOException
java.lang.InterruptedException
CheckedAnalysisException
-
locateCodebasesRequiredForAnalysis
private void locateCodebasesRequiredForAnalysis(IClassPath classPath, IClassPathBuilderProgress progress) throws java.lang.InterruptedException, java.io.IOException, ResourceNotFoundException
Make an effort to find the codebases containing any files required for analysis.- Throws:
java.lang.InterruptedException
java.io.IOException
ResourceNotFoundException
-
runningFindBugsFullJar
private boolean runningFindBugsFullJar()
-
buildFindBugsFullJarCodebaseList
private java.util.LinkedList<ClassPathBuilder.WorkListItem> buildFindBugsFullJarCodebaseList()
-
probeCodeBaseForResource
private boolean probeCodeBaseForResource(ClassPathBuilder.DiscoveredCodeBase discoveredCodeBase, java.lang.String resourceName)
Probe a codebase to see if a given source exists in that code base.- Parameters:
resourceName
- name of a resource- Returns:
- true if the resource exists in the codebase, false if not
-
dumpCodeBaseList
private void dumpCodeBaseList(java.util.Iterator<? extends ICodeBase> i, java.lang.String desc) throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
buildSystemCodebaseList
private java.util.LinkedList<ClassPathBuilder.WorkListItem> buildSystemCodebaseList()
-
isJava9orLater
private static boolean isJava9orLater()
-
buildFindBugsAnnotationCodebaseList
private java.util.LinkedList<ClassPathBuilder.WorkListItem> buildFindBugsAnnotationCodebaseList()
Create a worklist that will add the FindBugs lib/annotations.jar to the classpath.
-
buildJSR305AnnotationsCodebaseList
private java.util.LinkedList<ClassPathBuilder.WorkListItem> buildJSR305AnnotationsCodebaseList()
Create a worklist that will add the FindBugs lib/jsr305.jar to the classpath.
-
createFindBugsLibWorkList
private java.util.LinkedList<ClassPathBuilder.WorkListItem> createFindBugsLibWorkList(java.lang.String jarFileName)
-
matchesJarFile
private boolean matchesJarFile(java.lang.String entry, java.lang.String jarFileName)
-
addWorkListItemsForClasspath
private void addWorkListItemsForClasspath(java.util.LinkedList<ClassPathBuilder.WorkListItem> workList, java.lang.String path)
Add worklist items from given system classpath.- Parameters:
workList
- the worklistpath
- a system classpath
-
addWorkListItemsForExtDir
private void addWorkListItemsForExtDir(java.util.LinkedList<ClassPathBuilder.WorkListItem> workList, java.lang.String extDir)
Add worklist items from given extensions directory.- Parameters:
workList
- the worklistextDir
- an extensions directory
-
processWorkList
private void processWorkList(IClassPath classPath, java.util.LinkedList<ClassPathBuilder.WorkListItem> workList, IClassPathBuilderProgress progress) throws java.lang.InterruptedException, java.io.IOException, ResourceNotFoundException
Process classpath worklist items. We will attempt to find all nested archives and Class-Path entries specified in Jar manifests. This should give us as good an idea as possible of all of the classes available (and which are part of the application).- Parameters:
workList
- the worklist to processprogress
- IClassPathBuilderProgress callback- Throws:
java.lang.InterruptedException
java.io.IOException
ResourceNotFoundException
-
scanCodebase
private void scanCodebase(IClassPath classPath, java.util.LinkedList<ClassPathBuilder.WorkListItem> workList, ClassPathBuilder.DiscoveredCodeBase discoveredCodeBase) throws java.lang.InterruptedException
Scan given codebase in order to- check the codebase for nested archives (adding any found to the worklist)
- build a list of class resources found in the codebase
- Parameters:
workList
- the worklistdiscoveredCodeBase
- the codebase to scan- Throws:
java.lang.InterruptedException
-
parseClassName
private void parseClassName(ICodeBaseEntry entry)
Attempt to parse data of given resource in order to divine the real name of the class contained in the resource.- Parameters:
entry
- the resource
-
scanJarManifestForClassPathEntries
private void scanJarManifestForClassPathEntries(java.util.LinkedList<ClassPathBuilder.WorkListItem> workList, ICodeBase codeBase) throws java.io.IOException
Check a codebase for a Jar manifest to examine for Class-Path entries.- Parameters:
workList
- the worklistcodeBase
- the codebase for examine for a Jar manifest- Throws:
java.io.IOException
-
addToWorkList
private void addToWorkList(java.util.LinkedList<ClassPathBuilder.WorkListItem> workList, ClassPathBuilder.WorkListItem itemToAdd)
Add a worklist item to the worklist. This method maintains the invariant that all of the worklist items representing application codebases appear before all of the worklist items representing auxiliary codebases.- Parameters:
workList
- the worklistitemToAdd
- the worklist item to add
-
getAppClassList
public java.util.List<ClassDescriptor> getAppClassList()
Description copied from interface:IClassPathBuilder
Get the list of application classes discovered while scanning the classpath.- Specified by:
getAppClassList
in interfaceIClassPathBuilder
- Returns:
- list of application classes
-
-