Package edu.umd.cs.findbugs
Class Project
- java.lang.Object
-
- edu.umd.cs.findbugs.Project
-
- All Implemented Interfaces:
XMLWriteable
,java.lang.AutoCloseable
public class Project extends java.lang.Object implements XMLWriteable, java.lang.AutoCloseable
A project in the GUI. This consists of some number of Jar files to analyze for bugs, and optionally
- some number of source directories, for locating the program's source code
- some number of auxiliary classpath entries, for locating classes referenced by the program which the user doesn't want to analyze
- some number of boolean options
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Project.WorkList
Worklist for finding implicit classpath entries.private static class
Project.WorkListItem
Worklist item for finding implicit classpath entries.
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.lang.String>
analysisTargets
List of jars/directories to analyzeprivate static java.lang.String
AUX_CLASSPATH_ENTRIES_KEY
(package private) static java.lang.String
AUX_CLASSPATH_ENTRY_ELEMENT_NAME
private java.util.List<java.lang.String>
auxClasspathEntryList
The list of auxiliary classpath entries.private UserPreferences
configuration
private java.util.List<java.io.File>
currentWorkingDirectoryList
private java.util.Map<java.lang.String,java.lang.Boolean>
enabledPlugins
key is plugin idprivate static boolean
FILE_IGNORE_CASE
Hack for whether files are case insensitive.(package private) static java.lang.String
FILENAME_ATTRIBUTE_NAME
private IGuiCallback
guiCallback
private boolean
isModified
Flag to indicate that this Project has been modified.(package private) static java.lang.String
JAR_ELEMENT_NAME
private static java.lang.String
JAR_FILES_KEY
private static org.slf4j.Logger
LOG
private static java.lang.String
OPTIONS_KEY
(package private) static java.lang.String
PLUGIN_ELEMENT_NAME
(package private) static java.lang.String
PLUGIN_ID_ATTRIBUTE_NAME
(package private) static java.lang.String
PLUGIN_STATUS_ELEMENT_NAME
private java.lang.String
projectName
(package private) static java.lang.String
PROJECTNAME_ATTRIBUTE_NAME
static java.lang.String
RELATIVE_PATHS
private SourceFinder
sourceFinder
(package private) static java.lang.String
SRC_DIR_ELEMENT_NAME
private static java.lang.String
SRC_DIRS_KEY
private java.util.List<java.lang.String>
srcDirList
The list of source directories.private Filter
suppressionFilter
private long
timestampForAnalyzedClasses
static java.lang.String
UNNAMED_PROJECT
StaticConstant used to name anonymous projects.(package private) static java.lang.String
WRK_DIR_ELEMENT_NAME
-
Constructor Summary
Constructors Constructor Description Project()
Create an anonymous project.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(Project project2)
add information from project2 to this projectboolean
addAuxClasspathEntry(java.lang.String auxClasspathEntry)
Add an auxiliary classpath entryboolean
addFile(java.lang.String fileName)
Add a file to the project.boolean
addSourceDir(java.lang.String sourceDir)
Deprecated.Calling this method repeatedly performs poorly because a SourceFinder is created each time, which checks all files for existence each time.boolean
addSourceDirs(java.util.Collection<java.lang.String> sourceDirs)
Add source directories to the project.void
addTimestamp(long timestamp)
private <T> boolean
addToListInternal(java.util.Collection<T> list, T value)
Add a value to given list, making the Project modified if the value is not already present in the list.boolean
addWorkingDir(java.lang.String dirName)
Add a working directory to the project.static <T> java.util.List<T>
appendWithoutDuplicates(java.util.List<T> lst1, java.util.List<T> lst2)
void
close()
private java.lang.String
convertToRelative(java.lang.String srcFile, java.lang.String base)
Converts a full path to a relative path if possibleprivate java.lang.Iterable<java.lang.String>
convertToRelative(java.util.List<java.lang.String> paths, java.lang.String base)
Project
duplicate()
Return an exact copy of this Project.java.lang.String
getAuxClasspathEntry(int n)
Get the n'th auxiliary classpath entry.java.util.List<java.lang.String>
getAuxClasspathEntryList()
Return the list of aux classpath entries.UserPreferences
getConfiguration()
java.lang.String
getFile(int num)
Get the given file in the list of project files.java.lang.String[]
getFileArray()
Get project files as an array of Strings.int
getFileCount()
Get the number of files in the project.java.util.List<java.lang.String>
getFileList()
Get the list of files, directories, and zip files in the project.IGuiCallback
getGuiCallback()
java.util.List<java.lang.String>
getImplicitClasspathEntryList()
Deprecated.FindBugs2 and ClassPathBuilder take care of this automaticallyint
getNumAuxClasspathEntries()
Get the number of auxiliary classpath entries.int
getNumSourceDirs()
Get the number of source directories in the project.java.lang.Boolean
getPluginStatus(Plugin plugin)
java.lang.String
getProjectName()
java.lang.Iterable<java.lang.String>
getResolvedSourcePaths()
java.lang.String
getSourceDir(int num)
Get the given source directory.java.lang.String[]
getSourceDirArray()
Get source dirs as an array of Strings.java.util.List<java.lang.String>
getSourceDirList()
Get the source dir list.SourceFinder
getSourceFinder()
Filter
getSuppressionFilter()
long
getTimestamp()
boolean
isGuiAvaliable()
boolean
isModified()
Return whether or not this Project has unsaved modifications.private java.lang.String
makeAbsoluteCWD(java.lang.String fileName)
Make the given filename absolute relative to the current working directory.private java.util.List<java.lang.String>
makeAbsoluteCwdCandidates(java.lang.String fileName)
Make the given filename absolute relative to the current working directory candidates.private void
processComponentJar(java.net.URL jarFileURL, Project.WorkList workList, java.util.List<java.lang.String> implicitClasspath)
Examine the manifest of a single zip/jar file for implicit classapth entries.static Project
readProject(java.lang.String argument)
Read Project from named file.static Project
readXML(java.io.File f)
void
removeAuxClasspathEntry(int n)
Remove the n'th auxiliary classpath entry.void
removeFile(int num)
Remove file at the given index in the list of project filesvoid
removeSourceDir(int num)
Remove source directory at given index.void
setConfiguration(UserPreferences configuration)
void
setCurrentWorkingDirectory(java.io.File f)
void
setGuiCallback(IGuiCallback guiCallback)
void
setModified(boolean isModified)
Set whether or not this Project has unsaved modifications.void
setPluginStatusTrinary(java.lang.String pluginId, java.lang.Boolean enabled)
void
setProjectName(java.lang.String projectName)
void
setSuppressionFilter(Filter suppressionFilter)
void
setTimestamp(long timestamp)
java.lang.String
toString()
Convert to a string in a nice (displayable) format.static java.lang.String
transformFilename(java.lang.String fileName)
Transform a user-entered filename into a proper filename, by adding the ".fb" file extension if it isn't already present.void
write(java.lang.String outputFile, boolean useRelativePaths, java.lang.String relativeBase)
Deprecated.void
writeXML(XMLOutput xmlOutput)
Write this object to given XMLOutput.void
writeXML(XMLOutput xmlOutput, java.io.File destination, BugCollection bugCollection)
void
writeXML(java.io.File f, BugCollection bugCollection)
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
currentWorkingDirectoryList
private final java.util.List<java.io.File> currentWorkingDirectoryList
-
projectName
private java.lang.String projectName
-
analysisTargets
private java.util.List<java.lang.String> analysisTargets
List of jars/directories to analyze
-
srcDirList
private java.util.List<java.lang.String> srcDirList
The list of source directories.
-
auxClasspathEntryList
private java.util.List<java.lang.String> auxClasspathEntryList
The list of auxiliary classpath entries.
-
isModified
private boolean isModified
Flag to indicate that this Project has been modified.
-
configuration
private UserPreferences configuration
-
enabledPlugins
private final java.util.Map<java.lang.String,java.lang.Boolean> enabledPlugins
key is plugin id
-
UNNAMED_PROJECT
public static final java.lang.String UNNAMED_PROJECT
StaticConstant used to name anonymous projects.- See Also:
- Constant Field Values
-
timestampForAnalyzedClasses
private long timestampForAnalyzedClasses
-
guiCallback
private IGuiCallback guiCallback
-
suppressionFilter
@Nonnull private Filter suppressionFilter
-
sourceFinder
private SourceFinder sourceFinder
-
OPTIONS_KEY
private static final java.lang.String OPTIONS_KEY
- See Also:
- Constant Field Values
-
JAR_FILES_KEY
private static final java.lang.String JAR_FILES_KEY
- See Also:
- Constant Field Values
-
SRC_DIRS_KEY
private static final java.lang.String SRC_DIRS_KEY
- See Also:
- Constant Field Values
-
AUX_CLASSPATH_ENTRIES_KEY
private static final java.lang.String AUX_CLASSPATH_ENTRIES_KEY
- See Also:
- Constant Field Values
-
RELATIVE_PATHS
public static final java.lang.String RELATIVE_PATHS
- See Also:
- Constant Field Values
-
JAR_ELEMENT_NAME
static final java.lang.String JAR_ELEMENT_NAME
- See Also:
- Constant Field Values
-
AUX_CLASSPATH_ENTRY_ELEMENT_NAME
static final java.lang.String AUX_CLASSPATH_ENTRY_ELEMENT_NAME
- See Also:
- Constant Field Values
-
SRC_DIR_ELEMENT_NAME
static final java.lang.String SRC_DIR_ELEMENT_NAME
- See Also:
- Constant Field Values
-
WRK_DIR_ELEMENT_NAME
static final java.lang.String WRK_DIR_ELEMENT_NAME
- See Also:
- Constant Field Values
-
FILENAME_ATTRIBUTE_NAME
static final java.lang.String FILENAME_ATTRIBUTE_NAME
- See Also:
- Constant Field Values
-
PROJECTNAME_ATTRIBUTE_NAME
static final java.lang.String PROJECTNAME_ATTRIBUTE_NAME
- See Also:
- Constant Field Values
-
PLUGIN_ELEMENT_NAME
static final java.lang.String PLUGIN_ELEMENT_NAME
- See Also:
- Constant Field Values
-
PLUGIN_ID_ATTRIBUTE_NAME
static final java.lang.String PLUGIN_ID_ATTRIBUTE_NAME
- See Also:
- Constant Field Values
-
PLUGIN_STATUS_ELEMENT_NAME
static final java.lang.String PLUGIN_STATUS_ELEMENT_NAME
- See Also:
- Constant Field Values
-
FILE_IGNORE_CASE
private static final boolean FILE_IGNORE_CASE
Hack for whether files are case insensitive. For now, we'll assume that Windows is the only case insensitive OS. (OpenVMS users, feel free to submit a patch :-)
-
-
Method Detail
-
getPluginStatus
@CheckForNull public java.lang.Boolean getPluginStatus(Plugin plugin)
-
setPluginStatusTrinary
public void setPluginStatusTrinary(java.lang.String pluginId, java.lang.Boolean enabled)
-
getConfiguration
public UserPreferences getConfiguration()
-
setConfiguration
public void setConfiguration(@Nonnull UserPreferences configuration)
- Parameters:
configuration
- The configuration to set, non null
-
duplicate
public Project duplicate()
Return an exact copy of this Project.
-
getSourceFinder
public SourceFinder getSourceFinder()
-
isGuiAvaliable
public boolean isGuiAvaliable()
-
add
public void add(Project project2)
add information from project2 to this project
-
appendWithoutDuplicates
public static <T> java.util.List<T> appendWithoutDuplicates(java.util.List<T> lst1, java.util.List<T> lst2)
-
setCurrentWorkingDirectory
public void setCurrentWorkingDirectory(java.io.File f)
-
isModified
public boolean isModified()
Return whether or not this Project has unsaved modifications.
-
setModified
public void setModified(boolean isModified)
Set whether or not this Project has unsaved modifications.
-
addFile
public boolean addFile(java.lang.String fileName)
Add a file to the project.- Parameters:
fileName
- the file to add- Returns:
- true if the file was added, or false if the file was already present
-
addSourceDir
@Deprecated public boolean addSourceDir(java.lang.String sourceDir)
Deprecated.Calling this method repeatedly performs poorly because a SourceFinder is created each time, which checks all files for existence each time. UseaddSourceDirs(java.util.Collection<java.lang.String>)
instead.Add a source directory to the project.- Parameters:
sourceDir
- The source directory to add. These can be either an absolute path or relative to any of the working directories in this project object.- Returns:
- true if the source directory was added or false if it was already present
-
addSourceDirs
public boolean addSourceDirs(java.util.Collection<java.lang.String> sourceDirs)
Add source directories to the project.- Parameters:
sourceDirs
- The source directories to add. These can be either absolute paths or relative to any of the working directories in this project object.- Returns:
- true if a source directory was added or false if all source directories were already present
-
addWorkingDir
public boolean addWorkingDir(java.lang.String dirName)
Add a working directory to the project.- Parameters:
dirName
- the directory to add- Returns:
- true if the working directory was added, or false if the working directory was already present
-
getFileCount
public int getFileCount()
Get the number of files in the project.- Returns:
- the number of files in the project
-
getFile
public java.lang.String getFile(int num)
Get the given file in the list of project files.- Parameters:
num
- the number of the file in the list of project files- Returns:
- the name of the file
-
removeFile
public void removeFile(int num)
Remove file at the given index in the list of project files- Parameters:
num
- index of the file to remove in the list of project files
-
getFileList
public java.util.List<java.lang.String> getFileList()
Get the list of files, directories, and zip files in the project.
-
getNumSourceDirs
public int getNumSourceDirs()
Get the number of source directories in the project.- Returns:
- the number of source directories in the project
-
getSourceDir
public java.lang.String getSourceDir(int num)
Get the given source directory.- Parameters:
num
- the number of the source directory- Returns:
- the source directory
-
removeSourceDir
public void removeSourceDir(int num)
Remove source directory at given index.- Parameters:
num
- index of the source directory to remove
-
getFileArray
public java.lang.String[] getFileArray()
Get project files as an array of Strings.
-
getSourceDirArray
public java.lang.String[] getSourceDirArray()
Get source dirs as an array of Strings.
-
getSourceDirList
public java.util.List<java.lang.String> getSourceDirList()
Get the source dir list.
-
addAuxClasspathEntry
public boolean addAuxClasspathEntry(java.lang.String auxClasspathEntry)
Add an auxiliary classpath entry- Parameters:
auxClasspathEntry
- the entry- Returns:
- true if the entry was added successfully, or false if the given entry is already in the list
-
getNumAuxClasspathEntries
public int getNumAuxClasspathEntries()
Get the number of auxiliary classpath entries.
-
getAuxClasspathEntry
public java.lang.String getAuxClasspathEntry(int n)
Get the n'th auxiliary classpath entry.
-
removeAuxClasspathEntry
public void removeAuxClasspathEntry(int n)
Remove the n'th auxiliary classpath entry.
-
getAuxClasspathEntryList
public java.util.List<java.lang.String> getAuxClasspathEntryList()
Return the list of aux classpath entries.
-
getImplicitClasspathEntryList
@Deprecated public java.util.List<java.lang.String> getImplicitClasspathEntryList()
Deprecated.FindBugs2 and ClassPathBuilder take care of this automaticallyReturn the list of implicit classpath entries. The implicit classpath is computed from the closure of the set of jar files that are referenced by the"Class-Path"
attribute of the manifest of the any jar file that is part of this project or by the"Class-Path"
attribute of any directly or indirectly referenced jar. The referenced jar files that exist are the list of implicit classpath entries.
-
processComponentJar
private void processComponentJar(java.net.URL jarFileURL, Project.WorkList workList, java.util.List<java.lang.String> implicitClasspath)
Examine the manifest of a single zip/jar file for implicit classapth entries.- Parameters:
jarFileURL
- URL of the zip/jar fileworkList
- worklist of zip/jar files to examineimplicitClasspath
- list of implicit classpath entries found
-
write
@Deprecated public void write(java.lang.String outputFile, boolean useRelativePaths, java.lang.String relativeBase) throws java.io.IOException
Deprecated.Save the project to an output file.- Parameters:
outputFile
- name of output fileuseRelativePaths
- true if the project should be written using only relative pathsrelativeBase
- if useRelativePaths is true, this file is taken as the base directory in terms of which all files should be made relative- Throws:
java.io.IOException
- if an error occurs while writing
-
readXML
public static Project readXML(java.io.File f) throws java.io.IOException, org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException
- Throws:
java.io.IOException
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
-
writeXML
public void writeXML(java.io.File f, @CheckForNull BugCollection bugCollection) throws java.io.IOException
- Throws:
java.io.IOException
-
readProject
public static Project readProject(java.lang.String argument) throws java.io.IOException
Read Project from named file.- Parameters:
argument
- command line argument containing project file name- Returns:
- the Project
- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
Convert to a string in a nice (displayable) format.- Overrides:
toString
in classjava.lang.Object
-
transformFilename
public static java.lang.String transformFilename(java.lang.String fileName)
Transform a user-entered filename into a proper filename, by adding the ".fb" file extension if it isn't already present.
-
writeXML
public void writeXML(XMLOutput xmlOutput) throws java.io.IOException
Description copied from interface:XMLWriteable
Write this object to given XMLOutput.- Specified by:
writeXML
in interfaceXMLWriteable
- Parameters:
xmlOutput
- the XMLOutput for the document- Throws:
java.io.IOException
-
writeXML
public void writeXML(XMLOutput xmlOutput, @CheckForNull java.io.File destination, @CheckForNull BugCollection bugCollection) throws java.io.IOException
- Throws:
java.io.IOException
-
convertToRelative
private java.lang.Iterable<java.lang.String> convertToRelative(java.util.List<java.lang.String> paths, java.lang.String base)
-
convertToRelative
private java.lang.String convertToRelative(java.lang.String srcFile, java.lang.String base)
Converts a full path to a relative path if possible- Parameters:
srcFile
- path to convert- Returns:
- the converted filename
-
makeAbsoluteCWD
private java.lang.String makeAbsoluteCWD(java.lang.String fileName)
Make the given filename absolute relative to the current working directory.
-
makeAbsoluteCwdCandidates
private java.util.List<java.lang.String> makeAbsoluteCwdCandidates(java.lang.String fileName)
Make the given filename absolute relative to the current working directory candidates. If the given filename exists in more than one of the working directories, a list of these existing absolute paths is returned. The returned list is guaranteed to be non-empty. The returned paths might exist or not exist and might be relative or absolute.- Returns:
- A list of at least one candidate path for the given filename.
-
addToListInternal
private <T> boolean addToListInternal(java.util.Collection<T> list, T value)
Add a value to given list, making the Project modified if the value is not already present in the list.- Parameters:
list
- the listvalue
- the value to be added- Returns:
- true if the value was not already present in the list, false otherwise
-
setTimestamp
public void setTimestamp(long timestamp)
-
addTimestamp
public void addTimestamp(long timestamp)
-
getTimestamp
public long getTimestamp()
-
setProjectName
public void setProjectName(java.lang.String projectName)
-
getProjectName
public java.lang.String getProjectName()
-
setSuppressionFilter
public void setSuppressionFilter(@Nonnull Filter suppressionFilter)
-
getSuppressionFilter
@Nonnull public Filter getSuppressionFilter()
-
setGuiCallback
public void setGuiCallback(IGuiCallback guiCallback)
-
getGuiCallback
public IGuiCallback getGuiCallback()
-
getResolvedSourcePaths
public java.lang.Iterable<java.lang.String> getResolvedSourcePaths()
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
-
-