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 classClassPathBuilder.DiscoveredCodeBaseA codebase discovered during classpath building.(package private) static classClassPathBuilder.WorkListItemWorklist item.
-
Field Summary
Fields Modifier and Type Field Description private java.util.LinkedList<ClassDescriptor>appClassListprivate IClassFactoryclassFactoryprivate static booleanDEBUGprivate java.util.LinkedList<ClassPathBuilder.DiscoveredCodeBase>discoveredCodeBaseListprivate java.util.Map<java.lang.String,ClassPathBuilder.DiscoveredCodeBase>discoveredCodeBaseMapprivate IErrorLoggererrorLoggerprivate static booleanNO_PARSE_CLASS_NAMESprivate java.util.LinkedList<ClassPathBuilder.WorkListItem>projectWorkListprivate booleanscanNestedArchivesprivate static booleanVERBOSE
-
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 voidaddCodeBase(ICodeBaseLocator locator, boolean isApplication)Add a project codebase.private voidaddToWorkList(java.util.LinkedList<ClassPathBuilder.WorkListItem> workList, ClassPathBuilder.WorkListItem itemToAdd)Add a worklist item to the worklist.private voidaddWorkListItemsForClasspath(java.util.LinkedList<ClassPathBuilder.WorkListItem> workList, java.lang.String path)Add worklist items from given system classpath.private voidaddWorkListItemsForExtDir(java.util.LinkedList<ClassPathBuilder.WorkListItem> workList, java.lang.String extDir)Add worklist items from given extensions directory.voidbuild(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 voiddumpCodeBaseList(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 booleanisJava9orLater()private voidlocateCodebasesRequiredForAnalysis(IClassPath classPath, IClassPathBuilderProgress progress)Make an effort to find the codebases containing any files required for analysis.private booleanmatchesJarFile(java.lang.String entry, java.lang.String jarFileName)private voidparseClassName(ICodeBaseEntry entry)Attempt to parse data of given resource in order to divine the real name of the class contained in the resource.private booleanprobeCodeBaseForResource(ClassPathBuilder.DiscoveredCodeBase discoveredCodeBase, java.lang.String resourceName)Probe a codebase to see if a given source exists in that code base.private voidprocessWorkList(IClassPath classPath, java.util.LinkedList<ClassPathBuilder.WorkListItem> workList, IClassPathBuilderProgress progress)Process classpath worklist items.private booleanrunningFindBugsFullJar()private voidscanCodebase(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 voidscanJarManifestForClassPathEntries(java.util.LinkedList<ClassPathBuilder.WorkListItem> workList, ICodeBase codeBase)Check a codebase for a Jar manifest to examine for Class-Path entries.voidscanNestedArchives(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:IClassPathBuilderAdd a project codebase.- Specified by:
addCodeBasein 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:IClassPathBuilderSet whether or not nested archives should be scanned. This should be called before the build() method is called.- Specified by:
scanNestedArchivesin 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:IClassPathBuilderBuild the classpath.- Specified by:
buildin interfaceIClassPathBuilder- Parameters:
classPath- IClassPath object to buildprogress- IClassPathBuilderProgress callback- Throws:
ResourceNotFoundExceptionjava.io.IOExceptionjava.lang.InterruptedExceptionCheckedAnalysisException
-
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.InterruptedExceptionjava.io.IOExceptionResourceNotFoundException
-
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.InterruptedExceptionjava.io.IOExceptionResourceNotFoundException
-
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:IClassPathBuilderGet the list of application classes discovered while scanning the classpath.- Specified by:
getAppClassListin interfaceIClassPathBuilder- Returns:
- list of application classes
-
-